• 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/xfa/cfxjse_arguments.h"
8 
9 #include "fxjs/xfa/cfxjse_context.h"
10 #include "fxjs/xfa/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(m_pInfo->GetIsolate());
32 }
33 
GetInt32(int32_t index) const34 int32_t CFXJSE_Arguments::GetInt32(int32_t index) const {
35   return static_cast<int32_t>(
36       (*m_pInfo)[index]
37           ->NumberValue(m_pInfo->GetIsolate()->GetCurrentContext())
38           .FromMaybe(0.0));
39 }
40 
GetFloat(int32_t index) const41 float CFXJSE_Arguments::GetFloat(int32_t index) const {
42   return static_cast<float>(
43       (*m_pInfo)[index]
44           ->NumberValue(m_pInfo->GetIsolate()->GetCurrentContext())
45           .FromMaybe(0.0));
46 }
47 
GetUTF8String(int32_t index) const48 ByteString CFXJSE_Arguments::GetUTF8String(int32_t index) const {
49   v8::Isolate* isolate = m_pInfo->GetIsolate();
50   v8::Local<v8::Value> info = (*m_pInfo)[index];
51   v8::Local<v8::String> hString =
52       info->ToString(isolate->GetCurrentContext()).ToLocalChecked();
53   v8::String::Utf8Value szStringVal(isolate, hString);
54   return ByteString(*szStringVal);
55 }
56 
GetReturnValue() const57 CFXJSE_Value* CFXJSE_Arguments::GetReturnValue() const {
58   return m_pRetValue.Get();
59 }
60