summaryrefslogtreecommitdiff
path: root/xfa/src/fxjse
diff options
context:
space:
mode:
Diffstat (limited to 'xfa/src/fxjse')
-rw-r--r--xfa/src/fxjse/src/class.cpp646
-rw-r--r--xfa/src/fxjse/src/class.h90
-rw-r--r--xfa/src/fxjse/src/context.cpp482
-rw-r--r--xfa/src/fxjse/src/context.h82
-rw-r--r--xfa/src/fxjse/src/dynprop.cpp882
-rw-r--r--xfa/src/fxjse/src/runtime.cpp224
-rw-r--r--xfa/src/fxjse/src/runtime.h88
-rw-r--r--xfa/src/fxjse/src/scope_inline.h210
-rw-r--r--xfa/src/fxjse/src/util_inline.h94
-rw-r--r--xfa/src/fxjse/src/value.cpp1088
-rw-r--r--xfa/src/fxjse/src/value.h476
11 files changed, 2181 insertions, 2181 deletions
diff --git a/xfa/src/fxjse/src/class.cpp b/xfa/src/fxjse/src/class.cpp
index 3b801a8a89..844241ab30 100644
--- a/xfa/src/fxjse/src/class.cpp
+++ b/xfa/src/fxjse/src/class.cpp
@@ -1,323 +1,323 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "xfa/src/foxitlib.h"
-#include "fxv8.h"
-#include "context.h"
-#include "class.h"
-#include "value.h"
-#include "scope_inline.h"
-#include "util_inline.h"
-static void FXJSE_V8ConstructorCallback_Wrapper(
- const v8::FunctionCallbackInfo<v8::Value>& info);
-static void FXJSE_V8FunctionCallback_Wrapper(
- const v8::FunctionCallbackInfo<v8::Value>& info);
-static void FXJSE_V8GetterCallback_Wrapper(
- v8::Local<v8::String> property,
- const v8::PropertyCallbackInfo<v8::Value>& info);
-static void FXJSE_V8SetterCallback_Wrapper(
- v8::Local<v8::String> property,
- v8::Local<v8::Value> value,
- const v8::PropertyCallbackInfo<void>& info);
-void FXJSE_DefineFunctions(FXJSE_HCONTEXT hContext,
- const FXJSE_FUNCTION* lpFunctions,
- int nNum) {
- CFXJSE_Context* lpContext = reinterpret_cast<CFXJSE_Context*>(hContext);
- ASSERT(lpContext);
- CFXJSE_ScopeUtil_IsolateHandleContext scope(lpContext);
- v8::Isolate* pIsolate = lpContext->GetRuntime();
- v8::Local<v8::Object> hGlobalObject =
- FXJSE_GetGlobalObjectFromContext(scope.GetLocalContext());
- for (int32_t i = 0; i < nNum; i++) {
- hGlobalObject->ForceSet(
- v8::String::NewFromUtf8(pIsolate, lpFunctions[i].name),
- v8::Function::New(
- pIsolate, FXJSE_V8FunctionCallback_Wrapper,
- v8::External::New(pIsolate,
- const_cast<FXJSE_FUNCTION*>(lpFunctions + i))),
- static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete));
- }
-}
-FXJSE_HCLASS FXJSE_DefineClass(FXJSE_HCONTEXT hContext,
- const FXJSE_CLASS* lpClass) {
- CFXJSE_Context* lpContext = reinterpret_cast<CFXJSE_Context*>(hContext);
- ASSERT(lpContext);
- return reinterpret_cast<FXJSE_HCLASS>(
- CFXJSE_Class::Create(lpContext, lpClass, FALSE));
-}
-FXJSE_HCLASS FXJSE_GetClass(FXJSE_HCONTEXT hContext,
- const CFX_ByteStringC& szName) {
- return reinterpret_cast<FXJSE_HCLASS>(CFXJSE_Class::GetClassFromContext(
- reinterpret_cast<CFXJSE_Context*>(hContext), szName));
-}
-static void FXJSE_V8FunctionCallback_Wrapper(
- const v8::FunctionCallbackInfo<v8::Value>& info) {
- const FXJSE_FUNCTION* lpFunctionInfo =
- static_cast<FXJSE_FUNCTION*>(info.Data().As<v8::External>()->Value());
- if (!lpFunctionInfo) {
- return;
- }
- CFX_ByteStringC szFunctionName(lpFunctionInfo->name);
- CFXJSE_Value* lpThisValue = CFXJSE_Value::Create(info.GetIsolate());
- lpThisValue->ForceSetValue(info.This());
- CFXJSE_Value* lpRetValue = CFXJSE_Value::Create(info.GetIsolate());
- CFXJSE_ArgumentsImpl impl = {&info, lpRetValue};
- lpFunctionInfo->callbackProc(reinterpret_cast<FXJSE_HOBJECT>(lpThisValue),
- szFunctionName,
- reinterpret_cast<CFXJSE_Arguments&>(impl));
- if (!lpRetValue->DirectGetValue().IsEmpty()) {
- info.GetReturnValue().Set(lpRetValue->DirectGetValue());
- }
- delete lpRetValue;
- lpRetValue = NULL;
- delete lpThisValue;
- lpThisValue = NULL;
-}
-static void FXJSE_V8ClassGlobalConstructorCallback_Wrapper(
- const v8::FunctionCallbackInfo<v8::Value>& info) {
- const FXJSE_CLASS* lpClassDefinition =
- static_cast<FXJSE_CLASS*>(info.Data().As<v8::External>()->Value());
- if (!lpClassDefinition) {
- return;
- }
- CFX_ByteStringC szFunctionName(lpClassDefinition->name);
- CFXJSE_Value* lpThisValue = CFXJSE_Value::Create(info.GetIsolate());
- lpThisValue->ForceSetValue(info.This());
- CFXJSE_Value* lpRetValue = CFXJSE_Value::Create(info.GetIsolate());
- CFXJSE_ArgumentsImpl impl = {&info, lpRetValue};
- lpClassDefinition->constructor(reinterpret_cast<FXJSE_HOBJECT>(lpThisValue),
- szFunctionName,
- reinterpret_cast<CFXJSE_Arguments&>(impl));
- if (!lpRetValue->DirectGetValue().IsEmpty()) {
- info.GetReturnValue().Set(lpRetValue->DirectGetValue());
- }
- delete lpRetValue;
- lpRetValue = NULL;
- delete lpThisValue;
- lpThisValue = NULL;
-}
-static void FXJSE_V8GetterCallback_Wrapper(
- v8::Local<v8::String> property,
- const v8::PropertyCallbackInfo<v8::Value>& info) {
- const FXJSE_PROPERTY* lpPropertyInfo =
- static_cast<FXJSE_PROPERTY*>(info.Data().As<v8::External>()->Value());
- if (!lpPropertyInfo) {
- return;
- }
- CFX_ByteStringC szPropertyName(lpPropertyInfo->name);
- CFXJSE_Value* lpThisValue = CFXJSE_Value::Create(info.GetIsolate());
- CFXJSE_Value* lpPropValue = CFXJSE_Value::Create(info.GetIsolate());
- lpThisValue->ForceSetValue(info.This());
- lpPropertyInfo->getProc(reinterpret_cast<FXJSE_HOBJECT>(lpThisValue),
- szPropertyName,
- reinterpret_cast<FXJSE_HVALUE>(lpPropValue));
- info.GetReturnValue().Set(lpPropValue->DirectGetValue());
- delete lpThisValue;
- lpThisValue = NULL;
- delete lpPropValue;
- lpPropValue = NULL;
-}
-static void FXJSE_V8SetterCallback_Wrapper(
- v8::Local<v8::String> property,
- v8::Local<v8::Value> value,
- const v8::PropertyCallbackInfo<void>& info) {
- const FXJSE_PROPERTY* lpPropertyInfo =
- static_cast<FXJSE_PROPERTY*>(info.Data().As<v8::External>()->Value());
- if (!lpPropertyInfo) {
- return;
- }
- CFX_ByteStringC szPropertyName(lpPropertyInfo->name);
- CFXJSE_Value* lpThisValue = CFXJSE_Value::Create(info.GetIsolate());
- CFXJSE_Value* lpPropValue = CFXJSE_Value::Create(info.GetIsolate());
- lpThisValue->ForceSetValue(info.This());
- lpPropValue->ForceSetValue(value);
- lpPropertyInfo->setProc(reinterpret_cast<FXJSE_HOBJECT>(lpThisValue),
- szPropertyName,
- reinterpret_cast<FXJSE_HVALUE>(lpPropValue));
- delete lpThisValue;
- lpThisValue = NULL;
- delete lpPropValue;
- lpPropValue = NULL;
-}
-static void FXJSE_V8ConstructorCallback_Wrapper(
- const v8::FunctionCallbackInfo<v8::Value>& info) {
- const FXJSE_CLASS* lpClassDefinition =
- static_cast<FXJSE_CLASS*>(info.Data().As<v8::External>()->Value());
- if (!lpClassDefinition) {
- return;
- }
- FXSYS_assert(info.This()->InternalFieldCount());
- info.This()->SetAlignedPointerInInternalField(0, NULL);
-}
-FXJSE_HRUNTIME CFXJSE_Arguments::GetRuntime() const {
- const CFXJSE_ArgumentsImpl* lpArguments =
- reinterpret_cast<const CFXJSE_ArgumentsImpl* const>(this);
- return reinterpret_cast<FXJSE_HRUNTIME>(
- lpArguments->m_pRetValue->GetIsolate());
-}
-int32_t CFXJSE_Arguments::GetLength() const {
- const CFXJSE_ArgumentsImpl* lpArguments =
- reinterpret_cast<const CFXJSE_ArgumentsImpl* const>(this);
- return lpArguments->m_pInfo->Length();
-}
-FXJSE_HVALUE CFXJSE_Arguments::GetValue(int32_t index) const {
- const CFXJSE_ArgumentsImpl* lpArguments =
- reinterpret_cast<const CFXJSE_ArgumentsImpl* const>(this);
- CFXJSE_Value* lpArgValue = CFXJSE_Value::Create(v8::Isolate::GetCurrent());
- ASSERT(lpArgValue);
- lpArgValue->ForceSetValue((*lpArguments->m_pInfo)[index]);
- return reinterpret_cast<FXJSE_HVALUE>(lpArgValue);
-}
-FX_BOOL CFXJSE_Arguments::GetBoolean(int32_t index) const {
- const CFXJSE_ArgumentsImpl* lpArguments =
- reinterpret_cast<const CFXJSE_ArgumentsImpl* const>(this);
- return (*lpArguments->m_pInfo)[index]->BooleanValue();
-}
-int32_t CFXJSE_Arguments::GetInt32(int32_t index) const {
- const CFXJSE_ArgumentsImpl* lpArguments =
- reinterpret_cast<const CFXJSE_ArgumentsImpl* const>(this);
- return static_cast<int32_t>((*lpArguments->m_pInfo)[index]->NumberValue());
-}
-FX_FLOAT CFXJSE_Arguments::GetFloat(int32_t index) const {
- const CFXJSE_ArgumentsImpl* lpArguments =
- reinterpret_cast<const CFXJSE_ArgumentsImpl* const>(this);
- return static_cast<FX_FLOAT>((*lpArguments->m_pInfo)[index]->NumberValue());
-}
-CFX_ByteString CFXJSE_Arguments::GetUTF8String(int32_t index) const {
- const CFXJSE_ArgumentsImpl* lpArguments =
- reinterpret_cast<const CFXJSE_ArgumentsImpl* const>(this);
- v8::Local<v8::String> hString = (*lpArguments->m_pInfo)[index]->ToString();
- v8::String::Utf8Value szStringVal(hString);
- return CFX_ByteString(*szStringVal);
-}
-void* CFXJSE_Arguments::GetObject(int32_t index, FXJSE_HCLASS hClass) const {
- const CFXJSE_ArgumentsImpl* lpArguments =
- reinterpret_cast<const CFXJSE_ArgumentsImpl* const>(this);
- v8::Local<v8::Value> hValue = (*lpArguments->m_pInfo)[index];
- ASSERT(!hValue.IsEmpty());
- if (!hValue->IsObject()) {
- return NULL;
- }
- CFXJSE_Class* lpClass = reinterpret_cast<CFXJSE_Class*>(hClass);
- return FXJSE_RetrieveObjectBinding(hValue.As<v8::Object>(), lpClass);
-}
-FXJSE_HVALUE CFXJSE_Arguments::GetReturnValue() {
- const CFXJSE_ArgumentsImpl* lpArguments =
- reinterpret_cast<const CFXJSE_ArgumentsImpl* const>(this);
- return reinterpret_cast<FXJSE_HVALUE>(lpArguments->m_pRetValue);
-}
-static void FXJSE_Context_GlobalObjToString(
- const v8::FunctionCallbackInfo<v8::Value>& info) {
- const FXJSE_CLASS* lpClass =
- static_cast<FXJSE_CLASS*>(info.Data().As<v8::External>()->Value());
- if (!lpClass) {
- return;
- }
- if (info.This() == info.Holder() && lpClass->name) {
- CFX_ByteString szStringVal;
- szStringVal.Format("[object %s]", lpClass->name);
- info.GetReturnValue().Set(v8::String::NewFromUtf8(
- info.GetIsolate(), (const FX_CHAR*)szStringVal,
- v8::String::kNormalString, szStringVal.GetLength()));
- } else {
- info.GetReturnValue().Set(info.This()->ObjectProtoToString());
- }
-}
-CFXJSE_Class* CFXJSE_Class::Create(CFXJSE_Context* lpContext,
- const FXJSE_CLASS* lpClassDefinition,
- FX_BOOL bIsJSGlobal) {
- if (!lpContext || !lpClassDefinition) {
- return NULL;
- }
- CFXJSE_Class* pClass =
- GetClassFromContext(lpContext, lpClassDefinition->name);
- if (pClass) {
- return pClass;
- }
- v8::Isolate* pIsolate = lpContext->m_pIsolate;
- pClass = new CFXJSE_Class(lpContext);
- pClass->m_szClassName = lpClassDefinition->name;
- pClass->m_lpClassDefinition = lpClassDefinition;
- CFXJSE_ScopeUtil_IsolateHandleRootContext scope(pIsolate);
- v8::Local<v8::FunctionTemplate> hFunctionTemplate = v8::FunctionTemplate::New(
- pIsolate, bIsJSGlobal ? 0 : FXJSE_V8ConstructorCallback_Wrapper,
- v8::External::New(pIsolate, const_cast<FXJSE_CLASS*>(lpClassDefinition)));
- hFunctionTemplate->SetClassName(
- v8::String::NewFromUtf8(pIsolate, lpClassDefinition->name));
- hFunctionTemplate->InstanceTemplate()->SetInternalFieldCount(1);
- v8::Local<v8::ObjectTemplate> hObjectTemplate =
- hFunctionTemplate->InstanceTemplate();
- SetUpNamedPropHandler(pIsolate, hObjectTemplate, lpClassDefinition);
-
- if (lpClassDefinition->propNum) {
- for (int32_t i = 0; i < lpClassDefinition->propNum; i++) {
- hObjectTemplate->SetNativeDataProperty(
- v8::String::NewFromUtf8(pIsolate,
- lpClassDefinition->properties[i].name),
- lpClassDefinition->properties[i].getProc
- ? FXJSE_V8GetterCallback_Wrapper
- : NULL,
- lpClassDefinition->properties[i].setProc
- ? FXJSE_V8SetterCallback_Wrapper
- : NULL,
- v8::External::New(pIsolate, const_cast<FXJSE_PROPERTY*>(
- lpClassDefinition->properties + i)),
- static_cast<v8::PropertyAttribute>(v8::DontDelete));
- }
- }
- if (lpClassDefinition->methNum) {
- for (int32_t i = 0; i < lpClassDefinition->methNum; i++) {
- hObjectTemplate->Set(
- v8::String::NewFromUtf8(pIsolate, lpClassDefinition->methods[i].name),
- v8::FunctionTemplate::New(
- pIsolate, FXJSE_V8FunctionCallback_Wrapper,
- v8::External::New(pIsolate, const_cast<FXJSE_FUNCTION*>(
- lpClassDefinition->methods + i))),
- static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete));
- }
- }
- if (lpClassDefinition->constructor) {
- if (bIsJSGlobal) {
- hObjectTemplate->Set(
- v8::String::NewFromUtf8(pIsolate, lpClassDefinition->name),
- v8::FunctionTemplate::New(
- pIsolate, FXJSE_V8ClassGlobalConstructorCallback_Wrapper,
- v8::External::New(pIsolate,
- const_cast<FXJSE_CLASS*>(lpClassDefinition))),
- static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete));
- } else {
- v8::Local<v8::Context> hLocalContext =
- v8::Local<v8::Context>::New(pIsolate, lpContext->m_hContext);
- FXJSE_GetGlobalObjectFromContext(hLocalContext)
- ->Set(v8::String::NewFromUtf8(pIsolate, lpClassDefinition->name),
- v8::Function::New(
- pIsolate, FXJSE_V8ClassGlobalConstructorCallback_Wrapper,
- v8::External::New(pIsolate, const_cast<FXJSE_CLASS*>(
- lpClassDefinition))));
- }
- }
- if (bIsJSGlobal) {
- hObjectTemplate->Set(
- v8::String::NewFromUtf8(pIsolate, "toString"),
- v8::FunctionTemplate::New(
- pIsolate, FXJSE_Context_GlobalObjToString,
- v8::External::New(pIsolate,
- const_cast<FXJSE_CLASS*>(lpClassDefinition))));
- }
- pClass->m_hTemplate.Reset(lpContext->m_pIsolate, hFunctionTemplate);
- lpContext->m_rgClasses.Add(pClass);
- return pClass;
-}
-CFXJSE_Class* CFXJSE_Class::GetClassFromContext(CFXJSE_Context* pContext,
- const CFX_ByteStringC& szName) {
- for (int count = pContext->m_rgClasses.GetSize(), i = 0; i < count; i++) {
- CFXJSE_Class* pClass = pContext->m_rgClasses[i];
- if (pClass->m_szClassName == szName) {
- return pClass;
- }
- }
- return NULL;
-}
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "xfa/src/foxitlib.h"
+#include "fxv8.h"
+#include "context.h"
+#include "class.h"
+#include "value.h"
+#include "scope_inline.h"
+#include "util_inline.h"
+static void FXJSE_V8ConstructorCallback_Wrapper(
+ const v8::FunctionCallbackInfo<v8::Value>& info);
+static void FXJSE_V8FunctionCallback_Wrapper(
+ const v8::FunctionCallbackInfo<v8::Value>& info);
+static void FXJSE_V8GetterCallback_Wrapper(
+ v8::Local<v8::String> property,
+ const v8::PropertyCallbackInfo<v8::Value>& info);
+static void FXJSE_V8SetterCallback_Wrapper(
+ v8::Local<v8::String> property,
+ v8::Local<v8::Value> value,
+ const v8::PropertyCallbackInfo<void>& info);
+void FXJSE_DefineFunctions(FXJSE_HCONTEXT hContext,
+ const FXJSE_FUNCTION* lpFunctions,
+ int nNum) {
+ CFXJSE_Context* lpContext = reinterpret_cast<CFXJSE_Context*>(hContext);
+ ASSERT(lpContext);
+ CFXJSE_ScopeUtil_IsolateHandleContext scope(lpContext);
+ v8::Isolate* pIsolate = lpContext->GetRuntime();
+ v8::Local<v8::Object> hGlobalObject =
+ FXJSE_GetGlobalObjectFromContext(scope.GetLocalContext());
+ for (int32_t i = 0; i < nNum; i++) {
+ hGlobalObject->ForceSet(
+ v8::String::NewFromUtf8(pIsolate, lpFunctions[i].name),
+ v8::Function::New(
+ pIsolate, FXJSE_V8FunctionCallback_Wrapper,
+ v8::External::New(pIsolate,
+ const_cast<FXJSE_FUNCTION*>(lpFunctions + i))),
+ static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete));
+ }
+}
+FXJSE_HCLASS FXJSE_DefineClass(FXJSE_HCONTEXT hContext,
+ const FXJSE_CLASS* lpClass) {
+ CFXJSE_Context* lpContext = reinterpret_cast<CFXJSE_Context*>(hContext);
+ ASSERT(lpContext);
+ return reinterpret_cast<FXJSE_HCLASS>(
+ CFXJSE_Class::Create(lpContext, lpClass, FALSE));
+}
+FXJSE_HCLASS FXJSE_GetClass(FXJSE_HCONTEXT hContext,
+ const CFX_ByteStringC& szName) {
+ return reinterpret_cast<FXJSE_HCLASS>(CFXJSE_Class::GetClassFromContext(
+ reinterpret_cast<CFXJSE_Context*>(hContext), szName));
+}
+static void FXJSE_V8FunctionCallback_Wrapper(
+ const v8::FunctionCallbackInfo<v8::Value>& info) {
+ const FXJSE_FUNCTION* lpFunctionInfo =
+ static_cast<FXJSE_FUNCTION*>(info.Data().As<v8::External>()->Value());
+ if (!lpFunctionInfo) {
+ return;
+ }
+ CFX_ByteStringC szFunctionName(lpFunctionInfo->name);
+ CFXJSE_Value* lpThisValue = CFXJSE_Value::Create(info.GetIsolate());
+ lpThisValue->ForceSetValue(info.This());
+ CFXJSE_Value* lpRetValue = CFXJSE_Value::Create(info.GetIsolate());
+ CFXJSE_ArgumentsImpl impl = {&info, lpRetValue};
+ lpFunctionInfo->callbackProc(reinterpret_cast<FXJSE_HOBJECT>(lpThisValue),
+ szFunctionName,
+ reinterpret_cast<CFXJSE_Arguments&>(impl));
+ if (!lpRetValue->DirectGetValue().IsEmpty()) {
+ info.GetReturnValue().Set(lpRetValue->DirectGetValue());
+ }
+ delete lpRetValue;
+ lpRetValue = NULL;
+ delete lpThisValue;
+ lpThisValue = NULL;
+}
+static void FXJSE_V8ClassGlobalConstructorCallback_Wrapper(
+ const v8::FunctionCallbackInfo<v8::Value>& info) {
+ const FXJSE_CLASS* lpClassDefinition =
+ static_cast<FXJSE_CLASS*>(info.Data().As<v8::External>()->Value());
+ if (!lpClassDefinition) {
+ return;
+ }
+ CFX_ByteStringC szFunctionName(lpClassDefinition->name);
+ CFXJSE_Value* lpThisValue = CFXJSE_Value::Create(info.GetIsolate());
+ lpThisValue->ForceSetValue(info.This());
+ CFXJSE_Value* lpRetValue = CFXJSE_Value::Create(info.GetIsolate());
+ CFXJSE_ArgumentsImpl impl = {&info, lpRetValue};
+ lpClassDefinition->constructor(reinterpret_cast<FXJSE_HOBJECT>(lpThisValue),
+ szFunctionName,
+ reinterpret_cast<CFXJSE_Arguments&>(impl));
+ if (!lpRetValue->DirectGetValue().IsEmpty()) {
+ info.GetReturnValue().Set(lpRetValue->DirectGetValue());
+ }
+ delete lpRetValue;
+ lpRetValue = NULL;
+ delete lpThisValue;
+ lpThisValue = NULL;
+}
+static void FXJSE_V8GetterCallback_Wrapper(
+ v8::Local<v8::String> property,
+ const v8::PropertyCallbackInfo<v8::Value>& info) {
+ const FXJSE_PROPERTY* lpPropertyInfo =
+ static_cast<FXJSE_PROPERTY*>(info.Data().As<v8::External>()->Value());
+ if (!lpPropertyInfo) {
+ return;
+ }
+ CFX_ByteStringC szPropertyName(lpPropertyInfo->name);
+ CFXJSE_Value* lpThisValue = CFXJSE_Value::Create(info.GetIsolate());
+ CFXJSE_Value* lpPropValue = CFXJSE_Value::Create(info.GetIsolate());
+ lpThisValue->ForceSetValue(info.This());
+ lpPropertyInfo->getProc(reinterpret_cast<FXJSE_HOBJECT>(lpThisValue),
+ szPropertyName,
+ reinterpret_cast<FXJSE_HVALUE>(lpPropValue));
+ info.GetReturnValue().Set(lpPropValue->DirectGetValue());
+ delete lpThisValue;
+ lpThisValue = NULL;
+ delete lpPropValue;
+ lpPropValue = NULL;
+}
+static void FXJSE_V8SetterCallback_Wrapper(
+ v8::Local<v8::String> property,
+ v8::Local<v8::Value> value,
+ const v8::PropertyCallbackInfo<void>& info) {
+ const FXJSE_PROPERTY* lpPropertyInfo =
+ static_cast<FXJSE_PROPERTY*>(info.Data().As<v8::External>()->Value());
+ if (!lpPropertyInfo) {
+ return;
+ }
+ CFX_ByteStringC szPropertyName(lpPropertyInfo->name);
+ CFXJSE_Value* lpThisValue = CFXJSE_Value::Create(info.GetIsolate());
+ CFXJSE_Value* lpPropValue = CFXJSE_Value::Create(info.GetIsolate());
+ lpThisValue->ForceSetValue(info.This());
+ lpPropValue->ForceSetValue(value);
+ lpPropertyInfo->setProc(reinterpret_cast<FXJSE_HOBJECT>(lpThisValue),
+ szPropertyName,
+ reinterpret_cast<FXJSE_HVALUE>(lpPropValue));
+ delete lpThisValue;
+ lpThisValue = NULL;
+ delete lpPropValue;
+ lpPropValue = NULL;
+}
+static void FXJSE_V8ConstructorCallback_Wrapper(
+ const v8::FunctionCallbackInfo<v8::Value>& info) {
+ const FXJSE_CLASS* lpClassDefinition =
+ static_cast<FXJSE_CLASS*>(info.Data().As<v8::External>()->Value());
+ if (!lpClassDefinition) {
+ return;
+ }
+ FXSYS_assert(info.This()->InternalFieldCount());
+ info.This()->SetAlignedPointerInInternalField(0, NULL);
+}
+FXJSE_HRUNTIME CFXJSE_Arguments::GetRuntime() const {
+ const CFXJSE_ArgumentsImpl* lpArguments =
+ reinterpret_cast<const CFXJSE_ArgumentsImpl* const>(this);
+ return reinterpret_cast<FXJSE_HRUNTIME>(
+ lpArguments->m_pRetValue->GetIsolate());
+}
+int32_t CFXJSE_Arguments::GetLength() const {
+ const CFXJSE_ArgumentsImpl* lpArguments =
+ reinterpret_cast<const CFXJSE_ArgumentsImpl* const>(this);
+ return lpArguments->m_pInfo->Length();
+}
+FXJSE_HVALUE CFXJSE_Arguments::GetValue(int32_t index) const {
+ const CFXJSE_ArgumentsImpl* lpArguments =
+ reinterpret_cast<const CFXJSE_ArgumentsImpl* const>(this);
+ CFXJSE_Value* lpArgValue = CFXJSE_Value::Create(v8::Isolate::GetCurrent());
+ ASSERT(lpArgValue);
+ lpArgValue->ForceSetValue((*lpArguments->m_pInfo)[index]);
+ return reinterpret_cast<FXJSE_HVALUE>(lpArgValue);
+}
+FX_BOOL CFXJSE_Arguments::GetBoolean(int32_t index) const {
+ const CFXJSE_ArgumentsImpl* lpArguments =
+ reinterpret_cast<const CFXJSE_ArgumentsImpl* const>(this);
+ return (*lpArguments->m_pInfo)[index]->BooleanValue();
+}
+int32_t CFXJSE_Arguments::GetInt32(int32_t index) const {
+ const CFXJSE_ArgumentsImpl* lpArguments =
+ reinterpret_cast<const CFXJSE_ArgumentsImpl* const>(this);
+ return static_cast<int32_t>((*lpArguments->m_pInfo)[index]->NumberValue());
+}
+FX_FLOAT CFXJSE_Arguments::GetFloat(int32_t index) const {
+ const CFXJSE_ArgumentsImpl* lpArguments =
+ reinterpret_cast<const CFXJSE_ArgumentsImpl* const>(this);
+ return static_cast<FX_FLOAT>((*lpArguments->m_pInfo)[index]->NumberValue());
+}
+CFX_ByteString CFXJSE_Arguments::GetUTF8String(int32_t index) const {
+ const CFXJSE_ArgumentsImpl* lpArguments =
+ reinterpret_cast<const CFXJSE_ArgumentsImpl* const>(this);
+ v8::Local<v8::String> hString = (*lpArguments->m_pInfo)[index]->ToString();
+ v8::String::Utf8Value szStringVal(hString);
+ return CFX_ByteString(*szStringVal);
+}
+void* CFXJSE_Arguments::GetObject(int32_t index, FXJSE_HCLASS hClass) const {
+ const CFXJSE_ArgumentsImpl* lpArguments =
+ reinterpret_cast<const CFXJSE_ArgumentsImpl* const>(this);
+ v8::Local<v8::Value> hValue = (*lpArguments->m_pInfo)[index];
+ ASSERT(!hValue.IsEmpty());
+ if (!hValue->IsObject()) {
+ return NULL;
+ }
+ CFXJSE_Class* lpClass = reinterpret_cast<CFXJSE_Class*>(hClass);
+ return FXJSE_RetrieveObjectBinding(hValue.As<v8::Object>(), lpClass);
+}
+FXJSE_HVALUE CFXJSE_Arguments::GetReturnValue() {
+ const CFXJSE_ArgumentsImpl* lpArguments =
+ reinterpret_cast<const CFXJSE_ArgumentsImpl* const>(this);
+ return reinterpret_cast<FXJSE_HVALUE>(lpArguments->m_pRetValue);
+}
+static void FXJSE_Context_GlobalObjToString(
+ const v8::FunctionCallbackInfo<v8::Value>& info) {
+ const FXJSE_CLASS* lpClass =
+ static_cast<FXJSE_CLASS*>(info.Data().As<v8::External>()->Value());
+ if (!lpClass) {
+ return;
+ }
+ if (info.This() == info.Holder() && lpClass->name) {
+ CFX_ByteString szStringVal;
+ szStringVal.Format("[object %s]", lpClass->name);
+ info.GetReturnValue().Set(v8::String::NewFromUtf8(
+ info.GetIsolate(), (const FX_CHAR*)szStringVal,
+ v8::String::kNormalString, szStringVal.GetLength()));
+ } else {
+ info.GetReturnValue().Set(info.This()->ObjectProtoToString());
+ }
+}
+CFXJSE_Class* CFXJSE_Class::Create(CFXJSE_Context* lpContext,
+ const FXJSE_CLASS* lpClassDefinition,
+ FX_BOOL bIsJSGlobal) {
+ if (!lpContext || !lpClassDefinition) {
+ return NULL;
+ }
+ CFXJSE_Class* pClass =
+ GetClassFromContext(lpContext, lpClassDefinition->name);
+ if (pClass) {
+ return pClass;
+ }
+ v8::Isolate* pIsolate = lpContext->m_pIsolate;
+ pClass = new CFXJSE_Class(lpContext);
+ pClass->m_szClassName = lpClassDefinition->name;
+ pClass->m_lpClassDefinition = lpClassDefinition;
+ CFXJSE_ScopeUtil_IsolateHandleRootContext scope(pIsolate);
+ v8::Local<v8::FunctionTemplate> hFunctionTemplate = v8::FunctionTemplate::New(
+ pIsolate, bIsJSGlobal ? 0 : FXJSE_V8ConstructorCallback_Wrapper,
+ v8::External::New(pIsolate, const_cast<FXJSE_CLASS*>(lpClassDefinition)));
+ hFunctionTemplate->SetClassName(
+ v8::String::NewFromUtf8(pIsolate, lpClassDefinition->name));
+ hFunctionTemplate->InstanceTemplate()->SetInternalFieldCount(1);
+ v8::Local<v8::ObjectTemplate> hObjectTemplate =
+ hFunctionTemplate->InstanceTemplate();
+ SetUpNamedPropHandler(pIsolate, hObjectTemplate, lpClassDefinition);
+
+ if (lpClassDefinition->propNum) {
+ for (int32_t i = 0; i < lpClassDefinition->propNum; i++) {
+ hObjectTemplate->SetNativeDataProperty(
+ v8::String::NewFromUtf8(pIsolate,
+ lpClassDefinition->properties[i].name),
+ lpClassDefinition->properties[i].getProc
+ ? FXJSE_V8GetterCallback_Wrapper
+ : NULL,
+ lpClassDefinition->properties[i].setProc
+ ? FXJSE_V8SetterCallback_Wrapper
+ : NULL,
+ v8::External::New(pIsolate, const_cast<FXJSE_PROPERTY*>(
+ lpClassDefinition->properties + i)),
+ static_cast<v8::PropertyAttribute>(v8::DontDelete));
+ }
+ }
+ if (lpClassDefinition->methNum) {
+ for (int32_t i = 0; i < lpClassDefinition->methNum; i++) {
+ hObjectTemplate->Set(
+ v8::String::NewFromUtf8(pIsolate, lpClassDefinition->methods[i].name),
+ v8::FunctionTemplate::New(
+ pIsolate, FXJSE_V8FunctionCallback_Wrapper,
+ v8::External::New(pIsolate, const_cast<FXJSE_FUNCTION*>(
+ lpClassDefinition->methods + i))),
+ static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete));
+ }
+ }
+ if (lpClassDefinition->constructor) {
+ if (bIsJSGlobal) {
+ hObjectTemplate->Set(
+ v8::String::NewFromUtf8(pIsolate, lpClassDefinition->name),
+ v8::FunctionTemplate::New(
+ pIsolate, FXJSE_V8ClassGlobalConstructorCallback_Wrapper,
+ v8::External::New(pIsolate,
+ const_cast<FXJSE_CLASS*>(lpClassDefinition))),
+ static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete));
+ } else {
+ v8::Local<v8::Context> hLocalContext =
+ v8::Local<v8::Context>::New(pIsolate, lpContext->m_hContext);
+ FXJSE_GetGlobalObjectFromContext(hLocalContext)
+ ->Set(v8::String::NewFromUtf8(pIsolate, lpClassDefinition->name),
+ v8::Function::New(
+ pIsolate, FXJSE_V8ClassGlobalConstructorCallback_Wrapper,
+ v8::External::New(pIsolate, const_cast<FXJSE_CLASS*>(
+ lpClassDefinition))));
+ }
+ }
+ if (bIsJSGlobal) {
+ hObjectTemplate->Set(
+ v8::String::NewFromUtf8(pIsolate, "toString"),
+ v8::FunctionTemplate::New(
+ pIsolate, FXJSE_Context_GlobalObjToString,
+ v8::External::New(pIsolate,
+ const_cast<FXJSE_CLASS*>(lpClassDefinition))));
+ }
+ pClass->m_hTemplate.Reset(lpContext->m_pIsolate, hFunctionTemplate);
+ lpContext->m_rgClasses.Add(pClass);
+ return pClass;
+}
+CFXJSE_Class* CFXJSE_Class::GetClassFromContext(CFXJSE_Context* pContext,
+ const CFX_ByteStringC& szName) {
+ for (int count = pContext->m_rgClasses.GetSize(), i = 0; i < count; i++) {
+ CFXJSE_Class* pClass = pContext->m_rgClasses[i];
+ if (pClass->m_szClassName == szName) {
+ return pClass;
+ }
+ }
+ return NULL;
+}
diff --git a/xfa/src/fxjse/src/class.h b/xfa/src/fxjse/src/class.h
index 90cabe6542..d1c8852a74 100644
--- a/xfa/src/fxjse/src/class.h
+++ b/xfa/src/fxjse/src/class.h
@@ -1,46 +1,46 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#ifndef FXJSE_CLASS_H_
-#define FXJSE_CLASS_H_
-class CFXJSE_Context;
-class CFXJSE_Value;
-class CFXJSE_Class {
- protected:
- CFXJSE_Class(CFXJSE_Context* lpContext)
- : m_lpClassDefinition(nullptr), m_pContext(lpContext) {}
-
- public:
- inline CFXJSE_Context* GetContext() { return m_pContext; }
- inline v8::Global<v8::FunctionTemplate>& GetTemplate() { return m_hTemplate; }
-
- public:
- static CFXJSE_Class* Create(CFXJSE_Context* pContext,
- const FXJSE_CLASS* lpClassDefintion,
- FX_BOOL bIsJSGlobal = FALSE);
- static CFXJSE_Class* GetClassFromContext(CFXJSE_Context* pContext,
- const CFX_ByteStringC& szName);
- static void SetUpDynPropHandler(CFXJSE_Context* pContext,
- CFXJSE_Value* pValue,
- const FXJSE_CLASS* lpClassDefinition);
- static void SetUpNamedPropHandler(
- v8::Isolate* pIsolate,
- v8::Local<v8::ObjectTemplate>& hObjectTemplate,
- const FXJSE_CLASS* lpClassDefinition);
-
- protected:
- CFX_ByteString m_szClassName;
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef FXJSE_CLASS_H_
+#define FXJSE_CLASS_H_
+class CFXJSE_Context;
+class CFXJSE_Value;
+class CFXJSE_Class {
+ protected:
+ CFXJSE_Class(CFXJSE_Context* lpContext)
+ : m_lpClassDefinition(nullptr), m_pContext(lpContext) {}
+
+ public:
+ inline CFXJSE_Context* GetContext() { return m_pContext; }
+ inline v8::Global<v8::FunctionTemplate>& GetTemplate() { return m_hTemplate; }
+
+ public:
+ static CFXJSE_Class* Create(CFXJSE_Context* pContext,
+ const FXJSE_CLASS* lpClassDefintion,
+ FX_BOOL bIsJSGlobal = FALSE);
+ static CFXJSE_Class* GetClassFromContext(CFXJSE_Context* pContext,
+ const CFX_ByteStringC& szName);
+ static void SetUpDynPropHandler(CFXJSE_Context* pContext,
+ CFXJSE_Value* pValue,
+ const FXJSE_CLASS* lpClassDefinition);
+ static void SetUpNamedPropHandler(
+ v8::Isolate* pIsolate,
+ v8::Local<v8::ObjectTemplate>& hObjectTemplate,
+ const FXJSE_CLASS* lpClassDefinition);
+
+ protected:
+ CFX_ByteString m_szClassName;
const FXJSE_CLASS* m_lpClassDefinition;
- CFXJSE_Context* m_pContext;
- v8::Global<v8::FunctionTemplate> m_hTemplate;
- friend class CFXJSE_Context;
- friend class CFXJSE_Value;
-};
-struct CFXJSE_ArgumentsImpl {
- const v8::FunctionCallbackInfo<v8::Value>* m_pInfo;
- CFXJSE_Value* m_pRetValue;
-};
-#endif
+ CFXJSE_Context* m_pContext;
+ v8::Global<v8::FunctionTemplate> m_hTemplate;
+ friend class CFXJSE_Context;
+ friend class CFXJSE_Value;
+};
+struct CFXJSE_ArgumentsImpl {
+ const v8::FunctionCallbackInfo<v8::Value>* m_pInfo;
+ CFXJSE_Value* m_pRetValue;
+};
+#endif
diff --git a/xfa/src/fxjse/src/context.cpp b/xfa/src/fxjse/src/context.cpp
index e3f5b93e3c..7e214d5b89 100644
--- a/xfa/src/fxjse/src/context.cpp
+++ b/xfa/src/fxjse/src/context.cpp
@@ -1,241 +1,241 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "xfa/src/foxitlib.h"
-#include "fxv8.h"
-#include "context.h"
-#include "class.h"
-#include "value.h"
-#include "scope_inline.h"
-#include "util_inline.h"
-FXJSE_HCONTEXT FXJSE_Context_Create(FXJSE_HRUNTIME hRuntime,
- const FXJSE_CLASS* lpGlobalClass,
- void* lpGlobalObject) {
- CFXJSE_Context* pContext = CFXJSE_Context::Create(
- reinterpret_cast<v8::Isolate*>(hRuntime), lpGlobalClass, lpGlobalObject);
- return reinterpret_cast<FXJSE_HCONTEXT>(pContext);
-}
-void FXJSE_Context_Release(FXJSE_HCONTEXT hContext) {
- CFXJSE_Context* pContext = reinterpret_cast<CFXJSE_Context*>(hContext);
- if (pContext) {
- delete pContext;
- }
-}
-FXJSE_HVALUE FXJSE_Context_GetGlobalObject(FXJSE_HCONTEXT hContext) {
- CFXJSE_Context* pContext = reinterpret_cast<CFXJSE_Context*>(hContext);
- if (!pContext) {
- return NULL;
- }
- CFXJSE_Value* lpValue = CFXJSE_Value::Create(pContext->GetRuntime());
- ASSERT(lpValue);
- pContext->GetGlobalObject(lpValue);
- return reinterpret_cast<FXJSE_HVALUE>(lpValue);
-}
-FXJSE_HRUNTIME FXJSE_Context_GetRuntime(FXJSE_HCONTEXT hContext) {
- CFXJSE_Context* pContext = reinterpret_cast<CFXJSE_Context*>(hContext);
- return pContext ? reinterpret_cast<FXJSE_HRUNTIME>(pContext->GetRuntime())
- : NULL;
-}
-static const FX_CHAR* szCompatibleModeScripts[] = {
- "(function (global, list) { 'use strict'; var objname; for (objname in list) { var globalobj = global[objname];\n\
- if (globalobj) { list[objname].forEach( function (name) { if (!globalobj[name]) { Object.defineProperty(globalobj, name, {writable: true, enumerable: false, value: \n\
- (function (obj) {\n\
- if (arguments.length === 0) {\n\
- throw new TypeError('missing argument 0 when calling function ' + objname + '.' + name);\n\
- }\n\
- return globalobj.prototype[name].apply(obj, Array.prototype.slice.call(arguments, 1));\n\
-})});}});}}}(this, {String: ['substr', 'toUpperCase']}));",
-};
-void FXJSE_Context_EnableCompatibleMode(FXJSE_HCONTEXT hContext,
- FX_DWORD dwCompatibleFlags) {
- for (uint32_t i = 0; i < (uint32_t)FXJSE_COMPATIBLEMODEFLAGCOUNT; i++) {
- if (dwCompatibleFlags & (1 << i)) {
- FXJSE_ExecuteScript(hContext, szCompatibleModeScripts[i], NULL, NULL);
- }
- }
-}
-FX_BOOL FXJSE_ExecuteScript(FXJSE_HCONTEXT hContext,
- const FX_CHAR* szScript,
- FXJSE_HVALUE hRetValue,
- FXJSE_HVALUE hNewThisObject) {
- CFXJSE_Context* pContext = reinterpret_cast<CFXJSE_Context*>(hContext);
- ASSERT(pContext);
- return pContext->ExecuteScript(
- szScript, reinterpret_cast<CFXJSE_Value*>(hRetValue),
- reinterpret_cast<CFXJSE_Value*>(hNewThisObject));
-}
-v8::Local<v8::Object> FXJSE_CreateReturnValue(v8::Isolate* pIsolate,
- v8::TryCatch& trycatch) {
- v8::Local<v8::Object> hReturnValue = v8::Object::New(pIsolate);
- if (trycatch.HasCaught()) {
- v8::Local<v8::Value> hException = trycatch.Exception();
- v8::Local<v8::Message> hMessage = trycatch.Message();
- if (hException->IsObject()) {
- v8::Local<v8::Value> hValue;
- hValue = hException.As<v8::Object>()->Get(
- v8::String::NewFromUtf8(pIsolate, "name"));
- if (hValue->IsString() || hValue->IsStringObject()) {
- hReturnValue->Set(0, hValue);
- } else {
- hReturnValue->Set(0, v8::String::NewFromUtf8(pIsolate, "Error"));
- }
- hValue = hException.As<v8::Object>()->Get(
- v8::String::NewFromUtf8(pIsolate, "message"));
- if (hValue->IsString() || hValue->IsStringObject()) {
- hReturnValue->Set(1, hValue);
- } else {
- hReturnValue->Set(1, hMessage->Get());
- }
- } else {
- hReturnValue->Set(0, v8::String::NewFromUtf8(pIsolate, "Error"));
- hReturnValue->Set(1, hMessage->Get());
- }
- hReturnValue->Set(2, hException);
- hReturnValue->Set(3, v8::Integer::New(pIsolate, hMessage->GetLineNumber()));
- hReturnValue->Set(4, hMessage->GetSourceLine());
- hReturnValue->Set(5,
- v8::Integer::New(pIsolate, hMessage->GetStartColumn()));
- hReturnValue->Set(6, v8::Integer::New(pIsolate, hMessage->GetEndColumn()));
- }
- return hReturnValue;
-}
-FX_BOOL FXJSE_ReturnValue_GetMessage(FXJSE_HVALUE hRetValue,
- CFX_ByteString& utf8Name,
- CFX_ByteString& utf8Message) {
- CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hRetValue);
- if (!lpValue) {
- return FALSE;
- }
- v8::Isolate* pIsolate = lpValue->GetIsolate();
- CFXJSE_ScopeUtil_IsolateHandleRootContext scope(pIsolate);
- v8::Local<v8::Value> hValue =
- v8::Local<v8::Value>::New(pIsolate, lpValue->DirectGetValue());
- if (!hValue->IsObject()) {
- return FALSE;
- }
- v8::String::Utf8Value hStringVal0(
- hValue.As<v8::Object>()->Get(0)->ToString());
- utf8Name = *hStringVal0;
- v8::String::Utf8Value hStringVal1(
- hValue.As<v8::Object>()->Get(1)->ToString());
- utf8Message = *hStringVal1;
- return TRUE;
-}
-FX_BOOL FXJSE_ReturnValue_GetLineInfo(FXJSE_HVALUE hRetValue,
- int32_t& nLine,
- int32_t& nCol) {
- CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hRetValue);
- if (!lpValue) {
- return FALSE;
- }
- v8::Isolate* pIsolate = lpValue->GetIsolate();
- CFXJSE_ScopeUtil_IsolateHandleRootContext scope(pIsolate);
- v8::Local<v8::Value> hValue =
- v8::Local<v8::Value>::New(pIsolate, lpValue->DirectGetValue());
- if (!hValue->IsObject()) {
- return FALSE;
- }
- nLine = hValue.As<v8::Object>()->Get(3)->ToInt32()->Value();
- nCol = hValue.As<v8::Object>()->Get(5)->ToInt32()->Value();
- return TRUE;
-}
-CFXJSE_Context* CFXJSE_Context::Create(v8::Isolate* pIsolate,
- const FXJSE_CLASS* lpGlobalClass,
- void* lpGlobalObject) {
- CFXJSE_ScopeUtil_IsolateHandle scope(pIsolate);
- CFXJSE_Context* pContext = new CFXJSE_Context(pIsolate);
- CFXJSE_Class* lpGlobalClassObj = NULL;
- v8::Local<v8::ObjectTemplate> hObjectTemplate;
- if (lpGlobalClass) {
- lpGlobalClassObj = CFXJSE_Class::Create(pContext, lpGlobalClass, TRUE);
- ASSERT(lpGlobalClassObj);
- v8::Local<v8::FunctionTemplate> hFunctionTemplate =
- v8::Local<v8::FunctionTemplate>::New(pIsolate,
- lpGlobalClassObj->m_hTemplate);
- hObjectTemplate = hFunctionTemplate->InstanceTemplate();
- } else {
- hObjectTemplate = v8::ObjectTemplate::New();
- hObjectTemplate->SetInternalFieldCount(1);
- }
- v8::Local<v8::Context> hNewContext =
- v8::Context::New(pIsolate, NULL, hObjectTemplate);
- v8::Local<v8::Context> hRootContext = v8::Local<v8::Context>::New(
- pIsolate, CFXJSE_RuntimeData::Get(pIsolate)->m_hRootContext);
- hNewContext->SetSecurityToken(hRootContext->GetSecurityToken());
- v8::Local<v8::Object> hGlobalObject =
- FXJSE_GetGlobalObjectFromContext(hNewContext);
- FXJSE_UpdateObjectBinding(hGlobalObject, lpGlobalObject);
- pContext->m_hContext.Reset(pIsolate, hNewContext);
- return pContext;
-}
-CFXJSE_Context::~CFXJSE_Context() {
- for (int32_t i = 0, count = m_rgClasses.GetSize(); i < count; i++) {
- CFXJSE_Class* pClass = m_rgClasses[i];
- if (pClass) {
- delete pClass;
- }
- }
- m_rgClasses.RemoveAll();
-}
-void CFXJSE_Context::GetGlobalObject(CFXJSE_Value* pValue) {
- ASSERT(pValue);
- CFXJSE_ScopeUtil_IsolateHandleContext scope(this);
- v8::Local<v8::Context> hContext =
- v8::Local<v8::Context>::New(m_pIsolate, m_hContext);
- v8::Local<v8::Object> hGlobalObject = hContext->Global();
- pValue->ForceSetValue(hGlobalObject);
-}
-FX_BOOL CFXJSE_Context::ExecuteScript(const FX_CHAR* szScript,
- CFXJSE_Value* lpRetValue,
- CFXJSE_Value* lpNewThisObject) {
- CFXJSE_ScopeUtil_IsolateHandleContext scope(this);
- v8::TryCatch trycatch;
- v8::Local<v8::String> hScriptString =
- v8::String::NewFromUtf8(m_pIsolate, szScript);
- if (lpNewThisObject == NULL) {
- v8::Local<v8::Script> hScript = v8::Script::Compile(hScriptString);
- if (!trycatch.HasCaught()) {
- v8::Local<v8::Value> hValue = hScript->Run();
- if (!trycatch.HasCaught()) {
- if (lpRetValue) {
- lpRetValue->m_hValue.Reset(m_pIsolate, hValue);
- }
- return TRUE;
- }
- }
- if (lpRetValue) {
- lpRetValue->m_hValue.Reset(m_pIsolate,
- FXJSE_CreateReturnValue(m_pIsolate, trycatch));
- }
- return FALSE;
- } else {
- v8::Local<v8::Value> hNewThis =
- v8::Local<v8::Value>::New(m_pIsolate, lpNewThisObject->m_hValue);
- ASSERT(!hNewThis.IsEmpty());
- v8::Local<v8::Script> hWrapper =
- v8::Script::Compile(v8::String::NewFromUtf8(
- m_pIsolate, "(function () { return eval(arguments[0]); })"));
- v8::Local<v8::Value> hWrapperValue = hWrapper->Run();
- ASSERT(hWrapperValue->IsFunction());
- v8::Local<v8::Function> hWrapperFn = hWrapperValue.As<v8::Function>();
- if (!trycatch.HasCaught()) {
- v8::Local<v8::Value> rgArgs[] = {hScriptString};
- v8::Local<v8::Value> hValue =
- hWrapperFn->Call(hNewThis.As<v8::Object>(), 1, rgArgs);
- if (!trycatch.HasCaught()) {
- if (lpRetValue) {
- lpRetValue->m_hValue.Reset(m_pIsolate, hValue);
- }
- return TRUE;
- }
- }
- if (lpRetValue) {
- lpRetValue->m_hValue.Reset(m_pIsolate,
- FXJSE_CreateReturnValue(m_pIsolate, trycatch));
- }
- return FALSE;
- }
-}
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "xfa/src/foxitlib.h"
+#include "fxv8.h"
+#include "context.h"
+#include "class.h"
+#include "value.h"
+#include "scope_inline.h"
+#include "util_inline.h"
+FXJSE_HCONTEXT FXJSE_Context_Create(FXJSE_HRUNTIME hRuntime,
+ const FXJSE_CLASS* lpGlobalClass,
+ void* lpGlobalObject) {
+ CFXJSE_Context* pContext = CFXJSE_Context::Create(
+ reinterpret_cast<v8::Isolate*>(hRuntime), lpGlobalClass, lpGlobalObject);
+ return reinterpret_cast<FXJSE_HCONTEXT>(pContext);
+}
+void FXJSE_Context_Release(FXJSE_HCONTEXT hContext) {
+ CFXJSE_Context* pContext = reinterpret_cast<CFXJSE_Context*>(hContext);
+ if (pContext) {
+ delete pContext;
+ }
+}
+FXJSE_HVALUE FXJSE_Context_GetGlobalObject(FXJSE_HCONTEXT hContext) {
+ CFXJSE_Context* pContext = reinterpret_cast<CFXJSE_Context*>(hContext);
+ if (!pContext) {
+ return NULL;
+ }
+ CFXJSE_Value* lpValue = CFXJSE_Value::Create(pContext->GetRuntime());
+ ASSERT(lpValue);
+ pContext->GetGlobalObject(lpValue);
+ return reinterpret_cast<FXJSE_HVALUE>(lpValue);
+}
+FXJSE_HRUNTIME FXJSE_Context_GetRuntime(FXJSE_HCONTEXT hContext) {
+ CFXJSE_Context* pContext = reinterpret_cast<CFXJSE_Context*>(hContext);
+ return pContext ? reinterpret_cast<FXJSE_HRUNTIME>(pContext->GetRuntime())
+ : NULL;
+}
+static const FX_CHAR* szCompatibleModeScripts[] = {
+ "(function (global, list) { 'use strict'; var objname; for (objname in list) { var globalobj = global[objname];\n\
+ if (globalobj) { list[objname].forEach( function (name) { if (!globalobj[name]) { Object.defineProperty(globalobj, name, {writable: true, enumerable: false, value: \n\
+ (function (obj) {\n\
+ if (arguments.length === 0) {\n\
+ throw new TypeError('missing argument 0 when calling function ' + objname + '.' + name);\n\
+ }\n\
+ return globalobj.prototype[name].apply(obj, Array.prototype.slice.call(arguments, 1));\n\
+})});}});}}}(this, {String: ['substr', 'toUpperCase']}));",
+};
+void FXJSE_Context_EnableCompatibleMode(FXJSE_HCONTEXT hContext,
+ FX_DWORD dwCompatibleFlags) {
+ for (uint32_t i = 0; i < (uint32_t)FXJSE_COMPATIBLEMODEFLAGCOUNT; i++) {
+ if (dwCompatibleFlags & (1 << i)) {
+ FXJSE_ExecuteScript(hContext, szCompatibleModeScripts[i], NULL, NULL);
+ }
+ }
+}
+FX_BOOL FXJSE_ExecuteScript(FXJSE_HCONTEXT hContext,
+ const FX_CHAR* szScript,
+ FXJSE_HVALUE hRetValue,
+ FXJSE_HVALUE hNewThisObject) {
+ CFXJSE_Context* pContext = reinterpret_cast<CFXJSE_Context*>(hContext);
+ ASSERT(pContext);
+ return pContext->ExecuteScript(
+ szScript, reinterpret_cast<CFXJSE_Value*>(hRetValue),
+ reinterpret_cast<CFXJSE_Value*>(hNewThisObject));
+}
+v8::Local<v8::Object> FXJSE_CreateReturnValue(v8::Isolate* pIsolate,
+ v8::TryCatch& trycatch) {
+ v8::Local<v8::Object> hReturnValue = v8::Object::New(pIsolate);
+ if (trycatch.HasCaught()) {
+ v8::Local<v8::Value> hException = trycatch.Exception();
+ v8::Local<v8::Message> hMessage = trycatch.Message();
+ if (hException->IsObject()) {
+ v8::Local<v8::Value> hValue;
+ hValue = hException.As<v8::Object>()->Get(
+ v8::String::NewFromUtf8(pIsolate, "name"));
+ if (hValue->IsString() || hValue->IsStringObject()) {
+ hReturnValue->Set(0, hValue);
+ } else {
+ hReturnValue->Set(0, v8::String::NewFromUtf8(pIsolate, "Error"));
+ }
+ hValue = hException.As<v8::Object>()->Get(
+ v8::String::NewFromUtf8(pIsolate, "message"));
+ if (hValue->IsString() || hValue->IsStringObject()) {
+ hReturnValue->Set(1, hValue);
+ } else {
+ hReturnValue->Set(1, hMessage->Get());
+ }
+ } else {
+ hReturnValue->Set(0, v8::String::NewFromUtf8(pIsolate, "Error"));
+ hReturnValue->Set(1, hMessage->Get());
+ }
+ hReturnValue->Set(2, hException);
+ hReturnValue->Set(3, v8::Integer::New(pIsolate, hMessage->GetLineNumber()));
+ hReturnValue->Set(4, hMessage->GetSourceLine());
+ hReturnValue->Set(5,
+ v8::Integer::New(pIsolate, hMessage->GetStartColumn()));
+ hReturnValue->Set(6, v8::Integer::New(pIsolate, hMessage->GetEndColumn()));
+ }
+ return hReturnValue;
+}
+FX_BOOL FXJSE_ReturnValue_GetMessage(FXJSE_HVALUE hRetValue,
+ CFX_ByteString& utf8Name,
+ CFX_ByteString& utf8Message) {
+ CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hRetValue);
+ if (!lpValue) {
+ return FALSE;
+ }
+ v8::Isolate* pIsolate = lpValue->GetIsolate();
+ CFXJSE_ScopeUtil_IsolateHandleRootContext scope(pIsolate);
+ v8::Local<v8::Value> hValue =
+ v8::Local<v8::Value>::New(pIsolate, lpValue->DirectGetValue());
+ if (!hValue->IsObject()) {
+ return FALSE;
+ }
+ v8::String::Utf8Value hStringVal0(
+ hValue.As<v8::Object>()->Get(0)->ToString());
+ utf8Name = *hStringVal0;
+ v8::String::Utf8Value hStringVal1(
+ hValue.As<v8::Object>()->Get(1)->ToString());
+ utf8Message = *hStringVal1;
+ return TRUE;
+}
+FX_BOOL FXJSE_ReturnValue_GetLineInfo(FXJSE_HVALUE hRetValue,
+ int32_t& nLine,
+ int32_t& nCol) {
+ CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hRetValue);
+ if (!lpValue) {
+ return FALSE;
+ }
+ v8::Isolate* pIsolate = lpValue->GetIsolate();
+ CFXJSE_ScopeUtil_IsolateHandleRootContext scope(pIsolate);
+ v8::Local<v8::Value> hValue =
+ v8::Local<v8::Value>::New(pIsolate, lpValue->DirectGetValue());
+ if (!hValue->IsObject()) {
+ return FALSE;
+ }
+ nLine = hValue.As<v8::Object>()->Get(3)->ToInt32()->Value();
+ nCol = hValue.As<v8::Object>()->Get(5)->ToInt32()->Value();
+ return TRUE;
+}
+CFXJSE_Context* CFXJSE_Context::Create(v8::Isolate* pIsolate,
+ const FXJSE_CLASS* lpGlobalClass,
+ void* lpGlobalObject) {
+ CFXJSE_ScopeUtil_IsolateHandle scope(pIsolate);
+ CFXJSE_Context* pContext = new CFXJSE_Context(pIsolate);
+ CFXJSE_Class* lpGlobalClassObj = NULL;
+ v8::Local<v8::ObjectTemplate> hObjectTemplate;
+ if (lpGlobalClass) {
+ lpGlobalClassObj = CFXJSE_Class::Create(pContext, lpGlobalClass, TRUE);
+ ASSERT(lpGlobalClassObj);
+ v8::Local<v8::FunctionTemplate> hFunctionTemplate =
+ v8::Local<v8::FunctionTemplate>::New(pIsolate,
+ lpGlobalClassObj->m_hTemplate);
+ hObjectTemplate = hFunctionTemplate->InstanceTemplate();
+ } else {
+ hObjectTemplate = v8::ObjectTemplate::New();
+ hObjectTemplate->SetInternalFieldCount(1);
+ }
+ v8::Local<v8::Context> hNewContext =
+ v8::Context::New(pIsolate, NULL, hObjectTemplate);
+ v8::Local<v8::Context> hRootContext = v8::Local<v8::Context>::New(
+ pIsolate, CFXJSE_RuntimeData::Get(pIsolate)->m_hRootContext);
+ hNewContext->SetSecurityToken(hRootContext->GetSecurityToken());
+ v8::Local<v8::Object> hGlobalObject =
+ FXJSE_GetGlobalObjectFromContext(hNewContext);
+ FXJSE_UpdateObjectBinding(hGlobalObject, lpGlobalObject);
+ pContext->m_hContext.Reset(pIsolate, hNewContext);
+ return pContext;
+}
+CFXJSE_Context::~CFXJSE_Context() {
+ for (int32_t i = 0, count = m_rgClasses.GetSize(); i < count; i++) {
+ CFXJSE_Class* pClass = m_rgClasses[i];
+ if (pClass) {
+ delete pClass;
+ }
+ }
+ m_rgClasses.RemoveAll();
+}
+void CFXJSE_Context::GetGlobalObject(CFXJSE_Value* pValue) {
+ ASSERT(pValue);
+ CFXJSE_ScopeUtil_IsolateHandleContext scope(this);
+ v8::Local<v8::Context> hContext =
+ v8::Local<v8::Context>::New(m_pIsolate, m_hContext);
+ v8::Local<v8::Object> hGlobalObject = hContext->Global();
+ pValue->ForceSetValue(hGlobalObject);
+}
+FX_BOOL CFXJSE_Context::ExecuteScript(const FX_CHAR* szScript,
+ CFXJSE_Value* lpRetValue,
+ CFXJSE_Value* lpNewThisObject) {
+ CFXJSE_ScopeUtil_IsolateHandleContext scope(this);
+ v8::TryCatch trycatch;
+ v8::Local<v8::String> hScriptString =
+ v8::String::NewFromUtf8(m_pIsolate, szScript);
+ if (lpNewThisObject == NULL) {
+ v8::Local<v8::Script> hScript = v8::Script::Compile(hScriptString);
+ if (!trycatch.HasCaught()) {
+ v8::Local<v8::Value> hValue = hScript->Run();
+ if (!trycatch.HasCaught()) {
+ if (lpRetValue) {
+ lpRetValue->m_hValue.Reset(m_pIsolate, hValue);
+ }
+ return TRUE;
+ }
+ }
+ if (lpRetValue) {
+ lpRetValue->m_hValue.Reset(m_pIsolate,
+ FXJSE_CreateReturnValue(m_pIsolate, trycatch));
+ }
+ return FALSE;
+ } else {
+ v8::Local<v8::Value> hNewThis =
+ v8::Local<v8::Value>::New(m_pIsolate, lpNewThisObject->m_hValue);
+ ASSERT(!hNewThis.IsEmpty());
+ v8::Local<v8::Script> hWrapper =
+ v8::Script::Compile(v8::String::NewFromUtf8(
+ m_pIsolate, "(function () { return eval(arguments[0]); })"));
+ v8::Local<v8::Value> hWrapperValue = hWrapper->Run();
+ ASSERT(hWrapperValue->IsFunction());
+ v8::Local<v8::Function> hWrapperFn = hWrapperValue.As<v8::Function>();
+ if (!trycatch.HasCaught()) {
+ v8::Local<v8::Value> rgArgs[] = {hScriptString};
+ v8::Local<v8::Value> hValue =
+ hWrapperFn->Call(hNewThis.As<v8::Object>(), 1, rgArgs);
+ if (!trycatch.HasCaught()) {
+ if (lpRetValue) {
+ lpRetValue->m_hValue.Reset(m_pIsolate, hValue);
+ }
+ return TRUE;
+ }
+ }
+ if (lpRetValue) {
+ lpRetValue->m_hValue.Reset(m_pIsolate,
+ FXJSE_CreateReturnValue(m_pIsolate, trycatch));
+ }
+ return FALSE;
+ }
+}
diff --git a/xfa/src/fxjse/src/context.h b/xfa/src/fxjse/src/context.h
index 33067fc3ed..d0267fc852 100644
--- a/xfa/src/fxjse/src/context.h
+++ b/xfa/src/fxjse/src/context.h
@@ -1,41 +1,41 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#ifndef FXJSE_CONTEXT_H_
-#define FXJSE_CONTEXT_H_
-class CFXJSE_Class;
-class CFXJSE_Value;
-class CFXJSE_Context {
- protected:
- CFXJSE_Context(v8::Isolate* pIsolate) : m_pIsolate(pIsolate) {}
-
- public:
- static CFXJSE_Context* Create(v8::Isolate* pIsolate,
- const FXJSE_CLASS* lpGlobalClass = NULL,
- void* lpGlobalObject = NULL);
- ~CFXJSE_Context();
- V8_INLINE v8::Isolate* GetRuntime(void) { return m_pIsolate; }
- void GetGlobalObject(CFXJSE_Value* pValue);
- FX_BOOL ExecuteScript(const FX_CHAR* szScript,
- CFXJSE_Value* lpRetValue,
- CFXJSE_Value* lpNewThisObject = NULL);
-
- protected:
- CFXJSE_Context();
- CFXJSE_Context(const CFXJSE_Context&);
- CFXJSE_Context& operator=(const CFXJSE_Context&);
-
- protected:
- v8::Global<v8::Context> m_hContext;
- v8::Isolate* m_pIsolate;
- CFX_ArrayTemplate<CFXJSE_Class*> m_rgClasses;
- friend class CFXJSE_Class;
- friend class CFXJSE_ScopeUtil_IsolateHandleContext;
- friend class CFXJSE_ScopeUtil_IsolateHandleRootOrNormalContext;
-};
-v8::Local<v8::Object> FXJSE_CreateReturnValue(v8::Isolate* pIsolate,
- v8::TryCatch& trycatch);
-#endif
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef FXJSE_CONTEXT_H_
+#define FXJSE_CONTEXT_H_
+class CFXJSE_Class;
+class CFXJSE_Value;
+class CFXJSE_Context {
+ protected:
+ CFXJSE_Context(v8::Isolate* pIsolate) : m_pIsolate(pIsolate) {}
+
+ public:
+ static CFXJSE_Context* Create(v8::Isolate* pIsolate,
+ const FXJSE_CLASS* lpGlobalClass = NULL,
+ void* lpGlobalObject = NULL);
+ ~CFXJSE_Context();
+ V8_INLINE v8::Isolate* GetRuntime(void) { return m_pIsolate; }
+ void GetGlobalObject(CFXJSE_Value* pValue);
+ FX_BOOL ExecuteScript(const FX_CHAR* szScript,
+ CFXJSE_Value* lpRetValue,
+ CFXJSE_Value* lpNewThisObject = NULL);
+
+ protected:
+ CFXJSE_Context();
+ CFXJSE_Context(const CFXJSE_Context&);
+ CFXJSE_Context& operator=(const CFXJSE_Context&);
+
+ protected:
+ v8::Global<v8::Context> m_hContext;
+ v8::Isolate* m_pIsolate;
+ CFX_ArrayTemplate<CFXJSE_Class*> m_rgClasses;
+ friend class CFXJSE_Class;
+ friend class CFXJSE_ScopeUtil_IsolateHandleContext;
+ friend class CFXJSE_ScopeUtil_IsolateHandleRootOrNormalContext;
+};
+v8::Local<v8::Object> FXJSE_CreateReturnValue(v8::Isolate* pIsolate,
+ v8::TryCatch& trycatch);
+#endif
diff --git a/xfa/src/fxjse/src/dynprop.cpp b/xfa/src/fxjse/src/dynprop.cpp
index 37c59f9ede..10f90a4ea5 100644
--- a/xfa/src/fxjse/src/dynprop.cpp
+++ b/xfa/src/fxjse/src/dynprop.cpp
@@ -1,457 +1,457 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "xfa/src/foxitlib.h"
-#include "fxv8.h"
-#include "class.h"
-#include "value.h"
-static void FXJSE_DynPropGetterAdapter_MethodCallback(
- const v8::FunctionCallbackInfo<v8::Value>& info) {
- v8::Local<v8::Object> hCallBackInfo = info.Data().As<v8::Object>();
- FXJSE_CLASS* lpClass = static_cast<FXJSE_CLASS*>(
- hCallBackInfo->GetAlignedPointerFromInternalField(0));
- v8::Local<v8::String> hPropName =
- hCallBackInfo->GetInternalField(1).As<v8::String>();
- ASSERT(lpClass && !hPropName.IsEmpty());
- v8::String::Utf8Value szPropName(hPropName);
- CFX_ByteStringC szFxPropName = *szPropName;
- CFXJSE_Value* lpThisValue = CFXJSE_Value::Create(info.GetIsolate());
- lpThisValue->ForceSetValue(info.This());
- CFXJSE_Value* lpRetValue = CFXJSE_Value::Create(info.GetIsolate());
- CFXJSE_ArgumentsImpl impl = {&info, lpRetValue};
- lpClass->dynMethodCall(reinterpret_cast<FXJSE_HOBJECT>(lpThisValue),
- szFxPropName,
- reinterpret_cast<CFXJSE_Arguments&>(impl));
- if (!lpRetValue->DirectGetValue().IsEmpty()) {
- info.GetReturnValue().Set(lpRetValue->DirectGetValue());
- }
- delete lpRetValue;
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "xfa/src/foxitlib.h"
+#include "fxv8.h"
+#include "class.h"
+#include "value.h"
+static void FXJSE_DynPropGetterAdapter_MethodCallback(
+ const v8::FunctionCallbackInfo<v8::Value>& info) {
+ v8::Local<v8::Object> hCallBackInfo = info.Data().As<v8::Object>();
+ FXJSE_CLASS* lpClass = static_cast<FXJSE_CLASS*>(
+ hCallBackInfo->GetAlignedPointerFromInternalField(0));
+ v8::Local<v8::String> hPropName =
+ hCallBackInfo->GetInternalField(1).As<v8::String>();
+ ASSERT(lpClass && !hPropName.IsEmpty());
+ v8::String::Utf8Value szPropName(hPropName);
+ CFX_ByteStringC szFxPropName = *szPropName;
+ CFXJSE_Value* lpThisValue = CFXJSE_Value::Create(info.GetIsolate());
+ lpThisValue->ForceSetValue(info.This());
+ CFXJSE_Value* lpRetValue = CFXJSE_Value::Create(info.GetIsolate());
+ CFXJSE_ArgumentsImpl impl = {&info, lpRetValue};
+ lpClass->dynMethodCall(reinterpret_cast<FXJSE_HOBJECT>(lpThisValue),
+ szFxPropName,
+ reinterpret_cast<CFXJSE_Arguments&>(impl));
+ if (!lpRetValue->DirectGetValue().IsEmpty()) {
+ info.GetReturnValue().Set(lpRetValue->DirectGetValue());
+ }
+ delete lpRetValue;
lpRetValue = nullptr;
- delete lpThisValue;
+ delete lpThisValue;
lpThisValue = nullptr;
-}
-static void FXJSE_DynPropGetterAdapter(const FXJSE_CLASS* lpClass,
- FXJSE_HOBJECT hObject,
- const CFX_ByteStringC& szPropName,
- FXJSE_HVALUE hValue) {
- ASSERT(lpClass);
- int32_t nPropType =
+}
+static void FXJSE_DynPropGetterAdapter(const FXJSE_CLASS* lpClass,
+ FXJSE_HOBJECT hObject,
+ const CFX_ByteStringC& szPropName,
+ FXJSE_HVALUE hValue) {
+ ASSERT(lpClass);
+ int32_t nPropType =
lpClass->dynPropTypeGetter == nullptr
- ? FXJSE_ClassPropType_Property
- : lpClass->dynPropTypeGetter(hObject, szPropName, FALSE);
- if (nPropType == FXJSE_ClassPropType_Property) {
- if (lpClass->dynPropGetter) {
- lpClass->dynPropGetter(hObject, szPropName, hValue);
- }
- } else if (nPropType == FXJSE_ClassPropType_Method) {
- if (lpClass->dynMethodCall && hValue) {
- CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
- v8::Isolate* pIsolate = lpValue->GetIsolate();
- v8::HandleScope hscope(pIsolate);
- v8::Local<v8::ObjectTemplate> hCallBackInfoTemplate =
- v8::ObjectTemplate::New();
- hCallBackInfoTemplate->SetInternalFieldCount(2);
- v8::Local<v8::Object> hCallBackInfo =
- hCallBackInfoTemplate->NewInstance();
- hCallBackInfo->SetAlignedPointerInInternalField(
- 0, const_cast<FXJSE_CLASS*>(lpClass));
- hCallBackInfo->SetInternalField(
- 1, v8::String::NewFromUtf8(
- pIsolate, reinterpret_cast<const char*>(szPropName.GetPtr()),
- v8::String::kNormalString, szPropName.GetLength()));
- lpValue->ForceSetValue(v8::Function::New(
- lpValue->GetIsolate(), FXJSE_DynPropGetterAdapter_MethodCallback,
- hCallBackInfo));
- }
- }
-}
-static void FXJSE_DynPropSetterAdapter(const FXJSE_CLASS* lpClass,
- FXJSE_HOBJECT hObject,
- const CFX_ByteStringC& szPropName,
- FXJSE_HVALUE hValue) {
- ASSERT(lpClass);
- int32_t nPropType =
+ ? FXJSE_ClassPropType_Property
+ : lpClass->dynPropTypeGetter(hObject, szPropName, FALSE);
+ if (nPropType == FXJSE_ClassPropType_Property) {
+ if (lpClass->dynPropGetter) {
+ lpClass->dynPropGetter(hObject, szPropName, hValue);
+ }
+ } else if (nPropType == FXJSE_ClassPropType_Method) {
+ if (lpClass->dynMethodCall && hValue) {
+ CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
+ v8::Isolate* pIsolate = lpValue->GetIsolate();
+ v8::HandleScope hscope(pIsolate);
+ v8::Local<v8::ObjectTemplate> hCallBackInfoTemplate =
+ v8::ObjectTemplate::New();
+ hCallBackInfoTemplate->SetInternalFieldCount(2);
+ v8::Local<v8::Object> hCallBackInfo =
+ hCallBackInfoTemplate->NewInstance();
+ hCallBackInfo->SetAlignedPointerInInternalField(
+ 0, const_cast<FXJSE_CLASS*>(lpClass));
+ hCallBackInfo->SetInternalField(
+ 1, v8::String::NewFromUtf8(
+ pIsolate, reinterpret_cast<const char*>(szPropName.GetPtr()),
+ v8::String::kNormalString, szPropName.GetLength()));
+ lpValue->ForceSetValue(v8::Function::New(
+ lpValue->GetIsolate(), FXJSE_DynPropGetterAdapter_MethodCallback,
+ hCallBackInfo));
+ }
+ }
+}
+static void FXJSE_DynPropSetterAdapter(const FXJSE_CLASS* lpClass,
+ FXJSE_HOBJECT hObject,
+ const CFX_ByteStringC& szPropName,
+ FXJSE_HVALUE hValue) {
+ ASSERT(lpClass);
+ int32_t nPropType =
lpClass->dynPropTypeGetter == nullptr
- ? FXJSE_ClassPropType_Property
- : lpClass->dynPropTypeGetter(hObject, szPropName, FALSE);
- if (nPropType != FXJSE_ClassPropType_Method) {
- if (lpClass->dynPropSetter) {
- lpClass->dynPropSetter(hObject, szPropName, hValue);
- }
- }
-}
-static FX_BOOL FXJSE_DynPropQueryAdapter(const FXJSE_CLASS* lpClass,
- FXJSE_HOBJECT hObject,
- const CFX_ByteStringC& szPropName) {
- ASSERT(lpClass);
- int32_t nPropType =
+ ? FXJSE_ClassPropType_Property
+ : lpClass->dynPropTypeGetter(hObject, szPropName, FALSE);
+ if (nPropType != FXJSE_ClassPropType_Method) {
+ if (lpClass->dynPropSetter) {
+ lpClass->dynPropSetter(hObject, szPropName, hValue);
+ }
+ }
+}
+static FX_BOOL FXJSE_DynPropQueryAdapter(const FXJSE_CLASS* lpClass,
+ FXJSE_HOBJECT hObject,
+ const CFX_ByteStringC& szPropName) {
+ ASSERT(lpClass);
+ int32_t nPropType =
lpClass->dynPropTypeGetter == nullptr
- ? FXJSE_ClassPropType_Property
- : lpClass->dynPropTypeGetter(hObject, szPropName, TRUE);
- return nPropType != FXJSE_ClassPropType_None;
-}
-static FX_BOOL FXJSE_DynPropDeleterAdapter(const FXJSE_CLASS* lpClass,
- FXJSE_HOBJECT hObject,
- const CFX_ByteStringC& szPropName) {
- ASSERT(lpClass);
- int32_t nPropType =
+ ? FXJSE_ClassPropType_Property
+ : lpClass->dynPropTypeGetter(hObject, szPropName, TRUE);
+ return nPropType != FXJSE_ClassPropType_None;
+}
+static FX_BOOL FXJSE_DynPropDeleterAdapter(const FXJSE_CLASS* lpClass,
+ FXJSE_HOBJECT hObject,
+ const CFX_ByteStringC& szPropName) {
+ ASSERT(lpClass);
+ int32_t nPropType =
lpClass->dynPropTypeGetter == nullptr
- ? FXJSE_ClassPropType_Property
- : lpClass->dynPropTypeGetter(hObject, szPropName, FALSE);
- if (nPropType != FXJSE_ClassPropType_Method) {
- if (lpClass->dynPropDeleter) {
- return lpClass->dynPropDeleter(hObject, szPropName);
- } else {
- return nPropType == FXJSE_ClassPropType_Property ? FALSE : TRUE;
- }
- }
- return FALSE;
-}
-static void FXJSE_V8ProxyCallback_getOwnPropertyDescriptor_getter(
- const v8::FunctionCallbackInfo<v8::Value>& info) {
- v8::Local<v8::Object> hCallBackInfo = info.Data().As<v8::Object>();
- FXJSE_CLASS* lpClass = static_cast<FXJSE_CLASS*>(
- hCallBackInfo->GetAlignedPointerFromInternalField(0));
- v8::Local<v8::String> hPropName =
- hCallBackInfo->GetInternalField(1).As<v8::String>();
- ASSERT(lpClass && !hPropName.IsEmpty());
- v8::String::Utf8Value szPropName(hPropName);
- CFX_ByteStringC szFxPropName = *szPropName;
- CFXJSE_Value* lpThisValue = CFXJSE_Value::Create(info.GetIsolate());
- CFXJSE_Value* lpNewValue = CFXJSE_Value::Create(info.GetIsolate());
- lpThisValue->ForceSetValue(info.This());
- FXJSE_DynPropGetterAdapter(
- lpClass, reinterpret_cast<FXJSE_HOBJECT>(lpThisValue), szFxPropName,
- reinterpret_cast<FXJSE_HVALUE>(lpNewValue));
- info.GetReturnValue().Set(lpNewValue->DirectGetValue());
- delete lpThisValue;
+ ? FXJSE_ClassPropType_Property
+ : lpClass->dynPropTypeGetter(hObject, szPropName, FALSE);
+ if (nPropType != FXJSE_ClassPropType_Method) {
+ if (lpClass->dynPropDeleter) {
+ return lpClass->dynPropDeleter(hObject, szPropName);
+ } else {
+ return nPropType == FXJSE_ClassPropType_Property ? FALSE : TRUE;
+ }
+ }
+ return FALSE;
+}
+static void FXJSE_V8ProxyCallback_getOwnPropertyDescriptor_getter(
+ const v8::FunctionCallbackInfo<v8::Value>& info) {
+ v8::Local<v8::Object> hCallBackInfo = info.Data().As<v8::Object>();
+ FXJSE_CLASS* lpClass = static_cast<FXJSE_CLASS*>(
+ hCallBackInfo->GetAlignedPointerFromInternalField(0));
+ v8::Local<v8::String> hPropName =
+ hCallBackInfo->GetInternalField(1).As<v8::String>();
+ ASSERT(lpClass && !hPropName.IsEmpty());
+ v8::String::Utf8Value szPropName(hPropName);
+ CFX_ByteStringC szFxPropName = *szPropName;
+ CFXJSE_Value* lpThisValue = CFXJSE_Value::Create(info.GetIsolate());
+ CFXJSE_Value* lpNewValue = CFXJSE_Value::Create(info.GetIsolate());
+ lpThisValue->ForceSetValue(info.This());
+ FXJSE_DynPropGetterAdapter(
+ lpClass, reinterpret_cast<FXJSE_HOBJECT>(lpThisValue), szFxPropName,
+ reinterpret_cast<FXJSE_HVALUE>(lpNewValue));
+ info.GetReturnValue().Set(lpNewValue->DirectGetValue());
+ delete lpThisValue;
lpThisValue = nullptr;
- delete lpNewValue;
+ delete lpNewValue;
lpNewValue = nullptr;
-}
-static void FXJSE_V8ProxyCallback_getOwnPropertyDescriptor_setter(
- const v8::FunctionCallbackInfo<v8::Value>& info) {
- v8::Local<v8::Object> hCallBackInfo = info.Data().As<v8::Object>();
- FXJSE_CLASS* lpClass = static_cast<FXJSE_CLASS*>(
- hCallBackInfo->GetAlignedPointerFromInternalField(0));
- v8::Local<v8::String> hPropName =
- hCallBackInfo->GetInternalField(1).As<v8::String>();
- ASSERT(lpClass && !hPropName.IsEmpty());
- v8::String::Utf8Value szPropName(hPropName);
- CFX_ByteStringC szFxPropName = *szPropName;
- CFXJSE_Value* lpThisValue = CFXJSE_Value::Create(info.GetIsolate());
- CFXJSE_Value* lpNewValue = CFXJSE_Value::Create(info.GetIsolate());
- lpThisValue->ForceSetValue(info.This());
- lpNewValue->ForceSetValue(info[0]);
- FXJSE_DynPropSetterAdapter(
- lpClass, reinterpret_cast<FXJSE_HOBJECT>(lpThisValue), szFxPropName,
- reinterpret_cast<FXJSE_HVALUE>(lpNewValue));
- delete lpThisValue;
+}
+static void FXJSE_V8ProxyCallback_getOwnPropertyDescriptor_setter(
+ const v8::FunctionCallbackInfo<v8::Value>& info) {
+ v8::Local<v8::Object> hCallBackInfo = info.Data().As<v8::Object>();
+ FXJSE_CLASS* lpClass = static_cast<FXJSE_CLASS*>(
+ hCallBackInfo->GetAlignedPointerFromInternalField(0));
+ v8::Local<v8::String> hPropName =
+ hCallBackInfo->GetInternalField(1).As<v8::String>();
+ ASSERT(lpClass && !hPropName.IsEmpty());
+ v8::String::Utf8Value szPropName(hPropName);
+ CFX_ByteStringC szFxPropName = *szPropName;
+ CFXJSE_Value* lpThisValue = CFXJSE_Value::Create(info.GetIsolate());
+ CFXJSE_Value* lpNewValue = CFXJSE_Value::Create(info.GetIsolate());
+ lpThisValue->ForceSetValue(info.This());
+ lpNewValue->ForceSetValue(info[0]);
+ FXJSE_DynPropSetterAdapter(
+ lpClass, reinterpret_cast<FXJSE_HOBJECT>(lpThisValue), szFxPropName,
+ reinterpret_cast<FXJSE_HVALUE>(lpNewValue));
+ delete lpThisValue;
lpThisValue = nullptr;
- delete lpNewValue;
+ delete lpNewValue;
lpNewValue = nullptr;
-}
-static void FXJSE_V8ProxyCallback_getOwnPropertyDescriptor(
- const v8::FunctionCallbackInfo<v8::Value>& info) {
- const FXJSE_CLASS* lpClass =
- static_cast<FXJSE_CLASS*>(info.Data().As<v8::External>()->Value());
- if (!lpClass) {
- return;
- }
- v8::Isolate* pIsolate = info.GetIsolate();
- v8::HandleScope scope(pIsolate);
- v8::Local<v8::String> hPropName = info[0]->ToString();
- v8::String::Utf8Value szPropName(hPropName);
- CFX_ByteStringC szFxPropName(*szPropName, szPropName.length());
- v8::Local<v8::ObjectTemplate> hCallBackInfoTemplate =
- v8::ObjectTemplate::New();
- hCallBackInfoTemplate->SetInternalFieldCount(2);
- v8::Local<v8::Object> hCallBackInfo = hCallBackInfoTemplate->NewInstance();
- hCallBackInfo->SetAlignedPointerInInternalField(
- 0, const_cast<FXJSE_CLASS*>(lpClass));
- hCallBackInfo->SetInternalField(1, hPropName);
- v8::Local<v8::Object> hPropDescriptor = v8::Object::New(pIsolate);
- hPropDescriptor->ForceSet(
- v8::String::NewFromUtf8(pIsolate, "get"),
- v8::Function::New(pIsolate,
- FXJSE_V8ProxyCallback_getOwnPropertyDescriptor_getter,
- hCallBackInfo));
- hPropDescriptor->ForceSet(
- v8::String::NewFromUtf8(pIsolate, "set"),
- v8::Function::New(pIsolate,
- FXJSE_V8ProxyCallback_getOwnPropertyDescriptor_setter,
- hCallBackInfo));
- hPropDescriptor->ForceSet(v8::String::NewFromUtf8(pIsolate, "enumerable"),
- v8::Boolean::New(pIsolate, false));
- hPropDescriptor->ForceSet(v8::String::NewFromUtf8(pIsolate, "configurable"),
- v8::Boolean::New(pIsolate, true));
- info.GetReturnValue().Set(hPropDescriptor);
-}
-static void FXJSE_V8ProxyCallback_getPropertyDescriptor(
- const v8::FunctionCallbackInfo<v8::Value>& info) {
- v8::Isolate* pIsolate = info.GetIsolate();
- v8::Local<v8::Object> hChainObj =
- info.This()->GetPrototype().As<v8::Object>();
- v8::Local<v8::Script> fnSource = v8::Script::Compile(v8::String::NewFromUtf8(
- pIsolate,
- "(function (o, name) { var fn, x, d; fn = "
- "Object.getOwnPropertyDescriptor; x = o; while(x && !(d = fn(x, "
- "name))){x = x.__proto__;} return d; })"));
- v8::Local<v8::Function> fn = fnSource->Run().As<v8::Function>();
- v8::Local<v8::Value> rgArgs[] = {hChainObj, info[0]};
- v8::Local<v8::Value> hChainDescriptor = fn->Call(info.This(), 2, rgArgs);
- if (!hChainDescriptor.IsEmpty() && hChainDescriptor->IsObject()) {
- info.GetReturnValue().Set(hChainDescriptor);
- } else {
- FXJSE_V8ProxyCallback_getOwnPropertyDescriptor(info);
- }
-}
-static void FXJSE_V8ProxyCallback_getOwnPropertyNames(
- const v8::FunctionCallbackInfo<v8::Value>& info) {
- v8::Isolate* pIsolate = info.GetIsolate();
- v8::HandleScope scope(pIsolate);
- info.GetReturnValue().Set(v8::Array::New(pIsolate));
-}
-static void FXJSE_V8ProxyCallback_getPropertyNames(
- const v8::FunctionCallbackInfo<v8::Value>& info) {
- v8::Local<v8::Object> hChainObj =
- info.This()->GetPrototype().As<v8::Object>();
- v8::Local<v8::Value> hChainPropertyNames = hChainObj->GetPropertyNames();
- info.GetReturnValue().Set(hChainPropertyNames);
-}
-static void FXJSE_V8ProxyCallback_defineProperty(
- const v8::FunctionCallbackInfo<v8::Value>& info) {
- const FXJSE_CLASS* lpClass =
- static_cast<FXJSE_CLASS*>(info.Data().As<v8::External>()->Value());
- if (!lpClass) {
- return;
- }
- v8::Isolate* pIsolate = info.GetIsolate();
- v8::HandleScope scope(pIsolate);
- v8::Local<v8::String> hPropName = info[0]->ToString();
- v8::Local<v8::Object> hPropDescriptor = info[1]->ToObject();
- v8::String::Utf8Value szPropName(hPropName);
- if (!hPropDescriptor->Has(v8::String::NewFromUtf8(pIsolate, "value"))) {
- return;
- }
- v8::Local<v8::Value> hPropValue =
- hPropDescriptor->Get(v8::String::NewFromUtf8(pIsolate, "value"));
- CFX_ByteStringC szFxPropName(*szPropName, szPropName.length());
- CFXJSE_Value* lpThisValue = CFXJSE_Value::Create(info.GetIsolate());
- CFXJSE_Value* lpPropValue = CFXJSE_Value::Create(info.GetIsolate());
- lpThisValue->ForceSetValue(info.This());
- lpPropValue->ForceSetValue(hPropValue);
- FXJSE_DynPropSetterAdapter(
- lpClass, reinterpret_cast<FXJSE_HOBJECT>(lpThisValue), szFxPropName,
- reinterpret_cast<FXJSE_HVALUE>(lpPropValue));
- delete lpThisValue;
+}
+static void FXJSE_V8ProxyCallback_getOwnPropertyDescriptor(
+ const v8::FunctionCallbackInfo<v8::Value>& info) {
+ const FXJSE_CLASS* lpClass =
+ static_cast<FXJSE_CLASS*>(info.Data().As<v8::External>()->Value());
+ if (!lpClass) {
+ return;
+ }
+ v8::Isolate* pIsolate = info.GetIsolate();
+ v8::HandleScope scope(pIsolate);
+ v8::Local<v8::String> hPropName = info[0]->ToString();
+ v8::String::Utf8Value szPropName(hPropName);
+ CFX_ByteStringC szFxPropName(*szPropName, szPropName.length());
+ v8::Local<v8::ObjectTemplate> hCallBackInfoTemplate =
+ v8::ObjectTemplate::New();
+ hCallBackInfoTemplate->SetInternalFieldCount(2);
+ v8::Local<v8::Object> hCallBackInfo = hCallBackInfoTemplate->NewInstance();
+ hCallBackInfo->SetAlignedPointerInInternalField(
+ 0, const_cast<FXJSE_CLASS*>(lpClass));
+ hCallBackInfo->SetInternalField(1, hPropName);
+ v8::Local<v8::Object> hPropDescriptor = v8::Object::New(pIsolate);
+ hPropDescriptor->ForceSet(
+ v8::String::NewFromUtf8(pIsolate, "get"),
+ v8::Function::New(pIsolate,
+ FXJSE_V8ProxyCallback_getOwnPropertyDescriptor_getter,
+ hCallBackInfo));
+ hPropDescriptor->ForceSet(
+ v8::String::NewFromUtf8(pIsolate, "set"),
+ v8::Function::New(pIsolate,
+ FXJSE_V8ProxyCallback_getOwnPropertyDescriptor_setter,
+ hCallBackInfo));
+ hPropDescriptor->ForceSet(v8::String::NewFromUtf8(pIsolate, "enumerable"),
+ v8::Boolean::New(pIsolate, false));
+ hPropDescriptor->ForceSet(v8::String::NewFromUtf8(pIsolate, "configurable"),
+ v8::Boolean::New(pIsolate, true));
+ info.GetReturnValue().Set(hPropDescriptor);
+}
+static void FXJSE_V8ProxyCallback_getPropertyDescriptor(
+ const v8::FunctionCallbackInfo<v8::Value>& info) {
+ v8::Isolate* pIsolate = info.GetIsolate();
+ v8::Local<v8::Object> hChainObj =
+ info.This()->GetPrototype().As<v8::Object>();
+ v8::Local<v8::Script> fnSource = v8::Script::Compile(v8::String::NewFromUtf8(
+ pIsolate,
+ "(function (o, name) { var fn, x, d; fn = "
+ "Object.getOwnPropertyDescriptor; x = o; while(x && !(d = fn(x, "
+ "name))){x = x.__proto__;} return d; })"));
+ v8::Local<v8::Function> fn = fnSource->Run().As<v8::Function>();
+ v8::Local<v8::Value> rgArgs[] = {hChainObj, info[0]};
+ v8::Local<v8::Value> hChainDescriptor = fn->Call(info.This(), 2, rgArgs);
+ if (!hChainDescriptor.IsEmpty() && hChainDescriptor->IsObject()) {
+ info.GetReturnValue().Set(hChainDescriptor);
+ } else {
+ FXJSE_V8ProxyCallback_getOwnPropertyDescriptor(info);
+ }
+}
+static void FXJSE_V8ProxyCallback_getOwnPropertyNames(
+ const v8::FunctionCallbackInfo<v8::Value>& info) {
+ v8::Isolate* pIsolate = info.GetIsolate();
+ v8::HandleScope scope(pIsolate);
+ info.GetReturnValue().Set(v8::Array::New(pIsolate));
+}
+static void FXJSE_V8ProxyCallback_getPropertyNames(
+ const v8::FunctionCallbackInfo<v8::Value>& info) {
+ v8::Local<v8::Object> hChainObj =
+ info.This()->GetPrototype().As<v8::Object>();
+ v8::Local<v8::Value> hChainPropertyNames = hChainObj->GetPropertyNames();
+ info.GetReturnValue().Set(hChainPropertyNames);
+}
+static void FXJSE_V8ProxyCallback_defineProperty(
+ const v8::FunctionCallbackInfo<v8::Value>& info) {
+ const FXJSE_CLASS* lpClass =
+ static_cast<FXJSE_CLASS*>(info.Data().As<v8::External>()->Value());
+ if (!lpClass) {
+ return;
+ }
+ v8::Isolate* pIsolate = info.GetIsolate();
+ v8::HandleScope scope(pIsolate);
+ v8::Local<v8::String> hPropName = info[0]->ToString();
+ v8::Local<v8::Object> hPropDescriptor = info[1]->ToObject();
+ v8::String::Utf8Value szPropName(hPropName);
+ if (!hPropDescriptor->Has(v8::String::NewFromUtf8(pIsolate, "value"))) {
+ return;
+ }
+ v8::Local<v8::Value> hPropValue =
+ hPropDescriptor->Get(v8::String::NewFromUtf8(pIsolate, "value"));
+ CFX_ByteStringC szFxPropName(*szPropName, szPropName.length());
+ CFXJSE_Value* lpThisValue = CFXJSE_Value::Create(info.GetIsolate());
+ CFXJSE_Value* lpPropValue = CFXJSE_Value::Create(info.GetIsolate());
+ lpThisValue->ForceSetValue(info.This());
+ lpPropValue->ForceSetValue(hPropValue);
+ FXJSE_DynPropSetterAdapter(
+ lpClass, reinterpret_cast<FXJSE_HOBJECT>(lpThisValue), szFxPropName,
+ reinterpret_cast<FXJSE_HVALUE>(lpPropValue));
+ delete lpThisValue;
lpThisValue = nullptr;
- delete lpPropValue;
+ delete lpPropValue;
lpPropValue = nullptr;
-}
-static void FXJSE_V8ProxyCallback_delete(
- const v8::FunctionCallbackInfo<v8::Value>& info) {
- info.GetReturnValue().Set(true);
- const FXJSE_CLASS* lpClass =
- static_cast<FXJSE_CLASS*>(info.Data().As<v8::External>()->Value());
- if (!lpClass) {
- return;
- }
- v8::Isolate* pIsolate = info.GetIsolate();
- v8::HandleScope scope(pIsolate);
- v8::Local<v8::String> hPropName = info[0]->ToString();
- v8::String::Utf8Value szPropName(hPropName);
- CFX_ByteStringC szFxPropName(*szPropName, szPropName.length());
- CFXJSE_Value* lpThisValue = CFXJSE_Value::Create(info.GetIsolate());
- lpThisValue->ForceSetValue(info.This());
- info.GetReturnValue().Set(
- FXJSE_DynPropDeleterAdapter(
- lpClass, reinterpret_cast<FXJSE_HOBJECT>(lpThisValue), szFxPropName)
- ? true
- : false);
- delete lpThisValue;
+}
+static void FXJSE_V8ProxyCallback_delete(
+ const v8::FunctionCallbackInfo<v8::Value>& info) {
+ info.GetReturnValue().Set(true);
+ const FXJSE_CLASS* lpClass =
+ static_cast<FXJSE_CLASS*>(info.Data().As<v8::External>()->Value());
+ if (!lpClass) {
+ return;
+ }
+ v8::Isolate* pIsolate = info.GetIsolate();
+ v8::HandleScope scope(pIsolate);
+ v8::Local<v8::String> hPropName = info[0]->ToString();
+ v8::String::Utf8Value szPropName(hPropName);
+ CFX_ByteStringC szFxPropName(*szPropName, szPropName.length());
+ CFXJSE_Value* lpThisValue = CFXJSE_Value::Create(info.GetIsolate());
+ lpThisValue->ForceSetValue(info.This());
+ info.GetReturnValue().Set(
+ FXJSE_DynPropDeleterAdapter(
+ lpClass, reinterpret_cast<FXJSE_HOBJECT>(lpThisValue), szFxPropName)
+ ? true
+ : false);
+ delete lpThisValue;
lpThisValue = nullptr;
-}
-static void FXJSE_V8ProxyCallback_fix(
- const v8::FunctionCallbackInfo<v8::Value>& info) {
- info.GetReturnValue().SetUndefined();
-}
+}
+static void FXJSE_V8ProxyCallback_fix(
+ const v8::FunctionCallbackInfo<v8::Value>& info) {
+ info.GetReturnValue().SetUndefined();
+}
static void FXJSE_V8_GenericNamedPropertyQueryCallback(
v8::Local<v8::Name> property,
- const v8::PropertyCallbackInfo<v8::Integer>& info) {
- v8::Local<v8::Object> thisObject = info.This();
- const FXJSE_CLASS* lpClass =
- static_cast<FXJSE_CLASS*>(info.Data().As<v8::External>()->Value());
- v8::Isolate* pIsolate = info.GetIsolate();
- v8::HandleScope scope(pIsolate);
- v8::String::Utf8Value szPropName(property);
- CFX_ByteStringC szFxPropName(*szPropName, szPropName.length());
- CFXJSE_Value* lpThisValue = CFXJSE_Value::Create(info.GetIsolate());
- lpThisValue->ForceSetValue(thisObject);
- if (FXJSE_DynPropQueryAdapter(lpClass,
- reinterpret_cast<FXJSE_HOBJECT>(lpThisValue),
- szFxPropName)) {
- info.GetReturnValue().Set(v8::DontDelete);
- } else {
- const int32_t iV8Absent = 64;
- info.GetReturnValue().Set(iV8Absent);
- }
- delete lpThisValue;
+ const v8::PropertyCallbackInfo<v8::Integer>& info) {
+ v8::Local<v8::Object> thisObject = info.This();
+ const FXJSE_CLASS* lpClass =
+ static_cast<FXJSE_CLASS*>(info.Data().As<v8::External>()->Value());
+ v8::Isolate* pIsolate = info.GetIsolate();
+ v8::HandleScope scope(pIsolate);
+ v8::String::Utf8Value szPropName(property);
+ CFX_ByteStringC szFxPropName(*szPropName, szPropName.length());
+ CFXJSE_Value* lpThisValue = CFXJSE_Value::Create(info.GetIsolate());
+ lpThisValue->ForceSetValue(thisObject);
+ if (FXJSE_DynPropQueryAdapter(lpClass,
+ reinterpret_cast<FXJSE_HOBJECT>(lpThisValue),
+ szFxPropName)) {
+ info.GetReturnValue().Set(v8::DontDelete);
+ } else {
+ const int32_t iV8Absent = 64;
+ info.GetReturnValue().Set(iV8Absent);
+ }
+ delete lpThisValue;
lpThisValue = nullptr;
-}
-static void FXJSE_V8_GenericNamedPropertyDeleterCallback(
- v8::Local<v8::Name> property,
- const v8::PropertyCallbackInfo<v8::Boolean>& info) {
- v8::Local<v8::Object> thisObject = info.This();
- const FXJSE_CLASS* lpClass =
- static_cast<FXJSE_CLASS*>(info.Data().As<v8::External>()->Value());
- v8::Isolate* pIsolate = info.GetIsolate();
- v8::HandleScope scope(pIsolate);
- v8::String::Utf8Value szPropName(property);
- CFX_ByteStringC szFxPropName(*szPropName, szPropName.length());
- CFXJSE_Value* lpThisValue = CFXJSE_Value::Create(info.GetIsolate());
- lpThisValue->ForceSetValue(thisObject);
- info.GetReturnValue().Set(
- FXJSE_DynPropDeleterAdapter(
- lpClass, reinterpret_cast<FXJSE_HOBJECT>(lpThisValue), szFxPropName)
- ? true
- : false);
- delete lpThisValue;
- lpThisValue = nullptr;
-}
-static void FXJSE_V8_GenericNamedPropertyGetterCallback(
- v8::Local<v8::Name> property,
- const v8::PropertyCallbackInfo<v8::Value>& info) {
- v8::Local<v8::Object> thisObject = info.This();
- const FXJSE_CLASS* lpClass =
- static_cast<FXJSE_CLASS*>(info.Data().As<v8::External>()->Value());
- v8::String::Utf8Value szPropName(property);
- CFX_ByteStringC szFxPropName(*szPropName, szPropName.length());
- CFXJSE_Value* lpThisValue = CFXJSE_Value::Create(info.GetIsolate());
- lpThisValue->ForceSetValue(thisObject);
- CFXJSE_Value* lpNewValue = CFXJSE_Value::Create(info.GetIsolate());
- FXJSE_DynPropGetterAdapter(
- lpClass, reinterpret_cast<FXJSE_HOBJECT>(lpThisValue), szFxPropName,
- reinterpret_cast<FXJSE_HVALUE>(lpNewValue));
- info.GetReturnValue().Set(lpNewValue->DirectGetValue());
- delete lpThisValue;
- lpThisValue = nullptr;
-}
-static void FXJSE_V8_GenericNamedPropertySetterCallback(
- v8::Local<v8::Name> property,
- v8::Local<v8::Value> value,
- const v8::PropertyCallbackInfo<v8::Value>& info) {
- v8::Local<v8::Object> thisObject = info.This();
- const FXJSE_CLASS* lpClass =
- static_cast<FXJSE_CLASS*>(info.Data().As<v8::External>()->Value());
- v8::String::Utf8Value szPropName(property);
- CFX_ByteStringC szFxPropName(*szPropName, szPropName.length());
- CFXJSE_Value* lpThisValue = CFXJSE_Value::Create(info.GetIsolate());
- lpThisValue->ForceSetValue(thisObject);
- CFXJSE_Value* lpNewValue = CFXJSE_Value::Create(info.GetIsolate());
- lpNewValue->ForceSetValue(value);
- FXJSE_DynPropSetterAdapter(
- lpClass, reinterpret_cast<FXJSE_HOBJECT>(lpThisValue), szFxPropName,
- reinterpret_cast<FXJSE_HVALUE>(lpNewValue));
- info.GetReturnValue().Set(value);
- delete lpThisValue;
- lpThisValue = nullptr;
-}
-static void FXJSE_V8_GenericNamedPropertyEnumeratorCallback(
- const v8::PropertyCallbackInfo<v8::Array>& info) {
- const FXJSE_CLASS* lpClass =
- static_cast<FXJSE_CLASS*>(info.Data().As<v8::External>()->Value());
- v8::Isolate* pIsolate = info.GetIsolate();
- v8::Local<v8::Array> newArray = v8::Array::New(pIsolate, lpClass->propNum);
- for (int i = 0; i < lpClass->propNum; i++) {
- newArray->Set(
- i, v8::String::NewFromUtf8(pIsolate, lpClass->properties[i].name));
- }
- info.GetReturnValue().Set(newArray);
-}
-
-void CFXJSE_Class::SetUpDynPropHandler(CFXJSE_Context* pContext,
- CFXJSE_Value* pValue,
- const FXJSE_CLASS* lpClassDefinition) {
- v8::Isolate* pIsolate = pValue->GetIsolate();
- CFXJSE_ScopeUtil_IsolateHandleRootOrNormalContext scope(pIsolate, pContext);
- v8::Local<v8::Context> hContext = v8::Local<v8::Context>::New(
- pIsolate, pContext ? pContext->m_hContext
- : CFXJSE_RuntimeData::Get(pIsolate)->m_hRootContext);
- v8::Local<v8::Object> hObject =
- v8::Local<v8::Value>::New(pIsolate, pValue->m_hValue).As<v8::Object>();
- v8::Local<v8::Object> hHarmonyProxyObj =
- hContext->Global()
- ->Get(v8::String::NewFromUtf8(pIsolate, "Proxy"))
- .As<v8::Object>();
- v8::Local<v8::Function> hHarmonyProxyCreateFn =
- hHarmonyProxyObj->Get(v8::String::NewFromUtf8(pIsolate, "create"))
- .As<v8::Function>();
- v8::Local<v8::Value> hOldPrototype = hObject->GetPrototype();
- v8::Local<v8::Object> hTrapper = v8::Object::New(pIsolate);
- hTrapper->ForceSet(
- v8::String::NewFromUtf8(pIsolate, "getOwnPropertyDescriptor"),
- v8::Function::New(
- pIsolate, FXJSE_V8ProxyCallback_getOwnPropertyDescriptor,
- v8::External::New(pIsolate,
- const_cast<FXJSE_CLASS*>(lpClassDefinition))));
- hTrapper->ForceSet(
- v8::String::NewFromUtf8(pIsolate, "getPropertyDescriptor"),
- v8::Function::New(pIsolate, FXJSE_V8ProxyCallback_getPropertyDescriptor,
- v8::External::New(pIsolate, const_cast<FXJSE_CLASS*>(
- lpClassDefinition))));
- hTrapper->ForceSet(
- v8::String::NewFromUtf8(pIsolate, "getOwnPropertyNames"),
- v8::Function::New(pIsolate, FXJSE_V8ProxyCallback_getOwnPropertyNames,
- v8::External::New(pIsolate, const_cast<FXJSE_CLASS*>(
- lpClassDefinition))));
- hTrapper->ForceSet(
- v8::String::NewFromUtf8(pIsolate, "getPropertyNames"),
- v8::Function::New(pIsolate, FXJSE_V8ProxyCallback_getPropertyNames,
- v8::External::New(pIsolate, const_cast<FXJSE_CLASS*>(
- lpClassDefinition))));
- hTrapper->ForceSet(
- v8::String::NewFromUtf8(pIsolate, "delete"),
- v8::Function::New(pIsolate, FXJSE_V8ProxyCallback_delete,
- v8::External::New(pIsolate, const_cast<FXJSE_CLASS*>(
- lpClassDefinition))));
- hTrapper->ForceSet(
- v8::String::NewFromUtf8(pIsolate, "defineProperty"),
- v8::Function::New(pIsolate, FXJSE_V8ProxyCallback_defineProperty,
- v8::External::New(pIsolate, const_cast<FXJSE_CLASS*>(
- lpClassDefinition))));
- hTrapper->ForceSet(
- v8::String::NewFromUtf8(pIsolate, "fix"),
- v8::Function::New(pIsolate, FXJSE_V8ProxyCallback_fix,
- v8::External::New(pIsolate, const_cast<FXJSE_CLASS*>(
- lpClassDefinition))));
- v8::Local<v8::Value> rgArgs[] = {hTrapper, hOldPrototype};
- v8::Local<v8::Value> hNewPrototype =
- hHarmonyProxyCreateFn->Call(hHarmonyProxyObj, 2, rgArgs);
- hObject->SetPrototype(hNewPrototype);
-}
-void CFXJSE_Class::SetUpNamedPropHandler(
- v8::Isolate* pIsolate,
- v8::Local<v8::ObjectTemplate>& hObjectTemplate,
- const FXJSE_CLASS* lpClassDefinition) {
- v8::NamedPropertyHandlerConfiguration configuration(
- lpClassDefinition->dynPropGetter
- ? FXJSE_V8_GenericNamedPropertyGetterCallback
- : 0,
- lpClassDefinition->dynPropSetter
- ? FXJSE_V8_GenericNamedPropertySetterCallback
- : 0,
- lpClassDefinition->dynPropTypeGetter
- ? FXJSE_V8_GenericNamedPropertyQueryCallback
- : 0,
- lpClassDefinition->dynPropDeleter
- ? FXJSE_V8_GenericNamedPropertyDeleterCallback
- : 0,
- FXJSE_V8_GenericNamedPropertyEnumeratorCallback,
- v8::External::New(pIsolate, const_cast<FXJSE_CLASS*>(lpClassDefinition)),
- v8::PropertyHandlerFlags::kNonMasking);
- hObjectTemplate->SetHandler(configuration);
-}
+}
+static void FXJSE_V8_GenericNamedPropertyDeleterCallback(
+ v8::Local<v8::Name> property,
+ const v8::PropertyCallbackInfo<v8::Boolean>& info) {
+ v8::Local<v8::Object> thisObject = info.This();
+ const FXJSE_CLASS* lpClass =
+ static_cast<FXJSE_CLASS*>(info.Data().As<v8::External>()->Value());
+ v8::Isolate* pIsolate = info.GetIsolate();
+ v8::HandleScope scope(pIsolate);
+ v8::String::Utf8Value szPropName(property);
+ CFX_ByteStringC szFxPropName(*szPropName, szPropName.length());
+ CFXJSE_Value* lpThisValue = CFXJSE_Value::Create(info.GetIsolate());
+ lpThisValue->ForceSetValue(thisObject);
+ info.GetReturnValue().Set(
+ FXJSE_DynPropDeleterAdapter(
+ lpClass, reinterpret_cast<FXJSE_HOBJECT>(lpThisValue), szFxPropName)
+ ? true
+ : false);
+ delete lpThisValue;
+ lpThisValue = nullptr;
+}
+static void FXJSE_V8_GenericNamedPropertyGetterCallback(
+ v8::Local<v8::Name> property,
+ const v8::PropertyCallbackInfo<v8::Value>& info) {
+ v8::Local<v8::Object> thisObject = info.This();
+ const FXJSE_CLASS* lpClass =
+ static_cast<FXJSE_CLASS*>(info.Data().As<v8::External>()->Value());
+ v8::String::Utf8Value szPropName(property);
+ CFX_ByteStringC szFxPropName(*szPropName, szPropName.length());
+ CFXJSE_Value* lpThisValue = CFXJSE_Value::Create(info.GetIsolate());
+ lpThisValue->ForceSetValue(thisObject);
+ CFXJSE_Value* lpNewValue = CFXJSE_Value::Create(info.GetIsolate());
+ FXJSE_DynPropGetterAdapter(
+ lpClass, reinterpret_cast<FXJSE_HOBJECT>(lpThisValue), szFxPropName,
+ reinterpret_cast<FXJSE_HVALUE>(lpNewValue));
+ info.GetReturnValue().Set(lpNewValue->DirectGetValue());
+ delete lpThisValue;
+ lpThisValue = nullptr;
+}
+static void FXJSE_V8_GenericNamedPropertySetterCallback(
+ v8::Local<v8::Name> property,
+ v8::Local<v8::Value> value,
+ const v8::PropertyCallbackInfo<v8::Value>& info) {
+ v8::Local<v8::Object> thisObject = info.This();
+ const FXJSE_CLASS* lpClass =
+ static_cast<FXJSE_CLASS*>(info.Data().As<v8::External>()->Value());
+ v8::String::Utf8Value szPropName(property);
+ CFX_ByteStringC szFxPropName(*szPropName, szPropName.length());
+ CFXJSE_Value* lpThisValue = CFXJSE_Value::Create(info.GetIsolate());
+ lpThisValue->ForceSetValue(thisObject);
+ CFXJSE_Value* lpNewValue = CFXJSE_Value::Create(info.GetIsolate());
+ lpNewValue->ForceSetValue(value);
+ FXJSE_DynPropSetterAdapter(
+ lpClass, reinterpret_cast<FXJSE_HOBJECT>(lpThisValue), szFxPropName,
+ reinterpret_cast<FXJSE_HVALUE>(lpNewValue));
+ info.GetReturnValue().Set(value);
+ delete lpThisValue;
+ lpThisValue = nullptr;
+}
+static void FXJSE_V8_GenericNamedPropertyEnumeratorCallback(
+ const v8::PropertyCallbackInfo<v8::Array>& info) {
+ const FXJSE_CLASS* lpClass =
+ static_cast<FXJSE_CLASS*>(info.Data().As<v8::External>()->Value());
+ v8::Isolate* pIsolate = info.GetIsolate();
+ v8::Local<v8::Array> newArray = v8::Array::New(pIsolate, lpClass->propNum);
+ for (int i = 0; i < lpClass->propNum; i++) {
+ newArray->Set(
+ i, v8::String::NewFromUtf8(pIsolate, lpClass->properties[i].name));
+ }
+ info.GetReturnValue().Set(newArray);
+}
+
+void CFXJSE_Class::SetUpDynPropHandler(CFXJSE_Context* pContext,
+ CFXJSE_Value* pValue,
+ const FXJSE_CLASS* lpClassDefinition) {
+ v8::Isolate* pIsolate = pValue->GetIsolate();
+ CFXJSE_ScopeUtil_IsolateHandleRootOrNormalContext scope(pIsolate, pContext);
+ v8::Local<v8::Context> hContext = v8::Local<v8::Context>::New(
+ pIsolate, pContext ? pContext->m_hContext
+ : CFXJSE_RuntimeData::Get(pIsolate)->m_hRootContext);
+ v8::Local<v8::Object> hObject =
+ v8::Local<v8::Value>::New(pIsolate, pValue->m_hValue).As<v8::Object>();
+ v8::Local<v8::Object> hHarmonyProxyObj =
+ hContext->Global()
+ ->Get(v8::String::NewFromUtf8(pIsolate, "Proxy"))
+ .As<v8::Object>();
+ v8::Local<v8::Function> hHarmonyProxyCreateFn =
+ hHarmonyProxyObj->Get(v8::String::NewFromUtf8(pIsolate, "create"))
+ .As<v8::Function>();
+ v8::Local<v8::Value> hOldPrototype = hObject->GetPrototype();
+ v8::Local<v8::Object> hTrapper = v8::Object::New(pIsolate);
+ hTrapper->ForceSet(
+ v8::String::NewFromUtf8(pIsolate, "getOwnPropertyDescriptor"),
+ v8::Function::New(
+ pIsolate, FXJSE_V8ProxyCallback_getOwnPropertyDescriptor,
+ v8::External::New(pIsolate,
+ const_cast<FXJSE_CLASS*>(lpClassDefinition))));
+ hTrapper->ForceSet(
+ v8::String::NewFromUtf8(pIsolate, "getPropertyDescriptor"),
+ v8::Function::New(pIsolate, FXJSE_V8ProxyCallback_getPropertyDescriptor,
+ v8::External::New(pIsolate, const_cast<FXJSE_CLASS*>(
+ lpClassDefinition))));
+ hTrapper->ForceSet(
+ v8::String::NewFromUtf8(pIsolate, "getOwnPropertyNames"),
+ v8::Function::New(pIsolate, FXJSE_V8ProxyCallback_getOwnPropertyNames,
+ v8::External::New(pIsolate, const_cast<FXJSE_CLASS*>(
+ lpClassDefinition))));
+ hTrapper->ForceSet(
+ v8::String::NewFromUtf8(pIsolate, "getPropertyNames"),
+ v8::Function::New(pIsolate, FXJSE_V8ProxyCallback_getPropertyNames,
+ v8::External::New(pIsolate, const_cast<FXJSE_CLASS*>(
+ lpClassDefinition))));
+ hTrapper->ForceSet(
+ v8::String::NewFromUtf8(pIsolate, "delete"),
+ v8::Function::New(pIsolate, FXJSE_V8ProxyCallback_delete,
+ v8::External::New(pIsolate, const_cast<FXJSE_CLASS*>(
+ lpClassDefinition))));
+ hTrapper->ForceSet(
+ v8::String::NewFromUtf8(pIsolate, "defineProperty"),
+ v8::Function::New(pIsolate, FXJSE_V8ProxyCallback_defineProperty,
+ v8::External::New(pIsolate, const_cast<FXJSE_CLASS*>(
+ lpClassDefinition))));
+ hTrapper->ForceSet(
+ v8::String::NewFromUtf8(pIsolate, "fix"),
+ v8::Function::New(pIsolate, FXJSE_V8ProxyCallback_fix,
+ v8::External::New(pIsolate, const_cast<FXJSE_CLASS*>(
+ lpClassDefinition))));
+ v8::Local<v8::Value> rgArgs[] = {hTrapper, hOldPrototype};
+ v8::Local<v8::Value> hNewPrototype =
+ hHarmonyProxyCreateFn->Call(hHarmonyProxyObj, 2, rgArgs);
+ hObject->SetPrototype(hNewPrototype);
+}
+void CFXJSE_Class::SetUpNamedPropHandler(
+ v8::Isolate* pIsolate,
+ v8::Local<v8::ObjectTemplate>& hObjectTemplate,
+ const FXJSE_CLASS* lpClassDefinition) {
+ v8::NamedPropertyHandlerConfiguration configuration(
+ lpClassDefinition->dynPropGetter
+ ? FXJSE_V8_GenericNamedPropertyGetterCallback
+ : 0,
+ lpClassDefinition->dynPropSetter
+ ? FXJSE_V8_GenericNamedPropertySetterCallback
+ : 0,
+ lpClassDefinition->dynPropTypeGetter
+ ? FXJSE_V8_GenericNamedPropertyQueryCallback
+ : 0,
+ lpClassDefinition->dynPropDeleter
+ ? FXJSE_V8_GenericNamedPropertyDeleterCallback
+ : 0,
+ FXJSE_V8_GenericNamedPropertyEnumeratorCallback,
+ v8::External::New(pIsolate, const_cast<FXJSE_CLASS*>(lpClassDefinition)),
+ v8::PropertyHandlerFlags::kNonMasking);
+ hObjectTemplate->SetHandler(configuration);
+}
diff --git a/xfa/src/fxjse/src/runtime.cpp b/xfa/src/fxjse/src/runtime.cpp
index b1630dcd11..5609c35b63 100644
--- a/xfa/src/fxjse/src/runtime.cpp
+++ b/xfa/src/fxjse/src/runtime.cpp
@@ -1,112 +1,112 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "fpdfsdk/include/jsapi/fxjs_v8.h" // For per-isolate data.
-#include "xfa/src/foxitlib.h"
-#include "fxv8.h"
-#include "runtime.h"
-#include "scope_inline.h"
-
-// Duplicates fpdfsdk's JS_Runtime.h, but keeps XFA from depending on it.
-// TODO(tsepez): make a single version of this.
-class FXJSE_ArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
- void* Allocate(size_t length) override { return calloc(1, length); }
- void* AllocateUninitialized(size_t length) override { return malloc(length); }
- void Free(void* data, size_t length) override { free(data); }
-};
-
-static void FXJSE_KillV8() {
- v8::V8::Dispose();
-}
-void FXJSE_Initialize() {
- if (!CFXJSE_RuntimeData::g_RuntimeList) {
- CFXJSE_RuntimeData::g_RuntimeList = new CFXJSE_RuntimeList;
- }
- static FX_BOOL bV8Initialized = FALSE;
- if (bV8Initialized) {
- return;
- }
- bV8Initialized = TRUE;
- atexit(FXJSE_KillV8);
-}
-static void FXJSE_Runtime_DisposeCallback(v8::Isolate* pIsolate) {
- {
- v8::Locker locker(pIsolate);
- if (FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(pIsolate)) {
- delete pData->m_pFXJSERuntimeData;
- pData->m_pFXJSERuntimeData = nullptr;
- }
- }
- pIsolate->Dispose();
-}
-void FXJSE_Finalize() {
- if (CFXJSE_RuntimeData::g_RuntimeList) {
- CFXJSE_RuntimeData::g_RuntimeList->RemoveAllRuntimes(
- FXJSE_Runtime_DisposeCallback);
- delete CFXJSE_RuntimeData::g_RuntimeList;
- CFXJSE_RuntimeData::g_RuntimeList = NULL;
- }
-}
-FXJSE_HRUNTIME FXJSE_Runtime_Create() {
- v8::Isolate::CreateParams params;
- params.array_buffer_allocator = new FXJSE_ArrayBufferAllocator();
- v8::Isolate* pIsolate = v8::Isolate::New(params);
- ASSERT(pIsolate && CFXJSE_RuntimeData::g_RuntimeList);
- CFXJSE_RuntimeData::g_RuntimeList->AppendRuntime(pIsolate);
- return reinterpret_cast<FXJSE_HRUNTIME>(pIsolate);
-}
-void FXJSE_Runtime_Release(FXJSE_HRUNTIME hRuntime) {
- v8::Isolate* pIsolate = reinterpret_cast<v8::Isolate*>(hRuntime);
- if (pIsolate) {
- ASSERT(CFXJSE_RuntimeData::g_RuntimeList);
- CFXJSE_RuntimeData::g_RuntimeList->RemoveRuntime(
- pIsolate, FXJSE_Runtime_DisposeCallback);
- }
-}
-CFXJSE_RuntimeData* CFXJSE_RuntimeData::Create(v8::Isolate* pIsolate) {
- CFXJSE_RuntimeData* pRuntimeData = new CFXJSE_RuntimeData(pIsolate);
- CFXJSE_ScopeUtil_IsolateHandle scope(pIsolate);
- v8::Local<v8::FunctionTemplate> hFuncTemplate =
- v8::FunctionTemplate::New(pIsolate);
- v8::Local<v8::Context> hContext =
- v8::Context::New(pIsolate, 0, hFuncTemplate->InstanceTemplate());
- hContext->SetSecurityToken(v8::External::New(pIsolate, pIsolate));
- pRuntimeData->m_hRootContextGlobalTemplate.Reset(pIsolate, hFuncTemplate);
- pRuntimeData->m_hRootContext.Reset(pIsolate, hContext);
- return pRuntimeData;
-}
-CFXJSE_RuntimeData* CFXJSE_RuntimeData::Get(v8::Isolate* pIsolate) {
- FXJS_PerIsolateData::SetUp(pIsolate);
- FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(pIsolate);
- if (!pData->m_pFXJSERuntimeData)
- pData->m_pFXJSERuntimeData = CFXJSE_RuntimeData::Create(pIsolate);
- return pData->m_pFXJSERuntimeData;
-}
-CFXJSE_RuntimeList* CFXJSE_RuntimeData::g_RuntimeList = NULL;
-void CFXJSE_RuntimeList::AppendRuntime(v8::Isolate* pIsolate) {
- m_RuntimeList.Add(pIsolate);
-}
-void CFXJSE_RuntimeList::RemoveRuntime(
- v8::Isolate* pIsolate,
- CFXJSE_RuntimeList::RuntimeDisposeCallback lpfnDisposeCallback) {
- int32_t iIdx = m_RuntimeList.Find(pIsolate, 0);
- if (iIdx >= 0) {
- m_RuntimeList.RemoveAt(iIdx, 1);
- }
- if (lpfnDisposeCallback) {
- lpfnDisposeCallback(pIsolate);
- }
-}
-void CFXJSE_RuntimeList::RemoveAllRuntimes(
- CFXJSE_RuntimeList::RuntimeDisposeCallback lpfnDisposeCallback) {
- int32_t iSize = m_RuntimeList.GetSize();
- if (lpfnDisposeCallback) {
- for (int32_t iIdx = 0; iIdx < iSize; iIdx++) {
- lpfnDisposeCallback(m_RuntimeList[iIdx]);
- }
- }
- m_RuntimeList.RemoveAll();
-}
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "fpdfsdk/include/jsapi/fxjs_v8.h" // For per-isolate data.
+#include "xfa/src/foxitlib.h"
+#include "fxv8.h"
+#include "runtime.h"
+#include "scope_inline.h"
+
+// Duplicates fpdfsdk's JS_Runtime.h, but keeps XFA from depending on it.
+// TODO(tsepez): make a single version of this.
+class FXJSE_ArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
+ void* Allocate(size_t length) override { return calloc(1, length); }
+ void* AllocateUninitialized(size_t length) override { return malloc(length); }
+ void Free(void* data, size_t length) override { free(data); }
+};
+
+static void FXJSE_KillV8() {
+ v8::V8::Dispose();
+}
+void FXJSE_Initialize() {
+ if (!CFXJSE_RuntimeData::g_RuntimeList) {
+ CFXJSE_RuntimeData::g_RuntimeList = new CFXJSE_RuntimeList;
+ }
+ static FX_BOOL bV8Initialized = FALSE;
+ if (bV8Initialized) {
+ return;
+ }
+ bV8Initialized = TRUE;
+ atexit(FXJSE_KillV8);
+}
+static void FXJSE_Runtime_DisposeCallback(v8::Isolate* pIsolate) {
+ {
+ v8::Locker locker(pIsolate);
+ if (FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(pIsolate)) {
+ delete pData->m_pFXJSERuntimeData;
+ pData->m_pFXJSERuntimeData = nullptr;
+ }
+ }
+ pIsolate->Dispose();
+}
+void FXJSE_Finalize() {
+ if (CFXJSE_RuntimeData::g_RuntimeList) {
+ CFXJSE_RuntimeData::g_RuntimeList->RemoveAllRuntimes(
+ FXJSE_Runtime_DisposeCallback);
+ delete CFXJSE_RuntimeData::g_RuntimeList;
+ CFXJSE_RuntimeData::g_RuntimeList = NULL;
+ }
+}
+FXJSE_HRUNTIME FXJSE_Runtime_Create() {
+ v8::Isolate::CreateParams params;
+ params.array_buffer_allocator = new FXJSE_ArrayBufferAllocator();
+ v8::Isolate* pIsolate = v8::Isolate::New(params);
+ ASSERT(pIsolate && CFXJSE_RuntimeData::g_RuntimeList);
+ CFXJSE_RuntimeData::g_RuntimeList->AppendRuntime(pIsolate);
+ return reinterpret_cast<FXJSE_HRUNTIME>(pIsolate);
+}
+void FXJSE_Runtime_Release(FXJSE_HRUNTIME hRuntime) {
+ v8::Isolate* pIsolate = reinterpret_cast<v8::Isolate*>(hRuntime);
+ if (pIsolate) {
+ ASSERT(CFXJSE_RuntimeData::g_RuntimeList);
+ CFXJSE_RuntimeData::g_RuntimeList->RemoveRuntime(
+ pIsolate, FXJSE_Runtime_DisposeCallback);
+ }
+}
+CFXJSE_RuntimeData* CFXJSE_RuntimeData::Create(v8::Isolate* pIsolate) {
+ CFXJSE_RuntimeData* pRuntimeData = new CFXJSE_RuntimeData(pIsolate);
+ CFXJSE_ScopeUtil_IsolateHandle scope(pIsolate);
+ v8::Local<v8::FunctionTemplate> hFuncTemplate =
+ v8::FunctionTemplate::New(pIsolate);
+ v8::Local<v8::Context> hContext =
+ v8::Context::New(pIsolate, 0, hFuncTemplate->InstanceTemplate());
+ hContext->SetSecurityToken(v8::External::New(pIsolate, pIsolate));
+ pRuntimeData->m_hRootContextGlobalTemplate.Reset(pIsolate, hFuncTemplate);
+ pRuntimeData->m_hRootContext.Reset(pIsolate, hContext);
+ return pRuntimeData;
+}
+CFXJSE_RuntimeData* CFXJSE_RuntimeData::Get(v8::Isolate* pIsolate) {
+ FXJS_PerIsolateData::SetUp(pIsolate);
+ FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(pIsolate);
+ if (!pData->m_pFXJSERuntimeData)
+ pData->m_pFXJSERuntimeData = CFXJSE_RuntimeData::Create(pIsolate);
+ return pData->m_pFXJSERuntimeData;
+}
+CFXJSE_RuntimeList* CFXJSE_RuntimeData::g_RuntimeList = NULL;
+void CFXJSE_RuntimeList::AppendRuntime(v8::Isolate* pIsolate) {
+ m_RuntimeList.Add(pIsolate);
+}
+void CFXJSE_RuntimeList::RemoveRuntime(
+ v8::Isolate* pIsolate,
+ CFXJSE_RuntimeList::RuntimeDisposeCallback lpfnDisposeCallback) {
+ int32_t iIdx = m_RuntimeList.Find(pIsolate, 0);
+ if (iIdx >= 0) {
+ m_RuntimeList.RemoveAt(iIdx, 1);
+ }
+ if (lpfnDisposeCallback) {
+ lpfnDisposeCallback(pIsolate);
+ }
+}
+void CFXJSE_RuntimeList::RemoveAllRuntimes(
+ CFXJSE_RuntimeList::RuntimeDisposeCallback lpfnDisposeCallback) {
+ int32_t iSize = m_RuntimeList.GetSize();
+ if (lpfnDisposeCallback) {
+ for (int32_t iIdx = 0; iIdx < iSize; iIdx++) {
+ lpfnDisposeCallback(m_RuntimeList[iIdx]);
+ }
+ }
+ m_RuntimeList.RemoveAll();
+}
diff --git a/xfa/src/fxjse/src/runtime.h b/xfa/src/fxjse/src/runtime.h
index d7c37aedb4..8c867ee328 100644
--- a/xfa/src/fxjse/src/runtime.h
+++ b/xfa/src/fxjse/src/runtime.h
@@ -1,44 +1,44 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#ifndef FXJSE_RUNTIME_H_
-#define FXJSE_RUNTIME_H_
-class CFXJSE_RuntimeList;
-class CFXJSE_RuntimeData {
- protected:
- CFXJSE_RuntimeData(v8::Isolate* pIsolate) : m_pIsolate(pIsolate){};
-
- public:
- static CFXJSE_RuntimeData* Create(v8::Isolate* pIsolate);
- static CFXJSE_RuntimeData* Get(v8::Isolate* pIsolate);
-
- public:
- v8::Isolate* m_pIsolate;
- v8::Global<v8::FunctionTemplate> m_hRootContextGlobalTemplate;
- v8::Global<v8::Context> m_hRootContext;
-
- public:
- static CFXJSE_RuntimeList* g_RuntimeList;
-
- protected:
- CFXJSE_RuntimeData();
- CFXJSE_RuntimeData(const CFXJSE_RuntimeData&);
- CFXJSE_RuntimeData& operator=(const CFXJSE_RuntimeData&);
-};
-class CFXJSE_RuntimeList {
- public:
- typedef void (*RuntimeDisposeCallback)(v8::Isolate*);
-
- public:
- void AppendRuntime(v8::Isolate* pIsolate);
- void RemoveRuntime(v8::Isolate* pIsolate,
- RuntimeDisposeCallback lpfnDisposeCallback);
- void RemoveAllRuntimes(RuntimeDisposeCallback lpfnDisposeCallback);
-
- protected:
- CFX_ArrayTemplate<v8::Isolate*> m_RuntimeList;
-};
-#endif
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef FXJSE_RUNTIME_H_
+#define FXJSE_RUNTIME_H_
+class CFXJSE_RuntimeList;
+class CFXJSE_RuntimeData {
+ protected:
+ CFXJSE_RuntimeData(v8::Isolate* pIsolate) : m_pIsolate(pIsolate){};
+
+ public:
+ static CFXJSE_RuntimeData* Create(v8::Isolate* pIsolate);
+ static CFXJSE_RuntimeData* Get(v8::Isolate* pIsolate);
+
+ public:
+ v8::Isolate* m_pIsolate;
+ v8::Global<v8::FunctionTemplate> m_hRootContextGlobalTemplate;
+ v8::Global<v8::Context> m_hRootContext;
+
+ public:
+ static CFXJSE_RuntimeList* g_RuntimeList;
+
+ protected:
+ CFXJSE_RuntimeData();
+ CFXJSE_RuntimeData(const CFXJSE_RuntimeData&);
+ CFXJSE_RuntimeData& operator=(const CFXJSE_RuntimeData&);
+};
+class CFXJSE_RuntimeList {
+ public:
+ typedef void (*RuntimeDisposeCallback)(v8::Isolate*);
+
+ public:
+ void AppendRuntime(v8::Isolate* pIsolate);
+ void RemoveRuntime(v8::Isolate* pIsolate,
+ RuntimeDisposeCallback lpfnDisposeCallback);
+ void RemoveAllRuntimes(RuntimeDisposeCallback lpfnDisposeCallback);
+
+ protected:
+ CFX_ArrayTemplate<v8::Isolate*> m_RuntimeList;
+};
+#endif
diff --git a/xfa/src/fxjse/src/scope_inline.h b/xfa/src/fxjse/src/scope_inline.h
index b02c73afb7..f7e1cdf146 100644
--- a/xfa/src/fxjse/src/scope_inline.h
+++ b/xfa/src/fxjse/src/scope_inline.h
@@ -1,105 +1,105 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#ifndef FXJSE_SCOPE_INLINE_H_
-#define FXJSE_SCOPE_INLINE_H_
-#include "runtime.h"
-#include "context.h"
-class CFXJSE_ScopeUtil_IsolateHandle {
- protected:
- v8::Isolate* m_isolate;
- v8::Locker m_locker;
- v8::Isolate::Scope m_iscope;
- v8::HandleScope m_hscope;
-
- public:
- explicit CFXJSE_ScopeUtil_IsolateHandle(v8::Isolate* pIsolate)
- : m_isolate(pIsolate),
- m_locker(pIsolate),
- m_iscope(pIsolate),
- m_hscope(pIsolate) {}
- v8::Isolate* GetIsolate() { return m_isolate; }
-
- private:
- CFXJSE_ScopeUtil_IsolateHandle(const CFXJSE_ScopeUtil_IsolateHandle&);
- void operator=(const CFXJSE_ScopeUtil_IsolateHandle&);
- void* operator new(size_t size);
- void operator delete(void*, size_t);
-};
-class CFXJSE_ScopeUtil_IsolateHandleRootContext {
- CFXJSE_ScopeUtil_IsolateHandle m_parent;
- v8::Context::Scope m_cscope;
-
- public:
- explicit CFXJSE_ScopeUtil_IsolateHandleRootContext(v8::Isolate* pIsolate)
- : m_parent(pIsolate),
- m_cscope(v8::Local<v8::Context>::New(
- pIsolate,
- CFXJSE_RuntimeData::Get(pIsolate)->m_hRootContext)) {}
-
- private:
- CFXJSE_ScopeUtil_IsolateHandleRootContext(
- const CFXJSE_ScopeUtil_IsolateHandleRootContext&);
- void operator=(const CFXJSE_ScopeUtil_IsolateHandleRootContext&);
- void* operator new(size_t size);
- void operator delete(void*, size_t);
-};
-class CFXJSE_ScopeUtil_IsolateHandleContext {
- CFXJSE_Context* m_context;
- CFXJSE_ScopeUtil_IsolateHandle m_parent;
- v8::Context::Scope m_cscope;
-
- public:
- explicit CFXJSE_ScopeUtil_IsolateHandleContext(CFXJSE_Context* pContext)
- : m_context(pContext),
- m_parent(pContext->m_pIsolate),
- m_cscope(v8::Local<v8::Context>::New(pContext->m_pIsolate,
- pContext->m_hContext)) {}
- v8::Isolate* GetIsolate() { return m_context->m_pIsolate; }
- v8::Local<v8::Context> GetLocalContext() {
- return v8::Local<v8::Context>::New(m_context->m_pIsolate,
- m_context->m_hContext);
- }
-
- private:
- CFXJSE_ScopeUtil_IsolateHandleContext(
- const CFXJSE_ScopeUtil_IsolateHandleContext&);
- void operator=(const CFXJSE_ScopeUtil_IsolateHandleContext&);
- void* operator new(size_t size);
- void operator delete(void*, size_t);
-};
-class CFXJSE_ScopeUtil_IsolateHandleRootOrNormalContext {
- CFXJSE_Context* m_context;
- CFXJSE_ScopeUtil_IsolateHandle m_parent;
- v8::Context::Scope m_cscope;
-
- public:
- explicit CFXJSE_ScopeUtil_IsolateHandleRootOrNormalContext(
- v8::Isolate* pIsolate,
- CFXJSE_Context* pContext)
- : m_context(pContext),
- m_parent(pIsolate),
- m_cscope(v8::Local<v8::Context>::New(
- pIsolate,
- pContext ? pContext->m_hContext
- : CFXJSE_RuntimeData::Get(pIsolate)->m_hRootContext)) {}
- v8::Isolate* GetIsolate() { return m_parent.GetIsolate(); }
- v8::Local<v8::Context> GetLocalContext() {
- v8::Isolate* pIsolate = m_parent.GetIsolate();
- return v8::Local<v8::Context>::New(
- pIsolate, m_context
- ? m_context->m_hContext
- : CFXJSE_RuntimeData::Get(pIsolate)->m_hRootContext);
- }
-
- private:
- CFXJSE_ScopeUtil_IsolateHandleRootOrNormalContext(
- const CFXJSE_ScopeUtil_IsolateHandleRootOrNormalContext&);
- void operator=(const CFXJSE_ScopeUtil_IsolateHandleRootOrNormalContext&);
- void* operator new(size_t size);
- void operator delete(void*, size_t);
-};
-#endif
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef FXJSE_SCOPE_INLINE_H_
+#define FXJSE_SCOPE_INLINE_H_
+#include "runtime.h"
+#include "context.h"
+class CFXJSE_ScopeUtil_IsolateHandle {
+ protected:
+ v8::Isolate* m_isolate;
+ v8::Locker m_locker;
+ v8::Isolate::Scope m_iscope;
+ v8::HandleScope m_hscope;
+
+ public:
+ explicit CFXJSE_ScopeUtil_IsolateHandle(v8::Isolate* pIsolate)
+ : m_isolate(pIsolate),
+ m_locker(pIsolate),
+ m_iscope(pIsolate),
+ m_hscope(pIsolate) {}
+ v8::Isolate* GetIsolate() { return m_isolate; }
+
+ private:
+ CFXJSE_ScopeUtil_IsolateHandle(const CFXJSE_ScopeUtil_IsolateHandle&);
+ void operator=(const CFXJSE_ScopeUtil_IsolateHandle&);
+ void* operator new(size_t size);
+ void operator delete(void*, size_t);
+};
+class CFXJSE_ScopeUtil_IsolateHandleRootContext {
+ CFXJSE_ScopeUtil_IsolateHandle m_parent;
+ v8::Context::Scope m_cscope;
+
+ public:
+ explicit CFXJSE_ScopeUtil_IsolateHandleRootContext(v8::Isolate* pIsolate)
+ : m_parent(pIsolate),
+ m_cscope(v8::Local<v8::Context>::New(
+ pIsolate,
+ CFXJSE_RuntimeData::Get(pIsolate)->m_hRootContext)) {}
+
+ private:
+ CFXJSE_ScopeUtil_IsolateHandleRootContext(
+ const CFXJSE_ScopeUtil_IsolateHandleRootContext&);
+ void operator=(const CFXJSE_ScopeUtil_IsolateHandleRootContext&);
+ void* operator new(size_t size);
+ void operator delete(void*, size_t);
+};
+class CFXJSE_ScopeUtil_IsolateHandleContext {
+ CFXJSE_Context* m_context;
+ CFXJSE_ScopeUtil_IsolateHandle m_parent;
+ v8::Context::Scope m_cscope;
+
+ public:
+ explicit CFXJSE_ScopeUtil_IsolateHandleContext(CFXJSE_Context* pContext)
+ : m_context(pContext),
+ m_parent(pContext->m_pIsolate),
+ m_cscope(v8::Local<v8::Context>::New(pContext->m_pIsolate,
+ pContext->m_hContext)) {}
+ v8::Isolate* GetIsolate() { return m_context->m_pIsolate; }
+ v8::Local<v8::Context> GetLocalContext() {
+ return v8::Local<v8::Context>::New(m_context->m_pIsolate,
+ m_context->m_hContext);
+ }
+
+ private:
+ CFXJSE_ScopeUtil_IsolateHandleContext(
+ const CFXJSE_ScopeUtil_IsolateHandleContext&);
+ void operator=(const CFXJSE_ScopeUtil_IsolateHandleContext&);
+ void* operator new(size_t size);
+ void operator delete(void*, size_t);
+};
+class CFXJSE_ScopeUtil_IsolateHandleRootOrNormalContext {
+ CFXJSE_Context* m_context;
+ CFXJSE_ScopeUtil_IsolateHandle m_parent;
+ v8::Context::Scope m_cscope;
+
+ public:
+ explicit CFXJSE_ScopeUtil_IsolateHandleRootOrNormalContext(
+ v8::Isolate* pIsolate,
+ CFXJSE_Context* pContext)
+ : m_context(pContext),
+ m_parent(pIsolate),
+ m_cscope(v8::Local<v8::Context>::New(
+ pIsolate,
+ pContext ? pContext->m_hContext
+ : CFXJSE_RuntimeData::Get(pIsolate)->m_hRootContext)) {}
+ v8::Isolate* GetIsolate() { return m_parent.GetIsolate(); }
+ v8::Local<v8::Context> GetLocalContext() {
+ v8::Isolate* pIsolate = m_parent.GetIsolate();
+ return v8::Local<v8::Context>::New(
+ pIsolate, m_context
+ ? m_context->m_hContext
+ : CFXJSE_RuntimeData::Get(pIsolate)->m_hRootContext);
+ }
+
+ private:
+ CFXJSE_ScopeUtil_IsolateHandleRootOrNormalContext(
+ const CFXJSE_ScopeUtil_IsolateHandleRootOrNormalContext&);
+ void operator=(const CFXJSE_ScopeUtil_IsolateHandleRootOrNormalContext&);
+ void* operator new(size_t size);
+ void operator delete(void*, size_t);
+};
+#endif
diff --git a/xfa/src/fxjse/src/util_inline.h b/xfa/src/fxjse/src/util_inline.h
index 80034aa9c2..3ab12c1ef4 100644
--- a/xfa/src/fxjse/src/util_inline.h
+++ b/xfa/src/fxjse/src/util_inline.h
@@ -1,47 +1,47 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#ifndef FXJSE_UTIL_INLINE_H_
-#define FXJSE_UTIL_INLINE_H_
-static V8_INLINE v8::Local<v8::Object> FXJSE_GetGlobalObjectFromContext(
- const v8::Local<v8::Context>& hContext) {
- return hContext->Global()->GetPrototype().As<v8::Object>();
-}
-static V8_INLINE void FXJSE_UpdateObjectBinding(v8::Local<v8::Object>& hObject,
- void* lpNewBinding) {
- ASSERT(!hObject.IsEmpty());
- ASSERT(hObject->InternalFieldCount() > 0);
- hObject->SetAlignedPointerInInternalField(0, lpNewBinding);
-}
-static V8_INLINE void* FXJSE_RetrieveObjectBinding(
- const v8::Local<v8::Object>& hJSObject,
- CFXJSE_Class* lpClass = NULL) {
- ASSERT(!hJSObject.IsEmpty());
- if (!hJSObject->IsObject()) {
- return NULL;
- }
- v8::Local<v8::Object> hObject = hJSObject;
- if (hObject->InternalFieldCount() == 0) {
- v8::Local<v8::Value> hProtoObject = hObject->GetPrototype();
- if (hProtoObject.IsEmpty() || !hProtoObject->IsObject()) {
- return NULL;
- }
- hObject = hProtoObject.As<v8::Object>();
- if (hObject->InternalFieldCount() == 0) {
- return NULL;
- }
- }
- if (lpClass) {
- v8::Local<v8::FunctionTemplate> hClass =
- v8::Local<v8::FunctionTemplate>::New(
- lpClass->GetContext()->GetRuntime(), lpClass->GetTemplate());
- if (!hClass->HasInstance(hObject)) {
- return NULL;
- }
- }
- return hObject->GetAlignedPointerFromInternalField(0);
-}
-#endif
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef FXJSE_UTIL_INLINE_H_
+#define FXJSE_UTIL_INLINE_H_
+static V8_INLINE v8::Local<v8::Object> FXJSE_GetGlobalObjectFromContext(
+ const v8::Local<v8::Context>& hContext) {
+ return hContext->Global()->GetPrototype().As<v8::Object>();
+}
+static V8_INLINE void FXJSE_UpdateObjectBinding(v8::Local<v8::Object>& hObject,
+ void* lpNewBinding) {
+ ASSERT(!hObject.IsEmpty());
+ ASSERT(hObject->InternalFieldCount() > 0);
+ hObject->SetAlignedPointerInInternalField(0, lpNewBinding);
+}
+static V8_INLINE void* FXJSE_RetrieveObjectBinding(
+ const v8::Local<v8::Object>& hJSObject,
+ CFXJSE_Class* lpClass = NULL) {
+ ASSERT(!hJSObject.IsEmpty());
+ if (!hJSObject->IsObject()) {
+ return NULL;
+ }
+ v8::Local<v8::Object> hObject = hJSObject;
+ if (hObject->InternalFieldCount() == 0) {
+ v8::Local<v8::Value> hProtoObject = hObject->GetPrototype();
+ if (hProtoObject.IsEmpty() || !hProtoObject->IsObject()) {
+ return NULL;
+ }
+ hObject = hProtoObject.As<v8::Object>();
+ if (hObject->InternalFieldCount() == 0) {
+ return NULL;
+ }
+ }
+ if (lpClass) {
+ v8::Local<v8::FunctionTemplate> hClass =
+ v8::Local<v8::FunctionTemplate>::New(
+ lpClass->GetContext()->GetRuntime(), lpClass->GetTemplate());
+ if (!hClass->HasInstance(hObject)) {
+ return NULL;
+ }
+ }
+ return hObject->GetAlignedPointerFromInternalField(0);
+}
+#endif
diff --git a/xfa/src/fxjse/src/value.cpp b/xfa/src/fxjse/src/value.cpp
index a482fb04b2..35c6169332 100644
--- a/xfa/src/fxjse/src/value.cpp
+++ b/xfa/src/fxjse/src/value.cpp
@@ -1,544 +1,544 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "xfa/src/foxitlib.h"
-#include "fxv8.h"
-#include "value.h"
-#include "class.h"
-#include <math.h>
-#include "util_inline.h"
-FX_BOOL FXJSE_Value_IsUndefined(FXJSE_HVALUE hValue) {
- CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
- return lpValue && lpValue->IsUndefined();
-}
-FX_BOOL FXJSE_Value_IsNull(FXJSE_HVALUE hValue) {
- CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
- return lpValue && lpValue->IsNull();
-}
-FX_BOOL FXJSE_Value_IsBoolean(FXJSE_HVALUE hValue) {
- CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
- return lpValue && lpValue->IsBoolean();
-}
-FX_BOOL FXJSE_Value_IsUTF8String(FXJSE_HVALUE hValue) {
- CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
- return lpValue && lpValue->IsString();
-}
-FX_BOOL FXJSE_Value_IsNumber(FXJSE_HVALUE hValue) {
- CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
- return lpValue && lpValue->IsNumber();
-}
-FX_BOOL FXJSE_Value_IsInteger(FXJSE_HVALUE hValue) {
- CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
- return lpValue && lpValue->IsInteger();
-}
-FX_BOOL FXJSE_Value_IsObject(FXJSE_HVALUE hValue) {
- CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
- return lpValue && lpValue->IsObject();
-}
-FX_BOOL FXJSE_Value_IsArray(FXJSE_HVALUE hValue) {
- CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
- return lpValue && lpValue->IsArray();
-}
-FX_BOOL FXJSE_Value_IsFunction(FXJSE_HVALUE hValue) {
- CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
- return lpValue && lpValue->IsFunction();
-}
-FX_BOOL FXJSE_Value_IsDate(FXJSE_HVALUE hValue) {
- CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
- return lpValue && lpValue->IsDate();
-}
-FX_BOOL FXJSE_Value_ToBoolean(FXJSE_HVALUE hValue) {
- CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
- ASSERT(lpValue);
- return lpValue->ToBoolean();
-}
-FX_FLOAT FXJSE_Value_ToFloat(FXJSE_HVALUE hValue) {
- CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
- ASSERT(lpValue);
- return lpValue->ToFloat();
-}
-FXJSE_DOUBLE FXJSE_Value_ToDouble(FXJSE_HVALUE hValue) {
- CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
- ASSERT(lpValue);
- return lpValue->ToDouble();
-}
-void FXJSE_Value_ToUTF8String(FXJSE_HVALUE hValue,
- CFX_ByteString& szStrOutput) {
- CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
- ASSERT(lpValue);
- return lpValue->ToString(szStrOutput);
-}
-int32_t FXJSE_Value_ToInteger(FXJSE_HVALUE hValue) {
- CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
- ASSERT(lpValue);
- return lpValue->ToInteger();
-}
-void* FXJSE_Value_ToObject(FXJSE_HVALUE hValue, FXJSE_HCLASS hClass) {
- CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
- CFXJSE_Class* lpClass = reinterpret_cast<CFXJSE_Class*>(hClass);
- ASSERT(lpValue);
- return lpValue->ToObject(lpClass);
-}
-void FXJSE_Value_SetUndefined(FXJSE_HVALUE hValue) {
- CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
- ASSERT(lpValue);
- return lpValue->SetUndefined();
-}
-void FXJSE_Value_SetNull(FXJSE_HVALUE hValue) {
- CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
- ASSERT(lpValue);
- return lpValue->SetNull();
-}
-void FXJSE_Value_SetBoolean(FXJSE_HVALUE hValue, FX_BOOL bBoolean) {
- CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
- ASSERT(lpValue);
- return lpValue->SetBoolean(bBoolean);
-}
-void FXJSE_Value_SetUTF8String(FXJSE_HVALUE hValue,
- const CFX_ByteStringC& szString) {
- CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
- ASSERT(lpValue);
- return lpValue->SetString(szString);
-}
-void FXJSE_Value_SetInteger(FXJSE_HVALUE hValue, int32_t nInteger) {
- CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
- ASSERT(lpValue);
- return lpValue->SetInteger(nInteger);
-}
-void FXJSE_Value_SetFloat(FXJSE_HVALUE hValue, FX_FLOAT fFloat) {
- CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
- ASSERT(lpValue);
- return lpValue->SetFloat(fFloat);
-}
-void FXJSE_Value_SetDouble(FXJSE_HVALUE hValue, FXJSE_DOUBLE dDouble) {
- CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
- ASSERT(lpValue);
- return lpValue->SetDouble(dDouble);
-}
-void FXJSE_Value_SetObject(FXJSE_HVALUE hValue,
- void* lpObject,
- FXJSE_HCLASS hClass) {
- CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
- CFXJSE_Class* lpClass = reinterpret_cast<CFXJSE_Class*>(hClass);
- if (lpClass == NULL) {
- ASSERT(lpObject == NULL);
- lpValue->SetJSObject();
- } else if (lpClass != NULL) {
- lpValue->SetHostObject(lpObject, lpClass);
- }
-}
-void FXJSE_Value_SetArray(FXJSE_HVALUE hValue,
- uint32_t uValueCount,
- FXJSE_HVALUE* rgValues) {
- CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
- return lpValue->SetArray(uValueCount,
- reinterpret_cast<CFXJSE_Value**>(rgValues));
-}
-void FXJSE_Value_SetDate(FXJSE_HVALUE hValue, FXJSE_DOUBLE dDouble) {
- CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
- return lpValue->SetDate(dDouble);
-}
-void FXJSE_Value_Set(FXJSE_HVALUE hValue, FXJSE_HVALUE hOriginalValue) {
- CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
- CFXJSE_Value* lpOriginalValue =
- reinterpret_cast<CFXJSE_Value*>(hOriginalValue);
- ASSERT(lpValue && lpOriginalValue);
- return lpValue->Assign(lpOriginalValue);
-}
-FX_BOOL FXJSE_Value_GetObjectProp(FXJSE_HVALUE hValue,
- const CFX_ByteStringC& szPropName,
- FXJSE_HVALUE hPropValue) {
- CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
- CFXJSE_Value* lpPropValue = reinterpret_cast<CFXJSE_Value*>(hPropValue);
- ASSERT(lpValue && lpPropValue);
- return lpValue->GetObjectProperty(szPropName, lpPropValue);
-}
-FX_BOOL FXJSE_Value_SetObjectProp(FXJSE_HVALUE hValue,
- const CFX_ByteStringC& szPropName,
- FXJSE_HVALUE hPropValue) {
- CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
- CFXJSE_Value* lpPropValue = reinterpret_cast<CFXJSE_Value*>(hPropValue);
- ASSERT(lpValue && lpPropValue);
- return lpValue->SetObjectProperty(szPropName, lpPropValue);
-}
-FX_BOOL FXJSE_Value_GetObjectPropByIdx(FXJSE_HVALUE hValue,
- uint32_t uPropIdx,
- FXJSE_HVALUE hPropValue) {
- CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
- CFXJSE_Value* lpPropValue = reinterpret_cast<CFXJSE_Value*>(hPropValue);
- ASSERT(lpValue && lpPropValue);
- return lpValue->GetObjectProperty(uPropIdx, lpPropValue);
-}
-FX_BOOL FXJSE_Value_SetObjectPropByIdx(FXJSE_HVALUE hValue,
- uint32_t uPropIdx,
- FXJSE_HVALUE hPropValue) {
- CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
- CFXJSE_Value* lpPropValue = reinterpret_cast<CFXJSE_Value*>(hPropValue);
- ASSERT(lpValue && lpPropValue);
- return lpValue->SetObjectProperty(uPropIdx, lpPropValue);
-}
-FX_BOOL FXJSE_Value_DeleteObjectProp(FXJSE_HVALUE hValue,
- const CFX_ByteStringC& szPropName) {
- CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
- ASSERT(lpValue);
- return lpValue->DeleteObjectProperty(szPropName);
-}
-FX_BOOL FXJSE_Value_ObjectHasOwnProp(FXJSE_HVALUE hValue,
- const CFX_ByteStringC& szPropName,
- FX_BOOL bUseTypeGetter) {
- CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
- ASSERT(lpValue);
- return lpValue->HasObjectOwnProperty(szPropName, bUseTypeGetter);
-}
-FX_BOOL FXJSE_Value_SetObjectOwnProp(FXJSE_HVALUE hValue,
- const CFX_ByteStringC& szPropName,
- FXJSE_HVALUE hPropValue) {
- CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
- CFXJSE_Value* lpPropValue = reinterpret_cast<CFXJSE_Value*>(hPropValue);
- ASSERT(lpValue && lpPropValue);
- return lpValue->SetObjectOwnProperty(szPropName, lpPropValue);
-}
-FX_BOOL FXJSE_Value_SetFunctionBind(FXJSE_HVALUE hValue,
- FXJSE_HVALUE hOldFunction,
- FXJSE_HVALUE hNewThis) {
- CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
- CFXJSE_Value* lpOldFunction = reinterpret_cast<CFXJSE_Value*>(hOldFunction);
- CFXJSE_Value* lpNewThis = reinterpret_cast<CFXJSE_Value*>(hNewThis);
- ASSERT(lpValue && lpOldFunction && lpNewThis);
- return lpValue->SetFunctionBind(lpOldFunction, lpNewThis);
-}
-FX_BOOL FXJSE_Value_CallFunction(FXJSE_HVALUE hFunction,
- FXJSE_HVALUE hThis,
- FXJSE_HVALUE hRetValue,
- uint32_t nArgCount,
- FXJSE_HVALUE* lpArgs) {
- CFXJSE_Value* lpFunction = reinterpret_cast<CFXJSE_Value*>(hFunction);
- CFXJSE_Value* lpThis = reinterpret_cast<CFXJSE_Value*>(hThis);
- CFXJSE_Value* lpRetValue = reinterpret_cast<CFXJSE_Value*>(hRetValue);
- ASSERT(lpFunction);
- return lpFunction->Call(lpThis, lpRetValue, nArgCount, lpArgs);
-}
-FXJSE_HVALUE FXJSE_Value_Create(FXJSE_HRUNTIME hRuntime) {
- CFXJSE_Value* lpValue =
- CFXJSE_Value::Create(reinterpret_cast<v8::Isolate*>(hRuntime));
- ASSERT(lpValue);
- return reinterpret_cast<FXJSE_HVALUE>(lpValue);
-}
-void FXJSE_Value_Release(FXJSE_HVALUE hValue) {
- CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
- if (lpValue) {
- delete lpValue;
- }
-}
-FXJSE_HRUNTIME FXJSE_Value_GetRuntime(FXJSE_HVALUE hValue) {
- CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
- ASSERT(lpValue);
- return reinterpret_cast<FXJSE_HRUNTIME>(lpValue->GetIsolate());
-}
-void FXJSE_ThrowMessage(const CFX_ByteStringC& utf8Name,
- const CFX_ByteStringC& utf8Message) {
- v8::Isolate* pIsolate = v8::Isolate::GetCurrent();
- ASSERT(pIsolate);
- CFXJSE_ScopeUtil_IsolateHandleRootContext scope(pIsolate);
- v8::Local<v8::String> hMessage = v8::String::NewFromUtf8(
- pIsolate, utf8Message.GetCStr(), v8::String::kNormalString,
- utf8Message.GetLength());
- v8::Local<v8::Value> hError;
- if (utf8Name == "RangeError") {
- hError = v8::Exception::RangeError(hMessage);
- } else if (utf8Name == "ReferenceError") {
- hError = v8::Exception::ReferenceError(hMessage);
- } else if (utf8Name == "SyntaxError") {
- hError = v8::Exception::SyntaxError(hMessage);
- } else if (utf8Name == "TypeError") {
- hError = v8::Exception::TypeError(hMessage);
- } else {
- hError = v8::Exception::Error(hMessage);
- if (utf8Name != "Error" && !utf8Name.IsEmpty()) {
- hError.As<v8::Object>()->Set(
- v8::String::NewFromUtf8(pIsolate, "name"),
- v8::String::NewFromUtf8(pIsolate, utf8Name.GetCStr(),
- v8::String::kNormalString,
- utf8Name.GetLength()));
- }
- }
- pIsolate->ThrowException(hError);
-}
-CFXJSE_Value* CFXJSE_Value::Create(v8::Isolate* pIsolate) {
- return new CFXJSE_Value(pIsolate);
-}
-void* CFXJSE_Value::ToObject(CFXJSE_Class* lpClass) const {
- ASSERT(!m_hValue.IsEmpty());
- CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate);
- v8::Local<v8::Value> hValue = v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
- ASSERT(!hValue.IsEmpty());
- if (!hValue->IsObject()) {
- return NULL;
- }
- return FXJSE_RetrieveObjectBinding(hValue.As<v8::Object>(), lpClass);
-}
-V8_INLINE static double FXJSE_ftod(FX_FLOAT fNumber) {
- if (sizeof(FX_FLOAT) != 4) {
- ASSERT(FALSE);
- return fNumber;
- }
- uint32_t nFloatBits = (uint32_t&)fNumber;
- uint8_t nExponent = (uint8_t)(nFloatBits >> 16 >> 7);
- if (nExponent == 0 || nExponent == 255) {
- return fNumber;
- }
- int8_t nErrExp = nExponent - 127 - 23;
- if (nErrExp >= 0) {
- return fNumber;
- }
- double dwError = pow(2.0, nErrExp), dwErrorHalf = dwError / 2;
- double dNumber = fNumber, dNumberAbs = fabs(fNumber);
- double dNumberAbsMin = dNumberAbs - dwErrorHalf,
- dNumberAbsMax = dNumberAbs + dwErrorHalf;
- int32_t iErrPos = 0;
- if (floor(dNumberAbsMin) == floor(dNumberAbsMax)) {
- dNumberAbsMin = fmod(dNumberAbsMin, 1.0);
- dNumberAbsMax = fmod(dNumberAbsMax, 1.0);
- int32_t iErrPosMin = 1, iErrPosMax = 38;
- do {
- int32_t iMid = (iErrPosMin + iErrPosMax) / 2;
- double dPow = pow(10.0, iMid);
- if (floor(dNumberAbsMin * dPow) == floor(dNumberAbsMax * dPow)) {
- iErrPosMin = iMid + 1;
- } else {
- iErrPosMax = iMid;
- }
- } while (iErrPosMin < iErrPosMax);
- iErrPos = iErrPosMax;
- }
- double dPow = pow(10.0, iErrPos);
- return fNumber < 0 ? ceil(dNumber * dPow - 0.5) / dPow
- : floor(dNumber * dPow + 0.5) / dPow;
-}
-void CFXJSE_Value::SetFloat(FX_FLOAT fFloat) {
- CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate);
- v8::Local<v8::Value> hValue = v8::Number::New(m_pIsolate, FXJSE_ftod(fFloat));
- m_hValue.Reset(m_pIsolate, hValue);
-}
-void CFXJSE_Value::SetHostObject(void* lpObject, CFXJSE_Class* lpClass) {
- CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate);
- ASSERT(lpClass);
- v8::Local<v8::FunctionTemplate> hClass =
- v8::Local<v8::FunctionTemplate>::New(m_pIsolate, lpClass->m_hTemplate);
- v8::Local<v8::Object> hObject = hClass->InstanceTemplate()->NewInstance();
- FXJSE_UpdateObjectBinding(hObject, lpObject);
- m_hValue.Reset(m_pIsolate, hObject);
-}
-void CFXJSE_Value::SetArray(uint32_t uValueCount, CFXJSE_Value** rgValues) {
- CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate);
- v8::Local<v8::Array> hArrayObject = v8::Array::New(m_pIsolate, uValueCount);
- if (rgValues) {
- for (uint32_t i = 0; i < uValueCount; i++) {
- if (rgValues[i]) {
- hArrayObject->Set(i, v8::Local<v8::Value>::New(
- m_pIsolate, rgValues[i]->DirectGetValue()));
- }
- }
- }
- m_hValue.Reset(m_pIsolate, hArrayObject);
-}
-void CFXJSE_Value::SetDate(FXJSE_DOUBLE dDouble) {
- CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate);
- v8::Local<v8::Value> hDate = v8::Date::New(m_pIsolate, dDouble);
- m_hValue.Reset(m_pIsolate, hDate);
-}
-FX_BOOL CFXJSE_Value::SetObjectProperty(const CFX_ByteStringC& szPropName,
- CFXJSE_Value* lpPropValue) {
- CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate);
- v8::Local<v8::Value> hObject =
- v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
- if (!hObject->IsObject()) {
- return FALSE;
- }
- v8::Local<v8::Value> hPropValue =
- v8::Local<v8::Value>::New(m_pIsolate, lpPropValue->DirectGetValue());
- return (FX_BOOL)hObject.As<v8::Object>()->Set(
- v8::String::NewFromUtf8(m_pIsolate, szPropName.GetCStr(),
- v8::String::kNormalString,
- szPropName.GetLength()),
- hPropValue);
-}
-FX_BOOL CFXJSE_Value::GetObjectProperty(const CFX_ByteStringC& szPropName,
- CFXJSE_Value* lpPropValue) {
- CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate);
- v8::Local<v8::Value> hObject =
- v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
- if (!hObject->IsObject()) {
- return FALSE;
- }
- v8::Local<v8::Value> hPropValue =
- hObject.As<v8::Object>()->Get(v8::String::NewFromUtf8(
- m_pIsolate, szPropName.GetCStr(), v8::String::kNormalString,
- szPropName.GetLength()));
- lpPropValue->ForceSetValue(hPropValue);
- return TRUE;
-}
-FX_BOOL CFXJSE_Value::SetObjectProperty(uint32_t uPropIdx,
- CFXJSE_Value* lpPropValue) {
- CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate);
- v8::Local<v8::Value> hObject =
- v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
- if (!hObject->IsObject()) {
- return FALSE;
- }
- v8::Local<v8::Value> hPropValue =
- v8::Local<v8::Value>::New(m_pIsolate, lpPropValue->DirectGetValue());
- return (FX_BOOL)hObject.As<v8::Object>()->Set(uPropIdx, hPropValue);
-}
-FX_BOOL CFXJSE_Value::GetObjectProperty(uint32_t uPropIdx,
- CFXJSE_Value* lpPropValue) {
- CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate);
- v8::Local<v8::Value> hObject =
- v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
- if (!hObject->IsObject()) {
- return FALSE;
- }
- v8::Local<v8::Value> hPropValue = hObject.As<v8::Object>()->Get(uPropIdx);
- lpPropValue->ForceSetValue(hPropValue);
- return TRUE;
-}
-FX_BOOL CFXJSE_Value::DeleteObjectProperty(const CFX_ByteStringC& szPropName) {
- CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate);
- v8::Local<v8::Value> hObject =
- v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
- if (!hObject->IsObject()) {
- return FALSE;
- }
- hObject.As<v8::Object>()->Delete(v8::String::NewFromUtf8(
- m_pIsolate, szPropName.GetCStr(), v8::String::kNormalString,
- szPropName.GetLength()));
- return TRUE;
-}
-FX_BOOL CFXJSE_Value::HasObjectOwnProperty(const CFX_ByteStringC& szPropName,
- FX_BOOL bUseTypeGetter) {
- CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate);
- v8::Local<v8::Value> hObject =
- v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
- if (!hObject->IsObject()) {
- return FALSE;
- }
- v8::Local<v8::String> hKey = v8::String::NewFromUtf8(
- m_pIsolate, szPropName.GetCStr(), v8::String::kNormalString,
- szPropName.GetLength());
- return hObject.As<v8::Object>()->HasRealNamedProperty(hKey) ||
- (bUseTypeGetter && hObject.As<v8::Object>()->HasOwnProperty(hKey));
-}
-FX_BOOL CFXJSE_Value::SetObjectOwnProperty(const CFX_ByteStringC& szPropName,
- CFXJSE_Value* lpPropValue) {
- CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate);
- v8::Local<v8::Value> hObject =
- v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
- if (!hObject->IsObject()) {
- return FALSE;
- }
- v8::Local<v8::Value> hValue =
- v8::Local<v8::Value>::New(m_pIsolate, lpPropValue->m_hValue);
- return hObject.As<v8::Object>()->ForceSet(
- v8::String::NewFromUtf8(m_pIsolate, szPropName.GetCStr(),
- v8::String::kNormalString,
- szPropName.GetLength()),
- hValue);
-}
-FX_BOOL CFXJSE_Value::SetFunctionBind(CFXJSE_Value* lpOldFunction,
- CFXJSE_Value* lpNewThis) {
- CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate);
- v8::Local<v8::Value> rgArgs[2];
- v8::Local<v8::Value> hOldFunction =
- v8::Local<v8::Value>::New(m_pIsolate, lpOldFunction->DirectGetValue());
- if (hOldFunction.IsEmpty() || !hOldFunction->IsFunction()) {
- return FALSE;
- }
- rgArgs[0] = hOldFunction;
- v8::Local<v8::Value> hNewThis =
- v8::Local<v8::Value>::New(m_pIsolate, lpNewThis->DirectGetValue());
- if (hNewThis.IsEmpty()) {
- return FALSE;
- }
- rgArgs[1] = hNewThis;
- v8::Local<v8::String> hBinderFuncSource =
- v8::String::NewFromUtf8(m_pIsolate,
- "(function (oldfunction, newthis) { return "
- "oldfunction.bind(newthis); })");
- v8::Local<v8::Function> hBinderFunc =
- v8::Script::Compile(hBinderFuncSource)->Run().As<v8::Function>();
- v8::Local<v8::Value> hBoundFunction =
- hBinderFunc->Call(m_pIsolate->GetCurrentContext()->Global(), 2, rgArgs);
- if (hBoundFunction.IsEmpty() || !hBoundFunction->IsFunction()) {
- return FALSE;
- }
- m_hValue.Reset(m_pIsolate, hBoundFunction);
- return TRUE;
-}
-#define FXJSE_INVALID_PTR ((void*)(intptr_t)-1)
-FX_BOOL CFXJSE_Value::Call(CFXJSE_Value* lpReceiver,
- CFXJSE_Value* lpRetValue,
- uint32_t nArgCount,
- FXJSE_HVALUE* lpArgs) {
- CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate);
- v8::Local<v8::Value> hFunctionValue =
- v8::Local<v8::Value>::New(m_pIsolate, DirectGetValue());
- v8::Local<v8::Object> hFunctionObject =
- !hFunctionValue.IsEmpty() && hFunctionValue->IsObject()
- ? hFunctionValue.As<v8::Object>()
- : v8::Local<v8::Object>();
- v8::TryCatch trycatch;
- if (hFunctionObject.IsEmpty() || !hFunctionObject->IsCallable()) {
- if (lpRetValue) {
- lpRetValue->ForceSetValue(FXJSE_CreateReturnValue(m_pIsolate, trycatch));
- }
- return FALSE;
- }
- v8::Local<v8::Value> hReturnValue;
- v8::Local<v8::Value>* lpLocalArgs = NULL;
- if (nArgCount) {
- lpLocalArgs = FX_Alloc(v8::Local<v8::Value>, nArgCount);
- for (uint32_t i = 0; i < nArgCount; i++) {
- new (lpLocalArgs + i) v8::Local<v8::Value>;
- CFXJSE_Value* lpArg = (CFXJSE_Value*)lpArgs[i];
- if (lpArg) {
- lpLocalArgs[i] =
- v8::Local<v8::Value>::New(m_pIsolate, lpArg->DirectGetValue());
- }
- if (lpLocalArgs[i].IsEmpty()) {
- lpLocalArgs[i] = v8::Undefined(m_pIsolate);
- }
- }
- }
- FX_BOOL bRetValue = TRUE;
- if (lpReceiver == FXJSE_INVALID_PTR) {
- hReturnValue = hFunctionObject->CallAsConstructor(nArgCount, lpLocalArgs);
- } else {
- v8::Local<v8::Value> hReceiver;
- if (lpReceiver) {
- hReceiver =
- v8::Local<v8::Value>::New(m_pIsolate, lpReceiver->DirectGetValue());
- }
- if (hReceiver.IsEmpty() || !hReceiver->IsObject()) {
- hReceiver = v8::Object::New(m_pIsolate);
- }
- hReturnValue =
- hFunctionObject->CallAsFunction(hReceiver, nArgCount, lpLocalArgs);
- }
- if (trycatch.HasCaught()) {
- hReturnValue = FXJSE_CreateReturnValue(m_pIsolate, trycatch);
- bRetValue = FALSE;
- }
- if (lpRetValue) {
- lpRetValue->ForceSetValue(hReturnValue);
- }
- if (lpLocalArgs) {
- for (uint32_t i = 0; i < nArgCount; i++) {
- lpLocalArgs[i].~Local();
- }
- FX_Free(lpLocalArgs);
- }
- return bRetValue;
-}
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "xfa/src/foxitlib.h"
+#include "fxv8.h"
+#include "value.h"
+#include "class.h"
+#include <math.h>
+#include "util_inline.h"
+FX_BOOL FXJSE_Value_IsUndefined(FXJSE_HVALUE hValue) {
+ CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
+ return lpValue && lpValue->IsUndefined();
+}
+FX_BOOL FXJSE_Value_IsNull(FXJSE_HVALUE hValue) {
+ CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
+ return lpValue && lpValue->IsNull();
+}
+FX_BOOL FXJSE_Value_IsBoolean(FXJSE_HVALUE hValue) {
+ CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
+ return lpValue && lpValue->IsBoolean();
+}
+FX_BOOL FXJSE_Value_IsUTF8String(FXJSE_HVALUE hValue) {
+ CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
+ return lpValue && lpValue->IsString();
+}
+FX_BOOL FXJSE_Value_IsNumber(FXJSE_HVALUE hValue) {
+ CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
+ return lpValue && lpValue->IsNumber();
+}
+FX_BOOL FXJSE_Value_IsInteger(FXJSE_HVALUE hValue) {
+ CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
+ return lpValue && lpValue->IsInteger();
+}
+FX_BOOL FXJSE_Value_IsObject(FXJSE_HVALUE hValue) {
+ CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
+ return lpValue && lpValue->IsObject();
+}
+FX_BOOL FXJSE_Value_IsArray(FXJSE_HVALUE hValue) {
+ CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
+ return lpValue && lpValue->IsArray();
+}
+FX_BOOL FXJSE_Value_IsFunction(FXJSE_HVALUE hValue) {
+ CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
+ return lpValue && lpValue->IsFunction();
+}
+FX_BOOL FXJSE_Value_IsDate(FXJSE_HVALUE hValue) {
+ CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
+ return lpValue && lpValue->IsDate();
+}
+FX_BOOL FXJSE_Value_ToBoolean(FXJSE_HVALUE hValue) {
+ CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
+ ASSERT(lpValue);
+ return lpValue->ToBoolean();
+}
+FX_FLOAT FXJSE_Value_ToFloat(FXJSE_HVALUE hValue) {
+ CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
+ ASSERT(lpValue);
+ return lpValue->ToFloat();
+}
+FXJSE_DOUBLE FXJSE_Value_ToDouble(FXJSE_HVALUE hValue) {
+ CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
+ ASSERT(lpValue);
+ return lpValue->ToDouble();
+}
+void FXJSE_Value_ToUTF8String(FXJSE_HVALUE hValue,
+ CFX_ByteString& szStrOutput) {
+ CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
+ ASSERT(lpValue);
+ return lpValue->ToString(szStrOutput);
+}
+int32_t FXJSE_Value_ToInteger(FXJSE_HVALUE hValue) {
+ CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
+ ASSERT(lpValue);
+ return lpValue->ToInteger();
+}
+void* FXJSE_Value_ToObject(FXJSE_HVALUE hValue, FXJSE_HCLASS hClass) {
+ CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
+ CFXJSE_Class* lpClass = reinterpret_cast<CFXJSE_Class*>(hClass);
+ ASSERT(lpValue);
+ return lpValue->ToObject(lpClass);
+}
+void FXJSE_Value_SetUndefined(FXJSE_HVALUE hValue) {
+ CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
+ ASSERT(lpValue);
+ return lpValue->SetUndefined();
+}
+void FXJSE_Value_SetNull(FXJSE_HVALUE hValue) {
+ CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
+ ASSERT(lpValue);
+ return lpValue->SetNull();
+}
+void FXJSE_Value_SetBoolean(FXJSE_HVALUE hValue, FX_BOOL bBoolean) {
+ CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
+ ASSERT(lpValue);
+ return lpValue->SetBoolean(bBoolean);
+}
+void FXJSE_Value_SetUTF8String(FXJSE_HVALUE hValue,
+ const CFX_ByteStringC& szString) {
+ CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
+ ASSERT(lpValue);
+ return lpValue->SetString(szString);
+}
+void FXJSE_Value_SetInteger(FXJSE_HVALUE hValue, int32_t nInteger) {
+ CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
+ ASSERT(lpValue);
+ return lpValue->SetInteger(nInteger);
+}
+void FXJSE_Value_SetFloat(FXJSE_HVALUE hValue, FX_FLOAT fFloat) {
+ CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
+ ASSERT(lpValue);
+ return lpValue->SetFloat(fFloat);
+}
+void FXJSE_Value_SetDouble(FXJSE_HVALUE hValue, FXJSE_DOUBLE dDouble) {
+ CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
+ ASSERT(lpValue);
+ return lpValue->SetDouble(dDouble);
+}
+void FXJSE_Value_SetObject(FXJSE_HVALUE hValue,
+ void* lpObject,
+ FXJSE_HCLASS hClass) {
+ CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
+ CFXJSE_Class* lpClass = reinterpret_cast<CFXJSE_Class*>(hClass);
+ if (lpClass == NULL) {
+ ASSERT(lpObject == NULL);
+ lpValue->SetJSObject();
+ } else if (lpClass != NULL) {
+ lpValue->SetHostObject(lpObject, lpClass);
+ }
+}
+void FXJSE_Value_SetArray(FXJSE_HVALUE hValue,
+ uint32_t uValueCount,
+ FXJSE_HVALUE* rgValues) {
+ CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
+ return lpValue->SetArray(uValueCount,
+ reinterpret_cast<CFXJSE_Value**>(rgValues));
+}
+void FXJSE_Value_SetDate(FXJSE_HVALUE hValue, FXJSE_DOUBLE dDouble) {
+ CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
+ return lpValue->SetDate(dDouble);
+}
+void FXJSE_Value_Set(FXJSE_HVALUE hValue, FXJSE_HVALUE hOriginalValue) {
+ CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
+ CFXJSE_Value* lpOriginalValue =
+ reinterpret_cast<CFXJSE_Value*>(hOriginalValue);
+ ASSERT(lpValue && lpOriginalValue);
+ return lpValue->Assign(lpOriginalValue);
+}
+FX_BOOL FXJSE_Value_GetObjectProp(FXJSE_HVALUE hValue,
+ const CFX_ByteStringC& szPropName,
+ FXJSE_HVALUE hPropValue) {
+ CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
+ CFXJSE_Value* lpPropValue = reinterpret_cast<CFXJSE_Value*>(hPropValue);
+ ASSERT(lpValue && lpPropValue);
+ return lpValue->GetObjectProperty(szPropName, lpPropValue);
+}
+FX_BOOL FXJSE_Value_SetObjectProp(FXJSE_HVALUE hValue,
+ const CFX_ByteStringC& szPropName,
+ FXJSE_HVALUE hPropValue) {
+ CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
+ CFXJSE_Value* lpPropValue = reinterpret_cast<CFXJSE_Value*>(hPropValue);
+ ASSERT(lpValue && lpPropValue);
+ return lpValue->SetObjectProperty(szPropName, lpPropValue);
+}
+FX_BOOL FXJSE_Value_GetObjectPropByIdx(FXJSE_HVALUE hValue,
+ uint32_t uPropIdx,
+ FXJSE_HVALUE hPropValue) {
+ CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
+ CFXJSE_Value* lpPropValue = reinterpret_cast<CFXJSE_Value*>(hPropValue);
+ ASSERT(lpValue && lpPropValue);
+ return lpValue->GetObjectProperty(uPropIdx, lpPropValue);
+}
+FX_BOOL FXJSE_Value_SetObjectPropByIdx(FXJSE_HVALUE hValue,
+ uint32_t uPropIdx,
+ FXJSE_HVALUE hPropValue) {
+ CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
+ CFXJSE_Value* lpPropValue = reinterpret_cast<CFXJSE_Value*>(hPropValue);
+ ASSERT(lpValue && lpPropValue);
+ return lpValue->SetObjectProperty(uPropIdx, lpPropValue);
+}
+FX_BOOL FXJSE_Value_DeleteObjectProp(FXJSE_HVALUE hValue,
+ const CFX_ByteStringC& szPropName) {
+ CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
+ ASSERT(lpValue);
+ return lpValue->DeleteObjectProperty(szPropName);
+}
+FX_BOOL FXJSE_Value_ObjectHasOwnProp(FXJSE_HVALUE hValue,
+ const CFX_ByteStringC& szPropName,
+ FX_BOOL bUseTypeGetter) {
+ CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
+ ASSERT(lpValue);
+ return lpValue->HasObjectOwnProperty(szPropName, bUseTypeGetter);
+}
+FX_BOOL FXJSE_Value_SetObjectOwnProp(FXJSE_HVALUE hValue,
+ const CFX_ByteStringC& szPropName,
+ FXJSE_HVALUE hPropValue) {
+ CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
+ CFXJSE_Value* lpPropValue = reinterpret_cast<CFXJSE_Value*>(hPropValue);
+ ASSERT(lpValue && lpPropValue);
+ return lpValue->SetObjectOwnProperty(szPropName, lpPropValue);
+}
+FX_BOOL FXJSE_Value_SetFunctionBind(FXJSE_HVALUE hValue,
+ FXJSE_HVALUE hOldFunction,
+ FXJSE_HVALUE hNewThis) {
+ CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
+ CFXJSE_Value* lpOldFunction = reinterpret_cast<CFXJSE_Value*>(hOldFunction);
+ CFXJSE_Value* lpNewThis = reinterpret_cast<CFXJSE_Value*>(hNewThis);
+ ASSERT(lpValue && lpOldFunction && lpNewThis);
+ return lpValue->SetFunctionBind(lpOldFunction, lpNewThis);
+}
+FX_BOOL FXJSE_Value_CallFunction(FXJSE_HVALUE hFunction,
+ FXJSE_HVALUE hThis,
+ FXJSE_HVALUE hRetValue,
+ uint32_t nArgCount,
+ FXJSE_HVALUE* lpArgs) {
+ CFXJSE_Value* lpFunction = reinterpret_cast<CFXJSE_Value*>(hFunction);
+ CFXJSE_Value* lpThis = reinterpret_cast<CFXJSE_Value*>(hThis);
+ CFXJSE_Value* lpRetValue = reinterpret_cast<CFXJSE_Value*>(hRetValue);
+ ASSERT(lpFunction);
+ return lpFunction->Call(lpThis, lpRetValue, nArgCount, lpArgs);
+}
+FXJSE_HVALUE FXJSE_Value_Create(FXJSE_HRUNTIME hRuntime) {
+ CFXJSE_Value* lpValue =
+ CFXJSE_Value::Create(reinterpret_cast<v8::Isolate*>(hRuntime));
+ ASSERT(lpValue);
+ return reinterpret_cast<FXJSE_HVALUE>(lpValue);
+}
+void FXJSE_Value_Release(FXJSE_HVALUE hValue) {
+ CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
+ if (lpValue) {
+ delete lpValue;
+ }
+}
+FXJSE_HRUNTIME FXJSE_Value_GetRuntime(FXJSE_HVALUE hValue) {
+ CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue);
+ ASSERT(lpValue);
+ return reinterpret_cast<FXJSE_HRUNTIME>(lpValue->GetIsolate());
+}
+void FXJSE_ThrowMessage(const CFX_ByteStringC& utf8Name,
+ const CFX_ByteStringC& utf8Message) {
+ v8::Isolate* pIsolate = v8::Isolate::GetCurrent();
+ ASSERT(pIsolate);
+ CFXJSE_ScopeUtil_IsolateHandleRootContext scope(pIsolate);
+ v8::Local<v8::String> hMessage = v8::String::NewFromUtf8(
+ pIsolate, utf8Message.GetCStr(), v8::String::kNormalString,
+ utf8Message.GetLength());
+ v8::Local<v8::Value> hError;
+ if (utf8Name == "RangeError") {
+ hError = v8::Exception::RangeError(hMessage);
+ } else if (utf8Name == "ReferenceError") {
+ hError = v8::Exception::ReferenceError(hMessage);
+ } else if (utf8Name == "SyntaxError") {
+ hError = v8::Exception::SyntaxError(hMessage);
+ } else if (utf8Name == "TypeError") {
+ hError = v8::Exception::TypeError(hMessage);
+ } else {
+ hError = v8::Exception::Error(hMessage);
+ if (utf8Name != "Error" && !utf8Name.IsEmpty()) {
+ hError.As<v8::Object>()->Set(
+ v8::String::NewFromUtf8(pIsolate, "name"),
+ v8::String::NewFromUtf8(pIsolate, utf8Name.GetCStr(),
+ v8::String::kNormalString,
+ utf8Name.GetLength()));
+ }
+ }
+ pIsolate->ThrowException(hError);
+}
+CFXJSE_Value* CFXJSE_Value::Create(v8::Isolate* pIsolate) {
+ return new CFXJSE_Value(pIsolate);
+}
+void* CFXJSE_Value::ToObject(CFXJSE_Class* lpClass) const {
+ ASSERT(!m_hValue.IsEmpty());
+ CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate);
+ v8::Local<v8::Value> hValue = v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
+ ASSERT(!hValue.IsEmpty());
+ if (!hValue->IsObject()) {
+ return NULL;
+ }
+ return FXJSE_RetrieveObjectBinding(hValue.As<v8::Object>(), lpClass);
+}
+V8_INLINE static double FXJSE_ftod(FX_FLOAT fNumber) {
+ if (sizeof(FX_FLOAT) != 4) {
+ ASSERT(FALSE);
+ return fNumber;
+ }
+ uint32_t nFloatBits = (uint32_t&)fNumber;
+ uint8_t nExponent = (uint8_t)(nFloatBits >> 16 >> 7);
+ if (nExponent == 0 || nExponent == 255) {
+ return fNumber;
+ }
+ int8_t nErrExp = nExponent - 127 - 23;
+ if (nErrExp >= 0) {
+ return fNumber;
+ }
+ double dwError = pow(2.0, nErrExp), dwErrorHalf = dwError / 2;
+ double dNumber = fNumber, dNumberAbs = fabs(fNumber);
+ double dNumberAbsMin = dNumberAbs - dwErrorHalf,
+ dNumberAbsMax = dNumberAbs + dwErrorHalf;
+ int32_t iErrPos = 0;
+ if (floor(dNumberAbsMin) == floor(dNumberAbsMax)) {
+ dNumberAbsMin = fmod(dNumberAbsMin, 1.0);
+ dNumberAbsMax = fmod(dNumberAbsMax, 1.0);
+ int32_t iErrPosMin = 1, iErrPosMax = 38;
+ do {
+ int32_t iMid = (iErrPosMin + iErrPosMax) / 2;
+ double dPow = pow(10.0, iMid);
+ if (floor(dNumberAbsMin * dPow) == floor(dNumberAbsMax * dPow)) {
+ iErrPosMin = iMid + 1;
+ } else {
+ iErrPosMax = iMid;
+ }
+ } while (iErrPosMin < iErrPosMax);
+ iErrPos = iErrPosMax;
+ }
+ double dPow = pow(10.0, iErrPos);
+ return fNumber < 0 ? ceil(dNumber * dPow - 0.5) / dPow
+ : floor(dNumber * dPow + 0.5) / dPow;
+}
+void CFXJSE_Value::SetFloat(FX_FLOAT fFloat) {
+ CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate);
+ v8::Local<v8::Value> hValue = v8::Number::New(m_pIsolate, FXJSE_ftod(fFloat));
+ m_hValue.Reset(m_pIsolate, hValue);
+}
+void CFXJSE_Value::SetHostObject(void* lpObject, CFXJSE_Class* lpClass) {
+ CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate);
+ ASSERT(lpClass);
+ v8::Local<v8::FunctionTemplate> hClass =
+ v8::Local<v8::FunctionTemplate>::New(m_pIsolate, lpClass->m_hTemplate);
+ v8::Local<v8::Object> hObject = hClass->InstanceTemplate()->NewInstance();
+ FXJSE_UpdateObjectBinding(hObject, lpObject);
+ m_hValue.Reset(m_pIsolate, hObject);
+}
+void CFXJSE_Value::SetArray(uint32_t uValueCount, CFXJSE_Value** rgValues) {
+ CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate);
+ v8::Local<v8::Array> hArrayObject = v8::Array::New(m_pIsolate, uValueCount);
+ if (rgValues) {
+ for (uint32_t i = 0; i < uValueCount; i++) {
+ if (rgValues[i]) {
+ hArrayObject->Set(i, v8::Local<v8::Value>::New(
+ m_pIsolate, rgValues[i]->DirectGetValue()));
+ }
+ }
+ }
+ m_hValue.Reset(m_pIsolate, hArrayObject);
+}
+void CFXJSE_Value::SetDate(FXJSE_DOUBLE dDouble) {
+ CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate);
+ v8::Local<v8::Value> hDate = v8::Date::New(m_pIsolate, dDouble);
+ m_hValue.Reset(m_pIsolate, hDate);
+}
+FX_BOOL CFXJSE_Value::SetObjectProperty(const CFX_ByteStringC& szPropName,
+ CFXJSE_Value* lpPropValue) {
+ CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate);
+ v8::Local<v8::Value> hObject =
+ v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
+ if (!hObject->IsObject()) {
+ return FALSE;
+ }
+ v8::Local<v8::Value> hPropValue =
+ v8::Local<v8::Value>::New(m_pIsolate, lpPropValue->DirectGetValue());
+ return (FX_BOOL)hObject.As<v8::Object>()->Set(
+ v8::String::NewFromUtf8(m_pIsolate, szPropName.GetCStr(),
+ v8::String::kNormalString,
+ szPropName.GetLength()),
+ hPropValue);
+}
+FX_BOOL CFXJSE_Value::GetObjectProperty(const CFX_ByteStringC& szPropName,
+ CFXJSE_Value* lpPropValue) {
+ CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate);
+ v8::Local<v8::Value> hObject =
+ v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
+ if (!hObject->IsObject()) {
+ return FALSE;
+ }
+ v8::Local<v8::Value> hPropValue =
+ hObject.As<v8::Object>()->Get(v8::String::NewFromUtf8(
+ m_pIsolate, szPropName.GetCStr(), v8::String::kNormalString,
+ szPropName.GetLength()));
+ lpPropValue->ForceSetValue(hPropValue);
+ return TRUE;
+}
+FX_BOOL CFXJSE_Value::SetObjectProperty(uint32_t uPropIdx,
+ CFXJSE_Value* lpPropValue) {
+ CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate);
+ v8::Local<v8::Value> hObject =
+ v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
+ if (!hObject->IsObject()) {
+ return FALSE;
+ }
+ v8::Local<v8::Value> hPropValue =
+ v8::Local<v8::Value>::New(m_pIsolate, lpPropValue->DirectGetValue());
+ return (FX_BOOL)hObject.As<v8::Object>()->Set(uPropIdx, hPropValue);
+}
+FX_BOOL CFXJSE_Value::GetObjectProperty(uint32_t uPropIdx,
+ CFXJSE_Value* lpPropValue) {
+ CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate);
+ v8::Local<v8::Value> hObject =
+ v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
+ if (!hObject->IsObject()) {
+ return FALSE;
+ }
+ v8::Local<v8::Value> hPropValue = hObject.As<v8::Object>()->Get(uPropIdx);
+ lpPropValue->ForceSetValue(hPropValue);
+ return TRUE;
+}
+FX_BOOL CFXJSE_Value::DeleteObjectProperty(const CFX_ByteStringC& szPropName) {
+ CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate);
+ v8::Local<v8::Value> hObject =
+ v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
+ if (!hObject->IsObject()) {
+ return FALSE;
+ }
+ hObject.As<v8::Object>()->Delete(v8::String::NewFromUtf8(
+ m_pIsolate, szPropName.GetCStr(), v8::String::kNormalString,
+ szPropName.GetLength()));
+ return TRUE;
+}
+FX_BOOL CFXJSE_Value::HasObjectOwnProperty(const CFX_ByteStringC& szPropName,
+ FX_BOOL bUseTypeGetter) {
+ CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate);
+ v8::Local<v8::Value> hObject =
+ v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
+ if (!hObject->IsObject()) {
+ return FALSE;
+ }
+ v8::Local<v8::String> hKey = v8::String::NewFromUtf8(
+ m_pIsolate, szPropName.GetCStr(), v8::String::kNormalString,
+ szPropName.GetLength());
+ return hObject.As<v8::Object>()->HasRealNamedProperty(hKey) ||
+ (bUseTypeGetter && hObject.As<v8::Object>()->HasOwnProperty(hKey));
+}
+FX_BOOL CFXJSE_Value::SetObjectOwnProperty(const CFX_ByteStringC& szPropName,
+ CFXJSE_Value* lpPropValue) {
+ CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate);
+ v8::Local<v8::Value> hObject =
+ v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
+ if (!hObject->IsObject()) {
+ return FALSE;
+ }
+ v8::Local<v8::Value> hValue =
+ v8::Local<v8::Value>::New(m_pIsolate, lpPropValue->m_hValue);
+ return hObject.As<v8::Object>()->ForceSet(
+ v8::String::NewFromUtf8(m_pIsolate, szPropName.GetCStr(),
+ v8::String::kNormalString,
+ szPropName.GetLength()),
+ hValue);
+}
+FX_BOOL CFXJSE_Value::SetFunctionBind(CFXJSE_Value* lpOldFunction,
+ CFXJSE_Value* lpNewThis) {
+ CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate);
+ v8::Local<v8::Value> rgArgs[2];
+ v8::Local<v8::Value> hOldFunction =
+ v8::Local<v8::Value>::New(m_pIsolate, lpOldFunction->DirectGetValue());
+ if (hOldFunction.IsEmpty() || !hOldFunction->IsFunction()) {
+ return FALSE;
+ }
+ rgArgs[0] = hOldFunction;
+ v8::Local<v8::Value> hNewThis =
+ v8::Local<v8::Value>::New(m_pIsolate, lpNewThis->DirectGetValue());
+ if (hNewThis.IsEmpty()) {
+ return FALSE;
+ }
+ rgArgs[1] = hNewThis;
+ v8::Local<v8::String> hBinderFuncSource =
+ v8::String::NewFromUtf8(m_pIsolate,
+ "(function (oldfunction, newthis) { return "
+ "oldfunction.bind(newthis); })");
+ v8::Local<v8::Function> hBinderFunc =
+ v8::Script::Compile(hBinderFuncSource)->Run().As<v8::Function>();
+ v8::Local<v8::Value> hBoundFunction =
+ hBinderFunc->Call(m_pIsolate->GetCurrentContext()->Global(), 2, rgArgs);
+ if (hBoundFunction.IsEmpty() || !hBoundFunction->IsFunction()) {
+ return FALSE;
+ }
+ m_hValue.Reset(m_pIsolate, hBoundFunction);
+ return TRUE;
+}
+#define FXJSE_INVALID_PTR ((void*)(intptr_t)-1)
+FX_BOOL CFXJSE_Value::Call(CFXJSE_Value* lpReceiver,
+ CFXJSE_Value* lpRetValue,
+ uint32_t nArgCount,
+ FXJSE_HVALUE* lpArgs) {
+ CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate);
+ v8::Local<v8::Value> hFunctionValue =
+ v8::Local<v8::Value>::New(m_pIsolate, DirectGetValue());
+ v8::Local<v8::Object> hFunctionObject =
+ !hFunctionValue.IsEmpty() && hFunctionValue->IsObject()
+ ? hFunctionValue.As<v8::Object>()
+ : v8::Local<v8::Object>();
+ v8::TryCatch trycatch;
+ if (hFunctionObject.IsEmpty() || !hFunctionObject->IsCallable()) {
+ if (lpRetValue) {
+ lpRetValue->ForceSetValue(FXJSE_CreateReturnValue(m_pIsolate, trycatch));
+ }
+ return FALSE;
+ }
+ v8::Local<v8::Value> hReturnValue;
+ v8::Local<v8::Value>* lpLocalArgs = NULL;
+ if (nArgCount) {
+ lpLocalArgs = FX_Alloc(v8::Local<v8::Value>, nArgCount);
+ for (uint32_t i = 0; i < nArgCount; i++) {
+ new (lpLocalArgs + i) v8::Local<v8::Value>;
+ CFXJSE_Value* lpArg = (CFXJSE_Value*)lpArgs[i];
+ if (lpArg) {
+ lpLocalArgs[i] =
+ v8::Local<v8::Value>::New(m_pIsolate, lpArg->DirectGetValue());
+ }
+ if (lpLocalArgs[i].IsEmpty()) {
+ lpLocalArgs[i] = v8::Undefined(m_pIsolate);
+ }
+ }
+ }
+ FX_BOOL bRetValue = TRUE;
+ if (lpReceiver == FXJSE_INVALID_PTR) {
+ hReturnValue = hFunctionObject->CallAsConstructor(nArgCount, lpLocalArgs);
+ } else {
+ v8::Local<v8::Value> hReceiver;
+ if (lpReceiver) {
+ hReceiver =
+ v8::Local<v8::Value>::New(m_pIsolate, lpReceiver->DirectGetValue());
+ }
+ if (hReceiver.IsEmpty() || !hReceiver->IsObject()) {
+ hReceiver = v8::Object::New(m_pIsolate);
+ }
+ hReturnValue =
+ hFunctionObject->CallAsFunction(hReceiver, nArgCount, lpLocalArgs);
+ }
+ if (trycatch.HasCaught()) {
+ hReturnValue = FXJSE_CreateReturnValue(m_pIsolate, trycatch);
+ bRetValue = FALSE;
+ }
+ if (lpRetValue) {
+ lpRetValue->ForceSetValue(hReturnValue);
+ }
+ if (lpLocalArgs) {
+ for (uint32_t i = 0; i < nArgCount; i++) {
+ lpLocalArgs[i].~Local();
+ }
+ FX_Free(lpLocalArgs);
+ }
+ return bRetValue;
+}
diff --git a/xfa/src/fxjse/src/value.h b/xfa/src/fxjse/src/value.h
index ee102bdac3..856bd9c099 100644
--- a/xfa/src/fxjse/src/value.h
+++ b/xfa/src/fxjse/src/value.h
@@ -1,238 +1,238 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#ifndef FXJSE_VALUE_H_
-#define FXJSE_VALUE_H_
-#include "scope_inline.h"
-class CFXJSE_Value {
- public:
- CFXJSE_Value(v8::Isolate* pIsolate) : m_pIsolate(pIsolate) {}
-
- protected:
- CFXJSE_Value();
- CFXJSE_Value(const CFXJSE_Value&);
- CFXJSE_Value& operator=(const CFXJSE_Value&);
-
- public:
- V8_INLINE FX_BOOL IsUndefined() const {
- if (m_hValue.IsEmpty()) {
- return FALSE;
- }
- CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate);
- v8::Local<v8::Value> hValue =
- v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
- return hValue->IsUndefined();
- }
- V8_INLINE FX_BOOL IsNull() const {
- if (m_hValue.IsEmpty()) {
- return FALSE;
- }
- CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate);
- v8::Local<v8::Value> hValue =
- v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
- return hValue->IsNull();
- }
- V8_INLINE FX_BOOL IsBoolean() const {
- if (m_hValue.IsEmpty()) {
- return FALSE;
- }
- CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate);
- v8::Local<v8::Value> hValue =
- v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
- return hValue->IsBoolean();
- }
- V8_INLINE FX_BOOL IsString() const {
- if (m_hValue.IsEmpty()) {
- return FALSE;
- }
- CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate);
- v8::Local<v8::Value> hValue =
- v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
- return hValue->IsString();
- }
- V8_INLINE FX_BOOL IsNumber() const {
- if (m_hValue.IsEmpty()) {
- return FALSE;
- }
- CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate);
- v8::Local<v8::Value> hValue =
- v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
- return hValue->IsNumber();
- }
- V8_INLINE FX_BOOL IsInteger() const {
- if (m_hValue.IsEmpty()) {
- return FALSE;
- }
- CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate);
- v8::Local<v8::Value> hValue =
- v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
- return hValue->IsInt32();
- }
- V8_INLINE FX_BOOL IsObject() const {
- if (m_hValue.IsEmpty()) {
- return FALSE;
- }
- CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate);
- v8::Local<v8::Value> hValue =
- v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
- return hValue->IsObject();
- }
- V8_INLINE FX_BOOL IsArray() const {
- if (m_hValue.IsEmpty()) {
- return FALSE;
- }
- CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate);
- v8::Local<v8::Value> hValue =
- v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
- return hValue->IsArray();
- }
- V8_INLINE FX_BOOL IsFunction() const {
- if (m_hValue.IsEmpty()) {
- return FALSE;
- }
- CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate);
- v8::Local<v8::Value> hValue =
- v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
- return hValue->IsFunction();
- }
- V8_INLINE FX_BOOL IsDate() const {
- if (m_hValue.IsEmpty()) {
- return FALSE;
- }
- CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate);
- v8::Local<v8::Value> hValue =
- v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
- return hValue->IsDate();
- }
-
- public:
- V8_INLINE FX_BOOL ToBoolean() const {
- ASSERT(!m_hValue.IsEmpty());
- CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate);
- v8::Local<v8::Value> hValue =
- v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
- return static_cast<FX_BOOL>(hValue->BooleanValue());
- }
- V8_INLINE FX_FLOAT ToFloat() const {
- ASSERT(!m_hValue.IsEmpty());
- CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate);
- v8::Local<v8::Value> hValue =
- v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
- return static_cast<FX_FLOAT>(hValue->NumberValue());
- }
- V8_INLINE FXJSE_DOUBLE ToDouble() const {
- ASSERT(!m_hValue.IsEmpty());
- CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate);
- v8::Local<v8::Value> hValue =
- v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
- return static_cast<FXJSE_DOUBLE>(hValue->NumberValue());
- }
- V8_INLINE int32_t ToInteger() const {
- ASSERT(!m_hValue.IsEmpty());
- CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate);
- v8::Local<v8::Value> hValue =
- v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
- return static_cast<int32_t>(hValue->NumberValue());
- }
- V8_INLINE void ToString(CFX_ByteString& szStrOutput) const {
- ASSERT(!m_hValue.IsEmpty());
- CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate);
- v8::Local<v8::Value> hValue =
- v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
- v8::Local<v8::String> hString = hValue->ToString();
- v8::String::Utf8Value hStringVal(hString);
- szStrOutput = *hStringVal;
- }
- void* ToObject(CFXJSE_Class* lpClass) const;
-
- public:
- V8_INLINE void SetUndefined() {
- CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate);
- v8::Local<v8::Value> hValue = v8::Undefined(m_pIsolate);
- m_hValue.Reset(m_pIsolate, hValue);
- }
- V8_INLINE void SetNull() {
- CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate);
- v8::Local<v8::Value> hValue = v8::Null(m_pIsolate);
- m_hValue.Reset(m_pIsolate, hValue);
- }
- V8_INLINE void SetBoolean(FX_BOOL bBoolean) {
- CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate);
- v8::Local<v8::Value> hValue =
- v8::Boolean::New(m_pIsolate, bBoolean != FALSE);
- m_hValue.Reset(m_pIsolate, hValue);
- }
- V8_INLINE void SetInteger(int32_t nInteger) {
- CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate);
- v8::Local<v8::Value> hValue = v8::Integer::New(m_pIsolate, nInteger);
- m_hValue.Reset(m_pIsolate, hValue);
- }
- V8_INLINE void SetDouble(FXJSE_DOUBLE dDouble) {
- CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate);
- v8::Local<v8::Value> hValue = v8::Number::New(m_pIsolate, dDouble);
- m_hValue.Reset(m_pIsolate, hValue);
- }
- V8_INLINE void SetString(const CFX_ByteStringC& szString) {
- CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate);
- v8::Local<v8::Value> hValue = v8::String::NewFromUtf8(
- m_pIsolate, reinterpret_cast<const char*>(szString.GetPtr()),
- v8::String::kNormalString, szString.GetLength());
- m_hValue.Reset(m_pIsolate, hValue);
- }
- V8_INLINE void SetFloat(FX_FLOAT fFloat);
- V8_INLINE void SetJSObject() {
- CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate);
- v8::Local<v8::Value> hValue = v8::Object::New(m_pIsolate);
- m_hValue.Reset(m_pIsolate, hValue);
- }
- void SetHostObject(void* lpObject, CFXJSE_Class* lpClass);
- void SetArray(uint32_t uValueCount, CFXJSE_Value** rgValues);
- void SetDate(FXJSE_DOUBLE dDouble);
-
- public:
- FX_BOOL GetObjectProperty(const CFX_ByteStringC& szPropName,
- CFXJSE_Value* lpPropValue);
- FX_BOOL SetObjectProperty(const CFX_ByteStringC& szPropName,
- CFXJSE_Value* lpPropValue);
- FX_BOOL GetObjectProperty(uint32_t uPropIdx, CFXJSE_Value* lpPropValue);
- FX_BOOL SetObjectProperty(uint32_t uPropIdx, CFXJSE_Value* lpPropValue);
- FX_BOOL DeleteObjectProperty(const CFX_ByteStringC& szPropName);
- FX_BOOL HasObjectOwnProperty(const CFX_ByteStringC& szPropName,
- FX_BOOL bUseTypeGetter);
- FX_BOOL SetObjectOwnProperty(const CFX_ByteStringC& szPropName,
- CFXJSE_Value* lpPropValue);
- FX_BOOL SetFunctionBind(CFXJSE_Value* lpOldFunction, CFXJSE_Value* lpNewThis);
- FX_BOOL Call(CFXJSE_Value* lpReceiver,
- CFXJSE_Value* lpRetValue,
- uint32_t nArgCount,
- FXJSE_HVALUE* lpArgs);
-
- public:
- V8_INLINE v8::Isolate* GetIsolate() const { return m_pIsolate; }
- V8_INLINE const v8::Global<v8::Value>& DirectGetValue() const {
- return m_hValue;
- }
- V8_INLINE void ForceSetValue(v8::Local<v8::Value> hValue) {
- m_hValue.Reset(m_pIsolate, hValue);
- }
- V8_INLINE void Assign(const CFXJSE_Value* lpValue) {
- if (lpValue) {
- m_hValue.Reset(m_pIsolate, lpValue->m_hValue);
- } else {
- m_hValue.Reset();
- }
- }
-
- public:
- static CFXJSE_Value* Create(v8::Isolate* pIsolate);
-
- protected:
- v8::Isolate* m_pIsolate;
- v8::Global<v8::Value> m_hValue;
- friend class CFXJSE_Context;
- friend class CFXJSE_Class;
-};
-#endif
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef FXJSE_VALUE_H_
+#define FXJSE_VALUE_H_
+#include "scope_inline.h"
+class CFXJSE_Value {
+ public:
+ CFXJSE_Value(v8::Isolate* pIsolate) : m_pIsolate(pIsolate) {}
+
+ protected:
+ CFXJSE_Value();
+ CFXJSE_Value(const CFXJSE_Value&);
+ CFXJSE_Value& operator=(const CFXJSE_Value&);
+
+ public:
+ V8_INLINE FX_BOOL IsUndefined() const {
+ if (m_hValue.IsEmpty()) {
+ return FALSE;
+ }
+ CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate);
+ v8::Local<v8::Value> hValue =
+ v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
+ return hValue->IsUndefined();
+ }
+ V8_INLINE FX_BOOL IsNull() const {
+ if (m_hValue.IsEmpty()) {
+ return FALSE;
+ }
+ CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate);
+ v8::Local<v8::Value> hValue =
+ v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
+ return hValue->IsNull();
+ }
+ V8_INLINE FX_BOOL IsBoolean() const {
+ if (m_hValue.IsEmpty()) {
+ return FALSE;
+ }
+ CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate);
+ v8::Local<v8::Value> hValue =
+ v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
+ return hValue->IsBoolean();
+ }
+ V8_INLINE FX_BOOL IsString() const {
+ if (m_hValue.IsEmpty()) {
+ return FALSE;
+ }
+ CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate);
+ v8::Local<v8::Value> hValue =
+ v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
+ return hValue->IsString();
+ }
+ V8_INLINE FX_BOOL IsNumber() const {
+ if (m_hValue.IsEmpty()) {
+ return FALSE;
+ }
+ CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate);
+ v8::Local<v8::Value> hValue =
+ v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
+ return hValue->IsNumber();
+ }
+ V8_INLINE FX_BOOL IsInteger() const {
+ if (m_hValue.IsEmpty()) {
+ return FALSE;
+ }
+ CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate);
+ v8::Local<v8::Value> hValue =
+ v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
+ return hValue->IsInt32();
+ }
+ V8_INLINE FX_BOOL IsObject() const {
+ if (m_hValue.IsEmpty()) {
+ return FALSE;
+ }
+ CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate);
+ v8::Local<v8::Value> hValue =
+ v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
+ return hValue->IsObject();
+ }
+ V8_INLINE FX_BOOL IsArray() const {
+ if (m_hValue.IsEmpty()) {
+ return FALSE;
+ }
+ CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate);
+ v8::Local<v8::Value> hValue =
+ v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
+ return hValue->IsArray();
+ }
+ V8_INLINE FX_BOOL IsFunction() const {
+ if (m_hValue.IsEmpty()) {
+ return FALSE;
+ }
+ CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate);
+ v8::Local<v8::Value> hValue =
+ v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
+ return hValue->IsFunction();
+ }
+ V8_INLINE FX_BOOL IsDate() const {
+ if (m_hValue.IsEmpty()) {
+ return FALSE;
+ }
+ CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate);
+ v8::Local<v8::Value> hValue =
+ v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
+ return hValue->IsDate();
+ }
+
+ public:
+ V8_INLINE FX_BOOL ToBoolean() const {
+ ASSERT(!m_hValue.IsEmpty());
+ CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate);
+ v8::Local<v8::Value> hValue =
+ v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
+ return static_cast<FX_BOOL>(hValue->BooleanValue());
+ }
+ V8_INLINE FX_FLOAT ToFloat() const {
+ ASSERT(!m_hValue.IsEmpty());
+ CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate);
+ v8::Local<v8::Value> hValue =
+ v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
+ return static_cast<FX_FLOAT>(hValue->NumberValue());
+ }
+ V8_INLINE FXJSE_DOUBLE ToDouble() const {
+ ASSERT(!m_hValue.IsEmpty());
+ CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate);
+ v8::Local<v8::Value> hValue =
+ v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
+ return static_cast<FXJSE_DOUBLE>(hValue->NumberValue());
+ }
+ V8_INLINE int32_t ToInteger() const {
+ ASSERT(!m_hValue.IsEmpty());
+ CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate);
+ v8::Local<v8::Value> hValue =
+ v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
+ return static_cast<int32_t>(hValue->NumberValue());
+ }
+ V8_INLINE void ToString(CFX_ByteString& szStrOutput) const {
+ ASSERT(!m_hValue.IsEmpty());
+ CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate);
+ v8::Local<v8::Value> hValue =
+ v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
+ v8::Local<v8::String> hString = hValue->ToString();
+ v8::String::Utf8Value hStringVal(hString);
+ szStrOutput = *hStringVal;
+ }
+ void* ToObject(CFXJSE_Class* lpClass) const;
+
+ public:
+ V8_INLINE void SetUndefined() {
+ CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate);
+ v8::Local<v8::Value> hValue = v8::Undefined(m_pIsolate);
+ m_hValue.Reset(m_pIsolate, hValue);
+ }
+ V8_INLINE void SetNull() {
+ CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate);
+ v8::Local<v8::Value> hValue = v8::Null(m_pIsolate);
+ m_hValue.Reset(m_pIsolate, hValue);
+ }
+ V8_INLINE void SetBoolean(FX_BOOL bBoolean) {
+ CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate);
+ v8::Local<v8::Value> hValue =
+ v8::Boolean::New(m_pIsolate, bBoolean != FALSE);
+ m_hValue.Reset(m_pIsolate, hValue);
+ }
+ V8_INLINE void SetInteger(int32_t nInteger) {
+ CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate);
+ v8::Local<v8::Value> hValue = v8::Integer::New(m_pIsolate, nInteger);
+ m_hValue.Reset(m_pIsolate, hValue);
+ }
+ V8_INLINE void SetDouble(FXJSE_DOUBLE dDouble) {
+ CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate);
+ v8::Local<v8::Value> hValue = v8::Number::New(m_pIsolate, dDouble);
+ m_hValue.Reset(m_pIsolate, hValue);
+ }
+ V8_INLINE void SetString(const CFX_ByteStringC& szString) {
+ CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate);
+ v8::Local<v8::Value> hValue = v8::String::NewFromUtf8(
+ m_pIsolate, reinterpret_cast<const char*>(szString.GetPtr()),
+ v8::String::kNormalString, szString.GetLength());
+ m_hValue.Reset(m_pIsolate, hValue);
+ }
+ V8_INLINE void SetFloat(FX_FLOAT fFloat);
+ V8_INLINE void SetJSObject() {
+ CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate);
+ v8::Local<v8::Value> hValue = v8::Object::New(m_pIsolate);
+ m_hValue.Reset(m_pIsolate, hValue);
+ }
+ void SetHostObject(void* lpObject, CFXJSE_Class* lpClass);
+ void SetArray(uint32_t uValueCount, CFXJSE_Value** rgValues);
+ void SetDate(FXJSE_DOUBLE dDouble);
+
+ public:
+ FX_BOOL GetObjectProperty(const CFX_ByteStringC& szPropName,
+ CFXJSE_Value* lpPropValue);
+ FX_BOOL SetObjectProperty(const CFX_ByteStringC& szPropName,
+ CFXJSE_Value* lpPropValue);
+ FX_BOOL GetObjectProperty(uint32_t uPropIdx, CFXJSE_Value* lpPropValue);
+ FX_BOOL SetObjectProperty(uint32_t uPropIdx, CFXJSE_Value* lpPropValue);
+ FX_BOOL DeleteObjectProperty(const CFX_ByteStringC& szPropName);
+ FX_BOOL HasObjectOwnProperty(const CFX_ByteStringC& szPropName,
+ FX_BOOL bUseTypeGetter);
+ FX_BOOL SetObjectOwnProperty(const CFX_ByteStringC& szPropName,
+ CFXJSE_Value* lpPropValue);
+ FX_BOOL SetFunctionBind(CFXJSE_Value* lpOldFunction, CFXJSE_Value* lpNewThis);
+ FX_BOOL Call(CFXJSE_Value* lpReceiver,
+ CFXJSE_Value* lpRetValue,
+ uint32_t nArgCount,
+ FXJSE_HVALUE* lpArgs);
+
+ public:
+ V8_INLINE v8::Isolate* GetIsolate() const { return m_pIsolate; }
+ V8_INLINE const v8::Global<v8::Value>& DirectGetValue() const {
+ return m_hValue;
+ }
+ V8_INLINE void ForceSetValue(v8::Local<v8::Value> hValue) {
+ m_hValue.Reset(m_pIsolate, hValue);
+ }
+ V8_INLINE void Assign(const CFXJSE_Value* lpValue) {
+ if (lpValue) {
+ m_hValue.Reset(m_pIsolate, lpValue->m_hValue);
+ } else {
+ m_hValue.Reset();
+ }
+ }
+
+ public:
+ static CFXJSE_Value* Create(v8::Isolate* pIsolate);
+
+ protected:
+ v8::Isolate* m_pIsolate;
+ v8::Global<v8::Value> m_hValue;
+ friend class CFXJSE_Context;
+ friend class CFXJSE_Class;
+};
+#endif