From ce00f4a129899bfc62583c9e3b06654e5bbe17cb Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Fri, 4 Mar 2016 10:37:34 -0800 Subject: Fix deprecated ObjectTemplate::New() and TryCatch() warnings. R=jochen@chromium.org Review URL: https://codereview.chromium.org/1762643003 . --- xfa/src/fxjse/src/class.h | 3 - xfa/src/fxjse/src/context.cpp | 4 +- xfa/src/fxjse/src/dynprop.cpp | 241 +----------------------------------------- xfa/src/fxjse/src/value.cpp | 2 +- 4 files changed, 4 insertions(+), 246 deletions(-) (limited to 'xfa') diff --git a/xfa/src/fxjse/src/class.h b/xfa/src/fxjse/src/class.h index 794a34e7b8..3c1780fc58 100644 --- a/xfa/src/fxjse/src/class.h +++ b/xfa/src/fxjse/src/class.h @@ -28,9 +28,6 @@ class CFXJSE_Class { 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& hObjectTemplate, diff --git a/xfa/src/fxjse/src/context.cpp b/xfa/src/fxjse/src/context.cpp index 54b4f64efc..9d5b699c8b 100644 --- a/xfa/src/fxjse/src/context.cpp +++ b/xfa/src/fxjse/src/context.cpp @@ -182,7 +182,7 @@ CFXJSE_Context* CFXJSE_Context::Create(v8::Isolate* pIsolate, lpGlobalClassObj->m_hTemplate); hObjectTemplate = hFunctionTemplate->InstanceTemplate(); } else { - hObjectTemplate = v8::ObjectTemplate::New(); + hObjectTemplate = v8::ObjectTemplate::New(pIsolate); hObjectTemplate->SetInternalFieldCount(1); } v8::Local hNewContext = @@ -220,7 +220,7 @@ FX_BOOL CFXJSE_Context::ExecuteScript(const FX_CHAR* szScript, CFXJSE_Value* lpRetValue, CFXJSE_Value* lpNewThisObject) { CFXJSE_ScopeUtil_IsolateHandleContext scope(this); - v8::TryCatch trycatch; + v8::TryCatch trycatch(m_pIsolate); v8::Local hScriptString = v8::String::NewFromUtf8(m_pIsolate, szScript); if (lpNewThisObject == NULL) { diff --git a/xfa/src/fxjse/src/dynprop.cpp b/xfa/src/fxjse/src/dynprop.cpp index 26beb5c283..bc423c03c0 100644 --- a/xfa/src/fxjse/src/dynprop.cpp +++ b/xfa/src/fxjse/src/dynprop.cpp @@ -52,7 +52,7 @@ static void FXJSE_DynPropGetterAdapter(const FXJSE_CLASS* lpClass, v8::Isolate* pIsolate = lpValue->GetIsolate(); v8::HandleScope hscope(pIsolate); v8::Local hCallBackInfoTemplate = - v8::ObjectTemplate::New(); + v8::ObjectTemplate::New(pIsolate); hCallBackInfoTemplate->SetInternalFieldCount(2); v8::Local hCallBackInfo = hCallBackInfoTemplate->NewInstance(); @@ -114,184 +114,6 @@ static FX_BOOL FXJSE_DynPropDeleterAdapter(const FXJSE_CLASS* lpClass, return FALSE; } -static void FXJSE_V8ProxyCallback_getOwnPropertyDescriptor_getter( - const v8::FunctionCallbackInfo& info) { - v8::Local hCallBackInfo = info.Data().As(); - FXJSE_CLASS* lpClass = static_cast( - hCallBackInfo->GetAlignedPointerFromInternalField(0)); - v8::Local hPropName = - hCallBackInfo->GetInternalField(1).As(); - 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(lpThisValue), szFxPropName, - reinterpret_cast(lpNewValue)); - info.GetReturnValue().Set(lpNewValue->DirectGetValue()); - delete lpThisValue; - lpThisValue = nullptr; - delete lpNewValue; - lpNewValue = nullptr; -} - -static void FXJSE_V8ProxyCallback_getOwnPropertyDescriptor_setter( - const v8::FunctionCallbackInfo& info) { - v8::Local hCallBackInfo = info.Data().As(); - FXJSE_CLASS* lpClass = static_cast( - hCallBackInfo->GetAlignedPointerFromInternalField(0)); - v8::Local hPropName = - hCallBackInfo->GetInternalField(1).As(); - 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(lpThisValue), szFxPropName, - reinterpret_cast(lpNewValue)); - delete lpThisValue; - lpThisValue = nullptr; - delete lpNewValue; - lpNewValue = nullptr; -} - -static void FXJSE_V8ProxyCallback_getOwnPropertyDescriptor( - const v8::FunctionCallbackInfo& info) { - const FXJSE_CLASS* lpClass = - static_cast(info.Data().As()->Value()); - if (!lpClass) { - return; - } - v8::Isolate* pIsolate = info.GetIsolate(); - v8::HandleScope scope(pIsolate); - v8::Local hPropName = info[0]->ToString(); - v8::String::Utf8Value szPropName(hPropName); - CFX_ByteStringC szFxPropName(*szPropName, szPropName.length()); - v8::Local hCallBackInfoTemplate = - v8::ObjectTemplate::New(); - hCallBackInfoTemplate->SetInternalFieldCount(2); - v8::Local hCallBackInfo = hCallBackInfoTemplate->NewInstance(); - hCallBackInfo->SetAlignedPointerInInternalField( - 0, const_cast(lpClass)); - hCallBackInfo->SetInternalField(1, hPropName); - v8::Local 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& info) { - v8::Isolate* pIsolate = info.GetIsolate(); - v8::Local hChainObj = - info.This()->GetPrototype().As(); - v8::Local 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 fn = fnSource->Run().As(); - v8::Local rgArgs[] = {hChainObj, info[0]}; - v8::Local 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& 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& info) { - v8::Local hChainObj = - info.This()->GetPrototype().As(); - v8::Local hChainPropertyNames = hChainObj->GetPropertyNames(); - info.GetReturnValue().Set(hChainPropertyNames); -} - -static void FXJSE_V8ProxyCallback_defineProperty( - const v8::FunctionCallbackInfo& info) { - const FXJSE_CLASS* lpClass = - static_cast(info.Data().As()->Value()); - if (!lpClass) { - return; - } - v8::Isolate* pIsolate = info.GetIsolate(); - v8::HandleScope scope(pIsolate); - v8::Local hPropName = info[0]->ToString(); - v8::Local hPropDescriptor = info[1]->ToObject(); - v8::String::Utf8Value szPropName(hPropName); - if (!hPropDescriptor->Has(v8::String::NewFromUtf8(pIsolate, "value"))) { - return; - } - v8::Local 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(lpThisValue), szFxPropName, - reinterpret_cast(lpPropValue)); - delete lpThisValue; - lpThisValue = nullptr; - delete lpPropValue; - lpPropValue = nullptr; -} - -static void FXJSE_V8ProxyCallback_delete( - const v8::FunctionCallbackInfo& info) { - info.GetReturnValue().Set(true); - const FXJSE_CLASS* lpClass = - static_cast(info.Data().As()->Value()); - if (!lpClass) { - return; - } - v8::Isolate* pIsolate = info.GetIsolate(); - v8::HandleScope scope(pIsolate); - v8::Local 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(lpThisValue), szFxPropName) - ? true - : false); - delete lpThisValue; - lpThisValue = nullptr; -} - -static void FXJSE_V8ProxyCallback_fix( - const v8::FunctionCallbackInfo& info) { - info.GetReturnValue().SetUndefined(); -} - static void FXJSE_V8_GenericNamedPropertyQueryCallback( v8::Local property, const v8::PropertyCallbackInfo& info) { @@ -390,67 +212,6 @@ static void FXJSE_V8_GenericNamedPropertyEnumeratorCallback( 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 hContext = v8::Local::New( - pIsolate, pContext ? pContext->m_hContext - : CFXJSE_RuntimeData::Get(pIsolate)->m_hRootContext); - v8::Local hObject = - v8::Local::New(pIsolate, pValue->m_hValue).As(); - v8::Local hHarmonyProxyObj = - hContext->Global() - ->Get(v8::String::NewFromUtf8(pIsolate, "Proxy")) - .As(); - v8::Local hHarmonyProxyCreateFn = - hHarmonyProxyObj->Get(v8::String::NewFromUtf8(pIsolate, "create")) - .As(); - v8::Local hOldPrototype = hObject->GetPrototype(); - v8::Local 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(lpClassDefinition)))); - hTrapper->ForceSet( - v8::String::NewFromUtf8(pIsolate, "getPropertyDescriptor"), - v8::Function::New(pIsolate, FXJSE_V8ProxyCallback_getPropertyDescriptor, - v8::External::New(pIsolate, const_cast( - lpClassDefinition)))); - hTrapper->ForceSet( - v8::String::NewFromUtf8(pIsolate, "getOwnPropertyNames"), - v8::Function::New(pIsolate, FXJSE_V8ProxyCallback_getOwnPropertyNames, - v8::External::New(pIsolate, const_cast( - lpClassDefinition)))); - hTrapper->ForceSet( - v8::String::NewFromUtf8(pIsolate, "getPropertyNames"), - v8::Function::New(pIsolate, FXJSE_V8ProxyCallback_getPropertyNames, - v8::External::New(pIsolate, const_cast( - lpClassDefinition)))); - hTrapper->ForceSet( - v8::String::NewFromUtf8(pIsolate, "delete"), - v8::Function::New(pIsolate, FXJSE_V8ProxyCallback_delete, - v8::External::New(pIsolate, const_cast( - lpClassDefinition)))); - hTrapper->ForceSet( - v8::String::NewFromUtf8(pIsolate, "defineProperty"), - v8::Function::New(pIsolate, FXJSE_V8ProxyCallback_defineProperty, - v8::External::New(pIsolate, const_cast( - lpClassDefinition)))); - hTrapper->ForceSet( - v8::String::NewFromUtf8(pIsolate, "fix"), - v8::Function::New(pIsolate, FXJSE_V8ProxyCallback_fix, - v8::External::New(pIsolate, const_cast( - lpClassDefinition)))); - v8::Local rgArgs[] = {hTrapper, hOldPrototype}; - v8::Local hNewPrototype = - hHarmonyProxyCreateFn->Call(hHarmonyProxyObj, 2, rgArgs); - hObject->SetPrototype(hNewPrototype); -} - void CFXJSE_Class::SetUpNamedPropHandler( v8::Isolate* pIsolate, v8::Local& hObjectTemplate, diff --git a/xfa/src/fxjse/src/value.cpp b/xfa/src/fxjse/src/value.cpp index b3c47b65c0..d4e2c0dbc2 100644 --- a/xfa/src/fxjse/src/value.cpp +++ b/xfa/src/fxjse/src/value.cpp @@ -515,7 +515,7 @@ FX_BOOL CFXJSE_Value::Call(CFXJSE_Value* lpReceiver, ? hFunctionValue.As() : v8::Local(); - v8::TryCatch trycatch; + v8::TryCatch trycatch(m_pIsolate); if (hFunctionObject.IsEmpty() || !hFunctionObject->IsCallable()) { if (lpRetValue) lpRetValue->ForceSetValue(FXJSE_CreateReturnValue(m_pIsolate, trycatch)); -- cgit v1.2.3