diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2016-02-24 14:06:15 -0500 |
---|---|---|
committer | Dan Sinclair <dsinclair@chromium.org> | 2016-02-24 14:06:15 -0500 |
commit | 700f667e1f7186ec2b9bdea1534667ae520660e7 (patch) | |
tree | 0714595ea746c8a63da9ae52f1fb7867513ca5b3 /xfa/src/fxjse | |
parent | 9d46ddf6c1327f2696c56e7c29f0e3b4ed0763c2 (diff) | |
download | pdfium-700f667e1f7186ec2b9bdea1534667ae520660e7.tar.xz |
Remove fxv8.h
This header just includes other headers, remove file and callsites.
R=thestig@chromium.org, tsepez@chromium.org
Review URL: https://codereview.chromium.org/1734683002 .
Diffstat (limited to 'xfa/src/fxjse')
-rw-r--r-- | xfa/src/fxjse/src/class.cpp | 20 | ||||
-rw-r--r-- | xfa/src/fxjse/src/context.cpp | 14 | ||||
-rw-r--r-- | xfa/src/fxjse/src/dynprop.cpp | 21 | ||||
-rw-r--r-- | xfa/src/fxjse/src/fxv8.h | 15 | ||||
-rw-r--r-- | xfa/src/fxjse/src/runtime.cpp | 11 | ||||
-rw-r--r-- | xfa/src/fxjse/src/value.cpp | 232 |
6 files changed, 191 insertions, 122 deletions
diff --git a/xfa/src/fxjse/src/class.cpp b/xfa/src/fxjse/src/class.cpp index f33a87486d..ca36c358ef 100644 --- a/xfa/src/fxjse/src/class.cpp +++ b/xfa/src/fxjse/src/class.cpp @@ -7,10 +7,10 @@ #include "xfa/src/foxitlib.h" #include "xfa/src/fxjse/src/class.h" #include "xfa/src/fxjse/src/context.h" -#include "xfa/src/fxjse/src/fxv8.h" #include "xfa/src/fxjse/src/scope_inline.h" #include "xfa/src/fxjse/src/util_inline.h" #include "xfa/src/fxjse/src/value.h" + static void FXJSE_V8ConstructorCallback_Wrapper( const v8::FunctionCallbackInfo<v8::Value>& info); static void FXJSE_V8FunctionCallback_Wrapper( @@ -22,6 +22,7 @@ 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) { @@ -41,6 +42,7 @@ void FXJSE_DefineFunctions(FXJSE_HCONTEXT hContext, 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); @@ -48,11 +50,13 @@ FXJSE_HCLASS FXJSE_DefineClass(FXJSE_HCONTEXT hContext, 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 = @@ -76,6 +80,7 @@ static void FXJSE_V8FunctionCallback_Wrapper( delete lpThisValue; lpThisValue = NULL; } + static void FXJSE_V8ClassGlobalConstructorCallback_Wrapper( const v8::FunctionCallbackInfo<v8::Value>& info) { const FXJSE_CLASS* lpClassDefinition = @@ -99,6 +104,7 @@ static void FXJSE_V8ClassGlobalConstructorCallback_Wrapper( delete lpThisValue; lpThisValue = NULL; } + static void FXJSE_V8GetterCallback_Wrapper( v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& info) { @@ -120,6 +126,7 @@ static void FXJSE_V8GetterCallback_Wrapper( delete lpPropValue; lpPropValue = NULL; } + static void FXJSE_V8SetterCallback_Wrapper( v8::Local<v8::String> property, v8::Local<v8::Value> value, @@ -142,6 +149,7 @@ static void FXJSE_V8SetterCallback_Wrapper( delete lpPropValue; lpPropValue = NULL; } + static void FXJSE_V8ConstructorCallback_Wrapper( const v8::FunctionCallbackInfo<v8::Value>& info) { const FXJSE_CLASS* lpClassDefinition = @@ -152,17 +160,20 @@ static void FXJSE_V8ConstructorCallback_Wrapper( 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); @@ -171,21 +182,25 @@ FXJSE_HVALUE CFXJSE_Arguments::GetValue(int32_t index) const { 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); @@ -193,6 +208,7 @@ CFX_ByteString CFXJSE_Arguments::GetUTF8String(int32_t index) const { 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); @@ -204,6 +220,7 @@ void* CFXJSE_Arguments::GetObject(int32_t index, FXJSE_HCLASS hClass) const { 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); @@ -226,6 +243,7 @@ static void FXJSE_Context_GlobalObjToString( info.GetReturnValue().Set(info.This()->ObjectProtoToString()); } } + CFXJSE_Class* CFXJSE_Class::Create(CFXJSE_Context* lpContext, const FXJSE_CLASS* lpClassDefinition, FX_BOOL bIsJSGlobal) { diff --git a/xfa/src/fxjse/src/context.cpp b/xfa/src/fxjse/src/context.cpp index ba76cb2b19..83d1279327 100644 --- a/xfa/src/fxjse/src/context.cpp +++ b/xfa/src/fxjse/src/context.cpp @@ -7,10 +7,10 @@ #include "xfa/src/foxitlib.h" #include "xfa/src/fxjse/src/class.h" #include "xfa/src/fxjse/src/context.h" -#include "xfa/src/fxjse/src/fxv8.h" #include "xfa/src/fxjse/src/scope_inline.h" #include "xfa/src/fxjse/src/util_inline.h" #include "xfa/src/fxjse/src/value.h" + FXJSE_HCONTEXT FXJSE_Context_Create(FXJSE_HRUNTIME hRuntime, const FXJSE_CLASS* lpGlobalClass, void* lpGlobalObject) { @@ -18,12 +18,14 @@ FXJSE_HCONTEXT FXJSE_Context_Create(FXJSE_HRUNTIME hRuntime, 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) { @@ -34,11 +36,13 @@ FXJSE_HVALUE FXJSE_Context_GetGlobalObject(FXJSE_HCONTEXT hContext) { 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) {\n" " 'use strict';\n" @@ -73,6 +77,7 @@ void FXJSE_Context_EnableCompatibleMode(FXJSE_HCONTEXT hContext, } } } + FX_BOOL FXJSE_ExecuteScript(FXJSE_HCONTEXT hContext, const FX_CHAR* szScript, FXJSE_HVALUE hRetValue, @@ -83,6 +88,7 @@ FX_BOOL FXJSE_ExecuteScript(FXJSE_HCONTEXT hContext, 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); @@ -118,6 +124,7 @@ v8::Local<v8::Object> FXJSE_CreateReturnValue(v8::Isolate* pIsolate, } return hReturnValue; } + FX_BOOL FXJSE_ReturnValue_GetMessage(FXJSE_HVALUE hRetValue, CFX_ByteString& utf8Name, CFX_ByteString& utf8Message) { @@ -140,6 +147,7 @@ FX_BOOL FXJSE_ReturnValue_GetMessage(FXJSE_HVALUE hRetValue, utf8Message = *hStringVal1; return TRUE; } + FX_BOOL FXJSE_ReturnValue_GetLineInfo(FXJSE_HVALUE hRetValue, int32_t& nLine, int32_t& nCol) { @@ -158,6 +166,7 @@ FX_BOOL FXJSE_ReturnValue_GetLineInfo(FXJSE_HVALUE hRetValue, 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) { @@ -187,6 +196,7 @@ CFXJSE_Context* CFXJSE_Context::Create(v8::Isolate* pIsolate, 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]; @@ -196,6 +206,7 @@ CFXJSE_Context::~CFXJSE_Context() { } m_rgClasses.RemoveAll(); } + void CFXJSE_Context::GetGlobalObject(CFXJSE_Value* pValue) { ASSERT(pValue); CFXJSE_ScopeUtil_IsolateHandleContext scope(this); @@ -204,6 +215,7 @@ void CFXJSE_Context::GetGlobalObject(CFXJSE_Value* pValue) { 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) { diff --git a/xfa/src/fxjse/src/dynprop.cpp b/xfa/src/fxjse/src/dynprop.cpp index 2bfb1a0822..f8dc19fc40 100644 --- a/xfa/src/fxjse/src/dynprop.cpp +++ b/xfa/src/fxjse/src/dynprop.cpp @@ -6,8 +6,8 @@ #include "xfa/src/foxitlib.h" #include "xfa/src/fxjse/src/class.h" -#include "xfa/src/fxjse/src/fxv8.h" #include "xfa/src/fxjse/src/value.h" + static void FXJSE_DynPropGetterAdapter_MethodCallback( const v8::FunctionCallbackInfo<v8::Value>& info) { v8::Local<v8::Object> hCallBackInfo = info.Data().As<v8::Object>(); @@ -33,6 +33,7 @@ static void FXJSE_DynPropGetterAdapter_MethodCallback( delete lpThisValue; lpThisValue = nullptr; } + static void FXJSE_DynPropGetterAdapter(const FXJSE_CLASS* lpClass, FXJSE_HOBJECT hObject, const CFX_ByteStringC& szPropName, @@ -68,6 +69,7 @@ static void FXJSE_DynPropGetterAdapter(const FXJSE_CLASS* lpClass, } } } + static void FXJSE_DynPropSetterAdapter(const FXJSE_CLASS* lpClass, FXJSE_HOBJECT hObject, const CFX_ByteStringC& szPropName, @@ -83,6 +85,7 @@ static void FXJSE_DynPropSetterAdapter(const FXJSE_CLASS* lpClass, } } } + static FX_BOOL FXJSE_DynPropQueryAdapter(const FXJSE_CLASS* lpClass, FXJSE_HOBJECT hObject, const CFX_ByteStringC& szPropName) { @@ -93,6 +96,7 @@ static FX_BOOL FXJSE_DynPropQueryAdapter(const FXJSE_CLASS* lpClass, : 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) { @@ -110,6 +114,7 @@ static FX_BOOL FXJSE_DynPropDeleterAdapter(const FXJSE_CLASS* lpClass, } return FALSE; } + static void FXJSE_V8ProxyCallback_getOwnPropertyDescriptor_getter( const v8::FunctionCallbackInfo<v8::Value>& info) { v8::Local<v8::Object> hCallBackInfo = info.Data().As<v8::Object>(); @@ -132,6 +137,7 @@ static void FXJSE_V8ProxyCallback_getOwnPropertyDescriptor_getter( 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>(); @@ -154,6 +160,7 @@ static void FXJSE_V8ProxyCallback_getOwnPropertyDescriptor_setter( delete lpNewValue; lpNewValue = nullptr; } + static void FXJSE_V8ProxyCallback_getOwnPropertyDescriptor( const v8::FunctionCallbackInfo<v8::Value>& info) { const FXJSE_CLASS* lpClass = @@ -190,6 +197,7 @@ static void FXJSE_V8ProxyCallback_getOwnPropertyDescriptor( 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(); @@ -209,12 +217,14 @@ static void FXJSE_V8ProxyCallback_getPropertyDescriptor( 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 = @@ -222,6 +232,7 @@ static void FXJSE_V8ProxyCallback_getPropertyNames( 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 = @@ -252,6 +263,7 @@ static void FXJSE_V8ProxyCallback_defineProperty( delete lpPropValue; lpPropValue = nullptr; } + static void FXJSE_V8ProxyCallback_delete( const v8::FunctionCallbackInfo<v8::Value>& info) { info.GetReturnValue().Set(true); @@ -275,10 +287,12 @@ static void FXJSE_V8ProxyCallback_delete( delete lpThisValue; lpThisValue = nullptr; } + 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) { @@ -302,6 +316,7 @@ static void FXJSE_V8_GenericNamedPropertyQueryCallback( delete lpThisValue; lpThisValue = nullptr; } + static void FXJSE_V8_GenericNamedPropertyDeleterCallback( v8::Local<v8::Name> property, const v8::PropertyCallbackInfo<v8::Boolean>& info) { @@ -322,6 +337,7 @@ static void FXJSE_V8_GenericNamedPropertyDeleterCallback( delete lpThisValue; lpThisValue = nullptr; } + static void FXJSE_V8_GenericNamedPropertyGetterCallback( v8::Local<v8::Name> property, const v8::PropertyCallbackInfo<v8::Value>& info) { @@ -340,6 +356,7 @@ static void FXJSE_V8_GenericNamedPropertyGetterCallback( delete lpThisValue; lpThisValue = nullptr; } + static void FXJSE_V8_GenericNamedPropertySetterCallback( v8::Local<v8::Name> property, v8::Local<v8::Value> value, @@ -360,6 +377,7 @@ static void FXJSE_V8_GenericNamedPropertySetterCallback( delete lpThisValue; lpThisValue = nullptr; } + static void FXJSE_V8_GenericNamedPropertyEnumeratorCallback( const v8::PropertyCallbackInfo<v8::Array>& info) { const FXJSE_CLASS* lpClass = @@ -433,6 +451,7 @@ void CFXJSE_Class::SetUpDynPropHandler(CFXJSE_Context* pContext, hHarmonyProxyCreateFn->Call(hHarmonyProxyObj, 2, rgArgs); hObject->SetPrototype(hNewPrototype); } + void CFXJSE_Class::SetUpNamedPropHandler( v8::Isolate* pIsolate, v8::Local<v8::ObjectTemplate>& hObjectTemplate, diff --git a/xfa/src/fxjse/src/fxv8.h b/xfa/src/fxjse/src/fxv8.h deleted file mode 100644 index fcf1e59855..0000000000 --- a/xfa/src/fxjse/src/fxv8.h +++ /dev/null @@ -1,15 +0,0 @@ -// 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 - -// TODO(thestig): Remove this file and do IWYU. - -#ifndef XFA_SRC_FXJSE_SRC_FXV8_H_ -#define XFA_SRC_FXJSE_SRC_FXV8_H_ - -#include <libplatform/libplatform.h> -#include <v8.h> - -#endif // XFA_SRC_FXJSE_SRC_FXV8_H_ diff --git a/xfa/src/fxjse/src/runtime.cpp b/xfa/src/fxjse/src/runtime.cpp index 3553a9a443..a276319e6c 100644 --- a/xfa/src/fxjse/src/runtime.cpp +++ b/xfa/src/fxjse/src/runtime.cpp @@ -6,7 +6,6 @@ #include "fpdfsdk/include/jsapi/fxjs_v8.h" // For per-isolate data. #include "xfa/src/foxitlib.h" -#include "xfa/src/fxjse/src/fxv8.h" #include "xfa/src/fxjse/src/runtime.h" #include "xfa/src/fxjse/src/scope_inline.h" @@ -21,6 +20,7 @@ class FXJSE_ArrayBufferAllocator : public v8::ArrayBuffer::Allocator { static void FXJSE_KillV8() { v8::V8::Dispose(); } + void FXJSE_Initialize() { if (!CFXJSE_RuntimeData::g_RuntimeList) { CFXJSE_RuntimeData::g_RuntimeList = new CFXJSE_RuntimeList; @@ -32,6 +32,7 @@ void FXJSE_Initialize() { bV8Initialized = TRUE; atexit(FXJSE_KillV8); } + static void FXJSE_Runtime_DisposeCallback(v8::Isolate* pIsolate) { { v8::Locker locker(pIsolate); @@ -42,6 +43,7 @@ static void FXJSE_Runtime_DisposeCallback(v8::Isolate* pIsolate) { } pIsolate->Dispose(); } + void FXJSE_Finalize() { if (CFXJSE_RuntimeData::g_RuntimeList) { CFXJSE_RuntimeData::g_RuntimeList->RemoveAllRuntimes( @@ -50,6 +52,7 @@ void FXJSE_Finalize() { CFXJSE_RuntimeData::g_RuntimeList = NULL; } } + FXJSE_HRUNTIME FXJSE_Runtime_Create() { v8::Isolate::CreateParams params; params.array_buffer_allocator = new FXJSE_ArrayBufferAllocator(); @@ -58,6 +61,7 @@ FXJSE_HRUNTIME FXJSE_Runtime_Create() { CFXJSE_RuntimeData::g_RuntimeList->AppendRuntime(pIsolate); return reinterpret_cast<FXJSE_HRUNTIME>(pIsolate); } + void FXJSE_Runtime_Release(FXJSE_HRUNTIME hRuntime, bool bOwnedRuntime) { v8::Isolate* pIsolate = reinterpret_cast<v8::Isolate*>(hRuntime); if (!pIsolate) @@ -73,6 +77,7 @@ void FXJSE_Runtime_Release(FXJSE_HRUNTIME hRuntime, bool bOwnedRuntime) { } } } + CFXJSE_RuntimeData* CFXJSE_RuntimeData::Create(v8::Isolate* pIsolate) { CFXJSE_RuntimeData* pRuntimeData = new CFXJSE_RuntimeData(pIsolate); CFXJSE_ScopeUtil_IsolateHandle scope(pIsolate); @@ -85,6 +90,7 @@ CFXJSE_RuntimeData* CFXJSE_RuntimeData::Create(v8::Isolate* pIsolate) { 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); @@ -92,10 +98,12 @@ CFXJSE_RuntimeData* CFXJSE_RuntimeData::Get(v8::Isolate* pIsolate) { 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) { @@ -107,6 +115,7 @@ void CFXJSE_RuntimeList::RemoveRuntime( lpfnDisposeCallback(pIsolate); } } + void CFXJSE_RuntimeList::RemoveAllRuntimes( CFXJSE_RuntimeList::RuntimeDisposeCallback lpfnDisposeCallback) { int32_t iSize = m_RuntimeList.GetSize(); diff --git a/xfa/src/fxjse/src/value.cpp b/xfa/src/fxjse/src/value.cpp index 5aca40368f..aa0f7cfc86 100644 --- a/xfa/src/fxjse/src/value.cpp +++ b/xfa/src/fxjse/src/value.cpp @@ -8,7 +8,6 @@ #include "xfa/src/foxitlib.h" #include "xfa/src/fxjse/src/class.h" -#include "xfa/src/fxjse/src/fxv8.h" #include "xfa/src/fxjse/src/util_inline.h" #include "xfa/src/fxjse/src/value.h" @@ -16,140 +15,139 @@ 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(); + return reinterpret_cast<CFXJSE_Value*>(hValue)->ToBoolean(); } + FX_FLOAT FXJSE_Value_ToFloat(FXJSE_HVALUE hValue) { - CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue); - ASSERT(lpValue); - return lpValue->ToFloat(); + return reinterpret_cast<CFXJSE_Value*>(hValue)->ToFloat(); } + FXJSE_DOUBLE FXJSE_Value_ToDouble(FXJSE_HVALUE hValue) { - CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue); - ASSERT(lpValue); - return lpValue->ToDouble(); + return reinterpret_cast<CFXJSE_Value*>(hValue)->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); + return reinterpret_cast<CFXJSE_Value*>(hValue)->ToString(szStrOutput); } + int32_t FXJSE_Value_ToInteger(FXJSE_HVALUE hValue) { - CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue); - ASSERT(lpValue); - return lpValue->ToInteger(); + return reinterpret_cast<CFXJSE_Value*>(hValue)->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); + return reinterpret_cast<CFXJSE_Value*>(hValue)->ToObject(lpClass); } + void FXJSE_Value_SetUndefined(FXJSE_HVALUE hValue) { - CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue); - ASSERT(lpValue); - return lpValue->SetUndefined(); + reinterpret_cast<CFXJSE_Value*>(hValue)->SetUndefined(); } + void FXJSE_Value_SetNull(FXJSE_HVALUE hValue) { - CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue); - ASSERT(lpValue); - return lpValue->SetNull(); + reinterpret_cast<CFXJSE_Value*>(hValue)->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); + reinterpret_cast<CFXJSE_Value*>(hValue)->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); + reinterpret_cast<CFXJSE_Value*>(hValue)->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); + reinterpret_cast<CFXJSE_Value*>(hValue)->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); + reinterpret_cast<CFXJSE_Value*>(hValue)->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); + reinterpret_cast<CFXJSE_Value*>(hValue)->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); + if (!lpClass) { + ASSERT(!lpObject); lpValue->SetJSObject(); - } else if (lpClass != NULL) { + } else { 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)); + reinterpret_cast<CFXJSE_Value*>(hValue) + ->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); + reinterpret_cast<CFXJSE_Value*>(hValue)->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); + lpValue->Assign(lpOriginalValue); } + FX_BOOL FXJSE_Value_GetObjectProp(FXJSE_HVALUE hValue, const CFX_ByteStringC& szPropName, FXJSE_HVALUE hPropValue) { @@ -158,6 +156,7 @@ FX_BOOL FXJSE_Value_GetObjectProp(FXJSE_HVALUE hValue, ASSERT(lpValue && lpPropValue); return lpValue->GetObjectProperty(szPropName, lpPropValue); } + FX_BOOL FXJSE_Value_SetObjectProp(FXJSE_HVALUE hValue, const CFX_ByteStringC& szPropName, FXJSE_HVALUE hPropValue) { @@ -166,6 +165,7 @@ FX_BOOL FXJSE_Value_SetObjectProp(FXJSE_HVALUE hValue, ASSERT(lpValue && lpPropValue); return lpValue->SetObjectProperty(szPropName, lpPropValue); } + FX_BOOL FXJSE_Value_GetObjectPropByIdx(FXJSE_HVALUE hValue, uint32_t uPropIdx, FXJSE_HVALUE hPropValue) { @@ -174,6 +174,7 @@ FX_BOOL FXJSE_Value_GetObjectPropByIdx(FXJSE_HVALUE hValue, ASSERT(lpValue && lpPropValue); return lpValue->GetObjectProperty(uPropIdx, lpPropValue); } + FX_BOOL FXJSE_Value_SetObjectPropByIdx(FXJSE_HVALUE hValue, uint32_t uPropIdx, FXJSE_HVALUE hPropValue) { @@ -182,19 +183,20 @@ FX_BOOL FXJSE_Value_SetObjectPropByIdx(FXJSE_HVALUE hValue, 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); + return reinterpret_cast<CFXJSE_Value*>(hValue) + ->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); + return reinterpret_cast<CFXJSE_Value*>(hValue) + ->HasObjectOwnProperty(szPropName, bUseTypeGetter); } + FX_BOOL FXJSE_Value_SetObjectOwnProp(FXJSE_HVALUE hValue, const CFX_ByteStringC& szPropName, FXJSE_HVALUE hPropValue) { @@ -203,6 +205,7 @@ FX_BOOL FXJSE_Value_SetObjectOwnProp(FXJSE_HVALUE hValue, ASSERT(lpValue && lpPropValue); return lpValue->SetObjectOwnProperty(szPropName, lpPropValue); } + FX_BOOL FXJSE_Value_SetFunctionBind(FXJSE_HVALUE hValue, FXJSE_HVALUE hOldFunction, FXJSE_HVALUE hNewThis) { @@ -212,43 +215,44 @@ FX_BOOL FXJSE_Value_SetFunctionBind(FXJSE_HVALUE hValue, 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); + return reinterpret_cast<CFXJSE_Value*>(hFunction) + ->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); + return reinterpret_cast<FXJSE_HVALUE>( + CFXJSE_Value::Create(reinterpret_cast<v8::Isolate*>(hRuntime))); } + void FXJSE_Value_Release(FXJSE_HVALUE hValue) { CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue); - if (lpValue) { - delete 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()); + return reinterpret_cast<FXJSE_HRUNTIME>( + reinterpret_cast<CFXJSE_Value*>(hValue)->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") { @@ -269,33 +273,39 @@ void FXJSE_ThrowMessage(const CFX_ByteStringC& utf8Name, } 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; - } + + if (!hValue->IsObject()) + return nullptr; + 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) { + if (nExponent == 0 || nExponent == 255) return fNumber; - } + int8_t nErrExp = nExponent - 127 - 23; - if (nErrExp >= 0) { + if (nErrExp >= 0) return fNumber; - } + double dwError = pow(2.0, nErrExp), dwErrorHalf = dwError / 2; double dNumber = fNumber, dNumberAbs = fabs(fNumber); double dNumberAbsMin = dNumberAbs - dwErrorHalf, @@ -320,11 +330,13 @@ V8_INLINE static double FXJSE_ftod(FX_FLOAT fNumber) { 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); @@ -334,6 +346,7 @@ void CFXJSE_Value::SetHostObject(void* lpObject, CFXJSE_Class* lpClass) { 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); @@ -347,19 +360,21 @@ void CFXJSE_Value::SetArray(uint32_t uValueCount, CFXJSE_Value** rgValues) { } 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()) { + 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( @@ -368,14 +383,15 @@ FX_BOOL CFXJSE_Value::SetObjectProperty(const CFX_ByteStringC& szPropName, 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()) { + 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, @@ -383,64 +399,69 @@ FX_BOOL CFXJSE_Value::GetObjectProperty(const CFX_ByteStringC& szPropName, 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()) { + 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()) { + 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()) { + 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()) { + 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()) { + 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( @@ -449,21 +470,22 @@ FX_BOOL CFXJSE_Value::SetObjectOwnProperty(const CFX_ByteStringC& szPropName, 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()) { + 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()) { + if (hNewThis.IsEmpty()) return FALSE; - } + rgArgs[1] = hNewThis; v8::Local<v8::String> hBinderFuncSource = v8::String::NewFromUtf8(m_pIsolate, @@ -473,12 +495,13 @@ FX_BOOL CFXJSE_Value::SetFunctionBind(CFXJSE_Value* lpOldFunction, 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()) { + 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, @@ -491,13 +514,14 @@ FX_BOOL CFXJSE_Value::Call(CFXJSE_Value* lpReceiver, !hFunctionValue.IsEmpty() && hFunctionValue->IsObject() ? hFunctionValue.As<v8::Object>() : v8::Local<v8::Object>(); + v8::TryCatch trycatch; if (hFunctionObject.IsEmpty() || !hFunctionObject->IsCallable()) { - if (lpRetValue) { + if (lpRetValue) lpRetValue->ForceSetValue(FXJSE_CreateReturnValue(m_pIsolate, trycatch)); - } return FALSE; } + v8::Local<v8::Value> hReturnValue; v8::Local<v8::Value>* lpLocalArgs = NULL; if (nArgCount) { @@ -514,6 +538,7 @@ FX_BOOL CFXJSE_Value::Call(CFXJSE_Value* lpReceiver, } } } + FX_BOOL bRetValue = TRUE; if (lpReceiver == FXJSE_INVALID_PTR) { hReturnValue = hFunctionObject->CallAsConstructor(nArgCount, lpLocalArgs); @@ -523,23 +548,24 @@ FX_BOOL CFXJSE_Value::Call(CFXJSE_Value* lpReceiver, hReceiver = v8::Local<v8::Value>::New(m_pIsolate, lpReceiver->DirectGetValue()); } - if (hReceiver.IsEmpty() || !hReceiver->IsObject()) { + 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) { + + if (lpRetValue) lpRetValue->ForceSetValue(hReturnValue); - } + if (lpLocalArgs) { - for (uint32_t i = 0; i < nArgCount; i++) { + for (uint32_t i = 0; i < nArgCount; i++) lpLocalArgs[i].~Local(); - } FX_Free(lpLocalArgs); } return bRetValue; |