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

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

Issue 1252613002: FX_BOOL considered harmful. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Manual edits. Created 5 years, 5 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_Context.h ('k') | fpdfsdk/include/javascript/JS_EventHandler.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 #ifndef FPDFSDK_INCLUDE_JAVASCRIPT_JS_DEFINE_H_ 7 #ifndef FPDFSDK_INCLUDE_JAVASCRIPT_JS_DEFINE_H_
8 #define FPDFSDK_INCLUDE_JAVASCRIPT_JS_DEFINE_H_ 8 #define FPDFSDK_INCLUDE_JAVASCRIPT_JS_DEFINE_H_
9 9
10 #include "../jsapi/fxjs_v8.h" 10 #include "../jsapi/fxjs_v8.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 #define BEGIN_JS_STATIC_PROP(js_class_name) JSPropertySpec js_class_name::JS_Cla ss_Properties[] = { 44 #define BEGIN_JS_STATIC_PROP(js_class_name) JSPropertySpec js_class_name::JS_Cla ss_Properties[] = {
45 #define JS_STATIC_PROP_ENTRY(prop_name) {JS_WIDESTRING(prop_name), get_##prop_na me##_static, set_##prop_name##_static}, 45 #define JS_STATIC_PROP_ENTRY(prop_name) {JS_WIDESTRING(prop_name), get_##prop_na me##_static, set_##prop_name##_static},
46 #define END_JS_STATIC_PROP() {0, 0, 0}}; 46 #define END_JS_STATIC_PROP() {0, 0, 0}};
47 47
48 #define BEGIN_JS_STATIC_METHOD(js_class_name) JSMethodSpec js_class_name::JS_Cla ss_Methods[] = { 48 #define BEGIN_JS_STATIC_METHOD(js_class_name) JSMethodSpec js_class_name::JS_Cla ss_Methods[] = {
49 #define JS_STATIC_METHOD_ENTRY(method_name) {JS_WIDESTRING(method_name), method_ name##_static}, 49 #define JS_STATIC_METHOD_ENTRY(method_name) {JS_WIDESTRING(method_name), method_ name##_static},
50 #define END_JS_STATIC_METHOD() {0, 0}}; 50 #define END_JS_STATIC_METHOD() {0, 0}};
51 51
52 /* ======================================== PROP CALLBACK ====================== ====================== */ 52 /* ======================================== PROP CALLBACK ====================== ====================== */
53 53
54 template <class C, FX_BOOL (C::*M)(IFXJS_Context* cc, CJS_PropValue& vp, CFX_Wid eString& sError)> 54 template <class C, bool (C::*M)(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideSt ring& sError)>
55 void JSPropGetter(const char* prop_name_string, 55 void JSPropGetter(const char* prop_name_string,
56 const char* class_name_string, 56 const char* class_name_string,
57 v8::Local<v8::String> property, 57 v8::Local<v8::String> property,
58 const v8::PropertyCallbackInfo<v8::Value>& info) { 58 const v8::PropertyCallbackInfo<v8::Value>& info) {
59 v8::Isolate* isolate = info.GetIsolate(); 59 v8::Isolate* isolate = info.GetIsolate();
60 v8::Local<v8::Context> context = isolate->GetCurrentContext(); 60 v8::Local<v8::Context> context = isolate->GetCurrentContext();
61 v8::Local<v8::Value> v = context->GetEmbedderData(1); 61 v8::Local<v8::Value> v = context->GetEmbedderData(1);
62 v8::Local<v8::External> field = v8::Local<v8::External>::Cast(v); 62 v8::Local<v8::External> field = v8::Local<v8::External>::Cast(v);
63 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); 63 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value();
64 IFXJS_Context* pContext = pRuntime->GetCurrentContext(); 64 IFXJS_Context* pContext = pRuntime->GetCurrentContext();
65 CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder()); 65 CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder());
66 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); 66 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject());
67 CFX_WideString sError; 67 CFX_WideString sError;
68 CJS_PropValue value(isolate); 68 CJS_PropValue value(isolate);
69 value.StartGetting(); 69 value.StartGetting();
70 if (!(pObj->*M)(pContext, value, sError)) { 70 if (!(pObj->*M)(pContext, value, sError)) {
71 JS_Error(isolate, JSFormatErrorString(class_name_string, prop_name_string, s Error)); 71 JS_Error(isolate, JSFormatErrorString(class_name_string, prop_name_string, s Error));
72 return; 72 return;
73 } 73 }
74 info.GetReturnValue().Set((v8::Local<v8::Value>)value); 74 info.GetReturnValue().Set((v8::Local<v8::Value>)value);
75 } 75 }
76 76
77 template <class C, FX_BOOL (C::*M)(IFXJS_Context* cc, CJS_PropValue& vp, CFX_Wid eString& sError)> 77 template <class C, bool (C::*M)(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideSt ring& sError)>
78 void JSPropSetter(const char* prop_name_string, 78 void JSPropSetter(const char* prop_name_string,
79 const char* class_name_string, 79 const char* class_name_string,
80 v8::Local<v8::String> property, 80 v8::Local<v8::String> property,
81 v8::Local<v8::Value> value, 81 v8::Local<v8::Value> value,
82 const v8::PropertyCallbackInfo<void>& info) { 82 const v8::PropertyCallbackInfo<void>& info) {
83 v8::Isolate* isolate = info.GetIsolate(); 83 v8::Isolate* isolate = info.GetIsolate();
84 v8::Local<v8::Context> context = isolate->GetCurrentContext(); 84 v8::Local<v8::Context> context = isolate->GetCurrentContext();
85 v8::Local<v8::Value> v = context->GetEmbedderData(1); 85 v8::Local<v8::Value> v = context->GetEmbedderData(1);
86 v8::Local<v8::External> field = v8::Local<v8::External>::Cast(v); 86 v8::Local<v8::External> field = v8::Local<v8::External>::Cast(v);
87 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); 87 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value();
(...skipping 18 matching lines...) Expand all
106 static void set_##prop_name##_static( \ 106 static void set_##prop_name##_static( \
107 v8::Local<v8::String> property, \ 107 v8::Local<v8::String> property, \
108 v8::Local<v8::Value> value, \ 108 v8::Local<v8::Value> value, \
109 const v8::PropertyCallbackInfo<void>& info) { \ 109 const v8::PropertyCallbackInfo<void>& info) { \
110 JSPropSetter<class_name, &class_name::prop_name>( \ 110 JSPropSetter<class_name, &class_name::prop_name>( \
111 #prop_name, #class_name, property, value, info); \ 111 #prop_name, #class_name, property, value, info); \
112 } 112 }
113 113
114 /* ========================================= METHOD CALLBACK =================== ======================== */ 114 /* ========================================= METHOD CALLBACK =================== ======================== */
115 115
116 template <class C, FX_BOOL (C::*M)(IFXJS_Context* cc, const CJS_Parameters& para ms, CJS_Value& vRet, CFX_WideString& sError)> 116 template <class C, bool (C::*M)(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)>
117 void JSMethod(const char* method_name_string, 117 void JSMethod(const char* method_name_string,
118 const char* class_name_string, 118 const char* class_name_string,
119 const v8::FunctionCallbackInfo<v8::Value>& info) { 119 const v8::FunctionCallbackInfo<v8::Value>& info) {
120 v8::Isolate* isolate = info.GetIsolate(); 120 v8::Isolate* isolate = info.GetIsolate();
121 v8::Local<v8::Context> context = isolate->GetCurrentContext(); 121 v8::Local<v8::Context> context = isolate->GetCurrentContext();
122 v8::Local<v8::Value> v = context->GetEmbedderData(1); 122 v8::Local<v8::Value> v = context->GetEmbedderData(1);
123 v8::Local<v8::External> field = v8::Local<v8::External>::Cast(v); 123 v8::Local<v8::External> field = v8::Local<v8::External>::Cast(v);
124 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); 124 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value();
125 IFXJS_Context* cc = pRuntime->GetCurrentContext(); 125 IFXJS_Context* cc = pRuntime->GetCurrentContext();
126 CJS_Parameters parameters; 126 CJS_Parameters parameters;
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 233
234 /* ===================================== SPECIAL JS CLASS ====================== ========================= */ 234 /* ===================================== SPECIAL JS CLASS ====================== ========================= */
235 235
236 template <class Alt> 236 template <class Alt>
237 void JSSpecialPropQuery(const char *, v8::Local<v8::String> property,const v8::P ropertyCallbackInfo<v8::Integer>& info) { 237 void JSSpecialPropQuery(const char *, v8::Local<v8::String> property,const v8::P ropertyCallbackInfo<v8::Integer>& info) {
238 v8::Isolate* isolate = info.GetIsolate(); 238 v8::Isolate* isolate = info.GetIsolate();
239 v8::String::Utf8Value utf8_value(property); 239 v8::String::Utf8Value utf8_value(property);
240 CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_value.len gth()); 240 CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_value.len gth());
241 CJS_Object* pJSObj = reinterpret_cast<CJS_Object*>(JS_GetPrivate(isolate, info .Holder())); 241 CJS_Object* pJSObj = reinterpret_cast<CJS_Object*>(JS_GetPrivate(isolate, info .Holder()));
242 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); 242 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject());
243 FX_BOOL bRet = pObj->QueryProperty(propname.c_str()); 243 bool bRet = pObj->QueryProperty(propname.c_str());
244 info.GetReturnValue().Set(bRet ? 4 : 0); 244 info.GetReturnValue().Set(bRet ? 4 : 0);
245 } 245 }
246 246
247 template <class Alt> 247 template <class Alt>
248 void JSSpecialPropGet(const char* class_name, 248 void JSSpecialPropGet(const char* class_name,
249 v8::Local<v8::String> property, 249 v8::Local<v8::String> property,
250 const v8::PropertyCallbackInfo<v8::Value>& info) { 250 const v8::PropertyCallbackInfo<v8::Value>& info) {
251 v8::Isolate* isolate = info.GetIsolate(); 251 v8::Isolate* isolate = info.GetIsolate();
252 v8::Local<v8::Context> context = isolate->GetCurrentContext(); 252 v8::Local<v8::Context> context = isolate->GetCurrentContext();
253 v8::Local<v8::Value> v = context->GetEmbedderData(1); 253 v8::Local<v8::Value> v = context->GetEmbedderData(1);
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 if (JS_DefineObjAllProperties(pRuntime, nObjDefnID, js_class_nam e::queryprop_##js_class_name##_static, js_class_name::getprop_##js_class_name##_ static,js_class_name::putprop_##js_class_name##_static,js_class_name::delprop_## js_class_name##_static)<0) return -1;\ 375 if (JS_DefineObjAllProperties(pRuntime, nObjDefnID, js_class_nam e::queryprop_##js_class_name##_static, js_class_name::getprop_##js_class_name##_ static,js_class_name::putprop_##js_class_name##_static,js_class_name::delprop_## js_class_name##_static)<0) return -1;\
376 \ 376 \
377 return nObjDefnID;\ 377 return nObjDefnID;\
378 }\ 378 }\
379 \ 379 \
380 return -1;\ 380 return -1;\
381 } 381 }
382 382
383 /* ======================================== GLOBAL METHODS ===================== ======================= */ 383 /* ======================================== GLOBAL METHODS ===================== ======================= */
384 384
385 template <FX_BOOL (*F)(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Valu e& vRet, CFX_WideString& sError)> 385 template <bool (*F)(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)>
386 void JSGlobalFunc(const char *func_name_string, 386 void JSGlobalFunc(const char *func_name_string,
387 const v8::FunctionCallbackInfo<v8::Value>& info) { 387 const v8::FunctionCallbackInfo<v8::Value>& info) {
388 v8::Isolate* isolate = info.GetIsolate(); 388 v8::Isolate* isolate = info.GetIsolate();
389 v8::Local<v8::Context> context = isolate->GetCurrentContext(); 389 v8::Local<v8::Context> context = isolate->GetCurrentContext();
390 v8::Local<v8::Value> v = context->GetEmbedderData(1); 390 v8::Local<v8::Value> v = context->GetEmbedderData(1);
391 v8::Local<v8::External> field = v8::Local<v8::External>::Cast(v); 391 v8::Local<v8::External> field = v8::Local<v8::External>::Cast(v);
392 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); 392 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value();
393 IFXJS_Context* cc = pRuntime->GetCurrentContext(); 393 IFXJS_Context* cc = pRuntime->GetCurrentContext();
394 CJS_Parameters parameters; 394 CJS_Parameters parameters;
395 for (unsigned int i = 0; i<(unsigned int)info.Length(); i++) { 395 for (unsigned int i = 0; i<(unsigned int)info.Length(); i++) {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 #define VALUE_NAME_BOOLEAN L"boolean" 459 #define VALUE_NAME_BOOLEAN L"boolean"
460 #define VALUE_NAME_DATE L"date" 460 #define VALUE_NAME_DATE L"date"
461 #define VALUE_NAME_OBJECT L"object" 461 #define VALUE_NAME_OBJECT L"object"
462 #define VALUE_NAME_FXOBJ L"fxobj" 462 #define VALUE_NAME_FXOBJ L"fxobj"
463 #define VALUE_NAME_NULL L"null" 463 #define VALUE_NAME_NULL L"null"
464 #define VALUE_NAME_UNDEFINED L"undefined" 464 #define VALUE_NAME_UNDEFINED L"undefined"
465 465
466 FXJSVALUETYPE GET_VALUE_TYPE(v8::Local<v8::Value> p); 466 FXJSVALUETYPE GET_VALUE_TYPE(v8::Local<v8::Value> p);
467 467
468 #endif // FPDFSDK_INCLUDE_JAVASCRIPT_JS_DEFINE_H_ 468 #endif // FPDFSDK_INCLUDE_JAVASCRIPT_JS_DEFINE_H_
OLDNEW
« no previous file with comments | « fpdfsdk/include/javascript/JS_Context.h ('k') | fpdfsdk/include/javascript/JS_EventHandler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698