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

Side by Side Diff: fpdfsdk/javascript/JS_Define.h

Issue 1861183002: Make CFX_WideString::FromUTF8() take a CFX_ByteStringC argument. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Rebase, combine delcs with initialization. Created 4 years, 8 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/Document.cpp ('k') | fpdfsdk/jsapi/fxjs_v8.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 #ifndef FPDFSDK_JAVASCRIPT_JS_DEFINE_H_ 7 #ifndef FPDFSDK_JAVASCRIPT_JS_DEFINE_H_
8 #define FPDFSDK_JAVASCRIPT_JS_DEFINE_H_ 8 #define FPDFSDK_JAVASCRIPT_JS_DEFINE_H_
9 9
10 #include <vector> 10 #include <vector>
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 js_class_name::getprop_static, js_class_name::putprop_static, \ 347 js_class_name::getprop_static, js_class_name::putprop_static, \
348 js_class_name::delprop_static); \ 348 js_class_name::delprop_static); \
349 } 349 }
350 350
351 template <class Alt> 351 template <class Alt>
352 void JSSpecialPropQuery(const char*, 352 void JSSpecialPropQuery(const char*,
353 v8::Local<v8::String> property, 353 v8::Local<v8::String> property,
354 const v8::PropertyCallbackInfo<v8::Integer>& info) { 354 const v8::PropertyCallbackInfo<v8::Integer>& info) {
355 v8::Isolate* isolate = info.GetIsolate(); 355 v8::Isolate* isolate = info.GetIsolate();
356 v8::String::Utf8Value utf8_value(property); 356 v8::String::Utf8Value utf8_value(property);
357 CFX_WideString propname = 357 CFX_WideString propname = CFX_WideString::FromUTF8(
358 CFX_WideString::FromUTF8(*utf8_value, utf8_value.length()); 358 CFX_ByteStringC(*utf8_value, utf8_value.length()));
359 CJS_Object* pJSObj = 359 CJS_Object* pJSObj =
360 reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder())); 360 reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder()));
361 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); 361 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject());
362 FX_BOOL bRet = pObj->QueryProperty(propname.c_str()); 362 FX_BOOL bRet = pObj->QueryProperty(propname.c_str());
363 info.GetReturnValue().Set(bRet ? 4 : 0); 363 info.GetReturnValue().Set(bRet ? 4 : 0);
364 } 364 }
365 365
366 template <class Alt> 366 template <class Alt>
367 void JSSpecialPropGet(const char* class_name, 367 void JSSpecialPropGet(const char* class_name,
368 v8::Local<v8::String> property, 368 v8::Local<v8::String> property,
369 const v8::PropertyCallbackInfo<v8::Value>& info) { 369 const v8::PropertyCallbackInfo<v8::Value>& info) {
370 v8::Isolate* isolate = info.GetIsolate(); 370 v8::Isolate* isolate = info.GetIsolate();
371 CJS_Runtime* pRuntime = 371 CJS_Runtime* pRuntime =
372 static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(isolate)); 372 static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(isolate));
373 if (!pRuntime) 373 if (!pRuntime)
374 return; 374 return;
375 IJS_Context* pContext = pRuntime->GetCurrentContext(); 375 IJS_Context* pContext = pRuntime->GetCurrentContext();
376 CJS_Object* pJSObj = 376 CJS_Object* pJSObj =
377 reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder())); 377 reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder()));
378 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); 378 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject());
379 v8::String::Utf8Value utf8_value(property); 379 v8::String::Utf8Value utf8_value(property);
380 CFX_WideString propname = 380 CFX_WideString propname = CFX_WideString::FromUTF8(
381 CFX_WideString::FromUTF8(*utf8_value, utf8_value.length()); 381 CFX_ByteStringC(*utf8_value, utf8_value.length()));
382 CFX_WideString sError; 382 CFX_WideString sError;
383 CJS_PropValue value(pRuntime); 383 CJS_PropValue value(pRuntime);
384 value.StartGetting(); 384 value.StartGetting();
385 if (!pObj->DoProperty(pContext, propname.c_str(), value, sError)) { 385 if (!pObj->DoProperty(pContext, propname.c_str(), value, sError)) {
386 FXJS_Error(isolate, JSFormatErrorString(class_name, "GetProperty", sError)); 386 FXJS_Error(isolate, JSFormatErrorString(class_name, "GetProperty", sError));
387 return; 387 return;
388 } 388 }
389 info.GetReturnValue().Set((v8::Local<v8::Value>)value); 389 info.GetReturnValue().Set((v8::Local<v8::Value>)value);
390 } 390 }
391 391
392 template <class Alt> 392 template <class Alt>
393 void JSSpecialPropPut(const char* class_name, 393 void JSSpecialPropPut(const char* class_name,
394 v8::Local<v8::String> property, 394 v8::Local<v8::String> property,
395 v8::Local<v8::Value> value, 395 v8::Local<v8::Value> value,
396 const v8::PropertyCallbackInfo<v8::Value>& info) { 396 const v8::PropertyCallbackInfo<v8::Value>& info) {
397 v8::Isolate* isolate = info.GetIsolate(); 397 v8::Isolate* isolate = info.GetIsolate();
398 CJS_Runtime* pRuntime = 398 CJS_Runtime* pRuntime =
399 static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(isolate)); 399 static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(isolate));
400 if (!pRuntime) 400 if (!pRuntime)
401 return; 401 return;
402 IJS_Context* pContext = pRuntime->GetCurrentContext(); 402 IJS_Context* pContext = pRuntime->GetCurrentContext();
403 CJS_Object* pJSObj = 403 CJS_Object* pJSObj =
404 reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder())); 404 reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder()));
405 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); 405 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject());
406 v8::String::Utf8Value utf8_value(property); 406 v8::String::Utf8Value utf8_value(property);
407 CFX_WideString propname = 407 CFX_WideString propname = CFX_WideString::FromUTF8(
408 CFX_WideString::FromUTF8(*utf8_value, utf8_value.length()); 408 CFX_ByteStringC(*utf8_value, utf8_value.length()));
409 CFX_WideString sError; 409 CFX_WideString sError;
410 CJS_PropValue PropValue(CJS_Value(pRuntime, value, CJS_Value::VT_unknown)); 410 CJS_PropValue PropValue(CJS_Value(pRuntime, value, CJS_Value::VT_unknown));
411 PropValue.StartSetting(); 411 PropValue.StartSetting();
412 if (!pObj->DoProperty(pContext, propname.c_str(), PropValue, sError)) { 412 if (!pObj->DoProperty(pContext, propname.c_str(), PropValue, sError)) {
413 FXJS_Error(isolate, JSFormatErrorString(class_name, "PutProperty", sError)); 413 FXJS_Error(isolate, JSFormatErrorString(class_name, "PutProperty", sError));
414 } 414 }
415 } 415 }
416 416
417 template <class Alt> 417 template <class Alt>
418 void JSSpecialPropDel(const char* class_name, 418 void JSSpecialPropDel(const char* class_name,
419 v8::Local<v8::String> property, 419 v8::Local<v8::String> property,
420 const v8::PropertyCallbackInfo<v8::Boolean>& info) { 420 const v8::PropertyCallbackInfo<v8::Boolean>& info) {
421 v8::Isolate* isolate = info.GetIsolate(); 421 v8::Isolate* isolate = info.GetIsolate();
422 IJS_Runtime* pRuntime = FXJS_GetRuntimeFromIsolate(isolate); 422 IJS_Runtime* pRuntime = FXJS_GetRuntimeFromIsolate(isolate);
423 if (!pRuntime) 423 if (!pRuntime)
424 return; 424 return;
425 IJS_Context* pContext = pRuntime->GetCurrentContext(); 425 IJS_Context* pContext = pRuntime->GetCurrentContext();
426 CJS_Object* pJSObj = 426 CJS_Object* pJSObj =
427 reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder())); 427 reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder()));
428 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); 428 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject());
429 v8::String::Utf8Value utf8_value(property); 429 v8::String::Utf8Value utf8_value(property);
430 CFX_WideString propname = 430 CFX_WideString propname = CFX_WideString::FromUTF8(
431 CFX_WideString::FromUTF8(*utf8_value, utf8_value.length()); 431 CFX_ByteStringC(*utf8_value, utf8_value.length()));
432 CFX_WideString sError; 432 CFX_WideString sError;
433 if (!pObj->DelProperty(pContext, propname.c_str(), sError)) { 433 if (!pObj->DelProperty(pContext, propname.c_str(), sError)) {
434 CFX_ByteString cbName; 434 CFX_ByteString cbName;
435 cbName.Format("%s.%s", class_name, "DelProperty"); 435 cbName.Format("%s.%s", class_name, "DelProperty");
436 // Probably a missing call to JSFX_Error(). 436 // Probably a missing call to JSFX_Error().
437 } 437 }
438 } 438 }
439 439
440 template <FX_BOOL (*F)(IJS_Context*, 440 template <FX_BOOL (*F)(IJS_Context*,
441 const std::vector<CJS_Value>&, 441 const std::vector<CJS_Value>&,
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 for (size_t i = 0; i < FX_ArraySize(global_methods) - 1; ++i) { \ 484 for (size_t i = 0; i < FX_ArraySize(global_methods) - 1; ++i) { \
485 FXJS_DefineGlobalMethod(pIsolate, \ 485 FXJS_DefineGlobalMethod(pIsolate, \
486 js_class_name::global_methods[i].pName, \ 486 js_class_name::global_methods[i].pName, \
487 js_class_name::global_methods[i].pMethodCall); \ 487 js_class_name::global_methods[i].pMethodCall); \
488 } \ 488 } \
489 } 489 }
490 490
491 CJS_Value::Type GET_VALUE_TYPE(v8::Local<v8::Value> p); 491 CJS_Value::Type GET_VALUE_TYPE(v8::Local<v8::Value> p);
492 492
493 #endif // FPDFSDK_JAVASCRIPT_JS_DEFINE_H_ 493 #endif // FPDFSDK_JAVASCRIPT_JS_DEFINE_H_
OLDNEW
« no previous file with comments | « fpdfsdk/javascript/Document.cpp ('k') | fpdfsdk/jsapi/fxjs_v8.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698