From 848a13b6777cbff8cc4aea3ab3d69eaa0b82ae6c Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Fri, 9 Oct 2015 13:14:47 -0700 Subject: Pass IJS_Runtime, not IJS_Context, to native object constructors. This better separates the two IJS_ classes, with the IJS_Context taking on its proper role of describing an event. There's no need for the event details for object creation, so this gets much cleaner. Move some JS error reporting code from CJS_Context to CJS_Runtime. Make InitInstance() and ExitInstance() voids, they always return TRUE and we never check the result anyways. R=thestig@chromium.org Review URL: https://codereview.chromium.org/1389163007 . --- fpdfsdk/src/jsapi/fxjs_v8.cpp | 20 +++++++++----------- fpdfsdk/src/jsapi/fxjs_v8_embeddertest.cpp | 4 ++-- 2 files changed, 11 insertions(+), 13 deletions(-) (limited to 'fpdfsdk/src/jsapi') diff --git a/fpdfsdk/src/jsapi/fxjs_v8.cpp b/fpdfsdk/src/jsapi/fxjs_v8.cpp index e674a3f0b2..8a54475910 100644 --- a/fpdfsdk/src/jsapi/fxjs_v8.cpp +++ b/fpdfsdk/src/jsapi/fxjs_v8.cpp @@ -273,8 +273,7 @@ void FXJS_DefineGlobalConst(v8::Isolate* pIsolate, } void FXJS_InitializeRuntime(v8::Isolate* pIsolate, - IJS_Runtime* pFXRuntime, - IJS_Context* context, + IJS_Runtime* pIRuntime, v8::Global& v8PersistentContext) { if (pIsolate == g_isolate) ++g_isolate_ref_count; @@ -286,7 +285,7 @@ void FXJS_InitializeRuntime(v8::Isolate* pIsolate, v8::Context::Scope context_scope(v8Context); FXJS_PerIsolateData::SetUp(pIsolate); - v8Context->SetAlignedPointerInEmbedderData(kPerContextDataIndex, pFXRuntime); + v8Context->SetAlignedPointerInEmbedderData(kPerContextDataIndex, pIRuntime); int maxID = CFXJS_ObjDefinition::MaxID(pIsolate); for (int i = 0; i < maxID; ++i) { @@ -305,12 +304,12 @@ void FXJS_InitializeRuntime(v8::Isolate* pIsolate, ->SetAlignedPointerInInternalField(0, new CFXJS_PrivateData(i)); if (pObjDef->m_pConstructor) - pObjDef->m_pConstructor(context, v8Context->Global() - ->GetPrototype() - ->ToObject(v8Context) - .ToLocalChecked()); + pObjDef->m_pConstructor(pIRuntime, v8Context->Global() + ->GetPrototype() + ->ToObject(v8Context) + .ToLocalChecked()); } else if (pObjDef->m_ObjType == FXJSOBJTYPE_STATIC) { - v8::Local obj = FXJS_NewFxDynamicObj(pIsolate, context, i); + v8::Local obj = FXJS_NewFxDynamicObj(pIsolate, pIRuntime, i); v8Context->Global()->Set(v8Context, m_ObjName, obj).FromJust(); pObjDef->m_StaticObj.Reset(pIsolate, obj); } @@ -359,7 +358,6 @@ IJS_Runtime* FXJS_GetRuntimeFromIsolate(v8::Isolate* pIsolate) { int FXJS_Execute(v8::Isolate* pIsolate, IJS_Context* pJSContext, const wchar_t* script, - long length, FXJSErr* pError) { v8::Isolate::Scope isolate_scope(pIsolate); v8::TryCatch try_catch(pIsolate); @@ -386,7 +384,7 @@ int FXJS_Execute(v8::Isolate* pIsolate, } v8::Local FXJS_NewFxDynamicObj(v8::Isolate* pIsolate, - IJS_Context* pJSContext, + IJS_Runtime* pIRuntime, int nObjDefnID) { v8::Isolate::Scope isolate_scope(pIsolate); v8::Local context = pIsolate->GetCurrentContext(); @@ -413,7 +411,7 @@ v8::Local FXJS_NewFxDynamicObj(v8::Isolate* pIsolate, obj->SetAlignedPointerInInternalField(0, new CFXJS_PrivateData(nObjDefnID)); if (pObjDef->m_pConstructor) - pObjDef->m_pConstructor(pJSContext, obj); + pObjDef->m_pConstructor(pIRuntime, obj); return obj; } diff --git a/fpdfsdk/src/jsapi/fxjs_v8_embeddertest.cpp b/fpdfsdk/src/jsapi/fxjs_v8_embeddertest.cpp index 187d611770..b0f3f85167 100644 --- a/fpdfsdk/src/jsapi/fxjs_v8_embeddertest.cpp +++ b/fpdfsdk/src/jsapi/fxjs_v8_embeddertest.cpp @@ -32,7 +32,7 @@ class FXJSV8Embeddertest : public EmbedderTest { v8::Isolate::Scope isolate_scope(m_pIsolate); v8::HandleScope handle_scope(m_pIsolate); FXJS_PerIsolateData::SetUp(m_pIsolate); - FXJS_InitializeRuntime(m_pIsolate, nullptr, nullptr, m_pPersistentContext); + FXJS_InitializeRuntime(m_pIsolate, nullptr, m_pPersistentContext); } void TearDown() override { @@ -61,7 +61,7 @@ TEST_F(FXJSV8Embeddertest, Getters) { FXJSErr error; CFX_WideString wsInfo; CFX_WideString wsScript(kScript); - int sts = FXJS_Execute(isolate(), nullptr, kScript, wcslen(kScript), &error); + int sts = FXJS_Execute(isolate(), nullptr, kScript, &error); EXPECT_EQ(0, sts); v8::Local This = FXJS_GetThisObj(isolate()); -- cgit v1.2.3