diff options
author | tsepez <tsepez@chromium.org> | 2016-08-11 19:50:57 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-08-11 19:50:57 -0700 |
commit | d0b6ed1a0842386e474c5fcd6bdbb260bb631bd1 (patch) | |
tree | 6d7282f78ac953fc965e17815bcbef7995dd59ec | |
parent | 229d05df5bc5deb3890b26b614113c25d9b6935e (diff) | |
download | pdfium-d0b6ed1a0842386e474c5fcd6bdbb260bb631bd1.tar.xz |
Make FXJS_GetObjectElement return std::vector<CFX_WideString>.chromium/2829chromium/2828
Analogous to getting the length of JS array, this result
should be a C++-side object only.
Also rename to FXJS_GetObjectProperty to match JS nomenclature.
Review-Url: https://codereview.chromium.org/2242593002
-rw-r--r-- | fpdfsdk/javascript/Document.cpp | 21 | ||||
-rw-r--r-- | fpdfsdk/javascript/JS_Value.cpp | 2 | ||||
-rw-r--r-- | fpdfsdk/javascript/global.cpp | 10 | ||||
-rw-r--r-- | fxjs/fxjs_v8.cpp | 21 | ||||
-rw-r--r-- | fxjs/fxjs_v8_embeddertest.cpp | 3 | ||||
-rw-r--r-- | fxjs/include/fxjs_v8.h | 15 |
6 files changed, 42 insertions, 30 deletions
diff --git a/fpdfsdk/javascript/Document.cpp b/fpdfsdk/javascript/Document.cpp index ea77e1cfad..a55bf81139 100644 --- a/fpdfsdk/javascript/Document.cpp +++ b/fpdfsdk/javascript/Document.cpp @@ -615,17 +615,17 @@ FX_BOOL Document::submitForm(IJS_Context* cc, } else if (v.GetType() == CJS_Value::VT_object) { v8::Local<v8::Object> pObj = params[0].ToV8Object(pIsolate); v8::Local<v8::Value> pValue = - FXJS_GetObjectElement(pIsolate, pObj, L"cURL"); + FXJS_GetObjectProperty(pIsolate, pObj, L"cURL"); if (!pValue.IsEmpty()) strURL = CJS_Value(pRuntime, pValue).ToCFXWideString(pIsolate); - pValue = FXJS_GetObjectElement(pIsolate, pObj, L"bFDF"); + pValue = FXJS_GetObjectProperty(pIsolate, pObj, L"bFDF"); bFDF = CJS_Value(pRuntime, pValue).ToBool(pIsolate); - pValue = FXJS_GetObjectElement(pIsolate, pObj, L"bEmpty"); + pValue = FXJS_GetObjectProperty(pIsolate, pObj, L"bEmpty"); bEmpty = CJS_Value(pRuntime, pValue).ToBool(pIsolate); - pValue = FXJS_GetObjectElement(pIsolate, pObj, L"aFields"); + pValue = FXJS_GetObjectProperty(pIsolate, pObj, L"aFields"); aFields.Attach(CJS_Value(pRuntime, pValue).ToV8Array(pIsolate)); } @@ -712,22 +712,23 @@ FX_BOOL Document::mailDoc(IJS_Context* cc, if (params.size() >= 1 && params[0].GetType() == CJS_Value::VT_object) { v8::Local<v8::Object> pObj = params[0].ToV8Object(pIsolate); - v8::Local<v8::Value> pValue = FXJS_GetObjectElement(pIsolate, pObj, L"bUI"); + v8::Local<v8::Value> pValue = + FXJS_GetObjectProperty(pIsolate, pObj, L"bUI"); bUI = CJS_Value(pRuntime, pValue).ToInt(pIsolate); - pValue = FXJS_GetObjectElement(pIsolate, pObj, L"cTo"); + pValue = FXJS_GetObjectProperty(pIsolate, pObj, L"cTo"); cTo = CJS_Value(pRuntime, pValue).ToCFXWideString(pIsolate); - pValue = FXJS_GetObjectElement(pIsolate, pObj, L"cCc"); + pValue = FXJS_GetObjectProperty(pIsolate, pObj, L"cCc"); cCc = CJS_Value(pRuntime, pValue).ToCFXWideString(pIsolate); - pValue = FXJS_GetObjectElement(pIsolate, pObj, L"cBcc"); + pValue = FXJS_GetObjectProperty(pIsolate, pObj, L"cBcc"); cBcc = CJS_Value(pRuntime, pValue).ToCFXWideString(pIsolate); - pValue = FXJS_GetObjectElement(pIsolate, pObj, L"cSubject"); + pValue = FXJS_GetObjectProperty(pIsolate, pObj, L"cSubject"); cSubject = CJS_Value(pRuntime, pValue).ToCFXWideString(pIsolate); - pValue = FXJS_GetObjectElement(pIsolate, pObj, L"cMsg"); + pValue = FXJS_GetObjectProperty(pIsolate, pObj, L"cMsg"); cMsg = CJS_Value(pRuntime, pValue).ToCFXWideString(pIsolate); } diff --git a/fpdfsdk/javascript/JS_Value.cpp b/fpdfsdk/javascript/JS_Value.cpp index 8f448a9d9e..b7198353da 100644 --- a/fpdfsdk/javascript/JS_Value.cpp +++ b/fpdfsdk/javascript/JS_Value.cpp @@ -771,7 +771,7 @@ std::vector<CJS_Value> JS_ExpandKeywordParams( for (size_t i = 0; i < nKeywords; ++i) { const wchar_t* property = va_arg(ap, const wchar_t*); v8::Local<v8::Value> v8Value = - FXJS_GetObjectElement(pRuntime->GetIsolate(), pObj, property); + FXJS_GetObjectProperty(pRuntime->GetIsolate(), pObj, property); if (!v8Value->IsUndefined()) result[i] = CJS_Value(pRuntime, v8Value); } diff --git a/fpdfsdk/javascript/global.cpp b/fpdfsdk/javascript/global.cpp index 10bab26dd0..5ffc5594a6 100644 --- a/fpdfsdk/javascript/global.cpp +++ b/fpdfsdk/javascript/global.cpp @@ -273,13 +273,11 @@ void JSGlobalAlternate::ObjectToArray(IJS_Context* cc, CJS_GlobalVariableArray& array) { v8::Isolate* isolate = pObj->GetIsolate(); CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); - v8::Local<v8::Array> pKeyList = FXJS_GetObjectElementNames(isolate, pObj); - int nObjElements = pKeyList->Length(); - for (int i = 0; i < nObjElements; i++) { - CFX_WideString ws = - FXJS_ToString(isolate, FXJS_GetArrayElement(isolate, pKeyList, i)); + std::vector<CFX_WideString> pKeyList = + FXJS_GetObjectPropertyNames(isolate, pObj); + for (const auto& ws : pKeyList) { CFX_ByteString sKey = ws.UTF8Encode(); - v8::Local<v8::Value> v = FXJS_GetObjectElement(isolate, pObj, ws); + v8::Local<v8::Value> v = FXJS_GetObjectProperty(isolate, pObj, ws); switch (CJS_Value::GetValueType(v)) { case CJS_Value::VT_number: { CJS_KeyValue* pObjElement = new CJS_KeyValue; diff --git a/fxjs/fxjs_v8.cpp b/fxjs/fxjs_v8.cpp index d161af6281..92207fdd47 100644 --- a/fxjs/fxjs_v8.cpp +++ b/fxjs/fxjs_v8.cpp @@ -596,7 +596,7 @@ v8::Local<v8::String> FXJS_WSToJSString(v8::Isolate* pIsolate, .ToLocalChecked(); } -v8::Local<v8::Value> FXJS_GetObjectElement( +v8::Local<v8::Value> FXJS_GetObjectProperty( v8::Isolate* pIsolate, v8::Local<v8::Object> pObj, const CFX_WideString& wsPropertyName) { @@ -610,14 +610,23 @@ v8::Local<v8::Value> FXJS_GetObjectElement( return val; } -v8::Local<v8::Array> FXJS_GetObjectElementNames(v8::Isolate* pIsolate, - v8::Local<v8::Object> pObj) { +std::vector<CFX_WideString> FXJS_GetObjectPropertyNames( + v8::Isolate* pIsolate, + v8::Local<v8::Object> pObj) { if (pObj.IsEmpty()) - return v8::Local<v8::Array>(); + return std::vector<CFX_WideString>(); + v8::Local<v8::Array> val; if (!pObj->GetPropertyNames(pIsolate->GetCurrentContext()).ToLocal(&val)) - return v8::Local<v8::Array>(); - return val; + return std::vector<CFX_WideString>(); + + std::vector<CFX_WideString> result; + for (uint32_t i = 0; i < val->Length(); ++i) { + result.push_back(FXJS_ToString( + pIsolate, val->Get(pIsolate->GetCurrentContext(), i).ToLocalChecked())); + } + + return result; } void FXJS_PutObjectString(v8::Isolate* pIsolate, diff --git a/fxjs/fxjs_v8_embeddertest.cpp b/fxjs/fxjs_v8_embeddertest.cpp index b33ddca32d..71b004c144 100644 --- a/fxjs/fxjs_v8_embeddertest.cpp +++ b/fxjs/fxjs_v8_embeddertest.cpp @@ -26,7 +26,8 @@ class FXJSV8EmbedderTest : public JSEmbedderTest { } void CheckAssignmentInCurrentContext(double expected) { v8::Local<v8::Object> This = FXJS_GetThisObj(isolate()); - v8::Local<v8::Value> fred = FXJS_GetObjectElement(isolate(), This, L"fred"); + v8::Local<v8::Value> fred = + FXJS_GetObjectProperty(isolate(), This, L"fred"); EXPECT_TRUE(fred->IsNumber()); EXPECT_EQ(expected, fred->ToNumber(isolate()->GetCurrentContext()) .ToLocalChecked() diff --git a/fxjs/include/fxjs_v8.h b/fxjs/include/fxjs_v8.h index cd4d7c4dab..5e12b082be 100644 --- a/fxjs/include/fxjs_v8.h +++ b/fxjs/include/fxjs_v8.h @@ -211,16 +211,19 @@ void FXJS_Error(v8::Isolate* isolate, const CFX_WideString& message); v8::Local<v8::String> FXJS_WSToJSString(v8::Isolate* pIsolate, const CFX_WideString& wsPropertyName); -v8::Local<v8::Value> FXJS_GetObjectElement(v8::Isolate* pIsolate, - v8::Local<v8::Object> pObj, - const CFX_WideString& PropertyName); -v8::Local<v8::Array> FXJS_GetObjectElementNames(v8::Isolate* pIsolate, - v8::Local<v8::Object> pObj); + +std::vector<CFX_WideString> FXJS_GetObjectPropertyNames( + v8::Isolate* pIsolate, + v8::Local<v8::Object> pObj); +v8::Local<v8::Value> FXJS_GetObjectProperty(v8::Isolate* pIsolate, + v8::Local<v8::Object> pObj, + const CFX_WideString& PropertyName); + +unsigned FXJS_GetArrayLength(v8::Local<v8::Array> pArray); v8::Local<v8::Value> FXJS_GetArrayElement(v8::Isolate* pIsolate, v8::Local<v8::Array> pArray, unsigned index); -unsigned FXJS_GetArrayLength(v8::Local<v8::Array> pArray); void FXJS_PutObjectString(v8::Isolate* pIsolate, v8::Local<v8::Object> pObj, const CFX_WideString& wsPropertyName, |