OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "../../../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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 | 98 |
99 CFX_WideString ws = CFX_WideString(sMethodName); | 99 CFX_WideString ws = CFX_WideString(sMethodName); |
100 CFX_ByteString bsMethodName = ws.UTF8Encode(); | 100 CFX_ByteString bsMethodName = ws.UTF8Encode(); |
101 | 101 |
102 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(0); | 102 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(0); |
103 if(!pArray) return 0; | 103 if(!pArray) return 0; |
104 | 104 |
105 if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return 0; | 105 if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return 0; |
106 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID)
; | 106 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID)
; |
107 v8::Local<v8::ObjectTemplate> objTemp = v8::Local<v8::ObjectTemplate>::N
ew(isolate, pObjDef->m_objTemplate); | 107 v8::Local<v8::ObjectTemplate> objTemp = v8::Local<v8::ObjectTemplate>::N
ew(isolate, pObjDef->m_objTemplate); |
108 » objTemp->Set(v8::String::NewFromUtf8(isolate, FX_LPCSTR(bsMethodName)),
v8::FunctionTemplate::New(isolate, pMethodCall), v8::ReadOnly); | 108 » objTemp->Set(v8::String::NewFromUtf8(isolate, FX_LPCSTR(bsMethodName), v
8::NewStringType::kNormal).ToLocalChecked(), v8::FunctionTemplate::New(isolate,
pMethodCall), v8::ReadOnly); |
109 pObjDef->m_objTemplate.Reset(isolate,objTemp); | 109 pObjDef->m_objTemplate.Reset(isolate,objTemp); |
110 return 0; | 110 return 0; |
111 } | 111 } |
112 | 112 |
113 int JS_DefineObjProperty(IJS_Runtime* pJSRuntime, int nObjDefnID, const wchar_t*
sPropName, v8::AccessorGetterCallback pPropGet, v8::AccessorSetterCallback pPro
pPut) | 113 int JS_DefineObjProperty(IJS_Runtime* pJSRuntime, int nObjDefnID, const wchar_t*
sPropName, v8::AccessorGetterCallback pPropGet, v8::AccessorSetterCallback pPro
pPut) |
114 { | 114 { |
115 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; | 115 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; |
116 v8::Isolate::Scope isolate_scope(isolate); | 116 v8::Isolate::Scope isolate_scope(isolate); |
117 v8::HandleScope handle_scope(isolate); | 117 v8::HandleScope handle_scope(isolate); |
118 | 118 |
119 CFX_WideString ws = CFX_WideString(sPropName); | 119 CFX_WideString ws = CFX_WideString(sPropName); |
120 CFX_ByteString bsPropertyName = ws.UTF8Encode(); | 120 CFX_ByteString bsPropertyName = ws.UTF8Encode(); |
121 | 121 |
122 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(0); | 122 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(0); |
123 if(!pArray) return 0; | 123 if(!pArray) return 0; |
124 | 124 |
125 if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return 0; | 125 if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return 0; |
126 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID)
; | 126 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID)
; |
127 v8::Local<v8::ObjectTemplate> objTemp = v8::Local<v8::ObjectTemplate>::N
ew(isolate, pObjDef->m_objTemplate); | 127 v8::Local<v8::ObjectTemplate> objTemp = v8::Local<v8::ObjectTemplate>::N
ew(isolate, pObjDef->m_objTemplate); |
128 » objTemp->SetAccessor(v8::String::NewFromUtf8(isolate, FX_LPCSTR(bsProper
tyName)), pPropGet, pPropPut); | 128 » objTemp->SetAccessor(v8::String::NewFromUtf8(isolate, FX_LPCSTR(bsProper
tyName), v8::NewStringType::kNormal).ToLocalChecked(), pPropGet, pPropPut); |
129 pObjDef->m_objTemplate.Reset(isolate,objTemp); | 129 pObjDef->m_objTemplate.Reset(isolate,objTemp); |
130 return 0; | 130 return 0; |
131 } | 131 } |
132 | 132 |
133 int JS_DefineObjAllProperties(IJS_Runtime* pJSRuntime, int nObjDefnID, v8::N
amedPropertyQueryCallback pPropQurey, v8::NamedPropertyGetterCallback pPropGet,
v8::NamedPropertySetterCallback pPropPut, v8::NamedPropertyDeleterCallback pProp
Del) | 133 int JS_DefineObjAllProperties(IJS_Runtime* pJSRuntime, int nObjDefnID, v8::N
amedPropertyQueryCallback pPropQurey, v8::NamedPropertyGetterCallback pPropGet,
v8::NamedPropertySetterCallback pPropPut, v8::NamedPropertyDeleterCallback pProp
Del) |
134 { | 134 { |
135 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; | 135 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; |
136 v8::Isolate::Scope isolate_scope(isolate); | 136 v8::Isolate::Scope isolate_scope(isolate); |
137 v8::HandleScope handle_scope(isolate); | 137 v8::HandleScope handle_scope(isolate); |
138 | 138 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 CFX_ByteString bsMethodName = ws.UTF8Encode(); | 195 CFX_ByteString bsMethodName = ws.UTF8Encode(); |
196 | 196 |
197 v8::Local<v8::FunctionTemplate> funTempl = v8::FunctionTemplate::New(iso
late, pMethodCall); | 197 v8::Local<v8::FunctionTemplate> funTempl = v8::FunctionTemplate::New(iso
late, pMethodCall); |
198 v8::Local<v8::ObjectTemplate> objTemp; | 198 v8::Local<v8::ObjectTemplate> objTemp; |
199 | 199 |
200 v8::Persistent<v8::ObjectTemplate>& globalObjTemp = _getGlobalObjectTemp
late(pJSRuntime); | 200 v8::Persistent<v8::ObjectTemplate>& globalObjTemp = _getGlobalObjectTemp
late(pJSRuntime); |
201 if(globalObjTemp.IsEmpty()) | 201 if(globalObjTemp.IsEmpty()) |
202 objTemp = v8::ObjectTemplate::New(isolate); | 202 objTemp = v8::ObjectTemplate::New(isolate); |
203 else | 203 else |
204 objTemp = v8::Local<v8::ObjectTemplate>::New(isolate, globalObjT
emp); | 204 objTemp = v8::Local<v8::ObjectTemplate>::New(isolate, globalObjT
emp); |
205 » objTemp->Set(v8::String::NewFromUtf8(isolate, FX_LPCSTR(bsMethodName)),
funTempl, v8::ReadOnly); | 205 » objTemp->Set(v8::String::NewFromUtf8(isolate, FX_LPCSTR(bsMethodName), v
8::NewStringType::kNormal).ToLocalChecked(), funTempl, v8::ReadOnly); |
206 | 206 |
207 globalObjTemp.Reset(isolate,objTemp); | 207 globalObjTemp.Reset(isolate,objTemp); |
208 | 208 |
209 return 0; | 209 return 0; |
210 } | 210 } |
211 | 211 |
212 int JS_DefineGlobalConst(IJS_Runtime* pJSRuntime, const wchar_t* sConstName, v8:
:Handle<v8::Value> pDefault) | 212 int JS_DefineGlobalConst(IJS_Runtime* pJSRuntime, const wchar_t* sConstName, v8:
:Handle<v8::Value> pDefault) |
213 { | 213 { |
214 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; | 214 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; |
215 v8::Isolate::Scope isolate_scope(isolate); | 215 v8::Isolate::Scope isolate_scope(isolate); |
216 v8::HandleScope handle_scope(isolate); | 216 v8::HandleScope handle_scope(isolate); |
217 | 217 |
218 CFX_WideString ws = CFX_WideString(sConstName); | 218 CFX_WideString ws = CFX_WideString(sConstName); |
219 CFX_ByteString bsConst= ws.UTF8Encode(); | 219 CFX_ByteString bsConst= ws.UTF8Encode(); |
220 | 220 |
221 v8::Local<v8::ObjectTemplate> objTemp; | 221 v8::Local<v8::ObjectTemplate> objTemp; |
222 | 222 |
223 v8::Persistent<v8::ObjectTemplate>& globalObjTemp = _getGlobalObjectTemp
late(pJSRuntime); | 223 v8::Persistent<v8::ObjectTemplate>& globalObjTemp = _getGlobalObjectTemp
late(pJSRuntime); |
224 if(globalObjTemp.IsEmpty()) | 224 if(globalObjTemp.IsEmpty()) |
225 objTemp = v8::ObjectTemplate::New(isolate); | 225 objTemp = v8::ObjectTemplate::New(isolate); |
226 else | 226 else |
227 objTemp = v8::Local<v8::ObjectTemplate>::New(isolate, globalObjT
emp); | 227 objTemp = v8::Local<v8::ObjectTemplate>::New(isolate, globalObjT
emp); |
228 » objTemp->Set(v8::String::NewFromUtf8(isolate, FX_LPCSTR(bsConst)), pDefa
ult, v8::ReadOnly); | 228 » objTemp->Set(v8::String::NewFromUtf8(isolate, FX_LPCSTR(bsConst), v8::Ne
wStringType::kNormal).ToLocalChecked(), pDefault, v8::ReadOnly); |
229 | 229 |
230 globalObjTemp.Reset(isolate,objTemp); | 230 globalObjTemp.Reset(isolate,objTemp); |
231 | 231 |
232 return 0; | 232 return 0; |
233 } | 233 } |
234 | 234 |
235 | 235 |
236 void JS_InitialRuntime(IJS_Runtime* pJSRuntime,IFXJS_Runtime* pFXRuntime, IFXJS_
Context* context, v8::Persistent<v8::Context>& v8PersistentContext) | 236 void JS_InitialRuntime(IJS_Runtime* pJSRuntime,IFXJS_Runtime* pFXRuntime, IFXJS_
Context* context, v8::Persistent<v8::Context>& v8PersistentContext) |
237 { | 237 { |
238 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; | 238 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; |
239 v8::Isolate::Scope isolate_scope(isolate); | 239 v8::Isolate::Scope isolate_scope(isolate); |
240 v8::HandleScope handle_scope(isolate); | 240 v8::HandleScope handle_scope(isolate); |
241 | 241 |
242 v8::Persistent<v8::ObjectTemplate>& globalObjTemp = _getGlobalObjectTemp
late(pJSRuntime); | 242 v8::Persistent<v8::ObjectTemplate>& globalObjTemp = _getGlobalObjectTemp
late(pJSRuntime); |
243 v8::Handle<v8::Context> v8Context = v8::Context::New(isolate, NULL, v8::
Local<v8::ObjectTemplate>::New(isolate, globalObjTemp)); | 243 v8::Handle<v8::Context> v8Context = v8::Context::New(isolate, NULL, v8::
Local<v8::ObjectTemplate>::New(isolate, globalObjTemp)); |
244 v8::Context::Scope context_scope(v8Context); | 244 v8::Context::Scope context_scope(v8Context); |
245 | 245 |
246 v8::Handle<v8::External> ptr = v8::External::New(isolate, pFXRuntime); | 246 v8::Handle<v8::External> ptr = v8::External::New(isolate, pFXRuntime); |
247 v8Context->SetEmbedderData(1, ptr); | 247 v8Context->SetEmbedderData(1, ptr); |
248 | 248 |
249 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(0); | 249 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(0); |
250 if(!pArray) return; | 250 if(!pArray) return; |
251 | 251 |
252 for(int i=0; i<pArray->GetSize(); i++) | 252 for(int i=0; i<pArray->GetSize(); i++) |
253 { | 253 { |
254 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(i); | 254 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(i); |
255 CFX_WideString ws = CFX_WideString(pObjDef->objName); | 255 CFX_WideString ws = CFX_WideString(pObjDef->objName); |
256 CFX_ByteString bs = ws.UTF8Encode(); | 256 CFX_ByteString bs = ws.UTF8Encode(); |
257 » » v8::Handle<v8::String> objName = v8::String::NewFromUtf8(isolate
, bs.c_str(), v8::String::kNormalString, bs.GetLength()); | 257 » » v8::Handle<v8::String> objName = v8::String::NewFromUtf8(isolate
, bs.c_str(), v8::NewStringType::kNormal, bs.GetLength()).ToLocalChecked(); |
258 | 258 |
259 | 259 |
260 if(pObjDef->objType == JS_DYNAMIC) | 260 if(pObjDef->objType == JS_DYNAMIC) |
261 { | 261 { |
262 //Document is set as global object, need to construct it
first. | 262 //Document is set as global object, need to construct it
first. |
263 if(ws.Equal(L"Document")) | 263 if(ws.Equal(L"Document")) |
264 { | 264 { |
265 | 265 |
266 CJS_PrivateData* pPrivateData = new CJS_PrivateD
ata; | 266 CJS_PrivateData* pPrivateData = new CJS_PrivateD
ata; |
267 pPrivateData->ObjDefID = i; | 267 pPrivateData->ObjDefID = i; |
268 | 268 |
269 » » » » v8Context->Global()->GetPrototype()->ToObject()-
>SetAlignedPointerInInternalField(0, pPrivateData); | 269 » » » » v8Context->Global()->GetPrototype()->ToObject(v8
Context).ToLocalChecked()->SetAlignedPointerInInternalField(0, pPrivateData); |
270 | 270 |
271 if(pObjDef->m_pConstructor) | 271 if(pObjDef->m_pConstructor) |
272 » » » » » pObjDef->m_pConstructor(context, v8Conte
xt->Global()->GetPrototype()->ToObject(), v8Context->Global()->GetPrototype()->T
oObject()); | 272 » » » » » pObjDef->m_pConstructor(context, v8Conte
xt->Global()->GetPrototype()->ToObject(v8Context).ToLocalChecked(), v8Context->G
lobal()->GetPrototype()->ToObject(v8Context).ToLocalChecked()); |
273 } | 273 } |
274 } | 274 } |
275 else | 275 else |
276 { | 276 { |
277 v8::Handle<v8::Object> obj = JS_NewFxDynamicObj(pJSRunti
me, context, i); | 277 v8::Handle<v8::Object> obj = JS_NewFxDynamicObj(pJSRunti
me, context, i); |
278 » » » v8Context->Global()->Set(objName, obj); | 278 » » » v8Context->Global()->Set(v8Context, objName, obj).FromJu
st(); |
279 pObjDef->m_StaticObj.Reset(isolate, obj); | 279 pObjDef->m_StaticObj.Reset(isolate, obj); |
280 } | 280 } |
281 } | 281 } |
282 v8PersistentContext.Reset(isolate, v8Context); | 282 v8PersistentContext.Reset(isolate, v8Context); |
283 } | 283 } |
284 | 284 |
285 void JS_ReleaseRuntime(IJS_Runtime* pJSRuntime, v8::Persistent<v8::Context>& v8P
ersistentContext) | 285 void JS_ReleaseRuntime(IJS_Runtime* pJSRuntime, v8::Persistent<v8::Context>& v8P
ersistentContext) |
286 { | 286 { |
287 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; | 287 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; |
288 v8::Isolate::Scope isolate_scope(isolate); | 288 v8::Isolate::Scope isolate_scope(isolate); |
(...skipping 24 matching lines...) Expand all Loading... |
313 { | 313 { |
314 } | 314 } |
315 void JS_Release() | 315 void JS_Release() |
316 { | 316 { |
317 | 317 |
318 } | 318 } |
319 int JS_Parse(IJS_Runtime* pJSRuntime, IFXJS_Context* pJSContext, const wchar_t*
script, long length, FXJSErr* perror) | 319 int JS_Parse(IJS_Runtime* pJSRuntime, IFXJS_Context* pJSContext, const wchar_t*
script, long length, FXJSErr* perror) |
320 { | 320 { |
321 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; | 321 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; |
322 v8::Isolate::Scope isolate_scope(isolate); | 322 v8::Isolate::Scope isolate_scope(isolate); |
323 » v8::TryCatch try_catch; | 323 » v8::TryCatch try_catch(isolate); |
324 | 324 |
325 CFX_WideString wsScript(script); | 325 CFX_WideString wsScript(script); |
326 CFX_ByteString bsScript = wsScript.UTF8Encode(); | 326 CFX_ByteString bsScript = wsScript.UTF8Encode(); |
327 | 327 |
328 | 328 |
329 » v8::Handle<v8::Script> compiled_script = v8::Script::Compile(v8::String:
:NewFromUtf8(isolate, bsScript.c_str(), v8::String::kNormalString, bsScript.GetL
ength())); | 329 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
330 » if (compiled_script.IsEmpty()) { | 330 » v8::Local<v8::Script> compiled_script; |
| 331 if (!v8::Script::Compile(context, v8::String::NewFromUtf8(isolate, bsScr
ipt.c_str(), v8::NewStringType::kNormal, bsScript.GetLength()).ToLocalChecked())
.ToLocal(&compiled_script)) { |
331 v8::String::Utf8Value error(try_catch.Exception()); | 332 v8::String::Utf8Value error(try_catch.Exception()); |
332 return -1; | 333 return -1; |
333 } | 334 } |
334 return 0; | 335 return 0; |
335 } | 336 } |
336 | 337 |
337 int JS_Execute(IJS_Runtime* pJSRuntime, IFXJS_Context* pJSContext, const wchar_t
* script, long length, FXJSErr* perror) | 338 int JS_Execute(IJS_Runtime* pJSRuntime, IFXJS_Context* pJSContext, const wchar_t
* script, long length, FXJSErr* perror) |
338 { | 339 { |
339 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; | 340 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; |
340 v8::Isolate::Scope isolate_scope(isolate); | 341 v8::Isolate::Scope isolate_scope(isolate); |
341 » v8::TryCatch try_catch; | 342 » v8::TryCatch try_catch(isolate); |
342 | 343 |
343 CFX_WideString wsScript(script); | 344 CFX_WideString wsScript(script); |
344 CFX_ByteString bsScript = wsScript.UTF8Encode(); | 345 CFX_ByteString bsScript = wsScript.UTF8Encode(); |
345 | 346 |
346 v8::Handle<v8::Script> compiled_script = v8::Script::Compile(v8::String::New
FromUtf8(isolate, bsScript.c_str(), v8::String::kNormalString, bsScript.GetLengt
h())); | 347 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
347 » if (compiled_script.IsEmpty()) { | 348 v8::Local<v8::Script> compiled_script; |
| 349 if (!v8::Script::Compile(context, v8::String::NewFromUtf8(isolate, bsScr
ipt.c_str(), v8::NewStringType::kNormal, bsScript.GetLength()).ToLocalChecked())
.ToLocal(&compiled_script)) { |
348 v8::String::Utf8Value error(try_catch.Exception()); | 350 v8::String::Utf8Value error(try_catch.Exception()); |
349 return -1; | 351 return -1; |
350 } | 352 } |
351 | 353 |
352 » v8::Handle<v8::Value> result = compiled_script->Run(); | 354 » v8::Handle<v8::Value> result; |
353 » if (result.IsEmpty()) { | 355 if (!compiled_script->Run(context).ToLocal(&result)) { |
354 v8::String::Utf8Value error(try_catch.Exception()); | 356 v8::String::Utf8Value error(try_catch.Exception()); |
355 return -1; | 357 return -1; |
356 } | 358 } |
357 return 0; | 359 return 0; |
358 } | 360 } |
359 | 361 |
360 v8::Handle<v8::Object> JS_NewFxDynamicObj(IJS_Runtime* pJSRuntime, IFXJS_Context
* pJSContext, int nObjDefnID) | 362 v8::Handle<v8::Object> JS_NewFxDynamicObj(IJS_Runtime* pJSRuntime, IFXJS_Context
* pJSContext, int nObjDefnID) |
361 { | 363 { |
362 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; | 364 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; |
363 v8::Isolate::Scope isolate_scope(isolate); | 365 v8::Isolate::Scope isolate_scope(isolate); |
| 366 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
364 if(-1 == nObjDefnID) | 367 if(-1 == nObjDefnID) |
365 { | 368 { |
366 v8::Local<v8::ObjectTemplate> objTempl = v8::ObjectTemplate::New
(isolate); | 369 v8::Local<v8::ObjectTemplate> objTempl = v8::ObjectTemplate::New
(isolate); |
367 » » return objTempl->NewInstance(); | 370 v8::Local<v8::Object> obj; |
| 371 if (objTempl->NewInstance(context).ToLocal(&obj)) return obj; |
| 372 return v8::Handle<v8::Object>(); |
368 } | 373 } |
369 | 374 |
370 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(0); | 375 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(0); |
371 if(!pArray) return v8::Handle<v8::Object>(); | 376 if(!pArray) return v8::Handle<v8::Object>(); |
372 | 377 |
373 | 378 |
374 if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return v8::Handle<v8:
:Object>(); | 379 if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return v8::Handle<v8:
:Object>(); |
375 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID)
; | 380 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID)
; |
376 | 381 |
377 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | |
378 v8::Local<v8::ObjectTemplate> objTemp = v8::Local<v8::ObjectTemplate>::N
ew(isolate, pObjDef->m_objTemplate); | 382 v8::Local<v8::ObjectTemplate> objTemp = v8::Local<v8::ObjectTemplate>::N
ew(isolate, pObjDef->m_objTemplate); |
379 » v8::Local<v8::Object> obj = objTemp->NewInstance(); | 383 » v8::Local<v8::Object> obj; |
| 384 if (!objTemp->NewInstance(context).ToLocal(&obj)) return v8::Local<v8::O
bject>(); |
380 | 385 |
381 CJS_PrivateData* pPrivateData = new CJS_PrivateData; | 386 CJS_PrivateData* pPrivateData = new CJS_PrivateData; |
382 pPrivateData->ObjDefID = nObjDefnID; | 387 pPrivateData->ObjDefID = nObjDefnID; |
383 | 388 |
384 obj->SetAlignedPointerInInternalField(0, pPrivateData); | 389 obj->SetAlignedPointerInInternalField(0, pPrivateData); |
385 if(pObjDef->m_pConstructor) | 390 if(pObjDef->m_pConstructor) |
386 » » pObjDef->m_pConstructor(pJSContext, obj, context->Global()->GetP
rototype()->ToObject()); | 391 » » pObjDef->m_pConstructor(pJSContext, obj, context->Global()->GetP
rototype()->ToObject(context).ToLocalChecked()); |
387 | 392 |
388 return obj; | 393 return obj; |
389 } | 394 } |
390 | 395 |
391 v8::Handle<v8::Object> JS_GetStaticObj(IJS_Runtime* pJSRuntime, int nObjDefnID) | 396 v8::Handle<v8::Object> JS_GetStaticObj(IJS_Runtime* pJSRuntime, int nObjDefnID) |
392 { | 397 { |
393 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; | 398 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; |
394 v8::Isolate::Scope isolate_scope(isolate); | 399 v8::Isolate::Scope isolate_scope(isolate); |
395 | 400 |
396 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(0); | 401 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(0); |
(...skipping 12 matching lines...) Expand all Loading... |
409 v8::Handle<v8::Object> JS_GetThisObj(IJS_Runtime * pJSRuntime) | 414 v8::Handle<v8::Object> JS_GetThisObj(IJS_Runtime * pJSRuntime) |
410 { | 415 { |
411 //Return the global object. | 416 //Return the global object. |
412 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; | 417 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; |
413 v8::Isolate::Scope isolate_scope(isolate); | 418 v8::Isolate::Scope isolate_scope(isolate); |
414 | 419 |
415 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(0); | 420 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(0); |
416 if(!pArray) return v8::Handle<v8::Object>(); | 421 if(!pArray) return v8::Handle<v8::Object>(); |
417 | 422 |
418 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 423 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
419 » return context->Global()->GetPrototype()->ToObject(); | 424 » return context->Global()->GetPrototype()->ToObject(context).ToLocalCheck
ed(); |
420 } | 425 } |
421 | 426 |
422 int JS_GetObjDefnID(v8::Handle<v8::Object> pObj) | 427 int JS_GetObjDefnID(v8::Handle<v8::Object> pObj) |
423 { | 428 { |
424 if(pObj.IsEmpty() || !pObj->InternalFieldCount()) return -1; | 429 if(pObj.IsEmpty() || !pObj->InternalFieldCount()) return -1; |
425 CJS_PrivateData* pPrivateData = (CJS_PrivateData*)pObj->GetAlignedPointe
rFromInternalField(0); | 430 CJS_PrivateData* pPrivateData = (CJS_PrivateData*)pObj->GetAlignedPointe
rFromInternalField(0); |
426 if(pPrivateData) | 431 if(pPrivateData) |
427 return pPrivateData->ObjDefID; | 432 return pPrivateData->ObjDefID; |
428 return -1; | 433 return -1; |
429 } | 434 } |
(...skipping 23 matching lines...) Expand all Loading... |
453 return -1; | 458 return -1; |
454 } | 459 } |
455 | 460 |
456 void JS_Error(v8::Isolate* isolate, const CFX_WideString& message) | 461 void JS_Error(v8::Isolate* isolate, const CFX_WideString& message) |
457 { | 462 { |
458 // Conversion from pdfium's wchar_t wide-strings to v8's uint16_t | 463 // Conversion from pdfium's wchar_t wide-strings to v8's uint16_t |
459 // wide-strings isn't handled by v8, so use UTF8 as a common | 464 // wide-strings isn't handled by v8, so use UTF8 as a common |
460 // intermediate format. | 465 // intermediate format. |
461 CFX_ByteString utf8_message = message.UTF8Encode(); | 466 CFX_ByteString utf8_message = message.UTF8Encode(); |
462 isolate->ThrowException(v8::String::NewFromUtf8(isolate, | 467 isolate->ThrowException(v8::String::NewFromUtf8(isolate, |
463 utf8_message.c_str())); | 468 utf8_message.c_str(), |
| 469 v8::NewStringType::kNormal).
ToLocalChecked()); |
464 } | 470 } |
465 | 471 |
466 unsigned JS_CalcHash(const wchar_t* main, unsigned nLen) | 472 unsigned JS_CalcHash(const wchar_t* main, unsigned nLen) |
467 { | 473 { |
468 return (unsigned)FX_HashCode_String_GetW(main, nLen); | 474 return (unsigned)FX_HashCode_String_GetW(main, nLen); |
469 } | 475 } |
470 | 476 |
471 unsigned JS_CalcHash(const wchar_t* main) | 477 unsigned JS_CalcHash(const wchar_t* main) |
472 { | 478 { |
473 return (unsigned)FX_HashCode_String_GetW(main, FXSYS_wcslen(main)); | 479 return (unsigned)FX_HashCode_String_GetW(main, FXSYS_wcslen(main)); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 void* JS_GetPrivate(IJS_Runtime* pJSRuntime, v8::Handle<v8::Object> pObj) | 519 void* JS_GetPrivate(IJS_Runtime* pJSRuntime, v8::Handle<v8::Object> pObj) |
514 { | 520 { |
515 if(pObj.IsEmpty()) return NULL; | 521 if(pObj.IsEmpty()) return NULL; |
516 CJS_PrivateData* pPrivateData = NULL; | 522 CJS_PrivateData* pPrivateData = NULL; |
517 if(pObj->InternalFieldCount()) | 523 if(pObj->InternalFieldCount()) |
518 pPrivateData = (CJS_PrivateData*)pObj->GetAlignedPointerFromInte
rnalField(0); | 524 pPrivateData = (CJS_PrivateData*)pObj->GetAlignedPointerFromInte
rnalField(0); |
519 else | 525 else |
520 { | 526 { |
521 //It could be a global proxy object. | 527 //It could be a global proxy object. |
522 v8::Local<v8::Value> v = pObj->GetPrototype(); | 528 v8::Local<v8::Value> v = pObj->GetPrototype(); |
| 529 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; |
| 530 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
523 if(v->IsObject()) | 531 if(v->IsObject()) |
524 pPrivateData = (CJS_PrivateData*)v->ToObject()->GetAlign
edPointerFromInternalField(0); | 532 pPrivateData = (CJS_PrivateData*)v->ToObject(context).To
LocalChecked()->GetAlignedPointerFromInternalField(0); |
525 } | 533 } |
526 if(!pPrivateData) return NULL; | 534 if(!pPrivateData) return NULL; |
527 return pPrivateData->pPrivate; | 535 return pPrivateData->pPrivate; |
528 } | 536 } |
529 | 537 |
530 void JS_FreePrivate(void* pPrivateData) | 538 void JS_FreePrivate(void* pPrivateData) |
531 { | 539 { |
532 delete (CJS_PrivateData*)pPrivateData; | 540 delete (CJS_PrivateData*)pPrivateData; |
533 } | 541 } |
534 | 542 |
535 void JS_FreePrivate(v8::Handle<v8::Object> pObj) | 543 void JS_FreePrivate(v8::Handle<v8::Object> pObj) |
536 { | 544 { |
537 if(pObj.IsEmpty() || !pObj->InternalFieldCount()) return; | 545 if(pObj.IsEmpty() || !pObj->InternalFieldCount()) return; |
538 JS_FreePrivate(pObj->GetAlignedPointerFromInternalField(0)); | 546 JS_FreePrivate(pObj->GetAlignedPointerFromInternalField(0)); |
539 pObj->SetAlignedPointerInInternalField(0, NULL); | 547 pObj->SetAlignedPointerInInternalField(0, NULL); |
540 } | 548 } |
541 | 549 |
542 | 550 |
543 v8::Handle<v8::Value> JS_GetObjectValue(v8::Handle<v8::Object> pObj) | 551 v8::Handle<v8::Value> JS_GetObjectValue(v8::Handle<v8::Object> pObj) |
544 { | 552 { |
545 return pObj; | 553 return pObj; |
546 } | 554 } |
547 | 555 |
548 v8::Handle<v8::String> WSToJSString(IJS_Runtime* pJSRuntime, const wchar_t* Prop
ertyName, int Len = -1) | 556 v8::Handle<v8::String> WSToJSString(IJS_Runtime* pJSRuntime, const wchar_t* Prop
ertyName, int Len = -1) |
549 { | 557 { |
550 CFX_WideString ws = CFX_WideString(PropertyName,Len); | 558 CFX_WideString ws = CFX_WideString(PropertyName,Len); |
551 CFX_ByteString bs = ws.UTF8Encode(); | 559 CFX_ByteString bs = ws.UTF8Encode(); |
552 if(!pJSRuntime) pJSRuntime = v8::Isolate::GetCurrent(); | 560 if(!pJSRuntime) pJSRuntime = v8::Isolate::GetCurrent(); |
553 » return v8::String::NewFromUtf8(pJSRuntime, bs.c_str()); | 561 » return v8::String::NewFromUtf8(pJSRuntime, bs.c_str(), v8::NewStringType
::kNormal).ToLocalChecked(); |
554 } | 562 } |
555 | 563 |
556 v8::Handle<v8::Value> JS_GetObjectElement(IJS_Runtime* pJSRuntime, v8::Handle<v8
::Object> pObj,const wchar_t* PropertyName) | 564 v8::Handle<v8::Value> JS_GetObjectElement(IJS_Runtime* pJSRuntime, v8::Handle<v8
::Object> pObj,const wchar_t* PropertyName) |
557 { | 565 { |
558 if(pObj.IsEmpty()) return v8::Handle<v8::Value>(); | 566 if(pObj.IsEmpty()) return v8::Handle<v8::Value>(); |
559 » return pObj->Get(WSToJSString(pJSRuntime,PropertyName)); | 567 v8::Local<v8::Value> val; |
| 568 » if (!pObj->Get(pJSRuntime->GetCurrentContext(), WSToJSString(pJSRuntime,
PropertyName)).ToLocal(&val)) return v8::Handle<v8::Value>(); |
| 569 return val; |
560 } | 570 } |
561 | 571 |
562 v8::Handle<v8::Array> JS_GetObjectElementNames(v8::Handle<v8::Object> pObj) | 572 v8::Handle<v8::Array> JS_GetObjectElementNames(IJS_Runtime* pJSRuntime, v8::Hand
le<v8::Object> pObj) |
563 { | 573 { |
564 if(pObj.IsEmpty()) return v8::Handle<v8::Array>(); | 574 if(pObj.IsEmpty()) return v8::Handle<v8::Array>(); |
565 » return pObj->GetPropertyNames(); | 575 v8::Local<v8::Array> val; |
| 576 » if (!pObj->GetPropertyNames(pJSRuntime->GetCurrentContext()).ToLocal(&va
l)) return v8::Local<v8::Array>(); |
| 577 return val; |
566 } | 578 } |
567 | 579 |
568 void JS_PutObjectString(IJS_Runtime* pJSRuntime,v8::Handle<v8::Object> pObj, con
st wchar_t* PropertyName, const wchar_t* sValue) //VT_string | 580 void JS_PutObjectString(IJS_Runtime* pJSRuntime,v8::Handle<v8::Object> pObj, con
st wchar_t* PropertyName, const wchar_t* sValue) //VT_string |
569 { | 581 { |
570 if(pObj.IsEmpty()) return; | 582 if(pObj.IsEmpty()) return; |
571 » pObj->Set(WSToJSString(pJSRuntime, PropertyName), WSToJSString(pJSRuntim
e, sValue)); | 583 » pObj->Set(pJSRuntime->GetCurrentContext(), WSToJSString(pJSRuntime, Prop
ertyName), WSToJSString(pJSRuntime, sValue)).FromJust(); |
572 } | 584 } |
573 | 585 |
574 void JS_PutObjectNumber(IJS_Runtime* pJSRuntime,v8::Handle<v8::Object> pObj, con
st wchar_t* PropertyName, int nValue) | 586 void JS_PutObjectNumber(IJS_Runtime* pJSRuntime,v8::Handle<v8::Object> pObj, con
st wchar_t* PropertyName, int nValue) |
575 { | 587 { |
576 if(pObj.IsEmpty()) return; | 588 if(pObj.IsEmpty()) return; |
577 » pObj->Set(WSToJSString(pJSRuntime,PropertyName),v8::Int32::New(pJSRuntim
e, nValue)); | 589 » pObj->Set(pJSRuntime->GetCurrentContext(), WSToJSString(pJSRuntime,Prope
rtyName),v8::Int32::New(pJSRuntime, nValue)).FromJust(); |
578 } | 590 } |
579 | 591 |
580 void JS_PutObjectNumber(IJS_Runtime* pJSRuntime,v8::Handle<v8::Object> pObj, con
st wchar_t* PropertyName, float fValue) | 592 void JS_PutObjectNumber(IJS_Runtime* pJSRuntime,v8::Handle<v8::Object> pObj, con
st wchar_t* PropertyName, float fValue) |
581 { | 593 { |
582 if(pObj.IsEmpty()) return; | 594 if(pObj.IsEmpty()) return; |
583 » pObj->Set(WSToJSString(pJSRuntime,PropertyName),v8::Number::New(pJSRunti
me, (double)fValue)); | 595 » pObj->Set(pJSRuntime->GetCurrentContext(), WSToJSString(pJSRuntime,Prope
rtyName),v8::Number::New(pJSRuntime, (double)fValue)).FromJust(); |
584 } | 596 } |
585 | 597 |
586 void JS_PutObjectNumber(IJS_Runtime* pJSRuntime,v8::Handle<v8::Object> pObj, con
st wchar_t* PropertyName, double dValue) | 598 void JS_PutObjectNumber(IJS_Runtime* pJSRuntime,v8::Handle<v8::Object> pObj, con
st wchar_t* PropertyName, double dValue) |
587 { | 599 { |
588 if(pObj.IsEmpty()) return; | 600 if(pObj.IsEmpty()) return; |
589 » pObj->Set(WSToJSString(pJSRuntime,PropertyName),v8::Number::New(pJSRunti
me, (double)dValue)); | 601 » pObj->Set(pJSRuntime->GetCurrentContext(), WSToJSString(pJSRuntime,Prope
rtyName),v8::Number::New(pJSRuntime, (double)dValue)).FromJust(); |
590 } | 602 } |
591 | 603 |
592 void JS_PutObjectBoolean(IJS_Runtime* pJSRuntime,v8::Handle<v8::Object> pObj, co
nst wchar_t* PropertyName, bool bValue) | 604 void JS_PutObjectBoolean(IJS_Runtime* pJSRuntime,v8::Handle<v8::Object> pObj, co
nst wchar_t* PropertyName, bool bValue) |
593 { | 605 { |
594 if(pObj.IsEmpty()) return; | 606 if(pObj.IsEmpty()) return; |
595 » pObj->Set(WSToJSString(pJSRuntime,PropertyName),v8::Boolean::New(pJSRunt
ime, bValue)); | 607 » pObj->Set(pJSRuntime->GetCurrentContext(), WSToJSString(pJSRuntime,Prope
rtyName),v8::Boolean::New(pJSRuntime, bValue)).FromJust(); |
596 } | 608 } |
597 | 609 |
598 void JS_PutObjectObject(IJS_Runtime* pJSRuntime,v8::Handle<v8::Object> pObj, con
st wchar_t* PropertyName, v8::Handle<v8::Object> pPut) | 610 void JS_PutObjectObject(IJS_Runtime* pJSRuntime,v8::Handle<v8::Object> pObj, con
st wchar_t* PropertyName, v8::Handle<v8::Object> pPut) |
599 { | 611 { |
600 if(pObj.IsEmpty()) return; | 612 if(pObj.IsEmpty()) return; |
601 » pObj->Set(WSToJSString(pJSRuntime,PropertyName),pPut); | 613 » pObj->Set(pJSRuntime->GetCurrentContext(), WSToJSString(pJSRuntime,Prope
rtyName),pPut).FromJust(); |
602 } | 614 } |
603 | 615 |
604 void JS_PutObjectNull(IJS_Runtime* pJSRuntime,v8::Handle<v8::Object> pObj, const
wchar_t* PropertyName) | 616 void JS_PutObjectNull(IJS_Runtime* pJSRuntime,v8::Handle<v8::Object> pObj, const
wchar_t* PropertyName) |
605 { | 617 { |
606 if(pObj.IsEmpty()) return; | 618 if(pObj.IsEmpty()) return; |
607 » pObj->Set(WSToJSString(pJSRuntime,PropertyName),v8::Handle<v8::Object>()
); | 619 » pObj->Set(pJSRuntime->GetCurrentContext(), WSToJSString(pJSRuntime,Prope
rtyName),v8::Handle<v8::Object>()).FromJust(); |
608 } | 620 } |
609 | 621 |
610 v8::Handle<v8::Array> JS_NewArray(IJS_Runtime* pJSRuntime) | 622 v8::Handle<v8::Array> JS_NewArray(IJS_Runtime* pJSRuntime) |
611 { | 623 { |
612 return v8::Array::New(pJSRuntime); | 624 return v8::Array::New(pJSRuntime); |
613 } | 625 } |
614 | 626 |
615 unsigned JS_PutArrayElement(v8::Handle<v8::Array> pArray,unsigned index,v8::Hand
le<v8::Value> pValue,FXJSVALUETYPE eType) | 627 unsigned JS_PutArrayElement(IJS_Runtime* pJSRuntime, v8::Handle<v8::Array> pArra
y,unsigned index,v8::Handle<v8::Value> pValue,FXJSVALUETYPE eType) |
616 { | 628 { |
617 if(pArray.IsEmpty()) return 0; | 629 if(pArray.IsEmpty()) return 0; |
618 » pArray->Set(index, pValue); | 630 » if (pArray->Set(pJSRuntime->GetCurrentContext(), index, pValue).IsNothin
g()) return 0; |
619 return 1; | 631 return 1; |
620 } | 632 } |
621 | 633 |
622 v8::Handle<v8::Value> JS_GetArrayElemnet(v8::Handle<v8::Array> pArray,unsigned i
ndex) | 634 v8::Handle<v8::Value> JS_GetArrayElement(IJS_Runtime* pJSRuntime, v8::Handle<v8:
:Array> pArray,unsigned index) |
623 { | 635 { |
624 if(pArray.IsEmpty()) return v8::Handle<v8::Value>(); | 636 if(pArray.IsEmpty()) return v8::Handle<v8::Value>(); |
625 » return pArray->Get(index); | 637 v8::Local<v8::Value> val; |
| 638 » if (pArray->Get(pJSRuntime->GetCurrentContext(), index).ToLocal(&val)) r
eturn v8::Local<v8::Value>(); |
| 639 return val; |
626 } | 640 } |
627 | 641 |
628 unsigned JS_GetArrayLength(v8::Handle<v8::Array> pArray) | 642 unsigned JS_GetArrayLength(v8::Handle<v8::Array> pArray) |
629 { | 643 { |
630 if(pArray.IsEmpty()) return 0; | 644 if(pArray.IsEmpty()) return 0; |
631 return pArray->Length(); | 645 return pArray->Length(); |
632 } | 646 } |
633 | 647 |
634 v8::Handle<v8::Value> JS_NewNumber(IJS_Runtime* pJSRuntime,int number) | 648 v8::Handle<v8::Value> JS_NewNumber(IJS_Runtime* pJSRuntime,int number) |
635 { | 649 { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
674 return WSToJSString(pJSRuntime, string, nLen); | 688 return WSToJSString(pJSRuntime, string, nLen); |
675 } | 689 } |
676 | 690 |
677 v8::Handle<v8::Value> JS_NewNull() | 691 v8::Handle<v8::Value> JS_NewNull() |
678 { | 692 { |
679 return v8::Handle<v8::Value>(); | 693 return v8::Handle<v8::Value>(); |
680 } | 694 } |
681 | 695 |
682 v8::Handle<v8::Value> JS_NewDate(IJS_Runtime* pJSRuntime,double d) | 696 v8::Handle<v8::Value> JS_NewDate(IJS_Runtime* pJSRuntime,double d) |
683 { | 697 { |
684 » return v8::Date::New(pJSRuntime, d); | 698 » return v8::Date::New(pJSRuntime->GetCurrentContext(), d).ToLocalChecked(
); |
685 } | 699 } |
686 | 700 |
687 v8::Handle<v8::Value> JS_NewValue(IJS_Runtime* pJSRuntime) | 701 v8::Handle<v8::Value> JS_NewValue(IJS_Runtime* pJSRuntime) |
688 { | 702 { |
689 return v8::Handle<v8::Value>(); | 703 return v8::Handle<v8::Value>(); |
690 } | 704 } |
691 | 705 |
692 v8::Handle<v8::Value> JS_GetListValue(v8::Handle<v8::Value> pList, int index) | 706 v8::Handle<v8::Value> JS_GetListValue(IJS_Runtime* pJSRuntime, v8::Handle<v8::Va
lue> pList, int index) |
693 { | 707 { |
694 | 708 |
| 709 v8::Local<v8::Context> context = pJSRuntime->GetCurrentContext(); |
695 if(!pList.IsEmpty() && pList->IsObject()) | 710 if(!pList.IsEmpty() && pList->IsObject()) |
696 { | 711 { |
697 » » v8::Local<v8::Object> obj = pList->ToObject(); | 712 » » v8::Local<v8::Object> obj; |
698 » » return obj->Get(index); | 713 if (pList->ToObject(context).ToLocal(&obj)) |
| 714 { |
| 715 v8::Local<v8::Value> val; |
| 716 if (obj->Get(context, index).ToLocal(&val)) return val; |
| 717 } |
699 } | 718 } |
700 return v8::Handle<v8::Value>(); | 719 return v8::Handle<v8::Value>(); |
701 } | 720 } |
702 | 721 |
703 int» JS_ToInt32(v8::Handle<v8::Value> pValue) | 722 int» JS_ToInt32(IJS_Runtime* pJSRuntime, v8::Handle<v8::Value> pValue) |
704 { | 723 { |
705 if(pValue.IsEmpty()) return 0; | 724 if(pValue.IsEmpty()) return 0; |
706 » return pValue->ToInt32()->Value(); | 725 v8::Local<v8::Context> context = pJSRuntime->GetCurrentContext(); |
| 726 » return pValue->ToInt32(context).ToLocalChecked()->Value(); |
707 } | 727 } |
708 | 728 |
709 bool JS_ToBoolean(v8::Handle<v8::Value> pValue) | 729 bool JS_ToBoolean(IJS_Runtime* pJSRuntime, v8::Handle<v8::Value> pValue) |
710 { | 730 { |
711 if(pValue.IsEmpty()) return false; | 731 if(pValue.IsEmpty()) return false; |
712 » return pValue->ToBoolean()->Value(); | 732 v8::Local<v8::Context> context = pJSRuntime->GetCurrentContext(); |
| 733 » return pValue->ToBoolean(context).ToLocalChecked()->Value(); |
713 } | 734 } |
714 | 735 |
715 double JS_ToNumber(v8::Handle<v8::Value> pValue) | 736 double JS_ToNumber(IJS_Runtime* pJSRuntime, v8::Handle<v8::Value> pValue) |
716 { | 737 { |
717 if(pValue.IsEmpty()) return 0.0; | 738 if(pValue.IsEmpty()) return 0.0; |
718 » return pValue->ToNumber()->Value(); | 739 v8::Local<v8::Context> context = pJSRuntime->GetCurrentContext(); |
| 740 » return pValue->ToNumber(context).ToLocalChecked()->Value(); |
719 } | 741 } |
720 | 742 |
721 v8::Handle<v8::Object> JS_ToObject(v8::Handle<v8::Value> pValue) | 743 v8::Handle<v8::Object> JS_ToObject(IJS_Runtime* pJSRuntime, v8::Handle<v8::Value
> pValue) |
722 { | 744 { |
723 if(pValue.IsEmpty()) return v8::Handle<v8::Object>(); | 745 if(pValue.IsEmpty()) return v8::Handle<v8::Object>(); |
724 » return pValue->ToObject(); | 746 v8::Local<v8::Context> context = pJSRuntime->GetCurrentContext(); |
| 747 » return pValue->ToObject(context).ToLocalChecked(); |
725 } | 748 } |
726 | 749 |
727 CFX_WideString» JS_ToString(v8::Handle<v8::Value> pValue) | 750 CFX_WideString» JS_ToString(IJS_Runtime* pJSRuntime, v8::Handle<v8::Value> pValu
e) |
728 { | 751 { |
729 if(pValue.IsEmpty()) return L""; | 752 if(pValue.IsEmpty()) return L""; |
730 » v8::String::Utf8Value s(pValue->ToString()); | 753 v8::Local<v8::Context> context = pJSRuntime->GetCurrentContext(); |
| 754 » v8::String::Utf8Value s(pValue->ToString(context).ToLocalChecked()); |
731 return CFX_WideString::FromUTF8(*s, s.length()); | 755 return CFX_WideString::FromUTF8(*s, s.length()); |
732 } | 756 } |
733 | 757 |
734 v8::Handle<v8::Array> JS_ToArray(v8::Handle<v8::Value> pValue) | 758 v8::Handle<v8::Array> JS_ToArray(IJS_Runtime* pJSRuntime, v8::Handle<v8::Value>
pValue) |
735 { | 759 { |
736 if(pValue.IsEmpty()) return v8::Handle<v8::Array>(); | 760 if(pValue.IsEmpty()) return v8::Handle<v8::Array>(); |
737 » return v8::Handle<v8::Array>::Cast(pValue->ToObject()); | 761 v8::Local<v8::Context> context = pJSRuntime->GetCurrentContext(); |
| 762 » return v8::Handle<v8::Array>::Cast(pValue->ToObject(context).ToLocalChec
ked()); |
738 } | 763 } |
739 | 764 |
740 void JS_ValueCopy(v8::Handle<v8::Value>& pTo, v8::Handle<v8::Value> pFrom) | 765 void JS_ValueCopy(v8::Handle<v8::Value>& pTo, v8::Handle<v8::Value> pFrom) |
741 { | 766 { |
742 pTo = pFrom; | 767 pTo = pFrom; |
743 } | 768 } |
744 | 769 |
745 | 770 |
746 //JavaScript time implement begin. | 771 //JavaScript time implement begin. |
747 | 772 |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
961 | 986 |
962 double JS_DateParse(const wchar_t* string) | 987 double JS_DateParse(const wchar_t* string) |
963 { | 988 { |
964 v8::Isolate* pIsolate = v8::Isolate::GetCurrent(); | 989 v8::Isolate* pIsolate = v8::Isolate::GetCurrent(); |
965 v8::Isolate::Scope isolate_scope(pIsolate); | 990 v8::Isolate::Scope isolate_scope(pIsolate); |
966 v8::HandleScope scope(pIsolate); | 991 v8::HandleScope scope(pIsolate); |
967 | 992 |
968 v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); | 993 v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); |
969 | 994 |
970 //Use the built-in object method. | 995 //Use the built-in object method. |
971 » v8::Local<v8::Value> v = context->Global()->Get(v8::String::NewFromUtf8(
pIsolate, "Date")); | 996 » v8::Local<v8::Value> v = context->Global()->Get(context, v8::String::New
FromUtf8(pIsolate, "Date", v8::NewStringType::kNormal).ToLocalChecked()).ToLocal
Checked(); |
972 if(v->IsObject()) | 997 if(v->IsObject()) |
973 { | 998 { |
974 » » v8::Local<v8::Object> o = v->ToObject(); | 999 » » v8::Local<v8::Object> o = v->ToObject(context).ToLocalChecked(); |
975 » » v = o->Get(v8::String::NewFromUtf8(pIsolate, "parse")); | 1000 » » v = o->Get(context,v8::String::NewFromUtf8(pIsolate, "parse", v8
::NewStringType::kNormal).ToLocalChecked()).ToLocalChecked(); |
976 if(v->IsFunction()) | 1001 if(v->IsFunction()) |
977 { | 1002 { |
978 v8::Local<v8::Function> funC = v8::Handle<v8::Function>:
:Cast(v); | 1003 v8::Local<v8::Function> funC = v8::Handle<v8::Function>:
:Cast(v); |
979 | 1004 |
980 const int argc = 1; | 1005 const int argc = 1; |
981 v8::Local<v8::String> timeStr = WSToJSString(pIsolate, s
tring); | 1006 v8::Local<v8::String> timeStr = WSToJSString(pIsolate, s
tring); |
982 v8::Handle<v8::Value> argv[argc] = {timeStr}; | 1007 v8::Handle<v8::Value> argv[argc] = {timeStr}; |
983 » » » v = funC->Call(context->Global(), argc, argv); | 1008 » » » v = funC->Call(context, context->Global(), argc, argv).T
oLocalChecked(); |
984 if(v->IsNumber()) | 1009 if(v->IsNumber()) |
985 { | 1010 { |
986 » » » » double date = v->ToNumber()->Value(); | 1011 » » » » double date = v->ToNumber(context).ToLocalCheck
ed()->Value(); |
987 if(!_isfinite(date)) return date; | 1012 if(!_isfinite(date)) return date; |
988 return date + _getLocalTZA() + _getDaylightSavin
gTA(date); | 1013 return date + _getLocalTZA() + _getDaylightSavin
gTA(date); |
989 } | 1014 } |
990 | 1015 |
991 } | 1016 } |
992 } | 1017 } |
993 return 0; | 1018 return 0; |
994 } | 1019 } |
995 | 1020 |
996 double JS_MakeDay(int nYear, int nMonth, int nDate) | 1021 double JS_MakeDay(int nYear, int nMonth, int nDate) |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1035 { | 1060 { |
1036 return d != d; | 1061 return d != d; |
1037 } | 1062 } |
1038 | 1063 |
1039 double JS_LocalTime(double d) | 1064 double JS_LocalTime(double d) |
1040 { | 1065 { |
1041 return JS_GetDateTime() + _getDaylightSavingTA(d); | 1066 return JS_GetDateTime() + _getDaylightSavingTA(d); |
1042 } | 1067 } |
1043 | 1068 |
1044 //JavaScript time implement End. | 1069 //JavaScript time implement End. |
OLD | NEW |