Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1251)

Side by Side Diff: fpdfsdk/src/javascript/JS_Runtime.cpp

Issue 1270293002: Merge to XFA: Don't dispose the isolate if its provided by the embedder (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « fpdfsdk/include/javascript/JS_Runtime.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 } 94 }
95 95
96 /* ------------------------------ CJS_Runtime ------------------------------ */ 96 /* ------------------------------ CJS_Runtime ------------------------------ */
97 extern v8::Global<v8::ObjectTemplate>& _getGlobalObjectTemplate( 97 extern v8::Global<v8::ObjectTemplate>& _getGlobalObjectTemplate(
98 IJS_Runtime* pJSRuntime); 98 IJS_Runtime* pJSRuntime);
99 CJS_Runtime::CJS_Runtime(CPDFDoc_Environment* pApp) 99 CJS_Runtime::CJS_Runtime(CPDFDoc_Environment* pApp)
100 : m_pApp(pApp), 100 : m_pApp(pApp),
101 m_pDocument(NULL), 101 m_pDocument(NULL),
102 m_bBlocking(FALSE), 102 m_bBlocking(FALSE),
103 m_pFieldEventPath(NULL), 103 m_pFieldEventPath(NULL),
104 m_isolate(NULL) { 104 m_isolate(NULL),
105 m_isolateManaged(false) {
105 if (CPDFXFA_App::GetInstance()->GetJSERuntime()) { 106 if (CPDFXFA_App::GetInstance()->GetJSERuntime()) {
106 // TODO(tsepez): CPDFXFA_App should also use the embedder provided isolate. 107 // TODO(tsepez): CPDFXFA_App should also use the embedder provided isolate.
107 m_isolate = (v8::Isolate*)CPDFXFA_App::GetInstance()->GetJSERuntime(); 108 m_isolate = (v8::Isolate*)CPDFXFA_App::GetInstance()->GetJSERuntime();
108 } else if (m_pApp->GetFormFillInfo()->m_pJsPlatform->version >= 2) { 109 } else if (m_pApp->GetFormFillInfo()->m_pJsPlatform->version >= 2) {
109 m_isolate = reinterpret_cast<v8::Isolate*>( 110 m_isolate = reinterpret_cast<v8::Isolate*>(
110 m_pApp->GetFormFillInfo()->m_pJsPlatform->m_isolate); 111 m_pApp->GetFormFillInfo()->m_pJsPlatform->m_isolate);
111 } 112 }
112 if (!m_isolate) { 113 if (!m_isolate) {
113 m_pArrayBufferAllocator.reset(new CJS_ArrayBufferAllocator()); 114 m_pArrayBufferAllocator.reset(new CJS_ArrayBufferAllocator());
114 115
115 v8::Isolate::CreateParams params; 116 v8::Isolate::CreateParams params;
116 params.array_buffer_allocator = m_pArrayBufferAllocator.get(); 117 params.array_buffer_allocator = m_pArrayBufferAllocator.get();
117 m_isolate = v8::Isolate::New(params); 118 m_isolate = v8::Isolate::New(params);
119 m_isolateManaged = true;
118 } 120 }
119 121
120 v8::Isolate* isolate = m_isolate; 122 v8::Isolate* isolate = m_isolate;
121 v8::Isolate::Scope isolate_scope(isolate); 123 v8::Isolate::Scope isolate_scope(isolate);
122 v8::Locker locker(isolate); 124 v8::Locker locker(isolate);
123 v8::HandleScope handle_scope(isolate); 125 v8::HandleScope handle_scope(isolate);
124 if (CPDFXFA_App::GetInstance()->InitRuntime(FALSE)) { 126 if (CPDFXFA_App::GetInstance()->InitRuntime(FALSE)) {
125 CJS_Context* pContext = (CJS_Context*)NewContext(); 127 CJS_Context* pContext = (CJS_Context*)NewContext();
126 JS_InitialRuntime(*this, this, pContext, m_context); 128 JS_InitialRuntime(*this, this, pContext, m_context);
127 ReleaseContext(pContext); 129 ReleaseContext(pContext);
(...skipping 14 matching lines...) Expand all
142 144
143 m_ContextArray.RemoveAll(); 145 m_ContextArray.RemoveAll();
144 146
145 RemoveEventsInLoop(m_pFieldEventPath); 147 RemoveEventsInLoop(m_pFieldEventPath);
146 148
147 m_pApp = NULL; 149 m_pApp = NULL;
148 m_pDocument = NULL; 150 m_pDocument = NULL;
149 m_pFieldEventPath = NULL; 151 m_pFieldEventPath = NULL;
150 m_context.Reset(); 152 m_context.Reset();
151 153
154 if (m_isolateManaged)
155 m_isolate->Dispose();
152 m_isolate = NULL; 156 m_isolate = NULL;
153 } 157 }
154 158
155 FX_BOOL CJS_Runtime::InitJSObjects() { 159 FX_BOOL CJS_Runtime::InitJSObjects() {
156 v8::Isolate::Scope isolate_scope(GetIsolate()); 160 v8::Isolate::Scope isolate_scope(GetIsolate());
157 v8::Locker locker(GetIsolate()); 161 v8::Locker locker(GetIsolate());
158 v8::HandleScope handle_scope(GetIsolate()); 162 v8::HandleScope handle_scope(GetIsolate());
159 v8::Local<v8::Context> context = v8::Context::New(GetIsolate()); 163 v8::Local<v8::Context> context = v8::Context::New(GetIsolate());
160 v8::Context::Scope context_scope(context); 164 v8::Context::Scope context_scope(context);
161 // 0 - 8 165 // 0 - 8
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 // v8::Local<v8::Context>::New(GetIsolate(), m_context); 395 // v8::Local<v8::Context>::New(GetIsolate(), m_context);
392 v8::Local<v8::Value> propvalue = v8::Local<v8::Value>::New( 396 v8::Local<v8::Value> propvalue = v8::Local<v8::Value>::New(
393 GetIsolate(), ((CFXJSE_Value*)hValue)->DirectGetValue()); 397 GetIsolate(), ((CFXJSE_Value*)hValue)->DirectGetValue());
394 context->Global()->Set( 398 context->Global()->Set(
395 v8::String::NewFromUtf8(pIsolate, name, v8::String::kNormalString, 399 v8::String::NewFromUtf8(pIsolate, name, v8::String::kNormalString,
396 utf8Name.GetLength()), 400 utf8Name.GetLength()),
397 propvalue); 401 propvalue);
398 402
399 return TRUE; 403 return TRUE;
400 } 404 }
OLDNEW
« no previous file with comments | « fpdfsdk/include/javascript/JS_Runtime.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698