OLD | NEW |
---|---|
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 Loading... | |
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; | 43 typedef CFX_WideString JS_ErrorString; |
Lei Zhang
2015/03/02 20:13:13
I thought you were going to move this down to line
| |
41 | 44 |
42 #define JS_TRUE (unsigned)1 | 45 #define JS_TRUE (unsigned)1 |
43 #define JS_FALSE (unsigned)0 | 46 #define JS_FALSE (unsigned)0 |
44 | 47 |
45 typedef CFX_ArrayTemplate<float> CJS_PointsArray; | 48 typedef CFX_ArrayTemplate<float> CJS_PointsArray; |
46 typedef CFX_ArrayTemplate<int> CJS_IntArray; | 49 typedef CFX_ArrayTemplate<int> CJS_IntArray; |
47 | 50 |
48 /* ====================================== PUBLIC DEFINE SPEC =================== =========================== */ | 51 /* ====================================== PUBLIC DEFINE SPEC =================== =========================== */ |
49 #define JS_WIDESTRING(widestring) L###widestring | 52 #define JS_WIDESTRING(widestring) L###widestring |
50 | 53 |
51 #define BEGIN_JS_STATIC_CONST(js_class_name) JSConstSpec js_class_name::JS_Class _Consts[] = { | 54 #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}, | 55 #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}, | 56 #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}}; | 57 #define END_JS_STATIC_CONST() {0, 0, 0, 0}}; |
55 | 58 |
56 #define BEGIN_JS_STATIC_PROP(js_class_name) JSPropertySpec js_class_name::JS_Cla ss_Properties[] = { | 59 #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}, | 60 #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}}; | 61 #define END_JS_STATIC_PROP() {0, 0, 0}}; |
59 | 62 |
60 #define BEGIN_JS_STATIC_METHOD(js_class_name) JSMethodSpec js_class_name::JS_Cla ss_Methods[] = { | 63 #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}, | 64 #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}}; | 65 #define END_JS_STATIC_METHOD() {0, 0, 0}}; |
63 | 66 |
64 /* ======================================== PROP CALLBACK ====================== ====================== */ | 67 /* ======================================== PROP CALLBACK ====================== ====================== */ |
65 | 68 |
66 template <class C, FX_BOOL (C::*M)(IFXJS_Context* cc, CJS_PropValue& vp, JS_Erro rString& sError)> | 69 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, | 70 void JSPropGetter(const char* prop_name_string, |
68 const char* class_name_string, | 71 const char* class_name_string, |
69 v8::Local<v8::String> property, | 72 v8::Local<v8::String> property, |
70 const v8::PropertyCallbackInfo<v8::Value>& info) { | 73 const v8::PropertyCallbackInfo<v8::Value>& info) { |
71 v8::Isolate* isolate = info.GetIsolate(); | 74 v8::Isolate* isolate = info.GetIsolate(); |
72 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 75 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
73 v8::Local<v8::Value> v = context->GetEmbedderData(1); | 76 v8::Local<v8::Value> v = context->GetEmbedderData(1); |
74 v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(v); | 77 v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(v); |
75 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); | 78 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); |
76 IFXJS_Context* pContext = pRuntime->GetCurrentContext(); | 79 IFXJS_Context* pContext = pRuntime->GetCurrentContext(); |
77 CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder()); | 80 CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder()); |
78 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); | 81 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); |
79 JS_ErrorString sError; | 82 CFX_WideString sError; |
80 CJS_PropValue value(isolate); | 83 CJS_PropValue value(isolate); |
81 value.StartGetting(); | 84 value.StartGetting(); |
82 if (!(pObj->*M)(pContext, value, sError)) { | 85 if (!(pObj->*M)(pContext, value, sError)) { |
83 CFX_ByteString cbName; | 86 JS_Error(isolate, JSFormatErrorString(class_name_string, prop_name_string, s Error)); |
84 cbName.Format("%s.%s", class_name_string, prop_name_string); | |
85 JS_Error(NULL, CFX_WideString::FromLocal(cbName), sError); | |
86 return; | 87 return; |
87 } | 88 } |
88 info.GetReturnValue().Set((v8::Handle<v8::Value>)value); | 89 info.GetReturnValue().Set((v8::Handle<v8::Value>)value); |
89 } | 90 } |
90 | 91 |
91 template <class C, FX_BOOL (C::*M)(IFXJS_Context* cc, CJS_PropValue& vp, JS_Erro rString& sError)> | 92 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, | 93 void JSPropSetter(const char* prop_name_string, |
93 const char* class_name_string, | 94 const char* class_name_string, |
94 v8::Local<v8::String> property, | 95 v8::Local<v8::String> property, |
95 v8::Local<v8::Value> value, | 96 v8::Local<v8::Value> value, |
96 const v8::PropertyCallbackInfo<void>& info) { | 97 const v8::PropertyCallbackInfo<void>& info) { |
97 v8::Isolate* isolate = info.GetIsolate(); | 98 v8::Isolate* isolate = info.GetIsolate(); |
98 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 99 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
99 v8::Local<v8::Value> v = context->GetEmbedderData(1); | 100 v8::Local<v8::Value> v = context->GetEmbedderData(1); |
100 v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(v); | 101 v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(v); |
101 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); | 102 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); |
102 IFXJS_Context* pContext = pRuntime->GetCurrentContext(); | 103 IFXJS_Context* pContext = pRuntime->GetCurrentContext(); |
103 CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder()); | 104 CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder()); |
104 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); | 105 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); |
105 JS_ErrorString sError; | 106 CFX_WideString sError; |
106 CJS_PropValue propValue(CJS_Value(isolate, value, VT_unknown)); | 107 CJS_PropValue propValue(CJS_Value(isolate, value, VT_unknown)); |
107 propValue.StartSetting(); | 108 propValue.StartSetting(); |
108 if (!(pObj->*M)(pContext, propValue, sError)) { | 109 if (!(pObj->*M)(pContext, propValue, sError)) { |
109 CFX_ByteString cbName; | 110 JS_Error(isolate, JSFormatErrorString(class_name_string, prop_name_string, sError)); |
110 cbName.Format("%s.%s", class_name_string, prop_name_string); | |
111 JS_Error(NULL, CFX_WideString::FromLocal(cbName), sError); | |
112 } | 111 } |
113 } | 112 } |
114 | 113 |
115 #define JS_STATIC_PROP(prop_name, class_name) \ | 114 #define JS_STATIC_PROP(prop_name, class_name) \ |
116 static void get_##prop_name##_static( \ | 115 static void get_##prop_name##_static( \ |
117 v8::Local<v8::String> property, \ | 116 v8::Local<v8::String> property, \ |
118 const v8::PropertyCallbackInfo<v8::Value>& info) { \ | 117 const v8::PropertyCallbackInfo<v8::Value>& info) { \ |
119 JSPropGetter<class_name, &class_name::prop_name>( \ | 118 JSPropGetter<class_name, &class_name::prop_name>( \ |
120 #prop_name, #class_name, property, info); \ | 119 #prop_name, #class_name, property, info); \ |
121 } \ | 120 } \ |
122 static void set_##prop_name##_static( \ | 121 static void set_##prop_name##_static( \ |
123 v8::Local<v8::String> property, \ | 122 v8::Local<v8::String> property, \ |
124 v8::Local<v8::Value> value, \ | 123 v8::Local<v8::Value> value, \ |
125 const v8::PropertyCallbackInfo<void>& info) { \ | 124 const v8::PropertyCallbackInfo<void>& info) { \ |
126 JSPropSetter<class_name, &class_name::prop_name>( \ | 125 JSPropSetter<class_name, &class_name::prop_name>( \ |
127 #prop_name, #class_name, property, value, info); \ | 126 #prop_name, #class_name, property, value, info); \ |
128 } | 127 } |
129 | 128 |
130 /* ========================================= METHOD CALLBACK =================== ======================== */ | 129 /* ========================================= METHOD CALLBACK =================== ======================== */ |
131 | 130 |
132 template <class C, FX_BOOL (C::*M)(IFXJS_Context* cc, const CJS_Parameters& para ms, CJS_Value& vRet, JS_ErrorString& sError)> | 131 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, | 132 void JSMethod(const char* method_name_string, |
134 const char* class_name_string, | 133 const char* class_name_string, |
135 const v8::FunctionCallbackInfo<v8::Value>& info) { | 134 const v8::FunctionCallbackInfo<v8::Value>& info) { |
136 v8::Isolate* isolate = info.GetIsolate(); | 135 v8::Isolate* isolate = info.GetIsolate(); |
137 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 136 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
138 v8::Local<v8::Value> v = context->GetEmbedderData(1); | 137 v8::Local<v8::Value> v = context->GetEmbedderData(1); |
139 v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(v); | 138 v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(v); |
140 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); | 139 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); |
141 IFXJS_Context* cc = pRuntime->GetCurrentContext(); | 140 IFXJS_Context* cc = pRuntime->GetCurrentContext(); |
142 CJS_Parameters parameters; | 141 CJS_Parameters parameters; |
143 for (unsigned int i = 0; i<(unsigned int)info.Length(); i++) { | 142 for (unsigned int i = 0; i<(unsigned int)info.Length(); i++) { |
144 parameters.push_back(CJS_Value(isolate, info[i], VT_unknown)); | 143 parameters.push_back(CJS_Value(isolate, info[i], VT_unknown)); |
145 } | 144 } |
146 CJS_Value valueRes(isolate); | 145 CJS_Value valueRes(isolate); |
147 CJS_Object* pJSObj = (CJS_Object *)JS_GetPrivate(isolate,info.Holder()); | 146 CJS_Object* pJSObj = (CJS_Object *)JS_GetPrivate(isolate,info.Holder()); |
148 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); | 147 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); |
149 JS_ErrorString sError; | 148 CFX_WideString sError; |
150 if (!(pObj->*M)(cc, parameters, valueRes, sError)) { | 149 if (!(pObj->*M)(cc, parameters, valueRes, sError)) { |
151 CFX_ByteString cbName; | 150 JS_Error(isolate, JSFormatErrorString(class_name_string, method_name_strin g, sError)); |
152 cbName.Format("%s.%s", class_name_string, method_name_string); | |
153 JS_Error(NULL, CFX_WideString::FromLocal(cbName), sError); | |
154 return; | 151 return; |
155 } | 152 } |
156 info.GetReturnValue().Set(valueRes.ToJSValue()); | 153 info.GetReturnValue().Set(valueRes.ToJSValue()); |
157 } | 154 } |
158 | 155 |
159 #define JS_STATIC_METHOD(method_name, class_name) \ | 156 #define JS_STATIC_METHOD(method_name, class_name) \ |
160 static void method_name##_static( \ | 157 static void method_name##_static( \ |
161 const v8::FunctionCallbackInfo<v8::Value>& info) { \ | 158 const v8::FunctionCallbackInfo<v8::Value>& info) { \ |
162 JSMethod<class_name, &class_name::method_name>( \ | 159 JSMethod<class_name, &class_name::method_name>( \ |
163 #class_name, #method_name, info); \ | 160 #method_name, #class_name, info); \ |
164 } | 161 } |
165 | 162 |
166 #define JS_SPECIAL_STATIC_METHOD(method_name, class_alternate, class_name) \ | 163 #define JS_SPECIAL_STATIC_METHOD(method_name, class_alternate, class_name) \ |
167 static void method_name##_static( \ | 164 static void method_name##_static( \ |
168 const v8::FunctionCallbackInfo<v8::Value>& info) { \ | 165 const v8::FunctionCallbackInfo<v8::Value>& info) { \ |
169 JSMethod<class_alternate, &class_alternate::method_name>( \ | 166 JSMethod<class_alternate, &class_alternate::method_name>( \ |
170 #class_name, #method_name, info); \ | 167 #method_name, #class_name, info); \ |
171 } | 168 } |
172 | 169 |
173 /* ===================================== JS CLASS ============================== ================= */ | 170 /* ===================================== JS CLASS ============================== ================= */ |
174 | 171 |
175 #define DECLARE_JS_CLASS(js_class_name) \ | 172 #define DECLARE_JS_CLASS(js_class_name) \ |
176 static JSBool JSConstructor(IFXJS_Context* cc, JSFXObject obj,JSFXObject global);\ | 173 static JSBool JSConstructor(IFXJS_Context* cc, JSFXObject obj,JSFXObject global);\ |
177 static JSBool JSDestructor(JSFXObject obj);\ | 174 static JSBool JSDestructor(JSFXObject obj);\ |
178 static int Init(IJS_Runtime* pRuntime, FXJSOBJTYPE eObjType);\ | 175 static int Init(IJS_Runtime* pRuntime, FXJSOBJTYPE eObjType);\ |
179 static JSConstSpec JS_Class_Consts[];\ | 176 static JSConstSpec JS_Class_Consts[];\ |
180 static JSPropertySpec JS_Class_Properties[];\ | 177 static JSPropertySpec JS_Class_Properties[];\ |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
271 v8::Isolate* isolate = info.GetIsolate(); | 268 v8::Isolate* isolate = info.GetIsolate(); |
272 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 269 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
273 v8::Local<v8::Value> v = context->GetEmbedderData(1); | 270 v8::Local<v8::Value> v = context->GetEmbedderData(1); |
274 v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(v); | 271 v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(v); |
275 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); | 272 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); |
276 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); | 273 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); |
277 CJS_Object* pJSObj = reinterpret_cast<CJS_Object*>(JS_GetPrivate(isolate, info .Holder())); | 274 CJS_Object* pJSObj = reinterpret_cast<CJS_Object*>(JS_GetPrivate(isolate, info .Holder())); |
278 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); | 275 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); |
279 v8::String::Utf8Value utf8_value(property); | 276 v8::String::Utf8Value utf8_value(property); |
280 CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_value.len gth()); | 277 CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_value.len gth()); |
281 JS_ErrorString sError; | 278 CFX_WideString sError; |
282 CJS_PropValue value(isolate); | 279 CJS_PropValue value(isolate); |
283 value.StartGetting(); | 280 value.StartGetting(); |
284 if (!pObj->DoProperty(pRuntimeContext, propname.c_str(), value, sError)) { | 281 if (!pObj->DoProperty(pRuntimeContext, propname.c_str(), value, sError)) { |
285 CFX_ByteString cbName; | 282 JS_Error(isolate, JSFormatErrorString(class_name, "GetProperty", sError)); |
286 cbName.Format("%s.%s", class_name, L"GetProperty"); | 283 return; |
287 JS_Error(NULL,CFX_WideString::FromLocal(cbName), sError); | |
288 return; | |
289 } | 284 } |
290 info.GetReturnValue().Set((v8::Handle<v8::Value>)value); | 285 info.GetReturnValue().Set((v8::Handle<v8::Value>)value); |
291 } | 286 } |
292 | 287 |
293 template <class Alt> | 288 template <class Alt> |
294 void JSSpecialPropPut(const char* class_name, | 289 void JSSpecialPropPut(const char* class_name, |
295 v8::Local<v8::String> property, | 290 v8::Local<v8::String> property, |
296 v8::Local<v8::Value> value, | 291 v8::Local<v8::Value> value, |
297 const v8::PropertyCallbackInfo<v8::Value>& info) { | 292 const v8::PropertyCallbackInfo<v8::Value>& info) { |
298 v8::Isolate* isolate = info.GetIsolate(); | 293 v8::Isolate* isolate = info.GetIsolate(); |
299 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 294 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
300 v8::Local<v8::Value> v = context->GetEmbedderData(1); | 295 v8::Local<v8::Value> v = context->GetEmbedderData(1); |
301 v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(v); | 296 v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(v); |
302 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); | 297 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); |
303 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); | 298 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); |
304 CJS_Object* pJSObj = reinterpret_cast<CJS_Object*>(JS_GetPrivate(isolate, info .Holder())); | 299 CJS_Object* pJSObj = reinterpret_cast<CJS_Object*>(JS_GetPrivate(isolate, info .Holder())); |
305 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); | 300 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); |
306 v8::String::Utf8Value utf8_value(property); | 301 v8::String::Utf8Value utf8_value(property); |
307 CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_value.len gth()); | 302 CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_value.len gth()); |
308 JS_ErrorString sError; | 303 CFX_WideString sError; |
309 CJS_PropValue PropValue(CJS_Value(isolate,value,VT_unknown)); | 304 CJS_PropValue PropValue(CJS_Value(isolate,value,VT_unknown)); |
310 PropValue.StartSetting(); | 305 PropValue.StartSetting(); |
311 if (!pObj->DoProperty(pRuntimeContext, propname.c_str(), PropValue, sError)) { | 306 if (!pObj->DoProperty(pRuntimeContext, propname.c_str(), PropValue, sError)) { |
312 CFX_ByteString cbName; | 307 JS_Error(isolate, JSFormatErrorString(class_name, "PutProperty", sError)); |
313 cbName.Format("%s.%s", class_name, "PutProperty"); | |
314 JS_Error(NULL,CFX_WideString::FromLocal(cbName), sError); | |
315 } | 308 } |
316 } | 309 } |
317 | 310 |
318 template <class Alt> | 311 template <class Alt> |
319 void JSSpecialPropDel(const char* class_name, | 312 void JSSpecialPropDel(const char* class_name, |
320 v8::Local<v8::String> property, | 313 v8::Local<v8::String> property, |
321 const v8::PropertyCallbackInfo<v8::Boolean>& info) { | 314 const v8::PropertyCallbackInfo<v8::Boolean>& info) { |
322 v8::Isolate* isolate = info.GetIsolate(); | 315 v8::Isolate* isolate = info.GetIsolate(); |
323 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 316 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
324 v8::Local<v8::Value> v = context->GetEmbedderData(1); | 317 v8::Local<v8::Value> v = context->GetEmbedderData(1); |
325 v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(v); | 318 v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(v); |
326 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); | 319 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); |
327 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); | 320 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); |
328 CJS_Object* pJSObj = reinterpret_cast<CJS_Object*>(JS_GetPrivate(isolate, info .Holder())); | 321 CJS_Object* pJSObj = reinterpret_cast<CJS_Object*>(JS_GetPrivate(isolate, info .Holder())); |
329 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); | 322 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); |
330 v8::String::Utf8Value utf8_value(property); | 323 v8::String::Utf8Value utf8_value(property); |
331 CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_value.len gth()); | 324 CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_value.len gth()); |
332 JS_ErrorString sError; | 325 CFX_WideString sError; |
333 if (!pObj->DelProperty(pRuntimeContext, propname.c_str(), sError)) { | 326 if (!pObj->DelProperty(pRuntimeContext, propname.c_str(), sError)) { |
334 CFX_ByteString cbName; | 327 CFX_ByteString cbName; |
335 cbName.Format("%s.%s", class_name, "DelProperty"); | 328 cbName.Format("%s.%s", class_name, "DelProperty"); |
336 // Probably a missing call to JS_Error(). | 329 // Probably a missing call to JS_Error(). |
337 } | 330 } |
338 } | 331 } |
339 | 332 |
340 #define DECLARE_SPECIAL_JS_CLASS(js_class_name) \ | 333 #define DECLARE_SPECIAL_JS_CLASS(js_class_name) \ |
341 static JSBool JSConstructor(IFXJS_Context* cc, JSFXObject obj, JSFXObjec t global);\ | 334 static JSBool JSConstructor(IFXJS_Context* cc, JSFXObject obj, JSFXObjec t global);\ |
342 static JSBool JSDestructor(JSFXObject obj);\ | 335 static JSBool JSDestructor(JSFXObject obj);\ |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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;\ | 394 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 \ | 395 \ |
403 return nObjDefnID;\ | 396 return nObjDefnID;\ |
404 }\ | 397 }\ |
405 \ | 398 \ |
406 return -1;\ | 399 return -1;\ |
407 } | 400 } |
408 | 401 |
409 /* ======================================== GLOBAL METHODS ===================== ======================= */ | 402 /* ======================================== GLOBAL METHODS ===================== ======================= */ |
410 | 403 |
411 template <FX_BOOL (*F)(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Valu e& vRet, JS_ErrorString& sError)> | 404 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, | 405 void JSGlobalFunc(const char *func_name_string, |
413 const v8::FunctionCallbackInfo<v8::Value>& info) { | 406 const v8::FunctionCallbackInfo<v8::Value>& info) { |
414 v8::Isolate* isolate = info.GetIsolate(); | 407 v8::Isolate* isolate = info.GetIsolate(); |
415 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 408 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
416 v8::Local<v8::Value> v = context->GetEmbedderData(1); | 409 v8::Local<v8::Value> v = context->GetEmbedderData(1); |
417 v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(v); | 410 v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(v); |
418 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); | 411 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); |
419 IFXJS_Context* cc = pRuntime->GetCurrentContext(); | 412 IFXJS_Context* cc = pRuntime->GetCurrentContext(); |
420 CJS_Parameters parameters; | 413 CJS_Parameters parameters; |
421 for (unsigned int i = 0; i<(unsigned int)info.Length(); i++) { | 414 for (unsigned int i = 0; i<(unsigned int)info.Length(); i++) { |
422 parameters.push_back(CJS_Value(isolate, info[i], VT_unknown)); | 415 parameters.push_back(CJS_Value(isolate, info[i], VT_unknown)); |
423 } | 416 } |
424 CJS_Value valueRes(isolate); | 417 CJS_Value valueRes(isolate); |
425 JS_ErrorString sError; | 418 CFX_WideString sError; |
426 if (!(*F)(cc, parameters, valueRes, sError)) | 419 if (!(*F)(cc, parameters, valueRes, sError)) |
427 { | 420 { |
428 JS_Error(NULL, JS_WIDESTRING(fun_name), sError); | 421 JS_Error(isolate, JSFormatErrorString(func_name_string, nullptr, sError)); |
429 return; | 422 return; |
430 } | 423 } |
431 info.GetReturnValue().Set(valueRes.ToJSValue()); | 424 info.GetReturnValue().Set(valueRes.ToJSValue()); |
432 } | 425 } |
433 | 426 |
434 #define JS_STATIC_GLOBAL_FUN(fun_name) \ | 427 #define JS_STATIC_GLOBAL_FUN(fun_name) \ |
435 static void fun_name##_static(const v8::FunctionCallbackInfo<v8::Value>& info) { \ | 428 static void fun_name##_static(const v8::FunctionCallbackInfo<v8::Value>& info) { \ |
436 JSGlobalFunc<fun_name>(#fun_name, info); \ | 429 JSGlobalFunc<fun_name>(#fun_name, info); \ |
437 } | 430 } |
438 | 431 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
486 #define VALUE_NAME_BOOLEAN L"boolean" | 479 #define VALUE_NAME_BOOLEAN L"boolean" |
487 #define VALUE_NAME_DATE L"date" | 480 #define VALUE_NAME_DATE L"date" |
488 #define VALUE_NAME_OBJECT L"object" | 481 #define VALUE_NAME_OBJECT L"object" |
489 #define VALUE_NAME_FXOBJ L"fxobj" | 482 #define VALUE_NAME_FXOBJ L"fxobj" |
490 #define VALUE_NAME_NULL L"null" | 483 #define VALUE_NAME_NULL L"null" |
491 #define VALUE_NAME_UNDEFINED L"undefined" | 484 #define VALUE_NAME_UNDEFINED L"undefined" |
492 | 485 |
493 FXJSVALUETYPE GET_VALUE_TYPE(v8::Handle<v8::Value> p); | 486 FXJSVALUETYPE GET_VALUE_TYPE(v8::Handle<v8::Value> p); |
494 | 487 |
495 #endif //_JS_DEFINE_H_ | 488 #endif //_JS_DEFINE_H_ |
OLD | NEW |