| 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 FPDFSDK_INCLUDE_JAVASCRIPT_JS_DEFINE_H_ | 7 #ifndef FPDFSDK_INCLUDE_JAVASCRIPT_JS_DEFINE_H_ |
| 8 #define FPDFSDK_INCLUDE_JAVASCRIPT_JS_DEFINE_H_ | 8 #define FPDFSDK_INCLUDE_JAVASCRIPT_JS_DEFINE_H_ |
| 9 | 9 |
| 10 #include "../jsapi/fxjs_v8.h" | 10 #include "../jsapi/fxjs_v8.h" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 v8::Local<v8::String> property, | 81 v8::Local<v8::String> property, |
| 82 const v8::PropertyCallbackInfo<v8::Value>& info) { | 82 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 83 v8::Isolate* isolate = info.GetIsolate(); | 83 v8::Isolate* isolate = info.GetIsolate(); |
| 84 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 84 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
| 85 v8::Local<v8::Value> v = context->GetEmbedderData(1); | 85 v8::Local<v8::Value> v = context->GetEmbedderData(1); |
| 86 if (v.IsEmpty()) | 86 if (v.IsEmpty()) |
| 87 return; | 87 return; |
| 88 v8::Local<v8::External> field = v8::Local<v8::External>::Cast(v); | 88 v8::Local<v8::External> field = v8::Local<v8::External>::Cast(v); |
| 89 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); | 89 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); |
| 90 IFXJS_Context* pContext = pRuntime->GetCurrentContext(); | 90 IFXJS_Context* pContext = pRuntime->GetCurrentContext(); |
| 91 CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate, info.Holder()); | 91 CJS_Object* pJSObj = (CJS_Object*)FXJS_GetPrivate(isolate, info.Holder()); |
| 92 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); | 92 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); |
| 93 CFX_WideString sError; | 93 CFX_WideString sError; |
| 94 CJS_PropValue value(isolate); | 94 CJS_PropValue value(isolate); |
| 95 value.StartGetting(); | 95 value.StartGetting(); |
| 96 if (!(pObj->*M)(pContext, value, sError)) { | 96 if (!(pObj->*M)(pContext, value, sError)) { |
| 97 JS_Error(isolate, | 97 FXJS_Error(isolate, JSFormatErrorString(class_name_string, prop_name_string, |
| 98 JSFormatErrorString(class_name_string, prop_name_string, sError)); | 98 sError)); |
| 99 return; | 99 return; |
| 100 } | 100 } |
| 101 info.GetReturnValue().Set((v8::Local<v8::Value>)value); | 101 info.GetReturnValue().Set((v8::Local<v8::Value>)value); |
| 102 } | 102 } |
| 103 | 103 |
| 104 template <class C, | 104 template <class C, |
| 105 FX_BOOL (C::*M)(IFXJS_Context* cc, | 105 FX_BOOL (C::*M)(IFXJS_Context* cc, |
| 106 CJS_PropValue& vp, | 106 CJS_PropValue& vp, |
| 107 CFX_WideString& sError)> | 107 CFX_WideString& sError)> |
| 108 void JSPropSetter(const char* prop_name_string, | 108 void JSPropSetter(const char* prop_name_string, |
| 109 const char* class_name_string, | 109 const char* class_name_string, |
| 110 v8::Local<v8::String> property, | 110 v8::Local<v8::String> property, |
| 111 v8::Local<v8::Value> value, | 111 v8::Local<v8::Value> value, |
| 112 const v8::PropertyCallbackInfo<void>& info) { | 112 const v8::PropertyCallbackInfo<void>& info) { |
| 113 v8::Isolate* isolate = info.GetIsolate(); | 113 v8::Isolate* isolate = info.GetIsolate(); |
| 114 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 114 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
| 115 v8::Local<v8::Value> v = context->GetEmbedderData(1); | 115 v8::Local<v8::Value> v = context->GetEmbedderData(1); |
| 116 if (v.IsEmpty()) | 116 if (v.IsEmpty()) |
| 117 return; | 117 return; |
| 118 v8::Local<v8::External> field = v8::Local<v8::External>::Cast(v); | 118 v8::Local<v8::External> field = v8::Local<v8::External>::Cast(v); |
| 119 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); | 119 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); |
| 120 IFXJS_Context* pContext = pRuntime->GetCurrentContext(); | 120 IFXJS_Context* pContext = pRuntime->GetCurrentContext(); |
| 121 CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate, info.Holder()); | 121 CJS_Object* pJSObj = (CJS_Object*)FXJS_GetPrivate(isolate, info.Holder()); |
| 122 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); | 122 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); |
| 123 CFX_WideString sError; | 123 CFX_WideString sError; |
| 124 CJS_PropValue propValue(CJS_Value(isolate, value, VT_unknown)); | 124 CJS_PropValue propValue(CJS_Value(isolate, value, CJS_Value::VT_unknown)); |
| 125 propValue.StartSetting(); | 125 propValue.StartSetting(); |
| 126 if (!(pObj->*M)(pContext, propValue, sError)) { | 126 if (!(pObj->*M)(pContext, propValue, sError)) { |
| 127 JS_Error(isolate, | 127 FXJS_Error(isolate, JSFormatErrorString(class_name_string, prop_name_string, |
| 128 JSFormatErrorString(class_name_string, prop_name_string, sError)); | 128 sError)); |
| 129 } | 129 } |
| 130 } | 130 } |
| 131 | 131 |
| 132 #define JS_STATIC_PROP(prop_name, class_name) \ | 132 #define JS_STATIC_PROP(prop_name, class_name) \ |
| 133 static void get_##prop_name##_static( \ | 133 static void get_##prop_name##_static( \ |
| 134 v8::Local<v8::String> property, \ | 134 v8::Local<v8::String> property, \ |
| 135 const v8::PropertyCallbackInfo<v8::Value>& info) { \ | 135 const v8::PropertyCallbackInfo<v8::Value>& info) { \ |
| 136 JSPropGetter<class_name, &class_name::prop_name>(#prop_name, #class_name, \ | 136 JSPropGetter<class_name, &class_name::prop_name>(#prop_name, #class_name, \ |
| 137 property, info); \ | 137 property, info); \ |
| 138 } \ | 138 } \ |
| (...skipping 18 matching lines...) Expand all Loading... |
| 157 v8::Isolate* isolate = info.GetIsolate(); | 157 v8::Isolate* isolate = info.GetIsolate(); |
| 158 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 158 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
| 159 v8::Local<v8::Value> v = context->GetEmbedderData(1); | 159 v8::Local<v8::Value> v = context->GetEmbedderData(1); |
| 160 if (v.IsEmpty()) | 160 if (v.IsEmpty()) |
| 161 return; | 161 return; |
| 162 v8::Local<v8::External> field = v8::Local<v8::External>::Cast(v); | 162 v8::Local<v8::External> field = v8::Local<v8::External>::Cast(v); |
| 163 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); | 163 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); |
| 164 IFXJS_Context* cc = pRuntime->GetCurrentContext(); | 164 IFXJS_Context* cc = pRuntime->GetCurrentContext(); |
| 165 CJS_Parameters parameters; | 165 CJS_Parameters parameters; |
| 166 for (unsigned int i = 0; i < (unsigned int)info.Length(); i++) { | 166 for (unsigned int i = 0; i < (unsigned int)info.Length(); i++) { |
| 167 parameters.push_back(CJS_Value(isolate, info[i], VT_unknown)); | 167 parameters.push_back(CJS_Value(isolate, info[i], CJS_Value::VT_unknown)); |
| 168 } | 168 } |
| 169 CJS_Value valueRes(isolate); | 169 CJS_Value valueRes(isolate); |
| 170 CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate, info.Holder()); | 170 CJS_Object* pJSObj = (CJS_Object*)FXJS_GetPrivate(isolate, info.Holder()); |
| 171 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); | 171 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); |
| 172 CFX_WideString sError; | 172 CFX_WideString sError; |
| 173 if (!(pObj->*M)(cc, parameters, valueRes, sError)) { | 173 if (!(pObj->*M)(cc, parameters, valueRes, sError)) { |
| 174 JS_Error(isolate, JSFormatErrorString(class_name_string, method_name_string, | 174 FXJS_Error(isolate, JSFormatErrorString(class_name_string, |
| 175 sError)); | 175 method_name_string, sError)); |
| 176 return; | 176 return; |
| 177 } | 177 } |
| 178 info.GetReturnValue().Set(valueRes.ToV8Value()); | 178 info.GetReturnValue().Set(valueRes.ToV8Value()); |
| 179 } | 179 } |
| 180 | 180 |
| 181 #define JS_STATIC_METHOD(method_name, class_name) \ | 181 #define JS_STATIC_METHOD(method_name, class_name) \ |
| 182 static void method_name##_static( \ | 182 static void method_name##_static( \ |
| 183 const v8::FunctionCallbackInfo<v8::Value>& info) { \ | 183 const v8::FunctionCallbackInfo<v8::Value>& info) { \ |
| 184 JSMethod<class_name, &class_name::method_name>(#method_name, #class_name, \ | 184 JSMethod<class_name, &class_name::method_name>(#method_name, #class_name, \ |
| 185 info); \ | 185 info); \ |
| (...skipping 12 matching lines...) Expand all Loading... |
| 198 #define DECLARE_JS_CLASS(js_class_name) \ | 198 #define DECLARE_JS_CLASS(js_class_name) \ |
| 199 static void JSConstructor(IFXJS_Context* cc, v8::Local<v8::Object> obj, \ | 199 static void JSConstructor(IFXJS_Context* cc, v8::Local<v8::Object> obj, \ |
| 200 v8::Local<v8::Object> global); \ | 200 v8::Local<v8::Object> global); \ |
| 201 static void JSDestructor(v8::Local<v8::Object> obj); \ | 201 static void JSDestructor(v8::Local<v8::Object> obj); \ |
| 202 static void DefineJSObjects(v8::Isolate* pIsolate, FXJSOBJTYPE eObjType); \ | 202 static void DefineJSObjects(v8::Isolate* pIsolate, FXJSOBJTYPE eObjType); \ |
| 203 static JSConstSpec JS_Class_Consts[]; \ | 203 static JSConstSpec JS_Class_Consts[]; \ |
| 204 static JSPropertySpec JS_Class_Properties[]; \ | 204 static JSPropertySpec JS_Class_Properties[]; \ |
| 205 static JSMethodSpec JS_Class_Methods[]; \ | 205 static JSMethodSpec JS_Class_Methods[]; \ |
| 206 static const wchar_t* m_pClassName | 206 static const wchar_t* m_pClassName |
| 207 | 207 |
| 208 #define IMPLEMENT_JS_CLASS_RICH(js_class_name, class_alternate, class_name) \ | 208 #define IMPLEMENT_JS_CLASS_RICH(js_class_name, class_alternate, class_name) \ |
| 209 const wchar_t* js_class_name::m_pClassName = JS_WIDESTRING(class_name); \ | 209 const wchar_t* js_class_name::m_pClassName = JS_WIDESTRING(class_name); \ |
| 210 void js_class_name::JSConstructor(IFXJS_Context* cc, \ | 210 void js_class_name::JSConstructor(IFXJS_Context* cc, \ |
| 211 v8::Local<v8::Object> obj, \ | 211 v8::Local<v8::Object> obj, \ |
| 212 v8::Local<v8::Object> global) { \ | 212 v8::Local<v8::Object> global) { \ |
| 213 CJS_Object* pObj = new js_class_name(obj); \ | 213 CJS_Object* pObj = new js_class_name(obj); \ |
| 214 pObj->SetEmbedObject(new class_alternate(pObj)); \ | 214 pObj->SetEmbedObject(new class_alternate(pObj)); \ |
| 215 JS_SetPrivate(NULL, obj, (void*)pObj); \ | 215 FXJS_SetPrivate(NULL, obj, (void*)pObj); \ |
| 216 pObj->InitInstance(cc); \ | 216 pObj->InitInstance(cc); \ |
| 217 } \ | 217 } \ |
| 218 \ | 218 \ |
| 219 void js_class_name::JSDestructor(v8::Local<v8::Object> obj) { \ | 219 void js_class_name::JSDestructor(v8::Local<v8::Object> obj) { \ |
| 220 js_class_name* pObj = (js_class_name*)JS_GetPrivate(NULL, obj); \ | 220 js_class_name* pObj = (js_class_name*)FXJS_GetPrivate(NULL, obj); \ |
| 221 pObj->ExitInstance(); \ | 221 pObj->ExitInstance(); \ |
| 222 delete pObj; \ | 222 delete pObj; \ |
| 223 } \ | 223 } \ |
| 224 \ | 224 \ |
| 225 void js_class_name::DefineJSObjects(v8::Isolate* pIsolate, \ | 225 void js_class_name::DefineJSObjects(v8::Isolate* pIsolate, \ |
| 226 FXJSOBJTYPE eObjType) { \ | 226 FXJSOBJTYPE eObjType) { \ |
| 227 int nObjDefnID = JS_DefineObj(pIsolate, js_class_name::m_pClassName, \ | 227 int nObjDefnID = FXJS_DefineObj(pIsolate, js_class_name::m_pClassName, \ |
| 228 eObjType, JSConstructor, JSDestructor); \ | 228 eObjType, JSConstructor, JSDestructor); \ |
| 229 for (int i = 0; i < FX_ArraySize(JS_Class_Properties) - 1; ++i) { \ | 229 for (int i = 0; i < FX_ArraySize(JS_Class_Properties) - 1; ++i) { \ |
| 230 JS_DefineObjProperty(pIsolate, nObjDefnID, JS_Class_Properties[i].pName, \ | 230 FXJS_DefineObjProperty( \ |
| 231 JS_Class_Properties[i].pPropGet, \ | 231 pIsolate, nObjDefnID, JS_Class_Properties[i].pName, \ |
| 232 JS_Class_Properties[i].pPropPut); \ | 232 JS_Class_Properties[i].pPropGet, JS_Class_Properties[i].pPropPut); \ |
| 233 } \ | 233 } \ |
| 234 for (int i = 0; i < FX_ArraySize(JS_Class_Methods) - 1; ++i) { \ | 234 for (int i = 0; i < FX_ArraySize(JS_Class_Methods) - 1; ++i) { \ |
| 235 JS_DefineObjMethod(pIsolate, nObjDefnID, JS_Class_Methods[i].pName, \ | 235 FXJS_DefineObjMethod(pIsolate, nObjDefnID, JS_Class_Methods[i].pName, \ |
| 236 JS_Class_Methods[i].pMethodCall); \ | 236 JS_Class_Methods[i].pMethodCall); \ |
| 237 } \ | 237 } \ |
| 238 } | 238 } |
| 239 | 239 |
| 240 #define IMPLEMENT_JS_CLASS(js_class_name, class_name) \ | 240 #define IMPLEMENT_JS_CLASS(js_class_name, class_name) \ |
| 241 IMPLEMENT_JS_CLASS_RICH(js_class_name, class_name, class_name) | 241 IMPLEMENT_JS_CLASS_RICH(js_class_name, class_name, class_name) |
| 242 | 242 |
| 243 /* ======================================== CONST CLASS | 243 /* ======================================== CONST CLASS |
| 244 * ============================================ */ | 244 * ============================================ */ |
| 245 | 245 |
| 246 #define DECLARE_JS_CLASS_CONST() \ | 246 #define DECLARE_JS_CLASS_CONST() \ |
| 247 static void DefineJSObjects(v8::Isolate* pIsolate, FXJSOBJTYPE eObjType); \ | 247 static void DefineJSObjects(v8::Isolate* pIsolate, FXJSOBJTYPE eObjType); \ |
| 248 static JSConstSpec JS_Class_Consts[]; \ | 248 static JSConstSpec JS_Class_Consts[]; \ |
| 249 static const wchar_t* m_pClassName | 249 static const wchar_t* m_pClassName |
| 250 | 250 |
| 251 #define IMPLEMENT_JS_CLASS_CONST(js_class_name, class_name) \ | 251 #define IMPLEMENT_JS_CLASS_CONST(js_class_name, class_name) \ |
| 252 const wchar_t* js_class_name::m_pClassName = JS_WIDESTRING(class_name); \ | 252 const wchar_t* js_class_name::m_pClassName = JS_WIDESTRING(class_name); \ |
| 253 void js_class_name::DefineJSObjects(v8::Isolate* pIsolate, \ | 253 void js_class_name::DefineJSObjects(v8::Isolate* pIsolate, \ |
| 254 FXJSOBJTYPE eObjType) { \ | 254 FXJSOBJTYPE eObjType) { \ |
| 255 int nObjDefnID = JS_DefineObj(pIsolate, js_class_name::m_pClassName, \ | 255 int nObjDefnID = FXJS_DefineObj(pIsolate, js_class_name::m_pClassName, \ |
| 256 eObjType, NULL, NULL); \ | 256 eObjType, NULL, NULL); \ |
| 257 for (int i = 0; i < FX_ArraySize(JS_Class_Consts) - 1; ++i) { \ | 257 for (int i = 0; i < FX_ArraySize(JS_Class_Consts) - 1; ++i) { \ |
| 258 JS_DefineObjConst( \ | 258 FXJS_DefineObjConst( \ |
| 259 pIsolate, nObjDefnID, JS_Class_Consts[i].pName, \ | 259 pIsolate, nObjDefnID, JS_Class_Consts[i].pName, \ |
| 260 JS_Class_Consts[i].t == 0 \ | 260 JS_Class_Consts[i].t == 0 \ |
| 261 ? JS_NewNumber(pIsolate, JS_Class_Consts[i].number) \ | 261 ? FXJS_NewNumber(pIsolate, JS_Class_Consts[i].number) \ |
| 262 : JS_NewString(pIsolate, JS_Class_Consts[i].string)); \ | 262 : FXJS_NewString(pIsolate, JS_Class_Consts[i].string)); \ |
| 263 } \ | 263 } \ |
| 264 } | 264 } |
| 265 | 265 |
| 266 /* ===================================== SPECIAL JS CLASS | 266 /* ===================================== SPECIAL JS CLASS |
| 267 * =============================================== */ | 267 * =============================================== */ |
| 268 | 268 |
| 269 template <class Alt> | 269 template <class Alt> |
| 270 void JSSpecialPropQuery(const char*, | 270 void JSSpecialPropQuery(const char*, |
| 271 v8::Local<v8::String> property, | 271 v8::Local<v8::String> property, |
| 272 const v8::PropertyCallbackInfo<v8::Integer>& info) { | 272 const v8::PropertyCallbackInfo<v8::Integer>& info) { |
| 273 v8::Isolate* isolate = info.GetIsolate(); | 273 v8::Isolate* isolate = info.GetIsolate(); |
| 274 v8::String::Utf8Value utf8_value(property); | 274 v8::String::Utf8Value utf8_value(property); |
| 275 CFX_WideString propname = | 275 CFX_WideString propname = |
| 276 CFX_WideString::FromUTF8(*utf8_value, utf8_value.length()); | 276 CFX_WideString::FromUTF8(*utf8_value, utf8_value.length()); |
| 277 CJS_Object* pJSObj = | 277 CJS_Object* pJSObj = |
| 278 reinterpret_cast<CJS_Object*>(JS_GetPrivate(isolate, info.Holder())); | 278 reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder())); |
| 279 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); | 279 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); |
| 280 FX_BOOL bRet = pObj->QueryProperty(propname.c_str()); | 280 FX_BOOL bRet = pObj->QueryProperty(propname.c_str()); |
| 281 info.GetReturnValue().Set(bRet ? 4 : 0); | 281 info.GetReturnValue().Set(bRet ? 4 : 0); |
| 282 } | 282 } |
| 283 | 283 |
| 284 template <class Alt> | 284 template <class Alt> |
| 285 void JSSpecialPropGet(const char* class_name, | 285 void JSSpecialPropGet(const char* class_name, |
| 286 v8::Local<v8::String> property, | 286 v8::Local<v8::String> property, |
| 287 const v8::PropertyCallbackInfo<v8::Value>& info) { | 287 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 288 v8::Isolate* isolate = info.GetIsolate(); | 288 v8::Isolate* isolate = info.GetIsolate(); |
| 289 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 289 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
| 290 v8::Local<v8::Value> v = context->GetEmbedderData(1); | 290 v8::Local<v8::Value> v = context->GetEmbedderData(1); |
| 291 if (v.IsEmpty()) | 291 if (v.IsEmpty()) |
| 292 return; | 292 return; |
| 293 v8::Local<v8::External> field = v8::Local<v8::External>::Cast(v); | 293 v8::Local<v8::External> field = v8::Local<v8::External>::Cast(v); |
| 294 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); | 294 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); |
| 295 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); | 295 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); |
| 296 CJS_Object* pJSObj = | 296 CJS_Object* pJSObj = |
| 297 reinterpret_cast<CJS_Object*>(JS_GetPrivate(isolate, info.Holder())); | 297 reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder())); |
| 298 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); | 298 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); |
| 299 v8::String::Utf8Value utf8_value(property); | 299 v8::String::Utf8Value utf8_value(property); |
| 300 CFX_WideString propname = | 300 CFX_WideString propname = |
| 301 CFX_WideString::FromUTF8(*utf8_value, utf8_value.length()); | 301 CFX_WideString::FromUTF8(*utf8_value, utf8_value.length()); |
| 302 CFX_WideString sError; | 302 CFX_WideString sError; |
| 303 CJS_PropValue value(isolate); | 303 CJS_PropValue value(isolate); |
| 304 value.StartGetting(); | 304 value.StartGetting(); |
| 305 if (!pObj->DoProperty(pRuntimeContext, propname.c_str(), value, sError)) { | 305 if (!pObj->DoProperty(pRuntimeContext, propname.c_str(), value, sError)) { |
| 306 JS_Error(isolate, JSFormatErrorString(class_name, "GetProperty", sError)); | 306 FXJS_Error(isolate, JSFormatErrorString(class_name, "GetProperty", sError)); |
| 307 return; | 307 return; |
| 308 } | 308 } |
| 309 info.GetReturnValue().Set((v8::Local<v8::Value>)value); | 309 info.GetReturnValue().Set((v8::Local<v8::Value>)value); |
| 310 } | 310 } |
| 311 | 311 |
| 312 template <class Alt> | 312 template <class Alt> |
| 313 void JSSpecialPropPut(const char* class_name, | 313 void JSSpecialPropPut(const char* class_name, |
| 314 v8::Local<v8::String> property, | 314 v8::Local<v8::String> property, |
| 315 v8::Local<v8::Value> value, | 315 v8::Local<v8::Value> value, |
| 316 const v8::PropertyCallbackInfo<v8::Value>& info) { | 316 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 317 v8::Isolate* isolate = info.GetIsolate(); | 317 v8::Isolate* isolate = info.GetIsolate(); |
| 318 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 318 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
| 319 v8::Local<v8::Value> v = context->GetEmbedderData(1); | 319 v8::Local<v8::Value> v = context->GetEmbedderData(1); |
| 320 if (v.IsEmpty()) | 320 if (v.IsEmpty()) |
| 321 return; | 321 return; |
| 322 v8::Local<v8::External> field = v8::Local<v8::External>::Cast(v); | 322 v8::Local<v8::External> field = v8::Local<v8::External>::Cast(v); |
| 323 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); | 323 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); |
| 324 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); | 324 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); |
| 325 CJS_Object* pJSObj = | 325 CJS_Object* pJSObj = |
| 326 reinterpret_cast<CJS_Object*>(JS_GetPrivate(isolate, info.Holder())); | 326 reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder())); |
| 327 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); | 327 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); |
| 328 v8::String::Utf8Value utf8_value(property); | 328 v8::String::Utf8Value utf8_value(property); |
| 329 CFX_WideString propname = | 329 CFX_WideString propname = |
| 330 CFX_WideString::FromUTF8(*utf8_value, utf8_value.length()); | 330 CFX_WideString::FromUTF8(*utf8_value, utf8_value.length()); |
| 331 CFX_WideString sError; | 331 CFX_WideString sError; |
| 332 CJS_PropValue PropValue(CJS_Value(isolate, value, VT_unknown)); | 332 CJS_PropValue PropValue(CJS_Value(isolate, value, CJS_Value::VT_unknown)); |
| 333 PropValue.StartSetting(); | 333 PropValue.StartSetting(); |
| 334 if (!pObj->DoProperty(pRuntimeContext, propname.c_str(), PropValue, sError)) { | 334 if (!pObj->DoProperty(pRuntimeContext, propname.c_str(), PropValue, sError)) { |
| 335 JS_Error(isolate, JSFormatErrorString(class_name, "PutProperty", sError)); | 335 FXJS_Error(isolate, JSFormatErrorString(class_name, "PutProperty", sError)); |
| 336 } | 336 } |
| 337 } | 337 } |
| 338 | 338 |
| 339 template <class Alt> | 339 template <class Alt> |
| 340 void JSSpecialPropDel(const char* class_name, | 340 void JSSpecialPropDel(const char* class_name, |
| 341 v8::Local<v8::String> property, | 341 v8::Local<v8::String> property, |
| 342 const v8::PropertyCallbackInfo<v8::Boolean>& info) { | 342 const v8::PropertyCallbackInfo<v8::Boolean>& info) { |
| 343 v8::Isolate* isolate = info.GetIsolate(); | 343 v8::Isolate* isolate = info.GetIsolate(); |
| 344 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 344 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
| 345 v8::Local<v8::Value> v = context->GetEmbedderData(1); | 345 v8::Local<v8::Value> v = context->GetEmbedderData(1); |
| 346 if (v.IsEmpty()) | 346 if (v.IsEmpty()) |
| 347 return; | 347 return; |
| 348 v8::Local<v8::External> field = v8::Local<v8::External>::Cast(v); | 348 v8::Local<v8::External> field = v8::Local<v8::External>::Cast(v); |
| 349 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); | 349 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); |
| 350 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); | 350 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); |
| 351 CJS_Object* pJSObj = | 351 CJS_Object* pJSObj = |
| 352 reinterpret_cast<CJS_Object*>(JS_GetPrivate(isolate, info.Holder())); | 352 reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder())); |
| 353 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); | 353 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); |
| 354 v8::String::Utf8Value utf8_value(property); | 354 v8::String::Utf8Value utf8_value(property); |
| 355 CFX_WideString propname = | 355 CFX_WideString propname = |
| 356 CFX_WideString::FromUTF8(*utf8_value, utf8_value.length()); | 356 CFX_WideString::FromUTF8(*utf8_value, utf8_value.length()); |
| 357 CFX_WideString sError; | 357 CFX_WideString sError; |
| 358 if (!pObj->DelProperty(pRuntimeContext, propname.c_str(), sError)) { | 358 if (!pObj->DelProperty(pRuntimeContext, propname.c_str(), sError)) { |
| 359 CFX_ByteString cbName; | 359 CFX_ByteString cbName; |
| 360 cbName.Format("%s.%s", class_name, "DelProperty"); | 360 cbName.Format("%s.%s", class_name, "DelProperty"); |
| 361 // Probably a missing call to JS_Error(). | 361 // Probably a missing call to JSFX_Error(). |
| 362 } | 362 } |
| 363 } | 363 } |
| 364 | 364 |
| 365 #define DECLARE_SPECIAL_JS_CLASS(js_class_name) \ | 365 #define DECLARE_SPECIAL_JS_CLASS(js_class_name) \ |
| 366 static void JSConstructor(IFXJS_Context* cc, v8::Local<v8::Object> obj, \ | 366 static void JSConstructor(IFXJS_Context* cc, v8::Local<v8::Object> obj, \ |
| 367 v8::Local<v8::Object> global); \ | 367 v8::Local<v8::Object> global); \ |
| 368 static void JSDestructor(v8::Local<v8::Object> obj); \ | 368 static void JSDestructor(v8::Local<v8::Object> obj); \ |
| 369 static JSConstSpec JS_Class_Consts[]; \ | 369 static JSConstSpec JS_Class_Consts[]; \ |
| 370 static JSPropertySpec JS_Class_Properties[]; \ | 370 static JSPropertySpec JS_Class_Properties[]; \ |
| 371 static JSMethodSpec JS_Class_Methods[]; \ | 371 static JSMethodSpec JS_Class_Methods[]; \ |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 void js_class_name::delprop_##js_class_name##_static( \ | 404 void js_class_name::delprop_##js_class_name##_static( \ |
| 405 v8::Local<v8::String> property, \ | 405 v8::Local<v8::String> property, \ |
| 406 const v8::PropertyCallbackInfo<v8::Boolean>& info) { \ | 406 const v8::PropertyCallbackInfo<v8::Boolean>& info) { \ |
| 407 JSSpecialPropDel<class_alternate>(#class_name, property, info); \ | 407 JSSpecialPropDel<class_alternate>(#class_name, property, info); \ |
| 408 } \ | 408 } \ |
| 409 void js_class_name::JSConstructor(IFXJS_Context* cc, \ | 409 void js_class_name::JSConstructor(IFXJS_Context* cc, \ |
| 410 v8::Local<v8::Object> obj, \ | 410 v8::Local<v8::Object> obj, \ |
| 411 v8::Local<v8::Object> global) { \ | 411 v8::Local<v8::Object> global) { \ |
| 412 CJS_Object* pObj = new js_class_name(obj); \ | 412 CJS_Object* pObj = new js_class_name(obj); \ |
| 413 pObj->SetEmbedObject(new class_alternate(pObj)); \ | 413 pObj->SetEmbedObject(new class_alternate(pObj)); \ |
| 414 JS_SetPrivate(NULL, obj, (void*)pObj); \ | 414 FXJS_SetPrivate(NULL, obj, (void*)pObj); \ |
| 415 pObj->InitInstance(cc); \ | 415 pObj->InitInstance(cc); \ |
| 416 } \ | 416 } \ |
| 417 \ | 417 \ |
| 418 void js_class_name::JSDestructor(v8::Local<v8::Object> obj) { \ | 418 void js_class_name::JSDestructor(v8::Local<v8::Object> obj) { \ |
| 419 js_class_name* pObj = (js_class_name*)JS_GetPrivate(NULL, obj); \ | 419 js_class_name* pObj = (js_class_name*)FXJS_GetPrivate(NULL, obj); \ |
| 420 ASSERT(pObj != NULL); \ | 420 ASSERT(pObj != NULL); \ |
| 421 pObj->ExitInstance(); \ | 421 pObj->ExitInstance(); \ |
| 422 delete pObj; \ | 422 delete pObj; \ |
| 423 } \ | 423 } \ |
| 424 \ | 424 \ |
| 425 void js_class_name::DefineJSObjects(v8::Isolate* pIsolate, \ | 425 void js_class_name::DefineJSObjects(v8::Isolate* pIsolate, \ |
| 426 FXJSOBJTYPE eObjType) { \ | 426 FXJSOBJTYPE eObjType) { \ |
| 427 int nObjDefnID = JS_DefineObj(pIsolate, js_class_name::m_pClassName, \ | 427 int nObjDefnID = FXJS_DefineObj(pIsolate, js_class_name::m_pClassName, \ |
| 428 eObjType, JSConstructor, JSDestructor); \ | 428 eObjType, JSConstructor, JSDestructor); \ |
| 429 for (int i = 0; i < FX_ArraySize(JS_Class_Properties) - 1; ++i) { \ | 429 for (int i = 0; i < FX_ArraySize(JS_Class_Properties) - 1; ++i) { \ |
| 430 JS_DefineObjProperty(pIsolate, nObjDefnID, JS_Class_Properties[i].pName, \ | 430 FXJS_DefineObjProperty( \ |
| 431 JS_Class_Properties[i].pPropGet, \ | 431 pIsolate, nObjDefnID, JS_Class_Properties[i].pName, \ |
| 432 JS_Class_Properties[i].pPropPut); \ | 432 JS_Class_Properties[i].pPropGet, JS_Class_Properties[i].pPropPut); \ |
| 433 } \ | 433 } \ |
| 434 \ | 434 \ |
| 435 for (int i = 0; i < FX_ArraySize(JS_Class_Methods) - 1; ++i) { \ | 435 for (int i = 0; i < FX_ArraySize(JS_Class_Methods) - 1; ++i) { \ |
| 436 JS_DefineObjMethod(pIsolate, nObjDefnID, JS_Class_Methods[i].pName, \ | 436 FXJS_DefineObjMethod(pIsolate, nObjDefnID, JS_Class_Methods[i].pName, \ |
| 437 JS_Class_Methods[i].pMethodCall); \ | 437 JS_Class_Methods[i].pMethodCall); \ |
| 438 } \ | 438 } \ |
| 439 JS_DefineObjAllProperties( \ | 439 FXJS_DefineObjAllProperties( \ |
| 440 pIsolate, nObjDefnID, \ | 440 pIsolate, nObjDefnID, \ |
| 441 js_class_name::queryprop_##js_class_name##_static, \ | 441 js_class_name::queryprop_##js_class_name##_static, \ |
| 442 js_class_name::getprop_##js_class_name##_static, \ | 442 js_class_name::getprop_##js_class_name##_static, \ |
| 443 js_class_name::putprop_##js_class_name##_static, \ | 443 js_class_name::putprop_##js_class_name##_static, \ |
| 444 js_class_name::delprop_##js_class_name##_static); \ | 444 js_class_name::delprop_##js_class_name##_static); \ |
| 445 } | 445 } |
| 446 | 446 |
| 447 /* ======================================== GLOBAL METHODS | 447 /* ======================================== GLOBAL METHODS |
| 448 * ============================================ */ | 448 * ============================================ */ |
| 449 | 449 |
| 450 template <FX_BOOL (*F)(IFXJS_Context* cc, | 450 template <FX_BOOL (*F)(IFXJS_Context* cc, |
| 451 const CJS_Parameters& params, | 451 const CJS_Parameters& params, |
| 452 CJS_Value& vRet, | 452 CJS_Value& vRet, |
| 453 CFX_WideString& sError)> | 453 CFX_WideString& sError)> |
| 454 void JSGlobalFunc(const char* func_name_string, | 454 void JSGlobalFunc(const char* func_name_string, |
| 455 const v8::FunctionCallbackInfo<v8::Value>& info) { | 455 const v8::FunctionCallbackInfo<v8::Value>& info) { |
| 456 v8::Isolate* isolate = info.GetIsolate(); | 456 v8::Isolate* isolate = info.GetIsolate(); |
| 457 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 457 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
| 458 v8::Local<v8::Value> v = context->GetEmbedderData(1); | 458 v8::Local<v8::Value> v = context->GetEmbedderData(1); |
| 459 if (v.IsEmpty()) | 459 if (v.IsEmpty()) |
| 460 return; | 460 return; |
| 461 v8::Local<v8::External> field = v8::Local<v8::External>::Cast(v); | 461 v8::Local<v8::External> field = v8::Local<v8::External>::Cast(v); |
| 462 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); | 462 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); |
| 463 IFXJS_Context* cc = pRuntime->GetCurrentContext(); | 463 IFXJS_Context* cc = pRuntime->GetCurrentContext(); |
| 464 CJS_Parameters parameters; | 464 CJS_Parameters parameters; |
| 465 for (unsigned int i = 0; i < (unsigned int)info.Length(); i++) { | 465 for (unsigned int i = 0; i < (unsigned int)info.Length(); i++) { |
| 466 parameters.push_back(CJS_Value(isolate, info[i], VT_unknown)); | 466 parameters.push_back(CJS_Value(isolate, info[i], CJS_Value::VT_unknown)); |
| 467 } | 467 } |
| 468 CJS_Value valueRes(isolate); | 468 CJS_Value valueRes(isolate); |
| 469 CFX_WideString sError; | 469 CFX_WideString sError; |
| 470 if (!(*F)(cc, parameters, valueRes, sError)) { | 470 if (!(*F)(cc, parameters, valueRes, sError)) { |
| 471 JS_Error(isolate, JSFormatErrorString(func_name_string, nullptr, sError)); | 471 FXJS_Error(isolate, JSFormatErrorString(func_name_string, nullptr, sError)); |
| 472 return; | 472 return; |
| 473 } | 473 } |
| 474 info.GetReturnValue().Set(valueRes.ToV8Value()); | 474 info.GetReturnValue().Set(valueRes.ToV8Value()); |
| 475 } | 475 } |
| 476 | 476 |
| 477 #define JS_STATIC_GLOBAL_FUN(fun_name) \ | 477 #define JS_STATIC_GLOBAL_FUN(fun_name) \ |
| 478 static void fun_name##_static( \ | 478 static void fun_name##_static( \ |
| 479 const v8::FunctionCallbackInfo<v8::Value>& info) { \ | 479 const v8::FunctionCallbackInfo<v8::Value>& info) { \ |
| 480 JSGlobalFunc<fun_name>(#fun_name, info); \ | 480 JSGlobalFunc<fun_name>(#fun_name, info); \ |
| 481 } | 481 } |
| 482 | 482 |
| 483 #define JS_STATIC_DECLARE_GLOBAL_FUN() \ | 483 #define JS_STATIC_DECLARE_GLOBAL_FUN() \ |
| 484 static JSMethodSpec global_methods[]; \ | 484 static JSMethodSpec global_methods[]; \ |
| 485 static void DefineJSObjects(v8::Isolate* pIsolate) | 485 static void DefineJSObjects(v8::Isolate* pIsolate) |
| 486 | 486 |
| 487 #define BEGIN_JS_STATIC_GLOBAL_FUN(js_class_name) \ | 487 #define BEGIN_JS_STATIC_GLOBAL_FUN(js_class_name) \ |
| 488 JSMethodSpec js_class_name::global_methods[] = { | 488 JSMethodSpec js_class_name::global_methods[] = { |
| 489 #define JS_STATIC_GLOBAL_FUN_ENTRY(method_name) \ | 489 #define JS_STATIC_GLOBAL_FUN_ENTRY(method_name) \ |
| 490 JS_STATIC_METHOD_ENTRY(method_name) | 490 JS_STATIC_METHOD_ENTRY(method_name) |
| 491 | 491 |
| 492 #define END_JS_STATIC_GLOBAL_FUN() END_JS_STATIC_METHOD() | 492 #define END_JS_STATIC_GLOBAL_FUN() END_JS_STATIC_METHOD() |
| 493 | 493 |
| 494 #define IMPLEMENT_JS_STATIC_GLOBAL_FUN(js_class_name) \ | 494 #define IMPLEMENT_JS_STATIC_GLOBAL_FUN(js_class_name) \ |
| 495 void js_class_name::DefineJSObjects(v8::Isolate* pIsolate) { \ | 495 void js_class_name::DefineJSObjects(v8::Isolate* pIsolate) { \ |
| 496 for (int i = 0; i < FX_ArraySize(global_methods) - 1; ++i) { \ | 496 for (int i = 0; i < FX_ArraySize(global_methods) - 1; ++i) { \ |
| 497 JS_DefineGlobalMethod(pIsolate, js_class_name::global_methods[i].pName, \ | 497 FXJS_DefineGlobalMethod(pIsolate, \ |
| 498 js_class_name::global_methods[i].pMethodCall); \ | 498 js_class_name::global_methods[i].pName, \ |
| 499 } \ | 499 js_class_name::global_methods[i].pMethodCall); \ |
| 500 } \ |
| 500 } | 501 } |
| 501 | 502 |
| 502 FXJSVALUETYPE GET_VALUE_TYPE(v8::Local<v8::Value> p); | 503 CJS_Value::Type GET_VALUE_TYPE(v8::Local<v8::Value> p); |
| 503 | 504 |
| 504 #endif // FPDFSDK_INCLUDE_JAVASCRIPT_JS_DEFINE_H_ | 505 #endif // FPDFSDK_INCLUDE_JAVASCRIPT_JS_DEFINE_H_ |
| OLD | NEW |