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

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

Issue 963193003: Return error information from pdfium to JS. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Fix scope of c_str() 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
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
10 typedef v8::Value JSValue; 12 typedef v8::Value JSValue;
11 typedef v8::Handle<v8::Object> JSObject; 13 typedef v8::Handle<v8::Object> JSObject;
12 typedef v8::Handle<v8::Object> JSFXObject; 14 typedef v8::Handle<v8::Object> JSFXObject;
13 typedef unsigned JSBool; 15 typedef unsigned JSBool;
14 16
15 #include "JS_Object.h" 17 #include "JS_Object.h"
16 #include "JS_Value.h" 18 #include "JS_Value.h"
17 19
18 struct JSConstSpec 20 struct JSConstSpec
19 { 21 {
(...skipping 10 matching lines...) Expand all
30 v8::AccessorSetterCallback pPropPut; 32 v8::AccessorSetterCallback pPropPut;
31 }; 33 };
32 34
33 struct JSMethodSpec 35 struct JSMethodSpec
34 { 36 {
35 const wchar_t* pName; 37 const wchar_t* pName;
36 v8::FunctionCallback pMethodCall; 38 v8::FunctionCallback pMethodCall;
37 unsigned nParamNum; 39 unsigned nParamNum;
38 }; 40 };
39 41
40 typedef CFX_WideString JS_ErrorString;
41
42 #define JS_TRUE (unsigned)1 42 #define JS_TRUE (unsigned)1
43 #define JS_FALSE (unsigned)0 43 #define JS_FALSE (unsigned)0
44 44
45 typedef CFX_ArrayTemplate<float> CJS_PointsArray; 45 typedef CFX_ArrayTemplate<float> CJS_PointsArray;
46 typedef CFX_ArrayTemplate<int> CJS_IntArray; 46 typedef CFX_ArrayTemplate<int> CJS_IntArray;
47 47
48 typedef CFX_WideString JS_ErrorString;
49
50 namespace {
Lei Zhang 2015/02/28 02:50:49 I don't think this stops anyone that includes JS_D
Tom Sepez 2015/03/02 19:03:44 Argh, yeah, I'm in a header. I'll put this into t
51
52 CFX_WideString FormatErrorString(const char* class_name,
53 const char* property_name,
54 const CFX_WideString& details) {
55 CFX_WideString result = CFX_WideString::FromLocal(class_name);
56 if (property_name) {
57 result += L".";
58 result += CFX_WideString::FromLocal(property_name);
59 }
60 result += L": ";
61 result += details;
62 return result;
63 }
64
65 } // namespace
66
48 /* ====================================== PUBLIC DEFINE SPEC =================== =========================== */ 67 /* ====================================== PUBLIC DEFINE SPEC =================== =========================== */
49 #define JS_WIDESTRING(widestring) L###widestring 68 #define JS_WIDESTRING(widestring) L###widestring
50 69
51 #define BEGIN_JS_STATIC_CONST(js_class_name) JSConstSpec js_class_name::JS_Class _Consts[] = { 70 #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}, 71 #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}, 72 #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}}; 73 #define END_JS_STATIC_CONST() {0, 0, 0, 0}};
55 74
56 #define BEGIN_JS_STATIC_PROP(js_class_name) JSPropertySpec js_class_name::JS_Cla ss_Properties[] = { 75 #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}, 76 #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}}; 77 #define END_JS_STATIC_PROP() {0, 0, 0}};
59 78
60 #define BEGIN_JS_STATIC_METHOD(js_class_name) JSMethodSpec js_class_name::JS_Cla ss_Methods[] = { 79 #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}, 80 #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}}; 81 #define END_JS_STATIC_METHOD() {0, 0, 0}};
63 82
64 /* ======================================== PROP CALLBACK ====================== ====================== */ 83 /* ======================================== PROP CALLBACK ====================== ====================== */
65 84
66 template <class C, FX_BOOL (C::*M)(IFXJS_Context* cc, CJS_PropValue& vp, JS_Erro rString& sError)> 85 template <class C, FX_BOOL (C::*M)(IFXJS_Context* cc, CJS_PropValue& vp, CFX_Wid eString& sError)>
67 void JSPropGetter(const char* prop_name_string, 86 void JSPropGetter(const char* prop_name_string,
68 const char* class_name_string, 87 const char* class_name_string,
69 v8::Local<v8::String> property, 88 v8::Local<v8::String> property,
70 const v8::PropertyCallbackInfo<v8::Value>& info) { 89 const v8::PropertyCallbackInfo<v8::Value>& info) {
71 v8::Isolate* isolate = info.GetIsolate(); 90 v8::Isolate* isolate = info.GetIsolate();
72 v8::Local<v8::Context> context = isolate->GetCurrentContext(); 91 v8::Local<v8::Context> context = isolate->GetCurrentContext();
73 v8::Local<v8::Value> v = context->GetEmbedderData(1); 92 v8::Local<v8::Value> v = context->GetEmbedderData(1);
74 v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(v); 93 v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(v);
75 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); 94 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value();
76 IFXJS_Context* pContext = pRuntime->GetCurrentContext(); 95 IFXJS_Context* pContext = pRuntime->GetCurrentContext();
77 CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder()); 96 CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder());
78 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); 97 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject());
79 JS_ErrorString sError; 98 CFX_WideString sError;
80 CJS_PropValue value(isolate); 99 CJS_PropValue value(isolate);
81 value.StartGetting(); 100 value.StartGetting();
82 if (!(pObj->*M)(pContext, value, sError)) { 101 if (!(pObj->*M)(pContext, value, sError)) {
83 CFX_ByteString cbName; 102 JS_Error(isolate, FormatErrorString(class_name_string, prop_name_string, sEr ror));
84 cbName.Format("%s.%s", class_name_string, prop_name_string);
85 JS_Error(NULL, CFX_WideString::FromLocal(cbName), sError);
86 return; 103 return;
87 } 104 }
88 info.GetReturnValue().Set((v8::Handle<v8::Value>)value); 105 info.GetReturnValue().Set((v8::Handle<v8::Value>)value);
89 } 106 }
90 107
91 template <class C, FX_BOOL (C::*M)(IFXJS_Context* cc, CJS_PropValue& vp, JS_Erro rString& sError)> 108 template <class C, FX_BOOL (C::*M)(IFXJS_Context* cc, CJS_PropValue& vp, CFX_Wid eString& sError)>
92 void JSPropSetter(const char* prop_name_string, 109 void JSPropSetter(const char* prop_name_string,
93 const char* class_name_string, 110 const char* class_name_string,
94 v8::Local<v8::String> property, 111 v8::Local<v8::String> property,
95 v8::Local<v8::Value> value, 112 v8::Local<v8::Value> value,
96 const v8::PropertyCallbackInfo<void>& info) { 113 const v8::PropertyCallbackInfo<void>& info) {
97 v8::Isolate* isolate = info.GetIsolate(); 114 v8::Isolate* isolate = info.GetIsolate();
98 v8::Local<v8::Context> context = isolate->GetCurrentContext(); 115 v8::Local<v8::Context> context = isolate->GetCurrentContext();
99 v8::Local<v8::Value> v = context->GetEmbedderData(1); 116 v8::Local<v8::Value> v = context->GetEmbedderData(1);
100 v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(v); 117 v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(v);
101 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); 118 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value();
102 IFXJS_Context* pContext = pRuntime->GetCurrentContext(); 119 IFXJS_Context* pContext = pRuntime->GetCurrentContext();
103 CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder()); 120 CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder());
104 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); 121 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject());
105 JS_ErrorString sError; 122 CFX_WideString sError;
106 CJS_PropValue propValue(CJS_Value(isolate, value, VT_unknown)); 123 CJS_PropValue propValue(CJS_Value(isolate, value, VT_unknown));
107 propValue.StartSetting(); 124 propValue.StartSetting();
108 if (!(pObj->*M)(pContext, propValue, sError)) { 125 if (!(pObj->*M)(pContext, propValue, sError)) {
109 CFX_ByteString cbName; 126 JS_Error(isolate, FormatErrorString(class_name_string, prop_name_string, s Error));
110 cbName.Format("%s.%s", class_name_string, prop_name_string);
111 JS_Error(NULL, CFX_WideString::FromLocal(cbName), sError);
112 } 127 }
113 } 128 }
114 129
115 #define JS_STATIC_PROP(prop_name, class_name) \ 130 #define JS_STATIC_PROP(prop_name, class_name) \
116 static void get_##prop_name##_static( \ 131 static void get_##prop_name##_static( \
117 v8::Local<v8::String> property, \ 132 v8::Local<v8::String> property, \
118 const v8::PropertyCallbackInfo<v8::Value>& info) { \ 133 const v8::PropertyCallbackInfo<v8::Value>& info) { \
119 JSPropGetter<class_name, &class_name::prop_name>( \ 134 JSPropGetter<class_name, &class_name::prop_name>( \
120 #prop_name, #class_name, property, info); \ 135 #prop_name, #class_name, property, info); \
121 } \ 136 } \
122 static void set_##prop_name##_static( \ 137 static void set_##prop_name##_static( \
123 v8::Local<v8::String> property, \ 138 v8::Local<v8::String> property, \
124 v8::Local<v8::Value> value, \ 139 v8::Local<v8::Value> value, \
125 const v8::PropertyCallbackInfo<void>& info) { \ 140 const v8::PropertyCallbackInfo<void>& info) { \
126 JSPropSetter<class_name, &class_name::prop_name>( \ 141 JSPropSetter<class_name, &class_name::prop_name>( \
127 #prop_name, #class_name, property, value, info); \ 142 #prop_name, #class_name, property, value, info); \
128 } 143 }
129 144
130 /* ========================================= METHOD CALLBACK =================== ======================== */ 145 /* ========================================= METHOD CALLBACK =================== ======================== */
131 146
132 template <class C, FX_BOOL (C::*M)(IFXJS_Context* cc, const CJS_Parameters& para ms, CJS_Value& vRet, JS_ErrorString& sError)> 147 template <class C, FX_BOOL (C::*M)(IFXJS_Context* cc, const CJS_Parameters& para ms, CJS_Value& vRet, CFX_WideString& sError)>
133 void JSMethod(const char* method_name_string, 148 void JSMethod(const char* method_name_string,
134 const char* class_name_string, 149 const char* class_name_string,
135 const v8::FunctionCallbackInfo<v8::Value>& info) { 150 const v8::FunctionCallbackInfo<v8::Value>& info) {
136 v8::Isolate* isolate = info.GetIsolate(); 151 v8::Isolate* isolate = info.GetIsolate();
137 v8::Local<v8::Context> context = isolate->GetCurrentContext(); 152 v8::Local<v8::Context> context = isolate->GetCurrentContext();
138 v8::Local<v8::Value> v = context->GetEmbedderData(1); 153 v8::Local<v8::Value> v = context->GetEmbedderData(1);
139 v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(v); 154 v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(v);
140 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); 155 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value();
141 IFXJS_Context* cc = pRuntime->GetCurrentContext(); 156 IFXJS_Context* cc = pRuntime->GetCurrentContext();
142 CJS_Parameters parameters; 157 CJS_Parameters parameters;
143 for (unsigned int i = 0; i<(unsigned int)info.Length(); i++) { 158 for (unsigned int i = 0; i<(unsigned int)info.Length(); i++) {
144 parameters.push_back(CJS_Value(isolate, info[i], VT_unknown)); 159 parameters.push_back(CJS_Value(isolate, info[i], VT_unknown));
145 } 160 }
146 CJS_Value valueRes(isolate); 161 CJS_Value valueRes(isolate);
147 CJS_Object* pJSObj = (CJS_Object *)JS_GetPrivate(isolate,info.Holder()); 162 CJS_Object* pJSObj = (CJS_Object *)JS_GetPrivate(isolate,info.Holder());
148 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); 163 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject());
149 JS_ErrorString sError; 164 CFX_WideString sError;
150 if (!(pObj->*M)(cc, parameters, valueRes, sError)) { 165 if (!(pObj->*M)(cc, parameters, valueRes, sError)) {
151 CFX_ByteString cbName; 166 JS_Error(isolate, FormatErrorString(class_name_string, method_name_string, sError));
152 cbName.Format("%s.%s", class_name_string, method_name_string);
153 JS_Error(NULL, CFX_WideString::FromLocal(cbName), sError);
154 return; 167 return;
155 } 168 }
156 info.GetReturnValue().Set(valueRes.ToJSValue()); 169 info.GetReturnValue().Set(valueRes.ToJSValue());
157 } 170 }
158 171
159 #define JS_STATIC_METHOD(method_name, class_name) \ 172 #define JS_STATIC_METHOD(method_name, class_name) \
160 static void method_name##_static( \ 173 static void method_name##_static( \
161 const v8::FunctionCallbackInfo<v8::Value>& info) { \ 174 const v8::FunctionCallbackInfo<v8::Value>& info) { \
162 JSMethod<class_name, &class_name::method_name>( \ 175 JSMethod<class_name, &class_name::method_name>( \
163 #class_name, #method_name, info); \ 176 #method_name, #class_name, info); \
164 } 177 }
165 178
166 #define JS_SPECIAL_STATIC_METHOD(method_name, class_alternate, class_name) \ 179 #define JS_SPECIAL_STATIC_METHOD(method_name, class_alternate, class_name) \
167 static void method_name##_static( \ 180 static void method_name##_static( \
168 const v8::FunctionCallbackInfo<v8::Value>& info) { \ 181 const v8::FunctionCallbackInfo<v8::Value>& info) { \
169 JSMethod<class_alternate, &class_alternate::method_name>( \ 182 JSMethod<class_alternate, &class_alternate::method_name>( \
170 #class_name, #method_name, info); \ 183 #method_name, #class_name, info); \
171 } 184 }
172 185
173 /* ===================================== JS CLASS ============================== ================= */ 186 /* ===================================== JS CLASS ============================== ================= */
174 187
175 #define DECLARE_JS_CLASS(js_class_name) \ 188 #define DECLARE_JS_CLASS(js_class_name) \
176 static JSBool JSConstructor(IFXJS_Context* cc, JSFXObject obj,JSFXObject global);\ 189 static JSBool JSConstructor(IFXJS_Context* cc, JSFXObject obj,JSFXObject global);\
177 static JSBool JSDestructor(JSFXObject obj);\ 190 static JSBool JSDestructor(JSFXObject obj);\
178 static int Init(IJS_Runtime* pRuntime, FXJSOBJTYPE eObjType);\ 191 static int Init(IJS_Runtime* pRuntime, FXJSOBJTYPE eObjType);\
179 static JSConstSpec JS_Class_Consts[];\ 192 static JSConstSpec JS_Class_Consts[];\
180 static JSPropertySpec JS_Class_Properties[];\ 193 static JSPropertySpec JS_Class_Properties[];\
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 v8::Isolate* isolate = info.GetIsolate(); 284 v8::Isolate* isolate = info.GetIsolate();
272 v8::Local<v8::Context> context = isolate->GetCurrentContext(); 285 v8::Local<v8::Context> context = isolate->GetCurrentContext();
273 v8::Local<v8::Value> v = context->GetEmbedderData(1); 286 v8::Local<v8::Value> v = context->GetEmbedderData(1);
274 v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(v); 287 v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(v);
275 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); 288 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value();
276 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); 289 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext();
277 CJS_Object* pJSObj = reinterpret_cast<CJS_Object*>(JS_GetPrivate(isolate, info .Holder())); 290 CJS_Object* pJSObj = reinterpret_cast<CJS_Object*>(JS_GetPrivate(isolate, info .Holder()));
278 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); 291 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject());
279 v8::String::Utf8Value utf8_value(property); 292 v8::String::Utf8Value utf8_value(property);
280 CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_value.len gth()); 293 CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_value.len gth());
281 JS_ErrorString sError; 294 CFX_WideString sError;
282 CJS_PropValue value(isolate); 295 CJS_PropValue value(isolate);
283 value.StartGetting(); 296 value.StartGetting();
284 if (!pObj->DoProperty(pRuntimeContext, propname.c_str(), value, sError)) { 297 if (!pObj->DoProperty(pRuntimeContext, propname.c_str(), value, sError)) {
285 CFX_ByteString cbName; 298 JS_Error(isolate, FormatErrorString(class_name, "GetProperty", sError));
286 cbName.Format("%s.%s", class_name, L"GetProperty"); 299 return;
287 JS_Error(NULL,CFX_WideString::FromLocal(cbName), sError);
288 return;
289 } 300 }
290 info.GetReturnValue().Set((v8::Handle<v8::Value>)value); 301 info.GetReturnValue().Set((v8::Handle<v8::Value>)value);
291 } 302 }
292 303
293 template <class Alt> 304 template <class Alt>
294 void JSSpecialPropPut(const char* class_name, 305 void JSSpecialPropPut(const char* class_name,
295 v8::Local<v8::String> property, 306 v8::Local<v8::String> property,
296 v8::Local<v8::Value> value, 307 v8::Local<v8::Value> value,
297 const v8::PropertyCallbackInfo<v8::Value>& info) { 308 const v8::PropertyCallbackInfo<v8::Value>& info) {
298 v8::Isolate* isolate = info.GetIsolate(); 309 v8::Isolate* isolate = info.GetIsolate();
299 v8::Local<v8::Context> context = isolate->GetCurrentContext(); 310 v8::Local<v8::Context> context = isolate->GetCurrentContext();
300 v8::Local<v8::Value> v = context->GetEmbedderData(1); 311 v8::Local<v8::Value> v = context->GetEmbedderData(1);
301 v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(v); 312 v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(v);
302 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); 313 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value();
303 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); 314 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext();
304 CJS_Object* pJSObj = reinterpret_cast<CJS_Object*>(JS_GetPrivate(isolate, info .Holder())); 315 CJS_Object* pJSObj = reinterpret_cast<CJS_Object*>(JS_GetPrivate(isolate, info .Holder()));
305 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); 316 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject());
306 v8::String::Utf8Value utf8_value(property); 317 v8::String::Utf8Value utf8_value(property);
307 CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_value.len gth()); 318 CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_value.len gth());
308 JS_ErrorString sError; 319 CFX_WideString sError;
309 CJS_PropValue PropValue(CJS_Value(isolate,value,VT_unknown)); 320 CJS_PropValue PropValue(CJS_Value(isolate,value,VT_unknown));
310 PropValue.StartSetting(); 321 PropValue.StartSetting();
311 if (!pObj->DoProperty(pRuntimeContext, propname.c_str(), PropValue, sError)) { 322 if (!pObj->DoProperty(pRuntimeContext, propname.c_str(), PropValue, sError)) {
312 CFX_ByteString cbName; 323 JS_Error(isolate, FormatErrorString(class_name, "PutProperty", sError));
313 cbName.Format("%s.%s", class_name, "PutProperty");
314 JS_Error(NULL,CFX_WideString::FromLocal(cbName), sError);
315 } 324 }
316 } 325 }
317 326
318 template <class Alt> 327 template <class Alt>
319 void JSSpecialPropDel(const char* class_name, 328 void JSSpecialPropDel(const char* class_name,
320 v8::Local<v8::String> property, 329 v8::Local<v8::String> property,
321 const v8::PropertyCallbackInfo<v8::Boolean>& info) { 330 const v8::PropertyCallbackInfo<v8::Boolean>& info) {
322 v8::Isolate* isolate = info.GetIsolate(); 331 v8::Isolate* isolate = info.GetIsolate();
323 v8::Local<v8::Context> context = isolate->GetCurrentContext(); 332 v8::Local<v8::Context> context = isolate->GetCurrentContext();
324 v8::Local<v8::Value> v = context->GetEmbedderData(1); 333 v8::Local<v8::Value> v = context->GetEmbedderData(1);
325 v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(v); 334 v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(v);
326 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); 335 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value();
327 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); 336 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext();
328 CJS_Object* pJSObj = reinterpret_cast<CJS_Object*>(JS_GetPrivate(isolate, info .Holder())); 337 CJS_Object* pJSObj = reinterpret_cast<CJS_Object*>(JS_GetPrivate(isolate, info .Holder()));
329 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); 338 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject());
330 v8::String::Utf8Value utf8_value(property); 339 v8::String::Utf8Value utf8_value(property);
331 CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_value.len gth()); 340 CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_value.len gth());
332 JS_ErrorString sError; 341 CFX_WideString sError;
333 if (!pObj->DelProperty(pRuntimeContext, propname.c_str(), sError)) { 342 if (!pObj->DelProperty(pRuntimeContext, propname.c_str(), sError)) {
334 CFX_ByteString cbName; 343 CFX_ByteString cbName;
335 cbName.Format("%s.%s", class_name, "DelProperty"); 344 cbName.Format("%s.%s", class_name, "DelProperty");
336 // Probably a missing call to JS_Error(). 345 // Probably a missing call to JS_Error().
337 } 346 }
338 } 347 }
339 348
340 #define DECLARE_SPECIAL_JS_CLASS(js_class_name) \ 349 #define DECLARE_SPECIAL_JS_CLASS(js_class_name) \
341 static JSBool JSConstructor(IFXJS_Context* cc, JSFXObject obj, JSFXObjec t global);\ 350 static JSBool JSConstructor(IFXJS_Context* cc, JSFXObject obj, JSFXObjec t global);\
342 static JSBool JSDestructor(JSFXObject obj);\ 351 static JSBool JSDestructor(JSFXObject obj);\
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 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;\ 410 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;\
402 \ 411 \
403 return nObjDefnID;\ 412 return nObjDefnID;\
404 }\ 413 }\
405 \ 414 \
406 return -1;\ 415 return -1;\
407 } 416 }
408 417
409 /* ======================================== GLOBAL METHODS ===================== ======================= */ 418 /* ======================================== GLOBAL METHODS ===================== ======================= */
410 419
411 template <FX_BOOL (*F)(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Valu e& vRet, JS_ErrorString& sError)> 420 template <FX_BOOL (*F)(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Valu e& vRet, CFX_WideString& sError)>
412 void JSGlobalFunc(const char *func_name_string, 421 void JSGlobalFunc(const char *func_name_string,
413 const v8::FunctionCallbackInfo<v8::Value>& info) { 422 const v8::FunctionCallbackInfo<v8::Value>& info) {
414 v8::Isolate* isolate = info.GetIsolate(); 423 v8::Isolate* isolate = info.GetIsolate();
415 v8::Local<v8::Context> context = isolate->GetCurrentContext(); 424 v8::Local<v8::Context> context = isolate->GetCurrentContext();
416 v8::Local<v8::Value> v = context->GetEmbedderData(1); 425 v8::Local<v8::Value> v = context->GetEmbedderData(1);
417 v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(v); 426 v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(v);
418 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); 427 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value();
419 IFXJS_Context* cc = pRuntime->GetCurrentContext(); 428 IFXJS_Context* cc = pRuntime->GetCurrentContext();
420 CJS_Parameters parameters; 429 CJS_Parameters parameters;
421 for (unsigned int i = 0; i<(unsigned int)info.Length(); i++) { 430 for (unsigned int i = 0; i<(unsigned int)info.Length(); i++) {
422 parameters.push_back(CJS_Value(isolate, info[i], VT_unknown)); 431 parameters.push_back(CJS_Value(isolate, info[i], VT_unknown));
423 } 432 }
424 CJS_Value valueRes(isolate); 433 CJS_Value valueRes(isolate);
425 JS_ErrorString sError; 434 CFX_WideString sError;
426 if (!(*F)(cc, parameters, valueRes, sError)) 435 if (!(*F)(cc, parameters, valueRes, sError))
427 { 436 {
428 JS_Error(NULL, JS_WIDESTRING(fun_name), sError); 437 JS_Error(isolate, FormatErrorString(func_name_string, nullptr, sError));
429 return; 438 return;
430 } 439 }
431 info.GetReturnValue().Set(valueRes.ToJSValue()); 440 info.GetReturnValue().Set(valueRes.ToJSValue());
432 } 441 }
433 442
434 #define JS_STATIC_GLOBAL_FUN(fun_name) \ 443 #define JS_STATIC_GLOBAL_FUN(fun_name) \
435 static void fun_name##_static(const v8::FunctionCallbackInfo<v8::Value>& info) { \ 444 static void fun_name##_static(const v8::FunctionCallbackInfo<v8::Value>& info) { \
436 JSGlobalFunc<fun_name>(#fun_name, info); \ 445 JSGlobalFunc<fun_name>(#fun_name, info); \
437 } 446 }
438 447
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 #define VALUE_NAME_BOOLEAN L"boolean" 495 #define VALUE_NAME_BOOLEAN L"boolean"
487 #define VALUE_NAME_DATE L"date" 496 #define VALUE_NAME_DATE L"date"
488 #define VALUE_NAME_OBJECT L"object" 497 #define VALUE_NAME_OBJECT L"object"
489 #define VALUE_NAME_FXOBJ L"fxobj" 498 #define VALUE_NAME_FXOBJ L"fxobj"
490 #define VALUE_NAME_NULL L"null" 499 #define VALUE_NAME_NULL L"null"
491 #define VALUE_NAME_UNDEFINED L"undefined" 500 #define VALUE_NAME_UNDEFINED L"undefined"
492 501
493 FXJSVALUETYPE GET_VALUE_TYPE(v8::Handle<v8::Value> p); 502 FXJSVALUETYPE GET_VALUE_TYPE(v8::Handle<v8::Value> p);
494 503
495 #endif //_JS_DEFINE_H_ 504 #endif //_JS_DEFINE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698