From 892d7510db7015b1835d8e057a716518881f126d Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Tue, 21 Feb 2017 13:57:13 -0800 Subject: Avoid some widestring to bytestring conversions in fxjs. None of the names have non-ascii characters. Change-Id: I83a52d6276edf2f442fca33221f38f6a53c3ffe3 Reviewed-on: https://pdfium-review.googlesource.com/2816 Commit-Queue: Tom Sepez Reviewed-by: dsinclair --- fpdfsdk/javascript/JS_Define.h | 12 +++++------- fxjs/fxjs_v8.cpp | 16 ++++++++-------- fxjs/fxjs_v8.h | 2 +- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/fpdfsdk/javascript/JS_Define.h b/fpdfsdk/javascript/JS_Define.h index 6ad00632d3..4f5cc5d66e 100644 --- a/fpdfsdk/javascript/JS_Define.h +++ b/fpdfsdk/javascript/JS_Define.h @@ -34,8 +34,6 @@ struct JSMethodSpec { v8::FunctionCallback pMethodCall; }; -#define JS_WIDESTRING(widestring) L## #widestring - template void JSPropGetter(const char* prop_name_string, const char* class_name_string, @@ -141,13 +139,13 @@ void JSMethod(const char* method_name_string, // All JS classes have a name, an object defintion ID, and the ability to // register themselves with FXJS_V8. We never make a BASE class on its own // because it can't really do anything. -#define DECLARE_JS_CLASS_BASE_PART() \ - static const wchar_t* g_pClassName; \ - static int g_nObjDefnID; \ +#define DECLARE_JS_CLASS_BASE_PART() \ + static const char* g_pClassName; \ + static int g_nObjDefnID; \ static void DefineJSObjects(CFXJS_Engine* pEngine, FXJSOBJTYPE eObjType); -#define IMPLEMENT_JS_CLASS_BASE_PART(js_class_name, class_name) \ - const wchar_t* js_class_name::g_pClassName = JS_WIDESTRING(class_name); \ +#define IMPLEMENT_JS_CLASS_BASE_PART(js_class_name, class_name) \ + const char* js_class_name::g_pClassName = #class_name; \ int js_class_name::g_nObjDefnID = -1; // CONST classes provide constants, but not constructors, methods, or props. diff --git a/fxjs/fxjs_v8.cpp b/fxjs/fxjs_v8.cpp index 667d63be02..a5eba1bbc1 100644 --- a/fxjs/fxjs_v8.cpp +++ b/fxjs/fxjs_v8.cpp @@ -42,7 +42,7 @@ class CFXJS_ObjDefinition { } CFXJS_ObjDefinition(v8::Isolate* isolate, - const wchar_t* sObjName, + const char* sObjName, FXJSOBJTYPE eObjType, CFXJS_Engine::Constructor pConstructor, CFXJS_Engine::Destructor pDestructor) @@ -86,7 +86,7 @@ class CFXJS_ObjDefinition { return scope.Escape(m_Signature.Get(m_pIsolate)); } - const wchar_t* const m_ObjName; + const char* const m_ObjName; const FXJSOBJTYPE m_ObjType; const CFXJS_Engine::Constructor m_pConstructor; const CFXJS_Engine::Destructor m_pDestructor; @@ -257,7 +257,7 @@ void CFXJS_Engine::FreeObjectPrivate(v8::Local pObj) { pObj->SetAlignedPointerInInternalField(0, nullptr); } -int CFXJS_Engine::DefineObj(const wchar_t* sObjName, +int CFXJS_Engine::DefineObj(const char* sObjName, FXJSOBJTYPE eObjType, CFXJS_Engine::Constructor pConstructor, CFXJS_Engine::Destructor pDestructor) { @@ -392,14 +392,14 @@ void CFXJS_Engine::InitializeEngine() { ->ToObject(v8Context) .ToLocalChecked()); } else if (pObjDef->m_ObjType == FXJSOBJTYPE_STATIC) { - CFX_ByteString bs = FX_UTF8Encode(CFX_WideStringC(pObjDef->m_ObjName)); - v8::Local m_ObjName = - v8::String::NewFromUtf8(m_isolate, bs.c_str(), - v8::NewStringType::kNormal, bs.GetLength()) + v8::Local pObjName = + v8::String::NewFromUtf8(m_isolate, pObjDef->m_ObjName, + v8::NewStringType::kNormal, + strlen(pObjDef->m_ObjName)) .ToLocalChecked(); v8::Local obj = NewFxDynamicObj(i, true); - v8Context->Global()->Set(v8Context, m_ObjName, obj).FromJust(); + v8Context->Global()->Set(v8Context, pObjName, obj).FromJust(); m_StaticObjects[i] = new v8::Global(m_isolate, obj); } } diff --git a/fxjs/fxjs_v8.h b/fxjs/fxjs_v8.h index e82218f43c..541566f6d0 100644 --- a/fxjs/fxjs_v8.h +++ b/fxjs/fxjs_v8.h @@ -142,7 +142,7 @@ class CFXJS_Engine { v8::Isolate* GetIsolate() const { return m_isolate; } // Always returns a valid, newly-created objDefnID. - int DefineObj(const wchar_t* sObjName, + int DefineObj(const char* sObjName, FXJSOBJTYPE eObjType, Constructor pConstructor, Destructor pDestructor); -- cgit v1.2.3