1 // Copyright 2016 PDFium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 6 7 #include "fxjs/cfxjse_arguments.h" 8 9 #include "fxjs/cfxjse_context.h" 10 #include "fxjs/cfxjse_value.h" 11 #include "third_party/base/ptr_util.h" 12 13 CFXJSE_Arguments::CFXJSE_Arguments( 14 const v8::FunctionCallbackInfo<v8::Value>* pInfo, 15 CFXJSE_Value* pRetValue) 16 : m_pInfo(pInfo), m_pRetValue(pRetValue) {} 17 18 CFXJSE_Arguments::~CFXJSE_Arguments() {} 19 20 int32_t CFXJSE_Arguments::GetLength() const { 21 return m_pInfo->Length(); 22 } 23 24 std::unique_ptr<CFXJSE_Value> CFXJSE_Arguments::GetValue(int32_t index) const { 25 auto pArgValue = pdfium::MakeUnique<CFXJSE_Value>(v8::Isolate::GetCurrent()); 26 pArgValue->ForceSetValue((*m_pInfo)[index]); 27 return pArgValue; 28 } 29 30 bool CFXJSE_Arguments::GetBoolean(int32_t index) const { 31 return (*m_pInfo)[index]->BooleanValue(); 32 } 33 34 int32_t CFXJSE_Arguments::GetInt32(int32_t index) const { 35 return static_cast<int32_t>((*m_pInfo)[index]->NumberValue()); 36 } 37 38 float CFXJSE_Arguments::GetFloat(int32_t index) const { 39 return static_cast<float>((*m_pInfo)[index]->NumberValue()); 40 } 41 42 ByteString CFXJSE_Arguments::GetUTF8String(int32_t index) const { 43 v8::Local<v8::String> hString = (*m_pInfo)[index]->ToString(); 44 v8::String::Utf8Value szStringVal(m_pInfo->GetIsolate(), hString); 45 return ByteString(*szStringVal); 46 } 47 48 CFXJSE_HostObject* CFXJSE_Arguments::GetObject(int32_t index, 49 CFXJSE_Class* pClass) const { 50 v8::Local<v8::Value> hValue = (*m_pInfo)[index]; 51 ASSERT(!hValue.IsEmpty()); 52 if (!hValue->IsObject()) 53 return nullptr; 54 return FXJSE_RetrieveObjectBinding(hValue.As<v8::Object>(), pClass); 55 } 56 57 CFXJSE_Value* CFXJSE_Arguments::GetReturnValue() const { 58 return m_pRetValue.Get(); 59 } 60