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

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

Issue 1334833003: Merge to XFA: Remove some abstractions in fxjs_v8.h. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: 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::Locker locker(pIsolate);
284 v8::Locker locker(isolate); 276 v8::HandleScope handle_scope(pIsolate);
285 v8::HandleScope handle_scope(isolate);
286 277
287 v8::Global<v8::ObjectTemplate>& globalObjTemp = 278 v8::Global<v8::ObjectTemplate>& globalObjTemp =
288 _getGlobalObjectTemplate(pJSRuntime); 279 _getGlobalObjectTemplate(pIsolate);
289 v8::Local<v8::Context> v8Context = v8::Context::New( 280 v8::Local<v8::Context> v8Context = v8::Context::New(
290 isolate, NULL, 281 pIsolate, NULL,
291 v8::Local<v8::ObjectTemplate>::New(isolate, globalObjTemp)); 282 v8::Local<v8::ObjectTemplate>::New(pIsolate, globalObjTemp));
292 v8::Context::Scope context_scope(v8Context); 283 v8::Context::Scope context_scope(v8Context);
293 284
294 // v8::Local<External> ptr = External::New(isolate, pFXRuntime); 285 // v8::Local<External> ptr = External::New(isolate, pFXRuntime);
295 // v8Context->SetEmbedderData(1, ptr); 286 // v8Context->SetEmbedderData(1, ptr);
296 // TODO(tsepez): Don't use more than one embedder data slot. 287 // TODO(tsepez): Don't use more than one embedder data slot.
297 isolate->SetData(2, pFXRuntime); 288 pIsolate->SetData(2, pFXRuntime);
298 289
299 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlot); 290 CFX_PtrArray* pArray = (CFX_PtrArray*)pIsolate->GetData(g_embedderDataSlot);
300 if (!pArray) 291 if (!pArray)
301 return; 292 return;
302 293
303 for (int i = 0; i < pArray->GetSize(); i++) { 294 for (int i = 0; i < pArray->GetSize(); i++) {
304 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(i); 295 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(i);
305 CFX_WideString ws = CFX_WideString(pObjDef->objName); 296 CFX_WideString ws = CFX_WideString(pObjDef->objName);
306 CFX_ByteString bs = ws.UTF8Encode(); 297 CFX_ByteString bs = ws.UTF8Encode();
307 v8::Local<v8::String> objName = 298 v8::Local<v8::String> objName =
308 v8::String::NewFromUtf8(isolate, bs.c_str(), v8::NewStringType::kNormal, 299 v8::String::NewFromUtf8(pIsolate, bs.c_str(),
309 bs.GetLength()) 300 v8::NewStringType::kNormal,
310 .ToLocalChecked(); 301 bs.GetLength()).ToLocalChecked();
311 302
312 if (pObjDef->objType == JS_DYNAMIC) { 303 if (pObjDef->objType == JS_DYNAMIC) {
313 // Document is set as global object, need to construct it first. 304 // Document is set as global object, need to construct it first.
314 CFX_WideString wsString(L"Document"); 305 CFX_WideString wsString(L"Document");
315 if (ws.Equal(wsString)) { 306 if (ws.Equal(wsString)) {
316 CJS_PrivateData* pPrivateData = new CJS_PrivateData; 307 CJS_PrivateData* pPrivateData = new CJS_PrivateData;
317 pPrivateData->ObjDefID = i; 308 pPrivateData->ObjDefID = i;
318 309
319 v8Context->Global() 310 v8Context->Global()
320 ->GetPrototype() 311 ->GetPrototype()
321 ->ToObject(v8Context) 312 ->ToObject(v8Context)
322 .ToLocalChecked() 313 .ToLocalChecked()
323 ->SetAlignedPointerInInternalField(0, pPrivateData); 314 ->SetAlignedPointerInInternalField(0, pPrivateData);
324 315
325 if (pObjDef->m_pConstructor) 316 if (pObjDef->m_pConstructor)
326 pObjDef->m_pConstructor(context, v8Context->Global() 317 pObjDef->m_pConstructor(context, v8Context->Global()
327 ->GetPrototype() 318 ->GetPrototype()
328 ->ToObject(v8Context) 319 ->ToObject(v8Context)
329 .ToLocalChecked(), 320 .ToLocalChecked(),
330 v8Context->Global() 321 v8Context->Global()
331 ->GetPrototype() 322 ->GetPrototype()
332 ->ToObject(v8Context) 323 ->ToObject(v8Context)
333 .ToLocalChecked()); 324 .ToLocalChecked());
334 } 325 }
335 } else { 326 } else {
336 v8::Local<v8::Object> obj = JS_NewFxDynamicObj(pJSRuntime, context, i); 327 v8::Local<v8::Object> obj = JS_NewFxDynamicObj(pIsolate, context, i);
337 v8Context->Global()->Set(v8Context, objName, obj).FromJust(); 328 v8Context->Global()->Set(v8Context, objName, obj).FromJust();
338 pObjDef->m_StaticObj.Reset(isolate, obj); 329 pObjDef->m_StaticObj.Reset(pIsolate, obj);
339 } 330 }
340 } 331 }
341 v8PersistentContext.Reset(isolate, v8Context); 332 v8PersistentContext.Reset(pIsolate, v8Context);
342 } 333 }
343 334
344 void JS_ReleaseRuntime(IJS_Runtime* pJSRuntime, 335 void JS_ReleaseRuntime(v8::Isolate* pIsolate,
345 v8::Global<v8::Context>& v8PersistentContext) { 336 v8::Global<v8::Context>& v8PersistentContext) {
346 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; 337 v8::Isolate::Scope isolate_scope(pIsolate);
347 v8::Isolate::Scope isolate_scope(isolate); 338 v8::Locker locker(pIsolate);
348 v8::Locker locker(isolate); 339 v8::HandleScope handle_scope(pIsolate);
349 v8::HandleScope handle_scope(isolate); 340 v8::Local<v8::Context> context =
341 v8::Local<v8::Context>::New(pIsolate, v8PersistentContext);
342 v8::Context::Scope context_scope(context);
350 343
351 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlot); 344 CFX_PtrArray* pArray = (CFX_PtrArray*)pIsolate->GetData(g_embedderDataSlot);
352 if (!pArray) 345 if (!pArray)
353 return; 346 return;
354 347
355 for (int i = 0; i < pArray->GetSize(); i++) { 348 for (int i = 0; i < pArray->GetSize(); i++) {
356 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(i); 349 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(i);
357 if (!pObjDef->m_StaticObj.IsEmpty()) { 350 if (!pObjDef->m_StaticObj.IsEmpty()) {
358 v8::Local<v8::Object> pObj = 351 v8::Local<v8::Object> pObj =
359 v8::Local<v8::Object>::New(isolate, pObjDef->m_StaticObj); 352 v8::Local<v8::Object>::New(pIsolate, pObjDef->m_StaticObj);
360 if (pObjDef->m_pDestructor) 353 if (pObjDef->m_pDestructor)
361 pObjDef->m_pDestructor(pObj); 354 pObjDef->m_pDestructor(pObj);
362 JS_FreePrivate(pObj); 355 JS_FreePrivate(pObj);
363 } 356 }
364 delete pObjDef; 357 delete pObjDef;
365 } 358 }
366 delete pArray; 359 delete pArray;
367 isolate->SetData(1, NULL); 360
368 isolate->SetData(g_embedderDataSlot, NULL); 361 pIsolate->SetData(1, NULL);
362 pIsolate->SetData(g_embedderDataSlot, NULL);
369 // TODO(tsepez): Don't use more than one embedder data slot. 363 // TODO(tsepez): Don't use more than one embedder data slot.
370 isolate->SetData(2, NULL); 364 pIsolate->SetData(2, NULL);
371 } 365 }
372 366
373 void JS_Initial(unsigned int embedderDataSlot) { 367 void JS_Initial(unsigned int embedderDataSlot) {
374 g_embedderDataSlot = embedderDataSlot; 368 g_embedderDataSlot = embedderDataSlot;
375 } 369 }
376 370
377 void JS_Release() { 371 void JS_Release() {
378 } 372 }
379 373
380 int JS_Execute(IJS_Runtime* pJSRuntime, 374 int JS_Execute(v8::Isolate* pIsolate,
381 IFXJS_Context* pJSContext, 375 IFXJS_Context* pJSContext,
382 const wchar_t* script, 376 const wchar_t* script,
383 long length, 377 long length,
384 FXJSErr* perror) { 378 FXJSErr* perror) {
385 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; 379 v8::Isolate::Scope isolate_scope(pIsolate);
386 v8::Isolate::Scope isolate_scope(isolate); 380 v8::TryCatch try_catch(pIsolate);
387 v8::TryCatch try_catch(isolate);
388 381
389 CFX_WideString wsScript(script); 382 CFX_WideString wsScript(script);
390 CFX_ByteString bsScript = wsScript.UTF8Encode(); 383 CFX_ByteString bsScript = wsScript.UTF8Encode();
391 384
392 v8::Local<v8::Context> context = isolate->GetCurrentContext(); 385 v8::Local<v8::Context> context = pIsolate->GetCurrentContext();
393 v8::Local<v8::Script> compiled_script; 386 v8::Local<v8::Script> compiled_script;
394 if (!v8::Script::Compile(context, 387 if (!v8::Script::Compile(
395 v8::String::NewFromUtf8(isolate, bsScript.c_str(), 388 context, v8::String::NewFromUtf8(
396 v8::NewStringType::kNormal, 389 pIsolate, bsScript.c_str(), v8::NewStringType::kNormal,
397 bsScript.GetLength()) 390 bsScript.GetLength()).ToLocalChecked())
398 .ToLocalChecked())
399 .ToLocal(&compiled_script)) { 391 .ToLocal(&compiled_script)) {
400 v8::String::Utf8Value error(try_catch.Exception()); 392 v8::String::Utf8Value error(try_catch.Exception());
401 return -1; 393 return -1;
402 } 394 }
403 395
404 v8::Local<v8::Value> result; 396 v8::Local<v8::Value> result;
405 if (!compiled_script->Run(context).ToLocal(&result)) { 397 if (!compiled_script->Run(context).ToLocal(&result)) {
406 v8::String::Utf8Value error(try_catch.Exception()); 398 v8::String::Utf8Value error(try_catch.Exception());
407 return -1; 399 return -1;
408 } 400 }
409 return 0; 401 return 0;
410 } 402 }
411 403
412 v8::Local<v8::Object> JS_NewFxDynamicObj(IJS_Runtime* pJSRuntime, 404 v8::Local<v8::Object> JS_NewFxDynamicObj(v8::Isolate* pIsolate,
413 IFXJS_Context* pJSContext, 405 IFXJS_Context* pJSContext,
414 int nObjDefnID) { 406 int nObjDefnID) {
415 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; 407 v8::Isolate::Scope isolate_scope(pIsolate);
416 v8::Isolate::Scope isolate_scope(isolate); 408 v8::Local<v8::Context> context = pIsolate->GetCurrentContext();
417 v8::Local<v8::Context> context = isolate->GetCurrentContext();
418 if (-1 == nObjDefnID) { 409 if (-1 == nObjDefnID) {
419 v8::Local<v8::ObjectTemplate> objTempl = v8::ObjectTemplate::New(isolate); 410 v8::Local<v8::ObjectTemplate> objTempl = v8::ObjectTemplate::New(pIsolate);
420 v8::Local<v8::Object> obj; 411 v8::Local<v8::Object> obj;
421 if (objTempl->NewInstance(context).ToLocal(&obj)) 412 if (objTempl->NewInstance(context).ToLocal(&obj))
422 return obj; 413 return obj;
423 return v8::Local<v8::Object>(); 414 return v8::Local<v8::Object>();
424 } 415 }
425 416
426 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlot); 417 CFX_PtrArray* pArray = (CFX_PtrArray*)pIsolate->GetData(g_embedderDataSlot);
427 if (!pArray) 418 if (!pArray)
428 return v8::Local<v8::Object>(); 419 return v8::Local<v8::Object>();
429 420
430 if (nObjDefnID < 0 || nObjDefnID >= pArray->GetSize()) 421 if (nObjDefnID < 0 || nObjDefnID >= pArray->GetSize())
431 return v8::Local<v8::Object>(); 422 return v8::Local<v8::Object>();
432 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID); 423 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID);
433 424
434 v8::Local<v8::ObjectTemplate> objTemp = 425 v8::Local<v8::ObjectTemplate> objTemp =
435 v8::Local<v8::ObjectTemplate>::New(isolate, pObjDef->m_objTemplate); 426 v8::Local<v8::ObjectTemplate>::New(pIsolate, pObjDef->m_objTemplate);
436 v8::Local<v8::Object> obj; 427 v8::Local<v8::Object> obj;
437 if (!objTemp->NewInstance(context).ToLocal(&obj)) 428 if (!objTemp->NewInstance(context).ToLocal(&obj))
438 return v8::Local<v8::Object>(); 429 return v8::Local<v8::Object>();
439 CJS_PrivateData* pPrivateData = new CJS_PrivateData; 430 CJS_PrivateData* pPrivateData = new CJS_PrivateData;
440 pPrivateData->ObjDefID = nObjDefnID; 431 pPrivateData->ObjDefID = nObjDefnID;
441 432
442 obj->SetAlignedPointerInInternalField(0, pPrivateData); 433 obj->SetAlignedPointerInInternalField(0, pPrivateData);
443 if (pObjDef->m_pConstructor) 434 if (pObjDef->m_pConstructor)
444 pObjDef->m_pConstructor( 435 pObjDef->m_pConstructor(
445 pJSContext, obj, 436 pJSContext, obj,
446 context->Global()->GetPrototype()->ToObject(context).ToLocalChecked()); 437 context->Global()->GetPrototype()->ToObject(context).ToLocalChecked());
447 438
448 return obj; 439 return obj;
449 } 440 }
450 441
451 v8::Local<v8::Object> JS_GetStaticObj(IJS_Runtime* pJSRuntime, int nObjDefnID) { 442 v8::Local<v8::Object> JS_GetStaticObj(v8::Isolate* pIsolate, int nObjDefnID) {
452 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; 443 v8::Isolate::Scope isolate_scope(pIsolate);
453 v8::Isolate::Scope isolate_scope(isolate); 444 CFX_PtrArray* pArray = (CFX_PtrArray*)pIsolate->GetData(g_embedderDataSlot);
454
455 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlot);
456 if (!pArray) 445 if (!pArray)
457 return v8::Local<v8::Object>(); 446 return v8::Local<v8::Object>();
458 447
459 if (nObjDefnID < 0 || nObjDefnID >= pArray->GetSize()) 448 if (nObjDefnID < 0 || nObjDefnID >= pArray->GetSize())
460 return v8::Local<v8::Object>(); 449 return v8::Local<v8::Object>();
461 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID); 450 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID);
462 v8::Local<v8::Object> obj = 451 v8::Local<v8::Object> obj =
463 v8::Local<v8::Object>::New(isolate, pObjDef->m_StaticObj); 452 v8::Local<v8::Object>::New(pIsolate, pObjDef->m_StaticObj);
464 return obj; 453 return obj;
465 } 454 }
466 455
467 void JS_SetThisObj(IJS_Runtime* pJSRuntime, int nThisObjID) { 456 v8::Local<v8::Object> JS_GetThisObj(v8::Isolate* pIsolate) {
468 // Do nothing.
469 }
470 v8::Local<v8::Object> JS_GetThisObj(IJS_Runtime* pJSRuntime) {
471 // Return the global object. 457 // Return the global object.
472 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; 458 v8::Isolate::Scope isolate_scope(pIsolate);
473 v8::Isolate::Scope isolate_scope(isolate); 459 CFX_PtrArray* pArray = (CFX_PtrArray*)pIsolate->GetData(g_embedderDataSlot);
474
475 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlot);
476 if (!pArray) 460 if (!pArray)
477 return v8::Local<v8::Object>(); 461 return v8::Local<v8::Object>();
478 462
479 v8::Local<v8::Context> context = isolate->GetCurrentContext(); 463 v8::Local<v8::Context> context = pIsolate->GetCurrentContext();
480 return context->Global()->GetPrototype()->ToObject(context).ToLocalChecked(); 464 return context->Global()->GetPrototype()->ToObject(context).ToLocalChecked();
481 } 465 }
482 466
483 int JS_GetObjDefnID(v8::Local<v8::Object> pObj) { 467 int JS_GetObjDefnID(v8::Local<v8::Object> pObj) {
484 if (pObj.IsEmpty() || !pObj->InternalFieldCount()) 468 if (pObj.IsEmpty() || !pObj->InternalFieldCount())
485 return -1; 469 return -1;
486 CJS_PrivateData* pPrivateData = 470 CJS_PrivateData* pPrivateData =
487 (CJS_PrivateData*)pObj->GetAlignedPointerFromInternalField(0); 471 (CJS_PrivateData*)pObj->GetAlignedPointerFromInternalField(0);
488 if (pPrivateData) 472 if (pPrivateData)
489 return pPrivateData->ObjDefID; 473 return pPrivateData->ObjDefID;
490 return -1; 474 return -1;
491 } 475 }
492 476
493 IJS_Runtime* JS_GetRuntime(v8::Local<v8::Object> pObj) { 477 v8::Isolate* JS_GetRuntime(v8::Local<v8::Object> pObj) {
494 if (pObj.IsEmpty()) 478 if (pObj.IsEmpty())
495 return NULL; 479 return NULL;
496 v8::Local<v8::Context> context = pObj->CreationContext(); 480 v8::Local<v8::Context> context = pObj->CreationContext();
497 if (context.IsEmpty()) 481 if (context.IsEmpty())
498 return NULL; 482 return NULL;
499 return context->GetIsolate(); 483 return context->GetIsolate();
500 } 484 }
501 485
502 int JS_GetObjDefnID(IJS_Runtime* pJSRuntime, const wchar_t* pObjName) { 486 int JS_GetObjDefnID(v8::Isolate* pIsolate, const wchar_t* pObjName) {
503 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; 487 v8::Isolate::Scope isolate_scope(pIsolate);
504 v8::Isolate::Scope isolate_scope(isolate); 488 CFX_PtrArray* pArray = (CFX_PtrArray*)pIsolate->GetData(g_embedderDataSlot);
505
506 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlot);
507 if (!pArray) 489 if (!pArray)
508 return -1; 490 return -1;
509 491
510 for (int i = 0; i < pArray->GetSize(); i++) { 492 for (int i = 0; i < pArray->GetSize(); i++) {
511 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(i); 493 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(i);
512 if (FXSYS_wcscmp(pObjDef->objName, pObjName) == 0) 494 if (FXSYS_wcscmp(pObjDef->objName, pObjName) == 0)
513 return i; 495 return i;
514 } 496 }
515 return -1; 497 return -1;
516 } 498 }
517 499
518 void JS_Error(v8::Isolate* isolate, const CFX_WideString& message) { 500 void JS_Error(v8::Isolate* pIsolate, const CFX_WideString& message) {
519 // Conversion from pdfium's wchar_t wide-strings to v8's uint16_t 501 // Conversion from pdfium's wchar_t wide-strings to v8's uint16_t
520 // wide-strings isn't handled by v8, so use UTF8 as a common 502 // wide-strings isn't handled by v8, so use UTF8 as a common
521 // intermediate format. 503 // intermediate format.
522 CFX_ByteString utf8_message = message.UTF8Encode(); 504 CFX_ByteString utf8_message = message.UTF8Encode();
523 isolate->ThrowException(v8::String::NewFromUtf8(isolate, utf8_message.c_str(), 505 pIsolate->ThrowException(
524 v8::NewStringType::kNormal) 506 v8::String::NewFromUtf8(pIsolate, utf8_message.c_str(),
525 .ToLocalChecked()); 507 v8::NewStringType::kNormal).ToLocalChecked());
526 } 508 }
527 509
528 unsigned JS_CalcHash(const wchar_t* main, unsigned nLen) { 510 unsigned JS_CalcHash(const wchar_t* main, unsigned nLen) {
529 return (unsigned)FX_HashCode_String_GetW((const FX_WCHAR*)main, nLen); 511 return (unsigned)FX_HashCode_String_GetW((const FX_WCHAR*)main, nLen);
530 } 512 }
531 513
532 unsigned JS_CalcHash(const wchar_t* main) { 514 unsigned JS_CalcHash(const wchar_t* main) {
533 return (unsigned)FX_HashCode_String_GetW((const FX_WCHAR*)main, 515 return (unsigned)FX_HashCode_String_GetW((const FX_WCHAR*)main,
534 FXSYS_wcslen(main)); 516 FXSYS_wcslen(main));
535 } 517 }
(...skipping 17 matching lines...) Expand all
553 return NULL; 535 return NULL;
554 } 536 }
555 void JS_SetPrivate(v8::Local<v8::Object> pObj, void* p) { 537 void JS_SetPrivate(v8::Local<v8::Object> pObj, void* p) {
556 JS_SetPrivate(NULL, pObj, p); 538 JS_SetPrivate(NULL, pObj, p);
557 } 539 }
558 540
559 void* JS_GetPrivate(v8::Local<v8::Object> pObj) { 541 void* JS_GetPrivate(v8::Local<v8::Object> pObj) {
560 return JS_GetPrivate(NULL, pObj); 542 return JS_GetPrivate(NULL, pObj);
561 } 543 }
562 544
563 void JS_SetPrivate(IJS_Runtime* pJSRuntime, 545 void JS_SetPrivate(v8::Isolate* pIsolate, v8::Local<v8::Object> pObj, void* p) {
564 v8::Local<v8::Object> pObj,
565 void* p) {
566 if (pObj.IsEmpty() || !pObj->InternalFieldCount()) 546 if (pObj.IsEmpty() || !pObj->InternalFieldCount())
567 return; 547 return;
568 CJS_PrivateData* pPrivateData = 548 CJS_PrivateData* pPrivateData =
569 (CJS_PrivateData*)pObj->GetAlignedPointerFromInternalField(0); 549 (CJS_PrivateData*)pObj->GetAlignedPointerFromInternalField(0);
570 if (!pPrivateData) 550 if (!pPrivateData)
571 return; 551 return;
572 pPrivateData->pPrivate = p; 552 pPrivateData->pPrivate = p;
573 } 553 }
574 554
575 void* JS_GetPrivate(IJS_Runtime* pJSRuntime, v8::Local<v8::Object> pObj) { 555 void* JS_GetPrivate(v8::Isolate* pIsolate, v8::Local<v8::Object> pObj) {
576 if (pObj.IsEmpty()) 556 if (pObj.IsEmpty())
577 return NULL; 557 return NULL;
578 CJS_PrivateData* pPrivateData = NULL; 558 CJS_PrivateData* pPrivateData = NULL;
579 if (pObj->InternalFieldCount()) 559 if (pObj->InternalFieldCount())
580 pPrivateData = 560 pPrivateData =
581 (CJS_PrivateData*)pObj->GetAlignedPointerFromInternalField(0); 561 (CJS_PrivateData*)pObj->GetAlignedPointerFromInternalField(0);
582 else { 562 else {
583 // It could be a global proxy object. 563 // It could be a global proxy object.
584 v8::Local<v8::Value> v = pObj->GetPrototype(); 564 v8::Local<v8::Value> v = pObj->GetPrototype();
585 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; 565 v8::Isolate* isolate = (v8::Isolate*)pIsolate;
586 v8::Local<v8::Context> context = isolate->GetCurrentContext(); 566 v8::Local<v8::Context> context = isolate->GetCurrentContext();
587 if (v->IsObject()) 567 if (v->IsObject())
588 pPrivateData = (CJS_PrivateData*)v->ToObject(context) 568 pPrivateData = (CJS_PrivateData*)v->ToObject(context)
589 .ToLocalChecked() 569 .ToLocalChecked()
590 ->GetAlignedPointerFromInternalField(0); 570 ->GetAlignedPointerFromInternalField(0);
591 } 571 }
592 if (!pPrivateData) 572 if (!pPrivateData)
593 return NULL; 573 return NULL;
594 return pPrivateData->pPrivate; 574 return pPrivateData->pPrivate;
595 } 575 }
596 576
597 void JS_FreePrivate(void* pPrivateData) { 577 void JS_FreePrivate(void* pPrivateData) {
598 delete (CJS_PrivateData*)pPrivateData; 578 delete (CJS_PrivateData*)pPrivateData;
599 } 579 }
600 580
601 void JS_FreePrivate(v8::Local<v8::Object> pObj) { 581 void JS_FreePrivate(v8::Local<v8::Object> pObj) {
602 if (pObj.IsEmpty() || !pObj->InternalFieldCount()) 582 if (pObj.IsEmpty() || !pObj->InternalFieldCount())
603 return; 583 return;
604 JS_FreePrivate(pObj->GetAlignedPointerFromInternalField(0)); 584 JS_FreePrivate(pObj->GetAlignedPointerFromInternalField(0));
605 pObj->SetAlignedPointerInInternalField(0, NULL); 585 pObj->SetAlignedPointerInInternalField(0, NULL);
606 } 586 }
607 587
608 v8::Local<v8::Value> JS_GetObjectValue(v8::Local<v8::Object> pObj) { 588 v8::Local<v8::Value> JS_GetObjectValue(v8::Local<v8::Object> pObj) {
609 return pObj; 589 return pObj;
610 } 590 }
611 591
612 v8::Local<v8::String> WSToJSString(IJS_Runtime* pJSRuntime, 592 v8::Local<v8::String> WSToJSString(v8::Isolate* pIsolate,
613 const wchar_t* PropertyName, 593 const wchar_t* PropertyName,
614 int Len = -1) { 594 int Len = -1) {
615 CFX_WideString ws = CFX_WideString(PropertyName, Len); 595 CFX_WideString ws = CFX_WideString(PropertyName, Len);
616 CFX_ByteString bs = ws.UTF8Encode(); 596 CFX_ByteString bs = ws.UTF8Encode();
617 if (!pJSRuntime) 597 if (!pIsolate)
618 pJSRuntime = v8::Isolate::GetCurrent(); 598 pIsolate = v8::Isolate::GetCurrent();
619 return v8::String::NewFromUtf8(pJSRuntime, bs.c_str(), 599 return v8::String::NewFromUtf8(pIsolate, bs.c_str(),
620 v8::NewStringType::kNormal) 600 v8::NewStringType::kNormal).ToLocalChecked();
621 .ToLocalChecked();
622 } 601 }
623 602
624 v8::Local<v8::Value> JS_GetObjectElement(IJS_Runtime* pJSRuntime, 603 v8::Local<v8::Value> JS_GetObjectElement(v8::Isolate* pIsolate,
625 v8::Local<v8::Object> pObj, 604 v8::Local<v8::Object> pObj,
626 const wchar_t* PropertyName) { 605 const wchar_t* PropertyName) {
627 if (pObj.IsEmpty()) 606 if (pObj.IsEmpty())
628 return v8::Local<v8::Value>(); 607 return v8::Local<v8::Value>();
629 v8::Local<v8::Value> val; 608 v8::Local<v8::Value> val;
630 if (!pObj->Get(pJSRuntime->GetCurrentContext(), 609 if (!pObj->Get(pIsolate->GetCurrentContext(),
631 WSToJSString(pJSRuntime, PropertyName)) 610 WSToJSString(pIsolate, PropertyName)).ToLocal(&val))
632 .ToLocal(&val))
633 return v8::Local<v8::Value>(); 611 return v8::Local<v8::Value>();
634 return val; 612 return val;
635 } 613 }
636 614
637 v8::Local<v8::Array> JS_GetObjectElementNames(IJS_Runtime* pJSRuntime, 615 v8::Local<v8::Array> JS_GetObjectElementNames(v8::Isolate* pIsolate,
638 v8::Local<v8::Object> pObj) { 616 v8::Local<v8::Object> pObj) {
639 if (pObj.IsEmpty()) 617 if (pObj.IsEmpty())
640 return v8::Local<v8::Array>(); 618 return v8::Local<v8::Array>();
641 v8::Local<v8::Array> val; 619 v8::Local<v8::Array> val;
642 if (!pObj->GetPropertyNames(pJSRuntime->GetCurrentContext()).ToLocal(&val)) 620 if (!pObj->GetPropertyNames(pIsolate->GetCurrentContext()).ToLocal(&val))
643 return v8::Local<v8::Array>(); 621 return v8::Local<v8::Array>();
644 return val; 622 return val;
645 } 623 }
646 624
647 void JS_PutObjectString(IJS_Runtime* pJSRuntime, 625 void JS_PutObjectString(v8::Isolate* pIsolate,
648 v8::Local<v8::Object> pObj, 626 v8::Local<v8::Object> pObj,
649 const wchar_t* PropertyName, 627 const wchar_t* PropertyName,
650 const wchar_t* sValue) // VT_string 628 const wchar_t* sValue) // VT_string
651 { 629 {
652 if (pObj.IsEmpty()) 630 if (pObj.IsEmpty())
653 return; 631 return;
654 pObj->Set(pJSRuntime->GetCurrentContext(), 632 pObj->Set(pIsolate->GetCurrentContext(), WSToJSString(pIsolate, PropertyName),
655 WSToJSString(pJSRuntime, PropertyName), 633 WSToJSString(pIsolate, sValue)).FromJust();
656 WSToJSString(pJSRuntime, sValue))
657 .FromJust();
658 } 634 }
659 635
660 void JS_PutObjectNumber(IJS_Runtime* pJSRuntime, 636 void JS_PutObjectNumber(v8::Isolate* pIsolate,
661 v8::Local<v8::Object> pObj, 637 v8::Local<v8::Object> pObj,
662 const wchar_t* PropertyName, 638 const wchar_t* PropertyName,
663 int nValue) { 639 int nValue) {
664 if (pObj.IsEmpty()) 640 if (pObj.IsEmpty())
665 return; 641 return;
666 pObj->Set(pJSRuntime->GetCurrentContext(), 642 pObj->Set(pIsolate->GetCurrentContext(), WSToJSString(pIsolate, PropertyName),
667 WSToJSString(pJSRuntime, PropertyName), 643 v8::Int32::New(pIsolate, nValue)).FromJust();
668 v8::Int32::New(pJSRuntime, nValue))
669 .FromJust();
670 } 644 }
671 645
672 void JS_PutObjectNumber(IJS_Runtime* pJSRuntime, 646 void JS_PutObjectNumber(v8::Isolate* pIsolate,
673 v8::Local<v8::Object> pObj, 647 v8::Local<v8::Object> pObj,
674 const wchar_t* PropertyName, 648 const wchar_t* PropertyName,
675 float fValue) { 649 float fValue) {
676 if (pObj.IsEmpty()) 650 if (pObj.IsEmpty())
677 return; 651 return;
678 pObj->Set(pJSRuntime->GetCurrentContext(), 652 pObj->Set(pIsolate->GetCurrentContext(), WSToJSString(pIsolate, PropertyName),
679 WSToJSString(pJSRuntime, PropertyName), 653 v8::Number::New(pIsolate, (double)fValue)).FromJust();
680 v8::Number::New(pJSRuntime, (double)fValue))
681 .FromJust();
682 } 654 }
683 655
684 void JS_PutObjectNumber(IJS_Runtime* pJSRuntime, 656 void JS_PutObjectNumber(v8::Isolate* pIsolate,
685 v8::Local<v8::Object> pObj, 657 v8::Local<v8::Object> pObj,
686 const wchar_t* PropertyName, 658 const wchar_t* PropertyName,
687 double dValue) { 659 double dValue) {
688 if (pObj.IsEmpty()) 660 if (pObj.IsEmpty())
689 return; 661 return;
690 pObj->Set(pJSRuntime->GetCurrentContext(), 662 pObj->Set(pIsolate->GetCurrentContext(), WSToJSString(pIsolate, PropertyName),
691 WSToJSString(pJSRuntime, PropertyName), 663 v8::Number::New(pIsolate, (double)dValue)).FromJust();
692 v8::Number::New(pJSRuntime, (double)dValue))
693 .FromJust();
694 } 664 }
695 665
696 void JS_PutObjectBoolean(IJS_Runtime* pJSRuntime, 666 void JS_PutObjectBoolean(v8::Isolate* pIsolate,
697 v8::Local<v8::Object> pObj, 667 v8::Local<v8::Object> pObj,
698 const wchar_t* PropertyName, 668 const wchar_t* PropertyName,
699 bool bValue) { 669 bool bValue) {
700 if (pObj.IsEmpty()) 670 if (pObj.IsEmpty())
701 return; 671 return;
702 pObj->Set(pJSRuntime->GetCurrentContext(), 672 pObj->Set(pIsolate->GetCurrentContext(), WSToJSString(pIsolate, PropertyName),
703 WSToJSString(pJSRuntime, PropertyName), 673 v8::Boolean::New(pIsolate, bValue)).FromJust();
704 v8::Boolean::New(pJSRuntime, bValue))
705 .FromJust();
706 } 674 }
707 675
708 void JS_PutObjectObject(IJS_Runtime* pJSRuntime, 676 void JS_PutObjectObject(v8::Isolate* pIsolate,
709 v8::Local<v8::Object> pObj, 677 v8::Local<v8::Object> pObj,
710 const wchar_t* PropertyName, 678 const wchar_t* PropertyName,
711 v8::Local<v8::Object> pPut) { 679 v8::Local<v8::Object> pPut) {
712 if (pObj.IsEmpty()) 680 if (pObj.IsEmpty())
713 return; 681 return;
714 pObj->Set(pJSRuntime->GetCurrentContext(), 682 pObj->Set(pIsolate->GetCurrentContext(), WSToJSString(pIsolate, PropertyName),
715 WSToJSString(pJSRuntime, PropertyName), pPut) 683 pPut).FromJust();
716 .FromJust();
717 } 684 }
718 685
719 void JS_PutObjectNull(IJS_Runtime* pJSRuntime, 686 void JS_PutObjectNull(v8::Isolate* pIsolate,
720 v8::Local<v8::Object> pObj, 687 v8::Local<v8::Object> pObj,
721 const wchar_t* PropertyName) { 688 const wchar_t* PropertyName) {
722 if (pObj.IsEmpty()) 689 if (pObj.IsEmpty())
723 return; 690 return;
724 pObj->Set(pJSRuntime->GetCurrentContext(), 691 pObj->Set(pIsolate->GetCurrentContext(), WSToJSString(pIsolate, PropertyName),
725 WSToJSString(pJSRuntime, PropertyName), v8::Local<v8::Object>()) 692 v8::Local<v8::Object>()).FromJust();
726 .FromJust();
727 } 693 }
728 694
729 v8::Local<v8::Array> JS_NewArray(IJS_Runtime* pJSRuntime) { 695 v8::Local<v8::Array> JS_NewArray(v8::Isolate* pIsolate) {
730 return v8::Array::New(pJSRuntime); 696 return v8::Array::New(pIsolate);
731 } 697 }
732 698
733 unsigned JS_PutArrayElement(IJS_Runtime* pJSRuntime, 699 unsigned JS_PutArrayElement(v8::Isolate* pIsolate,
734 v8::Local<v8::Array> pArray, 700 v8::Local<v8::Array> pArray,
735 unsigned index, 701 unsigned index,
736 v8::Local<v8::Value> pValue, 702 v8::Local<v8::Value> pValue,
737 FXJSVALUETYPE eType) { 703 FXJSVALUETYPE eType) {
738 if (pArray.IsEmpty()) 704 if (pArray.IsEmpty())
739 return 0; 705 return 0;
740 if (pArray->Set(pJSRuntime->GetCurrentContext(), index, pValue).IsNothing()) 706 if (pArray->Set(pIsolate->GetCurrentContext(), index, pValue).IsNothing())
741 return 0; 707 return 0;
742 return 1; 708 return 1;
743 } 709 }
744 710
745 v8::Local<v8::Value> JS_GetArrayElement(IJS_Runtime* pJSRuntime, 711 v8::Local<v8::Value> JS_GetArrayElement(v8::Isolate* pIsolate,
746 v8::Local<v8::Array> pArray, 712 v8::Local<v8::Array> pArray,
747 unsigned index) { 713 unsigned index) {
748 if (pArray.IsEmpty()) 714 if (pArray.IsEmpty())
749 return v8::Local<v8::Value>(); 715 return v8::Local<v8::Value>();
750 v8::Local<v8::Value> val; 716 v8::Local<v8::Value> val;
751 if (!pArray->Get(pJSRuntime->GetCurrentContext(), index).ToLocal(&val)) 717 if (!pArray->Get(pIsolate->GetCurrentContext(), index).ToLocal(&val))
752 return v8::Local<v8::Value>(); 718 return v8::Local<v8::Value>();
753 return val; 719 return val;
754 } 720 }
755 721
756 unsigned JS_GetArrayLength(v8::Local<v8::Array> pArray) { 722 unsigned JS_GetArrayLength(v8::Local<v8::Array> pArray) {
757 if (pArray.IsEmpty()) 723 if (pArray.IsEmpty())
758 return 0; 724 return 0;
759 return pArray->Length(); 725 return pArray->Length();
760 } 726 }
761 727
762 v8::Local<v8::Value> JS_NewNumber(IJS_Runtime* pJSRuntime, int number) { 728 v8::Local<v8::Value> JS_NewNumber(v8::Isolate* pIsolate, int number) {
763 return v8::Int32::New(pJSRuntime, number); 729 return v8::Int32::New(pIsolate, number);
764 } 730 }
765 731
766 v8::Local<v8::Value> JS_NewNumber(IJS_Runtime* pJSRuntime, double number) { 732 v8::Local<v8::Value> JS_NewNumber(v8::Isolate* pIsolate, double number) {
767 return v8::Number::New(pJSRuntime, number); 733 return v8::Number::New(pIsolate, number);
768 } 734 }
769 735
770 v8::Local<v8::Value> JS_NewNumber(IJS_Runtime* pJSRuntime, float number) { 736 v8::Local<v8::Value> JS_NewNumber(v8::Isolate* pIsolate, float number) {
771 return v8::Number::New(pJSRuntime, (float)number); 737 return v8::Number::New(pIsolate, (float)number);
772 } 738 }
773 739
774 v8::Local<v8::Value> JS_NewBoolean(IJS_Runtime* pJSRuntime, bool b) { 740 v8::Local<v8::Value> JS_NewBoolean(v8::Isolate* pIsolate, bool b) {
775 return v8::Boolean::New(pJSRuntime, b); 741 return v8::Boolean::New(pIsolate, b);
776 } 742 }
777 743
778 v8::Local<v8::Value> JS_NewObject(IJS_Runtime* pJSRuntime, 744 v8::Local<v8::Value> JS_NewObject(v8::Isolate* pIsolate,
779 v8::Local<v8::Object> pObj) { 745 v8::Local<v8::Object> pObj) {
780 if (pObj.IsEmpty()) 746 if (pObj.IsEmpty())
781 return v8::Local<v8::Value>(); 747 return v8::Local<v8::Value>();
782 return pObj->Clone(); 748 return pObj->Clone();
783 } 749 }
784 750
785 v8::Local<v8::Value> JS_NewObject2(IJS_Runtime* pJSRuntime, 751 v8::Local<v8::Value> JS_NewObject2(v8::Isolate* pIsolate,
786 v8::Local<v8::Array> pObj) { 752 v8::Local<v8::Array> pObj) {
787 if (pObj.IsEmpty()) 753 if (pObj.IsEmpty())
788 return v8::Local<v8::Value>(); 754 return v8::Local<v8::Value>();
789 return pObj->Clone(); 755 return pObj->Clone();
790 } 756 }
791 757
792 v8::Local<v8::Value> JS_NewString(IJS_Runtime* pJSRuntime, 758 v8::Local<v8::Value> JS_NewString(v8::Isolate* pIsolate,
793 const wchar_t* string) { 759 const wchar_t* string) {
794 return WSToJSString(pJSRuntime, string); 760 return WSToJSString(pIsolate, string);
795 } 761 }
796 762
797 v8::Local<v8::Value> JS_NewString(IJS_Runtime* pJSRuntime, 763 v8::Local<v8::Value> JS_NewString(v8::Isolate* pIsolate,
798 const wchar_t* string, 764 const wchar_t* string,
799 unsigned nLen) { 765 unsigned nLen) {
800 return WSToJSString(pJSRuntime, string, nLen); 766 return WSToJSString(pIsolate, string, nLen);
801 } 767 }
802 768
803 v8::Local<v8::Value> JS_NewNull() { 769 v8::Local<v8::Value> JS_NewNull() {
804 return v8::Local<v8::Value>(); 770 return v8::Local<v8::Value>();
805 } 771 }
806 772
807 v8::Local<v8::Value> JS_NewDate(IJS_Runtime* pJSRuntime, double d) { 773 v8::Local<v8::Value> JS_NewDate(v8::Isolate* pIsolate, double d) {
808 return v8::Date::New(pJSRuntime->GetCurrentContext(), d).ToLocalChecked(); 774 return v8::Date::New(pIsolate->GetCurrentContext(), d).ToLocalChecked();
809 } 775 }
810 776
811 v8::Local<v8::Value> JS_NewValue(IJS_Runtime* pJSRuntime) { 777 v8::Local<v8::Value> JS_NewValue(v8::Isolate* pIsolate) {
812 return v8::Local<v8::Value>(); 778 return v8::Local<v8::Value>();
813 } 779 }
814 780
815 v8::Local<v8::Value> JS_GetListValue(IJS_Runtime* pJSRuntime, 781 v8::Local<v8::Value> JS_GetListValue(v8::Isolate* pIsolate,
816 v8::Local<v8::Value> pList, 782 v8::Local<v8::Value> pList,
817 int index) { 783 int index) {
818 v8::Local<v8::Context> context = pJSRuntime->GetCurrentContext(); 784 v8::Local<v8::Context> context = pIsolate->GetCurrentContext();
819 if (!pList.IsEmpty() && pList->IsObject()) { 785 if (!pList.IsEmpty() && pList->IsObject()) {
820 v8::Local<v8::Object> obj; 786 v8::Local<v8::Object> obj;
821 if (pList->ToObject(context).ToLocal(&obj)) { 787 if (pList->ToObject(context).ToLocal(&obj)) {
822 v8::Local<v8::Value> val; 788 v8::Local<v8::Value> val;
823 if (obj->Get(context, index).ToLocal(&val)) 789 if (obj->Get(context, index).ToLocal(&val))
824 return val; 790 return val;
825 } 791 }
826 } 792 }
827 return v8::Local<v8::Value>(); 793 return v8::Local<v8::Value>();
828 } 794 }
829 795
830 int JS_ToInt32(IJS_Runtime* pJSRuntime, v8::Local<v8::Value> pValue) { 796 int JS_ToInt32(v8::Isolate* pIsolate, v8::Local<v8::Value> pValue) {
831 if (pValue.IsEmpty()) 797 if (pValue.IsEmpty())
832 return 0; 798 return 0;
833 v8::Local<v8::Context> context = pJSRuntime->GetCurrentContext(); 799 v8::Local<v8::Context> context = pIsolate->GetCurrentContext();
834 return pValue->ToInt32(context).ToLocalChecked()->Value(); 800 return pValue->ToInt32(context).ToLocalChecked()->Value();
835 } 801 }
836 802
837 bool JS_ToBoolean(IJS_Runtime* pJSRuntime, v8::Local<v8::Value> pValue) { 803 bool JS_ToBoolean(v8::Isolate* pIsolate, v8::Local<v8::Value> pValue) {
838 if (pValue.IsEmpty()) 804 if (pValue.IsEmpty())
839 return false; 805 return false;
840 v8::Local<v8::Context> context = pJSRuntime->GetCurrentContext(); 806 v8::Local<v8::Context> context = pIsolate->GetCurrentContext();
841 return pValue->ToBoolean(context).ToLocalChecked()->Value(); 807 return pValue->ToBoolean(context).ToLocalChecked()->Value();
842 } 808 }
843 809
844 double JS_ToNumber(IJS_Runtime* pJSRuntime, v8::Local<v8::Value> pValue) { 810 double JS_ToNumber(v8::Isolate* pIsolate, v8::Local<v8::Value> pValue) {
845 if (pValue.IsEmpty()) 811 if (pValue.IsEmpty())
846 return 0.0; 812 return 0.0;
847 v8::Local<v8::Context> context = pJSRuntime->GetCurrentContext(); 813 v8::Local<v8::Context> context = pIsolate->GetCurrentContext();
848 return pValue->ToNumber(context).ToLocalChecked()->Value(); 814 return pValue->ToNumber(context).ToLocalChecked()->Value();
849 } 815 }
850 816
851 v8::Local<v8::Object> JS_ToObject(IJS_Runtime* pJSRuntime, 817 v8::Local<v8::Object> JS_ToObject(v8::Isolate* pIsolate,
852 v8::Local<v8::Value> pValue) { 818 v8::Local<v8::Value> pValue) {
853 if (pValue.IsEmpty()) 819 if (pValue.IsEmpty())
854 return v8::Local<v8::Object>(); 820 return v8::Local<v8::Object>();
855 v8::Local<v8::Context> context = pJSRuntime->GetCurrentContext(); 821 v8::Local<v8::Context> context = pIsolate->GetCurrentContext();
856 return pValue->ToObject(context).ToLocalChecked(); 822 return pValue->ToObject(context).ToLocalChecked();
857 } 823 }
858 824
859 CFX_WideString JS_ToString(IJS_Runtime* pJSRuntime, 825 CFX_WideString JS_ToString(v8::Isolate* pIsolate, v8::Local<v8::Value> pValue) {
860 v8::Local<v8::Value> pValue) {
861 if (pValue.IsEmpty()) 826 if (pValue.IsEmpty())
862 return L""; 827 return L"";
863 v8::Local<v8::Context> context = pJSRuntime->GetCurrentContext(); 828 v8::Local<v8::Context> context = pIsolate->GetCurrentContext();
864 v8::String::Utf8Value s(pValue->ToString(context).ToLocalChecked()); 829 v8::String::Utf8Value s(pValue->ToString(context).ToLocalChecked());
865 return CFX_WideString::FromUTF8(*s, s.length()); 830 return CFX_WideString::FromUTF8(*s, s.length());
866 } 831 }
867 832
868 v8::Local<v8::Array> JS_ToArray(IJS_Runtime* pJSRuntime, 833 v8::Local<v8::Array> JS_ToArray(v8::Isolate* pIsolate,
869 v8::Local<v8::Value> pValue) { 834 v8::Local<v8::Value> pValue) {
870 if (pValue.IsEmpty()) 835 if (pValue.IsEmpty())
871 return v8::Local<v8::Array>(); 836 return v8::Local<v8::Array>();
872 v8::Local<v8::Context> context = pJSRuntime->GetCurrentContext(); 837 v8::Local<v8::Context> context = pIsolate->GetCurrentContext();
873 return v8::Local<v8::Array>::Cast(pValue->ToObject(context).ToLocalChecked()); 838 return v8::Local<v8::Array>::Cast(pValue->ToObject(context).ToLocalChecked());
874 } 839 }
875 840
876 void JS_ValueCopy(v8::Local<v8::Value>& pTo, v8::Local<v8::Value> pFrom) { 841 void JS_ValueCopy(v8::Local<v8::Value>& pTo, v8::Local<v8::Value> pFrom) {
877 pTo = pFrom; 842 pTo = pFrom;
878 } 843 }
879 844
880 // JavaScript time implement begin. 845 // JavaScript time implement begin.
881 846
882 double _getLocalTZA() { 847 double _getLocalTZA() {
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
1154 1119
1155 bool JS_PortIsNan(double d) { 1120 bool JS_PortIsNan(double d) {
1156 return d != d; 1121 return d != d;
1157 } 1122 }
1158 1123
1159 double JS_LocalTime(double d) { 1124 double JS_LocalTime(double d) {
1160 return JS_GetDateTime() + _getDaylightSavingTA(d); 1125 return JS_GetDateTime() + _getDaylightSavingTA(d);
1161 } 1126 }
1162 1127
1163 // JavaScript time implement End. 1128 // 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