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

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

Issue 971013002: Merge to XFA: Return error information from pdfium to JS. (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/IJavaScript.h ('k') | fpdfsdk/include/javascript/JS_Object.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"
11 #include "resource.h"
12
10 typedef v8::Value JSValue; 13 typedef v8::Value JSValue;
11 typedef v8::Handle<v8::Object> JSObject; 14 typedef v8::Handle<v8::Object> JSObject;
12 typedef v8::Handle<v8::Object> JSFXObject; 15 typedef v8::Handle<v8::Object> JSFXObject;
13 typedef unsigned JSBool; 16 typedef unsigned JSBool;
14 17
15 #include "JS_Object.h" 18 #include "JS_Object.h"
16 #include "JS_Value.h" 19 #include "JS_Value.h"
17 20
18 struct JSConstSpec 21 struct JSConstSpec
19 { 22 {
(...skipping 10 matching lines...) Expand all
30 v8::AccessorSetterCallback pPropPut; 33 v8::AccessorSetterCallback pPropPut;
31 }; 34 };
32 35
33 struct JSMethodSpec 36 struct JSMethodSpec
34 { 37 {
35 const wchar_t* pName; 38 const wchar_t* pName;
36 v8::FunctionCallback pMethodCall; 39 v8::FunctionCallback pMethodCall;
37 unsigned nParamNum; 40 unsigned nParamNum;
38 }; 41 };
39 42
40 typedef CFX_WideString JS_ErrorString;
41
42 #define JS_TRUE (unsigned)1 43 #define JS_TRUE (unsigned)1
43 #define JS_FALSE (unsigned)0 44 #define JS_FALSE (unsigned)0
44 45
46 typedef CFX_WideString JS_ErrorString;
45 typedef CFX_ArrayTemplate<float> CJS_PointsArray; 47 typedef CFX_ArrayTemplate<float> CJS_PointsArray;
46 typedef CFX_ArrayTemplate<int> CJS_IntArray; 48 typedef CFX_ArrayTemplate<int> CJS_IntArray;
47 49
48 /* ====================================== PUBLIC DEFINE SPEC =================== =========================== */ 50 /* ====================================== PUBLIC DEFINE SPEC =================== =========================== */
49 #define JS_WIDESTRING(widestring) L###widestring 51 #define JS_WIDESTRING(widestring) L###widestring
50 52
51 #define BEGIN_JS_STATIC_CONST(js_class_name) JSConstSpec js_class_name::JS_Class _Consts[] = { 53 #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}, 54 #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}, 55 #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}}; 56 #define END_JS_STATIC_CONST() {0, 0, 0, 0}};
55 57
56 #define BEGIN_JS_STATIC_PROP(js_class_name) JSPropertySpec js_class_name::JS_Cla ss_Properties[] = { 58 #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}, 59 #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}}; 60 #define END_JS_STATIC_PROP() {0, 0, 0}};
59 61
60 #define BEGIN_JS_STATIC_METHOD(js_class_name) JSMethodSpec js_class_name::JS_Cla ss_Methods[] = { 62 #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}, 63 #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}}; 64 #define END_JS_STATIC_METHOD() {0, 0, 0}};
63 65
64 /* ======================================== PROP CALLBACK ====================== ====================== */ 66 /* ======================================== PROP CALLBACK ====================== ====================== */
65 67
66 template <class C, FX_BOOL (C::*M)(IFXJS_Context*, CJS_PropValue&, JS_ErrorStrin g&)> 68 template <class C, FX_BOOL (C::*M)(IFXJS_Context*, CJS_PropValue&, CFX_WideStrin g&)>
67 void JSPropGetter(const char* prop_name_string, 69 void JSPropGetter(const char* prop_name_string,
68 const char* class_name_string, 70 const char* class_name_string,
69 v8::Local<v8::String> property, 71 v8::Local<v8::String> property,
70 const v8::PropertyCallbackInfo<v8::Value>& info) { 72 const v8::PropertyCallbackInfo<v8::Value>& info) {
71 v8::Isolate* isolate = info.GetIsolate(); 73 v8::Isolate* isolate = info.GetIsolate();
72 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2); 74 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2);
73 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); 75 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext();
74 CJS_PropValue value(isolate); 76 CJS_PropValue value(isolate);
75 value.StartGetting(); 77 value.StartGetting();
76 CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder()); 78 CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder());
77 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); 79 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject());
78 JS_ErrorString sError; 80 CFX_WideString sError;
79 if (!(pObj->*M)(pRuntimeContext, value, sError)) { 81 if (!(pObj->*M)(pRuntimeContext, value, sError)) {
80 CFX_ByteString cbName; 82 JS_Error(isolate, JSFormatErrorString(class_name_string, prop_name_string, s Error));
81 cbName.Format("%s.%s", class_name_string, prop_name_string);
82 JS_Error(NULL, CFX_WideString::FromLocal(cbName), sError);
83 return; 83 return;
84 } 84 }
85 info.GetReturnValue().Set((v8::Handle<v8::Value>)value); 85 info.GetReturnValue().Set((v8::Handle<v8::Value>)value);
86 } 86 }
87 87
88 template <class C, FX_BOOL (C::*M)(IFXJS_Context*, CJS_PropValue&, JS_ErrorStrin g&)> 88 template <class C, FX_BOOL (C::*M)(IFXJS_Context*, CJS_PropValue&, CFX_WideStrin g&)>
89 void JSPropSetter(const char* prop_name_string, 89 void JSPropSetter(const char* prop_name_string,
90 const char* class_name_string, 90 const char* class_name_string,
91 v8::Local<v8::String> property, 91 v8::Local<v8::String> property,
92 v8::Local<v8::Value> value, 92 v8::Local<v8::Value> value,
93 const v8::PropertyCallbackInfo<void>& info) { 93 const v8::PropertyCallbackInfo<void>& info) {
94 v8::Isolate* isolate = info.GetIsolate(); 94 v8::Isolate* isolate = info.GetIsolate();
95 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2); 95 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2);
96 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); 96 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext();
97 CJS_PropValue propValue(CJS_Value(isolate, value, VT_unknown)); 97 CJS_PropValue propValue(CJS_Value(isolate, value, VT_unknown));
98 propValue.StartSetting(); 98 propValue.StartSetting();
99 CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder()); 99 CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder());
100 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); 100 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject());
101 JS_ErrorString sError; 101 CFX_WideString sError;
102 if (!(pObj->*M)(pRuntimeContext, propValue, sError)) { 102 if (!(pObj->*M)(pRuntimeContext, propValue, sError)) {
103 CFX_ByteString cbName; 103 JS_Error(isolate, JSFormatErrorString(class_name_string, prop_name_string, s Error));
104 cbName.Format("%s.%s", class_name_string, prop_name_string);
105 JS_Error(NULL, CFX_WideString::FromLocal(cbName), sError);
106 } 104 }
107 } 105 }
108 106
109 #define JS_STATIC_PROP(prop_name, class_name) \ 107 #define JS_STATIC_PROP(prop_name, class_name) \
110 static void get_##prop_name##_static( \ 108 static void get_##prop_name##_static( \
111 v8::Local<v8::String> property, \ 109 v8::Local<v8::String> property, \
112 const v8::PropertyCallbackInfo<v8::Value>& info) { \ 110 const v8::PropertyCallbackInfo<v8::Value>& info) { \
113 JSPropGetter<class_name, &class_name::prop_name>( \ 111 JSPropGetter<class_name, &class_name::prop_name>( \
114 #prop_name, #class_name, property, info); \ 112 #prop_name, #class_name, property, info); \
115 } \ 113 } \
116 static void set_##prop_name##_static( \ 114 static void set_##prop_name##_static( \
117 v8::Local<v8::String> property, \ 115 v8::Local<v8::String> property, \
118 v8::Local<v8::Value> value, \ 116 v8::Local<v8::Value> value, \
119 const v8::PropertyCallbackInfo<void>& info) { \ 117 const v8::PropertyCallbackInfo<void>& info) { \
120 JSPropSetter<class_name, &class_name::prop_name>( \ 118 JSPropSetter<class_name, &class_name::prop_name>( \
121 #prop_name, #class_name, property, value, info); \ 119 #prop_name, #class_name, property, value, info); \
122 } 120 }
123 121
124 /* ========================================= METHOD CALLBACK =================== ======================== */ 122 /* ========================================= METHOD CALLBACK =================== ======================== */
125 123
126 template <class C, FX_BOOL (C::*M)(IFXJS_Context*, const CJS_Parameters&, CJS_Va lue&, JS_ErrorString&)> 124 template <class C, FX_BOOL (C::*M)(IFXJS_Context*, const CJS_Parameters&, CJS_Va lue&, CFX_WideString&)>
127 void JSMethod(const char* method_name_string, 125 void JSMethod(const char* method_name_string,
128 const char* class_name_string, 126 const char* class_name_string,
129 const v8::FunctionCallbackInfo<v8::Value>& info) { 127 const v8::FunctionCallbackInfo<v8::Value>& info) {
130 v8::Isolate* isolate = info.GetIsolate(); 128 v8::Isolate* isolate = info.GetIsolate();
131 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2); 129 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2);
132 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); 130 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext();
133 CJS_Parameters parameters; 131 CJS_Parameters parameters;
134 for (unsigned int i = 0; i<(unsigned int)info.Length(); i++) { 132 for (unsigned int i = 0; i<(unsigned int)info.Length(); i++) {
135 parameters.push_back(CJS_Value(isolate, info[i], VT_unknown)); 133 parameters.push_back(CJS_Value(isolate, info[i], VT_unknown));
136 } 134 }
137 CJS_Value valueRes(isolate); 135 CJS_Value valueRes(isolate);
138 CJS_Object* pJSObj = (CJS_Object *)JS_GetPrivate(isolate,info.Holder()); 136 CJS_Object* pJSObj = (CJS_Object *)JS_GetPrivate(isolate,info.Holder());
139 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); 137 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject());
140 JS_ErrorString sError; 138 CFX_WideString sError;
141 if (!(pObj->*M)(pRuntimeContext, parameters, valueRes, sError)) { 139 if (!(pObj->*M)(pRuntimeContext, parameters, valueRes, sError)) {
142 CFX_ByteString cbName; 140 JS_Error(isolate, JSFormatErrorString(class_name_string, method_name_string, sError));
143 cbName.Format("%s.%s", class_name_string, method_name_string);
144 JS_Error(NULL, CFX_WideString::FromLocal(cbName), sError);
145 return; 141 return;
146 } 142 }
147 info.GetReturnValue().Set(valueRes.ToJSValue()); 143 info.GetReturnValue().Set(valueRes.ToJSValue());
148 } 144 }
149 145
150 #define JS_STATIC_METHOD(method_name, class_name) \ 146 #define JS_STATIC_METHOD(method_name, class_name) \
151 static void method_name##_static( \ 147 static void method_name##_static( \
152 const v8::FunctionCallbackInfo<v8::Value>& info) { \ 148 const v8::FunctionCallbackInfo<v8::Value>& info) { \
153 JSMethod<class_name, &class_name::method_name>( \ 149 JSMethod<class_name, &class_name::method_name>( \
154 #class_name, #method_name, info); \ 150 #method_name, #class_name, info); \
155 } 151 }
156 152
157 #define JS_SPECIAL_STATIC_METHOD(method_name, class_alternate, class_name) \ 153 #define JS_SPECIAL_STATIC_METHOD(method_name, class_alternate, class_name) \
158 static void method_name##_static( \ 154 static void method_name##_static( \
159 const v8::FunctionCallbackInfo<v8::Value>& info) { \ 155 const v8::FunctionCallbackInfo<v8::Value>& info) { \
160 JSMethod<class_alternate, &class_alternate::method_name>( \ 156 JSMethod<class_alternate, &class_alternate::method_name>( \
161 #class_name, #method_name, info); \ 157 #method_name, #class_name, info); \
162 } 158 }
163 159
164 /* ===================================== JS CLASS ============================== ================= */ 160 /* ===================================== JS CLASS ============================== ================= */
165 161
166 #define DECLARE_JS_CLASS(js_class_name) \ 162 #define DECLARE_JS_CLASS(js_class_name) \
167 static JSBool JSConstructor(IFXJS_Context* cc, JSFXObject obj,JSFXObject global);\ 163 static JSBool JSConstructor(IFXJS_Context* cc, JSFXObject obj,JSFXObject global);\
168 static JSBool JSDestructor(JSFXObject obj);\ 164 static JSBool JSDestructor(JSFXObject obj);\
169 static int Init(IJS_Runtime* pRuntime, FXJSOBJTYPE eObjType);\ 165 static int Init(IJS_Runtime* pRuntime, FXJSOBJTYPE eObjType);\
170 static JSConstSpec JS_Class_Consts[];\ 166 static JSConstSpec JS_Class_Consts[];\
171 static JSPropertySpec JS_Class_Properties[];\ 167 static JSPropertySpec JS_Class_Properties[];\
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 v8::Local<v8::String> property, 256 v8::Local<v8::String> property,
261 const v8::PropertyCallbackInfo<v8::Value>& info) { 257 const v8::PropertyCallbackInfo<v8::Value>& info) {
262 v8::Isolate* isolate = info.GetIsolate(); 258 v8::Isolate* isolate = info.GetIsolate();
263 v8::Local<v8::Context> context = isolate->GetCurrentContext(); 259 v8::Local<v8::Context> context = isolate->GetCurrentContext();
264 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2); 260 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2);
265 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); 261 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext();
266 CJS_Object* pJSObj = reinterpret_cast<CJS_Object*>(JS_GetPrivate(isolate, info .Holder())); 262 CJS_Object* pJSObj = reinterpret_cast<CJS_Object*>(JS_GetPrivate(isolate, info .Holder()));
267 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); 263 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject());
268 v8::String::Utf8Value utf8_value(property); 264 v8::String::Utf8Value utf8_value(property);
269 CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_value.len gth()); 265 CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_value.len gth());
270 JS_ErrorString sError; 266 CFX_WideString sError;
271 CJS_PropValue value(isolate); 267 CJS_PropValue value(isolate);
272 value.StartGetting(); 268 value.StartGetting();
273 if (!pObj->DoProperty(pRuntimeContext, propname.c_str(), value, sError)) { 269 if (!pObj->DoProperty(pRuntimeContext, propname.c_str(), value, sError)) {
274 CFX_ByteString cbName; 270 JS_Error(isolate, JSFormatErrorString(class_name, "GetProperty", sError));
275 cbName.Format("%s.%s", class_name, L"GetProperty"); 271 return;
276 JS_Error(NULL,CFX_WideString::FromLocal(cbName), sError);
277 return;
278 } 272 }
279 info.GetReturnValue().Set((v8::Handle<v8::Value>)value); 273 info.GetReturnValue().Set((v8::Handle<v8::Value>)value);
280 } 274 }
281 275
282 template <class Alt> 276 template <class Alt>
283 void JSSpecialPropPut(const char* class_name, 277 void JSSpecialPropPut(const char* class_name,
284 v8::Local<v8::String> property, 278 v8::Local<v8::String> property,
285 v8::Local<v8::Value> value, 279 v8::Local<v8::Value> value,
286 const v8::PropertyCallbackInfo<v8::Value>& info) { 280 const v8::PropertyCallbackInfo<v8::Value>& info) {
287 v8::Isolate* isolate = info.GetIsolate(); 281 v8::Isolate* isolate = info.GetIsolate();
288 v8::Local<v8::Context> context = isolate->GetCurrentContext(); 282 v8::Local<v8::Context> context = isolate->GetCurrentContext();
289 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2); 283 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2);
290 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); 284 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext();
291 CJS_Object* pJSObj = reinterpret_cast<CJS_Object*>(JS_GetPrivate(isolate, info .Holder())); 285 CJS_Object* pJSObj = reinterpret_cast<CJS_Object*>(JS_GetPrivate(isolate, info .Holder()));
292 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); 286 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject());
293 v8::String::Utf8Value utf8_value(property); 287 v8::String::Utf8Value utf8_value(property);
294 CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_value.len gth()); 288 CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_value.len gth());
295 JS_ErrorString sError; 289 CFX_WideString sError;
296 CJS_PropValue PropValue(CJS_Value(isolate,value,VT_unknown)); 290 CJS_PropValue PropValue(CJS_Value(isolate,value,VT_unknown));
297 PropValue.StartSetting(); 291 PropValue.StartSetting();
298 if (!pObj->DoProperty(pRuntimeContext, propname.c_str(), PropValue, sError)) { 292 if (!pObj->DoProperty(pRuntimeContext, propname.c_str(), PropValue, sError)) {
299 CFX_ByteString cbName; 293 JS_Error(isolate, JSFormatErrorString(class_name, "PutProperty", sError));
300 cbName.Format("%s.%s", class_name, "PutProperty");
301 JS_Error(NULL,CFX_WideString::FromLocal(cbName), sError);
302 } 294 }
303 } 295 }
304 296
305 template <class Alt> 297 template <class Alt>
306 void JSSpecialPropDel(const char* class_name, 298 void JSSpecialPropDel(const char* class_name,
307 v8::Local<v8::String> property, 299 v8::Local<v8::String> property,
308 const v8::PropertyCallbackInfo<v8::Boolean>& info) { 300 const v8::PropertyCallbackInfo<v8::Boolean>& info) {
309 v8::Isolate* isolate = info.GetIsolate(); 301 v8::Isolate* isolate = info.GetIsolate();
310 v8::Local<v8::Context> context = isolate->GetCurrentContext(); 302 v8::Local<v8::Context> context = isolate->GetCurrentContext();
311 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2); 303 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2);
312 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); 304 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext();
313 CJS_Object* pJSObj = reinterpret_cast<CJS_Object*>(JS_GetPrivate(isolate, info .Holder())); 305 CJS_Object* pJSObj = reinterpret_cast<CJS_Object*>(JS_GetPrivate(isolate, info .Holder()));
314 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); 306 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject());
315 v8::String::Utf8Value utf8_value(property); 307 v8::String::Utf8Value utf8_value(property);
316 CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_value.len gth()); 308 CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_value.len gth());
317 JS_ErrorString sError; 309 CFX_WideString sError;
318 if (!pObj->DelProperty(pRuntimeContext, propname.c_str(), sError)) { 310 if (!pObj->DelProperty(pRuntimeContext, propname.c_str(), sError)) {
319 CFX_ByteString cbName; 311 CFX_ByteString cbName;
320 cbName.Format("%s.%s", class_name, "DelProperty"); 312 cbName.Format("%s.%s", class_name, "DelProperty");
321 // Probably a missing call to JS_Error(). 313 // Probably a missing call to JS_Error().
322 } 314 }
323 } 315 }
324 316
325 #define DECLARE_SPECIAL_JS_CLASS(js_class_name) \ 317 #define DECLARE_SPECIAL_JS_CLASS(js_class_name) \
326 static JSBool JSConstructor(IFXJS_Context* cc, JSFXObject obj, JSFXObjec t global);\ 318 static JSBool JSConstructor(IFXJS_Context* cc, JSFXObject obj, JSFXObjec t global);\
327 static JSBool JSDestructor(JSFXObject obj);\ 319 static JSBool JSDestructor(JSFXObject obj);\
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 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;\ 378 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;\
387 \ 379 \
388 return nObjDefnID;\ 380 return nObjDefnID;\
389 }\ 381 }\
390 \ 382 \
391 return -1;\ 383 return -1;\
392 } 384 }
393 385
394 /* ======================================== GLOBAL METHODS ===================== ======================= */ 386 /* ======================================== GLOBAL METHODS ===================== ======================= */
395 387
396 template <FX_BOOL (*F)(IFXJS_Context*, const CJS_Parameters&, CJS_Value&, JS_Err orString&)> 388 template <FX_BOOL (*F)(IFXJS_Context*, const CJS_Parameters&, CJS_Value&, CFX_Wi deString&)>
397 void JSGlobalFunc(const char *func_name_string, 389 void JSGlobalFunc(const char *func_name_string,
398 const v8::FunctionCallbackInfo<v8::Value>& info) { 390 const v8::FunctionCallbackInfo<v8::Value>& info) {
399 v8::Isolate* isolate = info.GetIsolate(); 391 v8::Isolate* isolate = info.GetIsolate();
400 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2); 392 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2);
401 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); 393 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext();
402 CJS_Parameters parameters; 394 CJS_Parameters parameters;
403 for (unsigned int i = 0; i<(unsigned int)info.Length(); i++) { 395 for (unsigned int i = 0; i<(unsigned int)info.Length(); i++) {
404 parameters.push_back(CJS_Value(isolate, info[i], VT_unknown)); 396 parameters.push_back(CJS_Value(isolate, info[i], VT_unknown));
405 } 397 }
406 CJS_Value valueRes(isolate); 398 CJS_Value valueRes(isolate);
407 JS_ErrorString sError; 399 CFX_WideString sError;
408 if (!(*F)(pRuntimeContext, parameters, valueRes, sError)) 400 if (!(*F)(pRuntimeContext, parameters, valueRes, sError)) {
409 { 401 JS_Error(isolate, JSFormatErrorString(func_name_string, nullptr, sError));
410 JS_Error(NULL, JS_WIDESTRING(fun_name), sError);
411 return; 402 return;
412 } 403 }
413 info.GetReturnValue().Set(valueRes.ToJSValue()); 404 info.GetReturnValue().Set(valueRes.ToJSValue());
414 } 405 }
415 406
416 #define JS_STATIC_GLOBAL_FUN(fun_name) \ 407 #define JS_STATIC_GLOBAL_FUN(fun_name) \
417 static void fun_name##_static(const v8::FunctionCallbackInfo<v8::Value>& info) { \ 408 static void fun_name##_static(const v8::FunctionCallbackInfo<v8::Value>& info) { \
418 JSGlobalFunc<fun_name>(#fun_name, info); \ 409 JSGlobalFunc<fun_name>(#fun_name, info); \
419 } 410 }
420 411
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 #define VALUE_NAME_BOOLEAN L"boolean" 459 #define VALUE_NAME_BOOLEAN L"boolean"
469 #define VALUE_NAME_DATE L"date" 460 #define VALUE_NAME_DATE L"date"
470 #define VALUE_NAME_OBJECT L"object" 461 #define VALUE_NAME_OBJECT L"object"
471 #define VALUE_NAME_FXOBJ L"fxobj" 462 #define VALUE_NAME_FXOBJ L"fxobj"
472 #define VALUE_NAME_NULL L"null" 463 #define VALUE_NAME_NULL L"null"
473 #define VALUE_NAME_UNDEFINED L"undefined" 464 #define VALUE_NAME_UNDEFINED L"undefined"
474 465
475 FXJSVALUETYPE GET_VALUE_TYPE(v8::Handle<v8::Value> p); 466 FXJSVALUETYPE GET_VALUE_TYPE(v8::Handle<v8::Value> p);
476 467
477 #endif //_JS_DEFINE_H_ 468 #endif //_JS_DEFINE_H_
OLDNEW
« no previous file with comments | « fpdfsdk/include/javascript/IJavaScript.h ('k') | fpdfsdk/include/javascript/JS_Object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698