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" | 10 #include "../jsapi/fxjs_v8.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 /* ======================================== PROP CALLBACK ======================
====================== */ | 53 /* ======================================== PROP CALLBACK ======================
====================== */ |
54 | 54 |
55 template <class C, FX_BOOL (C::*M)(IFXJS_Context* cc, CJS_PropValue& vp, CFX_Wid
eString& sError)> | 55 template <class C, FX_BOOL (C::*M)(IFXJS_Context* cc, CJS_PropValue& vp, CFX_Wid
eString& sError)> |
56 void JSPropGetter(const char* prop_name_string, | 56 void JSPropGetter(const char* prop_name_string, |
57 const char* class_name_string, | 57 const char* class_name_string, |
58 v8::Local<v8::String> property, | 58 v8::Local<v8::String> property, |
59 const v8::PropertyCallbackInfo<v8::Value>& info) { | 59 const v8::PropertyCallbackInfo<v8::Value>& info) { |
60 v8::Isolate* isolate = info.GetIsolate(); | 60 v8::Isolate* isolate = info.GetIsolate(); |
61 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 61 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
62 v8::Local<v8::Value> v = context->GetEmbedderData(1); | 62 v8::Local<v8::Value> v = context->GetEmbedderData(1); |
63 v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(v); | 63 v8::Local<v8::External> field = v8::Local<v8::External>::Cast(v); |
64 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); | 64 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); |
65 IFXJS_Context* pContext = pRuntime->GetCurrentContext(); | 65 IFXJS_Context* pContext = pRuntime->GetCurrentContext(); |
66 CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder()); | 66 CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder()); |
67 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); | 67 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); |
68 CFX_WideString sError; | 68 CFX_WideString sError; |
69 CJS_PropValue value(isolate); | 69 CJS_PropValue value(isolate); |
70 value.StartGetting(); | 70 value.StartGetting(); |
71 if (!(pObj->*M)(pContext, value, sError)) { | 71 if (!(pObj->*M)(pContext, value, sError)) { |
72 JS_Error(isolate, JSFormatErrorString(class_name_string, prop_name_string, s
Error)); | 72 JS_Error(isolate, JSFormatErrorString(class_name_string, prop_name_string, s
Error)); |
73 return; | 73 return; |
74 } | 74 } |
75 info.GetReturnValue().Set((v8::Handle<v8::Value>)value); | 75 info.GetReturnValue().Set((v8::Local<v8::Value>)value); |
76 } | 76 } |
77 | 77 |
78 template <class C, FX_BOOL (C::*M)(IFXJS_Context* cc, CJS_PropValue& vp, CFX_Wid
eString& sError)> | 78 template <class C, FX_BOOL (C::*M)(IFXJS_Context* cc, CJS_PropValue& vp, CFX_Wid
eString& sError)> |
79 void JSPropSetter(const char* prop_name_string, | 79 void JSPropSetter(const char* prop_name_string, |
80 const char* class_name_string, | 80 const char* class_name_string, |
81 v8::Local<v8::String> property, | 81 v8::Local<v8::String> property, |
82 v8::Local<v8::Value> value, | 82 v8::Local<v8::Value> value, |
83 const v8::PropertyCallbackInfo<void>& info) { | 83 const v8::PropertyCallbackInfo<void>& info) { |
84 v8::Isolate* isolate = info.GetIsolate(); | 84 v8::Isolate* isolate = info.GetIsolate(); |
85 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 85 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
86 v8::Local<v8::Value> v = context->GetEmbedderData(1); | 86 v8::Local<v8::Value> v = context->GetEmbedderData(1); |
87 v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(v); | 87 v8::Local<v8::External> field = v8::Local<v8::External>::Cast(v); |
88 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); | 88 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); |
89 IFXJS_Context* pContext = pRuntime->GetCurrentContext(); | 89 IFXJS_Context* pContext = pRuntime->GetCurrentContext(); |
90 CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder()); | 90 CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder()); |
91 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); | 91 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); |
92 CFX_WideString sError; | 92 CFX_WideString sError; |
93 CJS_PropValue propValue(CJS_Value(isolate, value, VT_unknown)); | 93 CJS_PropValue propValue(CJS_Value(isolate, value, VT_unknown)); |
94 propValue.StartSetting(); | 94 propValue.StartSetting(); |
95 if (!(pObj->*M)(pContext, propValue, sError)) { | 95 if (!(pObj->*M)(pContext, propValue, sError)) { |
96 JS_Error(isolate, JSFormatErrorString(class_name_string, prop_name_string,
sError)); | 96 JS_Error(isolate, JSFormatErrorString(class_name_string, prop_name_string,
sError)); |
97 } | 97 } |
(...skipping 16 matching lines...) Expand all Loading... |
114 | 114 |
115 /* ========================================= METHOD CALLBACK ===================
======================== */ | 115 /* ========================================= METHOD CALLBACK ===================
======================== */ |
116 | 116 |
117 template <class C, FX_BOOL (C::*M)(IFXJS_Context* cc, const CJS_Parameters& para
ms, CJS_Value& vRet, CFX_WideString& sError)> | 117 template <class C, FX_BOOL (C::*M)(IFXJS_Context* cc, const CJS_Parameters& para
ms, CJS_Value& vRet, CFX_WideString& sError)> |
118 void JSMethod(const char* method_name_string, | 118 void JSMethod(const char* method_name_string, |
119 const char* class_name_string, | 119 const char* class_name_string, |
120 const v8::FunctionCallbackInfo<v8::Value>& info) { | 120 const v8::FunctionCallbackInfo<v8::Value>& info) { |
121 v8::Isolate* isolate = info.GetIsolate(); | 121 v8::Isolate* isolate = info.GetIsolate(); |
122 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 122 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
123 v8::Local<v8::Value> v = context->GetEmbedderData(1); | 123 v8::Local<v8::Value> v = context->GetEmbedderData(1); |
124 v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(v); | 124 v8::Local<v8::External> field = v8::Local<v8::External>::Cast(v); |
125 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); | 125 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); |
126 IFXJS_Context* cc = pRuntime->GetCurrentContext(); | 126 IFXJS_Context* cc = pRuntime->GetCurrentContext(); |
127 CJS_Parameters parameters; | 127 CJS_Parameters parameters; |
128 for (unsigned int i = 0; i<(unsigned int)info.Length(); i++) { | 128 for (unsigned int i = 0; i<(unsigned int)info.Length(); i++) { |
129 parameters.push_back(CJS_Value(isolate, info[i], VT_unknown)); | 129 parameters.push_back(CJS_Value(isolate, info[i], VT_unknown)); |
130 } | 130 } |
131 CJS_Value valueRes(isolate); | 131 CJS_Value valueRes(isolate); |
132 CJS_Object* pJSObj = (CJS_Object *)JS_GetPrivate(isolate,info.Holder()); | 132 CJS_Object* pJSObj = (CJS_Object *)JS_GetPrivate(isolate,info.Holder()); |
133 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); | 133 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); |
134 CFX_WideString sError; | 134 CFX_WideString sError; |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 info.GetReturnValue().Set(bRet ? 4 : 0); | 245 info.GetReturnValue().Set(bRet ? 4 : 0); |
246 } | 246 } |
247 | 247 |
248 template <class Alt> | 248 template <class Alt> |
249 void JSSpecialPropGet(const char* class_name, | 249 void JSSpecialPropGet(const char* class_name, |
250 v8::Local<v8::String> property, | 250 v8::Local<v8::String> property, |
251 const v8::PropertyCallbackInfo<v8::Value>& info) { | 251 const v8::PropertyCallbackInfo<v8::Value>& info) { |
252 v8::Isolate* isolate = info.GetIsolate(); | 252 v8::Isolate* isolate = info.GetIsolate(); |
253 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 253 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
254 v8::Local<v8::Value> v = context->GetEmbedderData(1); | 254 v8::Local<v8::Value> v = context->GetEmbedderData(1); |
255 v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(v); | 255 v8::Local<v8::External> field = v8::Local<v8::External>::Cast(v); |
256 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); | 256 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); |
257 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); | 257 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); |
258 CJS_Object* pJSObj = reinterpret_cast<CJS_Object*>(JS_GetPrivate(isolate, info
.Holder())); | 258 CJS_Object* pJSObj = reinterpret_cast<CJS_Object*>(JS_GetPrivate(isolate, info
.Holder())); |
259 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); | 259 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); |
260 v8::String::Utf8Value utf8_value(property); | 260 v8::String::Utf8Value utf8_value(property); |
261 CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_value.len
gth()); | 261 CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_value.len
gth()); |
262 CFX_WideString sError; | 262 CFX_WideString sError; |
263 CJS_PropValue value(isolate); | 263 CJS_PropValue value(isolate); |
264 value.StartGetting(); | 264 value.StartGetting(); |
265 if (!pObj->DoProperty(pRuntimeContext, propname.c_str(), value, sError)) { | 265 if (!pObj->DoProperty(pRuntimeContext, propname.c_str(), value, sError)) { |
266 JS_Error(isolate, JSFormatErrorString(class_name, "GetProperty", sError)); | 266 JS_Error(isolate, JSFormatErrorString(class_name, "GetProperty", sError)); |
267 return; | 267 return; |
268 } | 268 } |
269 info.GetReturnValue().Set((v8::Handle<v8::Value>)value); | 269 info.GetReturnValue().Set((v8::Local<v8::Value>)value); |
270 } | 270 } |
271 | 271 |
272 template <class Alt> | 272 template <class Alt> |
273 void JSSpecialPropPut(const char* class_name, | 273 void JSSpecialPropPut(const char* class_name, |
274 v8::Local<v8::String> property, | 274 v8::Local<v8::String> property, |
275 v8::Local<v8::Value> value, | 275 v8::Local<v8::Value> value, |
276 const v8::PropertyCallbackInfo<v8::Value>& info) { | 276 const v8::PropertyCallbackInfo<v8::Value>& info) { |
277 v8::Isolate* isolate = info.GetIsolate(); | 277 v8::Isolate* isolate = info.GetIsolate(); |
278 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 278 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
279 v8::Local<v8::Value> v = context->GetEmbedderData(1); | 279 v8::Local<v8::Value> v = context->GetEmbedderData(1); |
280 v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(v); | 280 v8::Local<v8::External> field = v8::Local<v8::External>::Cast(v); |
281 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); | 281 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); |
282 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); | 282 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); |
283 CJS_Object* pJSObj = reinterpret_cast<CJS_Object*>(JS_GetPrivate(isolate, info
.Holder())); | 283 CJS_Object* pJSObj = reinterpret_cast<CJS_Object*>(JS_GetPrivate(isolate, info
.Holder())); |
284 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); | 284 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); |
285 v8::String::Utf8Value utf8_value(property); | 285 v8::String::Utf8Value utf8_value(property); |
286 CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_value.len
gth()); | 286 CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_value.len
gth()); |
287 CFX_WideString sError; | 287 CFX_WideString sError; |
288 CJS_PropValue PropValue(CJS_Value(isolate,value,VT_unknown)); | 288 CJS_PropValue PropValue(CJS_Value(isolate,value,VT_unknown)); |
289 PropValue.StartSetting(); | 289 PropValue.StartSetting(); |
290 if (!pObj->DoProperty(pRuntimeContext, propname.c_str(), PropValue, sError)) { | 290 if (!pObj->DoProperty(pRuntimeContext, propname.c_str(), PropValue, sError)) { |
291 JS_Error(isolate, JSFormatErrorString(class_name, "PutProperty", sError)); | 291 JS_Error(isolate, JSFormatErrorString(class_name, "PutProperty", sError)); |
292 } | 292 } |
293 } | 293 } |
294 | 294 |
295 template <class Alt> | 295 template <class Alt> |
296 void JSSpecialPropDel(const char* class_name, | 296 void JSSpecialPropDel(const char* class_name, |
297 v8::Local<v8::String> property, | 297 v8::Local<v8::String> property, |
298 const v8::PropertyCallbackInfo<v8::Boolean>& info) { | 298 const v8::PropertyCallbackInfo<v8::Boolean>& info) { |
299 v8::Isolate* isolate = info.GetIsolate(); | 299 v8::Isolate* isolate = info.GetIsolate(); |
300 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 300 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
301 v8::Local<v8::Value> v = context->GetEmbedderData(1); | 301 v8::Local<v8::Value> v = context->GetEmbedderData(1); |
302 v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(v); | 302 v8::Local<v8::External> field = v8::Local<v8::External>::Cast(v); |
303 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); | 303 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); |
304 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); | 304 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); |
305 CJS_Object* pJSObj = reinterpret_cast<CJS_Object*>(JS_GetPrivate(isolate, info
.Holder())); | 305 CJS_Object* pJSObj = reinterpret_cast<CJS_Object*>(JS_GetPrivate(isolate, info
.Holder())); |
306 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); | 306 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); |
307 v8::String::Utf8Value utf8_value(property); | 307 v8::String::Utf8Value utf8_value(property); |
308 CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_value.len
gth()); | 308 CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_value.len
gth()); |
309 CFX_WideString sError; | 309 CFX_WideString sError; |
310 if (!pObj->DelProperty(pRuntimeContext, propname.c_str(), sError)) { | 310 if (!pObj->DelProperty(pRuntimeContext, propname.c_str(), sError)) { |
311 CFX_ByteString cbName; | 311 CFX_ByteString cbName; |
312 cbName.Format("%s.%s", class_name, "DelProperty"); | 312 cbName.Format("%s.%s", class_name, "DelProperty"); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 } | 382 } |
383 | 383 |
384 /* ======================================== GLOBAL METHODS =====================
======================= */ | 384 /* ======================================== GLOBAL METHODS =====================
======================= */ |
385 | 385 |
386 template <FX_BOOL (*F)(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Valu
e& vRet, CFX_WideString& sError)> | 386 template <FX_BOOL (*F)(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Valu
e& vRet, CFX_WideString& sError)> |
387 void JSGlobalFunc(const char *func_name_string, | 387 void JSGlobalFunc(const char *func_name_string, |
388 const v8::FunctionCallbackInfo<v8::Value>& info) { | 388 const v8::FunctionCallbackInfo<v8::Value>& info) { |
389 v8::Isolate* isolate = info.GetIsolate(); | 389 v8::Isolate* isolate = info.GetIsolate(); |
390 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 390 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
391 v8::Local<v8::Value> v = context->GetEmbedderData(1); | 391 v8::Local<v8::Value> v = context->GetEmbedderData(1); |
392 v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(v); | 392 v8::Local<v8::External> field = v8::Local<v8::External>::Cast(v); |
393 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); | 393 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); |
394 IFXJS_Context* cc = pRuntime->GetCurrentContext(); | 394 IFXJS_Context* cc = pRuntime->GetCurrentContext(); |
395 CJS_Parameters parameters; | 395 CJS_Parameters parameters; |
396 for (unsigned int i = 0; i<(unsigned int)info.Length(); i++) { | 396 for (unsigned int i = 0; i<(unsigned int)info.Length(); i++) { |
397 parameters.push_back(CJS_Value(isolate, info[i], VT_unknown)); | 397 parameters.push_back(CJS_Value(isolate, info[i], VT_unknown)); |
398 } | 398 } |
399 CJS_Value valueRes(isolate); | 399 CJS_Value valueRes(isolate); |
400 CFX_WideString sError; | 400 CFX_WideString sError; |
401 if (!(*F)(cc, parameters, valueRes, sError)) | 401 if (!(*F)(cc, parameters, valueRes, sError)) |
402 { | 402 { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 | 457 |
458 #define VALUE_NAME_STRING L"string" | 458 #define VALUE_NAME_STRING L"string" |
459 #define VALUE_NAME_NUMBER L"number" | 459 #define VALUE_NAME_NUMBER L"number" |
460 #define VALUE_NAME_BOOLEAN L"boolean" | 460 #define VALUE_NAME_BOOLEAN L"boolean" |
461 #define VALUE_NAME_DATE L"date" | 461 #define VALUE_NAME_DATE L"date" |
462 #define VALUE_NAME_OBJECT L"object" | 462 #define VALUE_NAME_OBJECT L"object" |
463 #define VALUE_NAME_FXOBJ L"fxobj" | 463 #define VALUE_NAME_FXOBJ L"fxobj" |
464 #define VALUE_NAME_NULL L"null" | 464 #define VALUE_NAME_NULL L"null" |
465 #define VALUE_NAME_UNDEFINED L"undefined" | 465 #define VALUE_NAME_UNDEFINED L"undefined" |
466 | 466 |
467 FXJSVALUETYPE GET_VALUE_TYPE(v8::Handle<v8::Value> p); | 467 FXJSVALUETYPE GET_VALUE_TYPE(v8::Local<v8::Value> p); |
468 | 468 |
469 #endif //_JS_DEFINE_H_ | 469 #endif //_JS_DEFINE_H_ |
OLD | NEW |