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 typedef v8::Value JSValue; | 10 typedef v8::Value JSValue; |
11 typedef v8::Handle<v8::Object> JSObject; | 11 typedef v8::Handle<v8::Object> JSObject; |
12 typedef v8::Handle<v8::Object> JSFXObject; | 12 typedef v8::Handle<v8::Object> JSFXObject; |
13 typedef unsigned JSBool; | 13 typedef unsigned JSBool; |
14 | 14 |
15 #include "JS_Object.h" | |
16 #include "JS_Value.h" | |
17 | |
15 struct JSConstSpec | 18 struct JSConstSpec |
16 { | 19 { |
17 const wchar_t* pName; | 20 const wchar_t* pName; |
18 double number; | 21 double number; |
19 const wchar_t* string; | 22 const wchar_t* string; |
20 FX_BYTE t; //0:double 1:str | 23 FX_BYTE t; //0:double 1:str |
21 }; | 24 }; |
22 | 25 |
23 struct JSPropertySpec | 26 struct JSPropertySpec |
24 { | 27 { |
(...skipping 26 matching lines...) Expand all Loading... | |
51 #define JS_STATIC_CONST_ENTRY_STRING(const_name, pValue) {JS_WIDESTRING(const_na me), 0, JS_WIDESTRING(pValue), 1}, | 54 #define JS_STATIC_CONST_ENTRY_STRING(const_name, pValue) {JS_WIDESTRING(const_na me), 0, JS_WIDESTRING(pValue), 1}, |
52 #define END_JS_STATIC_CONST() {0, 0, 0, 0}}; | 55 #define END_JS_STATIC_CONST() {0, 0, 0, 0}}; |
53 | 56 |
54 #define BEGIN_JS_STATIC_PROP(js_class_name) JSPropertySpec js_class_name::JS_Cla ss_Properties[] = { | 57 #define BEGIN_JS_STATIC_PROP(js_class_name) JSPropertySpec js_class_name::JS_Cla ss_Properties[] = { |
55 #define JS_STATIC_PROP_ENTRY(prop_name) {JS_WIDESTRING(prop_name), get_##prop_na me##_static, set_##prop_name##_static}, | 58 #define JS_STATIC_PROP_ENTRY(prop_name) {JS_WIDESTRING(prop_name), get_##prop_na me##_static, set_##prop_name##_static}, |
56 #define END_JS_STATIC_PROP() {0, 0, 0}}; | 59 #define END_JS_STATIC_PROP() {0, 0, 0}}; |
57 | 60 |
58 #define BEGIN_JS_STATIC_METHOD(js_class_name) JSMethodSpec js_class_name::JS_Cla ss_Methods[] = { | 61 #define BEGIN_JS_STATIC_METHOD(js_class_name) JSMethodSpec js_class_name::JS_Cla ss_Methods[] = { |
59 #define JS_STATIC_METHOD_ENTRY(method_name, nargs) {JS_WIDESTRING(method_name), method_name##_static, nargs}, | 62 #define JS_STATIC_METHOD_ENTRY(method_name, nargs) {JS_WIDESTRING(method_name), method_name##_static, nargs}, |
60 #define END_JS_STATIC_METHOD() {0, 0, 0}}; | 63 #define END_JS_STATIC_METHOD() {0, 0, 0}}; |
61 #define MEMLEAKCHECK_1() ((void)0) | |
62 #define MEMLEAKCHECK_2(main_name, sub_name) ((void)0) | |
63 | |
64 | |
65 /* | |
66 #ifdef _DEBUG | |
67 #define MEMLEAKCHECK_1() \ | |
68 _CrtMemState state1;\ | |
69 _CrtMemCheckpoint(&state1); | |
70 | |
71 #define MEMLEAKCHECK_2(main_name,sub_name) \ | |
72 _CrtMemState state2;\ | |
73 _CrtMemCheckpoint(&state2);\ | |
74 _CrtMemState diff;\ | |
75 _CrtMemDifference(&diff,&state1,&state2);\ | |
76 if (diff.lSizes[_NORMAL_BLOCK] > 0)\ | |
77 {\ | |
78 TRACE("Detected normal block memory leaks in JS Module! [%s.%s]\ n",#main_name,#sub_name);\ | |
79 _CrtMemDumpStatistics(&diff);\ | |
80 } | |
81 #else | |
82 #define MEMLEAKCHECK_1() ((void)0) | |
83 #define MEMLEAKCHECK_2(main_name,sub_name) ((void)0) | |
84 #endif | |
85 */ | |
86 | 64 |
87 /* ======================================== PROP CALLBACK ====================== ====================== */ | 65 /* ======================================== PROP CALLBACK ====================== ====================== */ |
88 | 66 |
89 #define JS_STATIC_PROP_GET(prop_name, class_name)\ | 67 template <class C, FX_BOOL (C::*M)(IFXJS_Context* cc, CJS_PropValue& vp, JS_Erro rString& sError)> |
90 static void get_##prop_name##_static(v8::Local<v8::String> property, \ | 68 void JSPropGetter(const char* prop_name_string, |
91 const v8::PropertyCallbackInfo<v8::Value> & info) \ | 69 const char* class_name_string, |
92 {\ | 70 v8::Local<v8::String> property, |
93 » v8::Isolate* isolate = info.GetIsolate();\ | 71 const v8::PropertyCallbackInfo<v8::Value>& info) { |
94 » v8::Local<v8::Context> context = isolate->GetCurrentContext();\ | 72 v8::Isolate* isolate = info.GetIsolate(); |
95 » IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2);\ | 73 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
96 » if (pRuntime == NULL) return;\ | 74 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2); |
97 » IFXJS_Context* cc = pRuntime->GetCurrentContext();\ | 75 IFXJS_Context* pContext = pRuntime->GetCurrentContext(); |
brucedawson
2015/02/18 22:23:34
The distinction between context and pContext is no
Tom Sepez
2015/02/18 23:26:48
It turns out that isolateContext, as you call it,
| |
98 » CJS_PropValue value(isolate);\ | 76 CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder()); |
99 » value.StartGetting();\ | 77 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); |
100 » CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder());\ | 78 JS_ErrorString sError; |
101 » ASSERT(pJSObj != NULL);\ | 79 CJS_PropValue value(isolate); |
brucedawson
2015/02/18 22:23:34
Why are these two lines (value declaration and fir
Tom Sepez
2015/02/18 23:26:48
Ok, I'll put it back the other way. The order in
| |
102 » class_name* pObj = (class_name*)pJSObj->GetEmbedObject();\ | 80 value.StartGetting(); |
103 » ASSERT(pObj != NULL);\ | 81 if (!(pObj->*M)(pContext, value, sError)) { |
104 » JS_ErrorString sError;\ | 82 CFX_ByteString cbName; |
105 » FX_BOOL bRet = FALSE;\ | 83 cbName.Format("%s.%s", class_name_string, prop_name_string); |
106 » MEMLEAKCHECK_1();\ | 84 JS_Error(NULL, CFX_WideString::FromLocal(cbName), sError); |
107 » bRet = pObj->prop_name(cc, value, sError);\ | 85 return; |
108 » MEMLEAKCHECK_2(class_name, prop_name);\ | 86 } |
109 » if (bRet)\ | 87 info.GetReturnValue().Set((v8::Handle<v8::Value>)value); |
110 » {\ | |
111 » » info.GetReturnValue().Set((v8::Handle<v8::Value>)value);\ | |
112 » » return ;\ | |
113 » }\ | |
114 » else\ | |
115 » {\ | |
116 » CFX_ByteString cbName;\ | |
117 » » cbName.Format("%s.%s", #class_name, #prop_name);\ | |
118 » » JS_Error(NULL,CFX_WideString::FromLocal(cbName), sError);\ | |
119 » » return ;\ | |
120 » }\ | |
121 } | 88 } |
122 | 89 |
123 #define JS_STATIC_PROP_SET(prop_name, class_name)\ | 90 template <class C, FX_BOOL (C::*M)(IFXJS_Context* cc, CJS_PropValue& vp, JS_Erro rString& sError)> |
124 static void set_##prop_name##_static(v8::Local<v8::String> property, \ | 91 void JSPropSetter(const char* prop_name_string, |
125 v8::Local<v8::Value> value, \ | 92 const char* class_name_string, |
126 const v8::PropertyCallbackInfo<void>& inf o) \ | 93 v8::Local<v8::String> property, |
127 {\ | 94 v8::Local<v8::Value> value, |
128 » v8::Isolate* isolate = info.GetIsolate();\ | 95 const v8::PropertyCallbackInfo<void>& info) { |
129 » v8::Local<v8::Context> context = isolate->GetCurrentContext();\ | 96 v8::Isolate* isolate = info.GetIsolate(); |
130 » IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2);\ | 97 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
131 » if (pRuntime == NULL) return;\ | 98 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2); |
132 » IFXJS_Context* cc = pRuntime->GetCurrentContext();\ | 99 IFXJS_Context* pContext = pRuntime->GetCurrentContext(); |
brucedawson
2015/02/18 22:23:34
The comments from above about context/pContext and
Tom Sepez
2015/02/18 23:26:49
Done.
| |
133 » CJS_PropValue propValue(CJS_Value(isolate,value,VT_unknown));\ | 100 CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder()); |
134 » propValue.StartSetting();\ | 101 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); |
135 » CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder());\ | 102 JS_ErrorString sError; |
136 » ASSERT(pJSObj != NULL);\ | 103 CJS_PropValue propValue(CJS_Value(isolate, value, VT_unknown)); |
137 » class_name* pObj = (class_name*)pJSObj->GetEmbedObject();\ | 104 propValue.StartSetting(); |
138 » ASSERT(pObj != NULL);\ | 105 if (!(pObj->*M)(pContext, propValue, sError)) { |
139 » JS_ErrorString sError;\ | 106 CFX_ByteString cbName; |
140 » FX_BOOL bRet = FALSE;\ | 107 cbName.Format("%s.%s", class_name_string, prop_name_string); |
141 » MEMLEAKCHECK_1();\ | 108 JS_Error(NULL, CFX_WideString::FromLocal(cbName), sError); |
142 » bRet = pObj->prop_name(cc, propValue, sError);\ | 109 } |
143 » MEMLEAKCHECK_2(class_name, prop_name);\ | |
144 » if (bRet)\ | |
145 » {\ | |
146 » » return ;\ | |
147 » }\ | |
148 » else\ | |
149 » {\ | |
150 » » CFX_ByteString cbName;\ | |
151 » » cbName.Format("%s.%s", #class_name, #prop_name);\ | |
152 » » JS_Error(NULL,CFX_WideString::FromLocal(cbName), sError);\ | |
153 » » return ;\ | |
154 » }\ | |
155 } | 110 } |
156 | 111 |
157 #define JS_STATIC_PROP(prop_name, class_name)\ | 112 #define JS_STATIC_PROP(prop_name, class_name) \ |
158 JS_STATIC_PROP_GET(prop_name, class_name);\ | 113 static void get_##prop_name##_static( \ |
159 JS_STATIC_PROP_SET(prop_name, class_name) | 114 v8::Local<v8::String> property, \ |
115 const v8::PropertyCallbackInfo<v8::Value>& info) { \ | |
116 JSPropGetter<class_name, &class_name::prop_name>( \ | |
117 #prop_name, #class_name, property, info); \ | |
118 } \ | |
119 static void set_##prop_name##_static( \ | |
120 v8::Local<v8::String> property, \ | |
121 v8::Local<v8::Value> value, \ | |
122 const v8::PropertyCallbackInfo<void>& info) { \ | |
123 JSPropSetter<class_name, &class_name::prop_name>( \ | |
124 #prop_name, #class_name, property, value, info); \ | |
125 } | |
160 | 126 |
161 /* ========================================= METHOD CALLBACK =================== ======================== */ | 127 /* ========================================= METHOD CALLBACK =================== ======================== */ |
162 | 128 |
163 #define JS_STATIC_METHOD(method_name, class_name)\ | 129 template <class C, FX_BOOL (C::*M)(IFXJS_Context* cc, const CJS_Parameters& para ms, CJS_Value& vRet, JS_ErrorString& sError)> |
164 static void method_name##_static(const v8::FunctionCallbackInfo<v8::Value>& in fo) \ | 130 void JSMethod(const char* method_name_string, |
165 {\ | 131 const char* class_name_string, |
166 » v8::Isolate* isolate = info.GetIsolate();\ | 132 const v8::FunctionCallbackInfo<v8::Value>& info) { |
167 » v8::Local<v8::Context> context = isolate->GetCurrentContext();\ | 133 v8::Isolate* isolate = info.GetIsolate(); |
168 » IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2);\ | 134 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
169 » if (pRuntime == NULL) return;\ | 135 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2); |
170 » IFXJS_Context* cc = pRuntime->GetCurrentContext();\ | 136 IFXJS_Context* cc = pRuntime->GetCurrentContext(); |
brucedawson
2015/02/18 22:23:34
Should use the same name for this context variable
Tom Sepez
2015/02/18 23:26:48
Done.
| |
171 » CJS_Parameters parameters;\ | 137 CJS_Parameters parameters; |
172 » for (unsigned int i = 0; i<(unsigned int)info.Length(); i++)\ | 138 for (unsigned int i = 0; i<(unsigned int)info.Length(); i++) { |
173 {\ | 139 parameters.push_back(CJS_Value(isolate, info[i], VT_unknown)); |
174 » » parameters.push_back(CJS_Value(isolate, info[i], VT_unknown));\ | 140 } |
175 » }\ | 141 CJS_Value valueRes(isolate); |
176 » CJS_Value valueRes(isolate);\ | 142 CJS_Object* pJSObj = (CJS_Object *)JS_GetPrivate(isolate,info.Holder()); |
177 » CJS_Object* pJSObj = (CJS_Object *)JS_GetPrivate(isolate,info.Holder()); \ | 143 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); |
178 » ASSERT(pJSObj != NULL);\ | 144 JS_ErrorString sError; |
179 » class_name* pObj = (class_name*)pJSObj->GetEmbedObject();\ | 145 if (!(pObj->*M)(cc, parameters, valueRes, sError)) { |
180 » ASSERT(pObj != NULL);\ | 146 CFX_ByteString cbName; |
181 » JS_ErrorString sError;\ | 147 cbName.Format("%s.%s", class_name_string, method_name_string); |
182 » FX_BOOL bRet = FALSE;\ | 148 JS_Error(NULL, CFX_WideString::FromLocal(cbName), sError); |
183 » MEMLEAKCHECK_1();\ | 149 return; |
184 » bRet = pObj->method_name(cc, parameters, valueRes, sError);\ | 150 } |
185 » MEMLEAKCHECK_2(class_name, method_name);\ | 151 info.GetReturnValue().Set(valueRes.ToJSValue()); |
186 » if (bRet)\ | |
187 » {\ | |
188 » » info.GetReturnValue().Set(valueRes.ToJSValue());\ | |
189 » » return ;\ | |
190 » }\ | |
191 » else\ | |
192 » {\ | |
193 » » CFX_ByteString cbName;\ | |
194 » » cbName.Format("%s.%s", #class_name, #method_name);\ | |
195 » » JS_Error(NULL, CFX_WideString::FromLocal(cbName), sError);\ | |
196 » » return ;\ | |
197 » }\ | |
198 } | 152 } |
199 | 153 |
154 #define JS_STATIC_METHOD(method_name, class_name) \ | |
155 static void method_name##_static( \ | |
156 const v8::FunctionCallbackInfo<v8::Value>& info) { \ | |
157 JSMethod<class_name, &class_name::method_name>( \ | |
158 #class_name, #method_name, info); \ | |
159 } | |
160 | |
161 #define JS_SPECIAL_STATIC_METHOD(method_name, class_alternate, class_name) \ | |
162 static void method_name##_static( \ | |
163 const v8::FunctionCallbackInfo<v8::Value>& info) { \ | |
164 JSMethod<class_alternate, &class_alternate::method_name>( \ | |
165 #class_name, #method_name, info); \ | |
166 } | |
167 | |
200 /* ===================================== JS CLASS ============================== ================= */ | 168 /* ===================================== JS CLASS ============================== ================= */ |
201 | 169 |
202 #define DECLARE_JS_CLASS(js_class_name) \ | 170 #define DECLARE_JS_CLASS(js_class_name) \ |
203 static JSBool JSConstructor(IFXJS_Context* cc, JSFXObject obj,JSFXObject global);\ | 171 static JSBool JSConstructor(IFXJS_Context* cc, JSFXObject obj,JSFXObject global);\ |
204 static JSBool JSDestructor(JSFXObject obj);\ | 172 static JSBool JSDestructor(JSFXObject obj);\ |
205 static int Init(IJS_Runtime* pRuntime, FXJSOBJTYPE eObjType);\ | 173 static int Init(IJS_Runtime* pRuntime, FXJSOBJTYPE eObjType);\ |
206 static void GetConsts(JSConstSpec*& pConsts, int& nSize);\ | 174 static void GetConsts(JSConstSpec*& pConsts, int& nSize);\ |
207 static void GetProperties(JSPropertySpec*& pProperties, int& nSize);\ | 175 static void GetProperties(JSPropertySpec*& pProperties, int& nSize);\ |
208 static void GetMethods(JSMethodSpec*& pMethods, int& nSize);\ | 176 static void GetMethods(JSMethodSpec*& pMethods, int& nSize);\ |
209 static JSConstSpec JS_Class_Consts[];\ | 177 static JSConstSpec JS_Class_Consts[];\ |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
325 void js_class_name::queryprop_##js_class_name##_static(JS_PROPQUERY_ARGS )\ | 293 void js_class_name::queryprop_##js_class_name##_static(JS_PROPQUERY_ARGS )\ |
326 {\ | 294 {\ |
327 v8::Isolate* isolate = info.GetIsolate();\ | 295 v8::Isolate* isolate = info.GetIsolate();\ |
328 v8::String::Utf8Value utf8_value(property);\ | 296 v8::String::Utf8Value utf8_value(property);\ |
329 CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_val ue.length());\ | 297 CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_val ue.length());\ |
330 CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder());\ | 298 CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder());\ |
331 ASSERT(pJSObj != NULL);\ | 299 ASSERT(pJSObj != NULL);\ |
332 class_alternate* pObj = (class_alternate*)pJSObj->GetEmbedObject();\ | 300 class_alternate* pObj = (class_alternate*)pJSObj->GetEmbedObject();\ |
333 ASSERT(pObj != NULL);\ | 301 ASSERT(pObj != NULL);\ |
334 FX_BOOL bRet = FALSE;\ | 302 FX_BOOL bRet = FALSE;\ |
335 MEMLEAKCHECK_1();\ | |
336 bRet = pObj->QueryProperty(propname.c_str());\ | 303 bRet = pObj->QueryProperty(propname.c_str());\ |
337 MEMLEAKCHECK_2(class_name, prop_name.c_str());\ | |
338 if (bRet)\ | 304 if (bRet)\ |
339 {\ | 305 {\ |
340 info.GetReturnValue().Set(0x004);\ | 306 info.GetReturnValue().Set(0x004);\ |
341 return ;\ | 307 return ;\ |
342 }\ | 308 }\ |
343 else\ | 309 else\ |
344 {\ | 310 {\ |
345 info.GetReturnValue().Set(0);\ | 311 info.GetReturnValue().Set(0);\ |
346 return ;\ | 312 return ;\ |
347 }\ | 313 }\ |
348 return ;\ | 314 return ;\ |
349 }\ | 315 }\ |
350 void js_class_name::getprop_##js_class_name##_static(JS_NAMED_PROPGET_AR GS)\ | 316 void js_class_name::getprop_##js_class_name##_static(JS_NAMED_PROPGET_AR GS)\ |
351 {\ | 317 {\ |
352 v8::Isolate* isolate = info.GetIsolate();\ | 318 v8::Isolate* isolate = info.GetIsolate();\ |
353 v8::Local<v8::Context> context = isolate->GetCurrentContext();\ | 319 v8::Local<v8::Context> context = isolate->GetCurrentContext();\ |
354 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2);\ | 320 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2);\ |
355 if (pRuntime == NULL) return;\ | 321 if (pRuntime == NULL) return;\ |
356 IFXJS_Context* cc = pRuntime->GetCurrentContext();\ | 322 IFXJS_Context* cc = pRuntime->GetCurrentContext();\ |
357 v8::String::Utf8Value utf8_value(property);\ | 323 v8::String::Utf8Value utf8_value(property);\ |
358 CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_val ue.length());\ | 324 CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_val ue.length());\ |
359 CJS_PropValue value(isolate);\ | 325 CJS_PropValue value(isolate);\ |
360 value.StartGetting();\ | 326 value.StartGetting();\ |
361 CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder());\ | 327 CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder());\ |
362 ASSERT(pJSObj != NULL);\ | 328 ASSERT(pJSObj != NULL);\ |
363 class_alternate* pObj = (class_alternate*)pJSObj->GetEmbedObject();\ | 329 class_alternate* pObj = (class_alternate*)pJSObj->GetEmbedObject();\ |
364 ASSERT(pObj != NULL);\ | 330 ASSERT(pObj != NULL);\ |
365 JS_ErrorString sError;\ | 331 JS_ErrorString sError;\ |
366 FX_BOOL bRet = FALSE;\ | 332 FX_BOOL bRet = FALSE;\ |
367 MEMLEAKCHECK_1();\ | |
368 bRet = pObj->DoProperty(cc, propname.c_str(), value, sError);\ | 333 bRet = pObj->DoProperty(cc, propname.c_str(), value, sError);\ |
369 MEMLEAKCHECK_2(class_name, L"GetProperty");\ | |
370 if (bRet)\ | 334 if (bRet)\ |
371 {\ | 335 {\ |
372 info.GetReturnValue().Set((v8::Handle<v8::Value>)value);\ | 336 info.GetReturnValue().Set((v8::Handle<v8::Value>)value);\ |
373 return ;\ | 337 return ;\ |
374 }\ | 338 }\ |
375 else\ | 339 else\ |
376 {\ | 340 {\ |
377 CFX_ByteString cbName;\ | 341 CFX_ByteString cbName;\ |
378 cbName.Format("%s.%s", #class_name, L"GetProperty");\ | 342 cbName.Format("%s.%s", #class_name, L"GetProperty");\ |
379 JS_Error(NULL,CFX_WideString::FromLocal(cbName), sError);\ | 343 JS_Error(NULL,CFX_WideString::FromLocal(cbName), sError);\ |
(...skipping 12 matching lines...) Expand all Loading... | |
392 v8::String::Utf8Value utf8_value(property);\ | 356 v8::String::Utf8Value utf8_value(property);\ |
393 CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_val ue.length());\ | 357 CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_val ue.length());\ |
394 CJS_PropValue PropValue(CJS_Value(isolate,value,VT_unknown));\ | 358 CJS_PropValue PropValue(CJS_Value(isolate,value,VT_unknown));\ |
395 PropValue.StartSetting();\ | 359 PropValue.StartSetting();\ |
396 CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder());\ | 360 CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder());\ |
397 if(!pJSObj) return;\ | 361 if(!pJSObj) return;\ |
398 class_alternate* pObj = (class_alternate*)pJSObj->GetEmbedObject();\ | 362 class_alternate* pObj = (class_alternate*)pJSObj->GetEmbedObject();\ |
399 ASSERT(pObj != NULL);\ | 363 ASSERT(pObj != NULL);\ |
400 JS_ErrorString sError;\ | 364 JS_ErrorString sError;\ |
401 FX_BOOL bRet = FALSE;\ | 365 FX_BOOL bRet = FALSE;\ |
402 MEMLEAKCHECK_1();\ | |
403 bRet = pObj->DoProperty(cc, propname.c_str(), PropValue, sError);\ | 366 bRet = pObj->DoProperty(cc, propname.c_str(), PropValue, sError);\ |
404 MEMLEAKCHECK_2(class_name,L"PutProperty");\ | |
405 if (bRet)\ | 367 if (bRet)\ |
406 {\ | 368 {\ |
407 return ;\ | 369 return ;\ |
408 }\ | 370 }\ |
409 else\ | 371 else\ |
410 {\ | 372 {\ |
411 CFX_ByteString cbName;\ | 373 CFX_ByteString cbName;\ |
412 cbName.Format("%s.%s", #class_name, "PutProperty");\ | 374 cbName.Format("%s.%s", #class_name, "PutProperty");\ |
413 JS_Error(NULL,CFX_WideString::FromLocal(cbName), sError);\ | 375 JS_Error(NULL,CFX_WideString::FromLocal(cbName), sError);\ |
414 return ;\ | 376 return ;\ |
415 }\ | 377 }\ |
416 JS_Error(NULL,L"PutProperty", L"Embeded object not found!");\ | 378 JS_Error(NULL,L"PutProperty", L"Embeded object not found!");\ |
417 return ;\ | 379 return ;\ |
418 }\ | 380 }\ |
419 void js_class_name::delprop_##js_class_name##_static(JS_PROPDEL_ARGS)\ | 381 void js_class_name::delprop_##js_class_name##_static(JS_PROPDEL_ARGS)\ |
420 {\ | 382 {\ |
421 v8::Isolate* isolate = info.GetIsolate();\ | 383 v8::Isolate* isolate = info.GetIsolate();\ |
422 v8::Local<v8::Context> context = isolate->GetCurrentContext();\ | 384 v8::Local<v8::Context> context = isolate->GetCurrentContext();\ |
423 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2);\ | 385 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2);\ |
424 if (pRuntime == NULL) return;\ | 386 if (pRuntime == NULL) return;\ |
425 IFXJS_Context* cc = pRuntime->GetCurrentContext();\ | 387 IFXJS_Context* cc = pRuntime->GetCurrentContext();\ |
426 v8::String::Utf8Value utf8_value(property);\ | 388 v8::String::Utf8Value utf8_value(property);\ |
427 CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_val ue.length());\ | 389 CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_val ue.length());\ |
428 CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder());\ | 390 CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder());\ |
429 ASSERT(pJSObj != NULL);\ | 391 ASSERT(pJSObj != NULL);\ |
430 class_alternate* pObj = (class_alternate*)pJSObj->GetEmbedObject();\ | 392 class_alternate* pObj = (class_alternate*)pJSObj->GetEmbedObject();\ |
431 ASSERT(pObj != NULL);\ | 393 ASSERT(pObj != NULL);\ |
432 JS_ErrorString sError;\ | 394 JS_ErrorString sError;\ |
433 FX_BOOL bRet = FALSE;\ | 395 FX_BOOL bRet = FALSE;\ |
434 MEMLEAKCHECK_1();\ | |
435 bRet = pObj->DelProperty(cc, propname.c_str(), sError);\ | 396 bRet = pObj->DelProperty(cc, propname.c_str(), sError);\ |
436 MEMLEAKCHECK_2(class_name,L"DelProperty");\ | |
437 if (bRet)\ | 397 if (bRet)\ |
438 {\ | 398 {\ |
439 return ;\ | 399 return ;\ |
440 }\ | 400 }\ |
441 else\ | 401 else\ |
442 {\ | 402 {\ |
443 CFX_ByteString cbName;\ | 403 CFX_ByteString cbName;\ |
444 cbName.Format("%s.%s", #class_name, "DelProperty");\ | 404 cbName.Format("%s.%s", #class_name, "DelProperty");\ |
445 return ;\ | 405 return ;\ |
446 }\ | 406 }\ |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
496 {\ | 456 {\ |
497 pProperties = JS_Class_Properties;\ | 457 pProperties = JS_Class_Properties;\ |
498 nSize = sizeof(JS_Class_Properties)/sizeof(JSPropertySpec)-1;\ | 458 nSize = sizeof(JS_Class_Properties)/sizeof(JSPropertySpec)-1;\ |
499 }\ | 459 }\ |
500 void js_class_name::GetMethods(JSMethodSpec*& pMethods, int& nSize)\ | 460 void js_class_name::GetMethods(JSMethodSpec*& pMethods, int& nSize)\ |
501 {\ | 461 {\ |
502 pMethods = JS_Class_Methods;\ | 462 pMethods = JS_Class_Methods;\ |
503 nSize = sizeof(JS_Class_Methods)/sizeof(JSMethodSpec)-1;\ | 463 nSize = sizeof(JS_Class_Methods)/sizeof(JSMethodSpec)-1;\ |
504 } | 464 } |
505 | 465 |
506 #define JS_SPECIAL_STATIC_METHOD(method_name, class_alternate, class_name)\ | 466 /* ======================================== GLOBAL METHODS ===================== ======================= */ |
507 » static void method_name##_static(const v8::FunctionCallbackInfo<v8::Valu e>& info)\ | 467 |
508 {\ | 468 template <FX_BOOL (*F)(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Valu e& vRet, JS_ErrorString& sError)> |
509 » v8::Isolate* isolate = info.GetIsolate();\ | 469 void JSGlobalFunc(const char *func_name_string, |
510 » v8::Local<v8::Context> context = isolate->GetCurrentContext();\ | 470 const v8::FunctionCallbackInfo<v8::Value>& info) { |
511 » IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2);\ | 471 v8::Isolate* isolate = info.GetIsolate(); |
512 » if (pRuntime == NULL) return;\ | 472 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
513 » IFXJS_Context* cc = pRuntime->GetCurrentContext();\ | 473 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2); |
514 » CJS_Parameters parameters;\ | 474 IFXJS_Context* cc = pRuntime->GetCurrentContext(); |
brucedawson
2015/02/18 22:23:34
Should use the same name for this context variable
| |
515 » for (unsigned int i = 0; i<(unsigned int)info.Length(); i++)\ | 475 CJS_Parameters parameters; |
516 » {\ | 476 for (unsigned int i = 0; i<(unsigned int)info.Length(); i++) { |
517 » parameters.push_back(CJS_Value(isolate, info[i], VT_unknown));\ | 477 parameters.push_back(CJS_Value(isolate, info[i], VT_unknown)); |
518 » }\ | 478 } |
519 » CJS_Value valueRes(isolate);\ | 479 CJS_Value valueRes(isolate); |
520 » CJS_Object* pJSObj = (CJS_Object *)JS_GetPrivate(isolate, info.Holder()) ;\ | 480 JS_ErrorString sError; |
521 » ASSERT(pJSObj != NULL);\ | 481 if (!(*F)(cc, parameters, valueRes, sError)) |
522 » class_alternate* pObj = (class_alternate*)pJSObj->GetEmbedObject();\ | 482 { |
523 » ASSERT(pObj != NULL);\ | 483 JS_Error(NULL, JS_WIDESTRING(fun_name), sError); |
524 » JS_ErrorString sError;\ | 484 return; |
525 » FX_BOOL bRet = FALSE;\ | 485 } |
526 » MEMLEAKCHECK_1();\ | 486 info.GetReturnValue().Set(valueRes.ToJSValue()); |
527 » bRet = pObj->method_name(cc, parameters, valueRes, sError);\ | |
528 » MEMLEAKCHECK_2(class_name, method_name);\ | |
529 » if (bRet)\ | |
530 » {\ | |
531 » » info.GetReturnValue().Set(valueRes.ToJSValue());\ | |
532 » » return ;\ | |
533 » }\ | |
534 » else\ | |
535 » {\ | |
536 » » CFX_ByteString cbName;\ | |
537 » » cbName.Format("%s.%s", #class_name, #method_name);\ | |
538 » » JS_Error(NULL, CFX_WideString::FromLocal(cbName), sError);\ | |
539 » » return ;\ | |
540 » }\ | |
541 » JS_Error(NULL, JS_WIDESTRING(method_name), L"Embeded object not found!" );\ | |
542 return ;\ | |
543 } | 487 } |
544 | 488 |
545 /* ======================================== GLOBAL METHODS ===================== ======================= */ | |
546 #define JS_STATIC_GLOBAL_FUN(fun_name) \ | 489 #define JS_STATIC_GLOBAL_FUN(fun_name) \ |
547 static void fun_name##_static(const v8::FunctionCallbackInfo<v8::Value>& info)\ | 490 static void fun_name##_static(const v8::FunctionCallbackInfo<v8::Value>& info) { \ |
548 {\ | 491 JSGlobalFunc<fun_name>(#fun_name, info); \ |
549 » v8::Isolate* isolate = info.GetIsolate();\ | 492 } |
550 » v8::Local<v8::Context> context = isolate->GetCurrentContext();\ | |
551 » IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2);\ | |
552 » if (pRuntime == NULL) return;\ | |
553 » IFXJS_Context* cc = pRuntime->GetCurrentContext();\ | |
554 » CJS_Parameters parameters;\ | |
555 » for (unsigned int i = 0; i<(unsigned int)info.Length(); i++)\ | |
556 » {\ | |
557 » parameters.push_back(CJS_Value(isolate, info[i], VT_unknown));\ | |
558 » }\ | |
559 » CJS_Value valueRes(isolate);\ | |
560 » JS_ErrorString sError;\ | |
561 » if (!fun_name(cc, parameters, valueRes, sError))\ | |
562 » {\ | |
563 » » JS_Error(NULL, JS_WIDESTRING(fun_name), sError);\ | |
564 » » return ;\ | |
565 » }\ | |
566 » info.GetReturnValue().Set(valueRes.ToJSValue());\ | |
567 » return ;\ | |
568 } | |
569 | 493 |
570 #define JS_STATIC_DECLARE_GLOBAL_FUN() \ | 494 #define JS_STATIC_DECLARE_GLOBAL_FUN() \ |
571 static JSMethodSpec global_methods[]; \ | 495 static JSMethodSpec global_methods[]; \ |
572 static int Init(IJS_Runtime* pRuntime) | 496 static int Init(IJS_Runtime* pRuntime) |
573 | 497 |
574 #define BEGIN_JS_STATIC_GLOBAL_FUN(js_class_name) \ | 498 #define BEGIN_JS_STATIC_GLOBAL_FUN(js_class_name) \ |
575 JSMethodSpec js_class_name::global_methods[] = { | 499 JSMethodSpec js_class_name::global_methods[] = { |
576 | 500 |
577 #define JS_STATIC_GLOBAL_FUN_ENTRY(method_name,nargs) JS_STATIC_METHOD_ENTRY(met hod_name,nargs) | 501 #define JS_STATIC_GLOBAL_FUN_ENTRY(method_name,nargs) JS_STATIC_METHOD_ENTRY(met hod_name,nargs) |
578 | 502 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
614 | 538 |
615 #define VALUE_NAME_STRING L"string" | 539 #define VALUE_NAME_STRING L"string" |
616 #define VALUE_NAME_NUMBER L"number" | 540 #define VALUE_NAME_NUMBER L"number" |
617 #define VALUE_NAME_BOOLEAN L"boolean" | 541 #define VALUE_NAME_BOOLEAN L"boolean" |
618 #define VALUE_NAME_DATE L"date" | 542 #define VALUE_NAME_DATE L"date" |
619 #define VALUE_NAME_OBJECT L"object" | 543 #define VALUE_NAME_OBJECT L"object" |
620 #define VALUE_NAME_FXOBJ L"fxobj" | 544 #define VALUE_NAME_FXOBJ L"fxobj" |
621 #define VALUE_NAME_NULL L"null" | 545 #define VALUE_NAME_NULL L"null" |
622 #define VALUE_NAME_UNDEFINED L"undefined" | 546 #define VALUE_NAME_UNDEFINED L"undefined" |
623 | 547 |
624 #define CLASSNAME_ARRAY L"Array" | |
625 #define CLASSNAME_DATE L"Date" | |
626 #define CLASSNAME_STRING L"v8::String" | |
627 | |
628 FXJSVALUETYPE GET_VALUE_TYPE(v8::Handle<v8::Value> p); | 548 FXJSVALUETYPE GET_VALUE_TYPE(v8::Handle<v8::Value> p); |
629 | 549 |
630 #endif //_JS_DEFINE_H_ | 550 #endif //_JS_DEFINE_H_ |
OLD | NEW |