summaryrefslogtreecommitdiff
path: root/fpdfsdk/src/jsapi/fxjs_v8.cpp
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2015-10-06 11:45:28 -0700
committerTom Sepez <tsepez@chromium.org>2015-10-06 11:45:28 -0700
commitcd56a7d6fb05bd0babf316a84280a26ecc649d45 (patch)
tree65a4ff0aa976f364e46d1ec69ebbe34ddbc99e90 /fpdfsdk/src/jsapi/fxjs_v8.cpp
parent3745841a4c4ab915c98865c1dd71f9debc3e2f99 (diff)
downloadpdfium-cd56a7d6fb05bd0babf316a84280a26ecc649d45.tar.xz
Merge to XFA: Store object definition ID in each js_class.
Manual edits in JS_Define.h. (cherry picked from commit f0a5b2803c09f3605dcd606e764ef604f0d2a8ea) Original Review URL: https://codereview.chromium.org/1382263002 . R=thestig@chromium.org Review URL: https://codereview.chromium.org/1382683008 .
Diffstat (limited to 'fpdfsdk/src/jsapi/fxjs_v8.cpp')
-rw-r--r--fpdfsdk/src/jsapi/fxjs_v8.cpp76
1 files changed, 25 insertions, 51 deletions
diff --git a/fpdfsdk/src/jsapi/fxjs_v8.cpp b/fpdfsdk/src/jsapi/fxjs_v8.cpp
index b4b9929265..765ec2700d 100644
--- a/fpdfsdk/src/jsapi/fxjs_v8.cpp
+++ b/fpdfsdk/src/jsapi/fxjs_v8.cpp
@@ -50,11 +50,10 @@ class CFXJS_ObjDefinition {
FXJSOBJTYPE eObjType,
FXJS_CONSTRUCTOR pConstructor,
FXJS_DESTRUCTOR pDestructor)
- : objName(sObjName),
- objType(eObjType),
+ : m_ObjName(sObjName),
+ m_ObjType(eObjType),
m_pConstructor(pConstructor),
m_pDestructor(pDestructor),
- m_bSetAsGlobalObject(FALSE),
m_pIsolate(isolate) {
v8::Isolate::Scope isolate_scope(isolate);
v8::HandleScope handle_scope(isolate);
@@ -65,11 +64,6 @@ class CFXJS_ObjDefinition {
v8::Local<v8::Signature> sig = v8::Signature::New(isolate, fun);
m_Signature.Reset(isolate, sig);
-
- // Document as the global object.
- if (FXSYS_wcscmp(sObjName, L"Document") == 0) {
- m_bSetAsGlobalObject = TRUE;
- }
}
int AssignID() {
@@ -90,11 +84,10 @@ class CFXJS_ObjDefinition {
return scope.Escape(m_Signature.Get(m_pIsolate));
}
- const wchar_t* objName;
- const FXJSOBJTYPE objType;
+ const wchar_t* const m_ObjName;
+ const FXJSOBJTYPE m_ObjType;
const FXJS_CONSTRUCTOR m_pConstructor;
const FXJS_DESTRUCTOR m_pDestructor;
- FX_BOOL m_bSetAsGlobalObject;
v8::Isolate* m_pIsolate;
v8::Global<v8::FunctionTemplate> m_FunctionTemplate;
@@ -107,10 +100,9 @@ static v8::Local<v8::ObjectTemplate> GetGlobalObjectTemplate(
int maxID = CFXJS_ObjDefinition::MaxID(pIsolate);
for (int i = 0; i < maxID; ++i) {
CFXJS_ObjDefinition* pObjDef = CFXJS_ObjDefinition::ForID(pIsolate, i);
- if (pObjDef->m_bSetAsGlobalObject)
+ if (pObjDef->m_ObjType == FXJSOBJTYPE_GLOBAL)
return pObjDef->GetInstanceTemplate();
}
-
if (!g_DefaultGlobalObjectTemplate) {
g_DefaultGlobalObjectTemplate = new v8::Global<v8::ObjectTemplate>;
g_DefaultGlobalObjectTemplate->Reset(pIsolate,
@@ -264,35 +256,31 @@ void FXJS_InitializeRuntime(v8::Isolate* pIsolate,
int maxID = CFXJS_ObjDefinition::MaxID(pIsolate);
for (int i = 0; i < maxID; ++i) {
CFXJS_ObjDefinition* pObjDef = CFXJS_ObjDefinition::ForID(pIsolate, i);
- CFX_WideString ws = CFX_WideString(pObjDef->objName);
- CFX_ByteString bs = ws.UTF8Encode();
- v8::Local<v8::String> objName =
+ CFX_ByteString bs = CFX_WideString(pObjDef->m_ObjName).UTF8Encode();
+ v8::Local<v8::String> m_ObjName =
v8::String::NewFromUtf8(pIsolate, bs.c_str(),
v8::NewStringType::kNormal,
bs.GetLength()).ToLocalChecked();
- if (pObjDef->objType == FXJS_DYNAMIC) {
- // Document is set as global object, need to construct it first.
- if (ws.Equal(L"Document")) {
- v8Context->Global()
- ->GetPrototype()
- ->ToObject(v8Context)
- .ToLocalChecked()
- ->SetAlignedPointerInInternalField(0, new CFXJS_PrivateData(i));
-
- if (pObjDef->m_pConstructor)
- pObjDef->m_pConstructor(context, v8Context->Global()
- ->GetPrototype()
- ->ToObject(v8Context)
- .ToLocalChecked(),
- v8Context->Global()
- ->GetPrototype()
- ->ToObject(v8Context)
- .ToLocalChecked());
- }
- } else {
+ if (pObjDef->m_ObjType == FXJSOBJTYPE_GLOBAL) {
+ v8Context->Global()
+ ->GetPrototype()
+ ->ToObject(v8Context)
+ .ToLocalChecked()
+ ->SetAlignedPointerInInternalField(0, new CFXJS_PrivateData(i));
+
+ if (pObjDef->m_pConstructor)
+ pObjDef->m_pConstructor(context, v8Context->Global()
+ ->GetPrototype()
+ ->ToObject(v8Context)
+ .ToLocalChecked(),
+ v8Context->Global()
+ ->GetPrototype()
+ ->ToObject(v8Context)
+ .ToLocalChecked());
+ } else if (pObjDef->m_ObjType == FXJSOBJTYPE_STATIC) {
v8::Local<v8::Object> obj = FXJS_NewFxDynamicObj(pIsolate, context, i);
- v8Context->Global()->Set(v8Context, objName, obj).FromJust();
+ v8Context->Global()->Set(v8Context, m_ObjName, obj).FromJust();
pObjDef->m_StaticObj.Reset(pIsolate, obj);
}
}
@@ -431,20 +419,6 @@ v8::Isolate* FXJS_GetRuntime(v8::Local<v8::Object> pObj) {
return context->GetIsolate();
}
-int FXJS_GetObjDefnID(v8::Isolate* pIsolate, const wchar_t* pObjName) {
- v8::Isolate::Scope isolate_scope(pIsolate);
- if (!FXJS_PerIsolateData::Get(pIsolate))
- return -1;
-
- int maxID = CFXJS_ObjDefinition::MaxID(pIsolate);
- for (int i = 0; i < maxID; ++i) {
- CFXJS_ObjDefinition* pObjDef = CFXJS_ObjDefinition::ForID(pIsolate, i);
- if (FXSYS_wcscmp(pObjDef->objName, pObjName) == 0)
- return i;
- }
- return -1;
-}
-
void FXJS_Error(v8::Isolate* pIsolate, const CFX_WideString& message) {
// Conversion from pdfium's wchar_t wide-strings to v8's uint16_t
// wide-strings isn't handled by v8, so use UTF8 as a common