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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 void* JS_ArrayBufferAllocator::Allocate(size_t length) { |
| 79 return calloc(1, length); |
| 80 } |
| 81 |
| 82 void* JS_ArrayBufferAllocator::AllocateUninitialized(size_t length) { |
| 83 return malloc(length); |
| 84 } |
| 85 |
| 86 void JS_ArrayBufferAllocator::Free(void* data, size_t length) { |
| 87 free(data); |
| 88 } |
| 89 |
| 90 void JS_PrepareIsolate(v8::Isolate* pIsolate) { |
| 91 if (!pIsolate->GetData(g_embedderDataSlot)) |
| 92 pIsolate->SetData(g_embedderDataSlot, new CFX_PtrArray()); |
| 93 } |
| 94 |
78 int JS_DefineObj(v8::Isolate* pIsolate, | 95 int JS_DefineObj(v8::Isolate* pIsolate, |
79 const wchar_t* sObjName, | 96 const wchar_t* sObjName, |
80 FXJSOBJTYPE eObjType, | 97 FXJSOBJTYPE eObjType, |
81 LP_CONSTRUCTOR pConstructor, | 98 LP_CONSTRUCTOR pConstructor, |
82 LP_DESTRUCTOR pDestructor) { | 99 LP_DESTRUCTOR pDestructor) { |
83 v8::Isolate::Scope isolate_scope(pIsolate); | 100 v8::Isolate::Scope isolate_scope(pIsolate); |
84 v8::HandleScope handle_scope(pIsolate); | 101 v8::HandleScope handle_scope(pIsolate); |
| 102 |
| 103 JS_PrepareIsolate(pIsolate); |
85 CFX_PtrArray* pArray = (CFX_PtrArray*)pIsolate->GetData(g_embedderDataSlot); | 104 CFX_PtrArray* pArray = (CFX_PtrArray*)pIsolate->GetData(g_embedderDataSlot); |
86 if (!pArray) { | |
87 pArray = new CFX_PtrArray(); | |
88 pIsolate->SetData(g_embedderDataSlot, pArray); | |
89 } | |
90 CJS_ObjDefintion* pObjDef = new CJS_ObjDefintion(pIsolate, sObjName, eObjType, | 105 CJS_ObjDefintion* pObjDef = new CJS_ObjDefintion(pIsolate, sObjName, eObjType, |
91 pConstructor, pDestructor); | 106 pConstructor, pDestructor); |
92 pArray->Add(pObjDef); | 107 pArray->Add(pObjDef); |
93 return pArray->GetSize() - 1; | 108 return pArray->GetSize() - 1; |
94 } | 109 } |
95 | 110 |
96 void JS_DefineObjMethod(v8::Isolate* pIsolate, | 111 void JS_DefineObjMethod(v8::Isolate* pIsolate, |
97 int nObjDefnID, | 112 int nObjDefnID, |
98 const wchar_t* sMethodName, | 113 const wchar_t* sMethodName, |
99 v8::FunctionCallback pMethodCall) { | 114 v8::FunctionCallback pMethodCall) { |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 else | 251 else |
237 objTemp = v8::Local<v8::ObjectTemplate>::New(pIsolate, globalObjTemp); | 252 objTemp = v8::Local<v8::ObjectTemplate>::New(pIsolate, globalObjTemp); |
238 objTemp->Set( | 253 objTemp->Set( |
239 v8::String::NewFromUtf8(pIsolate, bsConst.c_str(), | 254 v8::String::NewFromUtf8(pIsolate, bsConst.c_str(), |
240 v8::NewStringType::kNormal).ToLocalChecked(), | 255 v8::NewStringType::kNormal).ToLocalChecked(), |
241 pDefault, v8::ReadOnly); | 256 pDefault, v8::ReadOnly); |
242 | 257 |
243 globalObjTemp.Reset(pIsolate, objTemp); | 258 globalObjTemp.Reset(pIsolate, objTemp); |
244 } | 259 } |
245 | 260 |
246 void JS_InitialRuntime(v8::Isolate* pIsolate, | 261 void JS_InitializeRuntime(v8::Isolate* pIsolate, |
247 IFXJS_Runtime* pFXRuntime, | 262 IFXJS_Runtime* pFXRuntime, |
248 IFXJS_Context* context, | 263 IFXJS_Context* context, |
249 v8::Global<v8::Context>& v8PersistentContext) { | 264 v8::Global<v8::Context>& v8PersistentContext) { |
250 v8::Isolate::Scope isolate_scope(pIsolate); | 265 v8::Isolate::Scope isolate_scope(pIsolate); |
251 v8::Locker locker(pIsolate); | 266 v8::Locker locker(pIsolate); |
252 v8::HandleScope handle_scope(pIsolate); | 267 v8::HandleScope handle_scope(pIsolate); |
253 | 268 |
254 v8::Global<v8::ObjectTemplate>& globalObjTemp = | 269 v8::Global<v8::ObjectTemplate>& globalObjTemp = |
255 _getGlobalObjectTemplate(pIsolate); | 270 _getGlobalObjectTemplate(pIsolate); |
256 v8::Local<v8::Context> v8Context = v8::Context::New( | 271 v8::Local<v8::Context> v8Context = v8::Context::New( |
257 pIsolate, NULL, | 272 pIsolate, NULL, |
258 v8::Local<v8::ObjectTemplate>::New(pIsolate, globalObjTemp)); | 273 v8::Local<v8::ObjectTemplate>::New(pIsolate, globalObjTemp)); |
259 v8::Context::Scope context_scope(v8Context); | 274 v8::Context::Scope context_scope(v8Context); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 delete pObjDef; | 348 delete pObjDef; |
334 } | 349 } |
335 delete pArray; | 350 delete pArray; |
336 | 351 |
337 pIsolate->SetData(1, NULL); | 352 pIsolate->SetData(1, NULL); |
338 pIsolate->SetData(g_embedderDataSlot, NULL); | 353 pIsolate->SetData(g_embedderDataSlot, NULL); |
339 // TODO(tsepez): Don't use more than one embedder data slot. | 354 // TODO(tsepez): Don't use more than one embedder data slot. |
340 pIsolate->SetData(2, NULL); | 355 pIsolate->SetData(2, NULL); |
341 } | 356 } |
342 | 357 |
343 void JS_Initial(unsigned int embedderDataSlot) { | 358 void JS_Initialize(unsigned int embedderDataSlot) { |
344 g_embedderDataSlot = embedderDataSlot; | 359 g_embedderDataSlot = embedderDataSlot; |
345 } | 360 } |
346 | 361 |
347 void JS_Release() { | 362 void JS_Release() { |
348 } | 363 } |
349 | 364 |
350 int JS_Execute(v8::Isolate* pIsolate, | 365 int JS_Execute(v8::Isolate* pIsolate, |
351 IFXJS_Context* pJSContext, | 366 IFXJS_Context* pJSContext, |
352 const wchar_t* script, | 367 const wchar_t* script, |
353 long length, | 368 long length, |
(...skipping 741 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1095 | 1110 |
1096 bool JS_PortIsNan(double d) { | 1111 bool JS_PortIsNan(double d) { |
1097 return d != d; | 1112 return d != d; |
1098 } | 1113 } |
1099 | 1114 |
1100 double JS_LocalTime(double d) { | 1115 double JS_LocalTime(double d) { |
1101 return JS_GetDateTime() + _getDaylightSavingTA(d); | 1116 return JS_GetDateTime() + _getDaylightSavingTA(d); |
1102 } | 1117 } |
1103 | 1118 |
1104 // JavaScript time implement End. | 1119 // JavaScript time implement End. |
OLD | NEW |