summaryrefslogtreecommitdiff
path: root/fxjs/fxjs_v8.cpp
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2017-02-23 09:53:09 -0800
committerChromium commit bot <commit-bot@chromium.org>2017-02-23 18:32:16 +0000
commitc6dc69fb69e5d9974aa451d590194d568b78131b (patch)
treebec72acd1fee95da7d321ee700cf7aff23ecfe80 /fxjs/fxjs_v8.cpp
parentfc54e054811510c3d7c8a9c6af6c90c3222c7029 (diff)
downloadpdfium-c6dc69fb69e5d9974aa451d590194d568b78131b.tar.xz
Store JS string constants as single-byte strings.
Save some space since none contain non-ascii characters. Avoid allocating C++ WideStrings just to convert back to UTF8 when defining properties. Change-Id: Id94db21b32ee7a96856c35a09f7550b54599ae13 Reviewed-on: https://pdfium-review.googlesource.com/2826 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'fxjs/fxjs_v8.cpp')
-rw-r--r--fxjs/fxjs_v8.cpp26
1 files changed, 13 insertions, 13 deletions
diff --git a/fxjs/fxjs_v8.cpp b/fxjs/fxjs_v8.cpp
index 1f049a0dd3..053db07d3b 100644
--- a/fxjs/fxjs_v8.cpp
+++ b/fxjs/fxjs_v8.cpp
@@ -558,22 +558,14 @@ void* CFXJS_Engine::GetObjectPrivate(v8::Local<v8::Object> pObj) {
return pPerObjectData ? pPerObjectData->m_pPrivate : nullptr;
}
-v8::Local<v8::String> CFXJS_Engine::WSToJSString(
- const CFX_WideString& wsPropertyName) {
- v8::Isolate* pIsolate = m_isolate ? m_isolate : v8::Isolate::GetCurrent();
- CFX_ByteString bs = wsPropertyName.UTF8Encode();
- return v8::String::NewFromUtf8(pIsolate, bs.c_str(),
- v8::NewStringType::kNormal, bs.GetLength())
- .ToLocalChecked();
-}
-
v8::Local<v8::Value> CFXJS_Engine::GetObjectProperty(
v8::Local<v8::Object> pObj,
const CFX_WideString& wsPropertyName) {
if (pObj.IsEmpty())
return v8::Local<v8::Value>();
v8::Local<v8::Value> val;
- if (!pObj->Get(m_isolate->GetCurrentContext(), WSToJSString(wsPropertyName))
+ if (!pObj->Get(m_isolate->GetCurrentContext(),
+ NewString(wsPropertyName.AsStringC()))
.ToLocal(&val))
return v8::Local<v8::Value>();
return val;
@@ -602,7 +594,8 @@ void CFXJS_Engine::PutObjectProperty(v8::Local<v8::Object> pObj,
v8::Local<v8::Value> pPut) {
if (pObj.IsEmpty())
return;
- pObj->Set(m_isolate->GetCurrentContext(), WSToJSString(wsPropertyName), pPut)
+ pObj->Set(m_isolate->GetCurrentContext(),
+ NewString(wsPropertyName.AsStringC()), pPut)
.FromJust();
}
@@ -661,8 +654,15 @@ v8::Local<v8::Value> CFXJS_Engine::NewBoolean(bool b) {
return v8::Boolean::New(m_isolate, b);
}
-v8::Local<v8::Value> CFXJS_Engine::NewString(const CFX_WideString& str) {
- return WSToJSString(str.c_str());
+v8::Local<v8::Value> CFXJS_Engine::NewString(const CFX_ByteStringC& str) {
+ v8::Isolate* pIsolate = m_isolate ? m_isolate : v8::Isolate::GetCurrent();
+ return v8::String::NewFromUtf8(pIsolate, str.c_str(),
+ v8::NewStringType::kNormal, str.GetLength())
+ .ToLocalChecked();
+}
+
+v8::Local<v8::Value> CFXJS_Engine::NewString(const CFX_WideStringC& str) {
+ return NewString(FX_UTF8Encode(str).AsStringC());
}
v8::Local<v8::Value> CFXJS_Engine::NewNull() {