| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "fpdfsdk/javascript/global.h" | 7 #include "fpdfsdk/javascript/global.h" |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 return FALSE; | 74 return FALSE; |
| 75 | 75 |
| 76 it->second->bDeleted = TRUE; | 76 it->second->bDeleted = TRUE; |
| 77 return TRUE; | 77 return TRUE; |
| 78 } | 78 } |
| 79 | 79 |
| 80 FX_BOOL JSGlobalAlternate::DoProperty(IJS_Context* cc, | 80 FX_BOOL JSGlobalAlternate::DoProperty(IJS_Context* cc, |
| 81 const FX_WCHAR* propname, | 81 const FX_WCHAR* propname, |
| 82 CJS_PropValue& vp, | 82 CJS_PropValue& vp, |
| 83 CFX_WideString& sError) { | 83 CFX_WideString& sError) { |
| 84 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 84 if (vp.IsSetting()) { | 85 if (vp.IsSetting()) { |
| 85 CFX_ByteString sPropName = CFX_ByteString::FromUnicode(propname); | 86 CFX_ByteString sPropName = CFX_ByteString::FromUnicode(propname); |
| 86 switch (vp.GetType()) { | 87 switch (vp.GetJSValue()->GetType()) { |
| 87 case CJS_Value::VT_number: { | 88 case CJS_Value::VT_number: { |
| 88 double dData; | 89 double dData; |
| 89 vp >> dData; | 90 vp >> dData; |
| 90 return SetGlobalVariables(sPropName, JS_GlobalDataType::NUMBER, dData, | 91 return SetGlobalVariables(sPropName, JS_GlobalDataType::NUMBER, dData, |
| 91 false, "", v8::Local<v8::Object>(), FALSE); | 92 false, "", v8::Local<v8::Object>(), FALSE); |
| 92 } | 93 } |
| 93 case CJS_Value::VT_boolean: { | 94 case CJS_Value::VT_boolean: { |
| 94 bool bData; | 95 bool bData; |
| 95 vp >> bData; | 96 vp >> bData; |
| 96 return SetGlobalVariables(sPropName, JS_GlobalDataType::BOOLEAN, 0, | 97 return SetGlobalVariables(sPropName, JS_GlobalDataType::BOOLEAN, 0, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 115 case CJS_Value::VT_undefined: { | 116 case CJS_Value::VT_undefined: { |
| 116 DelProperty(cc, propname, sError); | 117 DelProperty(cc, propname, sError); |
| 117 return TRUE; | 118 return TRUE; |
| 118 } | 119 } |
| 119 default: | 120 default: |
| 120 break; | 121 break; |
| 121 } | 122 } |
| 122 } else { | 123 } else { |
| 123 auto it = m_mapGlobal.find(CFX_ByteString::FromUnicode(propname)); | 124 auto it = m_mapGlobal.find(CFX_ByteString::FromUnicode(propname)); |
| 124 if (it == m_mapGlobal.end()) { | 125 if (it == m_mapGlobal.end()) { |
| 125 vp.SetNull(); | 126 vp.GetJSValue()->SetNull(pRuntime); |
| 126 return TRUE; | 127 return TRUE; |
| 127 } | 128 } |
| 128 JSGlobalData* pData = it->second; | 129 JSGlobalData* pData = it->second; |
| 129 if (pData->bDeleted) { | 130 if (pData->bDeleted) { |
| 130 vp.SetNull(); | 131 vp.GetJSValue()->SetNull(pRuntime); |
| 131 return TRUE; | 132 return TRUE; |
| 132 } | 133 } |
| 133 switch (pData->nType) { | 134 switch (pData->nType) { |
| 134 case JS_GlobalDataType::NUMBER: | 135 case JS_GlobalDataType::NUMBER: |
| 135 vp << pData->dData; | 136 vp << pData->dData; |
| 136 return TRUE; | 137 return TRUE; |
| 137 case JS_GlobalDataType::BOOLEAN: | 138 case JS_GlobalDataType::BOOLEAN: |
| 138 vp << pData->bData; | 139 vp << pData->bData; |
| 139 return TRUE; | 140 return TRUE; |
| 140 case JS_GlobalDataType::STRING: | 141 case JS_GlobalDataType::STRING: |
| 141 vp << pData->sData; | 142 vp << pData->sData; |
| 142 return TRUE; | 143 return TRUE; |
| 143 case JS_GlobalDataType::OBJECT: { | 144 case JS_GlobalDataType::OBJECT: { |
| 144 v8::Local<v8::Object> obj = v8::Local<v8::Object>::New( | 145 v8::Local<v8::Object> obj = v8::Local<v8::Object>::New( |
| 145 vp.GetJSRuntime()->GetIsolate(), pData->pData); | 146 vp.GetJSRuntime()->GetIsolate(), pData->pData); |
| 146 vp << obj; | 147 vp << obj; |
| 147 return TRUE; | 148 return TRUE; |
| 148 } | 149 } |
| 149 case JS_GlobalDataType::NULLOBJ: | 150 case JS_GlobalDataType::NULLOBJ: |
| 150 vp.SetNull(); | 151 vp.GetJSValue()->SetNull(pRuntime); |
| 151 return TRUE; | 152 return TRUE; |
| 152 default: | 153 default: |
| 153 break; | 154 break; |
| 154 } | 155 } |
| 155 } | 156 } |
| 156 return FALSE; | 157 return FALSE; |
| 157 } | 158 } |
| 158 | 159 |
| 159 FX_BOOL JSGlobalAlternate::setPersistent(IJS_Context* cc, | 160 FX_BOOL JSGlobalAlternate::setPersistent(IJS_Context* cc, |
| 160 const std::vector<CJS_Value>& params, | 161 const std::vector<CJS_Value>& params, |
| 161 CJS_Value& vRet, | 162 CJS_Value& vRet, |
| 162 CFX_WideString& sError) { | 163 CFX_WideString& sError) { |
| 163 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | 164 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 165 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 164 if (params.size() != 2) { | 166 if (params.size() != 2) { |
| 165 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 167 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 166 return FALSE; | 168 return FALSE; |
| 167 } | 169 } |
| 168 | 170 |
| 169 auto it = m_mapGlobal.find(params[0].ToCFXByteString()); | 171 auto it = m_mapGlobal.find(params[0].ToCFXByteString(pRuntime->GetIsolate())); |
| 170 if (it != m_mapGlobal.end()) { | 172 if (it != m_mapGlobal.end()) { |
| 171 JSGlobalData* pData = it->second; | 173 JSGlobalData* pData = it->second; |
| 172 if (!pData->bDeleted) { | 174 if (!pData->bDeleted) { |
| 173 pData->bPersistent = params[1].ToBool(); | 175 pData->bPersistent = params[1].ToBool(pRuntime->GetIsolate()); |
| 174 return TRUE; | 176 return TRUE; |
| 175 } | 177 } |
| 176 } | 178 } |
| 177 | 179 |
| 178 sError = JSGetStringFromID(pContext, IDS_STRING_JSNOGLOBAL); | 180 sError = JSGetStringFromID(pContext, IDS_STRING_JSNOGLOBAL); |
| 179 return FALSE; | 181 return FALSE; |
| 180 } | 182 } |
| 181 | 183 |
| 182 void JSGlobalAlternate::UpdateGlobalPersistentVariables() { | 184 void JSGlobalAlternate::UpdateGlobalPersistentVariables() { |
| 183 for (int i = 0, sz = m_pGlobalData->GetSize(); i < sz; i++) { | 185 for (int i = 0, sz = m_pGlobalData->GetSize(); i < sz; i++) { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 } | 266 } |
| 265 } | 267 } |
| 266 } | 268 } |
| 267 } | 269 } |
| 268 | 270 |
| 269 void JSGlobalAlternate::ObjectToArray(IJS_Context* cc, | 271 void JSGlobalAlternate::ObjectToArray(IJS_Context* cc, |
| 270 v8::Local<v8::Object> pObj, | 272 v8::Local<v8::Object> pObj, |
| 271 CJS_GlobalVariableArray& array) { | 273 CJS_GlobalVariableArray& array) { |
| 272 v8::Isolate* isolate = pObj->GetIsolate(); | 274 v8::Isolate* isolate = pObj->GetIsolate(); |
| 273 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 275 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 274 | |
| 275 v8::Local<v8::Array> pKeyList = FXJS_GetObjectElementNames(isolate, pObj); | 276 v8::Local<v8::Array> pKeyList = FXJS_GetObjectElementNames(isolate, pObj); |
| 276 int nObjElements = pKeyList->Length(); | 277 int nObjElements = pKeyList->Length(); |
| 277 for (int i = 0; i < nObjElements; i++) { | 278 for (int i = 0; i < nObjElements; i++) { |
| 278 CFX_WideString ws = | 279 CFX_WideString ws = |
| 279 FXJS_ToString(isolate, FXJS_GetArrayElement(isolate, pKeyList, i)); | 280 FXJS_ToString(isolate, FXJS_GetArrayElement(isolate, pKeyList, i)); |
| 280 CFX_ByteString sKey = ws.UTF8Encode(); | 281 CFX_ByteString sKey = ws.UTF8Encode(); |
| 281 v8::Local<v8::Value> v = FXJS_GetObjectElement(isolate, pObj, ws); | 282 v8::Local<v8::Value> v = FXJS_GetObjectElement(isolate, pObj, ws); |
| 282 switch (CJS_Value::GetValueType(v)) { | 283 switch (CJS_Value::GetValueType(v)) { |
| 283 case CJS_Value::VT_number: { | 284 case CJS_Value::VT_number: { |
| 284 CJS_KeyValue* pObjElement = new CJS_KeyValue; | 285 CJS_KeyValue* pObjElement = new CJS_KeyValue; |
| 285 pObjElement->nType = JS_GlobalDataType::NUMBER; | 286 pObjElement->nType = JS_GlobalDataType::NUMBER; |
| 286 pObjElement->sKey = sKey; | 287 pObjElement->sKey = sKey; |
| 287 pObjElement->dData = FXJS_ToNumber(isolate, v); | 288 pObjElement->dData = FXJS_ToNumber(isolate, v); |
| 288 array.Add(pObjElement); | 289 array.Add(pObjElement); |
| 289 } break; | 290 } break; |
| 290 case CJS_Value::VT_boolean: { | 291 case CJS_Value::VT_boolean: { |
| 291 CJS_KeyValue* pObjElement = new CJS_KeyValue; | 292 CJS_KeyValue* pObjElement = new CJS_KeyValue; |
| 292 pObjElement->nType = JS_GlobalDataType::BOOLEAN; | 293 pObjElement->nType = JS_GlobalDataType::BOOLEAN; |
| 293 pObjElement->sKey = sKey; | 294 pObjElement->sKey = sKey; |
| 294 pObjElement->dData = FXJS_ToBoolean(isolate, v); | 295 pObjElement->dData = FXJS_ToBoolean(isolate, v); |
| 295 array.Add(pObjElement); | 296 array.Add(pObjElement); |
| 296 } break; | 297 } break; |
| 297 case CJS_Value::VT_string: { | 298 case CJS_Value::VT_string: { |
| 298 CFX_ByteString sValue = CJS_Value(pRuntime, v).ToCFXByteString(); | 299 CFX_ByteString sValue = |
| 300 CJS_Value(pRuntime, v).ToCFXByteString(pRuntime->GetIsolate()); |
| 299 CJS_KeyValue* pObjElement = new CJS_KeyValue; | 301 CJS_KeyValue* pObjElement = new CJS_KeyValue; |
| 300 pObjElement->nType = JS_GlobalDataType::STRING; | 302 pObjElement->nType = JS_GlobalDataType::STRING; |
| 301 pObjElement->sKey = sKey; | 303 pObjElement->sKey = sKey; |
| 302 pObjElement->sData = sValue; | 304 pObjElement->sData = sValue; |
| 303 array.Add(pObjElement); | 305 array.Add(pObjElement); |
| 304 } break; | 306 } break; |
| 305 case CJS_Value::VT_object: { | 307 case CJS_Value::VT_object: { |
| 306 CJS_KeyValue* pObjElement = new CJS_KeyValue; | 308 CJS_KeyValue* pObjElement = new CJS_KeyValue; |
| 307 pObjElement->nType = JS_GlobalDataType::OBJECT; | 309 pObjElement->nType = JS_GlobalDataType::OBJECT; |
| 308 pObjElement->sKey = sKey; | 310 pObjElement->sKey = sKey; |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 pNewData->nType = JS_GlobalDataType::NULLOBJ; | 436 pNewData->nType = JS_GlobalDataType::NULLOBJ; |
| 435 pNewData->bPersistent = bDefaultPersistent; | 437 pNewData->bPersistent = bDefaultPersistent; |
| 436 } break; | 438 } break; |
| 437 default: | 439 default: |
| 438 return FALSE; | 440 return FALSE; |
| 439 } | 441 } |
| 440 | 442 |
| 441 m_mapGlobal[propname] = pNewData; | 443 m_mapGlobal[propname] = pNewData; |
| 442 return TRUE; | 444 return TRUE; |
| 443 } | 445 } |
| OLD | NEW |