blob: 3d61c17751b1c63a73cb46efd99f463dc281ba73 [file] [log] [blame]
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001// Copyright 2014 PDFium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07004
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07005// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
Dan Sinclaire0345a42017-10-30 20:20:42 +00007#include "fxjs/cjs_global.h"
Tom Sepez37458412015-10-06 11:33:46 -07008
Dan Sinclair4b172c42017-10-23 11:22:31 -04009#include <map>
10#include <memory>
Tom Sepeza7757232017-04-18 11:10:39 -070011#include <utility>
Dan Sinclair3ebd1212016-03-09 09:59:23 -050012#include <vector>
13
Dan Sinclaircfb19442017-04-20 13:13:04 -040014#include "core/fxcrt/fx_extension.h"
Tom Sepez41d04e12018-10-30 22:07:36 +000015#include "fxjs/cfx_globaldata.h"
16#include "fxjs/cfx_keyvalue.h"
Dan Sinclaire0345a42017-10-30 20:20:42 +000017#include "fxjs/cjs_event_context.h"
Tom Sepez7dbb85b2019-06-11 19:49:00 +000018#include "fxjs/cjs_eventrecorder.h"
Dan Sinclaire0345a42017-10-30 20:20:42 +000019#include "fxjs/cjs_object.h"
Tom Sepez221f0b32018-06-04 22:11:27 +000020#include "fxjs/js_define.h"
Dan Sinclaire0345a42017-10-30 20:20:42 +000021#include "fxjs/js_resources.h"
Lei Zhang99f5bbb2018-10-09 21:31:28 +000022#include "third_party/base/ptr_util.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070023
Dan Sinclair4b172c42017-10-23 11:22:31 -040024namespace {
25
Adam Klein4c451ba2018-01-17 21:06:27 +000026WideString PropFromV8Prop(v8::Isolate* pIsolate,
27 v8::Local<v8::String> property) {
28 v8::String::Utf8Value utf8_value(pIsolate, property);
Dan Sinclair8f524d62017-10-25 13:30:31 -040029 return WideString::FromUTF8(ByteStringView(*utf8_value, utf8_value.length()));
30}
31
Dan Sinclair4b172c42017-10-23 11:22:31 -040032template <class Alt>
33void JSSpecialPropQuery(const char*,
34 v8::Local<v8::String> property,
35 const v8::PropertyCallbackInfo<v8::Integer>& info) {
Tom Sepez82999fa2018-07-16 22:17:46 +000036 auto pObj = JSGetObject<Alt>(info.Holder());
Lei Zhang6aa21902018-07-12 13:15:11 +000037 if (!pObj)
Dan Sinclair4b172c42017-10-23 11:22:31 -040038 return;
39
Lei Zhang6aa21902018-07-12 13:15:11 +000040 CJS_Runtime* pRuntime = pObj->GetRuntime();
Tom Sepezddaa40f2018-06-06 18:30:15 +000041 if (!pRuntime)
42 return;
43
Tom Sepez3a6d0582018-08-17 19:28:52 +000044 CJS_Result result =
Lei Zhang6aa21902018-07-12 13:15:11 +000045 pObj->QueryProperty(PropFromV8Prop(info.GetIsolate(), property).c_str());
Tom Sepezddaa40f2018-06-06 18:30:15 +000046
Dan Sinclair8f524d62017-10-25 13:30:31 -040047 info.GetReturnValue().Set(!result.HasError() ? 4 : 0);
Dan Sinclair4b172c42017-10-23 11:22:31 -040048}
49
50template <class Alt>
51void JSSpecialPropGet(const char* class_name,
52 v8::Local<v8::String> property,
53 const v8::PropertyCallbackInfo<v8::Value>& info) {
Tom Sepez82999fa2018-07-16 22:17:46 +000054 auto pObj = JSGetObject<Alt>(info.Holder());
Lei Zhang6aa21902018-07-12 13:15:11 +000055 if (!pObj)
Dan Sinclair4b172c42017-10-23 11:22:31 -040056 return;
57
Lei Zhang6aa21902018-07-12 13:15:11 +000058 CJS_Runtime* pRuntime = pObj->GetRuntime();
Tom Sepezddaa40f2018-06-06 18:30:15 +000059 if (!pRuntime)
60 return;
61
Tom Sepez3a6d0582018-08-17 19:28:52 +000062 CJS_Result result = pObj->GetProperty(
Adam Klein4c451ba2018-01-17 21:06:27 +000063 pRuntime, PropFromV8Prop(info.GetIsolate(), property).c_str());
Tom Sepezddaa40f2018-06-06 18:30:15 +000064
Dan Sinclair8f524d62017-10-25 13:30:31 -040065 if (result.HasError()) {
66 pRuntime->Error(
67 JSFormatErrorString(class_name, "GetProperty", result.Error()));
Dan Sinclair4b172c42017-10-23 11:22:31 -040068 return;
69 }
Dan Sinclair8f524d62017-10-25 13:30:31 -040070 if (result.HasReturn())
71 info.GetReturnValue().Set(result.Return());
Dan Sinclair4b172c42017-10-23 11:22:31 -040072}
73
74template <class Alt>
75void JSSpecialPropPut(const char* class_name,
76 v8::Local<v8::String> property,
77 v8::Local<v8::Value> value,
78 const v8::PropertyCallbackInfo<v8::Value>& info) {
Tom Sepez82999fa2018-07-16 22:17:46 +000079 auto pObj = JSGetObject<Alt>(info.Holder());
Lei Zhang6aa21902018-07-12 13:15:11 +000080 if (!pObj)
Dan Sinclair4b172c42017-10-23 11:22:31 -040081 return;
82
Lei Zhang6aa21902018-07-12 13:15:11 +000083 CJS_Runtime* pRuntime = pObj->GetRuntime();
Tom Sepezddaa40f2018-06-06 18:30:15 +000084 if (!pRuntime)
85 return;
86
Tom Sepez3a6d0582018-08-17 19:28:52 +000087 CJS_Result result = pObj->SetProperty(
Adam Klein4c451ba2018-01-17 21:06:27 +000088 pRuntime, PropFromV8Prop(info.GetIsolate(), property).c_str(), value);
Tom Sepezddaa40f2018-06-06 18:30:15 +000089
Dan Sinclair8f524d62017-10-25 13:30:31 -040090 if (result.HasError()) {
91 pRuntime->Error(
92 JSFormatErrorString(class_name, "PutProperty", result.Error()));
93 }
Dan Sinclair4b172c42017-10-23 11:22:31 -040094}
95
96template <class Alt>
97void JSSpecialPropDel(const char* class_name,
98 v8::Local<v8::String> property,
99 const v8::PropertyCallbackInfo<v8::Boolean>& info) {
Tom Sepez82999fa2018-07-16 22:17:46 +0000100 auto pObj = JSGetObject<Alt>(info.Holder());
Lei Zhang6aa21902018-07-12 13:15:11 +0000101 if (!pObj)
Dan Sinclair4b172c42017-10-23 11:22:31 -0400102 return;
103
Lei Zhang6aa21902018-07-12 13:15:11 +0000104 CJS_Runtime* pRuntime = pObj->GetRuntime();
Tom Sepezddaa40f2018-06-06 18:30:15 +0000105 if (!pRuntime)
106 return;
107
Tom Sepez3a6d0582018-08-17 19:28:52 +0000108 CJS_Result result = pObj->DelProperty(
Adam Klein4c451ba2018-01-17 21:06:27 +0000109 pRuntime, PropFromV8Prop(info.GetIsolate(), property).c_str());
Dan Sinclair8f524d62017-10-25 13:30:31 -0400110 if (result.HasError()) {
111 // TODO(dsinclair): Should this set the pRuntime->Error result?
Henrique Nakashima11506302017-12-06 22:09:40 +0000112 // ByteString cbName =
113 // ByteString::Format("%s.%s", class_name, "DelProperty");
Dan Sinclair4b172c42017-10-23 11:22:31 -0400114 }
115}
116
Lei Zhang5b346562018-08-28 23:36:08 +0000117template <class T>
118v8::Local<v8::String> GetV8StringFromProperty(v8::Local<v8::Name> property,
119 const T& info) {
120 return property->ToString(info.GetIsolate()->GetCurrentContext())
121 .ToLocalChecked();
122}
123
Dan Sinclair4b172c42017-10-23 11:22:31 -0400124} // namespace
125
Tom Sepez4a463d52018-11-07 22:32:41 +0000126CJS_Global::JSGlobalData::JSGlobalData() = default;
Dan Sinclairf7435522018-02-05 22:27:22 +0000127
Tom Sepez4a463d52018-11-07 22:32:41 +0000128CJS_Global::JSGlobalData::~JSGlobalData() = default;
Dan Sinclairf7435522018-02-05 22:27:22 +0000129
Dan Sinclairc94a7932017-10-26 16:48:57 -0400130const JSMethodSpec CJS_Global::MethodSpecs[] = {
Dan Sinclair909fa2d2017-12-12 01:53:28 +0000131 {"setPersistent", setPersistent_static}};
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700132
Dan Sinclairef299532017-10-26 16:48:30 -0400133int CJS_Global::ObjDefnID = -1;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700134
Dan Sinclair4b172c42017-10-23 11:22:31 -0400135// static
136void CJS_Global::setPersistent_static(
137 const v8::FunctionCallbackInfo<v8::Value>& info) {
Dan Sinclairf7435522018-02-05 22:27:22 +0000138 JSMethod<CJS_Global, &CJS_Global::setPersistent>("setPersistent", "global",
139 info);
Dan Sinclair4b172c42017-10-23 11:22:31 -0400140}
141
Dan Sinclairef299532017-10-26 16:48:30 -0400142// static
Dan Sinclair89d26c82017-10-26 12:21:28 -0400143void CJS_Global::queryprop_static(
Franziska Hinkelmann9a635e82018-03-21 12:58:25 +0000144 v8::Local<v8::Name> property,
Dan Sinclair89d26c82017-10-26 12:21:28 -0400145 const v8::PropertyCallbackInfo<v8::Integer>& info) {
Lei Zhang9bad2352018-06-28 13:29:33 +0000146 ASSERT(property->IsString());
Franziska Hinkelmann9a635e82018-03-21 12:58:25 +0000147 JSSpecialPropQuery<CJS_Global>(
148 "global",
Dan Elphickfd8dfdf2018-07-26 09:57:26 +0000149 v8::Local<v8::String>::New(info.GetIsolate(),
Lei Zhang5b346562018-08-28 23:36:08 +0000150 GetV8StringFromProperty(property, info)),
Franziska Hinkelmann9a635e82018-03-21 12:58:25 +0000151 info);
Dan Sinclair89d26c82017-10-26 12:21:28 -0400152}
153
Dan Sinclairef299532017-10-26 16:48:30 -0400154// static
Dan Sinclair89d26c82017-10-26 12:21:28 -0400155void CJS_Global::getprop_static(
Franziska Hinkelmann9a635e82018-03-21 12:58:25 +0000156 v8::Local<v8::Name> property,
Dan Sinclair89d26c82017-10-26 12:21:28 -0400157 const v8::PropertyCallbackInfo<v8::Value>& info) {
Lei Zhang9bad2352018-06-28 13:29:33 +0000158 ASSERT(property->IsString());
Franziska Hinkelmann9a635e82018-03-21 12:58:25 +0000159 JSSpecialPropGet<CJS_Global>(
160 "global",
Dan Elphickfd8dfdf2018-07-26 09:57:26 +0000161 v8::Local<v8::String>::New(info.GetIsolate(),
Lei Zhang5b346562018-08-28 23:36:08 +0000162 GetV8StringFromProperty(property, info)),
Franziska Hinkelmann9a635e82018-03-21 12:58:25 +0000163 info);
Dan Sinclair89d26c82017-10-26 12:21:28 -0400164}
165
Dan Sinclairef299532017-10-26 16:48:30 -0400166// static
Dan Sinclair89d26c82017-10-26 12:21:28 -0400167void CJS_Global::putprop_static(
Franziska Hinkelmann9a635e82018-03-21 12:58:25 +0000168 v8::Local<v8::Name> property,
Dan Sinclair89d26c82017-10-26 12:21:28 -0400169 v8::Local<v8::Value> value,
170 const v8::PropertyCallbackInfo<v8::Value>& info) {
Lei Zhang9bad2352018-06-28 13:29:33 +0000171 ASSERT(property->IsString());
Franziska Hinkelmann9a635e82018-03-21 12:58:25 +0000172 JSSpecialPropPut<CJS_Global>(
173 "global",
Dan Elphickfd8dfdf2018-07-26 09:57:26 +0000174 v8::Local<v8::String>::New(info.GetIsolate(),
Lei Zhang5b346562018-08-28 23:36:08 +0000175 GetV8StringFromProperty(property, info)),
Franziska Hinkelmann9a635e82018-03-21 12:58:25 +0000176 value, info);
Dan Sinclair89d26c82017-10-26 12:21:28 -0400177}
178
Dan Sinclairef299532017-10-26 16:48:30 -0400179// static
Dan Sinclair89d26c82017-10-26 12:21:28 -0400180void CJS_Global::delprop_static(
Franziska Hinkelmann9a635e82018-03-21 12:58:25 +0000181 v8::Local<v8::Name> property,
Dan Sinclair89d26c82017-10-26 12:21:28 -0400182 const v8::PropertyCallbackInfo<v8::Boolean>& info) {
Lei Zhang9bad2352018-06-28 13:29:33 +0000183 ASSERT(property->IsString());
Franziska Hinkelmann9a635e82018-03-21 12:58:25 +0000184 JSSpecialPropDel<CJS_Global>(
185 "global",
Dan Elphickfd8dfdf2018-07-26 09:57:26 +0000186 v8::Local<v8::String>::New(info.GetIsolate(),
Lei Zhang5b346562018-08-28 23:36:08 +0000187 GetV8StringFromProperty(property, info)),
Franziska Hinkelmann9a635e82018-03-21 12:58:25 +0000188 info);
Dan Sinclair89d26c82017-10-26 12:21:28 -0400189}
190
Dan Sinclairef299532017-10-26 16:48:30 -0400191// static
Dan Sinclair89d26c82017-10-26 12:21:28 -0400192void CJS_Global::DefineAllProperties(CFXJS_Engine* pEngine) {
193 pEngine->DefineObjAllProperties(
Dan Sinclairef299532017-10-26 16:48:30 -0400194 ObjDefnID, CJS_Global::queryprop_static, CJS_Global::getprop_static,
Dan Sinclair89d26c82017-10-26 12:21:28 -0400195 CJS_Global::putprop_static, CJS_Global::delprop_static);
196}
197
Dan Sinclairef299532017-10-26 16:48:30 -0400198// static
Lei Zhangad1f7b42018-07-11 13:04:43 +0000199int CJS_Global::GetObjDefnID() {
200 return ObjDefnID;
201}
202
203// static
Dan Sinclairbef4d3e2017-10-26 16:49:38 -0400204void CJS_Global::DefineJSObjects(CFXJS_Engine* pEngine) {
205 ObjDefnID = pEngine->DefineObj("global", FXJSOBJTYPE_STATIC,
Dan Sinclair998fee32018-02-05 21:43:19 +0000206 JSConstructor<CJS_Global>, JSDestructor);
Tom Sepez8b4ddeb2018-06-11 15:55:17 +0000207 DefineMethods(pEngine, ObjDefnID, MethodSpecs);
Dan Sinclair89d26c82017-10-26 12:21:28 -0400208 DefineAllProperties(pEngine);
209}
210
Tom Sepez36aae4f2018-06-04 19:44:37 +0000211CJS_Global::CJS_Global(v8::Local<v8::Object> pObject, CJS_Runtime* pRuntime)
Tom Sepez83b259e2018-06-08 20:43:55 +0000212 : CJS_Object(pObject, pRuntime) {
Lei Zhang5b346562018-08-28 23:36:08 +0000213 CPDFSDK_FormFillEnvironment* pFormFillEnv = GetRuntime()->GetFormFillEnv();
214 m_pFormFillEnv.Reset(pFormFillEnv);
Tom Sepezeccfe0e2018-11-01 16:34:52 +0000215 m_pGlobalData = CFX_GlobalData::GetRetainedInstance(nullptr);
Lei Zhang5b346562018-08-28 23:36:08 +0000216 UpdateGlobalPersistentVariables();
Tom Sepez83b259e2018-06-08 20:43:55 +0000217}
Dan Sinclair998fee32018-02-05 21:43:19 +0000218
Dan Sinclairf7435522018-02-05 22:27:22 +0000219CJS_Global::~CJS_Global() {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700220 DestroyGlobalPersisitentVariables();
Tom Sepezf4583622015-09-14 15:06:53 -0700221 m_pGlobalData->Release();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700222}
223
Tom Sepez3a6d0582018-08-17 19:28:52 +0000224CJS_Result CJS_Global::QueryProperty(const wchar_t* propname) {
Tom Sepez87ac6dc2018-11-30 23:10:17 +0000225 if (WideString(propname).EqualsASCII("setPersistent"))
226 return CJS_Result::Success();
227
228 return CJS_Result::Failure(JSMessage::kUnknownProperty);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700229}
230
Tom Sepez3a6d0582018-08-17 19:28:52 +0000231CJS_Result CJS_Global::DelProperty(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +0000232 const wchar_t* propname) {
Tom Sepez34dab072018-08-08 17:49:02 +0000233 auto it = m_MapGlobal.find(WideString(propname).ToDefANSI());
Tom Sepeza7757232017-04-18 11:10:39 -0700234 if (it == m_MapGlobal.end())
Tom Sepez3a6d0582018-08-17 19:28:52 +0000235 return CJS_Result::Failure(JSMessage::kUnknownProperty);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700236
tsepez4cf55152016-11-02 14:37:54 -0700237 it->second->bDeleted = true;
Tom Sepez3a6d0582018-08-17 19:28:52 +0000238 return CJS_Result::Success();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700239}
240
Tom Sepez3a6d0582018-08-17 19:28:52 +0000241CJS_Result CJS_Global::GetProperty(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +0000242 const wchar_t* propname) {
Tom Sepez34dab072018-08-08 17:49:02 +0000243 auto it = m_MapGlobal.find(WideString(propname).ToDefANSI());
dan sinclair5daf07a2017-10-24 21:46:57 -0400244 if (it == m_MapGlobal.end())
Tom Sepez3a6d0582018-08-17 19:28:52 +0000245 return CJS_Result::Success();
dan sinclaircbe23db2017-10-19 14:29:33 -0400246
247 JSGlobalData* pData = it->second.get();
dan sinclair5daf07a2017-10-24 21:46:57 -0400248 if (pData->bDeleted)
Tom Sepez3a6d0582018-08-17 19:28:52 +0000249 return CJS_Result::Success();
dan sinclaircbe23db2017-10-19 14:29:33 -0400250
251 switch (pData->nType) {
Tom Sepez4a463d52018-11-07 22:32:41 +0000252 case CFX_Value::DataType::NUMBER:
Tom Sepez3a6d0582018-08-17 19:28:52 +0000253 return CJS_Result::Success(pRuntime->NewNumber(pData->dData));
Tom Sepez4a463d52018-11-07 22:32:41 +0000254 case CFX_Value::DataType::BOOLEAN:
Tom Sepez3a6d0582018-08-17 19:28:52 +0000255 return CJS_Result::Success(pRuntime->NewBoolean(pData->bData));
Tom Sepez4a463d52018-11-07 22:32:41 +0000256 case CFX_Value::DataType::STRING:
Tom Sepez3a6d0582018-08-17 19:28:52 +0000257 return CJS_Result::Success(pRuntime->NewString(
Tom Sepez40317142018-11-27 00:18:33 +0000258 WideString::FromDefANSI(pData->sData.AsStringView()).AsStringView()));
Tom Sepez4a463d52018-11-07 22:32:41 +0000259 case CFX_Value::DataType::OBJECT:
Tom Sepez3a6d0582018-08-17 19:28:52 +0000260 return CJS_Result::Success(
Dan Sinclair8f524d62017-10-25 13:30:31 -0400261 v8::Local<v8::Object>::New(pRuntime->GetIsolate(), pData->pData));
Tom Sepez4a463d52018-11-07 22:32:41 +0000262 case CFX_Value::DataType::NULLOBJ:
Tom Sepez3a6d0582018-08-17 19:28:52 +0000263 return CJS_Result::Success(pRuntime->NewNull());
dan sinclaircbe23db2017-10-19 14:29:33 -0400264 default:
265 break;
266 }
Tom Sepez3a6d0582018-08-17 19:28:52 +0000267 return CJS_Result::Failure(JSMessage::kObjectTypeError);
dan sinclaircbe23db2017-10-19 14:29:33 -0400268}
269
Tom Sepez3a6d0582018-08-17 19:28:52 +0000270CJS_Result CJS_Global::SetProperty(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +0000271 const wchar_t* propname,
272 v8::Local<v8::Value> vp) {
Tom Sepez34dab072018-08-08 17:49:02 +0000273 ByteString sPropName = WideString(propname).ToDefANSI();
dan sinclair80435cb2017-10-24 21:40:24 -0400274 if (vp->IsNumber()) {
Tom Sepez4a463d52018-11-07 22:32:41 +0000275 return SetGlobalVariables(sPropName, CFX_Value::DataType::NUMBER,
Tom Sepez306ebab2018-12-03 22:12:55 +0000276 pRuntime->ToDouble(vp), false, ByteString(),
Dan Sinclair3cac3602017-10-24 15:15:27 -0400277 v8::Local<v8::Object>(), false);
278 }
dan sinclair80435cb2017-10-24 21:40:24 -0400279 if (vp->IsBoolean()) {
Tom Sepez4a463d52018-11-07 22:32:41 +0000280 return SetGlobalVariables(sPropName, CFX_Value::DataType::BOOLEAN, 0,
Tom Sepez306ebab2018-12-03 22:12:55 +0000281 pRuntime->ToBoolean(vp), ByteString(),
Dan Sinclair3cac3602017-10-24 15:15:27 -0400282 v8::Local<v8::Object>(), false);
283 }
dan sinclair80435cb2017-10-24 21:40:24 -0400284 if (vp->IsString()) {
Tom Sepez4a463d52018-11-07 22:32:41 +0000285 return SetGlobalVariables(sPropName, CFX_Value::DataType::STRING, 0, false,
286 pRuntime->ToWideString(vp).ToDefANSI(),
Tom Sepez34dab072018-08-08 17:49:02 +0000287 v8::Local<v8::Object>(), false);
Dan Sinclair3cac3602017-10-24 15:15:27 -0400288 }
dan sinclair80435cb2017-10-24 21:40:24 -0400289 if (vp->IsObject()) {
Tom Sepez4a463d52018-11-07 22:32:41 +0000290 return SetGlobalVariables(sPropName, CFX_Value::DataType::OBJECT, 0, false,
Tom Sepez306ebab2018-12-03 22:12:55 +0000291 ByteString(), pRuntime->ToObject(vp), false);
Dan Sinclair3cac3602017-10-24 15:15:27 -0400292 }
dan sinclair80435cb2017-10-24 21:40:24 -0400293 if (vp->IsNull()) {
Tom Sepez4a463d52018-11-07 22:32:41 +0000294 return SetGlobalVariables(sPropName, CFX_Value::DataType::NULLOBJ, 0, false,
Tom Sepez306ebab2018-12-03 22:12:55 +0000295 ByteString(), v8::Local<v8::Object>(), false);
Dan Sinclair3cac3602017-10-24 15:15:27 -0400296 }
dan sinclair80435cb2017-10-24 21:40:24 -0400297 if (vp->IsUndefined()) {
Dan Sinclair3cac3602017-10-24 15:15:27 -0400298 DelProperty(pRuntime, propname);
Tom Sepez3a6d0582018-08-17 19:28:52 +0000299 return CJS_Result::Success();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700300 }
Tom Sepez3a6d0582018-08-17 19:28:52 +0000301 return CJS_Result::Failure(JSMessage::kObjectTypeError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700302}
303
Tom Sepez3a6d0582018-08-17 19:28:52 +0000304CJS_Result CJS_Global::setPersistent(
dan sinclair80435cb2017-10-24 21:40:24 -0400305 CJS_Runtime* pRuntime,
Dan Sinclair8f524d62017-10-25 13:30:31 -0400306 const std::vector<v8::Local<v8::Value>>& params) {
307 if (params.size() != 2)
Tom Sepez3a6d0582018-08-17 19:28:52 +0000308 return CJS_Result::Failure(JSMessage::kParamError);
Dan Sinclair8f524d62017-10-25 13:30:31 -0400309
Tom Sepez34dab072018-08-08 17:49:02 +0000310 auto it = m_MapGlobal.find(pRuntime->ToWideString(params[0]).ToDefANSI());
Dan Sinclair8f524d62017-10-25 13:30:31 -0400311 if (it == m_MapGlobal.end() || it->second->bDeleted)
Tom Sepez3a6d0582018-08-17 19:28:52 +0000312 return CJS_Result::Failure(JSMessage::kGlobalNotFoundError);
Dan Sinclair8f524d62017-10-25 13:30:31 -0400313
dan sinclair80435cb2017-10-24 21:40:24 -0400314 it->second->bPersistent = pRuntime->ToBoolean(params[1]);
Tom Sepez3a6d0582018-08-17 19:28:52 +0000315 return CJS_Result::Success();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700316}
317
Dan Sinclairf7435522018-02-05 22:27:22 +0000318void CJS_Global::UpdateGlobalPersistentVariables() {
Tom Sepez6ffd8402018-06-06 20:51:04 +0000319 CJS_Runtime* pRuntime = GetRuntime();
320 if (!pRuntime)
321 return;
tsepezb4694242016-08-15 16:44:55 -0700322
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700323 for (int i = 0, sz = m_pGlobalData->GetSize(); i < sz; i++) {
Tom Sepez41d04e12018-10-30 22:07:36 +0000324 CFX_GlobalData::Element* pData = m_pGlobalData->GetAt(i);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700325 switch (pData->data.nType) {
Tom Sepez4a463d52018-11-07 22:32:41 +0000326 case CFX_Value::DataType::NUMBER:
327 SetGlobalVariables(pData->data.sKey, CFX_Value::DataType::NUMBER,
Tom Sepez306ebab2018-12-03 22:12:55 +0000328 pData->data.dData, false, ByteString(),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700329 v8::Local<v8::Object>(), pData->bPersistent == 1);
Tom Sepezca610782018-12-13 18:01:04 +0000330 pRuntime->PutObjectProperty(ToV8Object(),
331 pData->data.sKey.AsStringView(),
332 pRuntime->NewNumber(pData->data.dData));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700333 break;
Tom Sepez4a463d52018-11-07 22:32:41 +0000334 case CFX_Value::DataType::BOOLEAN:
335 SetGlobalVariables(pData->data.sKey, CFX_Value::DataType::BOOLEAN, 0,
Tom Sepez306ebab2018-12-03 22:12:55 +0000336 pData->data.bData == 1, ByteString(),
337 v8::Local<v8::Object>(), pData->bPersistent == 1);
tsepeze6cf0132017-01-18 14:38:18 -0800338 pRuntime->PutObjectProperty(
Tom Sepezca610782018-12-13 18:01:04 +0000339 ToV8Object(), pData->data.sKey.AsStringView(),
tsepeze6cf0132017-01-18 14:38:18 -0800340 pRuntime->NewBoolean(pData->data.bData == 1));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700341 break;
Tom Sepez4a463d52018-11-07 22:32:41 +0000342 case CFX_Value::DataType::STRING:
343 SetGlobalVariables(pData->data.sKey, CFX_Value::DataType::STRING, 0,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700344 false, pData->data.sData, v8::Local<v8::Object>(),
345 pData->bPersistent == 1);
tsepeze6cf0132017-01-18 14:38:18 -0800346 pRuntime->PutObjectProperty(
Tom Sepezca610782018-12-13 18:01:04 +0000347 ToV8Object(), pData->data.sKey.AsStringView(),
Tom Sepez3ef02422018-11-26 23:52:33 +0000348 pRuntime->NewString(
349 WideString::FromUTF8(pData->data.sData.AsStringView())
350 .AsStringView()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700351 break;
Tom Sepez4a463d52018-11-07 22:32:41 +0000352 case CFX_Value::DataType::OBJECT: {
Tom Sepez9ad9a5f2018-02-07 21:07:24 +0000353 v8::Local<v8::Object> pObj = pRuntime->NewObject();
Tom Sepez63b2fc72017-08-14 16:24:29 -0700354 if (!pObj.IsEmpty()) {
355 PutObjectProperty(pObj, &pData->data);
Tom Sepez4a463d52018-11-07 22:32:41 +0000356 SetGlobalVariables(pData->data.sKey, CFX_Value::DataType::OBJECT, 0,
Tom Sepez306ebab2018-12-03 22:12:55 +0000357 false, ByteString(), pObj,
358 pData->bPersistent == 1);
Tom Sepezca610782018-12-13 18:01:04 +0000359 pRuntime->PutObjectProperty(ToV8Object(),
360 pData->data.sKey.AsStringView(), pObj);
Tom Sepez63b2fc72017-08-14 16:24:29 -0700361 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700362 } break;
Tom Sepez4a463d52018-11-07 22:32:41 +0000363 case CFX_Value::DataType::NULLOBJ:
364 SetGlobalVariables(pData->data.sKey, CFX_Value::DataType::NULLOBJ, 0,
Tom Sepez306ebab2018-12-03 22:12:55 +0000365 false, ByteString(), v8::Local<v8::Object>(),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700366 pData->bPersistent == 1);
Tom Sepez3ef02422018-11-26 23:52:33 +0000367 pRuntime->PutObjectProperty(
Tom Sepezca610782018-12-13 18:01:04 +0000368 ToV8Object(), pData->data.sKey.AsStringView(), pRuntime->NewNull());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700369 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700370 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700371 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700372}
373
Dan Sinclairf7435522018-02-05 22:27:22 +0000374void CJS_Global::CommitGlobalPersisitentVariables(CJS_Runtime* pRuntime) {
Tom Sepeza7757232017-04-18 11:10:39 -0700375 for (const auto& iter : m_MapGlobal) {
Ryan Harrison275e2602017-09-18 14:23:18 -0400376 ByteString name = iter.first;
Tom Sepeza7757232017-04-18 11:10:39 -0700377 JSGlobalData* pData = iter.second.get();
Tom Sepez09d33bc2015-08-19 09:49:24 -0700378 if (pData->bDeleted) {
379 m_pGlobalData->DeleteGlobalVariable(name);
Tom Sepeza7757232017-04-18 11:10:39 -0700380 continue;
381 }
382 switch (pData->nType) {
Tom Sepez4a463d52018-11-07 22:32:41 +0000383 case CFX_Value::DataType::NUMBER:
Tom Sepeza7757232017-04-18 11:10:39 -0700384 m_pGlobalData->SetGlobalVariableNumber(name, pData->dData);
385 m_pGlobalData->SetGlobalVariablePersistent(name, pData->bPersistent);
386 break;
Tom Sepez4a463d52018-11-07 22:32:41 +0000387 case CFX_Value::DataType::BOOLEAN:
Tom Sepeza7757232017-04-18 11:10:39 -0700388 m_pGlobalData->SetGlobalVariableBoolean(name, pData->bData);
389 m_pGlobalData->SetGlobalVariablePersistent(name, pData->bPersistent);
390 break;
Tom Sepez4a463d52018-11-07 22:32:41 +0000391 case CFX_Value::DataType::STRING:
Tom Sepeza7757232017-04-18 11:10:39 -0700392 m_pGlobalData->SetGlobalVariableString(name, pData->sData);
393 m_pGlobalData->SetGlobalVariablePersistent(name, pData->bPersistent);
394 break;
Tom Sepez4a463d52018-11-07 22:32:41 +0000395 case CFX_Value::DataType::OBJECT: {
Tom Sepez41d04e12018-10-30 22:07:36 +0000396 CFX_GlobalArray array;
Dan Sinclairf7435522018-02-05 22:27:22 +0000397 v8::Local<v8::Object> obj =
398 v8::Local<v8::Object>::New(GetIsolate(), pData->pData);
Lei Zhangb1a4db52018-07-11 13:02:54 +0000399 ObjectToArray(pRuntime, obj, &array);
Tom Sepez436c9f12018-11-05 18:20:23 +0000400 m_pGlobalData->SetGlobalVariableObject(name, std::move(array));
Tom Sepeza7757232017-04-18 11:10:39 -0700401 m_pGlobalData->SetGlobalVariablePersistent(name, pData->bPersistent);
402 } break;
Tom Sepez4a463d52018-11-07 22:32:41 +0000403 case CFX_Value::DataType::NULLOBJ:
Tom Sepeza7757232017-04-18 11:10:39 -0700404 m_pGlobalData->SetGlobalVariableNull(name);
405 m_pGlobalData->SetGlobalVariablePersistent(name, pData->bPersistent);
406 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700407 }
408 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700409}
410
Dan Sinclairf7435522018-02-05 22:27:22 +0000411void CJS_Global::ObjectToArray(CJS_Runtime* pRuntime,
412 v8::Local<v8::Object> pObj,
Tom Sepez41d04e12018-10-30 22:07:36 +0000413 CFX_GlobalArray* pArray) {
Ryan Harrison275e2602017-09-18 14:23:18 -0400414 std::vector<WideString> pKeyList = pRuntime->GetObjectPropertyNames(pObj);
tsepezd0b6ed12016-08-11 19:50:57 -0700415 for (const auto& ws : pKeyList) {
Tom Sepezb4c95fe2018-11-27 01:09:44 +0000416 ByteString sKey = ws.ToUTF8();
Tom Sepezca610782018-12-13 18:01:04 +0000417 v8::Local<v8::Value> v =
418 pRuntime->GetObjectProperty(pObj, sKey.AsStringView());
Dan Sinclair3cac3602017-10-24 15:15:27 -0400419 if (v->IsNumber()) {
Tom Sepez41d04e12018-10-30 22:07:36 +0000420 auto pObjElement = pdfium::MakeUnique<CFX_KeyValue>();
Tom Sepez4a463d52018-11-07 22:32:41 +0000421 pObjElement->nType = CFX_Value::DataType::NUMBER;
Dan Sinclair3cac3602017-10-24 15:15:27 -0400422 pObjElement->sKey = sKey;
423 pObjElement->dData = pRuntime->ToDouble(v);
Tom Sepez8abd0df2018-09-14 23:07:11 +0000424 pArray->Add(std::move(pObjElement));
Dan Sinclair3cac3602017-10-24 15:15:27 -0400425 continue;
426 }
427 if (v->IsBoolean()) {
Tom Sepez41d04e12018-10-30 22:07:36 +0000428 auto pObjElement = pdfium::MakeUnique<CFX_KeyValue>();
Tom Sepez4a463d52018-11-07 22:32:41 +0000429 pObjElement->nType = CFX_Value::DataType::BOOLEAN;
Dan Sinclair3cac3602017-10-24 15:15:27 -0400430 pObjElement->sKey = sKey;
431 pObjElement->dData = pRuntime->ToBoolean(v);
Tom Sepez8abd0df2018-09-14 23:07:11 +0000432 pArray->Add(std::move(pObjElement));
Dan Sinclair3cac3602017-10-24 15:15:27 -0400433 continue;
434 }
435 if (v->IsString()) {
Tom Sepez34dab072018-08-08 17:49:02 +0000436 ByteString sValue = pRuntime->ToWideString(v).ToDefANSI();
Tom Sepez41d04e12018-10-30 22:07:36 +0000437 auto pObjElement = pdfium::MakeUnique<CFX_KeyValue>();
Tom Sepez4a463d52018-11-07 22:32:41 +0000438 pObjElement->nType = CFX_Value::DataType::STRING;
Dan Sinclair3cac3602017-10-24 15:15:27 -0400439 pObjElement->sKey = sKey;
440 pObjElement->sData = sValue;
Tom Sepez8abd0df2018-09-14 23:07:11 +0000441 pArray->Add(std::move(pObjElement));
Dan Sinclair3cac3602017-10-24 15:15:27 -0400442 continue;
443 }
444 if (v->IsObject()) {
Tom Sepez41d04e12018-10-30 22:07:36 +0000445 auto pObjElement = pdfium::MakeUnique<CFX_KeyValue>();
Tom Sepez4a463d52018-11-07 22:32:41 +0000446 pObjElement->nType = CFX_Value::DataType::OBJECT;
Dan Sinclair3cac3602017-10-24 15:15:27 -0400447 pObjElement->sKey = sKey;
Lei Zhangb1a4db52018-07-11 13:02:54 +0000448 ObjectToArray(pRuntime, pRuntime->ToObject(v), &pObjElement->objData);
Tom Sepez8abd0df2018-09-14 23:07:11 +0000449 pArray->Add(std::move(pObjElement));
Dan Sinclair3cac3602017-10-24 15:15:27 -0400450 continue;
451 }
452 if (v->IsNull()) {
Tom Sepez41d04e12018-10-30 22:07:36 +0000453 auto pObjElement = pdfium::MakeUnique<CFX_KeyValue>();
Tom Sepez4a463d52018-11-07 22:32:41 +0000454 pObjElement->nType = CFX_Value::DataType::NULLOBJ;
Dan Sinclair3cac3602017-10-24 15:15:27 -0400455 pObjElement->sKey = sKey;
Tom Sepez8abd0df2018-09-14 23:07:11 +0000456 pArray->Add(std::move(pObjElement));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700457 }
458 }
459}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700460
Dan Sinclairf7435522018-02-05 22:27:22 +0000461void CJS_Global::PutObjectProperty(v8::Local<v8::Object> pObj,
Tom Sepez41d04e12018-10-30 22:07:36 +0000462 CFX_KeyValue* pData) {
Tom Sepez6ffd8402018-06-06 20:51:04 +0000463 CJS_Runtime* pRuntime = GetRuntime();
464 if (pRuntime)
465 return;
tsepezb4694242016-08-15 16:44:55 -0700466
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700467 for (int i = 0, sz = pData->objData.Count(); i < sz; i++) {
Tom Sepez41d04e12018-10-30 22:07:36 +0000468 CFX_KeyValue* pObjData = pData->objData.GetAt(i);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700469 switch (pObjData->nType) {
Tom Sepez4a463d52018-11-07 22:32:41 +0000470 case CFX_Value::DataType::NUMBER:
Tom Sepezca610782018-12-13 18:01:04 +0000471 pRuntime->PutObjectProperty(pObj, pObjData->sKey.AsStringView(),
472 pRuntime->NewNumber(pObjData->dData));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700473 break;
Tom Sepez4a463d52018-11-07 22:32:41 +0000474 case CFX_Value::DataType::BOOLEAN:
Tom Sepezca610782018-12-13 18:01:04 +0000475 pRuntime->PutObjectProperty(pObj, pObjData->sKey.AsStringView(),
476 pRuntime->NewBoolean(pObjData->bData == 1));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700477 break;
Tom Sepez4a463d52018-11-07 22:32:41 +0000478 case CFX_Value::DataType::STRING:
tsepeze6cf0132017-01-18 14:38:18 -0800479 pRuntime->PutObjectProperty(
Tom Sepezca610782018-12-13 18:01:04 +0000480 pObj, pObjData->sKey.AsStringView(),
Tom Sepez3ef02422018-11-26 23:52:33 +0000481 pRuntime->NewString(
482 WideString::FromUTF8(pObjData->sData.AsStringView())
483 .AsStringView()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700484 break;
Tom Sepez4a463d52018-11-07 22:32:41 +0000485 case CFX_Value::DataType::OBJECT: {
Tom Sepez9ad9a5f2018-02-07 21:07:24 +0000486 v8::Local<v8::Object> pNewObj = pRuntime->NewObject();
Tom Sepez63b2fc72017-08-14 16:24:29 -0700487 if (!pNewObj.IsEmpty()) {
488 PutObjectProperty(pNewObj, pObjData);
Tom Sepezca610782018-12-13 18:01:04 +0000489 pRuntime->PutObjectProperty(pObj, pObjData->sKey.AsStringView(),
490 pNewObj);
Tom Sepez63b2fc72017-08-14 16:24:29 -0700491 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700492 } break;
Tom Sepez4a463d52018-11-07 22:32:41 +0000493 case CFX_Value::DataType::NULLOBJ:
Tom Sepezca610782018-12-13 18:01:04 +0000494 pRuntime->PutObjectProperty(pObj, pObjData->sKey.AsStringView(),
495 pRuntime->NewNull());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700496 break;
497 }
498 }
499}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700500
Dan Sinclairf7435522018-02-05 22:27:22 +0000501void CJS_Global::DestroyGlobalPersisitentVariables() {
Tom Sepeza7757232017-04-18 11:10:39 -0700502 m_MapGlobal.clear();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700503}
504
Tom Sepez3a6d0582018-08-17 19:28:52 +0000505CJS_Result CJS_Global::SetGlobalVariables(const ByteString& propname,
Tom Sepez4a463d52018-11-07 22:32:41 +0000506 CFX_Value::DataType nType,
Dan Sinclairf7435522018-02-05 22:27:22 +0000507 double dData,
508 bool bData,
509 const ByteString& sData,
510 v8::Local<v8::Object> pData,
511 bool bDefaultPersistent) {
tsepezb4c9f3f2016-04-13 15:41:21 -0700512 if (propname.IsEmpty())
Tom Sepez3a6d0582018-08-17 19:28:52 +0000513 return CJS_Result::Failure(JSMessage::kUnknownProperty);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700514
Tom Sepeza7757232017-04-18 11:10:39 -0700515 auto it = m_MapGlobal.find(propname);
516 if (it != m_MapGlobal.end()) {
517 JSGlobalData* pTemp = it->second.get();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700518 if (pTemp->bDeleted || pTemp->nType != nType) {
519 pTemp->dData = 0;
520 pTemp->bData = 0;
Lei Zhangfe2cd4d2017-11-22 20:04:12 +0000521 pTemp->sData.clear();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700522 pTemp->nType = nType;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700523 }
tsepez4cf55152016-11-02 14:37:54 -0700524 pTemp->bDeleted = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700525 switch (nType) {
Tom Sepez4a463d52018-11-07 22:32:41 +0000526 case CFX_Value::DataType::NUMBER:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700527 pTemp->dData = dData;
Tom Sepeza7757232017-04-18 11:10:39 -0700528 break;
Tom Sepez4a463d52018-11-07 22:32:41 +0000529 case CFX_Value::DataType::BOOLEAN:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700530 pTemp->bData = bData;
Tom Sepeza7757232017-04-18 11:10:39 -0700531 break;
Tom Sepez4a463d52018-11-07 22:32:41 +0000532 case CFX_Value::DataType::STRING:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700533 pTemp->sData = sData;
Tom Sepeza7757232017-04-18 11:10:39 -0700534 break;
Tom Sepez4a463d52018-11-07 22:32:41 +0000535 case CFX_Value::DataType::OBJECT:
Tom Sepez371379d2015-11-06 08:29:39 -0800536 pTemp->pData.Reset(pData->GetIsolate(), pData);
Tom Sepeza7757232017-04-18 11:10:39 -0700537 break;
Tom Sepez4a463d52018-11-07 22:32:41 +0000538 case CFX_Value::DataType::NULLOBJ:
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700539 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700540 default:
Tom Sepez3a6d0582018-08-17 19:28:52 +0000541 return CJS_Result::Failure(JSMessage::kObjectTypeError);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700542 }
Tom Sepez3a6d0582018-08-17 19:28:52 +0000543 return CJS_Result::Success();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700544 }
545
Tom Sepeza7757232017-04-18 11:10:39 -0700546 auto pNewData = pdfium::MakeUnique<JSGlobalData>();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700547 switch (nType) {
Tom Sepez4a463d52018-11-07 22:32:41 +0000548 case CFX_Value::DataType::NUMBER:
549 pNewData->nType = CFX_Value::DataType::NUMBER;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700550 pNewData->dData = dData;
551 pNewData->bPersistent = bDefaultPersistent;
Tom Sepeza7757232017-04-18 11:10:39 -0700552 break;
Tom Sepez4a463d52018-11-07 22:32:41 +0000553 case CFX_Value::DataType::BOOLEAN:
554 pNewData->nType = CFX_Value::DataType::BOOLEAN;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700555 pNewData->bData = bData;
556 pNewData->bPersistent = bDefaultPersistent;
Tom Sepeza7757232017-04-18 11:10:39 -0700557 break;
Tom Sepez4a463d52018-11-07 22:32:41 +0000558 case CFX_Value::DataType::STRING:
559 pNewData->nType = CFX_Value::DataType::STRING;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700560 pNewData->sData = sData;
561 pNewData->bPersistent = bDefaultPersistent;
Tom Sepeza7757232017-04-18 11:10:39 -0700562 break;
Tom Sepez4a463d52018-11-07 22:32:41 +0000563 case CFX_Value::DataType::OBJECT:
564 pNewData->nType = CFX_Value::DataType::OBJECT;
Tom Sepez371379d2015-11-06 08:29:39 -0800565 pNewData->pData.Reset(pData->GetIsolate(), pData);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700566 pNewData->bPersistent = bDefaultPersistent;
Tom Sepeza7757232017-04-18 11:10:39 -0700567 break;
Tom Sepez4a463d52018-11-07 22:32:41 +0000568 case CFX_Value::DataType::NULLOBJ:
569 pNewData->nType = CFX_Value::DataType::NULLOBJ;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700570 pNewData->bPersistent = bDefaultPersistent;
Tom Sepeza7757232017-04-18 11:10:39 -0700571 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700572 default:
Tom Sepez3a6d0582018-08-17 19:28:52 +0000573 return CJS_Result::Failure(JSMessage::kObjectTypeError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700574 }
Tom Sepeza7757232017-04-18 11:10:39 -0700575 m_MapGlobal[propname] = std::move(pNewData);
Tom Sepez3a6d0582018-08-17 19:28:52 +0000576 return CJS_Result::Success();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700577}