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

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

Issue 908033002: Replace ugly JS_Define macros with templates (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@js_global_func
Patch Set: Don't re-create generated pdf file. 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;
11 typedef v8::Handle<v8::Object> JSObject; 11 typedef v8::Handle<v8::Object> JSObject;
12 typedef v8::Handle<v8::Object> JSFXObject; 12 typedef v8::Handle<v8::Object> JSFXObject;
13 typedef unsigned JSBool; 13 typedef unsigned JSBool;
14 14
15 #include "JS_Object.h"
16 #include "JS_Value.h"
17
15 struct JSConstSpec 18 struct JSConstSpec
16 { 19 {
17 const wchar_t* pName; 20 const wchar_t* pName;
18 double number; 21 double number;
19 const wchar_t* string; 22 const wchar_t* string;
20 FX_BYTE t; //0:double 1:str 23 FX_BYTE t; //0:double 1:str
21 }; 24 };
22 25
23 struct JSPropertySpec 26 struct JSPropertySpec
24 { 27 {
(...skipping 14 matching lines...) Expand all
39 #define JS_TRUE (unsigned)1 42 #define JS_TRUE (unsigned)1
40 #define JS_FALSE (unsigned)0 43 #define JS_FALSE (unsigned)0
41 44
42 45
43 #define CJS_PointsArray CFX_ArrayTemplate<float> 46 #define CJS_PointsArray CFX_ArrayTemplate<float>
44 #define CJS_IntArray CFX_ArrayTemplate<int> 47 #define CJS_IntArray CFX_ArrayTemplate<int>
45 48
46 /* ====================================== PUBLIC DEFINE SPEC =================== =========================== */ 49 /* ====================================== PUBLIC DEFINE SPEC =================== =========================== */
47 #define JS_WIDESTRING(widestring) L###widestring 50 #define JS_WIDESTRING(widestring) L###widestring
48 51
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[] = { 52 #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}, 53 #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}, 54 #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}}; 55 #define END_JS_STATIC_CONST() {0, 0, 0, 0}};
55 56
56 #define BEGIN_JS_STATIC_PROP(js_class_name) JSPropertySpec js_class_name::JS_Cla ss_Properties[] = { 57 #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}, 58 #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}}; 59 #define END_JS_STATIC_PROP() {0, 0, 0}};
59 60
60 #define BEGIN_JS_STATIC_METHOD(js_class_name) JSMethodSpec js_class_name::JS_Cla ss_Methods[] = { 61 #define BEGIN_JS_STATIC_METHOD(js_class_name) JSMethodSpec js_class_name::JS_Cla ss_Methods[] = {
61 #define JS_STATIC_METHOD_ENTRY(method_name, nargs) {JS_WIDESTRING(method_name), method_name##_static, nargs}, 62 #define JS_STATIC_METHOD_ENTRY(method_name, nargs) {JS_WIDESTRING(method_name), method_name##_static, nargs},
62 #define END_JS_STATIC_METHOD() {0, 0, 0}}; 63 #define END_JS_STATIC_METHOD() {0, 0, 0}};
63 #define MEMLEAKCHECK_1() ((void)0)
64 #define MEMLEAKCHECK_2(main_name, sub_name) ((void)0)
65
66
67 /*
68 #ifdef _DEBUG
69 #define MEMLEAKCHECK_1() \
70 _CrtMemState state1;\
71 _CrtMemCheckpoint(&state1);
72
73 #define MEMLEAKCHECK_2(main_name,sub_name) \
74 _CrtMemState state2;\
75 _CrtMemCheckpoint(&state2);\
76 _CrtMemState diff;\
77 _CrtMemDifference(&diff,&state1,&state2);\
78 if (diff.lSizes[_NORMAL_BLOCK] > 0)\
79 {\
80 TRACE("Detected normal block memory leaks in JS Module! [%s.%s]\ n",#main_name,#sub_name);\
81 _CrtMemDumpStatistics(&diff);\
82 }
83 #else
84 #define MEMLEAKCHECK_1() ((void)0)
85 #define MEMLEAKCHECK_2(main_name,sub_name) ((void)0)
86 #endif
87 */
88 64
89 /* ======================================== PROP CALLBACK ====================== ====================== */ 65 /* ======================================== PROP CALLBACK ====================== ====================== */
90 66
91 #define JS_STATIC_PROP_GET(prop_name, class_name)\ 67 template <class C, FX_BOOL (C::*M)(IFXJS_Context* cc, CJS_PropValue& vp, JS_Erro rString& sError)>
92 » static void get_##prop_name##_static(JS_PROPGET_ARGS)\ 68 void JSPropGetter(const char* prop_name_string,
93 {\ 69 const char* class_name_string,
94 » v8::Isolate* isolate = info.GetIsolate();\ 70 v8::Local<v8::String> property,
95 » v8::Local<v8::Context> context = isolate->GetCurrentContext();\ 71 const v8::PropertyCallbackInfo<v8::Value>& info) {
96 » v8::Local<v8::Value> v = context->GetEmbedderData(1);\ 72 v8::Isolate* isolate = info.GetIsolate();
97 » ASSERT(!v.IsEmpty());\ 73 v8::Local<v8::Context> context = isolate->GetCurrentContext();
98 » if(v.IsEmpty()) return;\ 74 v8::Local<v8::Value> v = context->GetEmbedderData(1);
99 » v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(v);\ 75 if (v.IsEmpty()) {
brucedawson 2015/02/16 20:42:00 The assert/return was ambiguous in that it made it
100 » IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value();\ 76 return;
101 » IFXJS_Context* cc = pRuntime->GetCurrentContext();\ 77 }
102 » CJS_PropValue value(isolate);\ 78 v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(v);
103 » value.StartGetting();\ 79 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value();
104 » CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder());\ 80 IFXJS_Context* pContext = pRuntime->GetCurrentContext();
105 » ASSERT(pJSObj != NULL);\ 81 CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder());
106 » class_name* pObj = (class_name*)pJSObj->GetEmbedObject();\ 82 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject());
107 » ASSERT(pObj != NULL);\ 83 JS_ErrorString sError;
108 » JS_ErrorString sError;\ 84 CJS_PropValue value(isolate);
109 » FX_BOOL bRet = FALSE;\ 85 value.StartGetting();
110 » MEMLEAKCHECK_1();\ 86 if (!(pObj->*M)(pContext, value, sError)) {
111 » bRet = pObj->prop_name(cc, value, sError);\ 87 CFX_ByteString cbName;
112 » MEMLEAKCHECK_2(class_name, prop_name);\ 88 cbName.Format("%s.%s", class_name_string, prop_name_string);
113 » if (bRet)\ 89 JS_Error(NULL, CFX_WideString::FromLocal(cbName), sError);
114 » {\ 90 return;
115 » » info.GetReturnValue().Set((v8::Handle<v8::Value>)value);\ 91 }
116 » » return ;\ 92 info.GetReturnValue().Set((v8::Handle<v8::Value>)value);
117 » }\
118 » else\
119 » {\
120 » CFX_ByteString cbName;\
121 » » cbName.Format("%s.%s", #class_name, #prop_name);\
122 » » JS_Error(NULL,CFX_WideString::FromLocal(cbName), sError);\
123 » » return ;\
124 » }\
125 } 93 }
126 94
127 #define JS_STATIC_PROP_SET(prop_name, class_name)\ 95 template <class C, FX_BOOL (C::*M)(IFXJS_Context* cc, CJS_PropValue& vp, JS_Erro rString& sError)>
128 » static void set_##prop_name##_static(JS_PROPPUT_ARGS)\ 96 void JSPropSetter(const char* prop_name_string,
129 {\ 97 const char* class_name_string,
130 » v8::Isolate* isolate = info.GetIsolate();\ 98 v8::Local<v8::String> property,
131 » v8::Local<v8::Context> context = isolate->GetCurrentContext();\ 99 v8::Local<v8::Value> value,
132 » v8::Local<v8::Value> v = context->GetEmbedderData(1);\ 100 const v8::PropertyCallbackInfo<void>& info) {
133 » ASSERT(!v.IsEmpty());\ 101 v8::Isolate* isolate = info.GetIsolate();
134 » if(v.IsEmpty()) return;\ 102 v8::Local<v8::Context> context = isolate->GetCurrentContext();
135 » v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(v);\ 103 v8::Local<v8::Value> v = context->GetEmbedderData(1);
136 » IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value();\ 104 if (v.IsEmpty()) {
137 » IFXJS_Context* cc = pRuntime->GetCurrentContext();\ 105 return;
138 » CJS_PropValue propValue(CJS_Value(isolate,value,VT_unknown));\ 106 }
139 » propValue.StartSetting();\ 107 v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(v);
140 » CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder());\ 108 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value();
141 » ASSERT(pJSObj != NULL);\ 109 IFXJS_Context* pContext = pRuntime->GetCurrentContext();
142 » class_name* pObj = (class_name*)pJSObj->GetEmbedObject();\ 110 CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder());
143 » ASSERT(pObj != NULL);\ 111 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject());
144 » JS_ErrorString sError;\ 112 JS_ErrorString sError;
145 » FX_BOOL bRet = FALSE;\ 113 CJS_PropValue propValue(CJS_Value(isolate, value, VT_unknown));
146 » MEMLEAKCHECK_1();\ 114 propValue.StartSetting();
147 » bRet = pObj->prop_name(cc, propValue, sError);\ 115 if (!(pObj->*M)(pContext, propValue, sError)) {
148 » MEMLEAKCHECK_2(class_name, prop_name);\ 116 CFX_ByteString cbName;
149 » if (bRet)\ 117 cbName.Format("%s.%s", class_name_string, prop_name_string);
150 » {\ 118 JS_Error(NULL, CFX_WideString::FromLocal(cbName), sError);
151 » » return ;\ 119 }
152 » }\
153 » else\
154 » {\
155 » » CFX_ByteString cbName;\
156 » » cbName.Format("%s.%s", #class_name, #prop_name);\
157 » » JS_Error(NULL,CFX_WideString::FromLocal(cbName), sError);\
158 » » return ;\
159 » }\
160 } 120 }
161 121
162 #define JS_STATIC_PROP(prop_name, class_name)\ 122 #define JS_STATIC_PROP(prop_name, class_name) \
163 JS_STATIC_PROP_GET(prop_name, class_name);\ 123 static void get_##prop_name##_static( \
164 JS_STATIC_PROP_SET(prop_name, class_name) 124 v8::Local<v8::String> property, \
125 const v8::PropertyCallbackInfo<v8::Value>& info) { \
126 JSPropGetter<class_name, &class_name::prop_name>( \
127 #prop_name, #class_name, property, info); \
128 } \
129 static void set_##prop_name##_static( \
130 v8::Local<v8::String> property, \
131 v8::Local<v8::Value> value, \
132 const v8::PropertyCallbackInfo<void>& info) { \
133 JSPropSetter<class_name, &class_name::prop_name>( \
134 #prop_name, #class_name, property, value, info); \
135 }
165 136
166 /* ========================================= METHOD CALLBACK =================== ======================== */ 137 /* ========================================= METHOD CALLBACK =================== ======================== */
167 138
168 #define JS_STATIC_METHOD(method_name, class_name)\ 139 template <class C, FX_BOOL (C::*M)(IFXJS_Context* cc, const CJS_Parameters& para ms, CJS_Value& vRet, JS_ErrorString& sError)>
169 » static void method_name##_static(JS_METHOD_ARGS)\ 140 void JSMethod(const char* method_name_string,
170 {\ 141 const char* class_name_string,
171 » v8::Isolate* isolate = info.GetIsolate();\ 142 const v8::FunctionCallbackInfo<v8::Value>& info) {
172 » v8::Local<v8::Context> context = isolate->GetCurrentContext();\ 143 v8::Isolate* isolate = info.GetIsolate();
173 » v8::Local<v8::Value> v = context->GetEmbedderData(1);\ 144 v8::Local<v8::Context> context = isolate->GetCurrentContext();
174 » ASSERT(!v.IsEmpty());\ 145 v8::Local<v8::Value> v = context->GetEmbedderData(1);
175 » if(v.IsEmpty()) return;\ 146 if (v.IsEmpty()) {
176 » v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(v);\ 147 return;
177 » IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value();\ 148 }
178 » IFXJS_Context* cc = pRuntime->GetCurrentContext();\ 149 v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(v);
179 » CJS_Parameters parameters;\ 150 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value();
180 » for (unsigned int i = 0; i<(unsigned int)info.Length(); i++)\ 151 IFXJS_Context* cc = pRuntime->GetCurrentContext();
181 {\ 152 CJS_Parameters parameters;
182 » » parameters.push_back(CJS_Value(isolate, info[i], VT_unknown));\ 153 for (unsigned int i = 0; i<(unsigned int)info.Length(); i++) {
183 » }\ 154 parameters.push_back(CJS_Value(isolate, info[i], VT_unknown));
184 » CJS_Value valueRes(isolate);\ 155 }
185 » CJS_Object* pJSObj = (CJS_Object *)JS_GetPrivate(isolate,info.Holder()); \ 156 CJS_Value valueRes(isolate);
186 » ASSERT(pJSObj != NULL);\ 157 CJS_Object* pJSObj = (CJS_Object *)JS_GetPrivate(isolate,info.Holder());
187 » class_name* pObj = (class_name*)pJSObj->GetEmbedObject();\ 158 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject());
188 » ASSERT(pObj != NULL);\ 159 JS_ErrorString sError;
189 » JS_ErrorString sError;\ 160 if (!(pObj->*M)(cc, parameters, valueRes, sError)) {
190 » FX_BOOL bRet = FALSE;\ 161 CFX_ByteString cbName;
191 » MEMLEAKCHECK_1();\ 162 cbName.Format("%s.%s", class_name_string, method_name_string);
192 » bRet = pObj->method_name(cc, parameters, valueRes, sError);\ 163 JS_Error(NULL, CFX_WideString::FromLocal(cbName), sError);
193 » MEMLEAKCHECK_2(class_name, method_name);\ 164 return;
194 » if (bRet)\ 165 }
195 » {\ 166 info.GetReturnValue().Set(valueRes.ToJSValue());
196 » » info.GetReturnValue().Set(valueRes.ToJSValue());\
197 » » return ;\
198 » }\
199 » else\
200 » {\
201 » » CFX_ByteString cbName;\
202 » » cbName.Format("%s.%s", #class_name, #method_name);\
203 » » JS_Error(NULL, CFX_WideString::FromLocal(cbName), sError);\
204 » » return ;\
205 » }\
206 } 167 }
207 168
169 #define JS_STATIC_METHOD(method_name, class_name) \
170 static void method_name##_static( \
171 const v8::FunctionCallbackInfo<v8::Value>& info) { \
172 JSMethod<class_name, &class_name::method_name>( \
173 #class_name, #method_name, info); \
174 }
175
176 #define JS_SPECIAL_STATIC_METHOD(method_name, class_alternate, class_name) \
177 static void method_name##_static( \
178 const v8::FunctionCallbackInfo<v8::Value>& info) { \
179 JSMethod<class_alternate, &class_alternate::method_name>( \
180 #class_name, #method_name, info); \
181 }
182
208 /* ===================================== JS CLASS ============================== ================= */ 183 /* ===================================== JS CLASS ============================== ================= */
209 184
210 #define DECLARE_JS_CLASS(js_class_name) \ 185 #define DECLARE_JS_CLASS(js_class_name) \
211 static JSBool JSConstructor(IFXJS_Context* cc, JSFXObject obj,JSFXObject global);\ 186 static JSBool JSConstructor(IFXJS_Context* cc, JSFXObject obj,JSFXObject global);\
212 static JSBool JSDestructor(JSFXObject obj);\ 187 static JSBool JSDestructor(JSFXObject obj);\
213 static int Init(IJS_Runtime* pRuntime, FXJSOBJTYPE eObjType);\ 188 static int Init(IJS_Runtime* pRuntime, FXJSOBJTYPE eObjType);\
214 static void GetConsts(JSConstSpec*& pConsts, int& nSize);\ 189 static void GetConsts(JSConstSpec*& pConsts, int& nSize);\
215 static void GetProperties(JSPropertySpec*& pProperties, int& nSize);\ 190 static void GetProperties(JSPropertySpec*& pProperties, int& nSize);\
216 static void GetMethods(JSMethodSpec*& pMethods, int& nSize);\ 191 static void GetMethods(JSMethodSpec*& pMethods, int& nSize);\
217 static JSConstSpec JS_Class_Consts[];\ 192 static JSConstSpec JS_Class_Consts[];\
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 void js_class_name::queryprop_##js_class_name##_static(JS_PROPQUERY_ARGS )\ 308 void js_class_name::queryprop_##js_class_name##_static(JS_PROPQUERY_ARGS )\
334 {\ 309 {\
335 v8::Isolate* isolate = info.GetIsolate();\ 310 v8::Isolate* isolate = info.GetIsolate();\
336 v8::String::Utf8Value utf8_value(property);\ 311 v8::String::Utf8Value utf8_value(property);\
337 CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_val ue.length());\ 312 CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_val ue.length());\
338 CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder());\ 313 CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder());\
339 ASSERT(pJSObj != NULL);\ 314 ASSERT(pJSObj != NULL);\
340 class_alternate* pObj = (class_alternate*)pJSObj->GetEmbedObject();\ 315 class_alternate* pObj = (class_alternate*)pJSObj->GetEmbedObject();\
341 ASSERT(pObj != NULL);\ 316 ASSERT(pObj != NULL);\
342 FX_BOOL bRet = FALSE;\ 317 FX_BOOL bRet = FALSE;\
343 MEMLEAKCHECK_1();\
344 bRet = pObj->QueryProperty(propname.c_str());\ 318 bRet = pObj->QueryProperty(propname.c_str());\
345 MEMLEAKCHECK_2(class_name, prop_name.c_str());\
346 if (bRet)\ 319 if (bRet)\
347 {\ 320 {\
348 info.GetReturnValue().Set(0x004);\ 321 info.GetReturnValue().Set(0x004);\
349 return ;\ 322 return ;\
350 }\ 323 }\
351 else\ 324 else\
352 {\ 325 {\
353 info.GetReturnValue().Set(0);\ 326 info.GetReturnValue().Set(0);\
354 return ;\ 327 return ;\
355 }\ 328 }\
(...skipping 12 matching lines...) Expand all
368 v8::String::Utf8Value utf8_value(property);\ 341 v8::String::Utf8Value utf8_value(property);\
369 CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_val ue.length());\ 342 CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_val ue.length());\
370 CJS_PropValue value(isolate);\ 343 CJS_PropValue value(isolate);\
371 value.StartGetting();\ 344 value.StartGetting();\
372 CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder());\ 345 CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder());\
373 ASSERT(pJSObj != NULL);\ 346 ASSERT(pJSObj != NULL);\
374 class_alternate* pObj = (class_alternate*)pJSObj->GetEmbedObject();\ 347 class_alternate* pObj = (class_alternate*)pJSObj->GetEmbedObject();\
375 ASSERT(pObj != NULL);\ 348 ASSERT(pObj != NULL);\
376 JS_ErrorString sError;\ 349 JS_ErrorString sError;\
377 FX_BOOL bRet = FALSE;\ 350 FX_BOOL bRet = FALSE;\
378 MEMLEAKCHECK_1();\
379 bRet = pObj->DoProperty(cc, propname.c_str(), value, sError);\ 351 bRet = pObj->DoProperty(cc, propname.c_str(), value, sError);\
380 MEMLEAKCHECK_2(class_name, L"GetProperty");\
381 if (bRet)\ 352 if (bRet)\
382 {\ 353 {\
383 info.GetReturnValue().Set((v8::Handle<v8::Value>)value);\ 354 info.GetReturnValue().Set((v8::Handle<v8::Value>)value);\
384 return ;\ 355 return ;\
385 }\ 356 }\
386 else\ 357 else\
387 {\ 358 {\
388 CFX_ByteString cbName;\ 359 CFX_ByteString cbName;\
389 cbName.Format("%s.%s", #class_name, L"GetProperty");\ 360 cbName.Format("%s.%s", #class_name, L"GetProperty");\
390 JS_Error(NULL,CFX_WideString::FromLocal(cbName), sError);\ 361 JS_Error(NULL,CFX_WideString::FromLocal(cbName), sError);\
(...skipping 15 matching lines...) Expand all
406 v8::String::Utf8Value utf8_value(property);\ 377 v8::String::Utf8Value utf8_value(property);\
407 CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_val ue.length());\ 378 CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_val ue.length());\
408 CJS_PropValue PropValue(CJS_Value(isolate,value,VT_unknown));\ 379 CJS_PropValue PropValue(CJS_Value(isolate,value,VT_unknown));\
409 PropValue.StartSetting();\ 380 PropValue.StartSetting();\
410 CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder());\ 381 CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder());\
411 if(!pJSObj) return;\ 382 if(!pJSObj) return;\
412 class_alternate* pObj = (class_alternate*)pJSObj->GetEmbedObject();\ 383 class_alternate* pObj = (class_alternate*)pJSObj->GetEmbedObject();\
413 ASSERT(pObj != NULL);\ 384 ASSERT(pObj != NULL);\
414 JS_ErrorString sError;\ 385 JS_ErrorString sError;\
415 FX_BOOL bRet = FALSE;\ 386 FX_BOOL bRet = FALSE;\
416 MEMLEAKCHECK_1();\
417 bRet = pObj->DoProperty(cc, propname.c_str(), PropValue, sError);\ 387 bRet = pObj->DoProperty(cc, propname.c_str(), PropValue, sError);\
418 MEMLEAKCHECK_2(class_name,L"PutProperty");\
419 if (bRet)\ 388 if (bRet)\
420 {\ 389 {\
421 return ;\ 390 return ;\
422 }\ 391 }\
423 else\ 392 else\
424 {\ 393 {\
425 CFX_ByteString cbName;\ 394 CFX_ByteString cbName;\
426 cbName.Format("%s.%s", #class_name, "PutProperty");\ 395 cbName.Format("%s.%s", #class_name, "PutProperty");\
427 JS_Error(NULL,CFX_WideString::FromLocal(cbName), sError);\ 396 JS_Error(NULL,CFX_WideString::FromLocal(cbName), sError);\
428 return ;\ 397 return ;\
(...skipping 12 matching lines...) Expand all
441 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value();\ 410 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value();\
442 IFXJS_Context* cc = pRuntime->GetCurrentContext();\ 411 IFXJS_Context* cc = pRuntime->GetCurrentContext();\
443 v8::String::Utf8Value utf8_value(property);\ 412 v8::String::Utf8Value utf8_value(property);\
444 CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_val ue.length());\ 413 CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_val ue.length());\
445 CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder());\ 414 CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder());\
446 ASSERT(pJSObj != NULL);\ 415 ASSERT(pJSObj != NULL);\
447 class_alternate* pObj = (class_alternate*)pJSObj->GetEmbedObject();\ 416 class_alternate* pObj = (class_alternate*)pJSObj->GetEmbedObject();\
448 ASSERT(pObj != NULL);\ 417 ASSERT(pObj != NULL);\
449 JS_ErrorString sError;\ 418 JS_ErrorString sError;\
450 FX_BOOL bRet = FALSE;\ 419 FX_BOOL bRet = FALSE;\
451 MEMLEAKCHECK_1();\
452 bRet = pObj->DelProperty(cc, propname.c_str(), sError);\ 420 bRet = pObj->DelProperty(cc, propname.c_str(), sError);\
453 MEMLEAKCHECK_2(class_name,L"DelProperty");\
454 if (bRet)\ 421 if (bRet)\
455 {\ 422 {\
456 return ;\ 423 return ;\
457 }\ 424 }\
458 else\ 425 else\
459 {\ 426 {\
460 CFX_ByteString cbName;\ 427 CFX_ByteString cbName;\
461 cbName.Format("%s.%s", #class_name, "DelProperty");\ 428 cbName.Format("%s.%s", #class_name, "DelProperty");\
462 return ;\ 429 return ;\
463 }\ 430 }\
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 {\ 480 {\
514 pProperties = JS_Class_Properties;\ 481 pProperties = JS_Class_Properties;\
515 nSize = sizeof(JS_Class_Properties)/sizeof(JSPropertySpec)-1;\ 482 nSize = sizeof(JS_Class_Properties)/sizeof(JSPropertySpec)-1;\
516 }\ 483 }\
517 void js_class_name::GetMethods(JSMethodSpec*& pMethods, int& nSize)\ 484 void js_class_name::GetMethods(JSMethodSpec*& pMethods, int& nSize)\
518 {\ 485 {\
519 pMethods = JS_Class_Methods;\ 486 pMethods = JS_Class_Methods;\
520 nSize = sizeof(JS_Class_Methods)/sizeof(JSMethodSpec)-1;\ 487 nSize = sizeof(JS_Class_Methods)/sizeof(JSMethodSpec)-1;\
521 } 488 }
522 489
523 #define JS_SPECIAL_STATIC_METHOD(method_name, class_alternate, class_name)\ 490 /* ======================================== GLOBAL METHODS ===================== ======================= */
524 » static void method_name##_static(JS_METHOD_ARGS)\ 491
525 {\ 492 template <FX_BOOL (*F)(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Valu e& vRet, JS_ErrorString& sError)>
526 » v8::Isolate* isolate = info.GetIsolate();\ 493 void JSGlobalFunc(const char *func_name_string,
527 » v8::Local<v8::Context> context = isolate->GetCurrentContext();\ 494 const v8::FunctionCallbackInfo<v8::Value>& info) {
528 » v8::Local<v8::Value> v = context->GetEmbedderData(1);\ 495 v8::Isolate* isolate = info.GetIsolate();
529 » ASSERT(!v.IsEmpty());\ 496 v8::Local<v8::Context> context = isolate->GetCurrentContext();
530 » if(v.IsEmpty()) return;\ 497 v8::Local<v8::Value> v = context->GetEmbedderData(1);
531 » v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(v);\ 498 if (v.IsEmpty()) {
Lei Zhang 2015/02/14 00:00:15 Can we ever hit this? If we were to hit this case,
532 » IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value();\ 499 return;
533 » IFXJS_Context* cc = pRuntime->GetCurrentContext();\ 500 }
534 » CJS_Parameters parameters;\ 501 v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(v);
535 » for (unsigned int i = 0; i<(unsigned int)info.Length(); i++)\ 502 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value();
536 » {\ 503 IFXJS_Context* cc = pRuntime->GetCurrentContext();
537 » parameters.push_back(CJS_Value(isolate, info[i], VT_unknown));\ 504 CJS_Parameters parameters;
538 » }\ 505 for (unsigned int i = 0; i<(unsigned int)info.Length(); i++) {
539 » CJS_Value valueRes(isolate);\ 506 parameters.push_back(CJS_Value(isolate, info[i], VT_unknown));
540 » CJS_Object* pJSObj = (CJS_Object *)JS_GetPrivate(isolate, info.Holder()) ;\ 507 }
541 » ASSERT(pJSObj != NULL);\ 508 CJS_Value valueRes(isolate);
542 » class_alternate* pObj = (class_alternate*)pJSObj->GetEmbedObject();\ 509 JS_ErrorString sError;
543 » ASSERT(pObj != NULL);\ 510 if (!(*F)(cc, parameters, valueRes, sError))
544 » JS_ErrorString sError;\ 511 {
545 » FX_BOOL bRet = FALSE;\ 512 JS_Error(NULL, JS_WIDESTRING(fun_name), sError);
546 » MEMLEAKCHECK_1();\ 513 return;
547 » bRet = pObj->method_name(cc, parameters, valueRes, sError);\ 514 }
548 » MEMLEAKCHECK_2(class_name, method_name);\ 515 info.GetReturnValue().Set(valueRes.ToJSValue());
549 » if (bRet)\
550 » {\
551 » » info.GetReturnValue().Set(valueRes.ToJSValue());\
552 » » return ;\
553 » }\
554 » else\
555 » {\
556 » » CFX_ByteString cbName;\
557 » » cbName.Format("%s.%s", #class_name, #method_name);\
558 » » JS_Error(NULL, CFX_WideString::FromLocal(cbName), sError);\
559 » » return ;\
560 » }\
561 » JS_Error(NULL, JS_WIDESTRING(method_name), L"Embeded object not found!" );\
562 return ;\
563 } 516 }
564 517
565 /* ======================================== GLOBAL METHODS ===================== ======================= */
566 #define JS_STATIC_GLOBAL_FUN(fun_name) \ 518 #define JS_STATIC_GLOBAL_FUN(fun_name) \
567 static void fun_name##_static(JS_METHOD_ARGS)\ 519 static void fun_name##_static(const v8::FunctionCallbackInfo<v8::Value>& info) { \
568 {\ 520 JSGlobalFunc<fun_name>(#fun_name, info); \
569 » v8::Isolate* isolate = info.GetIsolate();\ 521 }
570 » v8::Local<v8::Context> context = isolate->GetCurrentContext();\
571 » v8::Local<v8::Value> v = context->GetEmbedderData(1);\
572 » ASSERT(!v.IsEmpty());\
573 » if(v.IsEmpty()) return;\
574 » v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(v);\
575 » IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value();\
576 » IFXJS_Context* cc = pRuntime->GetCurrentContext();\
577 » CJS_Parameters parameters;\
578 » for (unsigned int i = 0; i<(unsigned int)info.Length(); i++)\
579 » {\
580 » parameters.push_back(CJS_Value(isolate, info[i], VT_unknown));\
581 » }\
582 » CJS_Value valueRes(isolate);\
583 » JS_ErrorString sError;\
584 » if (!fun_name(cc, parameters, valueRes, sError))\
585 » {\
586 » » JS_Error(NULL, JS_WIDESTRING(fun_name), sError);\
587 » » return ;\
588 » }\
589 » info.GetReturnValue().Set(valueRes.ToJSValue());\
590 » return ;\
591 }
592 522
593 #define JS_STATIC_DECLARE_GLOBAL_FUN() \ 523 #define JS_STATIC_DECLARE_GLOBAL_FUN() \
594 static JSMethodSpec global_methods[]; \ 524 static JSMethodSpec global_methods[]; \
595 static int Init(IJS_Runtime* pRuntime) 525 static int Init(IJS_Runtime* pRuntime)
596 526
597 #define BEGIN_JS_STATIC_GLOBAL_FUN(js_class_name) \ 527 #define BEGIN_JS_STATIC_GLOBAL_FUN(js_class_name) \
598 JSMethodSpec js_class_name::global_methods[] = { 528 JSMethodSpec js_class_name::global_methods[] = {
599 529
600 #define JS_STATIC_GLOBAL_FUN_ENTRY(method_name,nargs) JS_STATIC_METHOD_ENTRY(met hod_name,nargs) 530 #define JS_STATIC_GLOBAL_FUN_ENTRY(method_name,nargs) JS_STATIC_METHOD_ENTRY(met hod_name,nargs)
601 531
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 #define VALUE_NAME_DATE L"date" 571 #define VALUE_NAME_DATE L"date"
642 #define VALUE_NAME_OBJECT L"object" 572 #define VALUE_NAME_OBJECT L"object"
643 #define VALUE_NAME_FXOBJ L"fxobj" 573 #define VALUE_NAME_FXOBJ L"fxobj"
644 #define VALUE_NAME_NULL L"null" 574 #define VALUE_NAME_NULL L"null"
645 #define VALUE_NAME_UNDEFINED L"undefined" 575 #define VALUE_NAME_UNDEFINED L"undefined"
646 576
647 #define CLASSNAME_ARRAY L"Array" 577 #define CLASSNAME_ARRAY L"Array"
648 #define CLASSNAME_DATE L"Date" 578 #define CLASSNAME_DATE L"Date"
649 #define CLASSNAME_STRING L"v8::String" 579 #define CLASSNAME_STRING L"v8::String"
650 580
651 extern const unsigned int JSCONST_nStringHash; 581 FXJSVALUETYPE GET_VALUE_TYPE(v8::Handle<v8::Value> p);
652 extern const unsigned int JSCONST_nNumberHash;
653 extern const unsigned int JSCONST_nBoolHash;
654 extern const unsigned int JSCONST_nDateHash;
655 extern const unsigned int JSCONST_nObjectHash;
656 extern const unsigned int JSCONST_nFXobjHash;
657 extern const unsigned int JSCONST_nNullHash;
658 extern const unsigned int JSCONST_nUndefHash;
659
660 static FXJSVALUETYPE GET_VALUE_TYPE(v8::Handle<v8::Value> p)
661 {
662
663 » » const unsigned int nHash = JS_CalcHash(JS_GetTypeof(p));
664
665 » » if (nHash == JSCONST_nUndefHash)
666 » » » return VT_undefined;
667 » » else if (nHash == JSCONST_nNullHash)
668 » » » return VT_null;
669 » » else if (nHash == JSCONST_nStringHash)
670 » » » return VT_string;
671 » » else if (nHash == JSCONST_nNumberHash)
672 » » » return VT_number;
673 » » else if (nHash == JSCONST_nBoolHash)
674 » » » return VT_boolean;
675 » » else if (nHash == JSCONST_nDateHash)
676 » » » return VT_date;
677 » » else if (nHash == JSCONST_nObjectHash)
678 » » » return VT_object;» »
679 » » else if (nHash == JSCONST_nFXobjHash)
680 » » » return VT_fxobject;
681
682 » » /*
683 » » const char * sType = p->getTypeof()->toDchars();
684 » » if (strcmp(sType,VALUE_NAME_STRING) == 0)
685 » » » return VT_string;
686 » » else if (strcmp(sType,VALUE_NAME_NUMBER) == 0)
687 » » » return VT_number;
688 » » else if (strcmp(sType,VALUE_NAME_BOOLEAN) == 0)
689 » » » return VT_boolean;
690 » » else if (strcmp(sType,VALUE_NAME_DATE) == 0)
691 » » » return VT_date;
692 » » else if (strcmp(sType,VALUE_NAME_OBJECT) == 0)
693 » » » return VT_object;
694 » » else if (strcmp(sType,VALUE_NAME_FXOBJ) == 0)
695 » » » return VT_object;
696 » » else if (strcmp(sType,VALUE_NAME_NULL) == 0)
697 » » » return VT_null;
698 » » else if (strcmp(sType,VALUE_NAME_UNDEFINED) == 0)
699 » » » return VT_undefined;
700 » » » */
701
702 » return VT_unknown;
703 }
704 582
705 #endif //_JS_DEFINE_H_ 583 #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