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::HandleScope handle_scope(pIsolate); | 266 v8::HandleScope handle_scope(pIsolate); |
252 | 267 |
253 v8::Global<v8::ObjectTemplate>& globalObjTemp = | 268 v8::Global<v8::ObjectTemplate>& globalObjTemp = |
254 _getGlobalObjectTemplate(pIsolate); | 269 _getGlobalObjectTemplate(pIsolate); |
255 v8::Local<v8::Context> v8Context = v8::Context::New( | 270 v8::Local<v8::Context> v8Context = v8::Context::New( |
256 pIsolate, NULL, | 271 pIsolate, NULL, |
257 v8::Local<v8::ObjectTemplate>::New(pIsolate, globalObjTemp)); | 272 v8::Local<v8::ObjectTemplate>::New(pIsolate, globalObjTemp)); |
258 v8::Context::Scope context_scope(v8Context); | 273 v8::Context::Scope context_scope(v8Context); |
259 | 274 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 if (pObjDef->m_pDestructor) | 339 if (pObjDef->m_pDestructor) |
325 pObjDef->m_pDestructor(pObj); | 340 pObjDef->m_pDestructor(pObj); |
326 JS_FreePrivate(pObj); | 341 JS_FreePrivate(pObj); |
327 } | 342 } |
328 delete pObjDef; | 343 delete pObjDef; |
329 } | 344 } |
330 delete pArray; | 345 delete pArray; |
331 pIsolate->SetData(g_embedderDataSlot, NULL); | 346 pIsolate->SetData(g_embedderDataSlot, NULL); |
332 } | 347 } |
333 | 348 |
334 void JS_Initial(unsigned int embedderDataSlot) { | 349 void JS_Initialize(unsigned int embedderDataSlot) { |
335 g_embedderDataSlot = embedderDataSlot; | 350 g_embedderDataSlot = embedderDataSlot; |
336 } | 351 } |
337 | 352 |
338 void JS_Release() { | 353 void JS_Release() { |
339 } | 354 } |
340 | 355 |
341 int JS_Execute(v8::Isolate* pIsolate, | 356 int JS_Execute(v8::Isolate* pIsolate, |
342 IFXJS_Context* pJSContext, | 357 IFXJS_Context* pJSContext, |
343 const wchar_t* script, | 358 const wchar_t* script, |
344 long length, | 359 long length, |
(...skipping 741 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1086 | 1101 |
1087 bool JS_PortIsNan(double d) { | 1102 bool JS_PortIsNan(double d) { |
1088 return d != d; | 1103 return d != d; |
1089 } | 1104 } |
1090 | 1105 |
1091 double JS_LocalTime(double d) { | 1106 double JS_LocalTime(double d) { |
1092 return JS_GetDateTime() + _getDaylightSavingTA(d); | 1107 return JS_GetDateTime() + _getDaylightSavingTA(d); |
1093 } | 1108 } |
1094 | 1109 |
1095 // JavaScript time implement End. | 1110 // JavaScript time implement End. |
OLD | NEW |