| 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 » v8::Local<v8::Value> v = context->GetEmbedderData(1);\ | 73 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
| 96 » ASSERT(!v.IsEmpty());\ | 74 v8::Local<v8::Value> v = context->GetEmbedderData(1); |
| 97 » if(v.IsEmpty()) return;\ | 75 v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(v); |
| 98 » v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(v);\ | 76 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); |
| 99 » IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value();\ | 77 IFXJS_Context* pContext = pRuntime->GetCurrentContext(); |
| 100 » IFXJS_Context* cc = pRuntime->GetCurrentContext();\ | 78 CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder()); |
| 101 » CJS_PropValue value(isolate);\ | 79 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); |
| 102 » value.StartGetting();\ | 80 JS_ErrorString sError; |
| 103 » CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder());\ | 81 CJS_PropValue value(isolate); |
| 104 » ASSERT(pJSObj != NULL);\ | 82 value.StartGetting(); |
| 105 » class_name* pObj = (class_name*)pJSObj->GetEmbedObject();\ | 83 if (!(pObj->*M)(pContext, value, sError)) { |
| 106 » ASSERT(pObj != NULL);\ | 84 CFX_ByteString cbName; |
| 107 » JS_ErrorString sError;\ | 85 cbName.Format("%s.%s", class_name_string, prop_name_string); |
| 108 » FX_BOOL bRet = FALSE;\ | 86 JS_Error(NULL, CFX_WideString::FromLocal(cbName), sError); |
| 109 » MEMLEAKCHECK_1();\ | 87 return; |
| 110 » bRet = pObj->prop_name(cc, value, sError);\ | 88 } |
| 111 » MEMLEAKCHECK_2(class_name, prop_name);\ | 89 info.GetReturnValue().Set((v8::Handle<v8::Value>)value); |
| 112 » if (bRet)\ | |
| 113 » {\ | |
| 114 » » info.GetReturnValue().Set((v8::Handle<v8::Value>)value);\ | |
| 115 » » return ;\ | |
| 116 » }\ | |
| 117 » else\ | |
| 118 » {\ | |
| 119 » CFX_ByteString cbName;\ | |
| 120 » » cbName.Format("%s.%s", #class_name, #prop_name);\ | |
| 121 » » JS_Error(NULL,CFX_WideString::FromLocal(cbName), sError);\ | |
| 122 » » return ;\ | |
| 123 » }\ | |
| 124 } | 90 } |
| 125 | 91 |
| 126 #define JS_STATIC_PROP_SET(prop_name, class_name)\ | 92 template <class C, FX_BOOL (C::*M)(IFXJS_Context* cc, CJS_PropValue& vp, JS_Erro
rString& sError)> |
| 127 static void set_##prop_name##_static(v8::Local<v8::String> property, \ | 93 void JSPropSetter(const char* prop_name_string, |
| 128 v8::Local<v8::Value> value, \ | 94 const char* class_name_string, |
| 129 const v8::PropertyCallbackInfo<void>& inf
o) \ | 95 v8::Local<v8::String> property, |
| 130 {\ | 96 v8::Local<v8::Value> value, |
| 131 » v8::Isolate* isolate = info.GetIsolate();\ | 97 const v8::PropertyCallbackInfo<void>& info) { |
| 132 » v8::Local<v8::Context> context = isolate->GetCurrentContext();\ | 98 v8::Isolate* isolate = info.GetIsolate(); |
| 133 » v8::Local<v8::Value> v = context->GetEmbedderData(1);\ | 99 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
| 134 » ASSERT(!v.IsEmpty());\ | 100 v8::Local<v8::Value> v = context->GetEmbedderData(1); |
| 135 » if(v.IsEmpty()) return;\ | 101 v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(v); |
| 136 » v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(v);\ | 102 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); |
| 137 » IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value();\ | 103 IFXJS_Context* pContext = pRuntime->GetCurrentContext(); |
| 138 » IFXJS_Context* cc = pRuntime->GetCurrentContext();\ | 104 CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder()); |
| 139 » CJS_PropValue propValue(CJS_Value(isolate,value,VT_unknown));\ | 105 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); |
| 140 » propValue.StartSetting();\ | 106 JS_ErrorString sError; |
| 141 » CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder());\ | 107 CJS_PropValue propValue(CJS_Value(isolate, value, VT_unknown)); |
| 142 » ASSERT(pJSObj != NULL);\ | 108 propValue.StartSetting(); |
| 143 » class_name* pObj = (class_name*)pJSObj->GetEmbedObject();\ | 109 if (!(pObj->*M)(pContext, propValue, sError)) { |
| 144 » ASSERT(pObj != NULL);\ | 110 CFX_ByteString cbName; |
| 145 » JS_ErrorString sError;\ | 111 cbName.Format("%s.%s", class_name_string, prop_name_string); |
| 146 » FX_BOOL bRet = FALSE;\ | 112 JS_Error(NULL, CFX_WideString::FromLocal(cbName), sError); |
| 147 » MEMLEAKCHECK_1();\ | 113 } |
| 148 » bRet = pObj->prop_name(cc, propValue, sError);\ | |
| 149 » MEMLEAKCHECK_2(class_name, prop_name);\ | |
| 150 » if (bRet)\ | |
| 151 » {\ | |
| 152 » » return ;\ | |
| 153 » }\ | |
| 154 » else\ | |
| 155 » {\ | |
| 156 » » CFX_ByteString cbName;\ | |
| 157 » » cbName.Format("%s.%s", #class_name, #prop_name);\ | |
| 158 » » JS_Error(NULL,CFX_WideString::FromLocal(cbName), sError);\ | |
| 159 » » return ;\ | |
| 160 » }\ | |
| 161 } | 114 } |
| 162 | 115 |
| 163 #define JS_STATIC_PROP(prop_name, class_name)\ | 116 #define JS_STATIC_PROP(prop_name, class_name) \ |
| 164 JS_STATIC_PROP_GET(prop_name, class_name);\ | 117 static void get_##prop_name##_static( \ |
| 165 JS_STATIC_PROP_SET(prop_name, class_name) | 118 v8::Local<v8::String> property, \ |
| 119 const v8::PropertyCallbackInfo<v8::Value>& info) { \ |
| 120 JSPropGetter<class_name, &class_name::prop_name>( \ |
| 121 #prop_name, #class_name, property, info); \ |
| 122 } \ |
| 123 static void set_##prop_name##_static( \ |
| 124 v8::Local<v8::String> property, \ |
| 125 v8::Local<v8::Value> value, \ |
| 126 const v8::PropertyCallbackInfo<void>& info) { \ |
| 127 JSPropSetter<class_name, &class_name::prop_name>( \ |
| 128 #prop_name, #class_name, property, value, info); \ |
| 129 } |
| 166 | 130 |
| 167 /* ========================================= METHOD CALLBACK ===================
======================== */ | 131 /* ========================================= METHOD CALLBACK ===================
======================== */ |
| 168 | 132 |
| 169 #define JS_STATIC_METHOD(method_name, class_name)\ | 133 template <class C, FX_BOOL (C::*M)(IFXJS_Context* cc, const CJS_Parameters& para
ms, CJS_Value& vRet, JS_ErrorString& sError)> |
| 170 static void method_name##_static(const v8::FunctionCallbackInfo<v8::Value>& in
fo) \ | 134 void JSMethod(const char* method_name_string, |
| 171 {\ | 135 const char* class_name_string, |
| 172 » v8::Isolate* isolate = info.GetIsolate();\ | 136 const v8::FunctionCallbackInfo<v8::Value>& info) { |
| 173 » v8::Local<v8::Context> context = isolate->GetCurrentContext();\ | 137 v8::Isolate* isolate = info.GetIsolate(); |
| 174 » v8::Local<v8::Value> v = context->GetEmbedderData(1);\ | 138 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
| 175 » ASSERT(!v.IsEmpty());\ | 139 v8::Local<v8::Value> v = context->GetEmbedderData(1); |
| 176 » if(v.IsEmpty()) return;\ | 140 v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(v); |
| 177 » v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(v);\ | 141 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); |
| 178 » IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value();\ | 142 IFXJS_Context* cc = pRuntime->GetCurrentContext(); |
| 179 » IFXJS_Context* cc = pRuntime->GetCurrentContext();\ | 143 CJS_Parameters parameters; |
| 180 » CJS_Parameters parameters;\ | 144 for (unsigned int i = 0; i<(unsigned int)info.Length(); i++) { |
| 181 » for (unsigned int i = 0; i<(unsigned int)info.Length(); i++)\ | 145 parameters.push_back(CJS_Value(isolate, info[i], VT_unknown)); |
| 182 {\ | 146 } |
| 183 » » parameters.push_back(CJS_Value(isolate, info[i], VT_unknown));\ | 147 CJS_Value valueRes(isolate); |
| 184 » }\ | 148 CJS_Object* pJSObj = (CJS_Object *)JS_GetPrivate(isolate,info.Holder()); |
| 185 » CJS_Value valueRes(isolate);\ | 149 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); |
| 186 » CJS_Object* pJSObj = (CJS_Object *)JS_GetPrivate(isolate,info.Holder());
\ | 150 JS_ErrorString sError; |
| 187 » ASSERT(pJSObj != NULL);\ | 151 if (!(pObj->*M)(cc, parameters, valueRes, sError)) { |
| 188 » class_name* pObj = (class_name*)pJSObj->GetEmbedObject();\ | 152 CFX_ByteString cbName; |
| 189 » ASSERT(pObj != NULL);\ | 153 cbName.Format("%s.%s", class_name_string, method_name_string); |
| 190 » JS_ErrorString sError;\ | 154 JS_Error(NULL, CFX_WideString::FromLocal(cbName), sError); |
| 191 » FX_BOOL bRet = FALSE;\ | 155 return; |
| 192 » MEMLEAKCHECK_1();\ | 156 } |
| 193 » bRet = pObj->method_name(cc, parameters, valueRes, sError);\ | 157 info.GetReturnValue().Set(valueRes.ToJSValue()); |
| 194 » MEMLEAKCHECK_2(class_name, method_name);\ | |
| 195 » if (bRet)\ | |
| 196 » {\ | |
| 197 » » info.GetReturnValue().Set(valueRes.ToJSValue());\ | |
| 198 » » return ;\ | |
| 199 » }\ | |
| 200 » else\ | |
| 201 » {\ | |
| 202 » » CFX_ByteString cbName;\ | |
| 203 » » cbName.Format("%s.%s", #class_name, #method_name);\ | |
| 204 » » JS_Error(NULL, CFX_WideString::FromLocal(cbName), sError);\ | |
| 205 » » return ;\ | |
| 206 » }\ | |
| 207 } | 158 } |
| 208 | 159 |
| 160 #define JS_STATIC_METHOD(method_name, class_name) \ |
| 161 static void method_name##_static( \ |
| 162 const v8::FunctionCallbackInfo<v8::Value>& info) { \ |
| 163 JSMethod<class_name, &class_name::method_name>( \ |
| 164 #class_name, #method_name, info); \ |
| 165 } |
| 166 |
| 167 #define JS_SPECIAL_STATIC_METHOD(method_name, class_alternate, class_name) \ |
| 168 static void method_name##_static( \ |
| 169 const v8::FunctionCallbackInfo<v8::Value>& info) { \ |
| 170 JSMethod<class_alternate, &class_alternate::method_name>( \ |
| 171 #class_name, #method_name, info); \ |
| 172 } |
| 173 |
| 209 /* ===================================== JS CLASS ==============================
================= */ | 174 /* ===================================== JS CLASS ==============================
================= */ |
| 210 | 175 |
| 211 #define DECLARE_JS_CLASS(js_class_name) \ | 176 #define DECLARE_JS_CLASS(js_class_name) \ |
| 212 static JSBool JSConstructor(IFXJS_Context* cc, JSFXObject obj,JSFXObject
global);\ | 177 static JSBool JSConstructor(IFXJS_Context* cc, JSFXObject obj,JSFXObject
global);\ |
| 213 static JSBool JSDestructor(JSFXObject obj);\ | 178 static JSBool JSDestructor(JSFXObject obj);\ |
| 214 static int Init(IJS_Runtime* pRuntime, FXJSOBJTYPE eObjType);\ | 179 static int Init(IJS_Runtime* pRuntime, FXJSOBJTYPE eObjType);\ |
| 215 static void GetConsts(JSConstSpec*& pConsts, int& nSize);\ | 180 static void GetConsts(JSConstSpec*& pConsts, int& nSize);\ |
| 216 static void GetProperties(JSPropertySpec*& pProperties, int& nSize);\ | 181 static void GetProperties(JSPropertySpec*& pProperties, int& nSize);\ |
| 217 static void GetMethods(JSMethodSpec*& pMethods, int& nSize);\ | 182 static void GetMethods(JSMethodSpec*& pMethods, int& nSize);\ |
| 218 static JSConstSpec JS_Class_Consts[];\ | 183 static JSConstSpec JS_Class_Consts[];\ |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 void js_class_name::queryprop_##js_class_name##_static(JS_PROPQUERY_ARGS
)\ | 299 void js_class_name::queryprop_##js_class_name##_static(JS_PROPQUERY_ARGS
)\ |
| 335 {\ | 300 {\ |
| 336 v8::Isolate* isolate = info.GetIsolate();\ | 301 v8::Isolate* isolate = info.GetIsolate();\ |
| 337 v8::String::Utf8Value utf8_value(property);\ | 302 v8::String::Utf8Value utf8_value(property);\ |
| 338 CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_val
ue.length());\ | 303 CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_val
ue.length());\ |
| 339 CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder());\ | 304 CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder());\ |
| 340 ASSERT(pJSObj != NULL);\ | 305 ASSERT(pJSObj != NULL);\ |
| 341 class_alternate* pObj = (class_alternate*)pJSObj->GetEmbedObject();\ | 306 class_alternate* pObj = (class_alternate*)pJSObj->GetEmbedObject();\ |
| 342 ASSERT(pObj != NULL);\ | 307 ASSERT(pObj != NULL);\ |
| 343 FX_BOOL bRet = FALSE;\ | 308 FX_BOOL bRet = FALSE;\ |
| 344 MEMLEAKCHECK_1();\ | |
| 345 bRet = pObj->QueryProperty(propname.c_str());\ | 309 bRet = pObj->QueryProperty(propname.c_str());\ |
| 346 MEMLEAKCHECK_2(class_name, prop_name.c_str());\ | |
| 347 if (bRet)\ | 310 if (bRet)\ |
| 348 {\ | 311 {\ |
| 349 info.GetReturnValue().Set(0x004);\ | 312 info.GetReturnValue().Set(0x004);\ |
| 350 return ;\ | 313 return ;\ |
| 351 }\ | 314 }\ |
| 352 else\ | 315 else\ |
| 353 {\ | 316 {\ |
| 354 info.GetReturnValue().Set(0);\ | 317 info.GetReturnValue().Set(0);\ |
| 355 return ;\ | 318 return ;\ |
| 356 }\ | 319 }\ |
| (...skipping 12 matching lines...) Expand all Loading... |
| 369 v8::String::Utf8Value utf8_value(property);\ | 332 v8::String::Utf8Value utf8_value(property);\ |
| 370 CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_val
ue.length());\ | 333 CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_val
ue.length());\ |
| 371 CJS_PropValue value(isolate);\ | 334 CJS_PropValue value(isolate);\ |
| 372 value.StartGetting();\ | 335 value.StartGetting();\ |
| 373 CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder());\ | 336 CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder());\ |
| 374 ASSERT(pJSObj != NULL);\ | 337 ASSERT(pJSObj != NULL);\ |
| 375 class_alternate* pObj = (class_alternate*)pJSObj->GetEmbedObject();\ | 338 class_alternate* pObj = (class_alternate*)pJSObj->GetEmbedObject();\ |
| 376 ASSERT(pObj != NULL);\ | 339 ASSERT(pObj != NULL);\ |
| 377 JS_ErrorString sError;\ | 340 JS_ErrorString sError;\ |
| 378 FX_BOOL bRet = FALSE;\ | 341 FX_BOOL bRet = FALSE;\ |
| 379 MEMLEAKCHECK_1();\ | |
| 380 bRet = pObj->DoProperty(cc, propname.c_str(), value, sError);\ | 342 bRet = pObj->DoProperty(cc, propname.c_str(), value, sError);\ |
| 381 MEMLEAKCHECK_2(class_name, L"GetProperty");\ | |
| 382 if (bRet)\ | 343 if (bRet)\ |
| 383 {\ | 344 {\ |
| 384 info.GetReturnValue().Set((v8::Handle<v8::Value>)value);\ | 345 info.GetReturnValue().Set((v8::Handle<v8::Value>)value);\ |
| 385 return ;\ | 346 return ;\ |
| 386 }\ | 347 }\ |
| 387 else\ | 348 else\ |
| 388 {\ | 349 {\ |
| 389 CFX_ByteString cbName;\ | 350 CFX_ByteString cbName;\ |
| 390 cbName.Format("%s.%s", #class_name, L"GetProperty");\ | 351 cbName.Format("%s.%s", #class_name, L"GetProperty");\ |
| 391 JS_Error(NULL,CFX_WideString::FromLocal(cbName), sError);\ | 352 JS_Error(NULL,CFX_WideString::FromLocal(cbName), sError);\ |
| (...skipping 15 matching lines...) Expand all Loading... |
| 407 v8::String::Utf8Value utf8_value(property);\ | 368 v8::String::Utf8Value utf8_value(property);\ |
| 408 CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_val
ue.length());\ | 369 CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_val
ue.length());\ |
| 409 CJS_PropValue PropValue(CJS_Value(isolate,value,VT_unknown));\ | 370 CJS_PropValue PropValue(CJS_Value(isolate,value,VT_unknown));\ |
| 410 PropValue.StartSetting();\ | 371 PropValue.StartSetting();\ |
| 411 CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder());\ | 372 CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder());\ |
| 412 if(!pJSObj) return;\ | 373 if(!pJSObj) return;\ |
| 413 class_alternate* pObj = (class_alternate*)pJSObj->GetEmbedObject();\ | 374 class_alternate* pObj = (class_alternate*)pJSObj->GetEmbedObject();\ |
| 414 ASSERT(pObj != NULL);\ | 375 ASSERT(pObj != NULL);\ |
| 415 JS_ErrorString sError;\ | 376 JS_ErrorString sError;\ |
| 416 FX_BOOL bRet = FALSE;\ | 377 FX_BOOL bRet = FALSE;\ |
| 417 MEMLEAKCHECK_1();\ | |
| 418 bRet = pObj->DoProperty(cc, propname.c_str(), PropValue, sError);\ | 378 bRet = pObj->DoProperty(cc, propname.c_str(), PropValue, sError);\ |
| 419 MEMLEAKCHECK_2(class_name,L"PutProperty");\ | |
| 420 if (bRet)\ | 379 if (bRet)\ |
| 421 {\ | 380 {\ |
| 422 return ;\ | 381 return ;\ |
| 423 }\ | 382 }\ |
| 424 else\ | 383 else\ |
| 425 {\ | 384 {\ |
| 426 CFX_ByteString cbName;\ | 385 CFX_ByteString cbName;\ |
| 427 cbName.Format("%s.%s", #class_name, "PutProperty");\ | 386 cbName.Format("%s.%s", #class_name, "PutProperty");\ |
| 428 JS_Error(NULL,CFX_WideString::FromLocal(cbName), sError);\ | 387 JS_Error(NULL,CFX_WideString::FromLocal(cbName), sError);\ |
| 429 return ;\ | 388 return ;\ |
| (...skipping 12 matching lines...) Expand all Loading... |
| 442 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value();\ | 401 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value();\ |
| 443 IFXJS_Context* cc = pRuntime->GetCurrentContext();\ | 402 IFXJS_Context* cc = pRuntime->GetCurrentContext();\ |
| 444 v8::String::Utf8Value utf8_value(property);\ | 403 v8::String::Utf8Value utf8_value(property);\ |
| 445 CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_val
ue.length());\ | 404 CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_val
ue.length());\ |
| 446 CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder());\ | 405 CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder());\ |
| 447 ASSERT(pJSObj != NULL);\ | 406 ASSERT(pJSObj != NULL);\ |
| 448 class_alternate* pObj = (class_alternate*)pJSObj->GetEmbedObject();\ | 407 class_alternate* pObj = (class_alternate*)pJSObj->GetEmbedObject();\ |
| 449 ASSERT(pObj != NULL);\ | 408 ASSERT(pObj != NULL);\ |
| 450 JS_ErrorString sError;\ | 409 JS_ErrorString sError;\ |
| 451 FX_BOOL bRet = FALSE;\ | 410 FX_BOOL bRet = FALSE;\ |
| 452 MEMLEAKCHECK_1();\ | |
| 453 bRet = pObj->DelProperty(cc, propname.c_str(), sError);\ | 411 bRet = pObj->DelProperty(cc, propname.c_str(), sError);\ |
| 454 MEMLEAKCHECK_2(class_name,L"DelProperty");\ | |
| 455 if (bRet)\ | 412 if (bRet)\ |
| 456 {\ | 413 {\ |
| 457 return ;\ | 414 return ;\ |
| 458 }\ | 415 }\ |
| 459 else\ | 416 else\ |
| 460 {\ | 417 {\ |
| 461 CFX_ByteString cbName;\ | 418 CFX_ByteString cbName;\ |
| 462 cbName.Format("%s.%s", #class_name, "DelProperty");\ | 419 cbName.Format("%s.%s", #class_name, "DelProperty");\ |
| 463 return ;\ | 420 return ;\ |
| 464 }\ | 421 }\ |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 514 {\ | 471 {\ |
| 515 pProperties = JS_Class_Properties;\ | 472 pProperties = JS_Class_Properties;\ |
| 516 nSize = sizeof(JS_Class_Properties)/sizeof(JSPropertySpec)-1;\ | 473 nSize = sizeof(JS_Class_Properties)/sizeof(JSPropertySpec)-1;\ |
| 517 }\ | 474 }\ |
| 518 void js_class_name::GetMethods(JSMethodSpec*& pMethods, int& nSize)\ | 475 void js_class_name::GetMethods(JSMethodSpec*& pMethods, int& nSize)\ |
| 519 {\ | 476 {\ |
| 520 pMethods = JS_Class_Methods;\ | 477 pMethods = JS_Class_Methods;\ |
| 521 nSize = sizeof(JS_Class_Methods)/sizeof(JSMethodSpec)-1;\ | 478 nSize = sizeof(JS_Class_Methods)/sizeof(JSMethodSpec)-1;\ |
| 522 } | 479 } |
| 523 | 480 |
| 524 #define JS_SPECIAL_STATIC_METHOD(method_name, class_alternate, class_name)\ | 481 /* ======================================== GLOBAL METHODS =====================
======================= */ |
| 525 » static void method_name##_static(const v8::FunctionCallbackInfo<v8::Valu
e>& info)\ | 482 |
| 526 {\ | 483 template <FX_BOOL (*F)(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Valu
e& vRet, JS_ErrorString& sError)> |
| 527 » v8::Isolate* isolate = info.GetIsolate();\ | 484 void JSGlobalFunc(const char *func_name_string, |
| 528 » v8::Local<v8::Context> context = isolate->GetCurrentContext();\ | 485 const v8::FunctionCallbackInfo<v8::Value>& info) { |
| 529 » v8::Local<v8::Value> v = context->GetEmbedderData(1);\ | 486 v8::Isolate* isolate = info.GetIsolate(); |
| 530 » ASSERT(!v.IsEmpty());\ | 487 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
| 531 » if(v.IsEmpty()) return;\ | 488 v8::Local<v8::Value> v = context->GetEmbedderData(1); |
| 532 » v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(v);\ | 489 v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(v); |
| 533 » IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value();\ | 490 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); |
| 534 » IFXJS_Context* cc = pRuntime->GetCurrentContext();\ | 491 IFXJS_Context* cc = pRuntime->GetCurrentContext(); |
| 535 » CJS_Parameters parameters;\ | 492 CJS_Parameters parameters; |
| 536 » for (unsigned int i = 0; i<(unsigned int)info.Length(); i++)\ | 493 for (unsigned int i = 0; i<(unsigned int)info.Length(); i++) { |
| 537 » {\ | 494 parameters.push_back(CJS_Value(isolate, info[i], VT_unknown)); |
| 538 » parameters.push_back(CJS_Value(isolate, info[i], VT_unknown));\ | 495 } |
| 539 » }\ | 496 CJS_Value valueRes(isolate); |
| 540 » CJS_Value valueRes(isolate);\ | 497 JS_ErrorString sError; |
| 541 » CJS_Object* pJSObj = (CJS_Object *)JS_GetPrivate(isolate, info.Holder())
;\ | 498 if (!(*F)(cc, parameters, valueRes, sError)) |
| 542 » ASSERT(pJSObj != NULL);\ | 499 { |
| 543 » class_alternate* pObj = (class_alternate*)pJSObj->GetEmbedObject();\ | 500 JS_Error(NULL, JS_WIDESTRING(fun_name), sError); |
| 544 » ASSERT(pObj != NULL);\ | 501 return; |
| 545 » JS_ErrorString sError;\ | 502 } |
| 546 » FX_BOOL bRet = FALSE;\ | 503 info.GetReturnValue().Set(valueRes.ToJSValue()); |
| 547 » MEMLEAKCHECK_1();\ | |
| 548 » bRet = pObj->method_name(cc, parameters, valueRes, sError);\ | |
| 549 » MEMLEAKCHECK_2(class_name, method_name);\ | |
| 550 » if (bRet)\ | |
| 551 » {\ | |
| 552 » » info.GetReturnValue().Set(valueRes.ToJSValue());\ | |
| 553 » » return ;\ | |
| 554 » }\ | |
| 555 » else\ | |
| 556 » {\ | |
| 557 » » CFX_ByteString cbName;\ | |
| 558 » » cbName.Format("%s.%s", #class_name, #method_name);\ | |
| 559 » » JS_Error(NULL, CFX_WideString::FromLocal(cbName), sError);\ | |
| 560 » » return ;\ | |
| 561 » }\ | |
| 562 » JS_Error(NULL, JS_WIDESTRING(method_name), L"Embeded object not found!"
);\ | |
| 563 return ;\ | |
| 564 } | 504 } |
| 565 | 505 |
| 566 /* ======================================== GLOBAL METHODS =====================
======================= */ | |
| 567 #define JS_STATIC_GLOBAL_FUN(fun_name) \ | 506 #define JS_STATIC_GLOBAL_FUN(fun_name) \ |
| 568 static void fun_name##_static(const v8::FunctionCallbackInfo<v8::Value>& info)\ | 507 static void fun_name##_static(const v8::FunctionCallbackInfo<v8::Value>& info)
{ \ |
| 569 {\ | 508 JSGlobalFunc<fun_name>(#fun_name, info); \ |
| 570 » v8::Isolate* isolate = info.GetIsolate();\ | 509 } |
| 571 » v8::Local<v8::Context> context = isolate->GetCurrentContext();\ | |
| 572 » v8::Local<v8::Value> v = context->GetEmbedderData(1);\ | |
| 573 » ASSERT(!v.IsEmpty());\ | |
| 574 » if(v.IsEmpty()) return;\ | |
| 575 » v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(v);\ | |
| 576 » IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value();\ | |
| 577 » IFXJS_Context* cc = pRuntime->GetCurrentContext();\ | |
| 578 » CJS_Parameters parameters;\ | |
| 579 » for (unsigned int i = 0; i<(unsigned int)info.Length(); i++)\ | |
| 580 » {\ | |
| 581 » parameters.push_back(CJS_Value(isolate, info[i], VT_unknown));\ | |
| 582 » }\ | |
| 583 » CJS_Value valueRes(isolate);\ | |
| 584 » JS_ErrorString sError;\ | |
| 585 » if (!fun_name(cc, parameters, valueRes, sError))\ | |
| 586 » {\ | |
| 587 » » JS_Error(NULL, JS_WIDESTRING(fun_name), sError);\ | |
| 588 » » return ;\ | |
| 589 » }\ | |
| 590 » info.GetReturnValue().Set(valueRes.ToJSValue());\ | |
| 591 » return ;\ | |
| 592 } | |
| 593 | 510 |
| 594 #define JS_STATIC_DECLARE_GLOBAL_FUN() \ | 511 #define JS_STATIC_DECLARE_GLOBAL_FUN() \ |
| 595 static JSMethodSpec global_methods[]; \ | 512 static JSMethodSpec global_methods[]; \ |
| 596 static int Init(IJS_Runtime* pRuntime) | 513 static int Init(IJS_Runtime* pRuntime) |
| 597 | 514 |
| 598 #define BEGIN_JS_STATIC_GLOBAL_FUN(js_class_name) \ | 515 #define BEGIN_JS_STATIC_GLOBAL_FUN(js_class_name) \ |
| 599 JSMethodSpec js_class_name::global_methods[] = { | 516 JSMethodSpec js_class_name::global_methods[] = { |
| 600 | 517 |
| 601 #define JS_STATIC_GLOBAL_FUN_ENTRY(method_name,nargs) JS_STATIC_METHOD_ENTRY(met
hod_name,nargs) | 518 #define JS_STATIC_GLOBAL_FUN_ENTRY(method_name,nargs) JS_STATIC_METHOD_ENTRY(met
hod_name,nargs) |
| 602 | 519 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 638 | 555 |
| 639 #define VALUE_NAME_STRING L"string" | 556 #define VALUE_NAME_STRING L"string" |
| 640 #define VALUE_NAME_NUMBER L"number" | 557 #define VALUE_NAME_NUMBER L"number" |
| 641 #define VALUE_NAME_BOOLEAN L"boolean" | 558 #define VALUE_NAME_BOOLEAN L"boolean" |
| 642 #define VALUE_NAME_DATE L"date" | 559 #define VALUE_NAME_DATE L"date" |
| 643 #define VALUE_NAME_OBJECT L"object" | 560 #define VALUE_NAME_OBJECT L"object" |
| 644 #define VALUE_NAME_FXOBJ L"fxobj" | 561 #define VALUE_NAME_FXOBJ L"fxobj" |
| 645 #define VALUE_NAME_NULL L"null" | 562 #define VALUE_NAME_NULL L"null" |
| 646 #define VALUE_NAME_UNDEFINED L"undefined" | 563 #define VALUE_NAME_UNDEFINED L"undefined" |
| 647 | 564 |
| 648 #define CLASSNAME_ARRAY L"Array" | |
| 649 #define CLASSNAME_DATE L"Date" | |
| 650 #define CLASSNAME_STRING L"v8::String" | |
| 651 | |
| 652 FXJSVALUETYPE GET_VALUE_TYPE(v8::Handle<v8::Value> p); | 565 FXJSVALUETYPE GET_VALUE_TYPE(v8::Handle<v8::Value> p); |
| 653 | 566 |
| 654 #endif //_JS_DEFINE_H_ | 567 #endif //_JS_DEFINE_H_ |
| OLD | NEW |