summaryrefslogtreecommitdiff
path: root/fpdfsdk/javascript/global.cpp
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-10-24 15:15:27 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-10-24 19:28:02 +0000
commit3cac3602f24f56413cc2ca312731675fc080b7ef (patch)
treecc5741593ce51f41276be2f8a1826bf452a7841c /fpdfsdk/javascript/global.cpp
parent1b2a18ec4ed99fc2ac56b5fde230bc2b348d9725 (diff)
downloadpdfium-3cac3602f24f56413cc2ca312731675fc080b7ef.tar.xz
Remove GetType from CJS_Value
This CL removes the GetType method from CJS_Value and, instead, retrieves the value from the v8 object directly. Change-Id: Ia8390f3ead163c09a39cae493e75fccdd41a0961 Reviewed-on: https://pdfium-review.googlesource.com/16615 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'fpdfsdk/javascript/global.cpp')
-rw-r--r--fpdfsdk/javascript/global.cpp128
1 files changed, 65 insertions, 63 deletions
diff --git a/fpdfsdk/javascript/global.cpp b/fpdfsdk/javascript/global.cpp
index f095440413..aae7c93160 100644
--- a/fpdfsdk/javascript/global.cpp
+++ b/fpdfsdk/javascript/global.cpp
@@ -325,31 +325,33 @@ bool JSGlobalAlternate::SetProperty(CJS_Runtime* pRuntime,
const wchar_t* propname,
const CJS_Value& vp) {
ByteString sPropName = ByteString::FromUnicode(propname);
- switch (vp.GetType()) {
- case CJS_Value::VT_number:
- return SetGlobalVariables(sPropName, JS_GlobalDataType::NUMBER,
- pRuntime->ToDouble(vp.ToV8Value()), false, "",
- v8::Local<v8::Object>(), false);
- case CJS_Value::VT_boolean:
- return SetGlobalVariables(sPropName, JS_GlobalDataType::BOOLEAN, 0,
- pRuntime->ToBoolean(vp.ToV8Value()), "",
- v8::Local<v8::Object>(), false);
- case CJS_Value::VT_string:
- return SetGlobalVariables(
- sPropName, JS_GlobalDataType::STRING, 0, false,
- ByteString::FromUnicode(pRuntime->ToWideString(vp.ToV8Value())),
- v8::Local<v8::Object>(), false);
- case CJS_Value::VT_object:
- return SetGlobalVariables(sPropName, JS_GlobalDataType::OBJECT, 0, false,
- "", pRuntime->ToObject(vp.ToV8Value()), false);
- case CJS_Value::VT_null:
- return SetGlobalVariables(sPropName, JS_GlobalDataType::NULLOBJ, 0, false,
- "", v8::Local<v8::Object>(), false);
- case CJS_Value::VT_undefined:
- DelProperty(pRuntime, propname);
- return true;
- default:
- break;
+ if (vp.ToV8Value()->IsNumber()) {
+ return SetGlobalVariables(sPropName, JS_GlobalDataType::NUMBER,
+ pRuntime->ToDouble(vp.ToV8Value()), false, "",
+ v8::Local<v8::Object>(), false);
+ }
+ if (vp.ToV8Value()->IsBoolean()) {
+ return SetGlobalVariables(sPropName, JS_GlobalDataType::BOOLEAN, 0,
+ pRuntime->ToBoolean(vp.ToV8Value()), "",
+ v8::Local<v8::Object>(), false);
+ }
+ if (vp.ToV8Value()->IsString()) {
+ return SetGlobalVariables(
+ sPropName, JS_GlobalDataType::STRING, 0, false,
+ ByteString::FromUnicode(pRuntime->ToWideString(vp.ToV8Value())),
+ v8::Local<v8::Object>(), false);
+ }
+ if (vp.ToV8Value()->IsObject()) {
+ return SetGlobalVariables(sPropName, JS_GlobalDataType::OBJECT, 0, false,
+ "", pRuntime->ToObject(vp.ToV8Value()), false);
+ }
+ if (vp.ToV8Value()->IsNull()) {
+ return SetGlobalVariables(sPropName, JS_GlobalDataType::NULLOBJ, 0, false,
+ "", v8::Local<v8::Object>(), false);
+ }
+ if (vp.ToV8Value()->IsUndefined()) {
+ DelProperty(pRuntime, propname);
+ return true;
}
return false;
}
@@ -471,44 +473,44 @@ void JSGlobalAlternate::ObjectToArray(CJS_Runtime* pRuntime,
for (const auto& ws : pKeyList) {
ByteString sKey = ws.UTF8Encode();
v8::Local<v8::Value> v = pRuntime->GetObjectProperty(pObj, ws);
- switch (CJS_Value::GetValueType(v)) {
- case CJS_Value::VT_number: {
- CJS_KeyValue* pObjElement = new CJS_KeyValue;
- pObjElement->nType = JS_GlobalDataType::NUMBER;
- pObjElement->sKey = sKey;
- pObjElement->dData = pRuntime->ToDouble(v);
- array.Add(pObjElement);
- } break;
- case CJS_Value::VT_boolean: {
- CJS_KeyValue* pObjElement = new CJS_KeyValue;
- pObjElement->nType = JS_GlobalDataType::BOOLEAN;
- pObjElement->sKey = sKey;
- pObjElement->dData = pRuntime->ToBoolean(v);
- array.Add(pObjElement);
- } break;
- case CJS_Value::VT_string: {
- ByteString sValue = ByteString::FromUnicode(pRuntime->ToWideString(v));
- CJS_KeyValue* pObjElement = new CJS_KeyValue;
- pObjElement->nType = JS_GlobalDataType::STRING;
- pObjElement->sKey = sKey;
- pObjElement->sData = sValue;
- array.Add(pObjElement);
- } break;
- case CJS_Value::VT_object: {
- CJS_KeyValue* pObjElement = new CJS_KeyValue;
- pObjElement->nType = JS_GlobalDataType::OBJECT;
- pObjElement->sKey = sKey;
- ObjectToArray(pRuntime, pRuntime->ToObject(v), pObjElement->objData);
- array.Add(pObjElement);
- } break;
- case CJS_Value::VT_null: {
- CJS_KeyValue* pObjElement = new CJS_KeyValue;
- pObjElement->nType = JS_GlobalDataType::NULLOBJ;
- pObjElement->sKey = sKey;
- array.Add(pObjElement);
- } break;
- default:
- break;
+ if (v->IsNumber()) {
+ CJS_KeyValue* pObjElement = new CJS_KeyValue;
+ pObjElement->nType = JS_GlobalDataType::NUMBER;
+ pObjElement->sKey = sKey;
+ pObjElement->dData = pRuntime->ToDouble(v);
+ array.Add(pObjElement);
+ continue;
+ }
+ if (v->IsBoolean()) {
+ CJS_KeyValue* pObjElement = new CJS_KeyValue;
+ pObjElement->nType = JS_GlobalDataType::BOOLEAN;
+ pObjElement->sKey = sKey;
+ pObjElement->dData = pRuntime->ToBoolean(v);
+ array.Add(pObjElement);
+ continue;
+ }
+ if (v->IsString()) {
+ ByteString sValue = ByteString::FromUnicode(pRuntime->ToWideString(v));
+ CJS_KeyValue* pObjElement = new CJS_KeyValue;
+ pObjElement->nType = JS_GlobalDataType::STRING;
+ pObjElement->sKey = sKey;
+ pObjElement->sData = sValue;
+ array.Add(pObjElement);
+ continue;
+ }
+ if (v->IsObject()) {
+ CJS_KeyValue* pObjElement = new CJS_KeyValue;
+ pObjElement->nType = JS_GlobalDataType::OBJECT;
+ pObjElement->sKey = sKey;
+ ObjectToArray(pRuntime, pRuntime->ToObject(v), pObjElement->objData);
+ array.Add(pObjElement);
+ continue;
+ }
+ if (v->IsNull()) {
+ CJS_KeyValue* pObjElement = new CJS_KeyValue;
+ pObjElement->nType = JS_GlobalDataType::NULLOBJ;
+ pObjElement->sKey = sKey;
+ array.Add(pObjElement);
}
}
}