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; |
(...skipping 24 matching lines...) Expand all Loading... |
35 const wchar_t* pName; | 35 const wchar_t* pName; |
36 v8::FunctionCallback pMethodCall; | 36 v8::FunctionCallback pMethodCall; |
37 unsigned nParamNum; | 37 unsigned nParamNum; |
38 }; | 38 }; |
39 | 39 |
40 typedef CFX_WideString JS_ErrorString; | 40 typedef CFX_WideString JS_ErrorString; |
41 | 41 |
42 #define JS_TRUE (unsigned)1 | 42 #define JS_TRUE (unsigned)1 |
43 #define JS_FALSE (unsigned)0 | 43 #define JS_FALSE (unsigned)0 |
44 | 44 |
45 | 45 typedef CFX_ArrayTemplate<float> CJS_PointsArray; |
46 #define CJS_PointsArray»» CFX_ArrayTemplate<float> | 46 typedef CFX_ArrayTemplate<int> CJS_IntArray; |
47 #define CJS_IntArray» » CFX_ArrayTemplate<int> | |
48 | 47 |
49 /* ====================================== PUBLIC DEFINE SPEC ===================
=========================== */ | 48 /* ====================================== PUBLIC DEFINE SPEC ===================
=========================== */ |
50 #define JS_WIDESTRING(widestring) L###widestring | 49 #define JS_WIDESTRING(widestring) L###widestring |
51 | 50 |
52 #define BEGIN_JS_STATIC_CONST(js_class_name) JSConstSpec js_class_name::JS_Class
_Consts[] = { | 51 #define BEGIN_JS_STATIC_CONST(js_class_name) JSConstSpec js_class_name::JS_Class
_Consts[] = { |
53 #define JS_STATIC_CONST_ENTRY_NUMBER(const_name, pValue) {JS_WIDESTRING(const_na
me), pValue, L"", 0}, | 52 #define JS_STATIC_CONST_ENTRY_NUMBER(const_name, pValue) {JS_WIDESTRING(const_na
me), pValue, L"", 0}, |
54 #define JS_STATIC_CONST_ENTRY_STRING(const_name, pValue) {JS_WIDESTRING(const_na
me), 0, JS_WIDESTRING(pValue), 1}, | 53 #define JS_STATIC_CONST_ENTRY_STRING(const_name, pValue) {JS_WIDESTRING(const_na
me), 0, JS_WIDESTRING(pValue), 1}, |
55 #define END_JS_STATIC_CONST() {0, 0, 0, 0}}; | 54 #define END_JS_STATIC_CONST() {0, 0, 0, 0}}; |
56 | 55 |
57 #define BEGIN_JS_STATIC_PROP(js_class_name) JSPropertySpec js_class_name::JS_Cla
ss_Properties[] = { | 56 #define BEGIN_JS_STATIC_PROP(js_class_name) JSPropertySpec js_class_name::JS_Cla
ss_Properties[] = { |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 return -1;\ | 261 return -1;\ |
263 }\ | 262 }\ |
264 void js_class_name::GetConsts(JSConstSpec*& pConsts, int& nSize)\ | 263 void js_class_name::GetConsts(JSConstSpec*& pConsts, int& nSize)\ |
265 {\ | 264 {\ |
266 pConsts = JS_Class_Consts;\ | 265 pConsts = JS_Class_Consts;\ |
267 nSize = sizeof(JS_Class_Consts)/sizeof(JSConstSpec)-1;\ | 266 nSize = sizeof(JS_Class_Consts)/sizeof(JSConstSpec)-1;\ |
268 } | 267 } |
269 | 268 |
270 /* ===================================== SPECIAL JS CLASS ======================
========================= */ | 269 /* ===================================== SPECIAL JS CLASS ======================
========================= */ |
271 | 270 |
| 271 template <class Alt> |
| 272 void JSSpecialPropQuery(const char *, v8::Local<v8::String> property,const v8::P
ropertyCallbackInfo<v8::Integer>& info) { |
| 273 v8::Isolate* isolate = info.GetIsolate(); |
| 274 v8::String::Utf8Value utf8_value(property); |
| 275 CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_value.len
gth()); |
| 276 CJS_Object* pJSObj = reinterpret_cast<CJS_Object*>(JS_GetPrivate(isolate, info
.Holder())); |
| 277 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); |
| 278 FX_BOOL bRet = pObj->QueryProperty(propname.c_str()); |
| 279 info.GetReturnValue().Set(bRet ? 4 : 0); |
| 280 } |
| 281 |
| 282 template <class Alt> |
| 283 void JSSpecialPropGet(const char* class_name, |
| 284 v8::Local<v8::String> property, |
| 285 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 286 v8::Isolate* isolate = info.GetIsolate(); |
| 287 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
| 288 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2); |
| 289 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); |
| 290 CJS_Object* pJSObj = reinterpret_cast<CJS_Object*>(JS_GetPrivate(isolate, info
.Holder())); |
| 291 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); |
| 292 v8::String::Utf8Value utf8_value(property); |
| 293 CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_value.len
gth()); |
| 294 JS_ErrorString sError; |
| 295 CJS_PropValue value(isolate); |
| 296 value.StartGetting(); |
| 297 if (!pObj->DoProperty(pRuntimeContext, propname.c_str(), value, sError)) { |
| 298 CFX_ByteString cbName; |
| 299 cbName.Format("%s.%s", class_name, L"GetProperty"); |
| 300 JS_Error(NULL,CFX_WideString::FromLocal(cbName), sError); |
| 301 return; |
| 302 } |
| 303 info.GetReturnValue().Set((v8::Handle<v8::Value>)value); |
| 304 } |
| 305 |
| 306 template <class Alt> |
| 307 void JSSpecialPropPut(const char* class_name, |
| 308 v8::Local<v8::String> property, |
| 309 v8::Local<v8::Value> value, |
| 310 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 311 v8::Isolate* isolate = info.GetIsolate(); |
| 312 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
| 313 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2); |
| 314 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); |
| 315 CJS_Object* pJSObj = reinterpret_cast<CJS_Object*>(JS_GetPrivate(isolate, info
.Holder())); |
| 316 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); |
| 317 v8::String::Utf8Value utf8_value(property); |
| 318 CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_value.len
gth()); |
| 319 JS_ErrorString sError; |
| 320 CJS_PropValue PropValue(CJS_Value(isolate,value,VT_unknown)); |
| 321 PropValue.StartSetting(); |
| 322 if (!pObj->DoProperty(pRuntimeContext, propname.c_str(), PropValue, sError)) { |
| 323 CFX_ByteString cbName; |
| 324 cbName.Format("%s.%s", class_name, "PutProperty"); |
| 325 JS_Error(NULL,CFX_WideString::FromLocal(cbName), sError); |
| 326 } |
| 327 } |
| 328 |
| 329 template <class Alt> |
| 330 void JSSpecialPropDel(const char* class_name, |
| 331 v8::Local<v8::String> property, |
| 332 const v8::PropertyCallbackInfo<v8::Boolean>& info) { |
| 333 v8::Isolate* isolate = info.GetIsolate(); |
| 334 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
| 335 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2); |
| 336 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); |
| 337 CJS_Object* pJSObj = reinterpret_cast<CJS_Object*>(JS_GetPrivate(isolate, info
.Holder())); |
| 338 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); |
| 339 v8::String::Utf8Value utf8_value(property); |
| 340 CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_value.len
gth()); |
| 341 JS_ErrorString sError; |
| 342 if (!pObj->DelProperty(pRuntimeContext, propname.c_str(), sError)) { |
| 343 CFX_ByteString cbName; |
| 344 cbName.Format("%s.%s", class_name, "DelProperty"); |
| 345 // Probably a missing call to JS_Error(). |
| 346 } |
| 347 } |
| 348 |
272 #define DECLARE_SPECIAL_JS_CLASS(js_class_name) \ | 349 #define DECLARE_SPECIAL_JS_CLASS(js_class_name) \ |
273 static JSBool JSConstructor(IFXJS_Context* cc, JSFXObject obj, JSFXObjec
t global);\ | 350 static JSBool JSConstructor(IFXJS_Context* cc, JSFXObject obj, JSFXObjec
t global);\ |
274 static JSBool JSDestructor(JSFXObject obj);\ | 351 static JSBool JSDestructor(JSFXObject obj);\ |
275 static void GetConsts(JSConstSpec*& pConsts, int& nSize);\ | 352 static void GetConsts(JSConstSpec*& pConsts, int& nSize);\ |
276 static void GetProperties(JSPropertySpec*& pProperties, int& nSize);\ | 353 static void GetProperties(JSPropertySpec*& pProperties, int& nSize);\ |
277 static void GetMethods(JSMethodSpec*& pMethods, int& nSize);\ | 354 static void GetMethods(JSMethodSpec*& pMethods, int& nSize);\ |
278 static JSConstSpec JS_Class_Consts[];\ | 355 static JSConstSpec JS_Class_Consts[];\ |
279 static JSPropertySpec JS_Class_Properties[];\ | 356 static JSPropertySpec JS_Class_Properties[];\ |
280 static JSMethodSpec JS_Class_Methods[];\ | 357 static JSMethodSpec JS_Class_Methods[];\ |
281 static int Init(IJS_Runtime* pRuntime, FXJSOBJTYPE eObjType);\ | 358 static int Init(IJS_Runtime* pRuntime, FXJSOBJTYPE eObjType);\ |
282 static const wchar_t* m_pClassName;\ | 359 static const wchar_t* m_pClassName;\ |
283 » static void queryprop_##js_class_name##_static(JS_PROPQUERY_ARGS);\ | 360 » static void queryprop_##js_class_name##_static(v8::Local<v8::String> pro
perty,const v8::PropertyCallbackInfo<v8::Integer>& info);\ |
284 » static void getprop_##js_class_name##_static(JS_NAMED_PROPGET_ARGS);\ | 361 » static void getprop_##js_class_name##_static(v8::Local<v8::String> prope
rty, const v8::PropertyCallbackInfo<v8::Value>& info);\ |
285 » static void putprop_##js_class_name##_static(JS_NAMED_PROPPUT_ARGS);\ | 362 » static void putprop_##js_class_name##_static(v8::Local<v8::String> prope
rty,v8::Local<v8::Value> value,const v8::PropertyCallbackInfo<v8::Value>& info);
\ |
286 » static void delprop_##js_class_name##_static(JS_PROPDEL_ARGS) | 363 » static void delprop_##js_class_name##_static(v8::Local<v8::String> prope
rty,const v8::PropertyCallbackInfo<v8::Boolean>& info) |
287 | 364 |
288 #define IMPLEMENT_SPECIAL_JS_CLASS(js_class_name, class_alternate, class_name) \ | 365 #define IMPLEMENT_SPECIAL_JS_CLASS(js_class_name, class_alternate, class_name) \ |
289 const wchar_t * js_class_name::m_pClassName = JS_WIDESTRING(class_name);\ | 366 const wchar_t * js_class_name::m_pClassName = JS_WIDESTRING(class_name);\ |
290 » void js_class_name::queryprop_##js_class_name##_static(JS_PROPQUERY_ARGS
)\ | 367 void js_class_name::queryprop_##js_class_name##_static(v8::Local<v8::String> pro
perty,const v8::PropertyCallbackInfo<v8::Integer>& info) { \ |
291 {\ | 368 JSSpecialPropQuery<class_alternate>(#class_name, property, info); \ |
292 » v8::Isolate* isolate = info.GetIsolate();\ | |
293 » v8::String::Utf8Value utf8_value(property);\ | |
294 » CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_val
ue.length());\ | |
295 » CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder());\ | |
296 » ASSERT(pJSObj != NULL);\ | |
297 » class_alternate* pObj = (class_alternate*)pJSObj->GetEmbedObject();\ | |
298 » ASSERT(pObj != NULL);\ | |
299 » FX_BOOL bRet = FALSE;\ | |
300 » bRet = pObj->QueryProperty(propname.c_str());\ | |
301 » if (bRet)\ | |
302 » {\ | |
303 » » info.GetReturnValue().Set(0x004);\ | |
304 » » return ;\ | |
305 » }\ | |
306 » else\ | |
307 » {\ | |
308 » » info.GetReturnValue().Set(0);\ | |
309 » » return ;\ | |
310 » }\ | |
311 » return ;\ | |
312 }\ | 369 }\ |
313 » void js_class_name::getprop_##js_class_name##_static(JS_NAMED_PROPGET_AR
GS)\ | 370 void js_class_name::getprop_##js_class_name##_static(v8::Local<v8::String> prope
rty, const v8::PropertyCallbackInfo<v8::Value>& info) { \ |
314 {\ | 371 JSSpecialPropGet<class_alternate>(#class_name, property, info); \ |
315 » v8::Isolate* isolate = info.GetIsolate();\ | 372 } \ |
316 » v8::Local<v8::Context> context = isolate->GetCurrentContext();\ | 373 void js_class_name::putprop_##js_class_name##_static(v8::Local<v8::String> prope
rty,v8::Local<v8::Value> value,const v8::PropertyCallbackInfo<v8::Value>& info)
{\ |
317 » IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2);\ | 374 JSSpecialPropPut<class_alternate>(#class_name, property, value, info); \ |
318 » if (pRuntime == NULL) return;\ | |
319 » IFXJS_Context* cc = pRuntime->GetCurrentContext();\ | |
320 » v8::String::Utf8Value utf8_value(property);\ | |
321 » CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_val
ue.length());\ | |
322 » CJS_PropValue value(isolate);\ | |
323 » value.StartGetting();\ | |
324 » CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder());\ | |
325 » ASSERT(pJSObj != NULL);\ | |
326 » class_alternate* pObj = (class_alternate*)pJSObj->GetEmbedObject();\ | |
327 » ASSERT(pObj != NULL);\ | |
328 » JS_ErrorString sError;\ | |
329 » FX_BOOL bRet = FALSE;\ | |
330 » bRet = pObj->DoProperty(cc, propname.c_str(), value, sError);\ | |
331 » if (bRet)\ | |
332 » {\ | |
333 » » info.GetReturnValue().Set((v8::Handle<v8::Value>)value);\ | |
334 » » return ;\ | |
335 » }\ | |
336 » else\ | |
337 » {\ | |
338 » » CFX_ByteString cbName;\ | |
339 » » cbName.Format("%s.%s", #class_name, L"GetProperty");\ | |
340 » » JS_Error(NULL,CFX_WideString::FromLocal(cbName), sError);\ | |
341 » » return ;\ | |
342 » }\ | |
343 » JS_Error(NULL,L"GetProperty", L"Embeded object not found!");\ | |
344 » return ;\ | |
345 }\ | 375 }\ |
346 » void js_class_name::putprop_##js_class_name##_static(JS_NAMED_PROPPUT_AR
GS)\ | 376 void js_class_name::delprop_##js_class_name##_static(v8::Local<v8::String> prope
rty,const v8::PropertyCallbackInfo<v8::Boolean>& info) { \ |
347 {\ | 377 JSSpecialPropDel<class_alternate>(#class_name, property, info); \ |
348 » v8::Isolate* isolate = info.GetIsolate();\ | 378 } \ |
349 » v8::Local<v8::Context> context = isolate->GetCurrentContext();\ | |
350 » IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2);\ | |
351 » if (pRuntime == NULL) return;\ | |
352 » IFXJS_Context* cc = pRuntime->GetCurrentContext();\ | |
353 » v8::String::Utf8Value utf8_value(property);\ | |
354 » CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_val
ue.length());\ | |
355 » CJS_PropValue PropValue(CJS_Value(isolate,value,VT_unknown));\ | |
356 » PropValue.StartSetting();\ | |
357 » CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder());\ | |
358 » if(!pJSObj) return;\ | |
359 » class_alternate* pObj = (class_alternate*)pJSObj->GetEmbedObject();\ | |
360 » ASSERT(pObj != NULL);\ | |
361 » JS_ErrorString sError;\ | |
362 » FX_BOOL bRet = FALSE;\ | |
363 » bRet = pObj->DoProperty(cc, propname.c_str(), PropValue, sError);\ | |
364 » if (bRet)\ | |
365 » {\ | |
366 » » return ;\ | |
367 » }\ | |
368 » else\ | |
369 » {\ | |
370 » » CFX_ByteString cbName;\ | |
371 » » cbName.Format("%s.%s", #class_name, "PutProperty");\ | |
372 » » JS_Error(NULL,CFX_WideString::FromLocal(cbName), sError);\ | |
373 » » return ;\ | |
374 » }\ | |
375 » JS_Error(NULL,L"PutProperty", L"Embeded object not found!");\ | |
376 » return ;\ | |
377 }\ | |
378 » void js_class_name::delprop_##js_class_name##_static(JS_PROPDEL_ARGS)\ | |
379 {\ | |
380 » v8::Isolate* isolate = info.GetIsolate();\ | |
381 » v8::Local<v8::Context> context = isolate->GetCurrentContext();\ | |
382 » IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2);\ | |
383 » if (pRuntime == NULL) return;\ | |
384 » IFXJS_Context* cc = pRuntime->GetCurrentContext();\ | |
385 » v8::String::Utf8Value utf8_value(property);\ | |
386 » CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_val
ue.length());\ | |
387 » CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder());\ | |
388 » ASSERT(pJSObj != NULL);\ | |
389 » class_alternate* pObj = (class_alternate*)pJSObj->GetEmbedObject();\ | |
390 » ASSERT(pObj != NULL);\ | |
391 » JS_ErrorString sError;\ | |
392 » FX_BOOL bRet = FALSE;\ | |
393 » bRet = pObj->DelProperty(cc, propname.c_str(), sError);\ | |
394 » if (bRet)\ | |
395 » {\ | |
396 » » return ;\ | |
397 » }\ | |
398 » else\ | |
399 » {\ | |
400 » » CFX_ByteString cbName;\ | |
401 » » cbName.Format("%s.%s", #class_name, "DelProperty");\ | |
402 » » return ;\ | |
403 » }\ | |
404 » return ;\ | |
405 }\ | |
406 JSBool js_class_name::JSConstructor(IFXJS_Context* cc, JSFXObject obj,JSFXObjec
t global)\ | 379 JSBool js_class_name::JSConstructor(IFXJS_Context* cc, JSFXObject obj,JSFXObjec
t global)\ |
407 {\ | 380 {\ |
408 CJS_Object* pObj = FX_NEW js_class_name(obj);\ | 381 CJS_Object* pObj = FX_NEW js_class_name(obj);\ |
409 pObj->SetEmbedObject(FX_NEW class_alternate(pObj));\ | 382 pObj->SetEmbedObject(FX_NEW class_alternate(pObj));\ |
410 JS_SetPrivate(NULL,obj, (void*)pObj); \ | 383 JS_SetPrivate(NULL,obj, (void*)pObj); \ |
411 pObj->InitInstance(cc);\ | 384 pObj->InitInstance(cc);\ |
412 return JS_TRUE;\ | 385 return JS_TRUE;\ |
413 }\ | 386 }\ |
414 \ | 387 \ |
415 JSBool js_class_name::JSDestructor(JSFXObject obj) \ | 388 JSBool js_class_name::JSDestructor(JSFXObject obj) \ |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
537 #define VALUE_NAME_BOOLEAN L"boolean" | 510 #define VALUE_NAME_BOOLEAN L"boolean" |
538 #define VALUE_NAME_DATE L"date" | 511 #define VALUE_NAME_DATE L"date" |
539 #define VALUE_NAME_OBJECT L"object" | 512 #define VALUE_NAME_OBJECT L"object" |
540 #define VALUE_NAME_FXOBJ L"fxobj" | 513 #define VALUE_NAME_FXOBJ L"fxobj" |
541 #define VALUE_NAME_NULL L"null" | 514 #define VALUE_NAME_NULL L"null" |
542 #define VALUE_NAME_UNDEFINED L"undefined" | 515 #define VALUE_NAME_UNDEFINED L"undefined" |
543 | 516 |
544 FXJSVALUETYPE GET_VALUE_TYPE(v8::Handle<v8::Value> p); | 517 FXJSVALUETYPE GET_VALUE_TYPE(v8::Handle<v8::Value> p); |
545 | 518 |
546 #endif //_JS_DEFINE_H_ | 519 #endif //_JS_DEFINE_H_ |
OLD | NEW |