Chromium Code Reviews| 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 | |
| 95 void JS_ResetIsolate(v8::Isolate* pIsolate) { | |
| 96 delete (CFX_PtrArray*)pIsolate->GetData(g_embedderDataSlot); | |
| 97 pIsolate->SetData(g_embedderDataSlot, nullptr); | |
| 98 } | |
| 99 | |
| 78 int JS_DefineObj(v8::Isolate* pIsolate, | 100 int JS_DefineObj(v8::Isolate* pIsolate, |
| 79 const wchar_t* sObjName, | 101 const wchar_t* sObjName, |
| 80 FXJSOBJTYPE eObjType, | 102 FXJSOBJTYPE eObjType, |
| 81 LP_CONSTRUCTOR pConstructor, | 103 LP_CONSTRUCTOR pConstructor, |
| 82 LP_DESTRUCTOR pDestructor) { | 104 LP_DESTRUCTOR pDestructor) { |
| 83 v8::Isolate::Scope isolate_scope(pIsolate); | 105 v8::Isolate::Scope isolate_scope(pIsolate); |
| 84 v8::HandleScope handle_scope(pIsolate); | 106 v8::HandleScope handle_scope(pIsolate); |
| 107 | |
| 108 JS_PrepareIsolate(pIsolate); | |
| 85 CFX_PtrArray* pArray = (CFX_PtrArray*)pIsolate->GetData(g_embedderDataSlot); | 109 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, | 110 CJS_ObjDefintion* pObjDef = new CJS_ObjDefintion(pIsolate, sObjName, eObjType, |
| 91 pConstructor, pDestructor); | 111 pConstructor, pDestructor); |
| 92 pArray->Add(pObjDef); | 112 pArray->Add(pObjDef); |
| 93 return pArray->GetSize() - 1; | 113 return pArray->GetSize() - 1; |
| 94 } | 114 } |
| 95 | 115 |
| 96 void JS_DefineObjMethod(v8::Isolate* pIsolate, | 116 void JS_DefineObjMethod(v8::Isolate* pIsolate, |
| 97 int nObjDefnID, | 117 int nObjDefnID, |
| 98 const wchar_t* sMethodName, | 118 const wchar_t* sMethodName, |
| 99 v8::FunctionCallback pMethodCall) { | 119 v8::FunctionCallback pMethodCall) { |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 321 if (!pObjDef->m_StaticObj.IsEmpty()) { | 341 if (!pObjDef->m_StaticObj.IsEmpty()) { |
| 322 v8::Local<v8::Object> pObj = | 342 v8::Local<v8::Object> pObj = |
| 323 v8::Local<v8::Object>::New(pIsolate, pObjDef->m_StaticObj); | 343 v8::Local<v8::Object>::New(pIsolate, pObjDef->m_StaticObj); |
| 324 if (pObjDef->m_pDestructor) | 344 if (pObjDef->m_pDestructor) |
| 325 pObjDef->m_pDestructor(pObj); | 345 pObjDef->m_pDestructor(pObj); |
| 326 JS_FreePrivate(pObj); | 346 JS_FreePrivate(pObj); |
| 327 } | 347 } |
| 328 delete pObjDef; | 348 delete pObjDef; |
| 329 } | 349 } |
| 330 delete pArray; | 350 delete pArray; |
| 331 pIsolate->SetData(g_embedderDataSlot, NULL); | 351 pIsolate->SetData(g_embedderDataSlot, NULL); |
|
Lei Zhang
2015/09/15 01:59:55
I guess this is where we would call JS_ResetIsolat
Tom Sepez
2015/09/15 15:56:42
Removed JS_ResetIsolate, added comment about this
| |
| 332 } | 352 } |
| 333 | 353 |
| 334 void JS_Initial(unsigned int embedderDataSlot) { | 354 void JS_Initial(unsigned int embedderDataSlot) { |
| 335 g_embedderDataSlot = embedderDataSlot; | 355 g_embedderDataSlot = embedderDataSlot; |
| 336 } | 356 } |
| 337 | 357 |
| 338 void JS_Release() { | 358 void JS_Release() { |
| 339 } | 359 } |
| 340 | 360 |
| 341 int JS_Execute(v8::Isolate* pIsolate, | 361 int JS_Execute(v8::Isolate* pIsolate, |
| (...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1086 | 1106 |
| 1087 bool JS_PortIsNan(double d) { | 1107 bool JS_PortIsNan(double d) { |
| 1088 return d != d; | 1108 return d != d; |
| 1089 } | 1109 } |
| 1090 | 1110 |
| 1091 double JS_LocalTime(double d) { | 1111 double JS_LocalTime(double d) { |
| 1092 return JS_GetDateTime() + _getDaylightSavingTA(d); | 1112 return JS_GetDateTime() + _getDaylightSavingTA(d); |
| 1093 } | 1113 } |
| 1094 | 1114 |
| 1095 // JavaScript time implement End. | 1115 // JavaScript time implement End. |
| OLD | NEW |