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 19 matching lines...) Expand all Loading... |
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 } | 34 } |
35 | 35 |
36 IFXJS_Runtime* CJS_RuntimeFactory::NewJSRuntime(CPDFDoc_Environ
ment* pApp) | 36 IFXJS_Runtime* CJS_RuntimeFactory::NewJSRuntime(CPDFDoc_Environ
ment* pApp) |
37 { | 37 { |
38 if (!m_bInit) | 38 if (!m_bInit) |
39 { | 39 { |
40 » » JS_Initial(); | 40 » » unsigned int embedderDataSlot = 0; |
| 41 » » if (pApp->GetFormFillInfo()->m_pJsPlatform->version >= 2) { |
| 42 » » » embedderDataSlot = pApp->GetFormFillInfo()->m_pJsPlatfor
m->m_v8EmbedderSlot; |
| 43 } |
| 44 » » JS_Initial(embedderDataSlot); |
41 m_bInit = TRUE; | 45 m_bInit = TRUE; |
42 } | 46 } |
43 return new CJS_Runtime(pApp); | 47 return new CJS_Runtime(pApp); |
44 } | 48 } |
45 void CJS_RuntimeFactory::AddRef() | 49 void CJS_RuntimeFactory::AddRef() |
46 { | 50 { |
47 //to do.Should be implemented as atom manipulation. | 51 //to do.Should be implemented as atom manipulation. |
48 m_nRef++; | 52 m_nRef++; |
49 } | 53 } |
50 void CJS_RuntimeFactory::Release() | 54 void CJS_RuntimeFactory::Release() |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 void CJS_ArrayBufferAllocator::Free(void* data, size_t length) { | 104 void CJS_ArrayBufferAllocator::Free(void* data, size_t length) { |
101 free(data); | 105 free(data); |
102 } | 106 } |
103 | 107 |
104 /* ------------------------------ CJS_Runtime ------------------------------ */ | 108 /* ------------------------------ CJS_Runtime ------------------------------ */ |
105 extern v8::Global<v8::ObjectTemplate>& _getGlobalObjectTemplate(IJS_Runtime* pJS
Runtime); | 109 extern v8::Global<v8::ObjectTemplate>& _getGlobalObjectTemplate(IJS_Runtime* pJS
Runtime); |
106 CJS_Runtime::CJS_Runtime(CPDFDoc_Environment* pApp) : | 110 CJS_Runtime::CJS_Runtime(CPDFDoc_Environment* pApp) : |
107 m_pApp(pApp), | 111 m_pApp(pApp), |
108 m_pDocument(NULL), | 112 m_pDocument(NULL), |
109 m_bBlocking(FALSE), | 113 m_bBlocking(FALSE), |
110 » m_pFieldEventPath(NULL) | 114 » m_pFieldEventPath(NULL), |
| 115 m_isolate(NULL) |
111 { | 116 { |
112 if (CPDFXFA_App::GetInstance()->GetJSERuntime()) { | 117 if (CPDFXFA_App::GetInstance()->GetJSERuntime()) { |
| 118 // TODO(tsepez): CPDFXFA_App should also use the embedder provid
ed isolate. |
113 m_isolate = (v8::Isolate*)CPDFXFA_App::GetInstance()->GetJSERunt
ime(); | 119 m_isolate = (v8::Isolate*)CPDFXFA_App::GetInstance()->GetJSERunt
ime(); |
114 » } else { | 120 » } else if (m_pApp->GetFormFillInfo()->m_pJsPlatform->version >= 2) { |
| 121 » » m_isolate = reinterpret_cast<v8::Isolate*>(m_pApp->GetFormFillIn
fo()->m_pJsPlatform->m_isolate); |
| 122 » } |
| 123 » if (!m_isolate) { |
115 m_pArrayBufferAllocator.reset(new CJS_ArrayBufferAllocator()); | 124 m_pArrayBufferAllocator.reset(new CJS_ArrayBufferAllocator()); |
| 125 |
116 v8::Isolate::CreateParams params; | 126 v8::Isolate::CreateParams params; |
117 params.array_buffer_allocator = m_pArrayBufferAllocator.get(); | 127 params.array_buffer_allocator = m_pArrayBufferAllocator.get(); |
118 m_isolate = v8::Isolate::New(params); | 128 m_isolate = v8::Isolate::New(params); |
119 » } | 129 } |
120 | 130 |
121 v8::Isolate* isolate = m_isolate; | 131 v8::Isolate* isolate = m_isolate; |
122 v8::Isolate::Scope isolate_scope(isolate); | 132 v8::Isolate::Scope isolate_scope(isolate); |
123 v8::Locker locker(isolate); | 133 v8::Locker locker(isolate); |
124 v8::HandleScope handle_scope(isolate); | 134 v8::HandleScope handle_scope(isolate); |
125 if (CPDFXFA_App::GetInstance()->InitRuntime(FALSE)) { | 135 if (CPDFXFA_App::GetInstance()->InitRuntime(FALSE)) { |
126 CJS_Context * pContext = (CJS_Context*)NewContext(); | 136 CJS_Context * pContext = (CJS_Context*)NewContext(); |
127 JS_InitialRuntime(*this, this, pContext, m_context); | 137 JS_InitialRuntime(*this, this, pContext, m_context); |
128 ReleaseContext(pContext); | 138 ReleaseContext(pContext); |
129 return; | 139 return; |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 v8::Local<v8::Context> context = | 395 v8::Local<v8::Context> context = |
386 v8::Local<v8::Context>::New(pIsolate, m_context); | 396 v8::Local<v8::Context>::New(pIsolate, m_context); |
387 v8::Context::Scope context_scope(context); | 397 v8::Context::Scope context_scope(context); |
388 | 398 |
389 //v8::Local<v8::Context> tmpCotext = v8::Local<v8::Context>::New(GetIsol
ate(), m_context); | 399 //v8::Local<v8::Context> tmpCotext = v8::Local<v8::Context>::New(GetIsol
ate(), m_context); |
390 v8::Local<v8::Value> propvalue = v8::Local<v8::Value>::New(GetIsolate(),
((CFXJSE_Value*)hValue)->DirectGetValue()); | 400 v8::Local<v8::Value> propvalue = v8::Local<v8::Value>::New(GetIsolate(),
((CFXJSE_Value*)hValue)->DirectGetValue()); |
391 context->Global()->Set(v8::String::NewFromUtf8(pIsolate, name, v8::Strin
g::kNormalString, utf8Name.GetLength()), propvalue); | 401 context->Global()->Set(v8::String::NewFromUtf8(pIsolate, name, v8::Strin
g::kNormalString, utf8Name.GetLength()), propvalue); |
392 | 402 |
393 return TRUE; | 403 return TRUE; |
394 } | 404 } |
OLD | NEW |