diff options
author | Oliver Chang <ochang@chromium.org> | 2016-04-05 12:22:19 -0700 |
---|---|---|
committer | Oliver Chang <ochang@chromium.org> | 2016-04-05 12:22:19 -0700 |
commit | f268cc9b8f4610acd22684ced01150e67c737fe7 (patch) | |
tree | f90ee09c1d9476fed6a569a7fe937de6f0113a40 | |
parent | 13789cc6b1e8c19889ba81191be8ceba1172fda7 (diff) | |
download | pdfium-f268cc9b8f4610acd22684ced01150e67c737fe7.tar.xz |
Merge to M50: Re-land "Only place primitive objects on the V8 global template."
This reverts commit 1a35d55dd6b0d1ea1918e2d6a6c25faf599ba168.
Prevent handles from being destructed after v8 is gone.
BUG=pdfium:419,600777
Original Review URL: https://codereview.chromium.org/1761073006 .
(cherry picked from commit 297b515e3d53095e36991480a194b54ce887757b)
R=tsepez@chromium.org
Review URL: https://codereview.chromium.org/1861813002 .
-rw-r--r-- | fpdfsdk/include/jsapi/fxjs_v8.h | 2 | ||||
-rw-r--r-- | fpdfsdk/src/javascript/Consts.cpp | 273 | ||||
-rw-r--r-- | fpdfsdk/src/javascript/JS_Runtime.cpp | 10 | ||||
-rw-r--r-- | fpdfsdk/src/javascript/JS_Runtime.h | 4 | ||||
-rw-r--r-- | fpdfsdk/src/jsapi/fxjs_v8.cpp | 11 |
5 files changed, 113 insertions, 187 deletions
diff --git a/fpdfsdk/include/jsapi/fxjs_v8.h b/fpdfsdk/include/jsapi/fxjs_v8.h index 4ec1c331e5..bb8a7382d4 100644 --- a/fpdfsdk/include/jsapi/fxjs_v8.h +++ b/fpdfsdk/include/jsapi/fxjs_v8.h @@ -189,7 +189,7 @@ void FXJS_DefineGlobalMethod(v8::Isolate* pIsolate, v8::FunctionCallback pMethodCall); void FXJS_DefineGlobalConst(v8::Isolate* pIsolate, const wchar_t* sConstName, - v8::Local<v8::Value> pDefault); + v8::FunctionCallback pConstGetter); // Called after FXJS_Define* calls made. void FXJS_InitializeRuntime( diff --git a/fpdfsdk/src/javascript/Consts.cpp b/fpdfsdk/src/javascript/Consts.cpp index 261f8257a8..b7cc2d0a46 100644 --- a/fpdfsdk/src/javascript/Consts.cpp +++ b/fpdfsdk/src/javascript/Consts.cpp @@ -11,8 +11,6 @@ #include "fpdfsdk/src/javascript/JS_Object.h" #include "fpdfsdk/src/javascript/JS_Value.h" -/* ------------------------------ border ------------------------------ */ - BEGIN_JS_STATIC_CONST(CJS_Border) JS_STATIC_CONST_ENTRY_STRING(L"s", L"solid") JS_STATIC_CONST_ENTRY_STRING(L"b", L"beveled") @@ -20,22 +18,16 @@ JS_STATIC_CONST_ENTRY_STRING(L"d", L"dashed") JS_STATIC_CONST_ENTRY_STRING(L"i", L"inset") JS_STATIC_CONST_ENTRY_STRING(L"u", L"underline") END_JS_STATIC_CONST() - IMPLEMENT_JS_CLASS_CONST(CJS_Border, border) -/* ------------------------------ display ------------------------------ */ - BEGIN_JS_STATIC_CONST(CJS_Display) JS_STATIC_CONST_ENTRY_NUMBER(L"visible", 0) JS_STATIC_CONST_ENTRY_NUMBER(L"hidden", 1) JS_STATIC_CONST_ENTRY_NUMBER(L"noPrint", 2) JS_STATIC_CONST_ENTRY_NUMBER(L"noView", 3) END_JS_STATIC_CONST() - IMPLEMENT_JS_CLASS_CONST(CJS_Display, display) -/* ------------------------------ font ------------------------------ */ - BEGIN_JS_STATIC_CONST(CJS_Font) JS_STATIC_CONST_ENTRY_STRING(L"Times", L"Times-Roman") JS_STATIC_CONST_ENTRY_STRING(L"TimesB", L"Times-Bold") @@ -52,22 +44,16 @@ JS_STATIC_CONST_ENTRY_STRING(L"CourBI", L"Courier-BoldOblique") JS_STATIC_CONST_ENTRY_STRING(L"Symbol", L"Symbol") JS_STATIC_CONST_ENTRY_STRING(L"ZapfD", L"ZapfDingbats") END_JS_STATIC_CONST() - IMPLEMENT_JS_CLASS_CONST(CJS_Font, font) -/* ------------------------------ highlight ------------------------------ */ - BEGIN_JS_STATIC_CONST(CJS_Highlight) JS_STATIC_CONST_ENTRY_STRING(L"n", L"none") JS_STATIC_CONST_ENTRY_STRING(L"i", L"invert") JS_STATIC_CONST_ENTRY_STRING(L"p", L"push") JS_STATIC_CONST_ENTRY_STRING(L"o", L"outline") END_JS_STATIC_CONST() - IMPLEMENT_JS_CLASS_CONST(CJS_Highlight, highlight) -/* ------------------------------ position ------------------------------ */ - BEGIN_JS_STATIC_CONST(CJS_Position) JS_STATIC_CONST_ENTRY_NUMBER(L"textOnly", 0) JS_STATIC_CONST_ENTRY_NUMBER(L"iconOnly", 1) @@ -77,31 +63,22 @@ JS_STATIC_CONST_ENTRY_NUMBER(L"iconTextH", 4) JS_STATIC_CONST_ENTRY_NUMBER(L"textIconH", 5) JS_STATIC_CONST_ENTRY_NUMBER(L"overlay", 6) END_JS_STATIC_CONST() - IMPLEMENT_JS_CLASS_CONST(CJS_Position, position) -/* ------------------------------ scaleHow ------------------------------ */ - BEGIN_JS_STATIC_CONST(CJS_ScaleHow) JS_STATIC_CONST_ENTRY_NUMBER(L"proportional", 0) JS_STATIC_CONST_ENTRY_NUMBER(L"anamorphic", 1) END_JS_STATIC_CONST() - IMPLEMENT_JS_CLASS_CONST(CJS_ScaleHow, scaleHow) -/* ------------------------------ scaleWhen ------------------------------ */ - BEGIN_JS_STATIC_CONST(CJS_ScaleWhen) JS_STATIC_CONST_ENTRY_NUMBER(L"always", 0) JS_STATIC_CONST_ENTRY_NUMBER(L"never", 1) JS_STATIC_CONST_ENTRY_NUMBER(L"tooBig", 2) JS_STATIC_CONST_ENTRY_NUMBER(L"tooSmall", 3) END_JS_STATIC_CONST() - IMPLEMENT_JS_CLASS_CONST(CJS_ScaleWhen, scaleWhen) -/* ------------------------------ style ------------------------------ */ - BEGIN_JS_STATIC_CONST(CJS_Style) JS_STATIC_CONST_ENTRY_STRING(L"ch", L"check") JS_STATIC_CONST_ENTRY_STRING(L"cr", L"cross") @@ -110,11 +87,8 @@ JS_STATIC_CONST_ENTRY_STRING(L"ci", L"circle") JS_STATIC_CONST_ENTRY_STRING(L"st", L"star") JS_STATIC_CONST_ENTRY_STRING(L"sq", L"square") END_JS_STATIC_CONST() - IMPLEMENT_JS_CLASS_CONST(CJS_Style, style) -/* ------------------------------ zoomtype ------------------------------ */ - BEGIN_JS_STATIC_CONST(CJS_Zoomtype) JS_STATIC_CONST_ENTRY_STRING(L"none", L"NoVary") JS_STATIC_CONST_ENTRY_STRING(L"fitP", L"FitPage") @@ -124,172 +98,109 @@ JS_STATIC_CONST_ENTRY_STRING(L"fitV", L"FitVisibleWidth") JS_STATIC_CONST_ENTRY_STRING(L"pref", L"Preferred") JS_STATIC_CONST_ENTRY_STRING(L"refW", L"ReflowWidth") END_JS_STATIC_CONST() - IMPLEMENT_JS_CLASS_CONST(CJS_Zoomtype, zoomtype) -/* ------------------------------ CJS_GlobalConsts ------------------------- */ - -static void DefineGlobalConstString(CJS_Runtime* pRuntime, - const wchar_t* pConstName, - const wchar_t* pValue) { - FXJS_DefineGlobalConst(pRuntime->GetIsolate(), pConstName, - FXJS_NewString(pRuntime->GetIsolate(), pValue)); -} +#define GLOBAL_STRING(rt, name, value) \ + FXJS_DefineGlobalConst( \ + (rt)->GetIsolate(), (name), \ + [](const v8::FunctionCallbackInfo<v8::Value>& info) { \ + info.GetReturnValue().Set(FXJS_NewString(info.GetIsolate(), (value))); \ + }) void CJS_GlobalConsts::DefineJSObjects(CJS_Runtime* pRuntime) { - DefineGlobalConstString( - pRuntime, L"IDS_GREATER_THAN", - L"Invalid value: must be greater than or equal to % s."); - DefineGlobalConstString( - pRuntime, L"IDS_GT_AND_LT", - L"Invalid value: must be greater than or equal to % s " - L"and less than or equal to % s."); - DefineGlobalConstString(pRuntime, L"IDS_LESS_THAN", - L"Invalid value: must be less than or equal to % s."); - DefineGlobalConstString(pRuntime, L"IDS_INVALID_MONTH", L"**Invalid**"); - DefineGlobalConstString( - pRuntime, L"IDS_INVALID_DATE", - L"Invalid date / time: please ensure that the date / time exists.Field"); - DefineGlobalConstString( - pRuntime, L"IDS_INVALID_VALUE", - L"The value entered does not match the format of the field"); - DefineGlobalConstString(pRuntime, L"IDS_AM", L"am"); - DefineGlobalConstString(pRuntime, L"IDS_PM", L"pm"); - DefineGlobalConstString( - pRuntime, L"IDS_MONTH_INFO", - L"January[1] February[2] March[3] April[4] May[5] " - L"June[6] July[7] August[8] September[9] October[10] " - L"November[11] December[12] Sept[9] Jan[1] Feb[2] Mar[3] " - L"Apr[4] Jun[6] Jul[7] Aug[8] Sep[9] Oct[10] Nov[11] " - L"Dec[12]"); - DefineGlobalConstString(pRuntime, L"IDS_STARTUP_CONSOLE_MSG", L"** ^ _ ^ **"); -} - -/* ------------------------------ CJS_GlobalArrays ------------------------ */ + GLOBAL_STRING(pRuntime, L"IDS_GREATER_THAN", + L"Invalid value: must be greater than or equal to % s."); -void DefineGlobalConstStringArray(CJS_Runtime* pRuntime, - const wchar_t* sConstName, - const wchar_t** pValues, - size_t nValues) { - CJS_Array array(pRuntime); - for (size_t i = 0; i < nValues; ++i) { - array.SetElement(i, CJS_Value(pRuntime, pValues[i])); - } - CJS_PropValue prop(pRuntime); - prop << array; - FXJS_DefineGlobalConst(pRuntime->GetIsolate(), sConstName, prop.ToV8Value()); -} - -void CJS_GlobalArrays::DefineJSObjects(CJS_Runtime* pRuntime) { - { - const FX_WCHAR* ArrayName = L"RE_NUMBER_ENTRY_DOT_SEP"; - const FX_WCHAR* ArrayContent[] = {L"[+-]?\\d*\\.?\\d*"}; - DefineGlobalConstStringArray(pRuntime, ArrayName, ArrayContent, - FX_ArraySize(ArrayContent)); - } - - { - const FX_WCHAR* ArrayName = L"RE_NUMBER_COMMIT_DOT_SEP"; - const FX_WCHAR* ArrayContent[] = { - L"[+-]?\\d+(\\.\\d+)?", /* -1.0 or -1 */ - L"[+-]?\\.\\d+", /* -.1 */ - L"[+-]?\\d+\\." /* -1. */ - }; - DefineGlobalConstStringArray(pRuntime, ArrayName, ArrayContent, - FX_ArraySize(ArrayContent)); - } - - { - const FX_WCHAR* ArrayName = L"RE_NUMBER_ENTRY_COMMA_SEP"; - const FX_WCHAR* ArrayContent[] = {L"[+-]?\\d*,?\\d*"}; - - DefineGlobalConstStringArray(pRuntime, ArrayName, ArrayContent, - FX_ArraySize(ArrayContent)); - } - - { - const FX_WCHAR* ArrayName = L"RE_NUMBER_COMMIT_COMMA_SEP"; - const FX_WCHAR* ArrayContent[] = { - L"[+-]?\\d+([.,]\\d+)?", /* -1,0 or -1 */ - L"[+-]?[.,]\\d+", /* -,1 */ - L"[+-]?\\d+[.,]" /* -1, */ - }; - DefineGlobalConstStringArray(pRuntime, ArrayName, ArrayContent, - FX_ArraySize(ArrayContent)); - } + GLOBAL_STRING(pRuntime, L"IDS_GT_AND_LT", + L"Invalid value: must be greater than or equal to % s " + L"and less than or equal to % s."); - { - const FX_WCHAR* ArrayName = L"RE_ZIP_ENTRY"; - const FX_WCHAR* ArrayContent[] = {L"\\d{0,5}"}; - DefineGlobalConstStringArray(pRuntime, ArrayName, ArrayContent, - FX_ArraySize(ArrayContent)); - } - - { - const FX_WCHAR* ArrayName = L"RE_ZIP_COMMIT"; - const FX_WCHAR* ArrayContent[] = {L"\\d{5}"}; - DefineGlobalConstStringArray(pRuntime, ArrayName, ArrayContent, - FX_ArraySize(ArrayContent)); - } + GLOBAL_STRING(pRuntime, L"IDS_LESS_THAN", + L"Invalid value: must be less than or equal to % s."); - { - const FX_WCHAR* ArrayName = L"RE_ZIP4_ENTRY"; - const FX_WCHAR* ArrayContent[] = {L"\\d{0,5}(\\.|[- ])?\\d{0,4}"}; - DefineGlobalConstStringArray(pRuntime, ArrayName, ArrayContent, - FX_ArraySize(ArrayContent)); - } + GLOBAL_STRING(pRuntime, L"IDS_INVALID_MONTH", L"**Invalid**"); + GLOBAL_STRING( + pRuntime, L"IDS_INVALID_DATE", + L"Invalid date / time: please ensure that the date / time exists.Field"); - { - const FX_WCHAR* ArrayName = L"RE_ZIP4_COMMIT"; - const FX_WCHAR* ArrayContent[] = {L"\\d{5}(\\.|[- ])?\\d{4}"}; - DefineGlobalConstStringArray(pRuntime, ArrayName, ArrayContent, - FX_ArraySize(ArrayContent)); - } + GLOBAL_STRING(pRuntime, L"IDS_INVALID_VALUE", + L"The value entered does not match the format of the field"); - { - const FX_WCHAR* ArrayName = L"RE_PHONE_ENTRY"; - const FX_WCHAR* ArrayContent[] = { - L"\\d{0,3}(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}", /* 555-1234 or 408 - 555-1234 */ - L"\\(\\d{0,3}", /* (408 */ - L"\\(\\d{0,3}\\)(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}", /* (408) - 555-1234 */ - /* (allow the addition of parens as an afterthought) */ - L"\\(\\d{0,3}(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}", /* (408 555-1234 - */ - L"\\d{0,3}\\)(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}", /* 408) 555-1234 - */ - L"011(\\.|[- \\d])*" /* international */ - }; - DefineGlobalConstStringArray(pRuntime, ArrayName, ArrayContent, - FX_ArraySize(ArrayContent)); - } + GLOBAL_STRING(pRuntime, L"IDS_AM", L"am"); + GLOBAL_STRING(pRuntime, L"IDS_PM", L"pm"); + GLOBAL_STRING(pRuntime, L"IDS_MONTH_INFO", + L"January[1] February[2] March[3] April[4] May[5] " + L"June[6] July[7] August[8] September[9] October[10] " + L"November[11] December[12] Sept[9] Jan[1] Feb[2] Mar[3] " + L"Apr[4] Jun[6] Jul[7] Aug[8] Sep[9] Oct[10] Nov[11] " + L"Dec[12]"); - { - const FX_WCHAR* ArrayName = L"RE_PHONE_COMMIT"; - const FX_WCHAR* ArrayContent[] = { - L"\\d{3}(\\.|[- ])?\\d{4}", /* 555-1234 */ - L"\\d{3}(\\.|[- ])?\\d{3}(\\.|[- ])?\\d{4}", /* 408 555-1234 */ - L"\\(\\d{3}\\)(\\.|[- ])?\\d{3}(\\.|[- ])?\\d{4}", /* (408) 555-1234 */ - L"011(\\.|[- \\d])*" /* international */ - }; - DefineGlobalConstStringArray(pRuntime, ArrayName, ArrayContent, - FX_ArraySize(ArrayContent)); - } + GLOBAL_STRING(pRuntime, L"IDS_STARTUP_CONSOLE_MSG", L"** ^ _ ^ **"); +} - { - const FX_WCHAR* ArrayName = L"RE_SSN_ENTRY"; - const FX_WCHAR* ArrayContent[] = { - L"\\d{0,3}(\\.|[- ])?\\d{0,2}(\\.|[- ])?\\d{0,4}"}; - DefineGlobalConstStringArray(pRuntime, ArrayName, ArrayContent, - FX_ArraySize(ArrayContent)); +#define GLOBAL_ARRAY(rt, name, ...) \ + { \ + const FX_WCHAR* values[] = {__VA_ARGS__}; \ + v8::Local<v8::Array> array = FXJS_NewArray((rt)->GetIsolate()); \ + for (size_t i = 0; i < FX_ArraySize(values); ++i) \ + array->Set(i, FXJS_NewString((rt)->GetIsolate(), values[i])); \ + rt->SetConstArray(name, array); \ + FXJS_DefineGlobalConst( \ + (rt)->GetIsolate(), (name), \ + [](const v8::FunctionCallbackInfo<v8::Value>& info) { \ + CJS_Runtime* pRuntime = static_cast<CJS_Runtime*>( \ + FXJS_GetRuntimeFromIsolate(info.GetIsolate())); \ + if (pRuntime) \ + info.GetReturnValue().Set(pRuntime->GetConstArray(name)); \ + }); \ } - { - const FX_WCHAR* ArrayName = L"RE_SSN_COMMIT"; - const FX_WCHAR* ArrayContent[] = { - L"\\d{3}(\\.|[- ])?\\d{2}(\\.|[- ])?\\d{4}"}; - DefineGlobalConstStringArray(pRuntime, ArrayName, ArrayContent, - FX_ArraySize(ArrayContent)); - } +void CJS_GlobalArrays::DefineJSObjects(CJS_Runtime* pRuntime) { + GLOBAL_ARRAY(pRuntime, L"RE_NUMBER_ENTRY_DOT_SEP", L"[+-]?\\d*\\.?\\d*"); + GLOBAL_ARRAY(pRuntime, L"RE_NUMBER_COMMIT_DOT_SEP", + L"[+-]?\\d+(\\.\\d+)?", // -1.0 or -1 + L"[+-]?\\.\\d+", // -.1 + L"[+-]?\\d+\\."); // -1. + + GLOBAL_ARRAY(pRuntime, L"RE_NUMBER_ENTRY_COMMA_SEP", L"[+-]?\\d*,?\\d*"); + GLOBAL_ARRAY(pRuntime, L"RE_NUMBER_COMMIT_COMMA_SEP", + L"[+-]?\\d+([.,]\\d+)?", // -1,0 or -1 + L"[+-]?[.,]\\d+", // -,1 + L"[+-]?\\d+[.,]"); // -1, + + GLOBAL_ARRAY(pRuntime, L"RE_ZIP_ENTRY", L"\\d{0,5}"); + GLOBAL_ARRAY(pRuntime, L"RE_ZIP_COMMIT", L"\\d{5}"); + GLOBAL_ARRAY(pRuntime, L"RE_ZIP4_ENTRY", L"\\d{0,5}(\\.|[- ])?\\d{0,4}"); + GLOBAL_ARRAY(pRuntime, L"RE_ZIP4_COMMIT", L"\\d{5}(\\.|[- ])?\\d{4}"); + GLOBAL_ARRAY(pRuntime, L"RE_PHONE_ENTRY", + // 555-1234 or 408 555-1234 + L"\\d{0,3}(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}", + + // (408 + L"\\(\\d{0,3}", + + // (408) 555-1234 + // (allow the addition of parens as an afterthought) + L"\\(\\d{0,3}\\)(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}", + + // (408 555-1234 + L"\\(\\d{0,3}(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}", + + // 408) 555-1234 + L"\\d{0,3}\\)(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}", + + // international + L"011(\\.|[- \\d])*"); + + GLOBAL_ARRAY( + pRuntime, L"RE_PHONE_COMMIT", L"\\d{3}(\\.|[- ])?\\d{4}", // 555-1234 + L"\\d{3}(\\.|[- ])?\\d{3}(\\.|[- ])?\\d{4}", // 408 555-1234 + L"\\(\\d{3}\\)(\\.|[- ])?\\d{3}(\\.|[- ])?\\d{4}", // (408) 555-1234 + L"011(\\.|[- \\d])*"); // international + + GLOBAL_ARRAY(pRuntime, L"RE_SSN_ENTRY", + L"\\d{0,3}(\\.|[- ])?\\d{0,2}(\\.|[- ])?\\d{0,4}"); + + GLOBAL_ARRAY(pRuntime, L"RE_SSN_COMMIT", + L"\\d{3}(\\.|[- ])?\\d{2}(\\.|[- ])?\\d{4}"); } diff --git a/fpdfsdk/src/javascript/JS_Runtime.cpp b/fpdfsdk/src/javascript/JS_Runtime.cpp index 76221db3f2..88696e5110 100644 --- a/fpdfsdk/src/javascript/JS_Runtime.cpp +++ b/fpdfsdk/src/javascript/JS_Runtime.cpp @@ -121,6 +121,7 @@ CJS_Runtime::~CJS_Runtime() { delete m_ContextArray.GetAt(i); m_ContextArray.RemoveAll(); + m_ConstArrays.clear(); FXJS_ReleaseRuntime(GetIsolate(), &m_context, &m_StaticObjects); m_pApp = NULL; @@ -256,6 +257,15 @@ v8::Local<v8::Context> CJS_Runtime::NewJSContext() { return v8::Local<v8::Context>::New(m_isolate, m_context); } +void CJS_Runtime::SetConstArray(const CFX_WideString& name, + v8::Local<v8::Array> array) { + m_ConstArrays[name] = v8::Global<v8::Array>(m_isolate, array); +} + +v8::Local<v8::Array> CJS_Runtime::GetConstArray(const CFX_WideString& name) { + return v8::Local<v8::Array>::New(m_isolate, m_ConstArrays[name]); +} + #ifdef PDF_ENABLE_XFA CFX_WideString ChangeObjName(const CFX_WideString& str) { CFX_WideString sRet = str; diff --git a/fpdfsdk/src/javascript/JS_Runtime.h b/fpdfsdk/src/javascript/JS_Runtime.h index 6fc3894f44..8215b88994 100644 --- a/fpdfsdk/src/javascript/JS_Runtime.h +++ b/fpdfsdk/src/javascript/JS_Runtime.h @@ -58,6 +58,9 @@ class CJS_Runtime : public IJS_Runtime { v8::Isolate* GetIsolate() const { return m_isolate; } v8::Local<v8::Context> NewJSContext(); + void SetConstArray(const CFX_WideString& name, v8::Local<v8::Array> array); + v8::Local<v8::Array> GetConstArray(const CFX_WideString& name); + #ifdef PDF_ENABLE_XFA FX_BOOL GetHValueByName(const CFX_ByteStringC& utf8Name, FXJSE_HVALUE hValue) override; @@ -80,6 +83,7 @@ class CJS_Runtime : public IJS_Runtime { bool m_isolateManaged; v8::Global<v8::Context> m_context; std::vector<v8::Global<v8::Object>*> m_StaticObjects; + std::map<CFX_WideString, v8::Global<v8::Array>> m_ConstArrays; std::set<Observer*> m_observers; }; diff --git a/fpdfsdk/src/jsapi/fxjs_v8.cpp b/fpdfsdk/src/jsapi/fxjs_v8.cpp index 4e139ca37b..e0e26deac8 100644 --- a/fpdfsdk/src/jsapi/fxjs_v8.cpp +++ b/fpdfsdk/src/jsapi/fxjs_v8.cpp @@ -292,14 +292,15 @@ void FXJS_DefineGlobalMethod(v8::Isolate* pIsolate, void FXJS_DefineGlobalConst(v8::Isolate* pIsolate, const wchar_t* sConstName, - v8::Local<v8::Value> pDefault) { + v8::FunctionCallback pConstGetter) { v8::Isolate::Scope isolate_scope(pIsolate); v8::HandleScope handle_scope(pIsolate); CFX_ByteString bsConst = CFX_WideString(sConstName).UTF8Encode(); - GetGlobalObjectTemplate(pIsolate)->Set( - v8::String::NewFromUtf8(pIsolate, bsConst.c_str(), - v8::NewStringType::kNormal).ToLocalChecked(), - pDefault, v8::ReadOnly); + GetGlobalObjectTemplate(pIsolate) + ->SetAccessorProperty(v8::String::NewFromUtf8(pIsolate, bsConst.c_str(), + v8::NewStringType::kNormal) + .ToLocalChecked(), + v8::FunctionTemplate::New(pIsolate, pConstGetter)); } void FXJS_InitializeRuntime( |