diff options
Diffstat (limited to 'fpdfsdk')
28 files changed, 473 insertions, 516 deletions
diff --git a/fpdfsdk/include/javascript/Consts.h b/fpdfsdk/include/javascript/Consts.h index 79f85f8002..165001784b 100644 --- a/fpdfsdk/include/javascript/Consts.h +++ b/fpdfsdk/include/javascript/Consts.h @@ -13,7 +13,7 @@ class CJS_Border : public CJS_Object { public: - explicit CJS_Border(JSFXObject pObject) : CJS_Object(pObject) {} + explicit CJS_Border(v8::Local<v8::Object> pObject) : CJS_Object(pObject) {} ~CJS_Border() override {} DECLARE_JS_CLASS_CONST(); @@ -23,7 +23,7 @@ class CJS_Border : public CJS_Object { class CJS_Display : public CJS_Object { public: - explicit CJS_Display(JSFXObject pObject) : CJS_Object(pObject) {} + explicit CJS_Display(v8::Local<v8::Object> pObject) : CJS_Object(pObject) {} ~CJS_Display() override {} DECLARE_JS_CLASS_CONST(); @@ -33,7 +33,7 @@ class CJS_Display : public CJS_Object { class CJS_Font : public CJS_Object { public: - explicit CJS_Font(JSFXObject pObject) : CJS_Object(pObject) {} + explicit CJS_Font(v8::Local<v8::Object> pObject) : CJS_Object(pObject) {} ~CJS_Font() override {} DECLARE_JS_CLASS_CONST(); @@ -43,7 +43,7 @@ class CJS_Font : public CJS_Object { class CJS_Highlight : public CJS_Object { public: - explicit CJS_Highlight(JSFXObject pObject) : CJS_Object(pObject) {} + explicit CJS_Highlight(v8::Local<v8::Object> pObject) : CJS_Object(pObject) {} ~CJS_Highlight() override {} DECLARE_JS_CLASS_CONST(); @@ -53,7 +53,7 @@ class CJS_Highlight : public CJS_Object { class CJS_Position : public CJS_Object { public: - explicit CJS_Position(JSFXObject pObject) : CJS_Object(pObject) {} + explicit CJS_Position(v8::Local<v8::Object> pObject) : CJS_Object(pObject) {} ~CJS_Position() override {} DECLARE_JS_CLASS_CONST(); @@ -63,7 +63,7 @@ class CJS_Position : public CJS_Object { class CJS_ScaleHow : public CJS_Object { public: - explicit CJS_ScaleHow(JSFXObject pObject) : CJS_Object(pObject) {} + explicit CJS_ScaleHow(v8::Local<v8::Object> pObject) : CJS_Object(pObject) {} ~CJS_ScaleHow() override {} DECLARE_JS_CLASS_CONST(); @@ -73,7 +73,7 @@ class CJS_ScaleHow : public CJS_Object { class CJS_ScaleWhen : public CJS_Object { public: - explicit CJS_ScaleWhen(JSFXObject pObject) : CJS_Object(pObject) {} + explicit CJS_ScaleWhen(v8::Local<v8::Object> pObject) : CJS_Object(pObject) {} ~CJS_ScaleWhen() override {} DECLARE_JS_CLASS_CONST(); @@ -83,7 +83,7 @@ class CJS_ScaleWhen : public CJS_Object { class CJS_Style : public CJS_Object { public: - explicit CJS_Style(JSFXObject pObject) : CJS_Object(pObject) {} + explicit CJS_Style(v8::Local<v8::Object> pObject) : CJS_Object(pObject) {} ~CJS_Style() override {} DECLARE_JS_CLASS_CONST(); @@ -93,26 +93,24 @@ class CJS_Style : public CJS_Object { class CJS_Zoomtype : public CJS_Object { public: - explicit CJS_Zoomtype(JSFXObject pObject) : CJS_Object(pObject) {} + explicit CJS_Zoomtype(v8::Local<v8::Object> pObject) : CJS_Object(pObject) {} ~CJS_Zoomtype() override {} DECLARE_JS_CLASS_CONST(); }; -/* ------------------------------ CJS_GlobalConsts - * ------------------------------ */ +/* ------------------------------ CJS_GlobalConsts -------------------------- */ class CJS_GlobalConsts : public CJS_Object { public: - static int Init(IJS_Runtime* pRuntime); + static int Init(v8::Isolate* pIsolate); }; -/* ------------------------------ CJS_GlobalArrays - * ------------------------------ */ +/* ------------------------------ CJS_GlobalArrays -------------------------- */ class CJS_GlobalArrays : public CJS_Object { public: - static int Init(IJS_Runtime* pRuntime); + static int Init(v8::Isolate* pIsolate); }; #endif // FPDFSDK_INCLUDE_JAVASCRIPT_CONSTS_H_ diff --git a/fpdfsdk/include/javascript/Document.h b/fpdfsdk/include/javascript/Document.h index e139557f1b..9340000118 100644 --- a/fpdfsdk/include/javascript/Document.h +++ b/fpdfsdk/include/javascript/Document.h @@ -27,7 +27,7 @@ class PrintParamsObj : public CJS_EmbedObj { class CJS_PrintParamsObj : public CJS_Object { public: - CJS_PrintParamsObj(JSFXObject pObject) : CJS_Object(pObject) {} + CJS_PrintParamsObj(v8::Local<v8::Object> pObject) : CJS_Object(pObject) {} ~CJS_PrintParamsObj() override {} DECLARE_JS_CLASS(CJS_PrintParamsObj); @@ -309,7 +309,6 @@ class Document : public CJS_EmbedObj { bool IsEnclosedInRect(CFX_FloatRect rect, CFX_FloatRect LinkRect); int CountWords(CPDF_TextObject* pTextObj); CFX_WideString GetObjWordStr(CPDF_TextObject* pTextObj, int nWordIndex); - FX_BOOL ParserParams(JSObject* pObj, CJS_AnnotObj& annotobj); v8::Isolate* m_isolate; IconTree* m_pIconTree; @@ -322,7 +321,7 @@ class Document : public CJS_EmbedObj { class CJS_Document : public CJS_Object { public: - explicit CJS_Document(JSFXObject pObject) : CJS_Object(pObject) {} + explicit CJS_Document(v8::Local<v8::Object> pObject) : CJS_Object(pObject) {} ~CJS_Document() override {} // CJS_Object diff --git a/fpdfsdk/include/javascript/Field.h b/fpdfsdk/include/javascript/Field.h index ca37ae57bd..4a6f524f72 100644 --- a/fpdfsdk/include/javascript/Field.h +++ b/fpdfsdk/include/javascript/Field.h @@ -533,7 +533,7 @@ class Field : public CJS_EmbedObj { class CJS_Field : public CJS_Object { public: - CJS_Field(JSFXObject pObject) : CJS_Object(pObject) {} + CJS_Field(v8::Local<v8::Object> pObject) : CJS_Object(pObject) {} ~CJS_Field(void) override {} FX_BOOL InitInstance(IFXJS_Context* cc) override; diff --git a/fpdfsdk/include/javascript/Icon.h b/fpdfsdk/include/javascript/Icon.h index 6d2f6e4645..9b6d21b985 100644 --- a/fpdfsdk/include/javascript/Icon.h +++ b/fpdfsdk/include/javascript/Icon.h @@ -27,7 +27,7 @@ class Icon : public CJS_EmbedObj { class CJS_Icon : public CJS_Object { public: - CJS_Icon(JSFXObject pObject) : CJS_Object(pObject) {} + CJS_Icon(v8::Local<v8::Object> pObject) : CJS_Object(pObject) {} ~CJS_Icon() override {} public: diff --git a/fpdfsdk/include/javascript/JS_Define.h b/fpdfsdk/include/javascript/JS_Define.h index db4b1c360d..b850fbe797 100644 --- a/fpdfsdk/include/javascript/JS_Define.h +++ b/fpdfsdk/include/javascript/JS_Define.h @@ -189,41 +189,42 @@ void JSMethod(const char* method_name_string, /* ===================================== JS CLASS * =============================================== */ -#define DECLARE_JS_CLASS(js_class_name) \ - static void JSConstructor(IFXJS_Context* cc, JSFXObject obj, \ - JSFXObject global); \ - static void JSDestructor(JSFXObject obj); \ - static int Init(IJS_Runtime* pRuntime, FXJSOBJTYPE eObjType); \ - static JSConstSpec JS_Class_Consts[]; \ - static JSPropertySpec JS_Class_Properties[]; \ - static JSMethodSpec JS_Class_Methods[]; \ +#define DECLARE_JS_CLASS(js_class_name) \ + static void JSConstructor(IFXJS_Context* cc, v8::Local<v8::Object> obj, \ + v8::Local<v8::Object> global); \ + static void JSDestructor(v8::Local<v8::Object> obj); \ + static int Init(v8::Isolate* pIsolate, FXJSOBJTYPE eObjType); \ + static JSConstSpec JS_Class_Consts[]; \ + static JSPropertySpec JS_Class_Properties[]; \ + static JSMethodSpec JS_Class_Methods[]; \ static const wchar_t* m_pClassName #define IMPLEMENT_JS_CLASS_RICH(js_class_name, class_alternate, class_name) \ const wchar_t* js_class_name::m_pClassName = JS_WIDESTRING(class_name); \ - void js_class_name::JSConstructor(IFXJS_Context* cc, JSFXObject obj, \ - JSFXObject global) { \ + void js_class_name::JSConstructor(IFXJS_Context* cc, \ + v8::Local<v8::Object> obj, \ + v8::Local<v8::Object> global) { \ CJS_Object* pObj = new js_class_name(obj); \ pObj->SetEmbedObject(new class_alternate(pObj)); \ JS_SetPrivate(NULL, obj, (void*)pObj); \ pObj->InitInstance(cc); \ } \ \ - void js_class_name::JSDestructor(JSFXObject obj) { \ + void js_class_name::JSDestructor(v8::Local<v8::Object> obj) { \ js_class_name* pObj = (js_class_name*)JS_GetPrivate(NULL, obj); \ ASSERT(pObj != NULL); \ pObj->ExitInstance(); \ delete pObj; \ } \ \ - int js_class_name::Init(IJS_Runtime* pRuntime, FXJSOBJTYPE eObjType) { \ - int nObjDefnID = JS_DefineObj(pRuntime, js_class_name::m_pClassName, \ + int js_class_name::Init(v8::Isolate* pIsolate, FXJSOBJTYPE eObjType) { \ + int nObjDefnID = JS_DefineObj(pIsolate, js_class_name::m_pClassName, \ eObjType, JSConstructor, JSDestructor); \ if (nObjDefnID >= 0) { \ for (int j = 0, \ szj = sizeof(JS_Class_Properties) / sizeof(JSPropertySpec) - 1; \ j < szj; j++) { \ - if (JS_DefineObjProperty(pRuntime, nObjDefnID, \ + if (JS_DefineObjProperty(pIsolate, nObjDefnID, \ JS_Class_Properties[j].pName, \ JS_Class_Properties[j].pPropGet, \ JS_Class_Properties[j].pPropPut) < 0) \ @@ -232,7 +233,7 @@ void JSMethod(const char* method_name_string, for (int k = 0, \ szk = sizeof(JS_Class_Methods) / sizeof(JSMethodSpec) - 1; \ k < szk; k++) { \ - if (JS_DefineObjMethod(pRuntime, nObjDefnID, \ + if (JS_DefineObjMethod(pIsolate, nObjDefnID, \ JS_Class_Methods[k].pName, \ JS_Class_Methods[k].pMethodCall) < 0) \ return -1; \ @@ -249,27 +250,27 @@ void JSMethod(const char* method_name_string, * ============================================ */ #define DECLARE_JS_CLASS_CONST() \ - static int Init(IJS_Runtime* pRuntime, FXJSOBJTYPE eObjType); \ + static int Init(v8::Isolate* pIsolate, FXJSOBJTYPE eObjType); \ static JSConstSpec JS_Class_Consts[]; \ static const wchar_t* m_pClassName #define IMPLEMENT_JS_CLASS_CONST(js_class_name, class_name) \ const wchar_t* js_class_name::m_pClassName = JS_WIDESTRING(class_name); \ - int js_class_name::Init(IJS_Runtime* pRuntime, FXJSOBJTYPE eObjType) { \ - int nObjDefnID = JS_DefineObj(pRuntime, js_class_name::m_pClassName, \ + int js_class_name::Init(v8::Isolate* pIsolate, FXJSOBJTYPE eObjType) { \ + int nObjDefnID = JS_DefineObj(pIsolate, js_class_name::m_pClassName, \ eObjType, NULL, NULL); \ if (nObjDefnID >= 0) { \ for (int i = 0, sz = sizeof(JS_Class_Consts) / sizeof(JSConstSpec) - 1; \ i < sz; i++) { \ if (JS_Class_Consts[i].t == 0) { \ if (JS_DefineObjConst( \ - pRuntime, nObjDefnID, JS_Class_Consts[i].pName, \ - JS_NewNumber(pRuntime, JS_Class_Consts[i].number)) < 0) \ + pIsolate, nObjDefnID, JS_Class_Consts[i].pName, \ + JS_NewNumber(pIsolate, JS_Class_Consts[i].number)) < 0) \ return -1; \ } else { \ if (JS_DefineObjConst( \ - pRuntime, nObjDefnID, JS_Class_Consts[i].pName, \ - JS_NewString(pRuntime, JS_Class_Consts[i].string)) < 0) \ + pIsolate, nObjDefnID, JS_Class_Consts[i].pName, \ + JS_NewString(pIsolate, JS_Class_Consts[i].string)) < 0) \ return -1; \ } \ } \ @@ -371,26 +372,26 @@ void JSSpecialPropDel(const char* class_name, } } -#define DECLARE_SPECIAL_JS_CLASS(js_class_name) \ - static void JSConstructor(IFXJS_Context* cc, JSFXObject obj, \ - JSFXObject global); \ - static void JSDestructor(JSFXObject obj); \ - static JSConstSpec JS_Class_Consts[]; \ - static JSPropertySpec JS_Class_Properties[]; \ - static JSMethodSpec JS_Class_Methods[]; \ - static int Init(IJS_Runtime* pRuntime, FXJSOBJTYPE eObjType); \ - static const wchar_t* m_pClassName; \ - static void queryprop_##js_class_name##_static( \ - v8::Local<v8::String> property, \ - const v8::PropertyCallbackInfo<v8::Integer>& info); \ - static void getprop_##js_class_name##_static( \ - v8::Local<v8::String> property, \ - const v8::PropertyCallbackInfo<v8::Value>& info); \ - static void putprop_##js_class_name##_static( \ - v8::Local<v8::String> property, v8::Local<v8::Value> value, \ - const v8::PropertyCallbackInfo<v8::Value>& info); \ - static void delprop_##js_class_name##_static( \ - v8::Local<v8::String> property, \ +#define DECLARE_SPECIAL_JS_CLASS(js_class_name) \ + static void JSConstructor(IFXJS_Context* cc, v8::Local<v8::Object> obj, \ + v8::Local<v8::Object> global); \ + static void JSDestructor(v8::Local<v8::Object> obj); \ + static JSConstSpec JS_Class_Consts[]; \ + static JSPropertySpec JS_Class_Properties[]; \ + static JSMethodSpec JS_Class_Methods[]; \ + static int Init(v8::Isolate* pIsolate, FXJSOBJTYPE eObjType); \ + static const wchar_t* m_pClassName; \ + static void queryprop_##js_class_name##_static( \ + v8::Local<v8::String> property, \ + const v8::PropertyCallbackInfo<v8::Integer>& info); \ + static void getprop_##js_class_name##_static( \ + v8::Local<v8::String> property, \ + const v8::PropertyCallbackInfo<v8::Value>& info); \ + static void putprop_##js_class_name##_static( \ + v8::Local<v8::String> property, v8::Local<v8::Value> value, \ + const v8::PropertyCallbackInfo<v8::Value>& info); \ + static void delprop_##js_class_name##_static( \ + v8::Local<v8::String> property, \ const v8::PropertyCallbackInfo<v8::Boolean>& info) #define IMPLEMENT_SPECIAL_JS_CLASS(js_class_name, class_alternate, class_name) \ @@ -415,30 +416,31 @@ void JSSpecialPropDel(const char* class_name, const v8::PropertyCallbackInfo<v8::Boolean>& info) { \ JSSpecialPropDel<class_alternate>(#class_name, property, info); \ } \ - void js_class_name::JSConstructor(IFXJS_Context* cc, JSFXObject obj, \ - JSFXObject global) { \ + void js_class_name::JSConstructor(IFXJS_Context* cc, \ + v8::Local<v8::Object> obj, \ + v8::Local<v8::Object> global) { \ CJS_Object* pObj = new js_class_name(obj); \ pObj->SetEmbedObject(new class_alternate(pObj)); \ JS_SetPrivate(NULL, obj, (void*)pObj); \ pObj->InitInstance(cc); \ } \ \ - void js_class_name::JSDestructor(JSFXObject obj) { \ + void js_class_name::JSDestructor(v8::Local<v8::Object> obj) { \ js_class_name* pObj = (js_class_name*)JS_GetPrivate(NULL, obj); \ ASSERT(pObj != NULL); \ pObj->ExitInstance(); \ delete pObj; \ } \ \ - int js_class_name::Init(IJS_Runtime* pRuntime, FXJSOBJTYPE eObjType) { \ - int nObjDefnID = JS_DefineObj(pRuntime, js_class_name::m_pClassName, \ + int js_class_name::Init(v8::Isolate* pIsolate, FXJSOBJTYPE eObjType) { \ + int nObjDefnID = JS_DefineObj(pIsolate, js_class_name::m_pClassName, \ eObjType, JSConstructor, JSDestructor); \ \ if (nObjDefnID >= 0) { \ for (int j = 0, \ szj = sizeof(JS_Class_Properties) / sizeof(JSPropertySpec) - 1; \ j < szj; j++) { \ - if (JS_DefineObjProperty(pRuntime, nObjDefnID, \ + if (JS_DefineObjProperty(pIsolate, nObjDefnID, \ JS_Class_Properties[j].pName, \ JS_Class_Properties[j].pPropGet, \ JS_Class_Properties[j].pPropPut) < 0) \ @@ -448,13 +450,13 @@ void JSSpecialPropDel(const char* class_name, for (int k = 0, \ szk = sizeof(JS_Class_Methods) / sizeof(JSMethodSpec) - 1; \ k < szk; k++) { \ - if (JS_DefineObjMethod(pRuntime, nObjDefnID, \ + if (JS_DefineObjMethod(pIsolate, nObjDefnID, \ JS_Class_Methods[k].pName, \ JS_Class_Methods[k].pMethodCall) < 0) \ return -1; \ } \ if (JS_DefineObjAllProperties( \ - pRuntime, nObjDefnID, \ + pIsolate, nObjDefnID, \ js_class_name::queryprop_##js_class_name##_static, \ js_class_name::getprop_##js_class_name##_static, \ js_class_name::putprop_##js_class_name##_static, \ @@ -503,7 +505,7 @@ void JSGlobalFunc(const char* func_name_string, #define JS_STATIC_DECLARE_GLOBAL_FUN() \ static JSMethodSpec global_methods[]; \ - static int Init(IJS_Runtime* pRuntime) + static int Init(v8::Isolate* pIsolate) #define BEGIN_JS_STATIC_GLOBAL_FUN(js_class_name) \ JSMethodSpec js_class_name::global_methods[] = { @@ -513,13 +515,13 @@ void JSGlobalFunc(const char* func_name_string, #define END_JS_STATIC_GLOBAL_FUN() END_JS_STATIC_METHOD() #define IMPLEMENT_JS_STATIC_GLOBAL_FUN(js_class_name) \ - int js_class_name::Init(IJS_Runtime* pRuntime) { \ + int js_class_name::Init(v8::Isolate* pIsolate) { \ for (int i = 0, sz = sizeof(js_class_name::global_methods) / \ sizeof(JSMethodSpec) - \ 1; \ i < sz; i++) { \ if (JS_DefineGlobalMethod( \ - pRuntime, js_class_name::global_methods[i].pName, \ + pIsolate, js_class_name::global_methods[i].pName, \ js_class_name::global_methods[i].pMethodCall) < 0) \ return -1; \ } \ @@ -528,25 +530,25 @@ void JSGlobalFunc(const char* func_name_string, /* ======================================== GLOBAL CONSTS * ============================================ */ -#define DEFINE_GLOBAL_CONST(pRuntime, const_name, const_value) \ +#define DEFINE_GLOBAL_CONST(pIsolate, const_name, const_value) \ if (JS_DefineGlobalConst( \ - pRuntime, JS_WIDESTRING(const_name), \ - JS_NewString(pRuntime, JS_WIDESTRING(const_value)))) \ + pIsolate, JS_WIDESTRING(const_name), \ + JS_NewString(pIsolate, JS_WIDESTRING(const_value)))) \ return -1 /* ======================================== GLOBAL ARRAYS * ============================================ */ -#define DEFINE_GLOBAL_ARRAY(pRuntime) \ +#define DEFINE_GLOBAL_ARRAY(pIsolate) \ int size = FX_ArraySize(ArrayContent); \ \ - CJS_Array array(pRuntime); \ + CJS_Array array(pIsolate); \ for (int i = 0; i < size; i++) \ - array.SetElement(i, CJS_Value(pRuntime, ArrayContent[i])); \ + array.SetElement(i, CJS_Value(pIsolate, ArrayContent[i])); \ \ - CJS_PropValue prop(pRuntime); \ + CJS_PropValue prop(pIsolate); \ prop << array; \ - if (JS_DefineGlobalConst(pRuntime, (const wchar_t*)ArrayName, \ + if (JS_DefineGlobalConst(pIsolate, (const wchar_t*)ArrayName, \ prop.ToV8Value()) < 0) \ return -1 diff --git a/fpdfsdk/include/javascript/JS_Object.h b/fpdfsdk/include/javascript/JS_Object.h index 9fd7bff3d4..a7772f1cf9 100644 --- a/fpdfsdk/include/javascript/JS_Object.h +++ b/fpdfsdk/include/javascript/JS_Object.h @@ -48,7 +48,7 @@ class CJS_EmbedObj { class CJS_Object { public: - explicit CJS_Object(JSFXObject pObject); + explicit CJS_Object(v8::Local<v8::Object> pObject); virtual ~CJS_Object(); void MakeWeak(); @@ -60,7 +60,7 @@ class CJS_Object { virtual FX_BOOL InitInstance(IFXJS_Context* cc) { return TRUE; } virtual FX_BOOL ExitInstance() { return TRUE; } - operator JSFXObject() { + operator v8::Local<v8::Object>() { return v8::Local<v8::Object>::New(m_pIsolate, m_pObject); } diff --git a/fpdfsdk/include/javascript/JS_Runtime.h b/fpdfsdk/include/javascript/JS_Runtime.h index 5a811fca1f..314330ca6c 100644 --- a/fpdfsdk/include/javascript/JS_Runtime.h +++ b/fpdfsdk/include/javascript/JS_Runtime.h @@ -40,7 +40,7 @@ class CJS_Runtime : public IFXJS_Runtime { void SetReaderDocument(CPDFSDK_Document* pReaderDoc) override; CPDFSDK_Document* GetReaderDocument() override { return m_pDocument; } - CPDFDoc_Environment* GetReaderApp() { return m_pApp; } + CPDFDoc_Environment* GetReaderApp() const { return m_pApp; } FX_BOOL InitJSObjects(); @@ -52,12 +52,9 @@ class CJS_Runtime : public IFXJS_Runtime { void BeginBlock() { m_bBlocking = TRUE; } void EndBlock() { m_bBlocking = FALSE; } - FX_BOOL IsBlocking() { return m_bBlocking; } - - operator IJS_Runtime*() { return (IJS_Runtime*)m_isolate; } - v8::Isolate* GetIsolate() { return m_isolate; } - void SetIsolate(v8::Isolate* isolate) { m_isolate = isolate; } + FX_BOOL IsBlocking() const { return m_bBlocking; } + v8::Isolate* GetIsolate() const { return m_isolate; } v8::Local<v8::Context> NewJSContext(); protected: @@ -66,7 +63,6 @@ class CJS_Runtime : public IFXJS_Runtime { CPDFSDK_Document* m_pDocument; FX_BOOL m_bBlocking; CJS_FieldEvent* m_pFieldEventPath; - v8::Isolate* m_isolate; bool m_isolateManaged; nonstd::unique_ptr<CJS_ArrayBufferAllocator> m_pArrayBufferAllocator; diff --git a/fpdfsdk/include/javascript/JS_Value.h b/fpdfsdk/include/javascript/JS_Value.h index 1606fb5396..771214d968 100644 --- a/fpdfsdk/include/javascript/JS_Value.h +++ b/fpdfsdk/include/javascript/JS_Value.h @@ -23,7 +23,7 @@ class CJS_Value { CJS_Value(v8::Isolate* isolate, const double& dValue); CJS_Value(v8::Isolate* isolate, const float& fValue); CJS_Value(v8::Isolate* isolate, const bool& bValue); - CJS_Value(v8::Isolate* isolate, JSFXObject); + CJS_Value(v8::Isolate* isolate, v8::Local<v8::Object>); CJS_Value(v8::Isolate* isolate, CJS_Object*); CJS_Value(v8::Isolate* isolate, CJS_Document*); CJS_Value(v8::Isolate* isolate, const FX_CHAR* pStr); @@ -108,8 +108,8 @@ class CJS_PropValue : public CJS_Value { void operator<<(CFX_WideString); void operator>>(CFX_WideString&) const; void operator<<(const FX_WCHAR* c_string); - void operator<<(JSFXObject); - void operator>>(JSFXObject&) const; + void operator<<(v8::Local<v8::Object>); + void operator>>(v8::Local<v8::Object>&) const; void operator>>(CJS_Array& array) const; void operator<<(CJS_Array& array); void operator<<(CJS_Date& date); diff --git a/fpdfsdk/include/javascript/PublicMethods.h b/fpdfsdk/include/javascript/PublicMethods.h index 96c5ea5ad0..02ace4a4c4 100644 --- a/fpdfsdk/include/javascript/PublicMethods.h +++ b/fpdfsdk/include/javascript/PublicMethods.h @@ -11,7 +11,7 @@ class CJS_PublicMethods : public CJS_Object { public: - CJS_PublicMethods(JSFXObject pObject) : CJS_Object(pObject) {} + CJS_PublicMethods(v8::Local<v8::Object> pObject) : CJS_Object(pObject) {} ~CJS_PublicMethods() override {} public: diff --git a/fpdfsdk/include/javascript/app.h b/fpdfsdk/include/javascript/app.h index 995c2605df..1ab02c5eac 100644 --- a/fpdfsdk/include/javascript/app.h +++ b/fpdfsdk/include/javascript/app.h @@ -30,7 +30,7 @@ class TimerObj : public CJS_EmbedObj { class CJS_TimerObj : public CJS_Object { public: - CJS_TimerObj(JSFXObject pObject) : CJS_Object(pObject) {} + CJS_TimerObj(v8::Local<v8::Object> pObject) : CJS_Object(pObject) {} ~CJS_TimerObj() override {} DECLARE_JS_CLASS(CJS_TimerObj); @@ -174,7 +174,7 @@ class app : public CJS_EmbedObj { class CJS_App : public CJS_Object { public: - explicit CJS_App(JSFXObject pObject) : CJS_Object(pObject) {} + explicit CJS_App(v8::Local<v8::Object> pObject) : CJS_Object(pObject) {} ~CJS_App() override {} DECLARE_JS_CLASS(CJS_App); diff --git a/fpdfsdk/include/javascript/color.h b/fpdfsdk/include/javascript/color.h index cabd770ee8..322c4c26fa 100644 --- a/fpdfsdk/include/javascript/color.h +++ b/fpdfsdk/include/javascript/color.h @@ -60,7 +60,7 @@ class color : public CJS_EmbedObj { class CJS_Color : public CJS_Object { public: - CJS_Color(JSFXObject pObject) : CJS_Object(pObject) {} + CJS_Color(v8::Local<v8::Object> pObject) : CJS_Object(pObject) {} ~CJS_Color() override {} DECLARE_JS_CLASS(CJS_Color); diff --git a/fpdfsdk/include/javascript/console.h b/fpdfsdk/include/javascript/console.h index e001695ebf..1571d109f1 100644 --- a/fpdfsdk/include/javascript/console.h +++ b/fpdfsdk/include/javascript/console.h @@ -35,7 +35,7 @@ class console : public CJS_EmbedObj { class CJS_Console : public CJS_Object { public: - CJS_Console(JSFXObject pObject) : CJS_Object(pObject) {} + CJS_Console(v8::Local<v8::Object> pObject) : CJS_Object(pObject) {} ~CJS_Console() override {} DECLARE_JS_CLASS(CJS_Console); diff --git a/fpdfsdk/include/javascript/event.h b/fpdfsdk/include/javascript/event.h index e48a659fc7..a934d54e62 100644 --- a/fpdfsdk/include/javascript/event.h +++ b/fpdfsdk/include/javascript/event.h @@ -59,7 +59,7 @@ class event : public CJS_EmbedObj { class CJS_Event : public CJS_Object { public: - CJS_Event(JSFXObject pObject) : CJS_Object(pObject) {} + CJS_Event(v8::Local<v8::Object> pObject) : CJS_Object(pObject) {} ~CJS_Event() override {} DECLARE_JS_CLASS(CJS_Event); diff --git a/fpdfsdk/include/javascript/global.h b/fpdfsdk/include/javascript/global.h index 7f78bb6bcb..10300a25ab 100644 --- a/fpdfsdk/include/javascript/global.h +++ b/fpdfsdk/include/javascript/global.h @@ -63,7 +63,7 @@ class JSGlobalAlternate : public CJS_EmbedObj { double dData, bool bData, const CFX_ByteString& sData, - JSObject pData, + v8::Local<v8::Object> pData, bool bDefaultPersistent); void ObjectToArray(v8::Local<v8::Object> pObj, @@ -79,7 +79,7 @@ class JSGlobalAlternate : public CJS_EmbedObj { class CJS_Global : public CJS_Object { public: - explicit CJS_Global(JSFXObject pObject) : CJS_Object(pObject) {} + explicit CJS_Global(v8::Local<v8::Object> pObject) : CJS_Object(pObject) {} ~CJS_Global() override {} // CJS_Object diff --git a/fpdfsdk/include/javascript/report.h b/fpdfsdk/include/javascript/report.h index 52be2f36e2..5b17dabc50 100644 --- a/fpdfsdk/include/javascript/report.h +++ b/fpdfsdk/include/javascript/report.h @@ -27,7 +27,7 @@ class Report : public CJS_EmbedObj { class CJS_Report : public CJS_Object { public: - CJS_Report(JSFXObject pObject) : CJS_Object(pObject) {} + CJS_Report(v8::Local<v8::Object> pObject) : CJS_Object(pObject) {} ~CJS_Report() override {} public: diff --git a/fpdfsdk/include/javascript/util.h b/fpdfsdk/include/javascript/util.h index 369985673a..d7a1ef7b8c 100644 --- a/fpdfsdk/include/javascript/util.h +++ b/fpdfsdk/include/javascript/util.h @@ -51,7 +51,7 @@ class util : public CJS_EmbedObj { class CJS_Util : public CJS_Object { public: - CJS_Util(JSFXObject pObject) : CJS_Object(pObject) {} + CJS_Util(v8::Local<v8::Object> pObject) : CJS_Object(pObject) {} ~CJS_Util() override {} DECLARE_JS_CLASS(CJS_Util); diff --git a/fpdfsdk/include/jsapi/fxjs_v8.h b/fpdfsdk/include/jsapi/fxjs_v8.h index f9d8f50248..8e52c68845 100644 --- a/fpdfsdk/include/jsapi/fxjs_v8.h +++ b/fpdfsdk/include/jsapi/fxjs_v8.h @@ -13,10 +13,6 @@ #include <v8.h> #include "../../../core/include/fxcrt/fx_string.h" // For CFX_WideString -typedef v8::Value JSValue; -typedef v8::Local<v8::Object> JSObject; -typedef v8::Local<v8::Object> JSFXObject; - enum FXJSOBJTYPE { JS_DYNAMIC = 0, JS_STATIC = 1, @@ -43,7 +39,6 @@ struct FXJSErr { /* --------------------------------------------- API * --------------------------------------------- */ -typedef v8::Isolate IJS_Runtime; class IFXJS_Context; class IFXJS_Runtime; @@ -52,143 +47,138 @@ typedef void (*LP_CONSTRUCTOR)(IFXJS_Context* cc, v8::Local<v8::Object> global); typedef void (*LP_DESTRUCTOR)(v8::Local<v8::Object> obj); -int JS_DefineObj(IJS_Runtime* pJSRuntime, +int JS_DefineObj(v8::Isolate* pIsolate, const wchar_t* sObjName, FXJSOBJTYPE eObjType, LP_CONSTRUCTOR pConstructor, LP_DESTRUCTOR pDestructor); -int JS_DefineObjMethod(IJS_Runtime* pJSRuntime, +int JS_DefineObjMethod(v8::Isolate* pIsolate, int nObjDefnID, const wchar_t* sMethodName, v8::FunctionCallback pMethodCall); -int JS_DefineObjProperty(IJS_Runtime* pJSRuntime, +int JS_DefineObjProperty(v8::Isolate* pIsolate, int nObjDefnID, const wchar_t* sPropName, v8::AccessorGetterCallback pPropGet, v8::AccessorSetterCallback pPropPut); -int JS_DefineObjAllProperties(IJS_Runtime* pJSRuntime, +int JS_DefineObjAllProperties(v8::Isolate* pIsolate, int nObjDefnID, v8::NamedPropertyQueryCallback pPropQurey, v8::NamedPropertyGetterCallback pPropGet, v8::NamedPropertySetterCallback pPropPut, v8::NamedPropertyDeleterCallback pPropDel); -int JS_DefineObjConst(IJS_Runtime* pJSRuntime, +int JS_DefineObjConst(v8::Isolate* pIsolate, int nObjDefnID, const wchar_t* sConstName, v8::Local<v8::Value> pDefault); -int JS_DefineGlobalMethod(IJS_Runtime* pJSRuntime, +int JS_DefineGlobalMethod(v8::Isolate* pIsolate, const wchar_t* sMethodName, v8::FunctionCallback pMethodCall); -int JS_DefineGlobalConst(IJS_Runtime* pJSRuntime, +int JS_DefineGlobalConst(v8::Isolate* pIsolate, const wchar_t* sConstName, v8::Local<v8::Value> pDefault); -void JS_InitialRuntime(IJS_Runtime* pJSRuntime, +void JS_InitialRuntime(v8::Isolate* pIsolate, IFXJS_Runtime* pFXRuntime, IFXJS_Context* context, v8::Global<v8::Context>& v8PersistentContext); -void JS_ReleaseRuntime(IJS_Runtime* pJSRuntime, +void JS_ReleaseRuntime(v8::Isolate* pIsolate, v8::Global<v8::Context>& v8PersistentContext); void JS_Initial(unsigned int embedderDataSlot); void JS_Release(); -int JS_Execute(IJS_Runtime* pJSRuntime, +int JS_Execute(v8::Isolate* pIsolate, IFXJS_Context* pJSContext, const wchar_t* script, long length, FXJSErr* perror); -v8::Local<v8::Object> JS_NewFxDynamicObj(IJS_Runtime* pJSRuntime, +v8::Local<v8::Object> JS_NewFxDynamicObj(v8::Isolate* pIsolate, IFXJS_Context* pJSContext, int nObjDefnID); -v8::Local<v8::Object> JS_GetStaticObj(IJS_Runtime* pJSRuntime, int nObjDefnID); -void JS_SetThisObj(IJS_Runtime* pJSRuntime, int nThisObjID); -v8::Local<v8::Object> JS_GetThisObj(IJS_Runtime* pJSRuntime); +v8::Local<v8::Object> JS_GetStaticObj(v8::Isolate* pIsolate, int nObjDefnID); +v8::Local<v8::Object> JS_GetThisObj(v8::Isolate* pIsolate); int JS_GetObjDefnID(v8::Local<v8::Object> pObj); -IJS_Runtime* JS_GetRuntime(v8::Local<v8::Object> pObj); -int JS_GetObjDefnID(IJS_Runtime* pJSRuntime, const wchar_t* pObjName); +v8::Isolate* JS_GetRuntime(v8::Local<v8::Object> pObj); +int JS_GetObjDefnID(v8::Isolate* pIsolate, const wchar_t* pObjName); void JS_Error(v8::Isolate* isolate, const CFX_WideString& message); unsigned JS_CalcHash(const wchar_t* main, unsigned nLen); unsigned JS_CalcHash(const wchar_t* main); const wchar_t* JS_GetTypeof(v8::Local<v8::Value> pObj); -void JS_SetPrivate(IJS_Runtime* pJSRuntime, - v8::Local<v8::Object> pObj, - void* p); -void* JS_GetPrivate(IJS_Runtime* pJSRuntime, v8::Local<v8::Object> pObj); +void JS_SetPrivate(v8::Isolate* pIsolate, v8::Local<v8::Object> pObj, void* p); +void* JS_GetPrivate(v8::Isolate* pIsolate, v8::Local<v8::Object> pObj); void JS_SetPrivate(v8::Local<v8::Object> pObj, void* p); void* JS_GetPrivate(v8::Local<v8::Object> pObj); void JS_FreePrivate(void* p); void JS_FreePrivate(v8::Local<v8::Object> pObj); v8::Local<v8::Value> JS_GetObjectValue(v8::Local<v8::Object> pObj); -v8::Local<v8::Value> JS_GetObjectElement(IJS_Runtime* pJSRuntime, +v8::Local<v8::Value> JS_GetObjectElement(v8::Isolate* pIsolate, v8::Local<v8::Object> pObj, const wchar_t* PropertyName); -v8::Local<v8::Array> JS_GetObjectElementNames(IJS_Runtime* pJSRuntime, +v8::Local<v8::Array> JS_GetObjectElementNames(v8::Isolate* pIsolate, v8::Local<v8::Object> pObj); -void JS_PutObjectString(IJS_Runtime* pJSRuntime, +void JS_PutObjectString(v8::Isolate* pIsolate, v8::Local<v8::Object> pObj, const wchar_t* PropertyName, const wchar_t* sValue); -void JS_PutObjectNumber(IJS_Runtime* pJSRuntime, +void JS_PutObjectNumber(v8::Isolate* pIsolate, v8::Local<v8::Object> pObj, const wchar_t* PropertyName, int nValue); -void JS_PutObjectNumber(IJS_Runtime* pJSRuntime, +void JS_PutObjectNumber(v8::Isolate* pIsolate, v8::Local<v8::Object> pObj, const wchar_t* PropertyName, float fValue); -void JS_PutObjectNumber(IJS_Runtime* pJSRuntime, +void JS_PutObjectNumber(v8::Isolate* pIsolate, v8::Local<v8::Object> pObj, const wchar_t* PropertyName, double dValue); -void JS_PutObjectBoolean(IJS_Runtime* pJSRuntime, +void JS_PutObjectBoolean(v8::Isolate* pIsolate, v8::Local<v8::Object> pObj, const wchar_t* PropertyName, bool bValue); -void JS_PutObjectObject(IJS_Runtime* pJSRuntime, +void JS_PutObjectObject(v8::Isolate* pIsolate, v8::Local<v8::Object> pObj, const wchar_t* PropertyName, v8::Local<v8::Object> pPut); -void JS_PutObjectNull(IJS_Runtime* pJSRuntime, +void JS_PutObjectNull(v8::Isolate* pIsolate, v8::Local<v8::Object> pObj, const wchar_t* PropertyName); -unsigned JS_PutArrayElement(IJS_Runtime* pJSRuntime, +unsigned JS_PutArrayElement(v8::Isolate* pIsolate, v8::Local<v8::Array> pArray, unsigned index, v8::Local<v8::Value> pValue, FXJSVALUETYPE eType); -v8::Local<v8::Value> JS_GetArrayElement(IJS_Runtime* pJSRuntime, +v8::Local<v8::Value> JS_GetArrayElement(v8::Isolate* pIsolate, v8::Local<v8::Array> pArray, unsigned index); unsigned JS_GetArrayLength(v8::Local<v8::Array> pArray); -v8::Local<v8::Value> JS_GetListValue(IJS_Runtime* pJSRuntime, +v8::Local<v8::Value> JS_GetListValue(v8::Isolate* pIsolate, v8::Local<v8::Value> pList, int index); -v8::Local<v8::Array> JS_NewArray(IJS_Runtime* pJSRuntime); -v8::Local<v8::Value> JS_NewNumber(IJS_Runtime* pJSRuntime, int number); -v8::Local<v8::Value> JS_NewNumber(IJS_Runtime* pJSRuntime, double number); -v8::Local<v8::Value> JS_NewNumber(IJS_Runtime* pJSRuntime, float number); -v8::Local<v8::Value> JS_NewBoolean(IJS_Runtime* pJSRuntime, bool b); -v8::Local<v8::Value> JS_NewObject(IJS_Runtime* pJSRuntime, +v8::Local<v8::Array> JS_NewArray(v8::Isolate* pIsolate); +v8::Local<v8::Value> JS_NewNumber(v8::Isolate* pIsolate, int number); +v8::Local<v8::Value> JS_NewNumber(v8::Isolate* pIsolate, double number); +v8::Local<v8::Value> JS_NewNumber(v8::Isolate* pIsolate, float number); +v8::Local<v8::Value> JS_NewBoolean(v8::Isolate* pIsolate, bool b); +v8::Local<v8::Value> JS_NewObject(v8::Isolate* pIsolate, v8::Local<v8::Object> pObj); -v8::Local<v8::Value> JS_NewObject2(IJS_Runtime* pJSRuntime, +v8::Local<v8::Value> JS_NewObject2(v8::Isolate* pIsolate, v8::Local<v8::Array> pObj); -v8::Local<v8::Value> JS_NewString(IJS_Runtime* pJSRuntime, - const wchar_t* string); -v8::Local<v8::Value> JS_NewString(IJS_Runtime* pJSRuntime, +v8::Local<v8::Value> JS_NewString(v8::Isolate* pIsolate, const wchar_t* string); +v8::Local<v8::Value> JS_NewString(v8::Isolate* pIsolate, const wchar_t* string, unsigned nLen); v8::Local<v8::Value> JS_NewNull(); -v8::Local<v8::Value> JS_NewDate(IJS_Runtime* pJSRuntime, double d); -v8::Local<v8::Value> JS_NewValue(IJS_Runtime* pJSRuntime); +v8::Local<v8::Value> JS_NewDate(v8::Isolate* pIsolate, double d); +v8::Local<v8::Value> JS_NewValue(v8::Isolate* pIsolate); -int JS_ToInt32(IJS_Runtime* pJSRuntime, v8::Local<v8::Value> pValue); -bool JS_ToBoolean(IJS_Runtime* pJSRuntime, v8::Local<v8::Value> pValue); -double JS_ToNumber(IJS_Runtime* pJSRuntime, v8::Local<v8::Value> pValue); -v8::Local<v8::Object> JS_ToObject(IJS_Runtime* pJSRuntime, +int JS_ToInt32(v8::Isolate* pIsolate, v8::Local<v8::Value> pValue); +bool JS_ToBoolean(v8::Isolate* pIsolate, v8::Local<v8::Value> pValue); +double JS_ToNumber(v8::Isolate* pIsolate, v8::Local<v8::Value> pValue); +v8::Local<v8::Object> JS_ToObject(v8::Isolate* pIsolate, v8::Local<v8::Value> pValue); -CFX_WideString JS_ToString(IJS_Runtime* pJSRuntime, - v8::Local<v8::Value> pValue); -v8::Local<v8::Array> JS_ToArray(IJS_Runtime* pJSRuntime, +CFX_WideString JS_ToString(v8::Isolate* pIsolate, v8::Local<v8::Value> pValue); +v8::Local<v8::Array> JS_ToArray(v8::Isolate* pIsolate, v8::Local<v8::Value> pValue); void JS_ValueCopy(v8::Local<v8::Value>& pTo, v8::Local<v8::Value> pFrom); diff --git a/fpdfsdk/src/javascript/Consts.cpp b/fpdfsdk/src/javascript/Consts.cpp index 4529f013fe..77cf445d77 100644 --- a/fpdfsdk/src/javascript/Consts.cpp +++ b/fpdfsdk/src/javascript/Consts.cpp @@ -130,28 +130,28 @@ IMPLEMENT_JS_CLASS_CONST(CJS_Zoomtype, zoomtype) /* ------------------------------ CJS_GlobalConsts * ------------------------------ */ -int CJS_GlobalConsts::Init(IJS_Runtime* pRuntime) { - DEFINE_GLOBAL_CONST(pRuntime, IDS_GREATER_THAN, Invalid value +int CJS_GlobalConsts::Init(v8::Isolate* pIsolate) { + DEFINE_GLOBAL_CONST(pIsolate, IDS_GREATER_THAN, Invalid value : must be greater than or equal to % s.); DEFINE_GLOBAL_CONST( - pRuntime, IDS_GT_AND_LT, Invalid value + pIsolate, IDS_GT_AND_LT, Invalid value : must be greater than or equal to % s and less than or equal to % s.); - DEFINE_GLOBAL_CONST(pRuntime, IDS_LESS_THAN, Invalid value + DEFINE_GLOBAL_CONST(pIsolate, IDS_LESS_THAN, Invalid value : must be less than or equal to % s.); - DEFINE_GLOBAL_CONST(pRuntime, IDS_INVALID_MONTH, **Invalid**); - DEFINE_GLOBAL_CONST(pRuntime, IDS_INVALID_DATE, Invalid date / time + DEFINE_GLOBAL_CONST(pIsolate, IDS_INVALID_MONTH, **Invalid**); + DEFINE_GLOBAL_CONST(pIsolate, IDS_INVALID_DATE, Invalid date / time : please ensure that the date / time exists.Field); - DEFINE_GLOBAL_CONST(pRuntime, IDS_INVALID_VALUE, + DEFINE_GLOBAL_CONST(pIsolate, IDS_INVALID_VALUE, The value entered does not match the format of the field); - DEFINE_GLOBAL_CONST(pRuntime, IDS_AM, am); - DEFINE_GLOBAL_CONST(pRuntime, IDS_PM, pm); + DEFINE_GLOBAL_CONST(pIsolate, IDS_AM, am); + DEFINE_GLOBAL_CONST(pIsolate, IDS_PM, pm); DEFINE_GLOBAL_CONST( - pRuntime, IDS_MONTH_INFO, + pIsolate, IDS_MONTH_INFO, January[1] February[2] March[3] April[4] May[5] June[6] July[7] August [8] September[9] October[10] November[11] December[12] Sept[9] Jan [1] Feb[2] Mar[3] Apr[4] Jun[6] Jul[7] Aug[8] Sep[9] Oct[10] Nov [11] Dec[12]); - DEFINE_GLOBAL_CONST(pRuntime, IDS_STARTUP_CONSOLE_MSG, ** ^ _ ^ **); + DEFINE_GLOBAL_CONST(pIsolate, IDS_STARTUP_CONSOLE_MSG, ** ^ _ ^ **); return 0; } @@ -159,11 +159,11 @@ int CJS_GlobalConsts::Init(IJS_Runtime* pRuntime) { /* ------------------------------ CJS_GlobalArrays * ------------------------------ */ -int CJS_GlobalArrays::Init(IJS_Runtime* pRuntime) { +int CJS_GlobalArrays::Init(v8::Isolate* pIsolate) { { const FX_WCHAR* ArrayName = L"RE_NUMBER_ENTRY_DOT_SEP"; const FX_WCHAR* ArrayContent[] = {L"[+-]?\\d*\\.?\\d*"}; - DEFINE_GLOBAL_ARRAY(pRuntime); + DEFINE_GLOBAL_ARRAY(pIsolate); } { @@ -173,14 +173,14 @@ int CJS_GlobalArrays::Init(IJS_Runtime* pRuntime) { L"[+-]?\\.\\d+", /* -.1 */ L"[+-]?\\d+\\." /* -1. */ }; - DEFINE_GLOBAL_ARRAY(pRuntime); + DEFINE_GLOBAL_ARRAY(pIsolate); } { const FX_WCHAR* ArrayName = L"RE_NUMBER_ENTRY_COMMA_SEP"; const FX_WCHAR* ArrayContent[] = {L"[+-]?\\d*,?\\d*"}; - DEFINE_GLOBAL_ARRAY(pRuntime); + DEFINE_GLOBAL_ARRAY(pIsolate); } { @@ -190,31 +190,31 @@ int CJS_GlobalArrays::Init(IJS_Runtime* pRuntime) { L"[+-]?[.,]\\d+", /* -,1 */ L"[+-]?\\d+[.,]" /* -1, */ }; - DEFINE_GLOBAL_ARRAY(pRuntime); + DEFINE_GLOBAL_ARRAY(pIsolate); } { const FX_WCHAR* ArrayName = L"RE_ZIP_ENTRY"; const FX_WCHAR* ArrayContent[] = {L"\\d{0,5}"}; - DEFINE_GLOBAL_ARRAY(pRuntime); + DEFINE_GLOBAL_ARRAY(pIsolate); } { const FX_WCHAR* ArrayName = L"RE_ZIP_COMMIT"; const FX_WCHAR* ArrayContent[] = {L"\\d{5}"}; - DEFINE_GLOBAL_ARRAY(pRuntime); + DEFINE_GLOBAL_ARRAY(pIsolate); } { const FX_WCHAR* ArrayName = L"RE_ZIP4_ENTRY"; const FX_WCHAR* ArrayContent[] = {L"\\d{0,5}(\\.|[- ])?\\d{0,4}"}; - DEFINE_GLOBAL_ARRAY(pRuntime); + DEFINE_GLOBAL_ARRAY(pIsolate); } { const FX_WCHAR* ArrayName = L"RE_ZIP4_COMMIT"; const FX_WCHAR* ArrayContent[] = {L"\\d{5}(\\.|[- ])?\\d{4}"}; - DEFINE_GLOBAL_ARRAY(pRuntime); + DEFINE_GLOBAL_ARRAY(pIsolate); } { @@ -232,7 +232,7 @@ int CJS_GlobalArrays::Init(IJS_Runtime* pRuntime) { */ L"011(\\.|[- \\d])*" /* international */ }; - DEFINE_GLOBAL_ARRAY(pRuntime); + DEFINE_GLOBAL_ARRAY(pIsolate); } { @@ -243,21 +243,21 @@ int CJS_GlobalArrays::Init(IJS_Runtime* pRuntime) { L"\\(\\d{3}\\)(\\.|[- ])?\\d{3}(\\.|[- ])?\\d{4}", /* (408) 555-1234 */ L"011(\\.|[- \\d])*" /* international */ }; - DEFINE_GLOBAL_ARRAY(pRuntime); + DEFINE_GLOBAL_ARRAY(pIsolate); } { const FX_WCHAR* ArrayName = L"RE_SSN_ENTRY"; const FX_WCHAR* ArrayContent[] = { L"\\d{0,3}(\\.|[- ])?\\d{0,2}(\\.|[- ])?\\d{0,4}"}; - DEFINE_GLOBAL_ARRAY(pRuntime); + DEFINE_GLOBAL_ARRAY(pIsolate); } { const FX_WCHAR* ArrayName = L"RE_SSN_COMMIT"; const FX_WCHAR* ArrayContent[] = { L"\\d{3}(\\.|[- ])?\\d{2}(\\.|[- ])?\\d{4}"}; - DEFINE_GLOBAL_ARRAY(pRuntime); + DEFINE_GLOBAL_ARRAY(pIsolate); } return 0; diff --git a/fpdfsdk/src/javascript/Document.cpp b/fpdfsdk/src/javascript/Document.cpp index 91805b825e..a8a4ebc491 100644 --- a/fpdfsdk/src/javascript/Document.cpp +++ b/fpdfsdk/src/javascript/Document.cpp @@ -260,11 +260,6 @@ FX_BOOL Document::pageNum(IFXJS_Context* cc, return TRUE; } -FX_BOOL Document::ParserParams(JSObject* pObj, CJS_AnnotObj& annotobj) { - // Not supported. - return TRUE; -} - FX_BOOL Document::addAnnot(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, @@ -330,8 +325,9 @@ FX_BOOL Document::getField(IFXJS_Context* cc, } CJS_Runtime* pRuntime = pContext->GetJSRuntime(); - JSFXObject pFieldObj = JS_NewFxDynamicObj( - *pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"Field")); + v8::Local<v8::Object> pFieldObj = + JS_NewFxDynamicObj(pRuntime->GetIsolate(), pContext, + JS_GetObjDefnID(pRuntime->GetIsolate(), L"Field")); v8::Isolate* isolate = GetIsolate(cc); CJS_Field* pJSField = (CJS_Field*)JS_GetPrivate(isolate, pFieldObj); @@ -462,10 +458,10 @@ FX_BOOL Document::print(IFXJS_Context* cc, int nlength = params.size(); if (nlength == 9) { if (params[8].GetType() == VT_fxobject) { - JSFXObject pObj = params[8].ToV8Object(); + v8::Local<v8::Object> pObj = params[8].ToV8Object(); { if (JS_GetObjDefnID(pObj) == - JS_GetObjDefnID(*pRuntime, L"PrintParamsObj")) { + JS_GetObjDefnID(pRuntime->GetIsolate(), L"PrintParamsObj")) { if (CJS_Object* pJSObj = params[8].ToCJSObject()) { if (PrintParamsObj* pprintparamsObj = (PrintParamsObj*)pJSObj->GetEmbedObject()) { @@ -664,7 +660,7 @@ FX_BOOL Document::submitForm(IFXJS_Context* cc, if (nSize > 3) aFields.Attach(params[3].ToV8Array()); } else if (v.GetType() == VT_object) { - JSObject pObj = params[0].ToV8Object(); + v8::Local<v8::Object> pObj = params[0].ToV8Object(); v8::Local<v8::Value> pValue = JS_GetObjectElement(isolate, pObj, L"cURL"); if (!pValue.IsEmpty()) strURL = @@ -771,7 +767,7 @@ FX_BOOL Document::mailDoc(IFXJS_Context* cc, v8::Isolate* isolate = GetIsolate(cc); if (params.size() >= 1 && params[0].GetType() == VT_object) { - JSObject pObj = params[0].ToV8Object(); + v8::Local<v8::Object> pObj = params[0].ToV8Object(); v8::Local<v8::Value> pValue = JS_GetObjectElement(isolate, pObj, L"bUI"); bUI = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToInt(); @@ -854,7 +850,8 @@ FX_BOOL Document::info(IFXJS_Context* cc, if (vp.IsGetting()) { CJS_Context* pContext = (CJS_Context*)cc; CJS_Runtime* pRuntime = pContext->GetJSRuntime(); - JSFXObject pObj = JS_NewFxDynamicObj(*pRuntime, pContext, -1); + v8::Local<v8::Object> pObj = + JS_NewFxDynamicObj(pRuntime->GetIsolate(), pContext, -1); JS_PutObjectString(isolate, pObj, L"Author", cwAuthor.c_str()); JS_PutObjectString(isolate, pObj, L"Title", cwTitle.c_str()); JS_PutObjectString(isolate, pObj, L"Subject", cwSubject.c_str()); @@ -1373,10 +1370,11 @@ FX_BOOL Document::addIcon(IFXJS_Context* cc, sError = JSGetStringFromID(pContext, IDS_STRING_JSTYPEERROR); return FALSE; } - JSFXObject pJSIcon = params[1].ToV8Object(); + v8::Local<v8::Object> pJSIcon = params[1].ToV8Object(); CJS_Runtime* pRuntime = pContext->GetJSRuntime(); - if (JS_GetObjDefnID(pJSIcon) != JS_GetObjDefnID(*pRuntime, L"Icon")) { + if (JS_GetObjDefnID(pJSIcon) != + JS_GetObjDefnID(pRuntime->GetIsolate(), L"Icon")) { sError = JSGetStringFromID(pContext, IDS_STRING_JSTYPEERROR); return FALSE; } @@ -1423,8 +1421,9 @@ FX_BOOL Document::icons(IFXJS_Context* cc, for (int i = 0; i < iIconTreeLength; i++) { pIconElement = (*m_pIconTree)[i]; - JSFXObject pObj = JS_NewFxDynamicObj(*pRuntime, pContext, - JS_GetObjDefnID(*pRuntime, L"Icon")); + v8::Local<v8::Object> pObj = + JS_NewFxDynamicObj(pRuntime->GetIsolate(), pContext, + JS_GetObjDefnID(pRuntime->GetIsolate(), L"Icon")); if (pObj.IsEmpty()) return FALSE; @@ -1466,8 +1465,9 @@ FX_BOOL Document::getIcon(IFXJS_Context* cc, if ((*m_pIconTree)[i]->IconName == swIconName) { Icon* pRetIcon = (*m_pIconTree)[i]->IconStream; - JSFXObject pObj = JS_NewFxDynamicObj(*pRuntime, pContext, - JS_GetObjDefnID(*pRuntime, L"Icon")); + v8::Local<v8::Object> pObj = + JS_NewFxDynamicObj(pRuntime->GetIsolate(), pContext, + JS_GetObjDefnID(pRuntime->GetIsolate(), L"Icon")); if (pObj.IsEmpty()) return FALSE; @@ -1662,8 +1662,9 @@ FX_BOOL Document::getPrintParams(IFXJS_Context* cc, CFX_WideString& sError) { CJS_Context* pContext = (CJS_Context*)cc; CJS_Runtime* pRuntime = pContext->GetJSRuntime(); - JSFXObject pRetObj = JS_NewFxDynamicObj( - *pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"PrintParamsObj")); + v8::Local<v8::Object> pRetObj = JS_NewFxDynamicObj( + pRuntime->GetIsolate(), pContext, + JS_GetObjDefnID(pRuntime->GetIsolate(), L"PrintParamsObj")); // Not implemented yet. diff --git a/fpdfsdk/src/javascript/Field.cpp b/fpdfsdk/src/javascript/Field.cpp index c44636872b..a0570cb56c 100644 --- a/fpdfsdk/src/javascript/Field.cpp +++ b/fpdfsdk/src/javascript/Field.cpp @@ -3315,8 +3315,9 @@ FX_BOOL Field::buttonGetIcon(IFXJS_Context* cc, CJS_Runtime* pRuntime = pContext->GetJSRuntime(); ASSERT(pRuntime != NULL); - JSFXObject pObj = JS_NewFxDynamicObj(*pRuntime, pContext, - JS_GetObjDefnID(*pRuntime, L"Icon")); + v8::Local<v8::Object> pObj = + JS_NewFxDynamicObj(pRuntime->GetIsolate(), pContext, + JS_GetObjDefnID(pRuntime->GetIsolate(), L"Icon")); ASSERT(pObj.IsEmpty() == FALSE); CJS_Icon* pJS_Icon = (CJS_Icon*)JS_GetPrivate(pObj); @@ -3530,8 +3531,9 @@ FX_BOOL Field::getArray(IFXJS_Context* cc, for (int j = 0, jsz = swSort.GetSize(); j < jsz; j++) { CFX_WideString* pStr = swSort.GetAt(j); - JSFXObject pObj = JS_NewFxDynamicObj(*pRuntime, pContext, - JS_GetObjDefnID(*pRuntime, L"Field")); + v8::Local<v8::Object> pObj = + JS_NewFxDynamicObj(pRuntime->GetIsolate(), pContext, + JS_GetObjDefnID(pRuntime->GetIsolate(), L"Field")); ASSERT(pObj.IsEmpty() == FALSE); CJS_Field* pJSField = (CJS_Field*)JS_GetPrivate(pObj); diff --git a/fpdfsdk/src/javascript/JS_Context.cpp b/fpdfsdk/src/javascript/JS_Context.cpp index 1e42b50138..2bee913ed7 100644 --- a/fpdfsdk/src/javascript/JS_Context.cpp +++ b/fpdfsdk/src/javascript/JS_Context.cpp @@ -55,8 +55,8 @@ FX_BOOL CJS_Context::RunScript(const CFX_WideString& script, FXJSErr error = {NULL, NULL, 0}; int nRet = 0; if (script.GetLength() > 0) { - nRet = JS_Execute(*m_pRuntime, this, script.c_str(), script.GetLength(), - &error); + nRet = JS_Execute(m_pRuntime->GetIsolate(), this, script.c_str(), + script.GetLength(), &error); } if (nRet < 0) { diff --git a/fpdfsdk/src/javascript/JS_EventHandler.cpp b/fpdfsdk/src/javascript/JS_EventHandler.cpp index 1eee92ddc1..acaacf2943 100644 --- a/fpdfsdk/src/javascript/JS_EventHandler.cpp +++ b/fpdfsdk/src/javascript/JS_EventHandler.cpp @@ -615,11 +615,13 @@ Field* CJS_EventHandler::Source() { CJS_Runtime* pRuntime = m_pJSContext->GetJSRuntime(); - JSFXObject pDocObj = JS_NewFxDynamicObj( - *pRuntime, m_pJSContext, JS_GetObjDefnID(*pRuntime, L"Document")); + v8::Local<v8::Object> pDocObj = + JS_NewFxDynamicObj(pRuntime->GetIsolate(), m_pJSContext, + JS_GetObjDefnID(pRuntime->GetIsolate(), L"Document")); ASSERT(pDocObj.IsEmpty() == FALSE); - JSFXObject pFieldObj = JS_NewFxDynamicObj( - *pRuntime, m_pJSContext, JS_GetObjDefnID(*pRuntime, L"Field")); + v8::Local<v8::Object> pFieldObj = + JS_NewFxDynamicObj(pRuntime->GetIsolate(), m_pJSContext, + JS_GetObjDefnID(pRuntime->GetIsolate(), L"Field")); ASSERT(pFieldObj.IsEmpty() == FALSE); CJS_Document* pJSDocument = (CJS_Document*)JS_GetPrivate(pDocObj); @@ -650,11 +652,13 @@ Field* CJS_EventHandler::Target_Field() { CJS_Runtime* pRuntime = m_pJSContext->GetJSRuntime(); - JSFXObject pDocObj = JS_NewFxDynamicObj( - *pRuntime, m_pJSContext, JS_GetObjDefnID(*pRuntime, L"Document")); + v8::Local<v8::Object> pDocObj = + JS_NewFxDynamicObj(pRuntime->GetIsolate(), m_pJSContext, + JS_GetObjDefnID(pRuntime->GetIsolate(), L"Document")); ASSERT(pDocObj.IsEmpty() == FALSE); - JSFXObject pFieldObj = JS_NewFxDynamicObj( - *pRuntime, m_pJSContext, JS_GetObjDefnID(*pRuntime, L"Field")); + v8::Local<v8::Object> pFieldObj = + JS_NewFxDynamicObj(pRuntime->GetIsolate(), m_pJSContext, + JS_GetObjDefnID(pRuntime->GetIsolate(), L"Field")); ASSERT(pFieldObj.IsEmpty() == FALSE); CJS_Document* pJSDocument = (CJS_Document*)JS_GetPrivate(pDocObj); diff --git a/fpdfsdk/src/javascript/JS_Object.cpp b/fpdfsdk/src/javascript/JS_Object.cpp index 02978982d8..17e987d96a 100644 --- a/fpdfsdk/src/javascript/JS_Object.cpp +++ b/fpdfsdk/src/javascript/JS_Object.cpp @@ -83,7 +83,7 @@ void DisposeObject(const v8::WeakCallbackInfo<CJS_Object>& data) { data.SetSecondPassCallback(FreeObject); } -CJS_Object::CJS_Object(JSFXObject pObject) : m_pEmbedObj(NULL) { +CJS_Object::CJS_Object(v8::Local<v8::Object> pObject) : m_pEmbedObj(NULL) { v8::Local<v8::Context> context = pObject->CreationContext(); m_pIsolate = context->GetIsolate(); m_pObject.Reset(m_pIsolate, pObject); diff --git a/fpdfsdk/src/javascript/JS_Runtime.cpp b/fpdfsdk/src/javascript/JS_Runtime.cpp index 4ef34a8d20..e3b3ed0f49 100644 --- a/fpdfsdk/src/javascript/JS_Runtime.cpp +++ b/fpdfsdk/src/javascript/JS_Runtime.cpp @@ -116,7 +116,7 @@ CJS_Runtime::CJS_Runtime(CPDFDoc_Environment* pApp) InitJSObjects(); CJS_Context* pContext = (CJS_Context*)NewContext(); - JS_InitialRuntime(*this, this, pContext, m_context); + JS_InitialRuntime(GetIsolate(), this, pContext, m_context); ReleaseContext(pContext); } @@ -125,9 +125,7 @@ CJS_Runtime::~CJS_Runtime() { delete m_ContextArray.GetAt(i); m_ContextArray.RemoveAll(); - - JS_ReleaseRuntime(*this, m_context); - + JS_ReleaseRuntime(GetIsolate(), m_context); RemoveEventsInLoop(m_pFieldEventPath); m_pApp = NULL; @@ -145,59 +143,59 @@ FX_BOOL CJS_Runtime::InitJSObjects() { v8::Local<v8::Context> context = v8::Context::New(GetIsolate()); v8::Context::Scope context_scope(context); // 0 - 8 - if (CJS_Border::Init(*this, JS_STATIC) < 0) + if (CJS_Border::Init(GetIsolate(), JS_STATIC) < 0) return FALSE; - if (CJS_Display::Init(*this, JS_STATIC) < 0) + if (CJS_Display::Init(GetIsolate(), JS_STATIC) < 0) return FALSE; - if (CJS_Font::Init(*this, JS_STATIC) < 0) + if (CJS_Font::Init(GetIsolate(), JS_STATIC) < 0) return FALSE; - if (CJS_Highlight::Init(*this, JS_STATIC) < 0) + if (CJS_Highlight::Init(GetIsolate(), JS_STATIC) < 0) return FALSE; - if (CJS_Position::Init(*this, JS_STATIC) < 0) + if (CJS_Position::Init(GetIsolate(), JS_STATIC) < 0) return FALSE; - if (CJS_ScaleHow::Init(*this, JS_STATIC) < 0) + if (CJS_ScaleHow::Init(GetIsolate(), JS_STATIC) < 0) return FALSE; - if (CJS_ScaleWhen::Init(*this, JS_STATIC) < 0) + if (CJS_ScaleWhen::Init(GetIsolate(), JS_STATIC) < 0) return FALSE; - if (CJS_Style::Init(*this, JS_STATIC) < 0) + if (CJS_Style::Init(GetIsolate(), JS_STATIC) < 0) return FALSE; - if (CJS_Zoomtype::Init(*this, JS_STATIC) < 0) + if (CJS_Zoomtype::Init(GetIsolate(), JS_STATIC) < 0) return FALSE; // 9 - 11 - if (CJS_App::Init(*this, JS_STATIC) < 0) + if (CJS_App::Init(GetIsolate(), JS_STATIC) < 0) return FALSE; - if (CJS_Color::Init(*this, JS_STATIC) < 0) + if (CJS_Color::Init(GetIsolate(), JS_STATIC) < 0) return FALSE; - if (CJS_Console::Init(*this, JS_STATIC) < 0) + if (CJS_Console::Init(GetIsolate(), JS_STATIC) < 0) return FALSE; // 12 - 14 - if (CJS_Document::Init(*this, JS_DYNAMIC) < 0) + if (CJS_Document::Init(GetIsolate(), JS_DYNAMIC) < 0) return FALSE; - if (CJS_Event::Init(*this, JS_STATIC) < 0) + if (CJS_Event::Init(GetIsolate(), JS_STATIC) < 0) return FALSE; - if (CJS_Field::Init(*this, JS_DYNAMIC) < 0) + if (CJS_Field::Init(GetIsolate(), JS_DYNAMIC) < 0) return FALSE; // 15 - 17 - if (CJS_Global::Init(*this, JS_STATIC) < 0) + if (CJS_Global::Init(GetIsolate(), JS_STATIC) < 0) return FALSE; - if (CJS_Icon::Init(*this, JS_DYNAMIC) < 0) + if (CJS_Icon::Init(GetIsolate(), JS_DYNAMIC) < 0) return FALSE; - if (CJS_Util::Init(*this, JS_STATIC) < 0) + if (CJS_Util::Init(GetIsolate(), JS_STATIC) < 0) return FALSE; - if (CJS_PublicMethods::Init(*this) < 0) + if (CJS_PublicMethods::Init(GetIsolate()) < 0) return FALSE; - if (CJS_GlobalConsts::Init(*this) < 0) + if (CJS_GlobalConsts::Init(GetIsolate()) < 0) return FALSE; - if (CJS_GlobalArrays::Init(*this) < 0) + if (CJS_GlobalArrays::Init(GetIsolate()) < 0) return FALSE; - if (CJS_TimerObj::Init(*this, JS_DYNAMIC) < 0) + if (CJS_TimerObj::Init(GetIsolate(), JS_DYNAMIC) < 0) return FALSE; - if (CJS_PrintParamsObj::Init(*this, JS_DYNAMIC) < 0) + if (CJS_PrintParamsObj::Init(GetIsolate(), JS_DYNAMIC) < 0) return FALSE; return TRUE; @@ -236,20 +234,17 @@ void CJS_Runtime::SetReaderDocument(CPDFSDK_Document* pReaderDoc) { v8::Context::Scope context_scope(context); m_pDocument = pReaderDoc; - if (pReaderDoc) { - JSObject pThis = JS_GetThisObj(*this); + v8::Local<v8::Object> pThis = JS_GetThisObj(GetIsolate()); if (!pThis.IsEmpty()) { - if (JS_GetObjDefnID(pThis) == JS_GetObjDefnID(*this, L"Document")) { + if (JS_GetObjDefnID(pThis) == + JS_GetObjDefnID(GetIsolate(), L"Document")) { if (CJS_Document* pJSDocument = (CJS_Document*)JS_GetPrivate(pThis)) { if (Document* pDocument = (Document*)pJSDocument->GetEmbedObject()) pDocument->AttachDoc(pReaderDoc); } } } - JS_SetThisObj(*this, JS_GetObjDefnID(*this, L"Document")); - } else { - JS_SetThisObj(*this, JS_GetObjDefnID(*this, L"app")); } } } diff --git a/fpdfsdk/src/javascript/JS_Value.cpp b/fpdfsdk/src/javascript/JS_Value.cpp index faa1eeb6fc..7fb2116e1f 100644 --- a/fpdfsdk/src/javascript/JS_Value.cpp +++ b/fpdfsdk/src/javascript/JS_Value.cpp @@ -39,7 +39,7 @@ CJS_Value::CJS_Value(v8::Isolate* isolate, const double& dValue) operator=(dValue); } -CJS_Value::CJS_Value(v8::Isolate* isolate, JSFXObject pJsObj) +CJS_Value::CJS_Value(v8::Isolate* isolate, v8::Local<v8::Object> pJsObj) : m_isolate(isolate) { operator=(pJsObj); } @@ -53,7 +53,7 @@ CJS_Value::CJS_Value(v8::Isolate* isolate, CJS_Document* pJsDoc) : m_isolate(isolate) { m_eType = VT_object; if (pJsDoc) - m_pValue = (JSFXObject)*pJsDoc; + m_pValue = (v8::Local<v8::Object>)*pJsDoc; } CJS_Value::CJS_Value(v8::Isolate* isolate, const FX_WCHAR* pWstr) @@ -168,13 +168,13 @@ void CJS_Value::operator=(v8::Local<v8::Object> pObj) { void CJS_Value::operator=(CJS_Object* pObj) { if (pObj) - operator=((JSFXObject)*pObj); + operator=((v8::Local<v8::Object>)*pObj); } void CJS_Value::operator=(CJS_Document* pJsDoc) { m_eType = VT_object; if (pJsDoc) { - m_pValue = static_cast<JSFXObject>(*pJsDoc); + m_pValue = static_cast<v8::Local<v8::Object>>(*pJsDoc); } } @@ -341,12 +341,12 @@ void CJS_PropValue::operator>>(CJS_Document*& ppJsDoc) const { ppJsDoc = static_cast<CJS_Document*>(CJS_Value::ToCJSObject()); } -void CJS_PropValue::operator<<(JSFXObject pObj) { +void CJS_PropValue::operator<<(v8::Local<v8::Object> pObj) { ASSERT(!m_bIsSetting); CJS_Value::operator=(pObj); } -void CJS_PropValue::operator>>(JSFXObject& ppObj) const { +void CJS_PropValue::operator>>(v8::Local<v8::Object>& ppObj) const { ASSERT(m_bIsSetting); ppObj = CJS_Value::ToV8Object(); } diff --git a/fpdfsdk/src/javascript/app.cpp b/fpdfsdk/src/javascript/app.cpp index 6db5d9a97f..a6794514d9 100644 --- a/fpdfsdk/src/javascript/app.cpp +++ b/fpdfsdk/src/javascript/app.cpp @@ -122,13 +122,15 @@ FX_BOOL app::activeDocs(IFXJS_Context* cc, if (CPDFSDK_Document* pDoc = pApp->GetSDKDocument()) { CJS_Document* pJSDocument = NULL; if (pDoc == pCurDoc) { - JSFXObject pObj = JS_GetThisObj(*pRuntime); - if (JS_GetObjDefnID(pObj) == JS_GetObjDefnID(*pRuntime, L"Document")) + v8::Local<v8::Object> pObj = JS_GetThisObj(pRuntime->GetIsolate()); + if (JS_GetObjDefnID(pObj) == + JS_GetObjDefnID(pRuntime->GetIsolate(), L"Document")) pJSDocument = (CJS_Document*)JS_GetPrivate(pRuntime->GetIsolate(), pObj); } else { - JSFXObject pObj = JS_NewFxDynamicObj( - *pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"Document")); + v8::Local<v8::Object> pObj = JS_NewFxDynamicObj( + pRuntime->GetIsolate(), pContext, + JS_GetObjDefnID(pRuntime->GetIsolate(), L"Document")); pJSDocument = (CJS_Document*)JS_GetPrivate(pRuntime->GetIsolate(), pObj); ASSERT(pJSDocument != NULL); } @@ -268,7 +270,7 @@ FX_BOOL app::alert(IFXJS_Context* cc, if (iSize == 1) { if (params[0].GetType() == VT_object) { - JSObject pObj = params[0].ToV8Object(); + v8::Local<v8::Object> pObj = params[0].ToV8Object(); { v8::Local<v8::Value> pValue = JS_GetObjectElement(isolate, pObj, L"cMsg"); @@ -413,8 +415,9 @@ FX_BOOL app::setInterval(IFXJS_Context* cc, // pTimer->SetStartTime(GetTickCount()); pTimer->SetJSTimer(dwInterval); - JSFXObject pRetObj = JS_NewFxDynamicObj( - *pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"TimerObj")); + v8::Local<v8::Object> pRetObj = + JS_NewFxDynamicObj(pRuntime->GetIsolate(), pContext, + JS_GetObjDefnID(pRuntime->GetIsolate(), L"TimerObj")); CJS_TimerObj* pJS_TimerObj = (CJS_TimerObj*)JS_GetPrivate(pRuntime->GetIsolate(), pRetObj); @@ -465,8 +468,9 @@ FX_BOOL app::setTimeOut(IFXJS_Context* cc, pTimer->SetTimeOut(dwTimeOut); pTimer->SetJSTimer(dwTimeOut); - JSFXObject pRetObj = JS_NewFxDynamicObj( - *pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"TimerObj")); + v8::Local<v8::Object> pRetObj = + JS_NewFxDynamicObj(pRuntime->GetIsolate(), pContext, + JS_GetObjDefnID(pRuntime->GetIsolate(), L"TimerObj")); CJS_TimerObj* pJS_TimerObj = (CJS_TimerObj*)JS_GetPrivate(pRuntime->GetIsolate(), pRetObj); @@ -497,9 +501,10 @@ FX_BOOL app::clearTimeOut(IFXJS_Context* cc, } if (params[0].GetType() == VT_fxobject) { - JSFXObject pObj = params[0].ToV8Object(); + v8::Local<v8::Object> pObj = params[0].ToV8Object(); { - if (JS_GetObjDefnID(pObj) == JS_GetObjDefnID(*pRuntime, L"TimerObj")) { + if (JS_GetObjDefnID(pObj) == + JS_GetObjDefnID(pRuntime->GetIsolate(), L"TimerObj")) { if (CJS_Object* pJSObj = params[0].ToCJSObject()) { if (TimerObj* pTimerObj = (TimerObj*)pJSObj->GetEmbedObject()) { if (CJS_Timer* pTimer = pTimerObj->GetTimer()) { @@ -539,9 +544,10 @@ FX_BOOL app::clearInterval(IFXJS_Context* cc, } if (params[0].GetType() == VT_fxobject) { - JSFXObject pObj = params[0].ToV8Object(); + v8::Local<v8::Object> pObj = params[0].ToV8Object(); { - if (JS_GetObjDefnID(pObj) == JS_GetObjDefnID(*pRuntime, L"TimerObj")) { + if (JS_GetObjDefnID(pObj) == + JS_GetObjDefnID(pRuntime->GetIsolate(), L"TimerObj")) { if (CJS_Object* pJSObj = params[0].ToCJSObject()) { if (TimerObj* pTimerObj = (TimerObj*)pJSObj->GetEmbedObject()) { if (CJS_Timer* pTimer = pTimerObj->GetTimer()) { @@ -636,7 +642,7 @@ FX_BOOL app::mailMsg(IFXJS_Context* cc, return FALSE; if (params[0].GetType() == VT_object) { - JSObject pObj = params[0].ToV8Object(); + v8::Local<v8::Object> pObj = params[0].ToV8Object(); v8::Local<v8::Value> pValue = JS_GetObjectElement(isolate, pObj, L"bUI"); bUI = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToBool(); @@ -774,7 +780,7 @@ FX_BOOL app::response(IFXJS_Context* cc, int iLength = params.size(); if (iLength > 0 && params[0].GetType() == VT_object) { - JSObject pObj = params[0].ToV8Object(); + v8::Local<v8::Object> pObj = params[0].ToV8Object(); v8::Local<v8::Value> pValue = JS_GetObjectElement(isolate, pObj, L"cQuestion"); swQuestion = diff --git a/fpdfsdk/src/javascript/global.cpp b/fpdfsdk/src/javascript/global.cpp index 94148762e2..e817eca32c 100644 --- a/fpdfsdk/src/javascript/global.cpp +++ b/fpdfsdk/src/javascript/global.cpp @@ -158,7 +158,7 @@ FX_BOOL JSGlobalAlternate::DoProperty(IFXJS_Context* cc, false, sData, v8::Local<v8::Object>(), FALSE); } case VT_object: { - JSObject pData; + v8::Local<v8::Object> pData; vp >> pData; return SetGlobalVariables(sPropName, JS_GLOBALDATA_TYPE_OBJECT, 0, false, "", pData, FALSE); @@ -246,7 +246,7 @@ void JSGlobalAlternate::UpdateGlobalPersistentVariables() { SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_NUMBER, pData->data.dData, false, "", v8::Local<v8::Object>(), pData->bPersistent == 1); - JS_PutObjectNumber(NULL, (JSFXObject)(*m_pJSObject), + JS_PutObjectNumber(NULL, (v8::Local<v8::Object>)(*m_pJSObject), pData->data.sKey.UTF8Decode().c_str(), pData->data.dData); break; @@ -254,7 +254,7 @@ void JSGlobalAlternate::UpdateGlobalPersistentVariables() { SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_BOOLEAN, 0, (bool)(pData->data.bData == 1), "", v8::Local<v8::Object>(), pData->bPersistent == 1); - JS_PutObjectBoolean(NULL, (JSFXObject)(*m_pJSObject), + JS_PutObjectBoolean(NULL, (v8::Local<v8::Object>)(*m_pJSObject), pData->data.sKey.UTF8Decode().c_str(), (bool)(pData->data.bData == 1)); break; @@ -262,27 +262,29 @@ void JSGlobalAlternate::UpdateGlobalPersistentVariables() { SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_STRING, 0, false, pData->data.sData, v8::Local<v8::Object>(), pData->bPersistent == 1); - JS_PutObjectString(NULL, (JSFXObject)(*m_pJSObject), + JS_PutObjectString(NULL, (v8::Local<v8::Object>)(*m_pJSObject), pData->data.sKey.UTF8Decode().c_str(), pData->data.sData.UTF8Decode().c_str()); break; case JS_GLOBALDATA_TYPE_OBJECT: { - IJS_Runtime* pRuntime = JS_GetRuntime((JSFXObject)(*m_pJSObject)); + v8::Isolate* pRuntime = + JS_GetRuntime((v8::Local<v8::Object>)(*m_pJSObject)); v8::Local<v8::Object> pObj = JS_NewFxDynamicObj(pRuntime, NULL, -1); PutObjectProperty(pObj, &pData->data); SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_OBJECT, 0, - false, "", (JSObject)pObj, pData->bPersistent == 1); - JS_PutObjectObject(NULL, (JSFXObject)(*m_pJSObject), + false, "", (v8::Local<v8::Object>)pObj, + pData->bPersistent == 1); + JS_PutObjectObject(NULL, (v8::Local<v8::Object>)(*m_pJSObject), pData->data.sKey.UTF8Decode().c_str(), - (JSObject)pObj); + (v8::Local<v8::Object>)pObj); } break; case JS_GLOBALDATA_TYPE_NULL: SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_NULL, 0, false, "", v8::Local<v8::Object>(), pData->bPersistent == 1); - JS_PutObjectNull(NULL, (JSFXObject)(*m_pJSObject), + JS_PutObjectNull(NULL, (v8::Local<v8::Object>)(*m_pJSObject), pData->data.sKey.UTF8Decode().c_str()); break; } @@ -398,30 +400,31 @@ void JSGlobalAlternate::PutObjectProperty(v8::Local<v8::Object> pObj, switch (pObjData->nType) { case JS_GLOBALDATA_TYPE_NUMBER: - JS_PutObjectNumber(NULL, (JSObject)pObj, + JS_PutObjectNumber(NULL, (v8::Local<v8::Object>)pObj, pObjData->sKey.UTF8Decode().c_str(), pObjData->dData); break; case JS_GLOBALDATA_TYPE_BOOLEAN: - JS_PutObjectBoolean(NULL, (JSObject)pObj, + JS_PutObjectBoolean(NULL, (v8::Local<v8::Object>)pObj, pObjData->sKey.UTF8Decode().c_str(), (bool)(pObjData->bData == 1)); break; case JS_GLOBALDATA_TYPE_STRING: - JS_PutObjectString(NULL, (JSObject)pObj, + JS_PutObjectString(NULL, (v8::Local<v8::Object>)pObj, pObjData->sKey.UTF8Decode().c_str(), pObjData->sData.UTF8Decode().c_str()); break; case JS_GLOBALDATA_TYPE_OBJECT: { - IJS_Runtime* pRuntime = JS_GetRuntime((JSFXObject)(*m_pJSObject)); + v8::Isolate* pRuntime = + JS_GetRuntime((v8::Local<v8::Object>)(*m_pJSObject)); v8::Local<v8::Object> pNewObj = JS_NewFxDynamicObj(pRuntime, NULL, -1); PutObjectProperty(pNewObj, pObjData); - JS_PutObjectObject(NULL, (JSObject)pObj, + JS_PutObjectObject(NULL, (v8::Local<v8::Object>)pObj, pObjData->sKey.UTF8Decode().c_str(), - (JSObject)pNewObj); + (v8::Local<v8::Object>)pNewObj); } break; case JS_GLOBALDATA_TYPE_NULL: - JS_PutObjectNull(NULL, (JSObject)pObj, + JS_PutObjectNull(NULL, (v8::Local<v8::Object>)pObj, pObjData->sKey.UTF8Decode().c_str()); break; } @@ -440,7 +443,7 @@ FX_BOOL JSGlobalAlternate::SetGlobalVariables(const FX_CHAR* propname, double dData, bool bData, const CFX_ByteString& sData, - JSObject pData, + v8::Local<v8::Object> pData, bool bDefaultPersistent) { if (!propname) return FALSE; diff --git a/fpdfsdk/src/jsapi/fxjs_v8.cpp b/fpdfsdk/src/jsapi/fxjs_v8.cpp index 1dd479aec6..b31284847a 100644 --- a/fpdfsdk/src/jsapi/fxjs_v8.cpp +++ b/fpdfsdk/src/jsapi/fxjs_v8.cpp @@ -75,37 +75,35 @@ class CJS_ObjDefintion { v8::Global<v8::Object> m_StaticObj; }; -int JS_DefineObj(IJS_Runtime* pJSRuntime, +int JS_DefineObj(v8::Isolate* pIsolate, const wchar_t* sObjName, FXJSOBJTYPE eObjType, LP_CONSTRUCTOR pConstructor, LP_DESTRUCTOR pDestructor) { - v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; - v8::Isolate::Scope isolate_scope(isolate); - v8::HandleScope handle_scope(isolate); - CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlot); + v8::Isolate::Scope isolate_scope(pIsolate); + v8::HandleScope handle_scope(pIsolate); + CFX_PtrArray* pArray = (CFX_PtrArray*)pIsolate->GetData(g_embedderDataSlot); if (!pArray) { pArray = new CFX_PtrArray(); - isolate->SetData(g_embedderDataSlot, pArray); + pIsolate->SetData(g_embedderDataSlot, pArray); } - CJS_ObjDefintion* pObjDef = new CJS_ObjDefintion(isolate, sObjName, eObjType, + CJS_ObjDefintion* pObjDef = new CJS_ObjDefintion(pIsolate, sObjName, eObjType, pConstructor, pDestructor); pArray->Add(pObjDef); return pArray->GetSize() - 1; } -int JS_DefineObjMethod(IJS_Runtime* pJSRuntime, +int JS_DefineObjMethod(v8::Isolate* pIsolate, int nObjDefnID, const wchar_t* sMethodName, v8::FunctionCallback pMethodCall) { - v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; - v8::Isolate::Scope isolate_scope(isolate); - v8::HandleScope handle_scope(isolate); + v8::Isolate::Scope isolate_scope(pIsolate); + v8::HandleScope handle_scope(pIsolate); CFX_WideString ws = CFX_WideString(sMethodName); CFX_ByteString bsMethodName = ws.UTF8Encode(); - CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlot); + CFX_PtrArray* pArray = (CFX_PtrArray*)pIsolate->GetData(g_embedderDataSlot); if (!pArray) return 0; @@ -113,28 +111,27 @@ int JS_DefineObjMethod(IJS_Runtime* pJSRuntime, return 0; CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID); v8::Local<v8::ObjectTemplate> objTemp = - v8::Local<v8::ObjectTemplate>::New(isolate, pObjDef->m_objTemplate); - objTemp->Set(v8::String::NewFromUtf8(isolate, bsMethodName.c_str(), - v8::NewStringType::kNormal) - .ToLocalChecked(), - v8::FunctionTemplate::New(isolate, pMethodCall), v8::ReadOnly); - pObjDef->m_objTemplate.Reset(isolate, objTemp); + v8::Local<v8::ObjectTemplate>::New(pIsolate, pObjDef->m_objTemplate); + objTemp->Set( + v8::String::NewFromUtf8(pIsolate, bsMethodName.c_str(), + v8::NewStringType::kNormal).ToLocalChecked(), + v8::FunctionTemplate::New(pIsolate, pMethodCall), v8::ReadOnly); + pObjDef->m_objTemplate.Reset(pIsolate, objTemp); return 0; } -int JS_DefineObjProperty(IJS_Runtime* pJSRuntime, +int JS_DefineObjProperty(v8::Isolate* pIsolate, int nObjDefnID, const wchar_t* sPropName, v8::AccessorGetterCallback pPropGet, v8::AccessorSetterCallback pPropPut) { - v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; - v8::Isolate::Scope isolate_scope(isolate); - v8::HandleScope handle_scope(isolate); + v8::Isolate::Scope isolate_scope(pIsolate); + v8::HandleScope handle_scope(pIsolate); CFX_WideString ws = CFX_WideString(sPropName); CFX_ByteString bsPropertyName = ws.UTF8Encode(); - CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlot); + CFX_PtrArray* pArray = (CFX_PtrArray*)pIsolate->GetData(g_embedderDataSlot); if (!pArray) return 0; @@ -142,26 +139,25 @@ int JS_DefineObjProperty(IJS_Runtime* pJSRuntime, return 0; CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID); v8::Local<v8::ObjectTemplate> objTemp = - v8::Local<v8::ObjectTemplate>::New(isolate, pObjDef->m_objTemplate); - objTemp->SetAccessor(v8::String::NewFromUtf8(isolate, bsPropertyName.c_str(), - v8::NewStringType::kNormal) - .ToLocalChecked(), - pPropGet, pPropPut); - pObjDef->m_objTemplate.Reset(isolate, objTemp); + v8::Local<v8::ObjectTemplate>::New(pIsolate, pObjDef->m_objTemplate); + objTemp->SetAccessor( + v8::String::NewFromUtf8(pIsolate, bsPropertyName.c_str(), + v8::NewStringType::kNormal).ToLocalChecked(), + pPropGet, pPropPut); + pObjDef->m_objTemplate.Reset(pIsolate, objTemp); return 0; } -int JS_DefineObjAllProperties(IJS_Runtime* pJSRuntime, +int JS_DefineObjAllProperties(v8::Isolate* pIsolate, int nObjDefnID, v8::NamedPropertyQueryCallback pPropQurey, v8::NamedPropertyGetterCallback pPropGet, v8::NamedPropertySetterCallback pPropPut, v8::NamedPropertyDeleterCallback pPropDel) { - v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; - v8::Isolate::Scope isolate_scope(isolate); - v8::HandleScope handle_scope(isolate); + v8::Isolate::Scope isolate_scope(pIsolate); + v8::HandleScope handle_scope(pIsolate); - CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlot); + CFX_PtrArray* pArray = (CFX_PtrArray*)pIsolate->GetData(g_embedderDataSlot); if (!pArray) return 0; @@ -169,21 +165,20 @@ int JS_DefineObjAllProperties(IJS_Runtime* pJSRuntime, return 0; CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID); v8::Local<v8::ObjectTemplate> objTemp = - v8::Local<v8::ObjectTemplate>::New(isolate, pObjDef->m_objTemplate); + v8::Local<v8::ObjectTemplate>::New(pIsolate, pObjDef->m_objTemplate); objTemp->SetNamedPropertyHandler(pPropGet, pPropPut, pPropQurey, pPropDel); - pObjDef->m_objTemplate.Reset(isolate, objTemp); + pObjDef->m_objTemplate.Reset(pIsolate, objTemp); return 0; } -int JS_DefineObjConst(IJS_Runtime* pJSRuntime, +int JS_DefineObjConst(v8::Isolate* pIsolate, int nObjDefnID, const wchar_t* sConstName, v8::Local<v8::Value> pDefault) { - v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; - v8::Isolate::Scope isolate_scope(isolate); - v8::HandleScope handle_scope(isolate); + v8::Isolate::Scope isolate_scope(pIsolate); + v8::HandleScope handle_scope(pIsolate); - CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlot); + CFX_PtrArray* pArray = (CFX_PtrArray*)pIsolate->GetData(g_embedderDataSlot); if (!pArray) return 0; @@ -194,19 +189,18 @@ int JS_DefineObjConst(IJS_Runtime* pJSRuntime, return 0; CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID); v8::Local<v8::ObjectTemplate> objTemp = - v8::Local<v8::ObjectTemplate>::New(isolate, pObjDef->m_objTemplate); - objTemp->Set(isolate, bsConstName.c_str(), pDefault); - pObjDef->m_objTemplate.Reset(isolate, objTemp); + v8::Local<v8::ObjectTemplate>::New(pIsolate, pObjDef->m_objTemplate); + objTemp->Set(pIsolate, bsConstName.c_str(), pDefault); + pObjDef->m_objTemplate.Reset(pIsolate, objTemp); return 0; } static v8::Global<v8::ObjectTemplate>& _getGlobalObjectTemplate( - IJS_Runtime* pJSRuntime) { - v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; - v8::Isolate::Scope isolate_scope(isolate); - v8::HandleScope handle_scope(isolate); + v8::Isolate* pIsolate) { + v8::Isolate::Scope isolate_scope(pIsolate); + v8::HandleScope handle_scope(pIsolate); - CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlot); + CFX_PtrArray* pArray = (CFX_PtrArray*)pIsolate->GetData(g_embedderDataSlot); ASSERT(pArray != NULL); for (int i = 0; i < pArray->GetSize(); i++) { CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(i); @@ -217,42 +211,40 @@ static v8::Global<v8::ObjectTemplate>& _getGlobalObjectTemplate( return gloabalObjectTemplate; } -int JS_DefineGlobalMethod(IJS_Runtime* pJSRuntime, +int JS_DefineGlobalMethod(v8::Isolate* pIsolate, const wchar_t* sMethodName, v8::FunctionCallback pMethodCall) { - v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; - v8::Isolate::Scope isolate_scope(isolate); - v8::HandleScope handle_scope(isolate); + v8::Isolate::Scope isolate_scope(pIsolate); + v8::HandleScope handle_scope(pIsolate); CFX_WideString ws = CFX_WideString(sMethodName); CFX_ByteString bsMethodName = ws.UTF8Encode(); v8::Local<v8::FunctionTemplate> funTempl = - v8::FunctionTemplate::New(isolate, pMethodCall); + v8::FunctionTemplate::New(pIsolate, pMethodCall); v8::Local<v8::ObjectTemplate> objTemp; v8::Global<v8::ObjectTemplate>& globalObjTemp = - _getGlobalObjectTemplate(pJSRuntime); + _getGlobalObjectTemplate(pIsolate); if (globalObjTemp.IsEmpty()) - objTemp = v8::ObjectTemplate::New(isolate); + objTemp = v8::ObjectTemplate::New(pIsolate); else - objTemp = v8::Local<v8::ObjectTemplate>::New(isolate, globalObjTemp); - objTemp->Set(v8::String::NewFromUtf8(isolate, bsMethodName.c_str(), - v8::NewStringType::kNormal) - .ToLocalChecked(), - funTempl, v8::ReadOnly); + objTemp = v8::Local<v8::ObjectTemplate>::New(pIsolate, globalObjTemp); + objTemp->Set( + v8::String::NewFromUtf8(pIsolate, bsMethodName.c_str(), + v8::NewStringType::kNormal).ToLocalChecked(), + funTempl, v8::ReadOnly); - globalObjTemp.Reset(isolate, objTemp); + globalObjTemp.Reset(pIsolate, objTemp); return 0; } -int JS_DefineGlobalConst(IJS_Runtime* pJSRuntime, +int JS_DefineGlobalConst(v8::Isolate* pIsolate, const wchar_t* sConstName, v8::Local<v8::Value> pDefault) { - v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; - v8::Isolate::Scope isolate_scope(isolate); - v8::HandleScope handle_scope(isolate); + v8::Isolate::Scope isolate_scope(pIsolate); + v8::HandleScope handle_scope(pIsolate); CFX_WideString ws = CFX_WideString(sConstName); CFX_ByteString bsConst = ws.UTF8Encode(); @@ -260,40 +252,39 @@ int JS_DefineGlobalConst(IJS_Runtime* pJSRuntime, v8::Local<v8::ObjectTemplate> objTemp; v8::Global<v8::ObjectTemplate>& globalObjTemp = - _getGlobalObjectTemplate(pJSRuntime); + _getGlobalObjectTemplate(pIsolate); if (globalObjTemp.IsEmpty()) - objTemp = v8::ObjectTemplate::New(isolate); + objTemp = v8::ObjectTemplate::New(pIsolate); else - objTemp = v8::Local<v8::ObjectTemplate>::New(isolate, globalObjTemp); - objTemp->Set(v8::String::NewFromUtf8(isolate, bsConst.c_str(), - v8::NewStringType::kNormal) - .ToLocalChecked(), - pDefault, v8::ReadOnly); + objTemp = v8::Local<v8::ObjectTemplate>::New(pIsolate, globalObjTemp); + objTemp->Set( + v8::String::NewFromUtf8(pIsolate, bsConst.c_str(), + v8::NewStringType::kNormal).ToLocalChecked(), + pDefault, v8::ReadOnly); - globalObjTemp.Reset(isolate, objTemp); + globalObjTemp.Reset(pIsolate, objTemp); return 0; } -void JS_InitialRuntime(IJS_Runtime* pJSRuntime, +void JS_InitialRuntime(v8::Isolate* pIsolate, IFXJS_Runtime* pFXRuntime, IFXJS_Context* context, v8::Global<v8::Context>& v8PersistentContext) { - v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; - v8::Isolate::Scope isolate_scope(isolate); - v8::HandleScope handle_scope(isolate); + v8::Isolate::Scope isolate_scope(pIsolate); + v8::HandleScope handle_scope(pIsolate); v8::Global<v8::ObjectTemplate>& globalObjTemp = - _getGlobalObjectTemplate(pJSRuntime); + _getGlobalObjectTemplate(pIsolate); v8::Local<v8::Context> v8Context = v8::Context::New( - isolate, NULL, - v8::Local<v8::ObjectTemplate>::New(isolate, globalObjTemp)); + pIsolate, NULL, + v8::Local<v8::ObjectTemplate>::New(pIsolate, globalObjTemp)); v8::Context::Scope context_scope(v8Context); - v8::Local<v8::External> ptr = v8::External::New(isolate, pFXRuntime); + v8::Local<v8::External> ptr = v8::External::New(pIsolate, pFXRuntime); v8Context->SetEmbedderData(1, ptr); - CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlot); + CFX_PtrArray* pArray = (CFX_PtrArray*)pIsolate->GetData(g_embedderDataSlot); if (!pArray) return; @@ -302,9 +293,9 @@ void JS_InitialRuntime(IJS_Runtime* pJSRuntime, CFX_WideString ws = CFX_WideString(pObjDef->objName); CFX_ByteString bs = ws.UTF8Encode(); v8::Local<v8::String> objName = - v8::String::NewFromUtf8(isolate, bs.c_str(), v8::NewStringType::kNormal, - bs.GetLength()) - .ToLocalChecked(); + v8::String::NewFromUtf8(pIsolate, bs.c_str(), + v8::NewStringType::kNormal, + bs.GetLength()).ToLocalChecked(); if (pObjDef->objType == JS_DYNAMIC) { // Document is set as global object, need to construct it first. @@ -329,24 +320,23 @@ void JS_InitialRuntime(IJS_Runtime* pJSRuntime, .ToLocalChecked()); } } else { - v8::Local<v8::Object> obj = JS_NewFxDynamicObj(pJSRuntime, context, i); + v8::Local<v8::Object> obj = JS_NewFxDynamicObj(pIsolate, context, i); v8Context->Global()->Set(v8Context, objName, obj).FromJust(); - pObjDef->m_StaticObj.Reset(isolate, obj); + pObjDef->m_StaticObj.Reset(pIsolate, obj); } } - v8PersistentContext.Reset(isolate, v8Context); + v8PersistentContext.Reset(pIsolate, v8Context); } -void JS_ReleaseRuntime(IJS_Runtime* pJSRuntime, +void JS_ReleaseRuntime(v8::Isolate* pIsolate, v8::Global<v8::Context>& v8PersistentContext) { - v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; - v8::Isolate::Scope isolate_scope(isolate); - v8::HandleScope handle_scope(isolate); + v8::Isolate::Scope isolate_scope(pIsolate); + v8::HandleScope handle_scope(pIsolate); v8::Local<v8::Context> context = - v8::Local<v8::Context>::New(isolate, v8PersistentContext); + v8::Local<v8::Context>::New(pIsolate, v8PersistentContext); v8::Context::Scope context_scope(context); - CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlot); + CFX_PtrArray* pArray = (CFX_PtrArray*)pIsolate->GetData(g_embedderDataSlot); if (!pArray) return; @@ -354,7 +344,7 @@ void JS_ReleaseRuntime(IJS_Runtime* pJSRuntime, CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(i); if (!pObjDef->m_StaticObj.IsEmpty()) { v8::Local<v8::Object> pObj = - v8::Local<v8::Object>::New(isolate, pObjDef->m_StaticObj); + v8::Local<v8::Object>::New(pIsolate, pObjDef->m_StaticObj); if (pObjDef->m_pDestructor) pObjDef->m_pDestructor(pObj); JS_FreePrivate(pObj); @@ -362,7 +352,7 @@ void JS_ReleaseRuntime(IJS_Runtime* pJSRuntime, delete pObjDef; } delete pArray; - isolate->SetData(g_embedderDataSlot, NULL); + pIsolate->SetData(g_embedderDataSlot, NULL); } void JS_Initial(unsigned int embedderDataSlot) { @@ -372,25 +362,23 @@ void JS_Initial(unsigned int embedderDataSlot) { void JS_Release() { } -int JS_Execute(IJS_Runtime* pJSRuntime, +int JS_Execute(v8::Isolate* pIsolate, IFXJS_Context* pJSContext, const wchar_t* script, long length, FXJSErr* perror) { - v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; - v8::Isolate::Scope isolate_scope(isolate); - v8::TryCatch try_catch(isolate); + v8::Isolate::Scope isolate_scope(pIsolate); + v8::TryCatch try_catch(pIsolate); CFX_WideString wsScript(script); CFX_ByteString bsScript = wsScript.UTF8Encode(); - v8::Local<v8::Context> context = isolate->GetCurrentContext(); + v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); v8::Local<v8::Script> compiled_script; - if (!v8::Script::Compile(context, - v8::String::NewFromUtf8(isolate, bsScript.c_str(), - v8::NewStringType::kNormal, - bsScript.GetLength()) - .ToLocalChecked()) + if (!v8::Script::Compile( + context, v8::String::NewFromUtf8( + pIsolate, bsScript.c_str(), v8::NewStringType::kNormal, + bsScript.GetLength()).ToLocalChecked()) .ToLocal(&compiled_script)) { v8::String::Utf8Value error(try_catch.Exception()); return -1; @@ -404,21 +392,20 @@ int JS_Execute(IJS_Runtime* pJSRuntime, return 0; } -v8::Local<v8::Object> JS_NewFxDynamicObj(IJS_Runtime* pJSRuntime, +v8::Local<v8::Object> JS_NewFxDynamicObj(v8::Isolate* pIsolate, IFXJS_Context* pJSContext, int nObjDefnID) { - v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; - v8::Isolate::Scope isolate_scope(isolate); - v8::Local<v8::Context> context = isolate->GetCurrentContext(); + v8::Isolate::Scope isolate_scope(pIsolate); + v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); if (-1 == nObjDefnID) { - v8::Local<v8::ObjectTemplate> objTempl = v8::ObjectTemplate::New(isolate); + v8::Local<v8::ObjectTemplate> objTempl = v8::ObjectTemplate::New(pIsolate); v8::Local<v8::Object> obj; if (objTempl->NewInstance(context).ToLocal(&obj)) return obj; return v8::Local<v8::Object>(); } - CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlot); + CFX_PtrArray* pArray = (CFX_PtrArray*)pIsolate->GetData(g_embedderDataSlot); if (!pArray) return v8::Local<v8::Object>(); @@ -427,7 +414,7 @@ v8::Local<v8::Object> JS_NewFxDynamicObj(IJS_Runtime* pJSRuntime, CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID); v8::Local<v8::ObjectTemplate> objTemp = - v8::Local<v8::ObjectTemplate>::New(isolate, pObjDef->m_objTemplate); + v8::Local<v8::ObjectTemplate>::New(pIsolate, pObjDef->m_objTemplate); v8::Local<v8::Object> obj; if (!objTemp->NewInstance(context).ToLocal(&obj)) return v8::Local<v8::Object>(); @@ -444,11 +431,9 @@ v8::Local<v8::Object> JS_NewFxDynamicObj(IJS_Runtime* pJSRuntime, return obj; } -v8::Local<v8::Object> JS_GetStaticObj(IJS_Runtime* pJSRuntime, int nObjDefnID) { - v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; - v8::Isolate::Scope isolate_scope(isolate); - - CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlot); +v8::Local<v8::Object> JS_GetStaticObj(v8::Isolate* pIsolate, int nObjDefnID) { + v8::Isolate::Scope isolate_scope(pIsolate); + CFX_PtrArray* pArray = (CFX_PtrArray*)pIsolate->GetData(g_embedderDataSlot); if (!pArray) return v8::Local<v8::Object>(); @@ -456,23 +441,18 @@ v8::Local<v8::Object> JS_GetStaticObj(IJS_Runtime* pJSRuntime, int nObjDefnID) { return v8::Local<v8::Object>(); CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID); v8::Local<v8::Object> obj = - v8::Local<v8::Object>::New(isolate, pObjDef->m_StaticObj); + v8::Local<v8::Object>::New(pIsolate, pObjDef->m_StaticObj); return obj; } -void JS_SetThisObj(IJS_Runtime* pJSRuntime, int nThisObjID) { - // Do nothing. -} -v8::Local<v8::Object> JS_GetThisObj(IJS_Runtime* pJSRuntime) { +v8::Local<v8::Object> JS_GetThisObj(v8::Isolate* pIsolate) { // Return the global object. - v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; - v8::Isolate::Scope isolate_scope(isolate); - - CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlot); + v8::Isolate::Scope isolate_scope(pIsolate); + CFX_PtrArray* pArray = (CFX_PtrArray*)pIsolate->GetData(g_embedderDataSlot); if (!pArray) return v8::Local<v8::Object>(); - v8::Local<v8::Context> context = isolate->GetCurrentContext(); + v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); return context->Global()->GetPrototype()->ToObject(context).ToLocalChecked(); } @@ -486,7 +466,7 @@ int JS_GetObjDefnID(v8::Local<v8::Object> pObj) { return -1; } -IJS_Runtime* JS_GetRuntime(v8::Local<v8::Object> pObj) { +v8::Isolate* JS_GetRuntime(v8::Local<v8::Object> pObj) { if (pObj.IsEmpty()) return NULL; v8::Local<v8::Context> context = pObj->CreationContext(); @@ -495,11 +475,9 @@ IJS_Runtime* JS_GetRuntime(v8::Local<v8::Object> pObj) { return context->GetIsolate(); } -int JS_GetObjDefnID(IJS_Runtime* pJSRuntime, const wchar_t* pObjName) { - v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; - v8::Isolate::Scope isolate_scope(isolate); - - CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlot); +int JS_GetObjDefnID(v8::Isolate* pIsolate, const wchar_t* pObjName) { + v8::Isolate::Scope isolate_scope(pIsolate); + CFX_PtrArray* pArray = (CFX_PtrArray*)pIsolate->GetData(g_embedderDataSlot); if (!pArray) return -1; @@ -511,14 +489,14 @@ int JS_GetObjDefnID(IJS_Runtime* pJSRuntime, const wchar_t* pObjName) { return -1; } -void JS_Error(v8::Isolate* isolate, const CFX_WideString& message) { +void JS_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 // intermediate format. CFX_ByteString utf8_message = message.UTF8Encode(); - isolate->ThrowException(v8::String::NewFromUtf8(isolate, utf8_message.c_str(), - v8::NewStringType::kNormal) - .ToLocalChecked()); + pIsolate->ThrowException( + v8::String::NewFromUtf8(pIsolate, utf8_message.c_str(), + v8::NewStringType::kNormal).ToLocalChecked()); } unsigned JS_CalcHash(const wchar_t* main, unsigned nLen) { @@ -555,9 +533,7 @@ void* JS_GetPrivate(v8::Local<v8::Object> pObj) { return JS_GetPrivate(NULL, pObj); } -void JS_SetPrivate(IJS_Runtime* pJSRuntime, - v8::Local<v8::Object> pObj, - void* p) { +void JS_SetPrivate(v8::Isolate* pIsolate, v8::Local<v8::Object> pObj, void* p) { if (pObj.IsEmpty() || !pObj->InternalFieldCount()) return; CJS_PrivateData* pPrivateData = @@ -567,7 +543,7 @@ void JS_SetPrivate(IJS_Runtime* pJSRuntime, pPrivateData->pPrivate = p; } -void* JS_GetPrivate(IJS_Runtime* pJSRuntime, v8::Local<v8::Object> pObj) { +void* JS_GetPrivate(v8::Isolate* pIsolate, v8::Local<v8::Object> pObj) { if (pObj.IsEmpty()) return NULL; CJS_PrivateData* pPrivateData = NULL; @@ -577,7 +553,7 @@ void* JS_GetPrivate(IJS_Runtime* pJSRuntime, v8::Local<v8::Object> pObj) { else { // It could be a global proxy object. v8::Local<v8::Value> v = pObj->GetPrototype(); - v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; + v8::Isolate* isolate = (v8::Isolate*)pIsolate; v8::Local<v8::Context> context = isolate->GetCurrentContext(); if (v->IsObject()) pPrivateData = (CJS_PrivateData*)v->ToObject(context) @@ -604,146 +580,132 @@ v8::Local<v8::Value> JS_GetObjectValue(v8::Local<v8::Object> pObj) { return pObj; } -v8::Local<v8::String> WSToJSString(IJS_Runtime* pJSRuntime, +v8::Local<v8::String> WSToJSString(v8::Isolate* pIsolate, const wchar_t* PropertyName, int Len = -1) { CFX_WideString ws = CFX_WideString(PropertyName, Len); CFX_ByteString bs = ws.UTF8Encode(); - if (!pJSRuntime) - pJSRuntime = v8::Isolate::GetCurrent(); - return v8::String::NewFromUtf8(pJSRuntime, bs.c_str(), - v8::NewStringType::kNormal) - .ToLocalChecked(); + if (!pIsolate) + pIsolate = v8::Isolate::GetCurrent(); + return v8::String::NewFromUtf8(pIsolate, bs.c_str(), + v8::NewStringType::kNormal).ToLocalChecked(); } -v8::Local<v8::Value> JS_GetObjectElement(IJS_Runtime* pJSRuntime, +v8::Local<v8::Value> JS_GetObjectElement(v8::Isolate* pIsolate, v8::Local<v8::Object> pObj, const wchar_t* PropertyName) { if (pObj.IsEmpty()) return v8::Local<v8::Value>(); v8::Local<v8::Value> val; - if (!pObj->Get(pJSRuntime->GetCurrentContext(), - WSToJSString(pJSRuntime, PropertyName)) - .ToLocal(&val)) + if (!pObj->Get(pIsolate->GetCurrentContext(), + WSToJSString(pIsolate, PropertyName)).ToLocal(&val)) return v8::Local<v8::Value>(); return val; } -v8::Local<v8::Array> JS_GetObjectElementNames(IJS_Runtime* pJSRuntime, +v8::Local<v8::Array> JS_GetObjectElementNames(v8::Isolate* pIsolate, v8::Local<v8::Object> pObj) { if (pObj.IsEmpty()) return v8::Local<v8::Array>(); v8::Local<v8::Array> val; - if (!pObj->GetPropertyNames(pJSRuntime->GetCurrentContext()).ToLocal(&val)) + if (!pObj->GetPropertyNames(pIsolate->GetCurrentContext()).ToLocal(&val)) return v8::Local<v8::Array>(); return val; } -void JS_PutObjectString(IJS_Runtime* pJSRuntime, +void JS_PutObjectString(v8::Isolate* pIsolate, v8::Local<v8::Object> pObj, const wchar_t* PropertyName, const wchar_t* sValue) // VT_string { if (pObj.IsEmpty()) return; - pObj->Set(pJSRuntime->GetCurrentContext(), - WSToJSString(pJSRuntime, PropertyName), - WSToJSString(pJSRuntime, sValue)) - .FromJust(); + pObj->Set(pIsolate->GetCurrentContext(), WSToJSString(pIsolate, PropertyName), + WSToJSString(pIsolate, sValue)).FromJust(); } -void JS_PutObjectNumber(IJS_Runtime* pJSRuntime, +void JS_PutObjectNumber(v8::Isolate* pIsolate, v8::Local<v8::Object> pObj, const wchar_t* PropertyName, int nValue) { if (pObj.IsEmpty()) return; - pObj->Set(pJSRuntime->GetCurrentContext(), - WSToJSString(pJSRuntime, PropertyName), - v8::Int32::New(pJSRuntime, nValue)) - .FromJust(); + pObj->Set(pIsolate->GetCurrentContext(), WSToJSString(pIsolate, PropertyName), + v8::Int32::New(pIsolate, nValue)).FromJust(); } -void JS_PutObjectNumber(IJS_Runtime* pJSRuntime, +void JS_PutObjectNumber(v8::Isolate* pIsolate, v8::Local<v8::Object> pObj, const wchar_t* PropertyName, float fValue) { if (pObj.IsEmpty()) return; - pObj->Set(pJSRuntime->GetCurrentContext(), - WSToJSString(pJSRuntime, PropertyName), - v8::Number::New(pJSRuntime, (double)fValue)) - .FromJust(); + pObj->Set(pIsolate->GetCurrentContext(), WSToJSString(pIsolate, PropertyName), + v8::Number::New(pIsolate, (double)fValue)).FromJust(); } -void JS_PutObjectNumber(IJS_Runtime* pJSRuntime, +void JS_PutObjectNumber(v8::Isolate* pIsolate, v8::Local<v8::Object> pObj, const wchar_t* PropertyName, double dValue) { if (pObj.IsEmpty()) return; - pObj->Set(pJSRuntime->GetCurrentContext(), - WSToJSString(pJSRuntime, PropertyName), - v8::Number::New(pJSRuntime, (double)dValue)) - .FromJust(); + pObj->Set(pIsolate->GetCurrentContext(), WSToJSString(pIsolate, PropertyName), + v8::Number::New(pIsolate, (double)dValue)).FromJust(); } -void JS_PutObjectBoolean(IJS_Runtime* pJSRuntime, +void JS_PutObjectBoolean(v8::Isolate* pIsolate, v8::Local<v8::Object> pObj, const wchar_t* PropertyName, bool bValue) { if (pObj.IsEmpty()) return; - pObj->Set(pJSRuntime->GetCurrentContext(), - WSToJSString(pJSRuntime, PropertyName), - v8::Boolean::New(pJSRuntime, bValue)) - .FromJust(); + pObj->Set(pIsolate->GetCurrentContext(), WSToJSString(pIsolate, PropertyName), + v8::Boolean::New(pIsolate, bValue)).FromJust(); } -void JS_PutObjectObject(IJS_Runtime* pJSRuntime, +void JS_PutObjectObject(v8::Isolate* pIsolate, v8::Local<v8::Object> pObj, const wchar_t* PropertyName, v8::Local<v8::Object> pPut) { if (pObj.IsEmpty()) return; - pObj->Set(pJSRuntime->GetCurrentContext(), - WSToJSString(pJSRuntime, PropertyName), pPut) - .FromJust(); + pObj->Set(pIsolate->GetCurrentContext(), WSToJSString(pIsolate, PropertyName), + pPut).FromJust(); } -void JS_PutObjectNull(IJS_Runtime* pJSRuntime, +void JS_PutObjectNull(v8::Isolate* pIsolate, v8::Local<v8::Object> pObj, const wchar_t* PropertyName) { if (pObj.IsEmpty()) return; - pObj->Set(pJSRuntime->GetCurrentContext(), - WSToJSString(pJSRuntime, PropertyName), v8::Local<v8::Object>()) - .FromJust(); + pObj->Set(pIsolate->GetCurrentContext(), WSToJSString(pIsolate, PropertyName), + v8::Local<v8::Object>()).FromJust(); } -v8::Local<v8::Array> JS_NewArray(IJS_Runtime* pJSRuntime) { - return v8::Array::New(pJSRuntime); +v8::Local<v8::Array> JS_NewArray(v8::Isolate* pIsolate) { + return v8::Array::New(pIsolate); } -unsigned JS_PutArrayElement(IJS_Runtime* pJSRuntime, +unsigned JS_PutArrayElement(v8::Isolate* pIsolate, v8::Local<v8::Array> pArray, unsigned index, v8::Local<v8::Value> pValue, FXJSVALUETYPE eType) { if (pArray.IsEmpty()) return 0; - if (pArray->Set(pJSRuntime->GetCurrentContext(), index, pValue).IsNothing()) + if (pArray->Set(pIsolate->GetCurrentContext(), index, pValue).IsNothing()) return 0; return 1; } -v8::Local<v8::Value> JS_GetArrayElement(IJS_Runtime* pJSRuntime, +v8::Local<v8::Value> JS_GetArrayElement(v8::Isolate* pIsolate, v8::Local<v8::Array> pArray, unsigned index) { if (pArray.IsEmpty()) return v8::Local<v8::Value>(); v8::Local<v8::Value> val; - if (!pArray->Get(pJSRuntime->GetCurrentContext(), index).ToLocal(&val)) + if (!pArray->Get(pIsolate->GetCurrentContext(), index).ToLocal(&val)) return v8::Local<v8::Value>(); return val; } @@ -754,63 +716,63 @@ unsigned JS_GetArrayLength(v8::Local<v8::Array> pArray) { return pArray->Length(); } -v8::Local<v8::Value> JS_NewNumber(IJS_Runtime* pJSRuntime, int number) { - return v8::Int32::New(pJSRuntime, number); +v8::Local<v8::Value> JS_NewNumber(v8::Isolate* pIsolate, int number) { + return v8::Int32::New(pIsolate, number); } -v8::Local<v8::Value> JS_NewNumber(IJS_Runtime* pJSRuntime, double number) { - return v8::Number::New(pJSRuntime, number); +v8::Local<v8::Value> JS_NewNumber(v8::Isolate* pIsolate, double number) { + return v8::Number::New(pIsolate, number); } -v8::Local<v8::Value> JS_NewNumber(IJS_Runtime* pJSRuntime, float number) { - return v8::Number::New(pJSRuntime, (float)number); +v8::Local<v8::Value> JS_NewNumber(v8::Isolate* pIsolate, float number) { + return v8::Number::New(pIsolate, (float)number); } -v8::Local<v8::Value> JS_NewBoolean(IJS_Runtime* pJSRuntime, bool b) { - return v8::Boolean::New(pJSRuntime, b); +v8::Local<v8::Value> JS_NewBoolean(v8::Isolate* pIsolate, bool b) { + return v8::Boolean::New(pIsolate, b); } -v8::Local<v8::Value> JS_NewObject(IJS_Runtime* pJSRuntime, +v8::Local<v8::Value> JS_NewObject(v8::Isolate* pIsolate, v8::Local<v8::Object> pObj) { if (pObj.IsEmpty()) return v8::Local<v8::Value>(); return pObj->Clone(); } -v8::Local<v8::Value> JS_NewObject2(IJS_Runtime* pJSRuntime, +v8::Local<v8::Value> JS_NewObject2(v8::Isolate* pIsolate, v8::Local<v8::Array> pObj) { if (pObj.IsEmpty()) return v8::Local<v8::Value>(); return pObj->Clone(); } -v8::Local<v8::Value> JS_NewString(IJS_Runtime* pJSRuntime, +v8::Local<v8::Value> JS_NewString(v8::Isolate* pIsolate, const wchar_t* string) { - return WSToJSString(pJSRuntime, string); + return WSToJSString(pIsolate, string); } -v8::Local<v8::Value> JS_NewString(IJS_Runtime* pJSRuntime, +v8::Local<v8::Value> JS_NewString(v8::Isolate* pIsolate, const wchar_t* string, unsigned nLen) { - return WSToJSString(pJSRuntime, string, nLen); + return WSToJSString(pIsolate, string, nLen); } v8::Local<v8::Value> JS_NewNull() { return v8::Local<v8::Value>(); } -v8::Local<v8::Value> JS_NewDate(IJS_Runtime* pJSRuntime, double d) { - return v8::Date::New(pJSRuntime->GetCurrentContext(), d).ToLocalChecked(); +v8::Local<v8::Value> JS_NewDate(v8::Isolate* pIsolate, double d) { + return v8::Date::New(pIsolate->GetCurrentContext(), d).ToLocalChecked(); } -v8::Local<v8::Value> JS_NewValue(IJS_Runtime* pJSRuntime) { +v8::Local<v8::Value> JS_NewValue(v8::Isolate* pIsolate) { return v8::Local<v8::Value>(); } -v8::Local<v8::Value> JS_GetListValue(IJS_Runtime* pJSRuntime, +v8::Local<v8::Value> JS_GetListValue(v8::Isolate* pIsolate, v8::Local<v8::Value> pList, int index) { - v8::Local<v8::Context> context = pJSRuntime->GetCurrentContext(); + v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); if (!pList.IsEmpty() && pList->IsObject()) { v8::Local<v8::Object> obj; if (pList->ToObject(context).ToLocal(&obj)) { @@ -822,49 +784,48 @@ v8::Local<v8::Value> JS_GetListValue(IJS_Runtime* pJSRuntime, return v8::Local<v8::Value>(); } -int JS_ToInt32(IJS_Runtime* pJSRuntime, v8::Local<v8::Value> pValue) { +int JS_ToInt32(v8::Isolate* pIsolate, v8::Local<v8::Value> pValue) { if (pValue.IsEmpty()) return 0; - v8::Local<v8::Context> context = pJSRuntime->GetCurrentContext(); + v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); return pValue->ToInt32(context).ToLocalChecked()->Value(); } -bool JS_ToBoolean(IJS_Runtime* pJSRuntime, v8::Local<v8::Value> pValue) { +bool JS_ToBoolean(v8::Isolate* pIsolate, v8::Local<v8::Value> pValue) { if (pValue.IsEmpty()) return false; - v8::Local<v8::Context> context = pJSRuntime->GetCurrentContext(); + v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); return pValue->ToBoolean(context).ToLocalChecked()->Value(); } -double JS_ToNumber(IJS_Runtime* pJSRuntime, v8::Local<v8::Value> pValue) { +double JS_ToNumber(v8::Isolate* pIsolate, v8::Local<v8::Value> pValue) { if (pValue.IsEmpty()) return 0.0; - v8::Local<v8::Context> context = pJSRuntime->GetCurrentContext(); + v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); return pValue->ToNumber(context).ToLocalChecked()->Value(); } -v8::Local<v8::Object> JS_ToObject(IJS_Runtime* pJSRuntime, +v8::Local<v8::Object> JS_ToObject(v8::Isolate* pIsolate, v8::Local<v8::Value> pValue) { if (pValue.IsEmpty()) return v8::Local<v8::Object>(); - v8::Local<v8::Context> context = pJSRuntime->GetCurrentContext(); + v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); return pValue->ToObject(context).ToLocalChecked(); } -CFX_WideString JS_ToString(IJS_Runtime* pJSRuntime, - v8::Local<v8::Value> pValue) { +CFX_WideString JS_ToString(v8::Isolate* pIsolate, v8::Local<v8::Value> pValue) { if (pValue.IsEmpty()) return L""; - v8::Local<v8::Context> context = pJSRuntime->GetCurrentContext(); + v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); v8::String::Utf8Value s(pValue->ToString(context).ToLocalChecked()); return CFX_WideString::FromUTF8(*s, s.length()); } -v8::Local<v8::Array> JS_ToArray(IJS_Runtime* pJSRuntime, +v8::Local<v8::Array> JS_ToArray(v8::Isolate* pIsolate, v8::Local<v8::Value> pValue) { if (pValue.IsEmpty()) return v8::Local<v8::Array>(); - v8::Local<v8::Context> context = pJSRuntime->GetCurrentContext(); + v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); return v8::Local<v8::Array>::Cast(pValue->ToObject(context).ToLocalChecked()); } |