| 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 { | 86 { |
| 87 m_nGlobalDataCount--; | 87 m_nGlobalDataCount--; |
| 88 | 88 |
| 89 if (m_nGlobalDataCount <= 0) | 89 if (m_nGlobalDataCount <= 0) |
| 90 { | 90 { |
| 91 delete m_pGlobalData; | 91 delete m_pGlobalData; |
| 92 m_pGlobalData = NULL; | 92 m_pGlobalData = NULL; |
| 93 } | 93 } |
| 94 } | 94 } |
| 95 | 95 |
| 96 void* CJS_ArrayBufferAllocator::Allocate(size_t length) { |
| 97 return calloc(1, length); |
| 98 } |
| 99 |
| 100 void* CJS_ArrayBufferAllocator::AllocateUninitialized(size_t length) { |
| 101 return malloc(length); |
| 102 } |
| 103 |
| 104 void CJS_ArrayBufferAllocator::Free(void* data, size_t length) { |
| 105 free(data); |
| 106 } |
| 107 |
| 96 /* ------------------------------ CJS_Runtime ------------------------------ */ | 108 /* ------------------------------ CJS_Runtime ------------------------------ */ |
| 97 extern v8::Persistent<v8::ObjectTemplate>& _getGlobalObjectTemplate(IJS_Runtime*
pJSRuntime); | 109 extern v8::Persistent<v8::ObjectTemplate>& _getGlobalObjectTemplate(IJS_Runtime*
pJSRuntime); |
| 98 CJS_Runtime::CJS_Runtime(CPDFDoc_Environment* pApp) : | 110 CJS_Runtime::CJS_Runtime(CPDFDoc_Environment* pApp) : |
| 99 m_pApp(pApp), | 111 m_pApp(pApp), |
| 100 m_pDocument(NULL), | 112 m_pDocument(NULL), |
| 101 m_bBlocking(FALSE), | 113 m_bBlocking(FALSE), |
| 102 » m_pFieldEventPath(NULL), | 114 » m_bRegistered(FALSE), |
| 103 » m_bRegistered(FALSE) | 115 » m_pFieldEventPath(NULL) |
| 104 { | 116 { |
| 105 » m_isolate = FPDFXFA_GetApp()->GetJSERuntime()?(v8::Isolate*)FPDFXFA_GetA
pp()->GetJSERuntime():v8::Isolate::New(); | 117 » if (FPDFXFA_GetApp()->GetJSERuntime()) { |
| 106 » //m_isolate->Enter(); | 118 » » m_isolate = (v8::Isolate*)FPDFXFA_GetApp()->GetJSERuntime(); |
| 119 » } else { |
| 120 » » m_pArrayBufferAllocator.reset(new CJS_ArrayBufferAllocator()); |
| 121 » » v8::Isolate::CreateParams params; |
| 122 » » params.array_buffer_allocator = m_pArrayBufferAllocator.get(); |
| 123 » » m_isolate = v8::Isolate::New(params); |
| 124 » } |
| 125 |
| 107 v8::Isolate* isolate = m_isolate; | 126 v8::Isolate* isolate = m_isolate; |
| 108 v8::Isolate::Scope isolate_scope(isolate); | 127 v8::Isolate::Scope isolate_scope(isolate); |
| 109 v8::Locker locker(isolate); | 128 v8::Locker locker(isolate); |
| 110 v8::HandleScope handle_scope(isolate); | 129 v8::HandleScope handle_scope(isolate); |
| 111 if (FPDFXFA_GetApp()->InitRuntime(FALSE)) { | 130 if (FPDFXFA_GetApp()->InitRuntime(FALSE)) { |
| 112 CJS_Context * pContext = (CJS_Context*)NewContext(); | 131 CJS_Context * pContext = (CJS_Context*)NewContext(); |
| 113 JS_InitialRuntime(*this, this, pContext, m_context); | 132 JS_InitialRuntime(*this, this, pContext, m_context); |
| 114 ReleaseContext(pContext); | 133 ReleaseContext(pContext); |
| 115 return; | 134 return; |
| 116 } | 135 } |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 v8::Local<v8::Context> context = | 394 v8::Local<v8::Context> context = |
| 376 v8::Local<v8::Context>::New(pIsolate, m_context); | 395 v8::Local<v8::Context>::New(pIsolate, m_context); |
| 377 v8::Context::Scope context_scope(context); | 396 v8::Context::Scope context_scope(context); |
| 378 | 397 |
| 379 //v8::Local<v8::Context> tmpCotext = v8::Local<v8::Context>::New(GetIsol
ate(), m_context); | 398 //v8::Local<v8::Context> tmpCotext = v8::Local<v8::Context>::New(GetIsol
ate(), m_context); |
| 380 v8::Local<v8::Value> propvalue = v8::Local<v8::Value>::New(GetIsolate(),
((CFXJSE_Value*)hValue)->DirectGetValue()); | 399 v8::Local<v8::Value> propvalue = v8::Local<v8::Value>::New(GetIsolate(),
((CFXJSE_Value*)hValue)->DirectGetValue()); |
| 381 context->Global()->Set(v8::String::NewFromUtf8(pIsolate, name, v8::Strin
g::kNormalString, utf8Name.GetLength()), propvalue); | 400 context->Global()->Set(v8::String::NewFromUtf8(pIsolate, name, v8::Strin
g::kNormalString, utf8Name.GetLength()), propvalue); |
| 382 | 401 |
| 383 return TRUE; | 402 return TRUE; |
| 384 } | 403 } |
| OLD | NEW |