Home | History | Annotate | Download | only in fxjs
      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 
     12 v8::Isolate* CFXJSE_Arguments::GetRuntime() const {
     13   return m_pRetValue->GetIsolate();
     14 }
     15 
     16 int32_t CFXJSE_Arguments::GetLength() const {
     17   return m_pInfo->Length();
     18 }
     19 
     20 std::unique_ptr<CFXJSE_Value> CFXJSE_Arguments::GetValue(int32_t index) const {
     21   std::unique_ptr<CFXJSE_Value> lpArgValue(
     22       new CFXJSE_Value(v8::Isolate::GetCurrent()));
     23   lpArgValue->ForceSetValue((*m_pInfo)[index]);
     24   return lpArgValue;
     25 }
     26 
     27 bool CFXJSE_Arguments::GetBoolean(int32_t index) const {
     28   return (*m_pInfo)[index]->BooleanValue();
     29 }
     30 
     31 int32_t CFXJSE_Arguments::GetInt32(int32_t index) const {
     32   return static_cast<int32_t>((*m_pInfo)[index]->NumberValue());
     33 }
     34 
     35 FX_FLOAT CFXJSE_Arguments::GetFloat(int32_t index) const {
     36   return static_cast<FX_FLOAT>((*m_pInfo)[index]->NumberValue());
     37 }
     38 
     39 CFX_ByteString CFXJSE_Arguments::GetUTF8String(int32_t index) const {
     40   v8::Local<v8::String> hString = (*m_pInfo)[index]->ToString();
     41   v8::String::Utf8Value szStringVal(hString);
     42   return CFX_ByteString(*szStringVal);
     43 }
     44 
     45 CFXJSE_HostObject* CFXJSE_Arguments::GetObject(int32_t index,
     46                                                CFXJSE_Class* pClass) const {
     47   v8::Local<v8::Value> hValue = (*m_pInfo)[index];
     48   ASSERT(!hValue.IsEmpty());
     49   if (!hValue->IsObject())
     50     return nullptr;
     51   return FXJSE_RetrieveObjectBinding(hValue.As<v8::Object>(), pClass);
     52 }
     53 
     54 CFXJSE_Value* CFXJSE_Arguments::GetReturnValue() {
     55   return m_pRetValue;
     56 }
     57