From ad978ed196882ce29e6a4e0757770da6cfc44f81 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Mon, 4 Jun 2018 19:19:07 +0000 Subject: cjs_globalconsts.cpp need not use v8::Context slots Small step towards deprecating FXJS's use of v8::Context slots. Reduces some string constant storage size while were at it by avoiding wide literals for ascii strings. Change-Id: Ibc651cff264302681645fde7c53bf77517b97651 Reviewed-on: https://pdfium-review.googlesource.com/33470 Commit-Queue: Tom Sepez Reviewed-by: dsinclair --- fxjs/cjs_globalconsts.cpp | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/fxjs/cjs_globalconsts.cpp b/fxjs/cjs_globalconsts.cpp index a07bf60302..cb6bd33c47 100644 --- a/fxjs/cjs_globalconsts.cpp +++ b/fxjs/cjs_globalconsts.cpp @@ -6,42 +6,44 @@ #include "fxjs/cjs_globalconsts.h" -#define GLOBAL_STRING(rt, name, value) \ - (rt)->DefineGlobalConst( \ - (name), [](const v8::FunctionCallbackInfo& info) { \ - info.GetReturnValue().Set( \ - CFXJS_Engine::EngineFromIsolateCurrentContext(info.GetIsolate()) \ - ->NewString(value)); \ +#define GLOBAL_STRING(rt, name, value) \ + (rt)->DefineGlobalConst( \ + (name), [](const v8::FunctionCallbackInfo& info) { \ + const char* pStr = (value); \ + info.GetReturnValue().Set( \ + v8::String::NewFromUtf8(info.GetIsolate(), pStr, \ + v8::NewStringType::kNormal, strlen(pStr)) \ + .ToLocalChecked()); \ }) // static void CJS_GlobalConsts::DefineJSObjects(CJS_Runtime* pRuntime) { GLOBAL_STRING(pRuntime, L"IDS_GREATER_THAN", - L"Invalid value: must be greater than or equal to % s."); + "Invalid value: must be greater than or equal to % s."); 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."); + "Invalid value: must be greater than or equal to % s " + "and less than or equal to % s."); GLOBAL_STRING(pRuntime, L"IDS_LESS_THAN", - L"Invalid value: must be less than or equal to % s."); + "Invalid value: must be less than or equal to % s."); - GLOBAL_STRING(pRuntime, L"IDS_INVALID_MONTH", L"**Invalid**"); + GLOBAL_STRING(pRuntime, L"IDS_INVALID_MONTH", "**Invalid**"); GLOBAL_STRING( pRuntime, L"IDS_INVALID_DATE", - L"Invalid date / time: please ensure that the date / time exists.Field"); + "Invalid date / time: please ensure that the date / time exists.Field"); GLOBAL_STRING(pRuntime, L"IDS_INVALID_VALUE", - L"The value entered does not match the format of the field"); + "The value entered does not match the format of the field"); - GLOBAL_STRING(pRuntime, L"IDS_AM", L"am"); - GLOBAL_STRING(pRuntime, L"IDS_PM", L"pm"); + GLOBAL_STRING(pRuntime, L"IDS_AM", "am"); + GLOBAL_STRING(pRuntime, L"IDS_PM", "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]"); + "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]"); - GLOBAL_STRING(pRuntime, L"IDS_STARTUP_CONSOLE_MSG", L"** ^ _ ^ **"); + GLOBAL_STRING(pRuntime, L"IDS_STARTUP_CONSOLE_MSG", "** ^ _ ^ **"); } -- cgit v1.2.3