Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Side by Side Diff: fpdfsdk/src/jsapi/fxjs_v8.cpp

Issue 1332973002: Remove some abstractions in fxjs_v8.h. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Remove implicit cast operator from CJS_Runtime. Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « fpdfsdk/src/javascript/global.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "../../../core/include/fxcrt/fx_basic.h" 7 #include "../../../core/include/fxcrt/fx_basic.h"
8 #include "../../../core/include/fxcrt/fx_ext.h" 8 #include "../../../core/include/fxcrt/fx_ext.h"
9 #include "../../include/jsapi/fxjs_v8.h" 9 #include "../../include/jsapi/fxjs_v8.h"
10 #include "../../include/fsdk_define.h" 10 #include "../../include/fsdk_define.h"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 const wchar_t* objName; 68 const wchar_t* objName;
69 FXJSOBJTYPE objType; 69 FXJSOBJTYPE objType;
70 LP_CONSTRUCTOR m_pConstructor; 70 LP_CONSTRUCTOR m_pConstructor;
71 LP_DESTRUCTOR m_pDestructor; 71 LP_DESTRUCTOR m_pDestructor;
72 FX_BOOL m_bSetAsGlobalObject; 72 FX_BOOL m_bSetAsGlobalObject;
73 73
74 v8::Global<v8::ObjectTemplate> m_objTemplate; 74 v8::Global<v8::ObjectTemplate> m_objTemplate;
75 v8::Global<v8::Object> m_StaticObj; 75 v8::Global<v8::Object> m_StaticObj;
76 }; 76 };
77 77
78 int JS_DefineObj(IJS_Runtime* pJSRuntime, 78 int JS_DefineObj(v8::Isolate* pIsolate,
79 const wchar_t* sObjName, 79 const wchar_t* sObjName,
80 FXJSOBJTYPE eObjType, 80 FXJSOBJTYPE eObjType,
81 LP_CONSTRUCTOR pConstructor, 81 LP_CONSTRUCTOR pConstructor,
82 LP_DESTRUCTOR pDestructor) { 82 LP_DESTRUCTOR pDestructor) {
83 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; 83 v8::Isolate::Scope isolate_scope(pIsolate);
84 v8::Isolate::Scope isolate_scope(isolate); 84 v8::HandleScope handle_scope(pIsolate);
85 v8::HandleScope handle_scope(isolate); 85 CFX_PtrArray* pArray = (CFX_PtrArray*)pIsolate->GetData(g_embedderDataSlot);
86 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlot);
87 if (!pArray) { 86 if (!pArray) {
88 pArray = new CFX_PtrArray(); 87 pArray = new CFX_PtrArray();
89 isolate->SetData(g_embedderDataSlot, pArray); 88 pIsolate->SetData(g_embedderDataSlot, pArray);
90 } 89 }
91 CJS_ObjDefintion* pObjDef = new CJS_ObjDefintion(isolate, sObjName, eObjType, 90 CJS_ObjDefintion* pObjDef = new CJS_ObjDefintion(pIsolate, sObjName, eObjType,
92 pConstructor, pDestructor); 91 pConstructor, pDestructor);
93 pArray->Add(pObjDef); 92 pArray->Add(pObjDef);
94 return pArray->GetSize() - 1; 93 return pArray->GetSize() - 1;
95 } 94 }
96 95
97 int JS_DefineObjMethod(IJS_Runtime* pJSRuntime, 96 int JS_DefineObjMethod(v8::Isolate* pIsolate,
98 int nObjDefnID, 97 int nObjDefnID,
99 const wchar_t* sMethodName, 98 const wchar_t* sMethodName,
100 v8::FunctionCallback pMethodCall) { 99 v8::FunctionCallback pMethodCall) {
101 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; 100 v8::Isolate::Scope isolate_scope(pIsolate);
102 v8::Isolate::Scope isolate_scope(isolate); 101 v8::HandleScope handle_scope(pIsolate);
103 v8::HandleScope handle_scope(isolate);
104 102
105 CFX_WideString ws = CFX_WideString(sMethodName); 103 CFX_WideString ws = CFX_WideString(sMethodName);
106 CFX_ByteString bsMethodName = ws.UTF8Encode(); 104 CFX_ByteString bsMethodName = ws.UTF8Encode();
107 105
108 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlot); 106 CFX_PtrArray* pArray = (CFX_PtrArray*)pIsolate->GetData(g_embedderDataSlot);
109 if (!pArray) 107 if (!pArray)
110 return 0; 108 return 0;
111 109
112 if (nObjDefnID < 0 || nObjDefnID >= pArray->GetSize()) 110 if (nObjDefnID < 0 || nObjDefnID >= pArray->GetSize())
113 return 0; 111 return 0;
114 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID); 112 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID);
115 v8::Local<v8::ObjectTemplate> objTemp = 113 v8::Local<v8::ObjectTemplate> objTemp =
116 v8::Local<v8::ObjectTemplate>::New(isolate, pObjDef->m_objTemplate); 114 v8::Local<v8::ObjectTemplate>::New(pIsolate, pObjDef->m_objTemplate);
117 objTemp->Set(v8::String::NewFromUtf8(isolate, bsMethodName.c_str(), 115 objTemp->Set(
118 v8::NewStringType::kNormal) 116 v8::String::NewFromUtf8(pIsolate, bsMethodName.c_str(),
119 .ToLocalChecked(), 117 v8::NewStringType::kNormal).ToLocalChecked(),
120 v8::FunctionTemplate::New(isolate, pMethodCall), v8::ReadOnly); 118 v8::FunctionTemplate::New(pIsolate, pMethodCall), v8::ReadOnly);
121 pObjDef->m_objTemplate.Reset(isolate, objTemp); 119 pObjDef->m_objTemplate.Reset(pIsolate, objTemp);
122 return 0; 120 return 0;
123 } 121 }
124 122
125 int JS_DefineObjProperty(IJS_Runtime* pJSRuntime, 123 int JS_DefineObjProperty(v8::Isolate* pIsolate,
126 int nObjDefnID, 124 int nObjDefnID,
127 const wchar_t* sPropName, 125 const wchar_t* sPropName,
128 v8::AccessorGetterCallback pPropGet, 126 v8::AccessorGetterCallback pPropGet,
129 v8::AccessorSetterCallback pPropPut) { 127 v8::AccessorSetterCallback pPropPut) {
130 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; 128 v8::Isolate::Scope isolate_scope(pIsolate);
131 v8::Isolate::Scope isolate_scope(isolate); 129 v8::HandleScope handle_scope(pIsolate);
132 v8::HandleScope handle_scope(isolate);
133 130
134 CFX_WideString ws = CFX_WideString(sPropName); 131 CFX_WideString ws = CFX_WideString(sPropName);
135 CFX_ByteString bsPropertyName = ws.UTF8Encode(); 132 CFX_ByteString bsPropertyName = ws.UTF8Encode();
136 133
137 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlot); 134 CFX_PtrArray* pArray = (CFX_PtrArray*)pIsolate->GetData(g_embedderDataSlot);
138 if (!pArray) 135 if (!pArray)
139 return 0; 136 return 0;
140 137
141 if (nObjDefnID < 0 || nObjDefnID >= pArray->GetSize()) 138 if (nObjDefnID < 0 || nObjDefnID >= pArray->GetSize())
142 return 0; 139 return 0;
143 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID); 140 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID);
144 v8::Local<v8::ObjectTemplate> objTemp = 141 v8::Local<v8::ObjectTemplate> objTemp =
145 v8::Local<v8::ObjectTemplate>::New(isolate, pObjDef->m_objTemplate); 142 v8::Local<v8::ObjectTemplate>::New(pIsolate, pObjDef->m_objTemplate);
146 objTemp->SetAccessor(v8::String::NewFromUtf8(isolate, bsPropertyName.c_str(), 143 objTemp->SetAccessor(
147 v8::NewStringType::kNormal) 144 v8::String::NewFromUtf8(pIsolate, bsPropertyName.c_str(),
148 .ToLocalChecked(), 145 v8::NewStringType::kNormal).ToLocalChecked(),
149 pPropGet, pPropPut); 146 pPropGet, pPropPut);
150 pObjDef->m_objTemplate.Reset(isolate, objTemp); 147 pObjDef->m_objTemplate.Reset(pIsolate, objTemp);
151 return 0; 148 return 0;
152 } 149 }
153 150
154 int JS_DefineObjAllProperties(IJS_Runtime* pJSRuntime, 151 int JS_DefineObjAllProperties(v8::Isolate* pIsolate,
155 int nObjDefnID, 152 int nObjDefnID,
156 v8::NamedPropertyQueryCallback pPropQurey, 153 v8::NamedPropertyQueryCallback pPropQurey,
157 v8::NamedPropertyGetterCallback pPropGet, 154 v8::NamedPropertyGetterCallback pPropGet,
158 v8::NamedPropertySetterCallback pPropPut, 155 v8::NamedPropertySetterCallback pPropPut,
159 v8::NamedPropertyDeleterCallback pPropDel) { 156 v8::NamedPropertyDeleterCallback pPropDel) {
160 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; 157 v8::Isolate::Scope isolate_scope(pIsolate);
161 v8::Isolate::Scope isolate_scope(isolate); 158 v8::HandleScope handle_scope(pIsolate);
162 v8::HandleScope handle_scope(isolate);
163 159
164 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlot); 160 CFX_PtrArray* pArray = (CFX_PtrArray*)pIsolate->GetData(g_embedderDataSlot);
165 if (!pArray) 161 if (!pArray)
166 return 0; 162 return 0;
167 163
168 if (nObjDefnID < 0 || nObjDefnID >= pArray->GetSize()) 164 if (nObjDefnID < 0 || nObjDefnID >= pArray->GetSize())
169 return 0; 165 return 0;
170 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID); 166 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID);
171 v8::Local<v8::ObjectTemplate> objTemp = 167 v8::Local<v8::ObjectTemplate> objTemp =
172 v8::Local<v8::ObjectTemplate>::New(isolate, pObjDef->m_objTemplate); 168 v8::Local<v8::ObjectTemplate>::New(pIsolate, pObjDef->m_objTemplate);
173 objTemp->SetNamedPropertyHandler(pPropGet, pPropPut, pPropQurey, pPropDel); 169 objTemp->SetNamedPropertyHandler(pPropGet, pPropPut, pPropQurey, pPropDel);
174 pObjDef->m_objTemplate.Reset(isolate, objTemp); 170 pObjDef->m_objTemplate.Reset(pIsolate, objTemp);
175 return 0; 171 return 0;
176 } 172 }
177 173
178 int JS_DefineObjConst(IJS_Runtime* pJSRuntime, 174 int JS_DefineObjConst(v8::Isolate* pIsolate,
179 int nObjDefnID, 175 int nObjDefnID,
180 const wchar_t* sConstName, 176 const wchar_t* sConstName,
181 v8::Local<v8::Value> pDefault) { 177 v8::Local<v8::Value> pDefault) {
182 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; 178 v8::Isolate::Scope isolate_scope(pIsolate);
183 v8::Isolate::Scope isolate_scope(isolate); 179 v8::HandleScope handle_scope(pIsolate);
184 v8::HandleScope handle_scope(isolate);
185 180
186 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlot); 181 CFX_PtrArray* pArray = (CFX_PtrArray*)pIsolate->GetData(g_embedderDataSlot);
187 if (!pArray) 182 if (!pArray)
188 return 0; 183 return 0;
189 184
190 CFX_WideString ws = CFX_WideString(sConstName); 185 CFX_WideString ws = CFX_WideString(sConstName);
191 CFX_ByteString bsConstName = ws.UTF8Encode(); 186 CFX_ByteString bsConstName = ws.UTF8Encode();
192 187
193 if (nObjDefnID < 0 || nObjDefnID >= pArray->GetSize()) 188 if (nObjDefnID < 0 || nObjDefnID >= pArray->GetSize())
194 return 0; 189 return 0;
195 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID); 190 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID);
196 v8::Local<v8::ObjectTemplate> objTemp = 191 v8::Local<v8::ObjectTemplate> objTemp =
197 v8::Local<v8::ObjectTemplate>::New(isolate, pObjDef->m_objTemplate); 192 v8::Local<v8::ObjectTemplate>::New(pIsolate, pObjDef->m_objTemplate);
198 objTemp->Set(isolate, bsConstName.c_str(), pDefault); 193 objTemp->Set(pIsolate, bsConstName.c_str(), pDefault);
199 pObjDef->m_objTemplate.Reset(isolate, objTemp); 194 pObjDef->m_objTemplate.Reset(pIsolate, objTemp);
200 return 0; 195 return 0;
201 } 196 }
202 197
203 static v8::Global<v8::ObjectTemplate>& _getGlobalObjectTemplate( 198 static v8::Global<v8::ObjectTemplate>& _getGlobalObjectTemplate(
204 IJS_Runtime* pJSRuntime) { 199 v8::Isolate* pIsolate) {
205 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; 200 v8::Isolate::Scope isolate_scope(pIsolate);
206 v8::Isolate::Scope isolate_scope(isolate); 201 v8::HandleScope handle_scope(pIsolate);
207 v8::HandleScope handle_scope(isolate);
208 202
209 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlot); 203 CFX_PtrArray* pArray = (CFX_PtrArray*)pIsolate->GetData(g_embedderDataSlot);
210 ASSERT(pArray != NULL); 204 ASSERT(pArray != NULL);
211 for (int i = 0; i < pArray->GetSize(); i++) { 205 for (int i = 0; i < pArray->GetSize(); i++) {
212 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(i); 206 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(i);
213 if (pObjDef->m_bSetAsGlobalObject) 207 if (pObjDef->m_bSetAsGlobalObject)
214 return pObjDef->m_objTemplate; 208 return pObjDef->m_objTemplate;
215 } 209 }
216 static v8::Global<v8::ObjectTemplate> gloabalObjectTemplate; 210 static v8::Global<v8::ObjectTemplate> gloabalObjectTemplate;
217 return gloabalObjectTemplate; 211 return gloabalObjectTemplate;
218 } 212 }
219 213
220 int JS_DefineGlobalMethod(IJS_Runtime* pJSRuntime, 214 int JS_DefineGlobalMethod(v8::Isolate* pIsolate,
221 const wchar_t* sMethodName, 215 const wchar_t* sMethodName,
222 v8::FunctionCallback pMethodCall) { 216 v8::FunctionCallback pMethodCall) {
223 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; 217 v8::Isolate::Scope isolate_scope(pIsolate);
224 v8::Isolate::Scope isolate_scope(isolate); 218 v8::HandleScope handle_scope(pIsolate);
225 v8::HandleScope handle_scope(isolate);
226 219
227 CFX_WideString ws = CFX_WideString(sMethodName); 220 CFX_WideString ws = CFX_WideString(sMethodName);
228 CFX_ByteString bsMethodName = ws.UTF8Encode(); 221 CFX_ByteString bsMethodName = ws.UTF8Encode();
229 222
230 v8::Local<v8::FunctionTemplate> funTempl = 223 v8::Local<v8::FunctionTemplate> funTempl =
231 v8::FunctionTemplate::New(isolate, pMethodCall); 224 v8::FunctionTemplate::New(pIsolate, pMethodCall);
232 v8::Local<v8::ObjectTemplate> objTemp; 225 v8::Local<v8::ObjectTemplate> objTemp;
233 226
234 v8::Global<v8::ObjectTemplate>& globalObjTemp = 227 v8::Global<v8::ObjectTemplate>& globalObjTemp =
235 _getGlobalObjectTemplate(pJSRuntime); 228 _getGlobalObjectTemplate(pIsolate);
236 if (globalObjTemp.IsEmpty()) 229 if (globalObjTemp.IsEmpty())
237 objTemp = v8::ObjectTemplate::New(isolate); 230 objTemp = v8::ObjectTemplate::New(pIsolate);
238 else 231 else
239 objTemp = v8::Local<v8::ObjectTemplate>::New(isolate, globalObjTemp); 232 objTemp = v8::Local<v8::ObjectTemplate>::New(pIsolate, globalObjTemp);
240 objTemp->Set(v8::String::NewFromUtf8(isolate, bsMethodName.c_str(), 233 objTemp->Set(
241 v8::NewStringType::kNormal) 234 v8::String::NewFromUtf8(pIsolate, bsMethodName.c_str(),
242 .ToLocalChecked(), 235 v8::NewStringType::kNormal).ToLocalChecked(),
243 funTempl, v8::ReadOnly); 236 funTempl, v8::ReadOnly);
244 237
245 globalObjTemp.Reset(isolate, objTemp); 238 globalObjTemp.Reset(pIsolate, objTemp);
246 239
247 return 0; 240 return 0;
248 } 241 }
249 242
250 int JS_DefineGlobalConst(IJS_Runtime* pJSRuntime, 243 int JS_DefineGlobalConst(v8::Isolate* pIsolate,
251 const wchar_t* sConstName, 244 const wchar_t* sConstName,
252 v8::Local<v8::Value> pDefault) { 245 v8::Local<v8::Value> pDefault) {
253 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; 246 v8::Isolate::Scope isolate_scope(pIsolate);
254 v8::Isolate::Scope isolate_scope(isolate); 247 v8::HandleScope handle_scope(pIsolate);
255 v8::HandleScope handle_scope(isolate);
256 248
257 CFX_WideString ws = CFX_WideString(sConstName); 249 CFX_WideString ws = CFX_WideString(sConstName);
258 CFX_ByteString bsConst = ws.UTF8Encode(); 250 CFX_ByteString bsConst = ws.UTF8Encode();
259 251
260 v8::Local<v8::ObjectTemplate> objTemp; 252 v8::Local<v8::ObjectTemplate> objTemp;
261 253
262 v8::Global<v8::ObjectTemplate>& globalObjTemp = 254 v8::Global<v8::ObjectTemplate>& globalObjTemp =
263 _getGlobalObjectTemplate(pJSRuntime); 255 _getGlobalObjectTemplate(pIsolate);
264 if (globalObjTemp.IsEmpty()) 256 if (globalObjTemp.IsEmpty())
265 objTemp = v8::ObjectTemplate::New(isolate); 257 objTemp = v8::ObjectTemplate::New(pIsolate);
266 else 258 else
267 objTemp = v8::Local<v8::ObjectTemplate>::New(isolate, globalObjTemp); 259 objTemp = v8::Local<v8::ObjectTemplate>::New(pIsolate, globalObjTemp);
268 objTemp->Set(v8::String::NewFromUtf8(isolate, bsConst.c_str(), 260 objTemp->Set(
269 v8::NewStringType::kNormal) 261 v8::String::NewFromUtf8(pIsolate, bsConst.c_str(),
270 .ToLocalChecked(), 262 v8::NewStringType::kNormal).ToLocalChecked(),
271 pDefault, v8::ReadOnly); 263 pDefault, v8::ReadOnly);
272 264
273 globalObjTemp.Reset(isolate, objTemp); 265 globalObjTemp.Reset(pIsolate, objTemp);
274 266
275 return 0; 267 return 0;
276 } 268 }
277 269
278 void JS_InitialRuntime(IJS_Runtime* pJSRuntime, 270 void JS_InitialRuntime(v8::Isolate* pIsolate,
279 IFXJS_Runtime* pFXRuntime, 271 IFXJS_Runtime* pFXRuntime,
280 IFXJS_Context* context, 272 IFXJS_Context* context,
281 v8::Global<v8::Context>& v8PersistentContext) { 273 v8::Global<v8::Context>& v8PersistentContext) {
282 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; 274 v8::Isolate::Scope isolate_scope(pIsolate);
283 v8::Isolate::Scope isolate_scope(isolate); 275 v8::HandleScope handle_scope(pIsolate);
284 v8::HandleScope handle_scope(isolate);
285 276
286 v8::Global<v8::ObjectTemplate>& globalObjTemp = 277 v8::Global<v8::ObjectTemplate>& globalObjTemp =
287 _getGlobalObjectTemplate(pJSRuntime); 278 _getGlobalObjectTemplate(pIsolate);
288 v8::Local<v8::Context> v8Context = v8::Context::New( 279 v8::Local<v8::Context> v8Context = v8::Context::New(
289 isolate, NULL, 280 pIsolate, NULL,
290 v8::Local<v8::ObjectTemplate>::New(isolate, globalObjTemp)); 281 v8::Local<v8::ObjectTemplate>::New(pIsolate, globalObjTemp));
291 v8::Context::Scope context_scope(v8Context); 282 v8::Context::Scope context_scope(v8Context);
292 283
293 v8::Local<v8::External> ptr = v8::External::New(isolate, pFXRuntime); 284 v8::Local<v8::External> ptr = v8::External::New(pIsolate, pFXRuntime);
294 v8Context->SetEmbedderData(1, ptr); 285 v8Context->SetEmbedderData(1, ptr);
295 286
296 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlot); 287 CFX_PtrArray* pArray = (CFX_PtrArray*)pIsolate->GetData(g_embedderDataSlot);
297 if (!pArray) 288 if (!pArray)
298 return; 289 return;
299 290
300 for (int i = 0; i < pArray->GetSize(); i++) { 291 for (int i = 0; i < pArray->GetSize(); i++) {
301 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(i); 292 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(i);
302 CFX_WideString ws = CFX_WideString(pObjDef->objName); 293 CFX_WideString ws = CFX_WideString(pObjDef->objName);
303 CFX_ByteString bs = ws.UTF8Encode(); 294 CFX_ByteString bs = ws.UTF8Encode();
304 v8::Local<v8::String> objName = 295 v8::Local<v8::String> objName =
305 v8::String::NewFromUtf8(isolate, bs.c_str(), v8::NewStringType::kNormal, 296 v8::String::NewFromUtf8(pIsolate, bs.c_str(),
306 bs.GetLength()) 297 v8::NewStringType::kNormal,
307 .ToLocalChecked(); 298 bs.GetLength()).ToLocalChecked();
308 299
309 if (pObjDef->objType == JS_DYNAMIC) { 300 if (pObjDef->objType == JS_DYNAMIC) {
310 // Document is set as global object, need to construct it first. 301 // Document is set as global object, need to construct it first.
311 if (ws.Equal(L"Document")) { 302 if (ws.Equal(L"Document")) {
312 CJS_PrivateData* pPrivateData = new CJS_PrivateData; 303 CJS_PrivateData* pPrivateData = new CJS_PrivateData;
313 pPrivateData->ObjDefID = i; 304 pPrivateData->ObjDefID = i;
314 305
315 v8Context->Global() 306 v8Context->Global()
316 ->GetPrototype() 307 ->GetPrototype()
317 ->ToObject(v8Context) 308 ->ToObject(v8Context)
318 .ToLocalChecked() 309 .ToLocalChecked()
319 ->SetAlignedPointerInInternalField(0, pPrivateData); 310 ->SetAlignedPointerInInternalField(0, pPrivateData);
320 311
321 if (pObjDef->m_pConstructor) 312 if (pObjDef->m_pConstructor)
322 pObjDef->m_pConstructor(context, v8Context->Global() 313 pObjDef->m_pConstructor(context, v8Context->Global()
323 ->GetPrototype() 314 ->GetPrototype()
324 ->ToObject(v8Context) 315 ->ToObject(v8Context)
325 .ToLocalChecked(), 316 .ToLocalChecked(),
326 v8Context->Global() 317 v8Context->Global()
327 ->GetPrototype() 318 ->GetPrototype()
328 ->ToObject(v8Context) 319 ->ToObject(v8Context)
329 .ToLocalChecked()); 320 .ToLocalChecked());
330 } 321 }
331 } else { 322 } else {
332 v8::Local<v8::Object> obj = JS_NewFxDynamicObj(pJSRuntime, context, i); 323 v8::Local<v8::Object> obj = JS_NewFxDynamicObj(pIsolate, context, i);
333 v8Context->Global()->Set(v8Context, objName, obj).FromJust(); 324 v8Context->Global()->Set(v8Context, objName, obj).FromJust();
334 pObjDef->m_StaticObj.Reset(isolate, obj); 325 pObjDef->m_StaticObj.Reset(pIsolate, obj);
335 } 326 }
336 } 327 }
337 v8PersistentContext.Reset(isolate, v8Context); 328 v8PersistentContext.Reset(pIsolate, v8Context);
338 } 329 }
339 330
340 void JS_ReleaseRuntime(IJS_Runtime* pJSRuntime, 331 void JS_ReleaseRuntime(v8::Isolate* pIsolate,
341 v8::Global<v8::Context>& v8PersistentContext) { 332 v8::Global<v8::Context>& v8PersistentContext) {
342 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; 333 v8::Isolate::Scope isolate_scope(pIsolate);
343 v8::Isolate::Scope isolate_scope(isolate); 334 v8::HandleScope handle_scope(pIsolate);
344 v8::HandleScope handle_scope(isolate);
345 v8::Local<v8::Context> context = 335 v8::Local<v8::Context> context =
346 v8::Local<v8::Context>::New(isolate, v8PersistentContext); 336 v8::Local<v8::Context>::New(pIsolate, v8PersistentContext);
347 v8::Context::Scope context_scope(context); 337 v8::Context::Scope context_scope(context);
348 338
349 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlot); 339 CFX_PtrArray* pArray = (CFX_PtrArray*)pIsolate->GetData(g_embedderDataSlot);
350 if (!pArray) 340 if (!pArray)
351 return; 341 return;
352 342
353 for (int i = 0; i < pArray->GetSize(); i++) { 343 for (int i = 0; i < pArray->GetSize(); i++) {
354 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(i); 344 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(i);
355 if (!pObjDef->m_StaticObj.IsEmpty()) { 345 if (!pObjDef->m_StaticObj.IsEmpty()) {
356 v8::Local<v8::Object> pObj = 346 v8::Local<v8::Object> pObj =
357 v8::Local<v8::Object>::New(isolate, pObjDef->m_StaticObj); 347 v8::Local<v8::Object>::New(pIsolate, pObjDef->m_StaticObj);
358 if (pObjDef->m_pDestructor) 348 if (pObjDef->m_pDestructor)
359 pObjDef->m_pDestructor(pObj); 349 pObjDef->m_pDestructor(pObj);
360 JS_FreePrivate(pObj); 350 JS_FreePrivate(pObj);
361 } 351 }
362 delete pObjDef; 352 delete pObjDef;
363 } 353 }
364 delete pArray; 354 delete pArray;
365 isolate->SetData(g_embedderDataSlot, NULL); 355 pIsolate->SetData(g_embedderDataSlot, NULL);
366 } 356 }
367 357
368 void JS_Initial(unsigned int embedderDataSlot) { 358 void JS_Initial(unsigned int embedderDataSlot) {
369 g_embedderDataSlot = embedderDataSlot; 359 g_embedderDataSlot = embedderDataSlot;
370 } 360 }
371 361
372 void JS_Release() { 362 void JS_Release() {
373 } 363 }
374 364
375 int JS_Execute(IJS_Runtime* pJSRuntime, 365 int JS_Execute(v8::Isolate* pIsolate,
376 IFXJS_Context* pJSContext, 366 IFXJS_Context* pJSContext,
377 const wchar_t* script, 367 const wchar_t* script,
378 long length, 368 long length,
379 FXJSErr* perror) { 369 FXJSErr* perror) {
380 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; 370 v8::Isolate::Scope isolate_scope(pIsolate);
381 v8::Isolate::Scope isolate_scope(isolate); 371 v8::TryCatch try_catch(pIsolate);
382 v8::TryCatch try_catch(isolate);
383 372
384 CFX_WideString wsScript(script); 373 CFX_WideString wsScript(script);
385 CFX_ByteString bsScript = wsScript.UTF8Encode(); 374 CFX_ByteString bsScript = wsScript.UTF8Encode();
386 375
387 v8::Local<v8::Context> context = isolate->GetCurrentContext(); 376 v8::Local<v8::Context> context = pIsolate->GetCurrentContext();
388 v8::Local<v8::Script> compiled_script; 377 v8::Local<v8::Script> compiled_script;
389 if (!v8::Script::Compile(context, 378 if (!v8::Script::Compile(
390 v8::String::NewFromUtf8(isolate, bsScript.c_str(), 379 context, v8::String::NewFromUtf8(
391 v8::NewStringType::kNormal, 380 pIsolate, bsScript.c_str(), v8::NewStringType::kNormal,
392 bsScript.GetLength()) 381 bsScript.GetLength()).ToLocalChecked())
393 .ToLocalChecked())
394 .ToLocal(&compiled_script)) { 382 .ToLocal(&compiled_script)) {
395 v8::String::Utf8Value error(try_catch.Exception()); 383 v8::String::Utf8Value error(try_catch.Exception());
396 return -1; 384 return -1;
397 } 385 }
398 386
399 v8::Local<v8::Value> result; 387 v8::Local<v8::Value> result;
400 if (!compiled_script->Run(context).ToLocal(&result)) { 388 if (!compiled_script->Run(context).ToLocal(&result)) {
401 v8::String::Utf8Value error(try_catch.Exception()); 389 v8::String::Utf8Value error(try_catch.Exception());
402 return -1; 390 return -1;
403 } 391 }
404 return 0; 392 return 0;
405 } 393 }
406 394
407 v8::Local<v8::Object> JS_NewFxDynamicObj(IJS_Runtime* pJSRuntime, 395 v8::Local<v8::Object> JS_NewFxDynamicObj(v8::Isolate* pIsolate,
408 IFXJS_Context* pJSContext, 396 IFXJS_Context* pJSContext,
409 int nObjDefnID) { 397 int nObjDefnID) {
410 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; 398 v8::Isolate::Scope isolate_scope(pIsolate);
411 v8::Isolate::Scope isolate_scope(isolate); 399 v8::Local<v8::Context> context = pIsolate->GetCurrentContext();
412 v8::Local<v8::Context> context = isolate->GetCurrentContext();
413 if (-1 == nObjDefnID) { 400 if (-1 == nObjDefnID) {
414 v8::Local<v8::ObjectTemplate> objTempl = v8::ObjectTemplate::New(isolate); 401 v8::Local<v8::ObjectTemplate> objTempl = v8::ObjectTemplate::New(pIsolate);
415 v8::Local<v8::Object> obj; 402 v8::Local<v8::Object> obj;
416 if (objTempl->NewInstance(context).ToLocal(&obj)) 403 if (objTempl->NewInstance(context).ToLocal(&obj))
417 return obj; 404 return obj;
418 return v8::Local<v8::Object>(); 405 return v8::Local<v8::Object>();
419 } 406 }
420 407
421 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlot); 408 CFX_PtrArray* pArray = (CFX_PtrArray*)pIsolate->GetData(g_embedderDataSlot);
422 if (!pArray) 409 if (!pArray)
423 return v8::Local<v8::Object>(); 410 return v8::Local<v8::Object>();
424 411
425 if (nObjDefnID < 0 || nObjDefnID >= pArray->GetSize()) 412 if (nObjDefnID < 0 || nObjDefnID >= pArray->GetSize())
426 return v8::Local<v8::Object>(); 413 return v8::Local<v8::Object>();
427 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID); 414 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID);
428 415
429 v8::Local<v8::ObjectTemplate> objTemp = 416 v8::Local<v8::ObjectTemplate> objTemp =
430 v8::Local<v8::ObjectTemplate>::New(isolate, pObjDef->m_objTemplate); 417 v8::Local<v8::ObjectTemplate>::New(pIsolate, pObjDef->m_objTemplate);
431 v8::Local<v8::Object> obj; 418 v8::Local<v8::Object> obj;
432 if (!objTemp->NewInstance(context).ToLocal(&obj)) 419 if (!objTemp->NewInstance(context).ToLocal(&obj))
433 return v8::Local<v8::Object>(); 420 return v8::Local<v8::Object>();
434 421
435 CJS_PrivateData* pPrivateData = new CJS_PrivateData; 422 CJS_PrivateData* pPrivateData = new CJS_PrivateData;
436 pPrivateData->ObjDefID = nObjDefnID; 423 pPrivateData->ObjDefID = nObjDefnID;
437 424
438 obj->SetAlignedPointerInInternalField(0, pPrivateData); 425 obj->SetAlignedPointerInInternalField(0, pPrivateData);
439 if (pObjDef->m_pConstructor) 426 if (pObjDef->m_pConstructor)
440 pObjDef->m_pConstructor( 427 pObjDef->m_pConstructor(
441 pJSContext, obj, 428 pJSContext, obj,
442 context->Global()->GetPrototype()->ToObject(context).ToLocalChecked()); 429 context->Global()->GetPrototype()->ToObject(context).ToLocalChecked());
443 430
444 return obj; 431 return obj;
445 } 432 }
446 433
447 v8::Local<v8::Object> JS_GetStaticObj(IJS_Runtime* pJSRuntime, int nObjDefnID) { 434 v8::Local<v8::Object> JS_GetStaticObj(v8::Isolate* pIsolate, int nObjDefnID) {
448 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; 435 v8::Isolate::Scope isolate_scope(pIsolate);
449 v8::Isolate::Scope isolate_scope(isolate); 436 CFX_PtrArray* pArray = (CFX_PtrArray*)pIsolate->GetData(g_embedderDataSlot);
450
451 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlot);
452 if (!pArray) 437 if (!pArray)
453 return v8::Local<v8::Object>(); 438 return v8::Local<v8::Object>();
454 439
455 if (nObjDefnID < 0 || nObjDefnID >= pArray->GetSize()) 440 if (nObjDefnID < 0 || nObjDefnID >= pArray->GetSize())
456 return v8::Local<v8::Object>(); 441 return v8::Local<v8::Object>();
457 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID); 442 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID);
458 v8::Local<v8::Object> obj = 443 v8::Local<v8::Object> obj =
459 v8::Local<v8::Object>::New(isolate, pObjDef->m_StaticObj); 444 v8::Local<v8::Object>::New(pIsolate, pObjDef->m_StaticObj);
460 return obj; 445 return obj;
461 } 446 }
462 447
463 void JS_SetThisObj(IJS_Runtime* pJSRuntime, int nThisObjID) { 448 v8::Local<v8::Object> JS_GetThisObj(v8::Isolate* pIsolate) {
464 // Do nothing.
465 }
466 v8::Local<v8::Object> JS_GetThisObj(IJS_Runtime* pJSRuntime) {
467 // Return the global object. 449 // Return the global object.
468 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; 450 v8::Isolate::Scope isolate_scope(pIsolate);
469 v8::Isolate::Scope isolate_scope(isolate); 451 CFX_PtrArray* pArray = (CFX_PtrArray*)pIsolate->GetData(g_embedderDataSlot);
470
471 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlot);
472 if (!pArray) 452 if (!pArray)
473 return v8::Local<v8::Object>(); 453 return v8::Local<v8::Object>();
474 454
475 v8::Local<v8::Context> context = isolate->GetCurrentContext(); 455 v8::Local<v8::Context> context = pIsolate->GetCurrentContext();
476 return context->Global()->GetPrototype()->ToObject(context).ToLocalChecked(); 456 return context->Global()->GetPrototype()->ToObject(context).ToLocalChecked();
477 } 457 }
478 458
479 int JS_GetObjDefnID(v8::Local<v8::Object> pObj) { 459 int JS_GetObjDefnID(v8::Local<v8::Object> pObj) {
480 if (pObj.IsEmpty() || !pObj->InternalFieldCount()) 460 if (pObj.IsEmpty() || !pObj->InternalFieldCount())
481 return -1; 461 return -1;
482 CJS_PrivateData* pPrivateData = 462 CJS_PrivateData* pPrivateData =
483 (CJS_PrivateData*)pObj->GetAlignedPointerFromInternalField(0); 463 (CJS_PrivateData*)pObj->GetAlignedPointerFromInternalField(0);
484 if (pPrivateData) 464 if (pPrivateData)
485 return pPrivateData->ObjDefID; 465 return pPrivateData->ObjDefID;
486 return -1; 466 return -1;
487 } 467 }
488 468
489 IJS_Runtime* JS_GetRuntime(v8::Local<v8::Object> pObj) { 469 v8::Isolate* JS_GetRuntime(v8::Local<v8::Object> pObj) {
490 if (pObj.IsEmpty()) 470 if (pObj.IsEmpty())
491 return NULL; 471 return NULL;
492 v8::Local<v8::Context> context = pObj->CreationContext(); 472 v8::Local<v8::Context> context = pObj->CreationContext();
493 if (context.IsEmpty()) 473 if (context.IsEmpty())
494 return NULL; 474 return NULL;
495 return context->GetIsolate(); 475 return context->GetIsolate();
496 } 476 }
497 477
498 int JS_GetObjDefnID(IJS_Runtime* pJSRuntime, const wchar_t* pObjName) { 478 int JS_GetObjDefnID(v8::Isolate* pIsolate, const wchar_t* pObjName) {
499 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; 479 v8::Isolate::Scope isolate_scope(pIsolate);
500 v8::Isolate::Scope isolate_scope(isolate); 480 CFX_PtrArray* pArray = (CFX_PtrArray*)pIsolate->GetData(g_embedderDataSlot);
501
502 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlot);
503 if (!pArray) 481 if (!pArray)
504 return -1; 482 return -1;
505 483
506 for (int i = 0; i < pArray->GetSize(); i++) { 484 for (int i = 0; i < pArray->GetSize(); i++) {
507 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(i); 485 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(i);
508 if (FXSYS_wcscmp(pObjDef->objName, pObjName) == 0) 486 if (FXSYS_wcscmp(pObjDef->objName, pObjName) == 0)
509 return i; 487 return i;
510 } 488 }
511 return -1; 489 return -1;
512 } 490 }
513 491
514 void JS_Error(v8::Isolate* isolate, const CFX_WideString& message) { 492 void JS_Error(v8::Isolate* pIsolate, const CFX_WideString& message) {
515 // Conversion from pdfium's wchar_t wide-strings to v8's uint16_t 493 // Conversion from pdfium's wchar_t wide-strings to v8's uint16_t
516 // wide-strings isn't handled by v8, so use UTF8 as a common 494 // wide-strings isn't handled by v8, so use UTF8 as a common
517 // intermediate format. 495 // intermediate format.
518 CFX_ByteString utf8_message = message.UTF8Encode(); 496 CFX_ByteString utf8_message = message.UTF8Encode();
519 isolate->ThrowException(v8::String::NewFromUtf8(isolate, utf8_message.c_str(), 497 pIsolate->ThrowException(
520 v8::NewStringType::kNormal) 498 v8::String::NewFromUtf8(pIsolate, utf8_message.c_str(),
521 .ToLocalChecked()); 499 v8::NewStringType::kNormal).ToLocalChecked());
522 } 500 }
523 501
524 unsigned JS_CalcHash(const wchar_t* main, unsigned nLen) { 502 unsigned JS_CalcHash(const wchar_t* main, unsigned nLen) {
525 return (unsigned)FX_HashCode_String_GetW(main, nLen); 503 return (unsigned)FX_HashCode_String_GetW(main, nLen);
526 } 504 }
527 505
528 unsigned JS_CalcHash(const wchar_t* main) { 506 unsigned JS_CalcHash(const wchar_t* main) {
529 return (unsigned)FX_HashCode_String_GetW(main, FXSYS_wcslen(main)); 507 return (unsigned)FX_HashCode_String_GetW(main, FXSYS_wcslen(main));
530 } 508 }
531 const wchar_t* JS_GetTypeof(v8::Local<v8::Value> pObj) { 509 const wchar_t* JS_GetTypeof(v8::Local<v8::Value> pObj) {
(...skipping 16 matching lines...) Expand all
548 return NULL; 526 return NULL;
549 } 527 }
550 void JS_SetPrivate(v8::Local<v8::Object> pObj, void* p) { 528 void JS_SetPrivate(v8::Local<v8::Object> pObj, void* p) {
551 JS_SetPrivate(NULL, pObj, p); 529 JS_SetPrivate(NULL, pObj, p);
552 } 530 }
553 531
554 void* JS_GetPrivate(v8::Local<v8::Object> pObj) { 532 void* JS_GetPrivate(v8::Local<v8::Object> pObj) {
555 return JS_GetPrivate(NULL, pObj); 533 return JS_GetPrivate(NULL, pObj);
556 } 534 }
557 535
558 void JS_SetPrivate(IJS_Runtime* pJSRuntime, 536 void JS_SetPrivate(v8::Isolate* pIsolate, v8::Local<v8::Object> pObj, void* p) {
559 v8::Local<v8::Object> pObj,
560 void* p) {
561 if (pObj.IsEmpty() || !pObj->InternalFieldCount()) 537 if (pObj.IsEmpty() || !pObj->InternalFieldCount())
562 return; 538 return;
563 CJS_PrivateData* pPrivateData = 539 CJS_PrivateData* pPrivateData =
564 (CJS_PrivateData*)pObj->GetAlignedPointerFromInternalField(0); 540 (CJS_PrivateData*)pObj->GetAlignedPointerFromInternalField(0);
565 if (!pPrivateData) 541 if (!pPrivateData)
566 return; 542 return;
567 pPrivateData->pPrivate = p; 543 pPrivateData->pPrivate = p;
568 } 544 }
569 545
570 void* JS_GetPrivate(IJS_Runtime* pJSRuntime, v8::Local<v8::Object> pObj) { 546 void* JS_GetPrivate(v8::Isolate* pIsolate, v8::Local<v8::Object> pObj) {
571 if (pObj.IsEmpty()) 547 if (pObj.IsEmpty())
572 return NULL; 548 return NULL;
573 CJS_PrivateData* pPrivateData = NULL; 549 CJS_PrivateData* pPrivateData = NULL;
574 if (pObj->InternalFieldCount()) 550 if (pObj->InternalFieldCount())
575 pPrivateData = 551 pPrivateData =
576 (CJS_PrivateData*)pObj->GetAlignedPointerFromInternalField(0); 552 (CJS_PrivateData*)pObj->GetAlignedPointerFromInternalField(0);
577 else { 553 else {
578 // It could be a global proxy object. 554 // It could be a global proxy object.
579 v8::Local<v8::Value> v = pObj->GetPrototype(); 555 v8::Local<v8::Value> v = pObj->GetPrototype();
580 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; 556 v8::Isolate* isolate = (v8::Isolate*)pIsolate;
581 v8::Local<v8::Context> context = isolate->GetCurrentContext(); 557 v8::Local<v8::Context> context = isolate->GetCurrentContext();
582 if (v->IsObject()) 558 if (v->IsObject())
583 pPrivateData = (CJS_PrivateData*)v->ToObject(context) 559 pPrivateData = (CJS_PrivateData*)v->ToObject(context)
584 .ToLocalChecked() 560 .ToLocalChecked()
585 ->GetAlignedPointerFromInternalField(0); 561 ->GetAlignedPointerFromInternalField(0);
586 } 562 }
587 if (!pPrivateData) 563 if (!pPrivateData)
588 return NULL; 564 return NULL;
589 return pPrivateData->pPrivate; 565 return pPrivateData->pPrivate;
590 } 566 }
591 567
592 void JS_FreePrivate(void* pPrivateData) { 568 void JS_FreePrivate(void* pPrivateData) {
593 delete (CJS_PrivateData*)pPrivateData; 569 delete (CJS_PrivateData*)pPrivateData;
594 } 570 }
595 571
596 void JS_FreePrivate(v8::Local<v8::Object> pObj) { 572 void JS_FreePrivate(v8::Local<v8::Object> pObj) {
597 if (pObj.IsEmpty() || !pObj->InternalFieldCount()) 573 if (pObj.IsEmpty() || !pObj->InternalFieldCount())
598 return; 574 return;
599 JS_FreePrivate(pObj->GetAlignedPointerFromInternalField(0)); 575 JS_FreePrivate(pObj->GetAlignedPointerFromInternalField(0));
600 pObj->SetAlignedPointerInInternalField(0, NULL); 576 pObj->SetAlignedPointerInInternalField(0, NULL);
601 } 577 }
602 578
603 v8::Local<v8::Value> JS_GetObjectValue(v8::Local<v8::Object> pObj) { 579 v8::Local<v8::Value> JS_GetObjectValue(v8::Local<v8::Object> pObj) {
604 return pObj; 580 return pObj;
605 } 581 }
606 582
607 v8::Local<v8::String> WSToJSString(IJS_Runtime* pJSRuntime, 583 v8::Local<v8::String> WSToJSString(v8::Isolate* pIsolate,
608 const wchar_t* PropertyName, 584 const wchar_t* PropertyName,
609 int Len = -1) { 585 int Len = -1) {
610 CFX_WideString ws = CFX_WideString(PropertyName, Len); 586 CFX_WideString ws = CFX_WideString(PropertyName, Len);
611 CFX_ByteString bs = ws.UTF8Encode(); 587 CFX_ByteString bs = ws.UTF8Encode();
612 if (!pJSRuntime) 588 if (!pIsolate)
613 pJSRuntime = v8::Isolate::GetCurrent(); 589 pIsolate = v8::Isolate::GetCurrent();
614 return v8::String::NewFromUtf8(pJSRuntime, bs.c_str(), 590 return v8::String::NewFromUtf8(pIsolate, bs.c_str(),
615 v8::NewStringType::kNormal) 591 v8::NewStringType::kNormal).ToLocalChecked();
616 .ToLocalChecked();
617 } 592 }
618 593
619 v8::Local<v8::Value> JS_GetObjectElement(IJS_Runtime* pJSRuntime, 594 v8::Local<v8::Value> JS_GetObjectElement(v8::Isolate* pIsolate,
620 v8::Local<v8::Object> pObj, 595 v8::Local<v8::Object> pObj,
621 const wchar_t* PropertyName) { 596 const wchar_t* PropertyName) {
622 if (pObj.IsEmpty()) 597 if (pObj.IsEmpty())
623 return v8::Local<v8::Value>(); 598 return v8::Local<v8::Value>();
624 v8::Local<v8::Value> val; 599 v8::Local<v8::Value> val;
625 if (!pObj->Get(pJSRuntime->GetCurrentContext(), 600 if (!pObj->Get(pIsolate->GetCurrentContext(),
626 WSToJSString(pJSRuntime, PropertyName)) 601 WSToJSString(pIsolate, PropertyName)).ToLocal(&val))
627 .ToLocal(&val))
628 return v8::Local<v8::Value>(); 602 return v8::Local<v8::Value>();
629 return val; 603 return val;
630 } 604 }
631 605
632 v8::Local<v8::Array> JS_GetObjectElementNames(IJS_Runtime* pJSRuntime, 606 v8::Local<v8::Array> JS_GetObjectElementNames(v8::Isolate* pIsolate,
633 v8::Local<v8::Object> pObj) { 607 v8::Local<v8::Object> pObj) {
634 if (pObj.IsEmpty()) 608 if (pObj.IsEmpty())
635 return v8::Local<v8::Array>(); 609 return v8::Local<v8::Array>();
636 v8::Local<v8::Array> val; 610 v8::Local<v8::Array> val;
637 if (!pObj->GetPropertyNames(pJSRuntime->GetCurrentContext()).ToLocal(&val)) 611 if (!pObj->GetPropertyNames(pIsolate->GetCurrentContext()).ToLocal(&val))
638 return v8::Local<v8::Array>(); 612 return v8::Local<v8::Array>();
639 return val; 613 return val;
640 } 614 }
641 615
642 void JS_PutObjectString(IJS_Runtime* pJSRuntime, 616 void JS_PutObjectString(v8::Isolate* pIsolate,
643 v8::Local<v8::Object> pObj, 617 v8::Local<v8::Object> pObj,
644 const wchar_t* PropertyName, 618 const wchar_t* PropertyName,
645 const wchar_t* sValue) // VT_string 619 const wchar_t* sValue) // VT_string
646 { 620 {
647 if (pObj.IsEmpty()) 621 if (pObj.IsEmpty())
648 return; 622 return;
649 pObj->Set(pJSRuntime->GetCurrentContext(), 623 pObj->Set(pIsolate->GetCurrentContext(), WSToJSString(pIsolate, PropertyName),
650 WSToJSString(pJSRuntime, PropertyName), 624 WSToJSString(pIsolate, sValue)).FromJust();
651 WSToJSString(pJSRuntime, sValue))
652 .FromJust();
653 } 625 }
654 626
655 void JS_PutObjectNumber(IJS_Runtime* pJSRuntime, 627 void JS_PutObjectNumber(v8::Isolate* pIsolate,
656 v8::Local<v8::Object> pObj, 628 v8::Local<v8::Object> pObj,
657 const wchar_t* PropertyName, 629 const wchar_t* PropertyName,
658 int nValue) { 630 int nValue) {
659 if (pObj.IsEmpty()) 631 if (pObj.IsEmpty())
660 return; 632 return;
661 pObj->Set(pJSRuntime->GetCurrentContext(), 633 pObj->Set(pIsolate->GetCurrentContext(), WSToJSString(pIsolate, PropertyName),
662 WSToJSString(pJSRuntime, PropertyName), 634 v8::Int32::New(pIsolate, nValue)).FromJust();
663 v8::Int32::New(pJSRuntime, nValue))
664 .FromJust();
665 } 635 }
666 636
667 void JS_PutObjectNumber(IJS_Runtime* pJSRuntime, 637 void JS_PutObjectNumber(v8::Isolate* pIsolate,
668 v8::Local<v8::Object> pObj, 638 v8::Local<v8::Object> pObj,
669 const wchar_t* PropertyName, 639 const wchar_t* PropertyName,
670 float fValue) { 640 float fValue) {
671 if (pObj.IsEmpty()) 641 if (pObj.IsEmpty())
672 return; 642 return;
673 pObj->Set(pJSRuntime->GetCurrentContext(), 643 pObj->Set(pIsolate->GetCurrentContext(), WSToJSString(pIsolate, PropertyName),
674 WSToJSString(pJSRuntime, PropertyName), 644 v8::Number::New(pIsolate, (double)fValue)).FromJust();
675 v8::Number::New(pJSRuntime, (double)fValue))
676 .FromJust();
677 } 645 }
678 646
679 void JS_PutObjectNumber(IJS_Runtime* pJSRuntime, 647 void JS_PutObjectNumber(v8::Isolate* pIsolate,
680 v8::Local<v8::Object> pObj, 648 v8::Local<v8::Object> pObj,
681 const wchar_t* PropertyName, 649 const wchar_t* PropertyName,
682 double dValue) { 650 double dValue) {
683 if (pObj.IsEmpty()) 651 if (pObj.IsEmpty())
684 return; 652 return;
685 pObj->Set(pJSRuntime->GetCurrentContext(), 653 pObj->Set(pIsolate->GetCurrentContext(), WSToJSString(pIsolate, PropertyName),
686 WSToJSString(pJSRuntime, PropertyName), 654 v8::Number::New(pIsolate, (double)dValue)).FromJust();
687 v8::Number::New(pJSRuntime, (double)dValue))
688 .FromJust();
689 } 655 }
690 656
691 void JS_PutObjectBoolean(IJS_Runtime* pJSRuntime, 657 void JS_PutObjectBoolean(v8::Isolate* pIsolate,
692 v8::Local<v8::Object> pObj, 658 v8::Local<v8::Object> pObj,
693 const wchar_t* PropertyName, 659 const wchar_t* PropertyName,
694 bool bValue) { 660 bool bValue) {
695 if (pObj.IsEmpty()) 661 if (pObj.IsEmpty())
696 return; 662 return;
697 pObj->Set(pJSRuntime->GetCurrentContext(), 663 pObj->Set(pIsolate->GetCurrentContext(), WSToJSString(pIsolate, PropertyName),
698 WSToJSString(pJSRuntime, PropertyName), 664 v8::Boolean::New(pIsolate, bValue)).FromJust();
699 v8::Boolean::New(pJSRuntime, bValue))
700 .FromJust();
701 } 665 }
702 666
703 void JS_PutObjectObject(IJS_Runtime* pJSRuntime, 667 void JS_PutObjectObject(v8::Isolate* pIsolate,
704 v8::Local<v8::Object> pObj, 668 v8::Local<v8::Object> pObj,
705 const wchar_t* PropertyName, 669 const wchar_t* PropertyName,
706 v8::Local<v8::Object> pPut) { 670 v8::Local<v8::Object> pPut) {
707 if (pObj.IsEmpty()) 671 if (pObj.IsEmpty())
708 return; 672 return;
709 pObj->Set(pJSRuntime->GetCurrentContext(), 673 pObj->Set(pIsolate->GetCurrentContext(), WSToJSString(pIsolate, PropertyName),
710 WSToJSString(pJSRuntime, PropertyName), pPut) 674 pPut).FromJust();
711 .FromJust();
712 } 675 }
713 676
714 void JS_PutObjectNull(IJS_Runtime* pJSRuntime, 677 void JS_PutObjectNull(v8::Isolate* pIsolate,
715 v8::Local<v8::Object> pObj, 678 v8::Local<v8::Object> pObj,
716 const wchar_t* PropertyName) { 679 const wchar_t* PropertyName) {
717 if (pObj.IsEmpty()) 680 if (pObj.IsEmpty())
718 return; 681 return;
719 pObj->Set(pJSRuntime->GetCurrentContext(), 682 pObj->Set(pIsolate->GetCurrentContext(), WSToJSString(pIsolate, PropertyName),
720 WSToJSString(pJSRuntime, PropertyName), v8::Local<v8::Object>()) 683 v8::Local<v8::Object>()).FromJust();
721 .FromJust();
722 } 684 }
723 685
724 v8::Local<v8::Array> JS_NewArray(IJS_Runtime* pJSRuntime) { 686 v8::Local<v8::Array> JS_NewArray(v8::Isolate* pIsolate) {
725 return v8::Array::New(pJSRuntime); 687 return v8::Array::New(pIsolate);
726 } 688 }
727 689
728 unsigned JS_PutArrayElement(IJS_Runtime* pJSRuntime, 690 unsigned JS_PutArrayElement(v8::Isolate* pIsolate,
729 v8::Local<v8::Array> pArray, 691 v8::Local<v8::Array> pArray,
730 unsigned index, 692 unsigned index,
731 v8::Local<v8::Value> pValue, 693 v8::Local<v8::Value> pValue,
732 FXJSVALUETYPE eType) { 694 FXJSVALUETYPE eType) {
733 if (pArray.IsEmpty()) 695 if (pArray.IsEmpty())
734 return 0; 696 return 0;
735 if (pArray->Set(pJSRuntime->GetCurrentContext(), index, pValue).IsNothing()) 697 if (pArray->Set(pIsolate->GetCurrentContext(), index, pValue).IsNothing())
736 return 0; 698 return 0;
737 return 1; 699 return 1;
738 } 700 }
739 701
740 v8::Local<v8::Value> JS_GetArrayElement(IJS_Runtime* pJSRuntime, 702 v8::Local<v8::Value> JS_GetArrayElement(v8::Isolate* pIsolate,
741 v8::Local<v8::Array> pArray, 703 v8::Local<v8::Array> pArray,
742 unsigned index) { 704 unsigned index) {
743 if (pArray.IsEmpty()) 705 if (pArray.IsEmpty())
744 return v8::Local<v8::Value>(); 706 return v8::Local<v8::Value>();
745 v8::Local<v8::Value> val; 707 v8::Local<v8::Value> val;
746 if (!pArray->Get(pJSRuntime->GetCurrentContext(), index).ToLocal(&val)) 708 if (!pArray->Get(pIsolate->GetCurrentContext(), index).ToLocal(&val))
747 return v8::Local<v8::Value>(); 709 return v8::Local<v8::Value>();
748 return val; 710 return val;
749 } 711 }
750 712
751 unsigned JS_GetArrayLength(v8::Local<v8::Array> pArray) { 713 unsigned JS_GetArrayLength(v8::Local<v8::Array> pArray) {
752 if (pArray.IsEmpty()) 714 if (pArray.IsEmpty())
753 return 0; 715 return 0;
754 return pArray->Length(); 716 return pArray->Length();
755 } 717 }
756 718
757 v8::Local<v8::Value> JS_NewNumber(IJS_Runtime* pJSRuntime, int number) { 719 v8::Local<v8::Value> JS_NewNumber(v8::Isolate* pIsolate, int number) {
758 return v8::Int32::New(pJSRuntime, number); 720 return v8::Int32::New(pIsolate, number);
759 } 721 }
760 722
761 v8::Local<v8::Value> JS_NewNumber(IJS_Runtime* pJSRuntime, double number) { 723 v8::Local<v8::Value> JS_NewNumber(v8::Isolate* pIsolate, double number) {
762 return v8::Number::New(pJSRuntime, number); 724 return v8::Number::New(pIsolate, number);
763 } 725 }
764 726
765 v8::Local<v8::Value> JS_NewNumber(IJS_Runtime* pJSRuntime, float number) { 727 v8::Local<v8::Value> JS_NewNumber(v8::Isolate* pIsolate, float number) {
766 return v8::Number::New(pJSRuntime, (float)number); 728 return v8::Number::New(pIsolate, (float)number);
767 } 729 }
768 730
769 v8::Local<v8::Value> JS_NewBoolean(IJS_Runtime* pJSRuntime, bool b) { 731 v8::Local<v8::Value> JS_NewBoolean(v8::Isolate* pIsolate, bool b) {
770 return v8::Boolean::New(pJSRuntime, b); 732 return v8::Boolean::New(pIsolate, b);
771 } 733 }
772 734
773 v8::Local<v8::Value> JS_NewObject(IJS_Runtime* pJSRuntime, 735 v8::Local<v8::Value> JS_NewObject(v8::Isolate* pIsolate,
774 v8::Local<v8::Object> pObj) { 736 v8::Local<v8::Object> pObj) {
775 if (pObj.IsEmpty()) 737 if (pObj.IsEmpty())
776 return v8::Local<v8::Value>(); 738 return v8::Local<v8::Value>();
777 return pObj->Clone(); 739 return pObj->Clone();
778 } 740 }
779 741
780 v8::Local<v8::Value> JS_NewObject2(IJS_Runtime* pJSRuntime, 742 v8::Local<v8::Value> JS_NewObject2(v8::Isolate* pIsolate,
781 v8::Local<v8::Array> pObj) { 743 v8::Local<v8::Array> pObj) {
782 if (pObj.IsEmpty()) 744 if (pObj.IsEmpty())
783 return v8::Local<v8::Value>(); 745 return v8::Local<v8::Value>();
784 return pObj->Clone(); 746 return pObj->Clone();
785 } 747 }
786 748
787 v8::Local<v8::Value> JS_NewString(IJS_Runtime* pJSRuntime, 749 v8::Local<v8::Value> JS_NewString(v8::Isolate* pIsolate,
788 const wchar_t* string) { 750 const wchar_t* string) {
789 return WSToJSString(pJSRuntime, string); 751 return WSToJSString(pIsolate, string);
790 } 752 }
791 753
792 v8::Local<v8::Value> JS_NewString(IJS_Runtime* pJSRuntime, 754 v8::Local<v8::Value> JS_NewString(v8::Isolate* pIsolate,
793 const wchar_t* string, 755 const wchar_t* string,
794 unsigned nLen) { 756 unsigned nLen) {
795 return WSToJSString(pJSRuntime, string, nLen); 757 return WSToJSString(pIsolate, string, nLen);
796 } 758 }
797 759
798 v8::Local<v8::Value> JS_NewNull() { 760 v8::Local<v8::Value> JS_NewNull() {
799 return v8::Local<v8::Value>(); 761 return v8::Local<v8::Value>();
800 } 762 }
801 763
802 v8::Local<v8::Value> JS_NewDate(IJS_Runtime* pJSRuntime, double d) { 764 v8::Local<v8::Value> JS_NewDate(v8::Isolate* pIsolate, double d) {
803 return v8::Date::New(pJSRuntime->GetCurrentContext(), d).ToLocalChecked(); 765 return v8::Date::New(pIsolate->GetCurrentContext(), d).ToLocalChecked();
804 } 766 }
805 767
806 v8::Local<v8::Value> JS_NewValue(IJS_Runtime* pJSRuntime) { 768 v8::Local<v8::Value> JS_NewValue(v8::Isolate* pIsolate) {
807 return v8::Local<v8::Value>(); 769 return v8::Local<v8::Value>();
808 } 770 }
809 771
810 v8::Local<v8::Value> JS_GetListValue(IJS_Runtime* pJSRuntime, 772 v8::Local<v8::Value> JS_GetListValue(v8::Isolate* pIsolate,
811 v8::Local<v8::Value> pList, 773 v8::Local<v8::Value> pList,
812 int index) { 774 int index) {
813 v8::Local<v8::Context> context = pJSRuntime->GetCurrentContext(); 775 v8::Local<v8::Context> context = pIsolate->GetCurrentContext();
814 if (!pList.IsEmpty() && pList->IsObject()) { 776 if (!pList.IsEmpty() && pList->IsObject()) {
815 v8::Local<v8::Object> obj; 777 v8::Local<v8::Object> obj;
816 if (pList->ToObject(context).ToLocal(&obj)) { 778 if (pList->ToObject(context).ToLocal(&obj)) {
817 v8::Local<v8::Value> val; 779 v8::Local<v8::Value> val;
818 if (obj->Get(context, index).ToLocal(&val)) 780 if (obj->Get(context, index).ToLocal(&val))
819 return val; 781 return val;
820 } 782 }
821 } 783 }
822 return v8::Local<v8::Value>(); 784 return v8::Local<v8::Value>();
823 } 785 }
824 786
825 int JS_ToInt32(IJS_Runtime* pJSRuntime, v8::Local<v8::Value> pValue) { 787 int JS_ToInt32(v8::Isolate* pIsolate, v8::Local<v8::Value> pValue) {
826 if (pValue.IsEmpty()) 788 if (pValue.IsEmpty())
827 return 0; 789 return 0;
828 v8::Local<v8::Context> context = pJSRuntime->GetCurrentContext(); 790 v8::Local<v8::Context> context = pIsolate->GetCurrentContext();
829 return pValue->ToInt32(context).ToLocalChecked()->Value(); 791 return pValue->ToInt32(context).ToLocalChecked()->Value();
830 } 792 }
831 793
832 bool JS_ToBoolean(IJS_Runtime* pJSRuntime, v8::Local<v8::Value> pValue) { 794 bool JS_ToBoolean(v8::Isolate* pIsolate, v8::Local<v8::Value> pValue) {
833 if (pValue.IsEmpty()) 795 if (pValue.IsEmpty())
834 return false; 796 return false;
835 v8::Local<v8::Context> context = pJSRuntime->GetCurrentContext(); 797 v8::Local<v8::Context> context = pIsolate->GetCurrentContext();
836 return pValue->ToBoolean(context).ToLocalChecked()->Value(); 798 return pValue->ToBoolean(context).ToLocalChecked()->Value();
837 } 799 }
838 800
839 double JS_ToNumber(IJS_Runtime* pJSRuntime, v8::Local<v8::Value> pValue) { 801 double JS_ToNumber(v8::Isolate* pIsolate, v8::Local<v8::Value> pValue) {
840 if (pValue.IsEmpty()) 802 if (pValue.IsEmpty())
841 return 0.0; 803 return 0.0;
842 v8::Local<v8::Context> context = pJSRuntime->GetCurrentContext(); 804 v8::Local<v8::Context> context = pIsolate->GetCurrentContext();
843 return pValue->ToNumber(context).ToLocalChecked()->Value(); 805 return pValue->ToNumber(context).ToLocalChecked()->Value();
844 } 806 }
845 807
846 v8::Local<v8::Object> JS_ToObject(IJS_Runtime* pJSRuntime, 808 v8::Local<v8::Object> JS_ToObject(v8::Isolate* pIsolate,
847 v8::Local<v8::Value> pValue) { 809 v8::Local<v8::Value> pValue) {
848 if (pValue.IsEmpty()) 810 if (pValue.IsEmpty())
849 return v8::Local<v8::Object>(); 811 return v8::Local<v8::Object>();
850 v8::Local<v8::Context> context = pJSRuntime->GetCurrentContext(); 812 v8::Local<v8::Context> context = pIsolate->GetCurrentContext();
851 return pValue->ToObject(context).ToLocalChecked(); 813 return pValue->ToObject(context).ToLocalChecked();
852 } 814 }
853 815
854 CFX_WideString JS_ToString(IJS_Runtime* pJSRuntime, 816 CFX_WideString JS_ToString(v8::Isolate* pIsolate, v8::Local<v8::Value> pValue) {
855 v8::Local<v8::Value> pValue) {
856 if (pValue.IsEmpty()) 817 if (pValue.IsEmpty())
857 return L""; 818 return L"";
858 v8::Local<v8::Context> context = pJSRuntime->GetCurrentContext(); 819 v8::Local<v8::Context> context = pIsolate->GetCurrentContext();
859 v8::String::Utf8Value s(pValue->ToString(context).ToLocalChecked()); 820 v8::String::Utf8Value s(pValue->ToString(context).ToLocalChecked());
860 return CFX_WideString::FromUTF8(*s, s.length()); 821 return CFX_WideString::FromUTF8(*s, s.length());
861 } 822 }
862 823
863 v8::Local<v8::Array> JS_ToArray(IJS_Runtime* pJSRuntime, 824 v8::Local<v8::Array> JS_ToArray(v8::Isolate* pIsolate,
864 v8::Local<v8::Value> pValue) { 825 v8::Local<v8::Value> pValue) {
865 if (pValue.IsEmpty()) 826 if (pValue.IsEmpty())
866 return v8::Local<v8::Array>(); 827 return v8::Local<v8::Array>();
867 v8::Local<v8::Context> context = pJSRuntime->GetCurrentContext(); 828 v8::Local<v8::Context> context = pIsolate->GetCurrentContext();
868 return v8::Local<v8::Array>::Cast(pValue->ToObject(context).ToLocalChecked()); 829 return v8::Local<v8::Array>::Cast(pValue->ToObject(context).ToLocalChecked());
869 } 830 }
870 831
871 void JS_ValueCopy(v8::Local<v8::Value>& pTo, v8::Local<v8::Value> pFrom) { 832 void JS_ValueCopy(v8::Local<v8::Value>& pTo, v8::Local<v8::Value> pFrom) {
872 pTo = pFrom; 833 pTo = pFrom;
873 } 834 }
874 835
875 // JavaScript time implement begin. 836 // JavaScript time implement begin.
876 837
877 double _getLocalTZA() { 838 double _getLocalTZA() {
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
1149 1110
1150 bool JS_PortIsNan(double d) { 1111 bool JS_PortIsNan(double d) {
1151 return d != d; 1112 return d != d;
1152 } 1113 }
1153 1114
1154 double JS_LocalTime(double d) { 1115 double JS_LocalTime(double d) {
1155 return JS_GetDateTime() + _getDaylightSavingTA(d); 1116 return JS_GetDateTime() + _getDaylightSavingTA(d);
1156 } 1117 }
1157 1118
1158 // JavaScript time implement End. 1119 // JavaScript time implement End.
OLDNEW
« no previous file with comments | « fpdfsdk/src/javascript/global.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698