diff options
author | Tom Sepez <tsepez@chromium.org> | 2018-02-07 21:07:24 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-02-07 21:07:24 +0000 |
commit | 9ad9a5fc81a36ab406ff49408dd0814d350bbc7e (patch) | |
tree | ec46a8cbec08c17d5932bd330c4fd4b5baa2c180 | |
parent | 161f992a81e400eeebba49387f174d836750d624 (diff) | |
download | pdfium-chromium/3343.tar.xz |
Split creation of ordinary object and bound objects in FXJS.chromium/3343
One can be performed by the CJS_V8 layer, the other requires the
full FXJS mechanism. Avoids using -1 as a special case.
Change-Id: I4a14ccb6a7fea393f84b70a07ada03b1a83c7d36
Reviewed-on: https://pdfium-review.googlesource.com/25830
Reviewed-by: dsinclair <dsinclair@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
-rw-r--r-- | fxjs/cjs_app.cpp | 4 | ||||
-rw-r--r-- | fxjs/cjs_document.cpp | 14 | ||||
-rw-r--r-- | fxjs/cjs_eventhandler.cpp | 8 | ||||
-rw-r--r-- | fxjs/cjs_field.cpp | 4 | ||||
-rw-r--r-- | fxjs/cjs_global.cpp | 4 | ||||
-rw-r--r-- | fxjs/cjs_v8.cpp | 4 | ||||
-rw-r--r-- | fxjs/cjs_v8.h | 1 | ||||
-rw-r--r-- | fxjs/fxjs_v8.cpp | 15 | ||||
-rw-r--r-- | fxjs/fxjs_v8.h | 3 | ||||
-rw-r--r-- | fxjs/fxjs_v8_embeddertest.cpp | 2 |
10 files changed, 28 insertions, 31 deletions
diff --git a/fxjs/cjs_app.cpp b/fxjs/cjs_app.cpp index 1df0146a58..5bd41e8bc0 100644 --- a/fxjs/cjs_app.cpp +++ b/fxjs/cjs_app.cpp @@ -317,7 +317,7 @@ CJS_Return CJS_App::setInterval( m_Timers.insert(std::unique_ptr<GlobalTimer>(timerRef)); v8::Local<v8::Object> pRetObj = - pRuntime->NewFxDynamicObj(CJS_TimerObj::GetObjDefnID()); + pRuntime->NewFXJSBoundObject(CJS_TimerObj::GetObjDefnID()); if (pRetObj.IsEmpty()) return CJS_Return(false); @@ -344,7 +344,7 @@ CJS_Return CJS_App::setTimeOut( m_Timers.insert(std::unique_ptr<GlobalTimer>(timerRef)); v8::Local<v8::Object> pRetObj = - pRuntime->NewFxDynamicObj(CJS_TimerObj::GetObjDefnID()); + pRuntime->NewFXJSBoundObject(CJS_TimerObj::GetObjDefnID()); if (pRetObj.IsEmpty()) return CJS_Return(false); diff --git a/fxjs/cjs_document.cpp b/fxjs/cjs_document.cpp index c4a5ff4091..83711e1b28 100644 --- a/fxjs/cjs_document.cpp +++ b/fxjs/cjs_document.cpp @@ -254,7 +254,7 @@ CJS_Return CJS_Document::getField( return CJS_Return(pRuntime->NewUndefined()); v8::Local<v8::Object> pFieldObj = - pRuntime->NewFxDynamicObj(CJS_Field::GetObjDefnID()); + pRuntime->NewFXJSBoundObject(CJS_Field::GetObjDefnID()); if (pFieldObj.IsEmpty()) return CJS_Return(false); @@ -672,7 +672,7 @@ CJS_Return CJS_Document::get_info(CJS_Runtime* pRuntime) { WideString cwModDate = pDictionary->GetUnicodeTextFor("ModDate"); WideString cwTrapped = pDictionary->GetUnicodeTextFor("Trapped"); - v8::Local<v8::Object> pObj = pRuntime->NewFxDynamicObj(-1); + v8::Local<v8::Object> pObj = pRuntime->NewObject(); pRuntime->PutObjectProperty(pObj, L"Author", pRuntime->NewString(cwAuthor.AsStringView())); pRuntime->PutObjectProperty(pObj, L"Title", @@ -1031,7 +1031,7 @@ CJS_Return CJS_Document::getAnnot( return CJS_Return(false); v8::Local<v8::Object> pObj = - pRuntime->NewFxDynamicObj(CJS_Annot::GetObjDefnID()); + pRuntime->NewFXJSBoundObject(CJS_Annot::GetObjDefnID()); if (pObj.IsEmpty()) return CJS_Return(false); @@ -1066,7 +1066,7 @@ CJS_Return CJS_Document::getAnnots( return CJS_Return(JSGetStringFromID(JSMessage::kBadObjectError)); v8::Local<v8::Object> pObj = - pRuntime->NewFxDynamicObj(CJS_Annot::GetObjDefnID()); + pRuntime->NewFXJSBoundObject(CJS_Annot::GetObjDefnID()); if (pObj.IsEmpty()) return CJS_Return(false); @@ -1143,7 +1143,7 @@ CJS_Return CJS_Document::get_icons(CJS_Runtime* pRuntime) { int i = 0; for (const auto& name : m_IconNames) { v8::Local<v8::Object> pObj = - pRuntime->NewFxDynamicObj(CJS_Icon::GetObjDefnID()); + pRuntime->NewFXJSBoundObject(CJS_Icon::GetObjDefnID()); if (pObj.IsEmpty()) return CJS_Return(false); @@ -1175,7 +1175,7 @@ CJS_Return CJS_Document::getIcon( return CJS_Return(false); v8::Local<v8::Object> pObj = - pRuntime->NewFxDynamicObj(CJS_Icon::GetObjDefnID()); + pRuntime->NewFXJSBoundObject(CJS_Icon::GetObjDefnID()); if (pObj.IsEmpty()) return CJS_Return(false); @@ -1325,7 +1325,7 @@ CJS_Return CJS_Document::getPrintParams( CJS_Runtime* pRuntime, const std::vector<v8::Local<v8::Value>>& params) { v8::Local<v8::Object> pRetObj = - pRuntime->NewFxDynamicObj(CJS_PrintParamsObj::GetObjDefnID()); + pRuntime->NewFXJSBoundObject(CJS_PrintParamsObj::GetObjDefnID()); if (pRetObj.IsEmpty()) return CJS_Return(false); diff --git a/fxjs/cjs_eventhandler.cpp b/fxjs/cjs_eventhandler.cpp index 6e7e840250..b09ca7e733 100644 --- a/fxjs/cjs_eventhandler.cpp +++ b/fxjs/cjs_eventhandler.cpp @@ -590,12 +590,12 @@ bool CJS_EventHandler::Shift() const { CJS_Field* CJS_EventHandler::Source() { CJS_Runtime* pRuntime = m_pJSEventContext->GetJSRuntime(); v8::Local<v8::Object> pDocObj = - pRuntime->NewFxDynamicObj(CJS_Document::GetObjDefnID()); + pRuntime->NewFXJSBoundObject(CJS_Document::GetObjDefnID()); if (pDocObj.IsEmpty()) return nullptr; v8::Local<v8::Object> pFieldObj = - pRuntime->NewFxDynamicObj(CJS_Field::GetObjDefnID()); + pRuntime->NewFXJSBoundObject(CJS_Field::GetObjDefnID()); if (pFieldObj.IsEmpty()) return nullptr; @@ -615,12 +615,12 @@ CJS_Field* CJS_EventHandler::Source() { CJS_Field* CJS_EventHandler::Target_Field() { CJS_Runtime* pRuntime = m_pJSEventContext->GetJSRuntime(); v8::Local<v8::Object> pDocObj = - pRuntime->NewFxDynamicObj(CJS_Document::GetObjDefnID()); + pRuntime->NewFXJSBoundObject(CJS_Document::GetObjDefnID()); if (pDocObj.IsEmpty()) return nullptr; v8::Local<v8::Object> pFieldObj = - pRuntime->NewFxDynamicObj(CJS_Field::GetObjDefnID()); + pRuntime->NewFXJSBoundObject(CJS_Field::GetObjDefnID()); if (pFieldObj.IsEmpty()) return nullptr; diff --git a/fxjs/cjs_field.cpp b/fxjs/cjs_field.cpp index 9138d93590..7b4c064a9e 100644 --- a/fxjs/cjs_field.cpp +++ b/fxjs/cjs_field.cpp @@ -2284,7 +2284,7 @@ CJS_Return CJS_Field::buttonGetIcon( return CJS_Return(false); v8::Local<v8::Object> pObj = - pRuntime->NewFxDynamicObj(CJS_Icon::GetObjDefnID()); + pRuntime->NewFXJSBoundObject(CJS_Icon::GetObjDefnID()); if (pObj.IsEmpty()) return CJS_Return(false); @@ -2404,7 +2404,7 @@ CJS_Return CJS_Field::getArray( int j = 0; for (const auto& pStr : swSort) { v8::Local<v8::Object> pObj = - pRuntime->NewFxDynamicObj(CJS_Field::GetObjDefnID()); + pRuntime->NewFXJSBoundObject(CJS_Field::GetObjDefnID()); if (pObj.IsEmpty()) return CJS_Return(false); diff --git a/fxjs/cjs_global.cpp b/fxjs/cjs_global.cpp index fbc6bf94e8..729190fe13 100644 --- a/fxjs/cjs_global.cpp +++ b/fxjs/cjs_global.cpp @@ -333,7 +333,7 @@ void CJS_Global::UpdateGlobalPersistentVariables() { pRuntime->NewString(pData->data.sData.UTF8Decode().AsStringView())); break; case JS_GlobalDataType::OBJECT: { - v8::Local<v8::Object> pObj = pRuntime->NewFxDynamicObj(-1); + v8::Local<v8::Object> pObj = pRuntime->NewObject(); if (!pObj.IsEmpty()) { PutObjectProperty(pObj, &pData->data); SetGlobalVariables(pData->data.sKey, JS_GlobalDataType::OBJECT, 0, @@ -461,7 +461,7 @@ void CJS_Global::PutObjectProperty(v8::Local<v8::Object> pObj, pRuntime->NewString(pObjData->sData.UTF8Decode().AsStringView())); break; case JS_GlobalDataType::OBJECT: { - v8::Local<v8::Object> pNewObj = pRuntime->NewFxDynamicObj(-1); + v8::Local<v8::Object> pNewObj = pRuntime->NewObject(); if (!pNewObj.IsEmpty()) { PutObjectProperty(pNewObj, pObjData); pRuntime->PutObjectProperty(pObj, pObjData->sKey.UTF8Decode(), diff --git a/fxjs/cjs_v8.cpp b/fxjs/cjs_v8.cpp index 7855813cba..0a1674076d 100644 --- a/fxjs/cjs_v8.cpp +++ b/fxjs/cjs_v8.cpp @@ -60,6 +60,10 @@ v8::Local<v8::Array> CJS_V8::NewArray() { return v8::Array::New(m_isolate); } +v8::Local<v8::Object> CJS_V8::NewObject() { + return v8::Object::New(m_isolate); +} + unsigned CJS_V8::PutArrayElement(v8::Local<v8::Array> pArray, unsigned index, v8::Local<v8::Value> pValue) { diff --git a/fxjs/cjs_v8.h b/fxjs/cjs_v8.h index 135930902e..b8a1e13881 100644 --- a/fxjs/cjs_v8.h +++ b/fxjs/cjs_v8.h @@ -30,6 +30,7 @@ class CJS_V8 { v8::Local<v8::Value> NewNull(); v8::Local<v8::Value> NewUndefined(); v8::Local<v8::Array> NewArray(); + v8::Local<v8::Object> NewObject(); v8::Local<v8::Number> NewNumber(int number); v8::Local<v8::Number> NewNumber(double number); v8::Local<v8::Number> NewNumber(float number); diff --git a/fxjs/fxjs_v8.cpp b/fxjs/fxjs_v8.cpp index 773f9025b1..8a04a0680e 100644 --- a/fxjs/fxjs_v8.cpp +++ b/fxjs/fxjs_v8.cpp @@ -414,7 +414,7 @@ void CFXJS_Engine::InitializeEngine() { } } else if (pObjDef->m_ObjType == FXJSOBJTYPE_STATIC) { v8::Local<v8::String> pObjName = NewString(pObjDef->m_ObjName); - v8::Local<v8::Object> obj = NewFxDynamicObj(i, true); + v8::Local<v8::Object> obj = NewFXJSBoundObject(i, true); if (!obj.IsEmpty()) { v8Context->Global()->Set(v8Context, pObjName, obj).FromJust(); m_StaticObjects[i] = v8::Global<v8::Object>(GetIsolate(), obj); @@ -484,19 +484,10 @@ int CFXJS_Engine::Execute(const WideString& script, FXJSErr* pError) { return 0; } -v8::Local<v8::Object> CFXJS_Engine::NewFxDynamicObj(int nObjDefnID, - bool bStatic) { +v8::Local<v8::Object> CFXJS_Engine::NewFXJSBoundObject(int nObjDefnID, + bool bStatic) { v8::Isolate::Scope isolate_scope(GetIsolate()); v8::Local<v8::Context> context = GetIsolate()->GetCurrentContext(); - if (nObjDefnID == -1) { - v8::Local<v8::ObjectTemplate> objTempl = - v8::ObjectTemplate::New(GetIsolate()); - v8::Local<v8::Object> obj; - if (!objTempl->NewInstance(context).ToLocal(&obj)) - return v8::Local<v8::Object>(); - return obj; - } - FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(GetIsolate()); if (!pData) return v8::Local<v8::Object>(); diff --git a/fxjs/fxjs_v8.h b/fxjs/fxjs_v8.h index 3e8e861403..0592847bb2 100644 --- a/fxjs/fxjs_v8.h +++ b/fxjs/fxjs_v8.h @@ -176,7 +176,8 @@ class CFXJS_Engine : public CJS_V8 { int Execute(const WideString& script, FXJSErr* perror); v8::Local<v8::Object> GetThisObj(); - v8::Local<v8::Object> NewFxDynamicObj(int nObjDefnID, bool bStatic = false); + v8::Local<v8::Object> NewFXJSBoundObject(int nObjDefnID, + bool bStatic = false); // Native object binding. void SetObjectPrivate(v8::Local<v8::Object> pObj, diff --git a/fxjs/fxjs_v8_embeddertest.cpp b/fxjs/fxjs_v8_embeddertest.cpp index 9e90663aa2..acc4366631 100644 --- a/fxjs/fxjs_v8_embeddertest.cpp +++ b/fxjs/fxjs_v8_embeddertest.cpp @@ -226,7 +226,7 @@ TEST_F(FXJSV8EmbedderTest, NewObject) { v8::HandleScope handle_scope(isolate()); v8::Context::Scope context_scope(GetV8Context()); - auto object = engine()->NewFxDynamicObj(-1); + auto object = engine()->NewObject(); ASSERT_FALSE(object.IsEmpty()); EXPECT_EQ(0u, engine()->GetObjectPropertyNames(object).size()); EXPECT_FALSE(engine()->GetObjectProperty(object, L"clams").IsEmpty()); |