summaryrefslogtreecommitdiff
path: root/fpdfsdk/src/javascript
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2015-10-09 13:14:47 -0700
committerTom Sepez <tsepez@chromium.org>2015-10-09 13:14:47 -0700
commit848a13b6777cbff8cc4aea3ab3d69eaa0b82ae6c (patch)
treed2c3a5ee4f67227ac33199f6d10caaf204c92896 /fpdfsdk/src/javascript
parentf1c713663192368d26031a4caed1f9705f4510af (diff)
downloadpdfium-848a13b6777cbff8cc4aea3ab3d69eaa0b82ae6c.tar.xz
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 .
Diffstat (limited to 'fpdfsdk/src/javascript')
-rw-r--r--fpdfsdk/src/javascript/Document.cpp28
-rw-r--r--fpdfsdk/src/javascript/Document.h2
-rw-r--r--fpdfsdk/src/javascript/Field.cpp18
-rw-r--r--fpdfsdk/src/javascript/Field.h2
-rw-r--r--fpdfsdk/src/javascript/JS_Context.cpp18
-rw-r--r--fpdfsdk/src/javascript/JS_Context.h2
-rw-r--r--fpdfsdk/src/javascript/JS_Define.h16
-rw-r--r--fpdfsdk/src/javascript/JS_EventHandler.cpp8
-rw-r--r--fpdfsdk/src/javascript/JS_Object.h4
-rw-r--r--fpdfsdk/src/javascript/JS_Runtime.cpp14
-rw-r--r--fpdfsdk/src/javascript/JS_Runtime.h3
-rw-r--r--fpdfsdk/src/javascript/JS_Runtime_Stub.cpp8
-rw-r--r--fpdfsdk/src/javascript/app.cpp11
-rw-r--r--fpdfsdk/src/javascript/global.cpp17
-rw-r--r--fpdfsdk/src/javascript/global.h2
15 files changed, 75 insertions, 78 deletions
diff --git a/fpdfsdk/src/javascript/Document.cpp b/fpdfsdk/src/javascript/Document.cpp
index 7c1f5775d2..24f55b03f9 100644
--- a/fpdfsdk/src/javascript/Document.cpp
+++ b/fpdfsdk/src/javascript/Document.cpp
@@ -140,17 +140,12 @@ END_JS_STATIC_METHOD()
IMPLEMENT_JS_CLASS(CJS_Document, Document)
-FX_BOOL CJS_Document::InitInstance(IJS_Context* cc) {
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
-
- Document* pDoc = (Document*)GetEmbedObject();
- ASSERT(pDoc != NULL);
-
- pDoc->AttachDoc(pContext->GetReaderDocument());
- pDoc->SetIsolate(pContext->GetJSRuntime()->GetIsolate());
- return TRUE;
-};
+void CJS_Document::InitInstance(IJS_Runtime* pIRuntime) {
+ CJS_Runtime* pRuntime = static_cast<CJS_Runtime*>(pIRuntime);
+ Document* pDoc = static_cast<Document*>(GetEmbedObject());
+ pDoc->AttachDoc(pRuntime->GetReaderDocument());
+ pDoc->SetIsolate(pRuntime->GetIsolate());
+}
/* --------------------------------- Document ---------------------------------
*/
@@ -326,7 +321,7 @@ FX_BOOL Document::getField(IJS_Context* cc,
CJS_Runtime* pRuntime = pContext->GetJSRuntime();
v8::Local<v8::Object> pFieldObj = FXJS_NewFxDynamicObj(
- pRuntime->GetIsolate(), pContext, CJS_Field::g_nObjDefnID);
+ pRuntime->GetIsolate(), pRuntime, CJS_Field::g_nObjDefnID);
v8::Isolate* isolate = GetIsolate(cc);
CJS_Field* pJSField = (CJS_Field*)FXJS_GetPrivate(isolate, pFieldObj);
@@ -835,7 +830,7 @@ FX_BOOL Document::info(IJS_Context* cc,
CJS_Context* pContext = (CJS_Context*)cc;
CJS_Runtime* pRuntime = pContext->GetJSRuntime();
v8::Local<v8::Object> pObj =
- FXJS_NewFxDynamicObj(pRuntime->GetIsolate(), pContext, -1);
+ FXJS_NewFxDynamicObj(pRuntime->GetIsolate(), pRuntime, -1);
FXJS_PutObjectString(isolate, pObj, L"Author", cwAuthor.c_str());
FXJS_PutObjectString(isolate, pObj, L"Title", cwTitle.c_str());
FXJS_PutObjectString(isolate, pObj, L"Subject", cwSubject.c_str());
@@ -1394,7 +1389,6 @@ FX_BOOL Document::icons(IJS_Context* cc,
return TRUE;
}
- CJS_Context* pContext = static_cast<CJS_Context*>(cc);
CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
CJS_Array Icons(pRuntime);
IconElement* pIconElement = NULL;
@@ -1403,7 +1397,7 @@ FX_BOOL Document::icons(IJS_Context* cc,
pIconElement = (*m_pIconTree)[i];
v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj(
- pRuntime->GetIsolate(), pContext, CJS_Icon::g_nObjDefnID);
+ pRuntime->GetIsolate(), pRuntime, CJS_Icon::g_nObjDefnID);
if (pObj.IsEmpty())
return FALSE;
@@ -1446,7 +1440,7 @@ FX_BOOL Document::getIcon(IJS_Context* cc,
Icon* pRetIcon = (*m_pIconTree)[i]->IconStream;
v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj(
- pRuntime->GetIsolate(), pContext, CJS_Icon::g_nObjDefnID);
+ pRuntime->GetIsolate(), pRuntime, CJS_Icon::g_nObjDefnID);
if (pObj.IsEmpty())
return FALSE;
@@ -1642,7 +1636,7 @@ FX_BOOL Document::getPrintParams(IJS_Context* cc,
CJS_Context* pContext = (CJS_Context*)cc;
CJS_Runtime* pRuntime = pContext->GetJSRuntime();
v8::Local<v8::Object> pRetObj = FXJS_NewFxDynamicObj(
- pRuntime->GetIsolate(), pContext, CJS_PrintParamsObj::g_nObjDefnID);
+ pRuntime->GetIsolate(), pRuntime, CJS_PrintParamsObj::g_nObjDefnID);
// Not implemented yet.
diff --git a/fpdfsdk/src/javascript/Document.h b/fpdfsdk/src/javascript/Document.h
index 8f68769eb9..4e6fdee218 100644
--- a/fpdfsdk/src/javascript/Document.h
+++ b/fpdfsdk/src/javascript/Document.h
@@ -309,7 +309,7 @@ class CJS_Document : public CJS_Object {
~CJS_Document() override {}
// CJS_Object
- FX_BOOL InitInstance(IJS_Context* cc) override;
+ void InitInstance(IJS_Runtime* pIRuntime) override;
DECLARE_JS_CLASS();
diff --git a/fpdfsdk/src/javascript/Field.cpp b/fpdfsdk/src/javascript/Field.cpp
index 56fc56b206..021a3a6a7b 100644
--- a/fpdfsdk/src/javascript/Field.cpp
+++ b/fpdfsdk/src/javascript/Field.cpp
@@ -110,16 +110,10 @@ END_JS_STATIC_METHOD()
IMPLEMENT_JS_CLASS(CJS_Field, Field)
-FX_BOOL CJS_Field::InitInstance(IJS_Context* cc) {
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
-
- Field* pField = (Field*)GetEmbedObject();
- ASSERT(pField != NULL);
-
- pField->SetIsolate(pContext->GetJSRuntime()->GetIsolate());
-
- return TRUE;
+void CJS_Field::InitInstance(IJS_Runtime* pIRuntime) {
+ CJS_Runtime* pRuntime = static_cast<CJS_Runtime*>(pIRuntime);
+ Field* pField = static_cast<Field*>(GetEmbedObject());
+ pField->SetIsolate(pRuntime->GetIsolate());
};
Field::Field(CJS_Object* pJSObject)
@@ -3279,7 +3273,7 @@ FX_BOOL Field::buttonGetIcon(IJS_Context* cc,
CJS_Context* pContext = (CJS_Context*)cc;
CJS_Runtime* pRuntime = pContext->GetJSRuntime();
v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj(
- pRuntime->GetIsolate(), pContext, CJS_Icon::g_nObjDefnID);
+ pRuntime->GetIsolate(), pRuntime, CJS_Icon::g_nObjDefnID);
ASSERT(pObj.IsEmpty() == FALSE);
CJS_Icon* pJS_Icon = (CJS_Icon*)FXJS_GetPrivate(pRuntime->GetIsolate(), pObj);
@@ -3488,7 +3482,7 @@ FX_BOOL Field::getArray(IJS_Context* cc,
for (int j = 0, jsz = swSort.GetSize(); j < jsz; j++) {
nonstd::unique_ptr<CFX_WideString> pStr(swSort.GetAt(j));
v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj(
- pRuntime->GetIsolate(), pContext, CJS_Field::g_nObjDefnID);
+ pRuntime->GetIsolate(), pRuntime, CJS_Field::g_nObjDefnID);
ASSERT(!pObj.IsEmpty());
CJS_Field* pJSField =
diff --git a/fpdfsdk/src/javascript/Field.h b/fpdfsdk/src/javascript/Field.h
index b263241712..21ae04c960 100644
--- a/fpdfsdk/src/javascript/Field.h
+++ b/fpdfsdk/src/javascript/Field.h
@@ -501,7 +501,7 @@ class CJS_Field : public CJS_Object {
CJS_Field(v8::Local<v8::Object> pObject) : CJS_Object(pObject) {}
~CJS_Field(void) override {}
- FX_BOOL InitInstance(IJS_Context* cc) override;
+ void InitInstance(IJS_Runtime* pIRuntime) override;
DECLARE_JS_CLASS();
JS_STATIC_PROP(alignment, Field);
diff --git a/fpdfsdk/src/javascript/JS_Context.cpp b/fpdfsdk/src/javascript/JS_Context.cpp
index b67096d9bc..cfca043333 100644
--- a/fpdfsdk/src/javascript/JS_Context.cpp
+++ b/fpdfsdk/src/javascript/JS_Context.cpp
@@ -33,14 +33,14 @@ CPDFDoc_Environment* CJS_Context::GetReaderApp() {
}
FX_BOOL CJS_Context::RunScript(const CFX_WideString& script,
- CFX_WideString& info) {
+ CFX_WideString* info) {
v8::Isolate::Scope isolate_scope(m_pRuntime->GetIsolate());
v8::HandleScope handle_scope(m_pRuntime->GetIsolate());
v8::Local<v8::Context> context = m_pRuntime->NewJSContext();
v8::Context::Scope context_scope(context);
if (m_bBusy) {
- info = JSGetStringFromID(this, IDS_STRING_JSBUSY);
+ *info = JSGetStringFromID(this, IDS_STRING_JSBUSY);
return FALSE;
}
m_bBusy = TRUE;
@@ -49,24 +49,20 @@ FX_BOOL CJS_Context::RunScript(const CFX_WideString& script,
CJS_Runtime::FieldEvent event(m_pEventHandler->TargetName(),
m_pEventHandler->EventType());
if (!m_pRuntime->AddEventToSet(event)) {
- info = JSGetStringFromID(this, IDS_STRING_JSEVENT);
+ *info = JSGetStringFromID(this, IDS_STRING_JSEVENT);
return FALSE;
}
- FXJSErr error = {NULL, NULL, 0};
+ CFX_WideString sErrorMessage;
int nRet = 0;
if (script.GetLength() > 0) {
- nRet = FXJS_Execute(m_pRuntime->GetIsolate(), this, script.c_str(),
- script.GetLength(), &error);
+ nRet = m_pRuntime->Execute(this, script.c_str(), &sErrorMessage);
}
if (nRet < 0) {
- CFX_WideString sLine;
- sLine.Format(L"[ Line: %05d { %s } ] : %s", error.linnum - 1, error.srcline,
- error.message);
- info += sLine;
+ *info += sErrorMessage;
} else {
- info = JSGetStringFromID(this, IDS_STRING_RUN);
+ *info = JSGetStringFromID(this, IDS_STRING_RUN);
}
m_pRuntime->RemoveEventFromSet(event);
diff --git a/fpdfsdk/src/javascript/JS_Context.h b/fpdfsdk/src/javascript/JS_Context.h
index 7fbcbec876..dc5d8339bf 100644
--- a/fpdfsdk/src/javascript/JS_Context.h
+++ b/fpdfsdk/src/javascript/JS_Context.h
@@ -21,7 +21,7 @@ class CJS_Context : public IJS_Context {
// IJS_Context
FX_BOOL RunScript(const CFX_WideString& script,
- CFX_WideString& info) override;
+ CFX_WideString* info) override;
void OnApp_Init() override;
void OnDoc_Open(CPDFSDK_Document* pDoc,
const CFX_WideString& strTargetName) override;
diff --git a/fpdfsdk/src/javascript/JS_Define.h b/fpdfsdk/src/javascript/JS_Define.h
index cb39841c53..3e5b797d07 100644
--- a/fpdfsdk/src/javascript/JS_Define.h
+++ b/fpdfsdk/src/javascript/JS_Define.h
@@ -247,22 +247,22 @@ void JSMethod(const char* method_name_string,
DefineMethods(pIsolate); \
}
-#define DECLARE_JS_CLASS_RICH_PART() \
- static void JSConstructor(IJS_Context* cc, v8::Local<v8::Object> obj); \
- static void JSDestructor(v8::Local<v8::Object> obj); \
- static void DefineProps(v8::Isolate* pIsoalte); \
- static void DefineMethods(v8::Isolate* pIsoalte); \
- static JSPropertySpec JS_Class_Properties[]; \
+#define DECLARE_JS_CLASS_RICH_PART() \
+ static void JSConstructor(IJS_Runtime* pRuntime, v8::Local<v8::Object> obj); \
+ static void JSDestructor(v8::Local<v8::Object> obj); \
+ static void DefineProps(v8::Isolate* pIsoalte); \
+ static void DefineMethods(v8::Isolate* pIsoalte); \
+ static JSPropertySpec JS_Class_Properties[]; \
static JSMethodSpec JS_Class_Methods[];
#define IMPLEMENT_JS_CLASS_RICH_PART(js_class_name, class_alternate, \
class_name) \
- void js_class_name::JSConstructor(IJS_Context* cc, \
+ void js_class_name::JSConstructor(IJS_Runtime* pIRuntime, \
v8::Local<v8::Object> obj) { \
CJS_Object* pObj = new js_class_name(obj); \
pObj->SetEmbedObject(new class_alternate(pObj)); \
FXJS_SetPrivate(nullptr, obj, (void*)pObj); \
- pObj->InitInstance(cc); \
+ pObj->InitInstance(pIRuntime); \
} \
void js_class_name::JSDestructor(v8::Local<v8::Object> obj) { \
js_class_name* pObj = (js_class_name*)FXJS_GetPrivate(nullptr, obj); \
diff --git a/fpdfsdk/src/javascript/JS_EventHandler.cpp b/fpdfsdk/src/javascript/JS_EventHandler.cpp
index dd5c4427ce..cb86fde24d 100644
--- a/fpdfsdk/src/javascript/JS_EventHandler.cpp
+++ b/fpdfsdk/src/javascript/JS_EventHandler.cpp
@@ -613,11 +613,11 @@ FX_BOOL CJS_EventHandler::Shift() {
Field* CJS_EventHandler::Source() {
CJS_Runtime* pRuntime = m_pJSContext->GetJSRuntime();
v8::Local<v8::Object> pDocObj = FXJS_NewFxDynamicObj(
- pRuntime->GetIsolate(), m_pJSContext, CJS_Document::g_nObjDefnID);
+ pRuntime->GetIsolate(), pRuntime, CJS_Document::g_nObjDefnID);
ASSERT(!pDocObj.IsEmpty());
v8::Local<v8::Object> pFieldObj = FXJS_NewFxDynamicObj(
- pRuntime->GetIsolate(), m_pJSContext, CJS_Field::g_nObjDefnID);
+ pRuntime->GetIsolate(), pRuntime, CJS_Field::g_nObjDefnID);
ASSERT(!pFieldObj.IsEmpty());
CJS_Document* pJSDocument =
@@ -636,11 +636,11 @@ Field* CJS_EventHandler::Source() {
Field* CJS_EventHandler::Target_Field() {
CJS_Runtime* pRuntime = m_pJSContext->GetJSRuntime();
v8::Local<v8::Object> pDocObj = FXJS_NewFxDynamicObj(
- pRuntime->GetIsolate(), m_pJSContext, CJS_Document::g_nObjDefnID);
+ pRuntime->GetIsolate(), pRuntime, CJS_Document::g_nObjDefnID);
ASSERT(!pDocObj.IsEmpty());
v8::Local<v8::Object> pFieldObj = FXJS_NewFxDynamicObj(
- pRuntime->GetIsolate(), m_pJSContext, CJS_Field::g_nObjDefnID);
+ pRuntime->GetIsolate(), pRuntime, CJS_Field::g_nObjDefnID);
ASSERT(!pFieldObj.IsEmpty());
CJS_Document* pJSDocument =
diff --git a/fpdfsdk/src/javascript/JS_Object.h b/fpdfsdk/src/javascript/JS_Object.h
index 563a316bd6..50751523f5 100644
--- a/fpdfsdk/src/javascript/JS_Object.h
+++ b/fpdfsdk/src/javascript/JS_Object.h
@@ -49,8 +49,8 @@ class CJS_Object {
virtual FX_BOOL IsType(const FX_CHAR* sClassName) { return TRUE; }
virtual CFX_ByteString GetClassName() { return ""; }
- virtual FX_BOOL InitInstance(IJS_Context* cc) { return TRUE; }
- virtual FX_BOOL ExitInstance() { return TRUE; }
+ virtual void InitInstance(IJS_Runtime* pIRuntime) {}
+ virtual void ExitInstance() {}
v8::Local<v8::Object> ToV8Object() { return m_pV8Object.Get(m_pIsolate); }
diff --git a/fpdfsdk/src/javascript/JS_Runtime.cpp b/fpdfsdk/src/javascript/JS_Runtime.cpp
index 069edc5cd6..4331476bed 100644
--- a/fpdfsdk/src/javascript/JS_Runtime.cpp
+++ b/fpdfsdk/src/javascript/JS_Runtime.cpp
@@ -64,7 +64,7 @@ CJS_Runtime::CJS_Runtime(CPDFDoc_Environment* pApp)
DefineJSObjects();
CJS_Context* pContext = (CJS_Context*)NewContext();
- FXJS_InitializeRuntime(GetIsolate(), this, pContext, m_context);
+ FXJS_InitializeRuntime(GetIsolate(), this, m_context);
ReleaseContext(pContext);
}
@@ -181,6 +181,18 @@ void CJS_Runtime::SetReaderDocument(CPDFSDK_Document* pReaderDoc) {
}
}
+int CJS_Runtime::Execute(IJS_Context* cc,
+ const wchar_t* script,
+ CFX_WideString* info) {
+ FXJSErr error = {};
+ int nRet = FXJS_Execute(m_isolate, cc, script, &error);
+ if (nRet < 0) {
+ info->Format(L"[ Line: %05d { %s } ] : %s", error.linnum - 1, error.srcline,
+ error.message);
+ }
+ return nRet;
+}
+
bool CJS_Runtime::AddEventToSet(const FieldEvent& event) {
return m_FieldEventSet.insert(event).second;
}
diff --git a/fpdfsdk/src/javascript/JS_Runtime.h b/fpdfsdk/src/javascript/JS_Runtime.h
index 8cbec38fc6..d90891eff0 100644
--- a/fpdfsdk/src/javascript/JS_Runtime.h
+++ b/fpdfsdk/src/javascript/JS_Runtime.h
@@ -40,6 +40,9 @@ class CJS_Runtime : public IJS_Runtime {
IJS_Context* GetCurrentContext() override;
void SetReaderDocument(CPDFSDK_Document* pReaderDoc) override;
CPDFSDK_Document* GetReaderDocument() override { return m_pDocument; }
+ int Execute(IJS_Context* cc,
+ const wchar_t* script,
+ CFX_WideString* info) override;
CPDFDoc_Environment* GetReaderApp() const { return m_pApp; }
diff --git a/fpdfsdk/src/javascript/JS_Runtime_Stub.cpp b/fpdfsdk/src/javascript/JS_Runtime_Stub.cpp
index 2c5e625fdc..a7b081faf7 100644
--- a/fpdfsdk/src/javascript/JS_Runtime_Stub.cpp
+++ b/fpdfsdk/src/javascript/JS_Runtime_Stub.cpp
@@ -15,7 +15,7 @@ class CJS_ContextStub final : public IJS_Context {
// IJS_Context:
FX_BOOL RunScript(const CFX_WideString& script,
- CFX_WideString& info) override {
+ CFX_WideString* info) override {
return FALSE;
}
@@ -136,6 +136,12 @@ class CJS_RuntimeStub final : public IJS_Runtime {
}
CPDFSDK_Document* GetReaderDocument() override { return m_pDoc; }
+ int Execute(IJS_Context* cc,
+ const wchar_t* script,
+ CFX_WideString* info) override {
+ return 0;
+ }
+
protected:
CPDFSDK_Document* m_pDoc;
nonstd::unique_ptr<CJS_ContextStub> m_pContext;
diff --git a/fpdfsdk/src/javascript/app.cpp b/fpdfsdk/src/javascript/app.cpp
index 93a627c97a..3db1e5b956 100644
--- a/fpdfsdk/src/javascript/app.cpp
+++ b/fpdfsdk/src/javascript/app.cpp
@@ -123,7 +123,7 @@ FX_BOOL app::activeDocs(IJS_Context* cc,
(CJS_Document*)FXJS_GetPrivate(pRuntime->GetIsolate(), pObj);
} else {
v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj(
- pRuntime->GetIsolate(), pContext, CJS_Document::g_nObjDefnID);
+ pRuntime->GetIsolate(), pRuntime, CJS_Document::g_nObjDefnID);
pJSDocument =
(CJS_Document*)FXJS_GetPrivate(pRuntime->GetIsolate(), pObj);
ASSERT(pJSDocument != NULL);
@@ -402,7 +402,7 @@ FX_BOOL app::setInterval(IJS_Context* cc,
m_aTimer.Add(pTimer);
v8::Local<v8::Object> pRetObj = FXJS_NewFxDynamicObj(
- pRuntime->GetIsolate(), pContext, CJS_TimerObj::g_nObjDefnID);
+ pRuntime->GetIsolate(), pRuntime, CJS_TimerObj::g_nObjDefnID);
CJS_TimerObj* pJS_TimerObj =
(CJS_TimerObj*)FXJS_GetPrivate(pRuntime->GetIsolate(), pRetObj);
TimerObj* pTimerObj = (TimerObj*)pJS_TimerObj->GetEmbedObject();
@@ -443,7 +443,7 @@ FX_BOOL app::setTimeOut(IJS_Context* cc,
m_aTimer.Add(pTimer);
v8::Local<v8::Object> pRetObj = FXJS_NewFxDynamicObj(
- pRuntime->GetIsolate(), pContext, CJS_TimerObj::g_nObjDefnID);
+ pRuntime->GetIsolate(), pRuntime, CJS_TimerObj::g_nObjDefnID);
CJS_TimerObj* pJS_TimerObj =
(CJS_TimerObj*)FXJS_GetPrivate(pRuntime->GetIsolate(), pRetObj);
TimerObj* pTimerObj = (TimerObj*)pJS_TimerObj->GetEmbedObject();
@@ -553,14 +553,11 @@ void app::TimerProc(CJS_Timer* pTimer) {
}
void app::RunJsScript(CJS_Runtime* pRuntime, const CFX_WideString& wsScript) {
- ASSERT(pRuntime != NULL);
-
if (!pRuntime->IsBlocking()) {
IJS_Context* pContext = pRuntime->NewContext();
- ASSERT(pContext != NULL);
pContext->OnExternal_Exec();
CFX_WideString wtInfo;
- pContext->RunScript(wsScript, wtInfo);
+ pContext->RunScript(wsScript, &wtInfo);
pRuntime->ReleaseContext(pContext);
}
}
diff --git a/fpdfsdk/src/javascript/global.cpp b/fpdfsdk/src/javascript/global.cpp
index c8510d27dc..cd0048d95b 100644
--- a/fpdfsdk/src/javascript/global.cpp
+++ b/fpdfsdk/src/javascript/global.cpp
@@ -87,17 +87,12 @@ END_JS_STATIC_METHOD()
IMPLEMENT_SPECIAL_JS_CLASS(CJS_Global, JSGlobalAlternate, global);
-FX_BOOL CJS_Global::InitInstance(IJS_Context* cc) {
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
-
- JSGlobalAlternate* pGlobal = (JSGlobalAlternate*)GetEmbedObject();
- ASSERT(pGlobal != NULL);
-
- pGlobal->Initial(pContext->GetReaderApp());
-
- return TRUE;
-};
+void CJS_Global::InitInstance(IJS_Runtime* pIRuntime) {
+ CJS_Runtime* pRuntime = static_cast<CJS_Runtime*>(pIRuntime);
+ JSGlobalAlternate* pGlobal =
+ static_cast<JSGlobalAlternate*>(GetEmbedObject());
+ pGlobal->Initial(pRuntime->GetReaderApp());
+}
JSGlobalAlternate::JSGlobalAlternate(CJS_Object* pJSObject)
: CJS_EmbedObj(pJSObject), m_pApp(NULL) {
diff --git a/fpdfsdk/src/javascript/global.h b/fpdfsdk/src/javascript/global.h
index 30f5d07b31..174e63a760 100644
--- a/fpdfsdk/src/javascript/global.h
+++ b/fpdfsdk/src/javascript/global.h
@@ -82,7 +82,7 @@ class CJS_Global : public CJS_Object {
~CJS_Global() override {}
// CJS_Object
- FX_BOOL InitInstance(IJS_Context* cc) override;
+ void InitInstance(IJS_Runtime* pIRuntime) override;
DECLARE_SPECIAL_JS_CLASS();
JS_SPECIAL_STATIC_METHOD(setPersistent, JSGlobalAlternate, global);