• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
CFXJSE_Arguments(const v8::FunctionCallbackInfo<v8::Value> * pInfo,CFXJSE_Value * pRetValue)13 CFXJSE_Arguments::CFXJSE_Arguments(
14     const v8::FunctionCallbackInfo<v8::Value>* pInfo,
15     CFXJSE_Value* pRetValue)
16     : m_pInfo(pInfo), m_pRetValue(pRetValue) {}
17 
~CFXJSE_Arguments()18 CFXJSE_Arguments::~CFXJSE_Arguments() {}
19 
GetLength() const20 int32_t CFXJSE_Arguments::GetLength() const {
21   return m_pInfo->Length();
22 }
23 
GetValue(int32_t index) const24 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 
GetBoolean(int32_t index) const30 bool CFXJSE_Arguments::GetBoolean(int32_t index) const {
31   return (*m_pInfo)[index]->BooleanValue();
32 }
33 
GetInt32(int32_t index) const34 int32_t CFXJSE_Arguments::GetInt32(int32_t index) const {
35   return static_cast<int32_t>((*m_pInfo)[index]->NumberValue());
36 }
37 
GetFloat(int32_t index) const38 float CFXJSE_Arguments::GetFloat(int32_t index) const {
39   return static_cast<float>((*m_pInfo)[index]->NumberValue());
40 }
41 
GetUTF8String(int32_t index) const42 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 
GetObject(int32_t index,CFXJSE_Class * pClass) const48 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 
GetReturnValue() const57 CFXJSE_Value* CFXJSE_Arguments::GetReturnValue() const {
58   return m_pRetValue.Get();
59 }
60