From da379c7af512aa7baa221d38b04c8aa9912b4e02 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Tue, 28 Aug 2018 23:12:22 +0000 Subject: Stop using deprecated v8::ObjectTemplate::NewInstance(). Fix nits in affected files. Change-Id: I3a0363c9b7c28359fd1c7cea305e4f7705a228c2 Reviewed-on: https://pdfium-review.googlesource.com/41355 Commit-Queue: Lei Zhang Reviewed-by: Tom Sepez --- fxjs/cfxjse_class.cpp | 40 ++++++++++++++++++++-------------------- fxjs/cfxjse_class.h | 12 ++++-------- fxjs/cfxjse_engine.cpp | 4 +++- fxjs/cfxjse_value.cpp | 15 +++++++++------ fxjs/cfxjse_value.h | 8 ++++---- 5 files changed, 40 insertions(+), 39 deletions(-) diff --git a/fxjs/cfxjse_class.cpp b/fxjs/cfxjse_class.cpp index 0d68147326..8e49ebe373 100644 --- a/fxjs/cfxjse_class.cpp +++ b/fxjs/cfxjse_class.cpp @@ -142,7 +142,9 @@ void DynPropGetterAdapter(const FXJSE_CLASS_DESCRIPTOR* lpClass, v8::ObjectTemplate::New(pIsolate); hCallBackInfoTemplate->SetInternalFieldCount(2); v8::Local hCallBackInfo = - hCallBackInfoTemplate->NewInstance(); + hCallBackInfoTemplate + ->NewInstance(pValue->GetIsolate()->GetCurrentContext()) + .ToLocalChecked(); hCallBackInfo->SetAlignedPointerInInternalField( 0, const_cast(lpClass)); hCallBackInfo->SetInternalField( @@ -251,6 +253,21 @@ void NamedPropertyEnumeratorCallback( info.GetReturnValue().Set(v8::Array::New(info.GetIsolate())); } +void SetUpNamedPropHandler(v8::Isolate* pIsolate, + v8::Local* pObjectTemplate, + const FXJSE_CLASS_DESCRIPTOR* lpClassDefinition) { + v8::NamedPropertyHandlerConfiguration configuration( + lpClassDefinition->dynPropGetter ? NamedPropertyGetterCallback : nullptr, + lpClassDefinition->dynPropSetter ? NamedPropertySetterCallback : nullptr, + lpClassDefinition->dynPropTypeGetter ? NamedPropertyQueryCallback + : nullptr, + nullptr, NamedPropertyEnumeratorCallback, + v8::External::New(pIsolate, + const_cast(lpClassDefinition)), + v8::PropertyHandlerFlags::kNonMasking); + (*pObjectTemplate)->SetHandler(configuration); +} + } // namespace // static @@ -280,7 +297,7 @@ CFXJSE_Class* CFXJSE_Class::Create( hFunctionTemplate->InstanceTemplate()->SetInternalFieldCount(2); v8::Local hObjectTemplate = hFunctionTemplate->InstanceTemplate(); - SetUpNamedPropHandler(pIsolate, hObjectTemplate, lpClassDefinition); + SetUpNamedPropHandler(pIsolate, &hObjectTemplate, lpClassDefinition); if (lpClassDefinition->methNum) { for (int32_t i = 0; i < lpClassDefinition->methNum; i++) { @@ -310,23 +327,6 @@ CFXJSE_Class* CFXJSE_Class::Create( return pResult; } -// static -void CFXJSE_Class::SetUpNamedPropHandler( - v8::Isolate* pIsolate, - v8::Local& hObjectTemplate, - const FXJSE_CLASS_DESCRIPTOR* lpClassDefinition) { - v8::NamedPropertyHandlerConfiguration configuration( - lpClassDefinition->dynPropGetter ? NamedPropertyGetterCallback : 0, - lpClassDefinition->dynPropSetter ? NamedPropertySetterCallback : 0, - lpClassDefinition->dynPropTypeGetter ? NamedPropertyQueryCallback : 0, 0, - NamedPropertyEnumeratorCallback, - v8::External::New(pIsolate, - const_cast(lpClassDefinition)), - v8::PropertyHandlerFlags::kNonMasking); - hObjectTemplate->SetHandler(configuration); -} - -CFXJSE_Class::CFXJSE_Class(CFXJSE_Context* lpContext) - : m_lpClassDefinition(nullptr), m_pContext(lpContext) {} +CFXJSE_Class::CFXJSE_Class(CFXJSE_Context* lpContext) : m_pContext(lpContext) {} CFXJSE_Class::~CFXJSE_Class() {} diff --git a/fxjs/cfxjse_class.h b/fxjs/cfxjse_class.h index 056525f30b..fd9786ea3b 100644 --- a/fxjs/cfxjse_class.h +++ b/fxjs/cfxjse_class.h @@ -20,11 +20,6 @@ class CFXJSE_Class { const FXJSE_CLASS_DESCRIPTOR* lpClassDefintion, bool bIsJSGlobal); - static void SetUpNamedPropHandler( - v8::Isolate* pIsolate, - v8::Local& hObjectTemplate, - const FXJSE_CLASS_DESCRIPTOR* lpClassDefinition); - explicit CFXJSE_Class(CFXJSE_Context* lpContext); ~CFXJSE_Class(); @@ -32,12 +27,13 @@ class CFXJSE_Class { v8::Global& GetTemplate() { return m_hTemplate; } protected: + friend class CFXJSE_Context; + friend class CFXJSE_Value; + ByteString m_szClassName; UnownedPtr m_lpClassDefinition; - UnownedPtr m_pContext; + UnownedPtr const m_pContext; v8::Global m_hTemplate; - friend class CFXJSE_Context; - friend class CFXJSE_Value; }; #endif // FXJS_CFXJSE_CLASS_H_ diff --git a/fxjs/cfxjse_engine.cpp b/fxjs/cfxjse_engine.cpp index a4fc0a2bdb..1812d02e50 100644 --- a/fxjs/cfxjse_engine.cpp +++ b/fxjs/cfxjse_engine.cpp @@ -805,7 +805,9 @@ v8::Local CFXJSE_Engine::NewXFAObject( v8::EscapableHandleScope scope(GetIsolate()); v8::Local klass = v8::Local::New(GetIsolate(), tmpl); - v8::Local object = klass->InstanceTemplate()->NewInstance(); + v8::Local object = klass->InstanceTemplate() + ->NewInstance(m_JsContext->GetContext()) + .ToLocalChecked(); FXJSE_UpdateObjectBinding(object, obj); return scope.Escape(object); } diff --git a/fxjs/cfxjse_value.cpp b/fxjs/cfxjse_value.cpp index 6afba97c2d..6d0f6f7fdf 100644 --- a/fxjs/cfxjse_value.cpp +++ b/fxjs/cfxjse_value.cpp @@ -84,7 +84,10 @@ void CFXJSE_Value::SetObject(CFXJSE_HostObject* lpObject, CFXJSE_ScopeUtil_IsolateHandleRootContext scope(GetIsolate()); v8::Local hClass = v8::Local::New(GetIsolate(), pClass->m_hTemplate); - v8::Local hObject = hClass->InstanceTemplate()->NewInstance(); + v8::Local hObject = + hClass->InstanceTemplate() + ->NewInstance(GetIsolate()->GetCurrentContext()) + .ToLocalChecked(); FXJSE_UpdateObjectBinding(hObject, lpObject); m_hValue.Reset(GetIsolate(), hObject); } @@ -125,11 +128,11 @@ bool CFXJSE_Value::SetObjectProperty(const ByteStringView& szPropName, v8::Local hPropValue = v8::Local::New(GetIsolate(), lpPropValue->DirectGetValue()); - return (bool)hObject.As()->Set( + return static_cast(hObject.As()->Set( v8::String::NewFromUtf8(GetIsolate(), szPropName.unterminated_c_str(), v8::String::kNormalString, szPropName.GetLength()), - hPropValue); + hPropValue)); } bool CFXJSE_Value::GetObjectProperty(const ByteStringView& szPropName, @@ -159,7 +162,7 @@ bool CFXJSE_Value::SetObjectProperty(uint32_t uPropIdx, v8::Local hPropValue = v8::Local::New(GetIsolate(), lpPropValue->DirectGetValue()); - return (bool)hObject.As()->Set(uPropIdx, hPropValue); + return static_cast(hObject.As()->Set(uPropIdx, hPropValue)); } bool CFXJSE_Value::GetObjectPropertyByIdx(uint32_t uPropIdx, @@ -219,7 +222,7 @@ bool CFXJSE_Value::SetObjectOwnProperty(const ByteStringView& szPropName, v8::Local::New(GetIsolate(), lpPropValue->m_hValue); return hObject.As() ->DefineOwnProperty( - m_pIsolate->GetCurrentContext(), + GetIsolate()->GetCurrentContext(), v8::String::NewFromUtf8(GetIsolate(), szPropName.unterminated_c_str(), v8::String::kNormalString, szPropName.GetLength()), @@ -249,7 +252,7 @@ bool CFXJSE_Value::SetFunctionBind(CFXJSE_Value* lpOldFunction, v8::String::NewFromUtf8(GetIsolate(), "(function (oldfunction, newthis) { return " "oldfunction.bind(newthis); })"); - v8::Local hContext = m_pIsolate->GetCurrentContext(); + v8::Local hContext = GetIsolate()->GetCurrentContext(); v8::Local hBinderFunc = v8::Script::Compile(hContext, hBinderFuncSource) .ToLocalChecked() diff --git a/fxjs/cfxjse_value.h b/fxjs/cfxjse_value.h index dd01843990..f83ddc31c7 100644 --- a/fxjs/cfxjse_value.h +++ b/fxjs/cfxjse_value.h @@ -88,11 +88,11 @@ class CFXJSE_Value { friend class CFXJSE_Class; friend class CFXJSE_Context; - CFXJSE_Value(); - CFXJSE_Value(const CFXJSE_Value&); - CFXJSE_Value& operator=(const CFXJSE_Value&); + CFXJSE_Value() = delete; + CFXJSE_Value(const CFXJSE_Value&) = delete; + CFXJSE_Value& operator=(const CFXJSE_Value&) = delete; - UnownedPtr m_pIsolate; + UnownedPtr const m_pIsolate; v8::Global m_hValue; }; -- cgit v1.2.3