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 14 matching lines...) Expand all Loading... |
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 #include "../../include/fpdfxfa/fpdfxfa_app.h" | 29 #include "../../include/fpdfxfa/fpdfxfa_app.h" |
30 #include "../../../xfa/src/fxjse/src/value.h" | 30 #include "../../../xfa/src/fxjse/src/value.h" |
31 | 31 |
32 CJS_RuntimeFactory::~CJS_RuntimeFactory() {} | 32 CJS_RuntimeFactory::~CJS_RuntimeFactory() {} |
33 | 33 |
34 IFXJS_Runtime* CJS_RuntimeFactory::NewJSRuntime(CPDFDoc_Environment* pApp) { | 34 IFXJS_Runtime* CJS_RuntimeFactory::NewJSRuntime(CPDFDoc_Environment* pApp) { |
35 if (!m_bInit) { | 35 m_bInit = true; |
36 unsigned int embedderDataSlot = 0; | |
37 if (pApp->GetFormFillInfo()->m_pJsPlatform->version >= 2) { | |
38 embedderDataSlot = | |
39 pApp->GetFormFillInfo()->m_pJsPlatform->m_v8EmbedderSlot; | |
40 } | |
41 JS_Initial(embedderDataSlot); | |
42 m_bInit = TRUE; | |
43 } | |
44 return new CJS_Runtime(pApp); | 36 return new CJS_Runtime(pApp); |
45 } | 37 } |
46 void CJS_RuntimeFactory::AddRef() { | 38 void CJS_RuntimeFactory::AddRef() { |
47 // to do.Should be implemented as atom manipulation. | |
48 m_nRef++; | 39 m_nRef++; |
49 } | 40 } |
50 void CJS_RuntimeFactory::Release() { | 41 void CJS_RuntimeFactory::Release() { |
51 if (m_bInit) { | 42 if (m_bInit) { |
52 // to do.Should be implemented as atom manipulation. | |
53 if (--m_nRef == 0) { | 43 if (--m_nRef == 0) { |
54 JS_Release(); | 44 JS_Release(); |
55 m_bInit = FALSE; | 45 m_bInit = FALSE; |
56 } | 46 } |
57 } | 47 } |
58 } | 48 } |
59 | 49 |
60 void CJS_RuntimeFactory::DeleteJSRuntime(IFXJS_Runtime* pRuntime) { | 50 void CJS_RuntimeFactory::DeleteJSRuntime(IFXJS_Runtime* pRuntime) { |
61 delete (CJS_Runtime*)pRuntime; | 51 delete (CJS_Runtime*)pRuntime; |
62 } | 52 } |
63 | 53 |
64 void* CJS_ArrayBufferAllocator::Allocate(size_t length) { | |
65 return calloc(1, length); | |
66 } | |
67 | |
68 void* CJS_ArrayBufferAllocator::AllocateUninitialized(size_t length) { | |
69 return malloc(length); | |
70 } | |
71 | |
72 void CJS_ArrayBufferAllocator::Free(void* data, size_t length) { | |
73 free(data); | |
74 } | |
75 | |
76 /* ------------------------------ CJS_Runtime ------------------------------ */ | 54 /* ------------------------------ CJS_Runtime ------------------------------ */ |
77 v8::Global<v8::ObjectTemplate>& _getGlobalObjectTemplate(v8::Isolate* pIsolate); | 55 v8::Global<v8::ObjectTemplate>& _getGlobalObjectTemplate(v8::Isolate* pIsolate); |
78 | 56 |
79 CJS_Runtime::CJS_Runtime(CPDFDoc_Environment* pApp) | 57 CJS_Runtime::CJS_Runtime(CPDFDoc_Environment* pApp) |
80 : m_pApp(pApp), | 58 : m_pApp(pApp), |
81 m_pDocument(NULL), | 59 m_pDocument(NULL), |
82 m_bBlocking(FALSE), | 60 m_bBlocking(FALSE), |
83 m_pFieldEventPath(NULL), | 61 m_pFieldEventPath(NULL), |
84 m_isolate(NULL), | 62 m_isolate(NULL), |
85 m_isolateManaged(false) { | 63 m_isolateManaged(false) { |
86 if (CPDFXFA_App::GetInstance()->GetJSERuntime()) { | 64 if (CPDFXFA_App::GetInstance()->GetJSERuntime()) { |
87 // TODO(tsepez): CPDFXFA_App should also use the embedder provided isolate. | 65 // TODO(tsepez): CPDFXFA_App should also use the embedder provided isolate. |
88 m_isolate = (v8::Isolate*)CPDFXFA_App::GetInstance()->GetJSERuntime(); | 66 m_isolate = (v8::Isolate*)CPDFXFA_App::GetInstance()->GetJSERuntime(); |
89 } else if (m_pApp->GetFormFillInfo()->m_pJsPlatform->version >= 2) { | 67 } else if (m_pApp->GetFormFillInfo()->m_pJsPlatform->version >= 2) { |
90 m_isolate = reinterpret_cast<v8::Isolate*>( | 68 m_isolate = reinterpret_cast<v8::Isolate*>( |
91 m_pApp->GetFormFillInfo()->m_pJsPlatform->m_isolate); | 69 m_pApp->GetFormFillInfo()->m_pJsPlatform->m_isolate); |
92 } | 70 } |
93 if (!m_isolate) { | 71 if (!m_isolate) { |
94 m_pArrayBufferAllocator.reset(new CJS_ArrayBufferAllocator()); | 72 m_pArrayBufferAllocator.reset(new JS_ArrayBufferAllocator()); |
95 | 73 |
96 v8::Isolate::CreateParams params; | 74 v8::Isolate::CreateParams params; |
97 params.array_buffer_allocator = m_pArrayBufferAllocator.get(); | 75 params.array_buffer_allocator = m_pArrayBufferAllocator.get(); |
98 m_isolate = v8::Isolate::New(params); | 76 m_isolate = v8::Isolate::New(params); |
99 m_isolateManaged = true; | 77 m_isolateManaged = true; |
100 } | 78 } |
101 | 79 |
102 v8::Isolate* isolate = m_isolate; | 80 v8::Isolate* isolate = m_isolate; |
103 v8::Isolate::Scope isolate_scope(isolate); | 81 v8::Isolate::Scope isolate_scope(isolate); |
104 v8::Locker locker(isolate); | 82 v8::Locker locker(isolate); |
105 v8::HandleScope handle_scope(isolate); | 83 v8::HandleScope handle_scope(isolate); |
106 if (CPDFXFA_App::GetInstance()->InitRuntime(FALSE)) { | 84 if (CPDFXFA_App::GetInstance()->InitRuntime(FALSE)) { |
107 CJS_Context* pContext = (CJS_Context*)NewContext(); | 85 CJS_Context* pContext = (CJS_Context*)NewContext(); |
108 JS_InitialRuntime(GetIsolate(), this, pContext, m_context); | 86 JS_InitializeRuntime(GetIsolate(), this, pContext, m_context); |
109 ReleaseContext(pContext); | 87 ReleaseContext(pContext); |
110 return; | 88 return; |
111 } | 89 } |
112 | 90 |
| 91 unsigned int embedderDataSlot = 0; |
| 92 if (m_pApp->GetFormFillInfo()->m_pJsPlatform->version >= 2) |
| 93 embedderDataSlot = pApp->GetFormFillInfo()->m_pJsPlatform->m_v8EmbedderSlot; |
| 94 JS_Initialize(embedderDataSlot); |
113 DefineJSObjects(); | 95 DefineJSObjects(); |
114 | 96 |
115 CJS_Context* pContext = (CJS_Context*)NewContext(); | 97 CJS_Context* pContext = (CJS_Context*)NewContext(); |
116 JS_InitialRuntime(GetIsolate(), this, pContext, m_context); | 98 JS_InitializeRuntime(GetIsolate(), this, pContext, m_context); |
117 ReleaseContext(pContext); | 99 ReleaseContext(pContext); |
118 } | 100 } |
119 | 101 |
120 CJS_Runtime::~CJS_Runtime() { | 102 CJS_Runtime::~CJS_Runtime() { |
121 int size = m_ContextArray.GetSize(); | 103 int size = m_ContextArray.GetSize(); |
122 for (int i = 0; i < size; i++) | 104 for (int i = 0; i < size; i++) |
123 delete m_ContextArray.GetAt(i); | 105 delete m_ContextArray.GetAt(i); |
124 | 106 |
125 m_ContextArray.RemoveAll(); | 107 m_ContextArray.RemoveAll(); |
126 | 108 |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 // v8::Local<v8::Context>::New(GetIsolate(), m_context); | 337 // v8::Local<v8::Context>::New(GetIsolate(), m_context); |
356 v8::Local<v8::Value> propvalue = v8::Local<v8::Value>::New( | 338 v8::Local<v8::Value> propvalue = v8::Local<v8::Value>::New( |
357 GetIsolate(), ((CFXJSE_Value*)hValue)->DirectGetValue()); | 339 GetIsolate(), ((CFXJSE_Value*)hValue)->DirectGetValue()); |
358 context->Global()->Set( | 340 context->Global()->Set( |
359 v8::String::NewFromUtf8(pIsolate, name, v8::String::kNormalString, | 341 v8::String::NewFromUtf8(pIsolate, name, v8::String::kNormalString, |
360 utf8Name.GetLength()), | 342 utf8Name.GetLength()), |
361 propvalue); | 343 propvalue); |
362 | 344 |
363 return TRUE; | 345 return TRUE; |
364 } | 346 } |
OLD | NEW |