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

Side by Side Diff: fpdfsdk/javascript/cjs_runtime.cpp

Issue 2012253002: Remove FXJSE_HOBJECT and FXJSE_HVALUE for CFXJSE_Value* (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@fxjse_hclass
Patch Set: Created 4 years, 6 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/javascript/cjs_runtime.h ('k') | fpdfsdk/javascript/ijs_runtime.h » ('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 "fpdfsdk/javascript/cjs_runtime.h" 7 #include "fpdfsdk/javascript/cjs_runtime.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 v8::Local<v8::Array> CJS_Runtime::GetConstArray(const CFX_WideString& name) { 253 v8::Local<v8::Array> CJS_Runtime::GetConstArray(const CFX_WideString& name) {
254 return v8::Local<v8::Array>::New(m_isolate, m_ConstArrays[name]); 254 return v8::Local<v8::Array>::New(m_isolate, m_ConstArrays[name]);
255 } 255 }
256 256
257 #ifdef PDF_ENABLE_XFA 257 #ifdef PDF_ENABLE_XFA
258 CFX_WideString ChangeObjName(const CFX_WideString& str) { 258 CFX_WideString ChangeObjName(const CFX_WideString& str) {
259 CFX_WideString sRet = str; 259 CFX_WideString sRet = str;
260 sRet.Replace(L"_", L"."); 260 sRet.Replace(L"_", L".");
261 return sRet; 261 return sRet;
262 } 262 }
263 FX_BOOL CJS_Runtime::GetHValueByName(const CFX_ByteStringC& utf8Name, 263 FX_BOOL CJS_Runtime::GetValueByName(const CFX_ByteStringC& utf8Name,
264 FXJSE_HVALUE hValue) { 264 CFXJSE_Value* pValue) {
265 #ifdef PDF_ENABLE_XFA 265 #ifdef PDF_ENABLE_XFA
266 const FX_CHAR* name = utf8Name.c_str(); 266 const FX_CHAR* name = utf8Name.c_str();
267 267
268 v8::Locker lock(GetIsolate()); 268 v8::Locker lock(GetIsolate());
269 v8::Isolate::Scope isolate_scope(GetIsolate()); 269 v8::Isolate::Scope isolate_scope(GetIsolate());
270 v8::HandleScope handle_scope(GetIsolate()); 270 v8::HandleScope handle_scope(GetIsolate());
271 v8::Local<v8::Context> old_context = GetIsolate()->GetCurrentContext(); 271 v8::Local<v8::Context> old_context = GetIsolate()->GetCurrentContext();
272 v8::Local<v8::Context> context = 272 v8::Local<v8::Context> context =
273 v8::Local<v8::Context>::New(GetIsolate(), m_context); 273 v8::Local<v8::Context>::New(GetIsolate(), m_context);
274 v8::Context::Scope context_scope(context); 274 v8::Context::Scope context_scope(context);
275 275
276 // Caution: We're about to hand to XFA an object that in order to invoke 276 // Caution: We're about to hand to XFA an object that in order to invoke
277 // methods will require that the current v8::Context always has a pointer 277 // methods will require that the current v8::Context always has a pointer
278 // to a CJS_Runtime in its embedder data slot. Unfortunately, XFA creates 278 // to a CJS_Runtime in its embedder data slot. Unfortunately, XFA creates
279 // its own v8::Context which has not initialized the embedder data slot. 279 // its own v8::Context which has not initialized the embedder data slot.
280 // Do so now. 280 // Do so now.
281 // TODO(tsepez): redesign PDF-side objects to not rely on v8::Context's 281 // TODO(tsepez): redesign PDF-side objects to not rely on v8::Context's
282 // embedder data slots, and/or to always use the right context. 282 // embedder data slots, and/or to always use the right context.
283 FXJS_SetRuntimeForV8Context(old_context, this); 283 FXJS_SetRuntimeForV8Context(old_context, this);
284 284
285 v8::Local<v8::Value> propvalue = 285 v8::Local<v8::Value> propvalue =
286 context->Global()->Get(v8::String::NewFromUtf8( 286 context->Global()->Get(v8::String::NewFromUtf8(
287 GetIsolate(), name, v8::String::kNormalString, utf8Name.GetLength())); 287 GetIsolate(), name, v8::String::kNormalString, utf8Name.GetLength()));
288 288
289 if (propvalue.IsEmpty()) { 289 if (propvalue.IsEmpty()) {
290 FXJSE_Value_SetUndefined(hValue); 290 FXJSE_Value_SetUndefined(pValue);
291 return FALSE; 291 return FALSE;
292 } 292 }
293 ((CFXJSE_Value*)hValue)->ForceSetValue(propvalue); 293 pValue->ForceSetValue(propvalue);
294 #endif 294 #endif
295 295
296 return TRUE; 296 return TRUE;
297 } 297 }
298 FX_BOOL CJS_Runtime::SetHValueByName(const CFX_ByteStringC& utf8Name, 298 FX_BOOL CJS_Runtime::SetValueByName(const CFX_ByteStringC& utf8Name,
299 FXJSE_HVALUE hValue) { 299 CFXJSE_Value* pValue) {
300 #ifdef PDF_ENABLE_XFA 300 #ifdef PDF_ENABLE_XFA
301 if (utf8Name.IsEmpty() || hValue == NULL) 301 if (utf8Name.IsEmpty() || !pValue)
302 return FALSE; 302 return FALSE;
303 const FX_CHAR* name = utf8Name.c_str(); 303 const FX_CHAR* name = utf8Name.c_str();
304 v8::Isolate* pIsolate = GetIsolate(); 304 v8::Isolate* pIsolate = GetIsolate();
305 v8::Locker lock(pIsolate); 305 v8::Locker lock(pIsolate);
306 v8::Isolate::Scope isolate_scope(pIsolate); 306 v8::Isolate::Scope isolate_scope(pIsolate);
307 v8::HandleScope handle_scope(pIsolate); 307 v8::HandleScope handle_scope(pIsolate);
308 v8::Local<v8::Context> context = 308 v8::Local<v8::Context> context =
309 v8::Local<v8::Context>::New(pIsolate, m_context); 309 v8::Local<v8::Context>::New(pIsolate, m_context);
310 v8::Context::Scope context_scope(context); 310 v8::Context::Scope context_scope(context);
311 311
312 // v8::Local<v8::Context> tmpCotext = 312 // v8::Local<v8::Context> tmpCotext =
313 // v8::Local<v8::Context>::New(GetIsolate(), m_context); 313 // v8::Local<v8::Context>::New(GetIsolate(), m_context);
314 v8::Local<v8::Value> propvalue = v8::Local<v8::Value>::New( 314 v8::Local<v8::Value> propvalue =
315 GetIsolate(), ((CFXJSE_Value*)hValue)->DirectGetValue()); 315 v8::Local<v8::Value>::New(GetIsolate(), pValue->DirectGetValue());
316 context->Global()->Set( 316 context->Global()->Set(
317 v8::String::NewFromUtf8(pIsolate, name, v8::String::kNormalString, 317 v8::String::NewFromUtf8(pIsolate, name, v8::String::kNormalString,
318 utf8Name.GetLength()), 318 utf8Name.GetLength()),
319 propvalue); 319 propvalue);
320 #endif 320 #endif
321 return TRUE; 321 return TRUE;
322 } 322 }
323 323
324 #endif 324 #endif
325 void CJS_Runtime::AddObserver(Observer* observer) { 325 void CJS_Runtime::AddObserver(Observer* observer) {
326 ASSERT(!pdfium::ContainsKey(m_observers, observer)); 326 ASSERT(!pdfium::ContainsKey(m_observers, observer));
327 m_observers.insert(observer); 327 m_observers.insert(observer);
328 } 328 }
329 329
330 void CJS_Runtime::RemoveObserver(Observer* observer) { 330 void CJS_Runtime::RemoveObserver(Observer* observer) {
331 ASSERT(pdfium::ContainsKey(m_observers, observer)); 331 ASSERT(pdfium::ContainsKey(m_observers, observer));
332 m_observers.erase(observer); 332 m_observers.erase(observer);
333 } 333 }
OLDNEW
« no previous file with comments | « fpdfsdk/javascript/cjs_runtime.h ('k') | fpdfsdk/javascript/ijs_runtime.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698