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

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

Issue 1389163007: Pass IJS_Runtime, not IJS_Context, to native object constructors. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: comment Created 5 years, 2 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
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 "JS_Runtime.h" 7 #include "JS_Runtime.h"
8 8
9 #include "../../include/fsdk_mgr.h" // For CPDFDoc_Environment. 9 #include "../../include/fsdk_mgr.h" // For CPDFDoc_Environment.
10 #include "../../include/javascript/IJavaScript.h" 10 #include "../../include/javascript/IJavaScript.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 pExternalIsolate = reinterpret_cast<v8::Isolate*>(pPlatform->m_isolate); 54 pExternalIsolate = reinterpret_cast<v8::Isolate*>(pPlatform->m_isolate);
55 embedderDataSlot = pPlatform->m_v8EmbedderSlot; 55 embedderDataSlot = pPlatform->m_v8EmbedderSlot;
56 } 56 }
57 FXJS_Initialize(embedderDataSlot, pExternalIsolate); 57 FXJS_Initialize(embedderDataSlot, pExternalIsolate);
58 } 58 }
59 m_isolateManaged = FXJS_GetIsolate(&m_isolate); 59 m_isolateManaged = FXJS_GetIsolate(&m_isolate);
60 if (m_isolateManaged || FXJS_GlobalIsolateRefCount() == 0) 60 if (m_isolateManaged || FXJS_GlobalIsolateRefCount() == 0)
61 DefineJSObjects(); 61 DefineJSObjects();
62 62
63 CJS_Context* pContext = (CJS_Context*)NewContext(); 63 CJS_Context* pContext = (CJS_Context*)NewContext();
64 FXJS_InitializeRuntime(GetIsolate(), this, pContext, m_context); 64 FXJS_InitializeRuntime(GetIsolate(), this, m_context);
65 ReleaseContext(pContext); 65 ReleaseContext(pContext);
66 } 66 }
67 67
68 CJS_Runtime::~CJS_Runtime() { 68 CJS_Runtime::~CJS_Runtime() {
69 for (auto* obs : m_observers) 69 for (auto* obs : m_observers)
70 obs->OnDestroyed(); 70 obs->OnDestroyed();
71 71
72 for (int i = 0, sz = m_ContextArray.GetSize(); i < sz; i++) 72 for (int i = 0, sz = m_ContextArray.GetSize(); i < sz; i++)
73 delete m_ContextArray.GetAt(i); 73 delete m_ContextArray.GetAt(i);
74 74
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 (CJS_Document*)FXJS_GetPrivate(GetIsolate(), pThis)) { 171 (CJS_Document*)FXJS_GetPrivate(GetIsolate(), pThis)) {
172 if (Document* pDocument = (Document*)pJSDocument->GetEmbedObject()) 172 if (Document* pDocument = (Document*)pJSDocument->GetEmbedObject())
173 pDocument->AttachDoc(pReaderDoc); 173 pDocument->AttachDoc(pReaderDoc);
174 } 174 }
175 } 175 }
176 } 176 }
177 } 177 }
178 } 178 }
179 } 179 }
180 180
181 int CJS_Runtime::Execute(IJS_Context* cc,
182 const wchar_t* script,
183 long length,
184 CFX_WideString& info) {
185 FXJSErr error = {};
186 int nRet = FXJS_Execute(m_isolate, cc, script, length, &error);
Lei Zhang 2015/10/08 23:52:01 FXJS_Execute() doesn't even use the length argumen
Tom Sepez 2015/10/09 00:14:20 Done.
187 if (nRet < 0) {
188 info.Format(L"[ Line: %05d { %s } ] : %s", error.linnum - 1, error.srcline,
189 error.message);
190 }
191 return nRet;
192 }
193
181 bool CJS_Runtime::AddEventToSet(const FieldEvent& event) { 194 bool CJS_Runtime::AddEventToSet(const FieldEvent& event) {
182 return m_FieldEventSet.insert(event).second; 195 return m_FieldEventSet.insert(event).second;
183 } 196 }
184 197
185 void CJS_Runtime::RemoveEventFromSet(const FieldEvent& event) { 198 void CJS_Runtime::RemoveEventFromSet(const FieldEvent& event) {
186 m_FieldEventSet.erase(event); 199 m_FieldEventSet.erase(event);
187 } 200 }
188 201
189 v8::Local<v8::Context> CJS_Runtime::NewJSContext() { 202 v8::Local<v8::Context> CJS_Runtime::NewJSContext() {
190 return v8::Local<v8::Context>::New(m_isolate, m_context); 203 return v8::Local<v8::Context>::New(m_isolate, m_context);
191 } 204 }
192 205
193 void CJS_Runtime::AddObserver(Observer* observer) { 206 void CJS_Runtime::AddObserver(Observer* observer) {
194 ASSERT(m_observers.find(observer) == m_observers.end()); 207 ASSERT(m_observers.find(observer) == m_observers.end());
195 m_observers.insert(observer); 208 m_observers.insert(observer);
196 } 209 }
197 210
198 void CJS_Runtime::RemoveObserver(Observer* observer) { 211 void CJS_Runtime::RemoveObserver(Observer* observer) {
199 ASSERT(m_observers.find(observer) != m_observers.end()); 212 ASSERT(m_observers.find(observer) != m_observers.end());
200 m_observers.erase(observer); 213 m_observers.erase(observer);
201 } 214 }
202 215
203 CFX_WideString ChangeObjName(const CFX_WideString& str) { 216 CFX_WideString ChangeObjName(const CFX_WideString& str) {
204 CFX_WideString sRet = str; 217 CFX_WideString sRet = str;
205 sRet.Replace(L"_", L"."); 218 sRet.Replace(L"_", L".");
206 return sRet; 219 return sRet;
207 } 220 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698