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 "../../include/javascript/JavaScript.h" | 7 #include "../../include/javascript/JavaScript.h" |
8 #include "../../include/javascript/IJavaScript.h" | 8 #include "../../include/javascript/IJavaScript.h" |
9 #include "../../include/javascript/JS_EventHandler.h" | 9 #include "../../include/javascript/JS_EventHandler.h" |
10 #include "../../include/javascript/JS_Runtime.h" | 10 #include "../../include/javascript/JS_Runtime.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "../../include/javascript/PublicMethods.h" | 23 #include "../../include/javascript/PublicMethods.h" |
24 #include "../../include/javascript/report.h" | 24 #include "../../include/javascript/report.h" |
25 #include "../../include/javascript/util.h" | 25 #include "../../include/javascript/util.h" |
26 #include "../../include/javascript/JS_GlobalData.h" | 26 #include "../../include/javascript/JS_GlobalData.h" |
27 #include "../../include/javascript/global.h" | 27 #include "../../include/javascript/global.h" |
28 #include "../../include/javascript/console.h" | 28 #include "../../include/javascript/console.h" |
29 | 29 |
30 CJS_RuntimeFactory::~CJS_RuntimeFactory() {} | 30 CJS_RuntimeFactory::~CJS_RuntimeFactory() {} |
31 | 31 |
32 IFXJS_Runtime* CJS_RuntimeFactory::NewJSRuntime(CPDFDoc_Environment* pApp) { | 32 IFXJS_Runtime* CJS_RuntimeFactory::NewJSRuntime(CPDFDoc_Environment* pApp) { |
33 if (!m_bInit) { | 33 m_bInit = true; |
34 unsigned int embedderDataSlot = 0; | |
35 if (pApp->GetFormFillInfo()->m_pJsPlatform->version >= 2) { | |
36 embedderDataSlot = | |
37 pApp->GetFormFillInfo()->m_pJsPlatform->m_v8EmbedderSlot; | |
38 } | |
39 JS_Initial(embedderDataSlot); | |
40 m_bInit = TRUE; | |
41 } | |
42 return new CJS_Runtime(pApp); | 34 return new CJS_Runtime(pApp); |
43 } | 35 } |
44 void CJS_RuntimeFactory::AddRef() { | 36 void CJS_RuntimeFactory::AddRef() { |
45 // to do.Should be implemented as atom manipulation. | |
46 m_nRef++; | 37 m_nRef++; |
47 } | 38 } |
48 void CJS_RuntimeFactory::Release() { | 39 void CJS_RuntimeFactory::Release() { |
49 if (m_bInit) { | 40 if (m_bInit) { |
50 // to do.Should be implemented as atom manipulation. | |
51 if (--m_nRef == 0) { | 41 if (--m_nRef == 0) { |
52 JS_Release(); | 42 JS_Release(); |
53 m_bInit = FALSE; | 43 m_bInit = FALSE; |
54 } | 44 } |
55 } | 45 } |
56 } | 46 } |
57 | 47 |
58 void CJS_RuntimeFactory::DeleteJSRuntime(IFXJS_Runtime* pRuntime) { | 48 void CJS_RuntimeFactory::DeleteJSRuntime(IFXJS_Runtime* pRuntime) { |
59 delete (CJS_Runtime*)pRuntime; | 49 delete (CJS_Runtime*)pRuntime; |
60 } | 50 } |
61 | 51 |
62 void* CJS_ArrayBufferAllocator::Allocate(size_t length) { | |
63 return calloc(1, length); | |
64 } | |
65 | |
66 void* CJS_ArrayBufferAllocator::AllocateUninitialized(size_t length) { | |
67 return malloc(length); | |
68 } | |
69 | |
70 void CJS_ArrayBufferAllocator::Free(void* data, size_t length) { | |
71 free(data); | |
72 } | |
73 | |
74 /* ------------------------------ CJS_Runtime ------------------------------ */ | 52 /* ------------------------------ CJS_Runtime ------------------------------ */ |
75 | 53 |
76 CJS_Runtime::CJS_Runtime(CPDFDoc_Environment* pApp) | 54 CJS_Runtime::CJS_Runtime(CPDFDoc_Environment* pApp) |
77 : m_pApp(pApp), | 55 : m_pApp(pApp), |
78 m_pDocument(NULL), | 56 m_pDocument(NULL), |
79 m_bBlocking(FALSE), | 57 m_bBlocking(FALSE), |
80 m_pFieldEventPath(NULL), | 58 m_pFieldEventPath(NULL), |
81 m_isolate(NULL), | 59 m_isolate(NULL), |
82 m_isolateManaged(false) { | 60 m_isolateManaged(false) { |
| 61 unsigned int embedderDataSlot = 0; |
83 if (m_pApp->GetFormFillInfo()->m_pJsPlatform->version >= 2) { | 62 if (m_pApp->GetFormFillInfo()->m_pJsPlatform->version >= 2) { |
84 m_isolate = reinterpret_cast<v8::Isolate*>( | 63 m_isolate = reinterpret_cast<v8::Isolate*>( |
85 m_pApp->GetFormFillInfo()->m_pJsPlatform->m_isolate); | 64 m_pApp->GetFormFillInfo()->m_pJsPlatform->m_isolate); |
| 65 embedderDataSlot = pApp->GetFormFillInfo()->m_pJsPlatform->m_v8EmbedderSlot; |
86 } | 66 } |
87 if (!m_isolate) { | 67 if (!m_isolate) { |
88 m_pArrayBufferAllocator.reset(new CJS_ArrayBufferAllocator()); | 68 m_pArrayBufferAllocator.reset(new JS_ArrayBufferAllocator()); |
89 | 69 |
90 v8::Isolate::CreateParams params; | 70 v8::Isolate::CreateParams params; |
91 params.array_buffer_allocator = m_pArrayBufferAllocator.get(); | 71 params.array_buffer_allocator = m_pArrayBufferAllocator.get(); |
92 m_isolate = v8::Isolate::New(params); | 72 m_isolate = v8::Isolate::New(params); |
93 m_isolateManaged = true; | 73 m_isolateManaged = true; |
94 } | 74 } |
95 | 75 |
| 76 JS_Initialize(embedderDataSlot); |
96 DefineJSObjects(); | 77 DefineJSObjects(); |
97 | 78 |
98 CJS_Context* pContext = (CJS_Context*)NewContext(); | 79 CJS_Context* pContext = (CJS_Context*)NewContext(); |
99 JS_InitialRuntime(GetIsolate(), this, pContext, m_context); | 80 JS_InitializeRuntime(GetIsolate(), this, pContext, m_context); |
100 ReleaseContext(pContext); | 81 ReleaseContext(pContext); |
101 } | 82 } |
102 | 83 |
103 CJS_Runtime::~CJS_Runtime() { | 84 CJS_Runtime::~CJS_Runtime() { |
104 for (int i = 0, sz = m_ContextArray.GetSize(); i < sz; i++) | 85 for (int i = 0, sz = m_ContextArray.GetSize(); i < sz; i++) |
105 delete m_ContextArray.GetAt(i); | 86 delete m_ContextArray.GetAt(i); |
106 | 87 |
107 m_ContextArray.RemoveAll(); | 88 m_ContextArray.RemoveAll(); |
108 JS_ReleaseRuntime(GetIsolate(), m_context); | 89 JS_ReleaseRuntime(GetIsolate(), m_context); |
109 RemoveEventsInLoop(m_pFieldEventPath); | 90 RemoveEventsInLoop(m_pFieldEventPath); |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 | 266 |
286 v8::Local<v8::Context> CJS_Runtime::NewJSContext() { | 267 v8::Local<v8::Context> CJS_Runtime::NewJSContext() { |
287 return v8::Local<v8::Context>::New(m_isolate, m_context); | 268 return v8::Local<v8::Context>::New(m_isolate, m_context); |
288 } | 269 } |
289 | 270 |
290 CFX_WideString ChangeObjName(const CFX_WideString& str) { | 271 CFX_WideString ChangeObjName(const CFX_WideString& str) { |
291 CFX_WideString sRet = str; | 272 CFX_WideString sRet = str; |
292 sRet.Replace(L"_", L"."); | 273 sRet.Replace(L"_", L"."); |
293 return sRet; | 274 return sRet; |
294 } | 275 } |
OLD | NEW |