blob: f390cefdf84a6d4bda957cd93ef6793bb294b944 [file] [log] [blame]
dsinclair08fea802016-07-12 10:37:52 -07001// 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
dsinclair43554682016-09-29 17:29:48 -07007#include "fxjs/cfxjse_arguments.h"
dsinclair08fea802016-07-12 10:37:52 -07008
dsinclair43554682016-09-29 17:29:48 -07009#include "fxjs/cfxjse_context.h"
10#include "fxjs/cfxjse_value.h"
Tom Sepez80547a12017-04-25 12:43:13 -070011#include "third_party/base/ptr_util.h"
dsinclair08fea802016-07-12 10:37:52 -070012
Tom Sepezd0409af2017-05-25 15:53:57 -070013CFXJSE_Arguments::CFXJSE_Arguments(
14 const v8::FunctionCallbackInfo<v8::Value>* pInfo,
15 CFXJSE_Value* pRetValue)
16 : m_pInfo(pInfo), m_pRetValue(pRetValue) {}
17
18CFXJSE_Arguments::~CFXJSE_Arguments() {}
19
dsinclair08fea802016-07-12 10:37:52 -070020int32_t CFXJSE_Arguments::GetLength() const {
21 return m_pInfo->Length();
22}
23
24std::unique_ptr<CFXJSE_Value> CFXJSE_Arguments::GetValue(int32_t index) const {
Tom Sepez80547a12017-04-25 12:43:13 -070025 auto pArgValue = pdfium::MakeUnique<CFXJSE_Value>(v8::Isolate::GetCurrent());
26 pArgValue->ForceSetValue((*m_pInfo)[index]);
27 return pArgValue;
dsinclair08fea802016-07-12 10:37:52 -070028}
29
tsepez304bb912016-11-03 06:10:26 -070030bool CFXJSE_Arguments::GetBoolean(int32_t index) const {
dsinclair08fea802016-07-12 10:37:52 -070031 return (*m_pInfo)[index]->BooleanValue();
32}
33
34int32_t CFXJSE_Arguments::GetInt32(int32_t index) const {
35 return static_cast<int32_t>((*m_pInfo)[index]->NumberValue());
36}
37
Dan Sinclair05df0752017-03-14 14:43:42 -040038float CFXJSE_Arguments::GetFloat(int32_t index) const {
39 return static_cast<float>((*m_pInfo)[index]->NumberValue());
dsinclair08fea802016-07-12 10:37:52 -070040}
41
Ryan Harrison275e2602017-09-18 14:23:18 -040042ByteString CFXJSE_Arguments::GetUTF8String(int32_t index) const {
dsinclair08fea802016-07-12 10:37:52 -070043 v8::Local<v8::String> hString = (*m_pInfo)[index]->ToString();
44 v8::String::Utf8Value szStringVal(hString);
Ryan Harrison275e2602017-09-18 14:23:18 -040045 return ByteString(*szStringVal);
dsinclair08fea802016-07-12 10:37:52 -070046}
47
48CFXJSE_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
Tom Sepezd0409af2017-05-25 15:53:57 -070057CFXJSE_Value* CFXJSE_Arguments::GetReturnValue() const {
58 return m_pRetValue.Get();
dsinclair08fea802016-07-12 10:37:52 -070059}