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

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

Issue 936613002: Merge to XFA: Tidy up JS_Defines.h (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Created 5 years, 10 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/Icon.h ('k') | fpdfsdk/include/javascript/PublicMethods.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 _JS_DEFINE_H_ 7 #ifndef _JS_DEFINE_H_
8 #define _JS_DEFINE_H_ 8 #define _JS_DEFINE_H_
9 9
10 typedef v8::Value JSValue; 10 typedef v8::Value JSValue;
(...skipping 28 matching lines...) Expand all
39 #define JS_TRUE (unsigned)1 39 #define JS_TRUE (unsigned)1
40 #define JS_FALSE (unsigned)0 40 #define JS_FALSE (unsigned)0
41 41
42 42
43 #define CJS_PointsArray CFX_ArrayTemplate<float> 43 #define CJS_PointsArray CFX_ArrayTemplate<float>
44 #define CJS_IntArray CFX_ArrayTemplate<int> 44 #define CJS_IntArray CFX_ArrayTemplate<int>
45 45
46 /* ====================================== PUBLIC DEFINE SPEC =================== =========================== */ 46 /* ====================================== PUBLIC DEFINE SPEC =================== =========================== */
47 #define JS_WIDESTRING(widestring) L###widestring 47 #define JS_WIDESTRING(widestring) L###widestring
48 48
49 #define OBJ_PROP_PARAMS IFXJS_Context* cc, CJS_PropValue& vp, JS _ErrorString& sError
50 #define OBJ_METHOD_PARAMS IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, JS_ErrorString& sError
51 #define BEGIN_JS_STATIC_CONST(js_class_name) JSConstSpec js_class_name::JS_Class _Consts[] = { 49 #define BEGIN_JS_STATIC_CONST(js_class_name) JSConstSpec js_class_name::JS_Class _Consts[] = {
52 #define JS_STATIC_CONST_ENTRY_NUMBER(const_name, pValue) {JS_WIDESTRING(const_na me), pValue, L"", 0}, 50 #define JS_STATIC_CONST_ENTRY_NUMBER(const_name, pValue) {JS_WIDESTRING(const_na me), pValue, L"", 0},
53 #define JS_STATIC_CONST_ENTRY_STRING(const_name, pValue) {JS_WIDESTRING(const_na me), 0, JS_WIDESTRING(pValue), 1}, 51 #define JS_STATIC_CONST_ENTRY_STRING(const_name, pValue) {JS_WIDESTRING(const_na me), 0, JS_WIDESTRING(pValue), 1},
54 #define END_JS_STATIC_CONST() {0, 0, 0, 0}}; 52 #define END_JS_STATIC_CONST() {0, 0, 0, 0}};
55 53
56 #define BEGIN_JS_STATIC_PROP(js_class_name) JSPropertySpec js_class_name::JS_Cla ss_Properties[] = { 54 #define BEGIN_JS_STATIC_PROP(js_class_name) JSPropertySpec js_class_name::JS_Cla ss_Properties[] = {
57 #define JS_STATIC_PROP_ENTRY(prop_name) {JS_WIDESTRING(prop_name), get_##prop_na me##_static, set_##prop_name##_static}, 55 #define JS_STATIC_PROP_ENTRY(prop_name) {JS_WIDESTRING(prop_name), get_##prop_na me##_static, set_##prop_name##_static},
58 #define END_JS_STATIC_PROP() {0, 0, 0}}; 56 #define END_JS_STATIC_PROP() {0, 0, 0}};
59 57
60 #define BEGIN_JS_STATIC_METHOD(js_class_name) JSMethodSpec js_class_name::JS_Cla ss_Methods[] = { 58 #define BEGIN_JS_STATIC_METHOD(js_class_name) JSMethodSpec js_class_name::JS_Cla ss_Methods[] = {
(...skipping 21 matching lines...) Expand all
82 } 80 }
83 #else 81 #else
84 #define MEMLEAKCHECK_1() ((void)0) 82 #define MEMLEAKCHECK_1() ((void)0)
85 #define MEMLEAKCHECK_2(main_name,sub_name) ((void)0) 83 #define MEMLEAKCHECK_2(main_name,sub_name) ((void)0)
86 #endif 84 #endif
87 */ 85 */
88 86
89 /* ======================================== PROP CALLBACK ====================== ====================== */ 87 /* ======================================== PROP CALLBACK ====================== ====================== */
90 88
91 #define JS_STATIC_PROP_GET(prop_name, class_name)\ 89 #define JS_STATIC_PROP_GET(prop_name, class_name)\
92 » static void get_##prop_name##_static(JS_PROPGET_ARGS)\ 90 static void get_##prop_name##_static(v8::Local<v8::String> property, \
91 const v8::PropertyCallbackInfo<v8::Value> & info) \
93 {\ 92 {\
94 v8::Isolate* isolate = info.GetIsolate();\ 93 v8::Isolate* isolate = info.GetIsolate();\
95 v8::Local<v8::Context> context = isolate->GetCurrentContext();\ 94 v8::Local<v8::Context> context = isolate->GetCurrentContext();\
96 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2);\ 95 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2);\
97 if (pRuntime == NULL) return;\ 96 if (pRuntime == NULL) return;\
98 IFXJS_Context* cc = pRuntime->GetCurrentContext();\ 97 IFXJS_Context* cc = pRuntime->GetCurrentContext();\
99 CJS_PropValue value(isolate);\ 98 CJS_PropValue value(isolate);\
100 value.StartGetting();\ 99 value.StartGetting();\
101 CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder());\ 100 CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder());\
102 ASSERT(pJSObj != NULL);\ 101 ASSERT(pJSObj != NULL);\
(...skipping 12 matching lines...) Expand all
115 else\ 114 else\
116 {\ 115 {\
117 CFX_ByteString cbName;\ 116 CFX_ByteString cbName;\
118 cbName.Format("%s.%s", #class_name, #prop_name);\ 117 cbName.Format("%s.%s", #class_name, #prop_name);\
119 JS_Error(NULL,CFX_WideString::FromLocal(cbName), sError);\ 118 JS_Error(NULL,CFX_WideString::FromLocal(cbName), sError);\
120 return ;\ 119 return ;\
121 }\ 120 }\
122 } 121 }
123 122
124 #define JS_STATIC_PROP_SET(prop_name, class_name)\ 123 #define JS_STATIC_PROP_SET(prop_name, class_name)\
125 » static void set_##prop_name##_static(JS_PROPPUT_ARGS)\ 124 static void set_##prop_name##_static(v8::Local<v8::String> property, \
125 v8::Local<v8::Value> value, \
126 const v8::PropertyCallbackInfo<void>& inf o) \
126 {\ 127 {\
127 v8::Isolate* isolate = info.GetIsolate();\ 128 v8::Isolate* isolate = info.GetIsolate();\
128 v8::Local<v8::Context> context = isolate->GetCurrentContext();\ 129 v8::Local<v8::Context> context = isolate->GetCurrentContext();\
129 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2);\ 130 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2);\
130 if (pRuntime == NULL) return;\ 131 if (pRuntime == NULL) return;\
131 IFXJS_Context* cc = pRuntime->GetCurrentContext();\ 132 IFXJS_Context* cc = pRuntime->GetCurrentContext();\
132 CJS_PropValue propValue(CJS_Value(isolate,value,VT_unknown));\ 133 CJS_PropValue propValue(CJS_Value(isolate,value,VT_unknown));\
133 propValue.StartSetting();\ 134 propValue.StartSetting();\
134 CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder());\ 135 CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder());\
135 ASSERT(pJSObj != NULL);\ 136 ASSERT(pJSObj != NULL);\
(...skipping 17 matching lines...) Expand all
153 }\ 154 }\
154 } 155 }
155 156
156 #define JS_STATIC_PROP(prop_name, class_name)\ 157 #define JS_STATIC_PROP(prop_name, class_name)\
157 JS_STATIC_PROP_GET(prop_name, class_name);\ 158 JS_STATIC_PROP_GET(prop_name, class_name);\
158 JS_STATIC_PROP_SET(prop_name, class_name) 159 JS_STATIC_PROP_SET(prop_name, class_name)
159 160
160 /* ========================================= METHOD CALLBACK =================== ======================== */ 161 /* ========================================= METHOD CALLBACK =================== ======================== */
161 162
162 #define JS_STATIC_METHOD(method_name, class_name)\ 163 #define JS_STATIC_METHOD(method_name, class_name)\
163 » static void method_name##_static(JS_METHOD_ARGS)\ 164 static void method_name##_static(const v8::FunctionCallbackInfo<v8::Value>& in fo) \
164 {\ 165 {\
165 v8::Isolate* isolate = info.GetIsolate();\ 166 v8::Isolate* isolate = info.GetIsolate();\
166 v8::Local<v8::Context> context = isolate->GetCurrentContext();\ 167 v8::Local<v8::Context> context = isolate->GetCurrentContext();\
167 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2);\ 168 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2);\
168 if (pRuntime == NULL) return;\ 169 if (pRuntime == NULL) return;\
169 IFXJS_Context* cc = pRuntime->GetCurrentContext();\ 170 IFXJS_Context* cc = pRuntime->GetCurrentContext();\
170 CJS_Parameters parameters;\ 171 CJS_Parameters parameters;\
171 for (unsigned int i = 0; i<(unsigned int)info.Length(); i++)\ 172 for (unsigned int i = 0; i<(unsigned int)info.Length(); i++)\
172 {\ 173 {\
173 parameters.push_back(CJS_Value(isolate, info[i], VT_unknown));\ 174 parameters.push_back(CJS_Value(isolate, info[i], VT_unknown));\
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 pProperties = JS_Class_Properties;\ 497 pProperties = JS_Class_Properties;\
497 nSize = sizeof(JS_Class_Properties)/sizeof(JSPropertySpec)-1;\ 498 nSize = sizeof(JS_Class_Properties)/sizeof(JSPropertySpec)-1;\
498 }\ 499 }\
499 void js_class_name::GetMethods(JSMethodSpec*& pMethods, int& nSize)\ 500 void js_class_name::GetMethods(JSMethodSpec*& pMethods, int& nSize)\
500 {\ 501 {\
501 pMethods = JS_Class_Methods;\ 502 pMethods = JS_Class_Methods;\
502 nSize = sizeof(JS_Class_Methods)/sizeof(JSMethodSpec)-1;\ 503 nSize = sizeof(JS_Class_Methods)/sizeof(JSMethodSpec)-1;\
503 } 504 }
504 505
505 #define JS_SPECIAL_STATIC_METHOD(method_name, class_alternate, class_name)\ 506 #define JS_SPECIAL_STATIC_METHOD(method_name, class_alternate, class_name)\
506 » static void method_name##_static(JS_METHOD_ARGS)\ 507 » static void method_name##_static(const v8::FunctionCallbackInfo<v8::Valu e>& info)\
507 {\ 508 {\
508 v8::Isolate* isolate = info.GetIsolate();\ 509 v8::Isolate* isolate = info.GetIsolate();\
509 v8::Local<v8::Context> context = isolate->GetCurrentContext();\ 510 v8::Local<v8::Context> context = isolate->GetCurrentContext();\
510 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2);\ 511 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2);\
511 if (pRuntime == NULL) return;\ 512 if (pRuntime == NULL) return;\
512 IFXJS_Context* cc = pRuntime->GetCurrentContext();\ 513 IFXJS_Context* cc = pRuntime->GetCurrentContext();\
513 CJS_Parameters parameters;\ 514 CJS_Parameters parameters;\
514 for (unsigned int i = 0; i<(unsigned int)info.Length(); i++)\ 515 for (unsigned int i = 0; i<(unsigned int)info.Length(); i++)\
515 {\ 516 {\
516 parameters.push_back(CJS_Value(isolate, info[i], VT_unknown));\ 517 parameters.push_back(CJS_Value(isolate, info[i], VT_unknown));\
(...skipping 19 matching lines...) Expand all
536 cbName.Format("%s.%s", #class_name, #method_name);\ 537 cbName.Format("%s.%s", #class_name, #method_name);\
537 JS_Error(NULL, CFX_WideString::FromLocal(cbName), sError);\ 538 JS_Error(NULL, CFX_WideString::FromLocal(cbName), sError);\
538 return ;\ 539 return ;\
539 }\ 540 }\
540 JS_Error(NULL, JS_WIDESTRING(method_name), L"Embeded object not found!" );\ 541 JS_Error(NULL, JS_WIDESTRING(method_name), L"Embeded object not found!" );\
541 return ;\ 542 return ;\
542 } 543 }
543 544
544 /* ======================================== GLOBAL METHODS ===================== ======================= */ 545 /* ======================================== GLOBAL METHODS ===================== ======================= */
545 #define JS_STATIC_GLOBAL_FUN(fun_name) \ 546 #define JS_STATIC_GLOBAL_FUN(fun_name) \
546 static void fun_name##_static(JS_METHOD_ARGS)\ 547 static void fun_name##_static(const v8::FunctionCallbackInfo<v8::Value>& info)\
547 {\ 548 {\
548 v8::Isolate* isolate = info.GetIsolate();\ 549 v8::Isolate* isolate = info.GetIsolate();\
549 v8::Local<v8::Context> context = isolate->GetCurrentContext();\ 550 v8::Local<v8::Context> context = isolate->GetCurrentContext();\
550 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2);\ 551 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2);\
551 if (pRuntime == NULL) return;\ 552 if (pRuntime == NULL) return;\
552 IFXJS_Context* cc = pRuntime->GetCurrentContext();\ 553 IFXJS_Context* cc = pRuntime->GetCurrentContext();\
553 CJS_Parameters parameters;\ 554 CJS_Parameters parameters;\
554 for (unsigned int i = 0; i<(unsigned int)info.Length(); i++)\ 555 for (unsigned int i = 0; i<(unsigned int)info.Length(); i++)\
555 {\ 556 {\
556 parameters.push_back(CJS_Value(isolate, info[i], VT_unknown));\ 557 parameters.push_back(CJS_Value(isolate, info[i], VT_unknown));\
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 #define VALUE_NAME_DATE L"date" 618 #define VALUE_NAME_DATE L"date"
618 #define VALUE_NAME_OBJECT L"object" 619 #define VALUE_NAME_OBJECT L"object"
619 #define VALUE_NAME_FXOBJ L"fxobj" 620 #define VALUE_NAME_FXOBJ L"fxobj"
620 #define VALUE_NAME_NULL L"null" 621 #define VALUE_NAME_NULL L"null"
621 #define VALUE_NAME_UNDEFINED L"undefined" 622 #define VALUE_NAME_UNDEFINED L"undefined"
622 623
623 #define CLASSNAME_ARRAY L"Array" 624 #define CLASSNAME_ARRAY L"Array"
624 #define CLASSNAME_DATE L"Date" 625 #define CLASSNAME_DATE L"Date"
625 #define CLASSNAME_STRING L"v8::String" 626 #define CLASSNAME_STRING L"v8::String"
626 627
627 extern const unsigned int JSCONST_nStringHash; 628 FXJSVALUETYPE GET_VALUE_TYPE(v8::Handle<v8::Value> p);
628 extern const unsigned int JSCONST_nNumberHash;
629 extern const unsigned int JSCONST_nBoolHash;
630 extern const unsigned int JSCONST_nDateHash;
631 extern const unsigned int JSCONST_nObjectHash;
632 extern const unsigned int JSCONST_nFXobjHash;
633 extern const unsigned int JSCONST_nNullHash;
634 extern const unsigned int JSCONST_nUndefHash;
635
636 static FXJSVALUETYPE GET_VALUE_TYPE(v8::Handle<v8::Value> p)
637 {
638
639 » » const unsigned int nHash = JS_CalcHash(JS_GetTypeof(p));
640
641 » » if (nHash == JSCONST_nUndefHash)
642 » » » return VT_undefined;
643 » » else if (nHash == JSCONST_nNullHash)
644 » » » return VT_null;
645 » » else if (nHash == JSCONST_nStringHash)
646 » » » return VT_string;
647 » » else if (nHash == JSCONST_nNumberHash)
648 » » » return VT_number;
649 » » else if (nHash == JSCONST_nBoolHash)
650 » » » return VT_boolean;
651 » » else if (nHash == JSCONST_nDateHash)
652 » » » return VT_date;
653 » » else if (nHash == JSCONST_nObjectHash)
654 » » » return VT_object;» »
655 » » else if (nHash == JSCONST_nFXobjHash)
656 » » » return VT_fxobject;
657
658 » » /*
659 » » const char * sType = p->getTypeof()->toDchars();
660 » » if (strcmp(sType,VALUE_NAME_STRING) == 0)
661 » » » return VT_string;
662 » » else if (strcmp(sType,VALUE_NAME_NUMBER) == 0)
663 » » » return VT_number;
664 » » else if (strcmp(sType,VALUE_NAME_BOOLEAN) == 0)
665 » » » return VT_boolean;
666 » » else if (strcmp(sType,VALUE_NAME_DATE) == 0)
667 » » » return VT_date;
668 » » else if (strcmp(sType,VALUE_NAME_OBJECT) == 0)
669 » » » return VT_object;
670 » » else if (strcmp(sType,VALUE_NAME_FXOBJ) == 0)
671 » » » return VT_object;
672 » » else if (strcmp(sType,VALUE_NAME_NULL) == 0)
673 » » » return VT_null;
674 » » else if (strcmp(sType,VALUE_NAME_UNDEFINED) == 0)
675 » » » return VT_undefined;
676 » » » */
677
678 » return VT_unknown;
679 }
680 629
681 #endif //_JS_DEFINE_H_ 630 #endif //_JS_DEFINE_H_
OLDNEW
« no previous file with comments | « fpdfsdk/include/javascript/Icon.h ('k') | fpdfsdk/include/javascript/PublicMethods.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698