dsinclair | 08fea80 | 2016-07-12 10:37:52 -0700 | [diff] [blame] | 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 | |
dsinclair | 4355468 | 2016-09-29 17:29:48 -0700 | [diff] [blame] | 7 | #include "fxjs/cfxjse_arguments.h" |
dsinclair | 08fea80 | 2016-07-12 10:37:52 -0700 | [diff] [blame] | 8 | |
dsinclair | 4355468 | 2016-09-29 17:29:48 -0700 | [diff] [blame] | 9 | #include "fxjs/cfxjse_context.h" |
| 10 | #include "fxjs/cfxjse_value.h" |
Tom Sepez | 80547a1 | 2017-04-25 12:43:13 -0700 | [diff] [blame] | 11 | #include "third_party/base/ptr_util.h" |
dsinclair | 08fea80 | 2016-07-12 10:37:52 -0700 | [diff] [blame] | 12 | |
Tom Sepez | d0409af | 2017-05-25 15:53:57 -0700 | [diff] [blame] | 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 | |
dsinclair | 08fea80 | 2016-07-12 10:37:52 -0700 | [diff] [blame] | 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 { |
Tom Sepez | 80547a1 | 2017-04-25 12:43:13 -0700 | [diff] [blame] | 25 | auto pArgValue = pdfium::MakeUnique<CFXJSE_Value>(v8::Isolate::GetCurrent()); |
| 26 | pArgValue->ForceSetValue((*m_pInfo)[index]); |
| 27 | return pArgValue; |
dsinclair | 08fea80 | 2016-07-12 10:37:52 -0700 | [diff] [blame] | 28 | } |
| 29 | |
tsepez | 304bb91 | 2016-11-03 06:10:26 -0700 | [diff] [blame] | 30 | bool CFXJSE_Arguments::GetBoolean(int32_t index) const { |
dsinclair | 08fea80 | 2016-07-12 10:37:52 -0700 | [diff] [blame] | 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 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 38 | float CFXJSE_Arguments::GetFloat(int32_t index) const { |
| 39 | return static_cast<float>((*m_pInfo)[index]->NumberValue()); |
dsinclair | 08fea80 | 2016-07-12 10:37:52 -0700 | [diff] [blame] | 40 | } |
| 41 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 42 | ByteString CFXJSE_Arguments::GetUTF8String(int32_t index) const { |
dsinclair | 08fea80 | 2016-07-12 10:37:52 -0700 | [diff] [blame] | 43 | v8::Local<v8::String> hString = (*m_pInfo)[index]->ToString(); |
| 44 | v8::String::Utf8Value szStringVal(hString); |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 45 | return ByteString(*szStringVal); |
dsinclair | 08fea80 | 2016-07-12 10:37:52 -0700 | [diff] [blame] | 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 | |
Tom Sepez | d0409af | 2017-05-25 15:53:57 -0700 | [diff] [blame] | 57 | CFXJSE_Value* CFXJSE_Arguments::GetReturnValue() const { |
| 58 | return m_pRetValue.Get(); |
dsinclair | 08fea80 | 2016-07-12 10:37:52 -0700 | [diff] [blame] | 59 | } |