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

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

Issue 969203002: Merge to XFA: Kill off JS_ErrorString type. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Created 5 years, 9 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/JS_Value.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 #include "../jsapi/fxjs_v8.h" 10 #include "../jsapi/fxjs_v8.h"
11 #include "resource.h" 11 #include "resource.h"
12 12
13 typedef v8::Value JSValue; 13 typedef v8::Value JSValue;
14 typedef v8::Handle<v8::Object> JSObject; 14 typedef v8::Handle<v8::Object> JSObject;
15 typedef v8::Handle<v8::Object> JSFXObject; 15 typedef v8::Handle<v8::Object> JSFXObject;
16 typedef unsigned JSBool;
17 16
18 #include "JS_Object.h" 17 #include "JS_Object.h"
19 #include "JS_Value.h" 18 #include "JS_Value.h"
20 19
21 struct JSConstSpec 20 struct JSConstSpec
22 { 21 {
23 const wchar_t* pName; 22 const wchar_t* pName;
24 double number; 23 double number;
25 const wchar_t* string; 24 const wchar_t* string;
26 FX_BYTE t; //0:double 1:str 25 FX_BYTE t; //0:double 1:str
27 }; 26 };
28 27
29 struct JSPropertySpec 28 struct JSPropertySpec
30 { 29 {
31 const wchar_t* pName; 30 const wchar_t* pName;
32 v8::AccessorGetterCallback pPropGet; 31 v8::AccessorGetterCallback pPropGet;
33 v8::AccessorSetterCallback pPropPut; 32 v8::AccessorSetterCallback pPropPut;
34 }; 33 };
35 34
36 struct JSMethodSpec 35 struct JSMethodSpec
37 { 36 {
38 const wchar_t* pName; 37 const wchar_t* pName;
39 v8::FunctionCallback pMethodCall; 38 v8::FunctionCallback pMethodCall;
40 unsigned nParamNum; 39 unsigned nParamNum;
41 }; 40 };
42 41
43 #define JS_TRUE (unsigned)1
44 #define JS_FALSE (unsigned)0
45
46 typedef CFX_WideString JS_ErrorString;
47 typedef CFX_ArrayTemplate<float> CJS_PointsArray;
48 typedef CFX_ArrayTemplate<int> CJS_IntArray;
49
50 /* ====================================== PUBLIC DEFINE SPEC =================== =========================== */ 42 /* ====================================== PUBLIC DEFINE SPEC =================== =========================== */
51 #define JS_WIDESTRING(widestring) L###widestring 43 #define JS_WIDESTRING(widestring) L###widestring
52 44
53 #define BEGIN_JS_STATIC_CONST(js_class_name) JSConstSpec js_class_name::JS_Class _Consts[] = { 45 #define BEGIN_JS_STATIC_CONST(js_class_name) JSConstSpec js_class_name::JS_Class _Consts[] = {
54 #define JS_STATIC_CONST_ENTRY_NUMBER(const_name, pValue) {JS_WIDESTRING(const_na me), pValue, L"", 0}, 46 #define JS_STATIC_CONST_ENTRY_NUMBER(const_name, pValue) {JS_WIDESTRING(const_na me), pValue, L"", 0},
55 #define JS_STATIC_CONST_ENTRY_STRING(const_name, pValue) {JS_WIDESTRING(const_na me), 0, JS_WIDESTRING(pValue), 1}, 47 #define JS_STATIC_CONST_ENTRY_STRING(const_name, pValue) {JS_WIDESTRING(const_na me), 0, JS_WIDESTRING(pValue), 1},
56 #define END_JS_STATIC_CONST() {0, 0, 0, 0}}; 48 #define END_JS_STATIC_CONST() {0, 0, 0, 0}};
57 49
58 #define BEGIN_JS_STATIC_PROP(js_class_name) JSPropertySpec js_class_name::JS_Cla ss_Properties[] = { 50 #define BEGIN_JS_STATIC_PROP(js_class_name) JSPropertySpec js_class_name::JS_Cla ss_Properties[] = {
59 #define JS_STATIC_PROP_ENTRY(prop_name) {JS_WIDESTRING(prop_name), get_##prop_na me##_static, set_##prop_name##_static}, 51 #define JS_STATIC_PROP_ENTRY(prop_name) {JS_WIDESTRING(prop_name), get_##prop_na me##_static, set_##prop_name##_static},
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 #define JS_SPECIAL_STATIC_METHOD(method_name, class_alternate, class_name) \ 145 #define JS_SPECIAL_STATIC_METHOD(method_name, class_alternate, class_name) \
154 static void method_name##_static( \ 146 static void method_name##_static( \
155 const v8::FunctionCallbackInfo<v8::Value>& info) { \ 147 const v8::FunctionCallbackInfo<v8::Value>& info) { \
156 JSMethod<class_alternate, &class_alternate::method_name>( \ 148 JSMethod<class_alternate, &class_alternate::method_name>( \
157 #method_name, #class_name, info); \ 149 #method_name, #class_name, info); \
158 } 150 }
159 151
160 /* ===================================== JS CLASS ============================== ================= */ 152 /* ===================================== JS CLASS ============================== ================= */
161 153
162 #define DECLARE_JS_CLASS(js_class_name) \ 154 #define DECLARE_JS_CLASS(js_class_name) \
163 » static JSBool JSConstructor(IFXJS_Context* cc, JSFXObject obj,JSFXObject global);\ 155 » static void JSConstructor(IFXJS_Context* cc, JSFXObject obj,JSFXObject g lobal);\
164 » static JSBool JSDestructor(JSFXObject obj);\ 156 » static void JSDestructor(JSFXObject obj);\
165 static int Init(IJS_Runtime* pRuntime, FXJSOBJTYPE eObjType);\ 157 static int Init(IJS_Runtime* pRuntime, FXJSOBJTYPE eObjType);\
166 static JSConstSpec JS_Class_Consts[];\ 158 static JSConstSpec JS_Class_Consts[];\
167 static JSPropertySpec JS_Class_Properties[];\ 159 static JSPropertySpec JS_Class_Properties[];\
168 static JSMethodSpec JS_Class_Methods[];\ 160 static JSMethodSpec JS_Class_Methods[];\
169 static const wchar_t* m_pClassName 161 static const wchar_t* m_pClassName
170 162
171 #define IMPLEMENT_JS_CLASS_RICH(js_class_name, class_alternate, class_name) \ 163 #define IMPLEMENT_JS_CLASS_RICH(js_class_name, class_alternate, class_name) \
172 const wchar_t* js_class_name::m_pClassName = JS_WIDESTRING(class_name);\ 164 const wchar_t* js_class_name::m_pClassName = JS_WIDESTRING(class_name);\
173 JSBool js_class_name::JSConstructor(IFXJS_Context* cc, JSFXObject obj, JSFXObjec t global)\ 165 void js_class_name::JSConstructor(IFXJS_Context* cc, JSFXObject obj, JSFXObject global)\
174 {\ 166 {\
175 CJS_Object* pObj = FX_NEW js_class_name(obj);\ 167 CJS_Object* pObj = FX_NEW js_class_name(obj);\
176 pObj->SetEmbedObject(FX_NEW class_alternate(pObj));\ 168 pObj->SetEmbedObject(FX_NEW class_alternate(pObj));\
177 JS_SetPrivate(NULL,obj,(void*)pObj); \ 169 JS_SetPrivate(NULL,obj,(void*)pObj); \
178 pObj->InitInstance(cc);\ 170 pObj->InitInstance(cc);\
179 return JS_TRUE;\
180 }\ 171 }\
181 \ 172 \
182 JSBool js_class_name::JSDestructor(JSFXObject obj) \ 173 void js_class_name::JSDestructor(JSFXObject obj) \
183 {\ 174 {\
184 js_class_name* pObj = (js_class_name*)JS_GetPrivate(NULL,obj);\ 175 js_class_name* pObj = (js_class_name*)JS_GetPrivate(NULL,obj);\
185 ASSERT(pObj != NULL);\ 176 ASSERT(pObj != NULL);\
186 pObj->ExitInstance();\ 177 pObj->ExitInstance();\
187 delete pObj;\ 178 delete pObj;\
188 return JS_TRUE;\
189 }\ 179 }\
190 \ 180 \
191 int js_class_name::Init(IJS_Runtime* pRuntime, FXJSOBJTYPE eObjType)\ 181 int js_class_name::Init(IJS_Runtime* pRuntime, FXJSOBJTYPE eObjType)\
192 {\ 182 {\
193 int nObjDefnID = JS_DefineObj(pRuntime, js_class_name::m_pClassName, eOb jType, JSConstructor, JSDestructor, 0);\ 183 int nObjDefnID = JS_DefineObj(pRuntime, js_class_name::m_pClassName, eOb jType, JSConstructor, JSDestructor, 0);\
194 if (nObjDefnID >= 0)\ 184 if (nObjDefnID >= 0)\
195 {\ 185 {\
196 for (int j=0, szj=sizeof(JS_Class_Properties)/sizeof(JSPropertyS pec)-1; j<szj; j++)\ 186 for (int j=0, szj=sizeof(JS_Class_Properties)/sizeof(JSPropertyS pec)-1; j<szj; j++)\
197 {\ 187 {\
198 if (JS_DefineObjProperty(pRuntime, nObjDefnID, JS_Class_ Properties[j].pName, JS_Class_Properties[j].pPropGet, JS_Class_Properties[j].pPr opPut) < 0) return -1;\ 188 if (JS_DefineObjProperty(pRuntime, nObjDefnID, JS_Class_ Properties[j].pName, JS_Class_Properties[j].pPropGet, JS_Class_Properties[j].pPr opPut) < 0) return -1;\
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_value.len gth()); 298 CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_value.len gth());
309 CFX_WideString sError; 299 CFX_WideString sError;
310 if (!pObj->DelProperty(pRuntimeContext, propname.c_str(), sError)) { 300 if (!pObj->DelProperty(pRuntimeContext, propname.c_str(), sError)) {
311 CFX_ByteString cbName; 301 CFX_ByteString cbName;
312 cbName.Format("%s.%s", class_name, "DelProperty"); 302 cbName.Format("%s.%s", class_name, "DelProperty");
313 // Probably a missing call to JS_Error(). 303 // Probably a missing call to JS_Error().
314 } 304 }
315 } 305 }
316 306
317 #define DECLARE_SPECIAL_JS_CLASS(js_class_name) \ 307 #define DECLARE_SPECIAL_JS_CLASS(js_class_name) \
318 » static JSBool JSConstructor(IFXJS_Context* cc, JSFXObject obj, JSFXObjec t global);\ 308 » static void JSConstructor(IFXJS_Context* cc, JSFXObject obj, JSFXObject global);\
319 » static JSBool JSDestructor(JSFXObject obj);\ 309 » static void JSDestructor(JSFXObject obj);\
320 static JSConstSpec JS_Class_Consts[];\ 310 static JSConstSpec JS_Class_Consts[];\
321 static JSPropertySpec JS_Class_Properties[];\ 311 static JSPropertySpec JS_Class_Properties[];\
322 static JSMethodSpec JS_Class_Methods[];\ 312 static JSMethodSpec JS_Class_Methods[];\
323 static int Init(IJS_Runtime* pRuntime, FXJSOBJTYPE eObjType);\ 313 static int Init(IJS_Runtime* pRuntime, FXJSOBJTYPE eObjType);\
324 static const wchar_t* m_pClassName;\ 314 static const wchar_t* m_pClassName;\
325 static void queryprop_##js_class_name##_static(v8::Local<v8::String> pro perty,const v8::PropertyCallbackInfo<v8::Integer>& info);\ 315 static void queryprop_##js_class_name##_static(v8::Local<v8::String> pro perty,const v8::PropertyCallbackInfo<v8::Integer>& info);\
326 static void getprop_##js_class_name##_static(v8::Local<v8::String> prope rty, const v8::PropertyCallbackInfo<v8::Value>& info);\ 316 static void getprop_##js_class_name##_static(v8::Local<v8::String> prope rty, const v8::PropertyCallbackInfo<v8::Value>& info);\
327 static void putprop_##js_class_name##_static(v8::Local<v8::String> prope rty,v8::Local<v8::Value> value,const v8::PropertyCallbackInfo<v8::Value>& info); \ 317 static void putprop_##js_class_name##_static(v8::Local<v8::String> prope rty,v8::Local<v8::Value> value,const v8::PropertyCallbackInfo<v8::Value>& info); \
328 static void delprop_##js_class_name##_static(v8::Local<v8::String> prope rty,const v8::PropertyCallbackInfo<v8::Boolean>& info) 318 static void delprop_##js_class_name##_static(v8::Local<v8::String> prope rty,const v8::PropertyCallbackInfo<v8::Boolean>& info)
329 319
330 #define IMPLEMENT_SPECIAL_JS_CLASS(js_class_name, class_alternate, class_name) \ 320 #define IMPLEMENT_SPECIAL_JS_CLASS(js_class_name, class_alternate, class_name) \
331 const wchar_t * js_class_name::m_pClassName = JS_WIDESTRING(class_name);\ 321 const wchar_t * js_class_name::m_pClassName = JS_WIDESTRING(class_name);\
332 void js_class_name::queryprop_##js_class_name##_static(v8::Local<v8::String> pro perty,const v8::PropertyCallbackInfo<v8::Integer>& info) { \ 322 void js_class_name::queryprop_##js_class_name##_static(v8::Local<v8::String> pro perty,const v8::PropertyCallbackInfo<v8::Integer>& info) { \
333 JSSpecialPropQuery<class_alternate>(#class_name, property, info); \ 323 JSSpecialPropQuery<class_alternate>(#class_name, property, info); \
334 }\ 324 }\
335 void js_class_name::getprop_##js_class_name##_static(v8::Local<v8::String> prope rty, const v8::PropertyCallbackInfo<v8::Value>& info) { \ 325 void js_class_name::getprop_##js_class_name##_static(v8::Local<v8::String> prope rty, const v8::PropertyCallbackInfo<v8::Value>& info) { \
336 JSSpecialPropGet<class_alternate>(#class_name, property, info); \ 326 JSSpecialPropGet<class_alternate>(#class_name, property, info); \
337 } \ 327 } \
338 void js_class_name::putprop_##js_class_name##_static(v8::Local<v8::String> prope rty,v8::Local<v8::Value> value,const v8::PropertyCallbackInfo<v8::Value>& info) {\ 328 void js_class_name::putprop_##js_class_name##_static(v8::Local<v8::String> prope rty,v8::Local<v8::Value> value,const v8::PropertyCallbackInfo<v8::Value>& info) {\
339 JSSpecialPropPut<class_alternate>(#class_name, property, value, info); \ 329 JSSpecialPropPut<class_alternate>(#class_name, property, value, info); \
340 }\ 330 }\
341 void js_class_name::delprop_##js_class_name##_static(v8::Local<v8::String> prope rty,const v8::PropertyCallbackInfo<v8::Boolean>& info) { \ 331 void js_class_name::delprop_##js_class_name##_static(v8::Local<v8::String> prope rty,const v8::PropertyCallbackInfo<v8::Boolean>& info) { \
342 JSSpecialPropDel<class_alternate>(#class_name, property, info); \ 332 JSSpecialPropDel<class_alternate>(#class_name, property, info); \
343 } \ 333 } \
344 JSBool js_class_name::JSConstructor(IFXJS_Context* cc, JSFXObject obj,JSFXObjec t global)\ 334 void js_class_name::JSConstructor(IFXJS_Context* cc, JSFXObject obj,JSFXObject global)\
345 {\ 335 {\
346 CJS_Object* pObj = FX_NEW js_class_name(obj);\ 336 CJS_Object* pObj = FX_NEW js_class_name(obj);\
347 pObj->SetEmbedObject(FX_NEW class_alternate(pObj));\ 337 pObj->SetEmbedObject(FX_NEW class_alternate(pObj));\
348 JS_SetPrivate(NULL,obj, (void*)pObj); \ 338 JS_SetPrivate(NULL,obj, (void*)pObj); \
349 pObj->InitInstance(cc);\ 339 pObj->InitInstance(cc);\
350 return JS_TRUE;\
351 }\ 340 }\
352 \ 341 \
353 JSBool js_class_name::JSDestructor(JSFXObject obj) \ 342 void js_class_name::JSDestructor(JSFXObject obj) \
354 {\ 343 {\
355 js_class_name* pObj = (js_class_name*)JS_GetPrivate(NULL,obj);\ 344 js_class_name* pObj = (js_class_name*)JS_GetPrivate(NULL,obj);\
356 ASSERT(pObj != NULL);\ 345 ASSERT(pObj != NULL);\
357 pObj->ExitInstance();\ 346 pObj->ExitInstance();\
358 delete pObj;\ 347 delete pObj;\
359 return JS_TRUE;\
360 }\ 348 }\
361 \ 349 \
362 int js_class_name::Init(IJS_Runtime* pRuntime, FXJSOBJTYPE eObjType)\ 350 int js_class_name::Init(IJS_Runtime* pRuntime, FXJSOBJTYPE eObjType)\
363 {\ 351 {\
364 \ 352 \
365 int nObjDefnID = JS_DefineObj(pRuntime, js_class_name::m_pClassName, eOb jType, JSConstructor, JSDestructor, 0);\ 353 int nObjDefnID = JS_DefineObj(pRuntime, js_class_name::m_pClassName, eOb jType, JSConstructor, JSDestructor, 0);\
366 \ 354 \
367 if (nObjDefnID >= 0)\ 355 if (nObjDefnID >= 0)\
368 {\ 356 {\
369 for (int j=0, szj=sizeof(JS_Class_Properties)/sizeof(JSPropertyS pec)-1; j<szj; j++)\ 357 for (int j=0, szj=sizeof(JS_Class_Properties)/sizeof(JSPropertyS pec)-1; j<szj; j++)\
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 #define VALUE_NAME_BOOLEAN L"boolean" 447 #define VALUE_NAME_BOOLEAN L"boolean"
460 #define VALUE_NAME_DATE L"date" 448 #define VALUE_NAME_DATE L"date"
461 #define VALUE_NAME_OBJECT L"object" 449 #define VALUE_NAME_OBJECT L"object"
462 #define VALUE_NAME_FXOBJ L"fxobj" 450 #define VALUE_NAME_FXOBJ L"fxobj"
463 #define VALUE_NAME_NULL L"null" 451 #define VALUE_NAME_NULL L"null"
464 #define VALUE_NAME_UNDEFINED L"undefined" 452 #define VALUE_NAME_UNDEFINED L"undefined"
465 453
466 FXJSVALUETYPE GET_VALUE_TYPE(v8::Handle<v8::Value> p); 454 FXJSVALUETYPE GET_VALUE_TYPE(v8::Handle<v8::Value> p);
467 455
468 #endif //_JS_DEFINE_H_ 456 #endif //_JS_DEFINE_H_
OLDNEW
« no previous file with comments | « fpdfsdk/include/javascript/Icon.h ('k') | fpdfsdk/include/javascript/JS_Value.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698