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

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

Issue 1332973002: Remove some abstractions in fxjs_v8.h. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Remove implicit cast operator from CJS_Runtime. Created 5 years, 3 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/src/javascript/JS_Object.cpp ('k') | fpdfsdk/src/javascript/JS_Value.cpp » ('j') | 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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 109
110 v8::Isolate::CreateParams params; 110 v8::Isolate::CreateParams params;
111 params.array_buffer_allocator = m_pArrayBufferAllocator.get(); 111 params.array_buffer_allocator = m_pArrayBufferAllocator.get();
112 m_isolate = v8::Isolate::New(params); 112 m_isolate = v8::Isolate::New(params);
113 m_isolateManaged = true; 113 m_isolateManaged = true;
114 } 114 }
115 115
116 InitJSObjects(); 116 InitJSObjects();
117 117
118 CJS_Context* pContext = (CJS_Context*)NewContext(); 118 CJS_Context* pContext = (CJS_Context*)NewContext();
119 JS_InitialRuntime(*this, this, pContext, m_context); 119 JS_InitialRuntime(GetIsolate(), this, pContext, m_context);
120 ReleaseContext(pContext); 120 ReleaseContext(pContext);
121 } 121 }
122 122
123 CJS_Runtime::~CJS_Runtime() { 123 CJS_Runtime::~CJS_Runtime() {
124 for (int i = 0, sz = m_ContextArray.GetSize(); i < sz; i++) 124 for (int i = 0, sz = m_ContextArray.GetSize(); i < sz; i++)
125 delete m_ContextArray.GetAt(i); 125 delete m_ContextArray.GetAt(i);
126 126
127 m_ContextArray.RemoveAll(); 127 m_ContextArray.RemoveAll();
128 128 JS_ReleaseRuntime(GetIsolate(), m_context);
129 JS_ReleaseRuntime(*this, m_context);
130
131 RemoveEventsInLoop(m_pFieldEventPath); 129 RemoveEventsInLoop(m_pFieldEventPath);
132 130
133 m_pApp = NULL; 131 m_pApp = NULL;
134 m_pDocument = NULL; 132 m_pDocument = NULL;
135 m_pFieldEventPath = NULL; 133 m_pFieldEventPath = NULL;
136 m_context.Reset(); 134 m_context.Reset();
137 135
138 if (m_isolateManaged) 136 if (m_isolateManaged)
139 m_isolate->Dispose(); 137 m_isolate->Dispose();
140 } 138 }
141 139
142 FX_BOOL CJS_Runtime::InitJSObjects() { 140 FX_BOOL CJS_Runtime::InitJSObjects() {
143 v8::Isolate::Scope isolate_scope(GetIsolate()); 141 v8::Isolate::Scope isolate_scope(GetIsolate());
144 v8::HandleScope handle_scope(GetIsolate()); 142 v8::HandleScope handle_scope(GetIsolate());
145 v8::Local<v8::Context> context = v8::Context::New(GetIsolate()); 143 v8::Local<v8::Context> context = v8::Context::New(GetIsolate());
146 v8::Context::Scope context_scope(context); 144 v8::Context::Scope context_scope(context);
147 // 0 - 8 145 // 0 - 8
148 if (CJS_Border::Init(*this, JS_STATIC) < 0) 146 if (CJS_Border::Init(GetIsolate(), JS_STATIC) < 0)
149 return FALSE; 147 return FALSE;
150 if (CJS_Display::Init(*this, JS_STATIC) < 0) 148 if (CJS_Display::Init(GetIsolate(), JS_STATIC) < 0)
151 return FALSE; 149 return FALSE;
152 if (CJS_Font::Init(*this, JS_STATIC) < 0) 150 if (CJS_Font::Init(GetIsolate(), JS_STATIC) < 0)
153 return FALSE; 151 return FALSE;
154 if (CJS_Highlight::Init(*this, JS_STATIC) < 0) 152 if (CJS_Highlight::Init(GetIsolate(), JS_STATIC) < 0)
155 return FALSE; 153 return FALSE;
156 if (CJS_Position::Init(*this, JS_STATIC) < 0) 154 if (CJS_Position::Init(GetIsolate(), JS_STATIC) < 0)
157 return FALSE; 155 return FALSE;
158 if (CJS_ScaleHow::Init(*this, JS_STATIC) < 0) 156 if (CJS_ScaleHow::Init(GetIsolate(), JS_STATIC) < 0)
159 return FALSE; 157 return FALSE;
160 if (CJS_ScaleWhen::Init(*this, JS_STATIC) < 0) 158 if (CJS_ScaleWhen::Init(GetIsolate(), JS_STATIC) < 0)
161 return FALSE; 159 return FALSE;
162 if (CJS_Style::Init(*this, JS_STATIC) < 0) 160 if (CJS_Style::Init(GetIsolate(), JS_STATIC) < 0)
163 return FALSE; 161 return FALSE;
164 if (CJS_Zoomtype::Init(*this, JS_STATIC) < 0) 162 if (CJS_Zoomtype::Init(GetIsolate(), JS_STATIC) < 0)
165 return FALSE; 163 return FALSE;
166 164
167 // 9 - 11 165 // 9 - 11
168 if (CJS_App::Init(*this, JS_STATIC) < 0) 166 if (CJS_App::Init(GetIsolate(), JS_STATIC) < 0)
169 return FALSE; 167 return FALSE;
170 if (CJS_Color::Init(*this, JS_STATIC) < 0) 168 if (CJS_Color::Init(GetIsolate(), JS_STATIC) < 0)
171 return FALSE; 169 return FALSE;
172 if (CJS_Console::Init(*this, JS_STATIC) < 0) 170 if (CJS_Console::Init(GetIsolate(), JS_STATIC) < 0)
173 return FALSE; 171 return FALSE;
174 172
175 // 12 - 14 173 // 12 - 14
176 if (CJS_Document::Init(*this, JS_DYNAMIC) < 0) 174 if (CJS_Document::Init(GetIsolate(), JS_DYNAMIC) < 0)
177 return FALSE; 175 return FALSE;
178 if (CJS_Event::Init(*this, JS_STATIC) < 0) 176 if (CJS_Event::Init(GetIsolate(), JS_STATIC) < 0)
179 return FALSE; 177 return FALSE;
180 if (CJS_Field::Init(*this, JS_DYNAMIC) < 0) 178 if (CJS_Field::Init(GetIsolate(), JS_DYNAMIC) < 0)
181 return FALSE; 179 return FALSE;
182 180
183 // 15 - 17 181 // 15 - 17
184 if (CJS_Global::Init(*this, JS_STATIC) < 0) 182 if (CJS_Global::Init(GetIsolate(), JS_STATIC) < 0)
185 return FALSE; 183 return FALSE;
186 if (CJS_Icon::Init(*this, JS_DYNAMIC) < 0) 184 if (CJS_Icon::Init(GetIsolate(), JS_DYNAMIC) < 0)
187 return FALSE; 185 return FALSE;
188 if (CJS_Util::Init(*this, JS_STATIC) < 0) 186 if (CJS_Util::Init(GetIsolate(), JS_STATIC) < 0)
189 return FALSE; 187 return FALSE;
190 188
191 if (CJS_PublicMethods::Init(*this) < 0) 189 if (CJS_PublicMethods::Init(GetIsolate()) < 0)
192 return FALSE; 190 return FALSE;
193 if (CJS_GlobalConsts::Init(*this) < 0) 191 if (CJS_GlobalConsts::Init(GetIsolate()) < 0)
194 return FALSE; 192 return FALSE;
195 if (CJS_GlobalArrays::Init(*this) < 0) 193 if (CJS_GlobalArrays::Init(GetIsolate()) < 0)
196 return FALSE; 194 return FALSE;
197 195
198 if (CJS_TimerObj::Init(*this, JS_DYNAMIC) < 0) 196 if (CJS_TimerObj::Init(GetIsolate(), JS_DYNAMIC) < 0)
199 return FALSE; 197 return FALSE;
200 if (CJS_PrintParamsObj::Init(*this, JS_DYNAMIC) < 0) 198 if (CJS_PrintParamsObj::Init(GetIsolate(), JS_DYNAMIC) < 0)
201 return FALSE; 199 return FALSE;
202 200
203 return TRUE; 201 return TRUE;
204 } 202 }
205 203
206 IFXJS_Context* CJS_Runtime::NewContext() { 204 IFXJS_Context* CJS_Runtime::NewContext() {
207 CJS_Context* p = new CJS_Context(this); 205 CJS_Context* p = new CJS_Context(this);
208 m_ContextArray.Add(p); 206 m_ContextArray.Add(p);
209 return p; 207 return p;
210 } 208 }
(...skipping 18 matching lines...) Expand all
229 227
230 void CJS_Runtime::SetReaderDocument(CPDFSDK_Document* pReaderDoc) { 228 void CJS_Runtime::SetReaderDocument(CPDFSDK_Document* pReaderDoc) {
231 if (m_pDocument != pReaderDoc) { 229 if (m_pDocument != pReaderDoc) {
232 v8::Isolate::Scope isolate_scope(m_isolate); 230 v8::Isolate::Scope isolate_scope(m_isolate);
233 v8::HandleScope handle_scope(m_isolate); 231 v8::HandleScope handle_scope(m_isolate);
234 v8::Local<v8::Context> context = 232 v8::Local<v8::Context> context =
235 v8::Local<v8::Context>::New(m_isolate, m_context); 233 v8::Local<v8::Context>::New(m_isolate, m_context);
236 v8::Context::Scope context_scope(context); 234 v8::Context::Scope context_scope(context);
237 235
238 m_pDocument = pReaderDoc; 236 m_pDocument = pReaderDoc;
239
240 if (pReaderDoc) { 237 if (pReaderDoc) {
241 JSObject pThis = JS_GetThisObj(*this); 238 v8::Local<v8::Object> pThis = JS_GetThisObj(GetIsolate());
242 if (!pThis.IsEmpty()) { 239 if (!pThis.IsEmpty()) {
243 if (JS_GetObjDefnID(pThis) == JS_GetObjDefnID(*this, L"Document")) { 240 if (JS_GetObjDefnID(pThis) ==
241 JS_GetObjDefnID(GetIsolate(), L"Document")) {
244 if (CJS_Document* pJSDocument = (CJS_Document*)JS_GetPrivate(pThis)) { 242 if (CJS_Document* pJSDocument = (CJS_Document*)JS_GetPrivate(pThis)) {
245 if (Document* pDocument = (Document*)pJSDocument->GetEmbedObject()) 243 if (Document* pDocument = (Document*)pJSDocument->GetEmbedObject())
246 pDocument->AttachDoc(pReaderDoc); 244 pDocument->AttachDoc(pReaderDoc);
247 } 245 }
248 } 246 }
249 } 247 }
250 JS_SetThisObj(*this, JS_GetObjDefnID(*this, L"Document"));
251 } else {
252 JS_SetThisObj(*this, JS_GetObjDefnID(*this, L"app"));
253 } 248 }
254 } 249 }
255 } 250 }
256 251
257 FX_BOOL CJS_Runtime::AddEventToLoop(const CFX_WideString& sTargetName, 252 FX_BOOL CJS_Runtime::AddEventToLoop(const CFX_WideString& sTargetName,
258 JS_EVENT_T eEventType) { 253 JS_EVENT_T eEventType) {
259 if (m_pFieldEventPath == NULL) { 254 if (m_pFieldEventPath == NULL) {
260 m_pFieldEventPath = new CJS_FieldEvent; 255 m_pFieldEventPath = new CJS_FieldEvent;
261 m_pFieldEventPath->sTargetName = sTargetName; 256 m_pFieldEventPath->sTargetName = sTargetName;
262 m_pFieldEventPath->eEventType = eEventType; 257 m_pFieldEventPath->eEventType = eEventType;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 322
328 v8::Local<v8::Context> CJS_Runtime::NewJSContext() { 323 v8::Local<v8::Context> CJS_Runtime::NewJSContext() {
329 return v8::Local<v8::Context>::New(m_isolate, m_context); 324 return v8::Local<v8::Context>::New(m_isolate, m_context);
330 } 325 }
331 326
332 CFX_WideString ChangeObjName(const CFX_WideString& str) { 327 CFX_WideString ChangeObjName(const CFX_WideString& str) {
333 CFX_WideString sRet = str; 328 CFX_WideString sRet = str;
334 sRet.Replace(L"_", L"."); 329 sRet.Replace(L"_", L".");
335 return sRet; 330 return sRet;
336 } 331 }
OLDNEW
« no previous file with comments | « fpdfsdk/src/javascript/JS_Object.cpp ('k') | fpdfsdk/src/javascript/JS_Value.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698