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