Chromium Code Reviews| 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 28 matching lines...) Expand all Loading... | |
| 39 #define JS_TRUE (unsigned)1 | 39 #define JS_TRUE (unsigned)1 | 
| 40 #define JS_FALSE (unsigned)0 | 40 #define JS_FALSE (unsigned)0 | 
| 41 | 41 | 
| 42 | 42 | 
| 43 #define CJS_PointsArray CFX_ArrayTemplate<float> | 43 #define CJS_PointsArray CFX_ArrayTemplate<float> | 
| 44 #define CJS_IntArray CFX_ArrayTemplate<int> | 44 #define CJS_IntArray CFX_ArrayTemplate<int> | 
| 45 | 45 | 
| 46 /* ====================================== PUBLIC DEFINE SPEC =================== =========================== */ | 46 /* ====================================== PUBLIC DEFINE SPEC =================== =========================== */ | 
| 47 #define JS_WIDESTRING(widestring) L###widestring | 47 #define JS_WIDESTRING(widestring) L###widestring | 
| 48 | 48 | 
| 49 #define OBJ_PROP_PARAMS IFXJS_Context* cc, CJS_PropValue& vp, JS _ErrorString& sError | |
| 50 #define OBJ_METHOD_PARAMS IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, JS_ErrorString& sError | |
| 51 #define BEGIN_JS_STATIC_CONST(js_class_name) JSConstSpec js_class_name::JS_Class _Consts[] = { | 49 #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}, | 50 #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}, | 51 #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}}; | 52 #define END_JS_STATIC_CONST() {0, 0, 0, 0}}; | 
| 55 | 53 | 
| 56 #define BEGIN_JS_STATIC_PROP(js_class_name) JSPropertySpec js_class_name::JS_Cla ss_Properties[] = { | 54 #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}, | 55 #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}}; | 56 #define END_JS_STATIC_PROP() {0, 0, 0}}; | 
| 59 | 57 | 
| 60 #define BEGIN_JS_STATIC_METHOD(js_class_name) JSMethodSpec js_class_name::JS_Cla ss_Methods[] = { | 58 #define BEGIN_JS_STATIC_METHOD(js_class_name) JSMethodSpec js_class_name::JS_Cla ss_Methods[] = { | 
| (...skipping 21 matching lines...) Expand all Loading... | |
| 82 } | 80 } | 
| 83 #else | 81 #else | 
| 84 #define MEMLEAKCHECK_1() ((void)0) | 82 #define MEMLEAKCHECK_1() ((void)0) | 
| 85 #define MEMLEAKCHECK_2(main_name,sub_name) ((void)0) | 83 #define MEMLEAKCHECK_2(main_name,sub_name) ((void)0) | 
| 86 #endif | 84 #endif | 
| 87 */ | 85 */ | 
| 88 | 86 | 
| 89 /* ======================================== PROP CALLBACK ====================== ====================== */ | 87 /* ======================================== PROP CALLBACK ====================== ====================== */ | 
| 90 | 88 | 
| 91 #define JS_STATIC_PROP_GET(prop_name, class_name)\ | 89 #define JS_STATIC_PROP_GET(prop_name, class_name)\ | 
| 92 » static void get_##prop_name##_static(JS_PROPGET_ARGS)\ | 90 static void get_##prop_name##_static(v8::Local<v8::String> property, \ | 
| 91 const v8::PropertyCallbackInfo<v8::Value> & info) \ | |
| 93 {\ | 92 {\ | 
| 94 v8::Isolate* isolate = info.GetIsolate();\ | 93 v8::Isolate* isolate = info.GetIsolate();\ | 
| 95 v8::Local<v8::Context> context = isolate->GetCurrentContext();\ | 94 v8::Local<v8::Context> context = isolate->GetCurrentContext();\ | 
| 96 v8::Local<v8::Value> v = context->GetEmbedderData(1);\ | 95 v8::Local<v8::Value> v = context->GetEmbedderData(1);\ | 
| 97 ASSERT(!v.IsEmpty());\ | 96 ASSERT(!v.IsEmpty());\ | 
| 98 if(v.IsEmpty()) return;\ | 97 if(v.IsEmpty()) return;\ | 
| 99 v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(v);\ | 98 v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(v);\ | 
| 100 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value();\ | 99 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value();\ | 
| 101 IFXJS_Context* cc = pRuntime->GetCurrentContext();\ | 100 IFXJS_Context* cc = pRuntime->GetCurrentContext();\ | 
| 102 CJS_PropValue value(isolate);\ | 101 CJS_PropValue value(isolate);\ | 
| (...skipping 15 matching lines...) Expand all Loading... | |
| 118 else\ | 117 else\ | 
| 119 {\ | 118 {\ | 
| 120 CFX_ByteString cbName;\ | 119 CFX_ByteString cbName;\ | 
| 121 cbName.Format("%s.%s", #class_name, #prop_name);\ | 120 cbName.Format("%s.%s", #class_name, #prop_name);\ | 
| 122 JS_Error(NULL,CFX_WideString::FromLocal(cbName), sError);\ | 121 JS_Error(NULL,CFX_WideString::FromLocal(cbName), sError);\ | 
| 123 return ;\ | 122 return ;\ | 
| 124 }\ | 123 }\ | 
| 125 } | 124 } | 
| 126 | 125 | 
| 127 #define JS_STATIC_PROP_SET(prop_name, class_name)\ | 126 #define JS_STATIC_PROP_SET(prop_name, class_name)\ | 
| 128 » static void set_##prop_name##_static(JS_PROPPUT_ARGS)\ | 127 static void set_##prop_name##_static(v8::Local<v8::String> property, \ | 
| 128 v8::Local<v8::Value> value, \ | |
| 129 const v8::PropertyCallbackInfo<void>& inf o) \ | |
| 129 {\ | 130 {\ | 
| 130 v8::Isolate* isolate = info.GetIsolate();\ | 131 v8::Isolate* isolate = info.GetIsolate();\ | 
| 131 v8::Local<v8::Context> context = isolate->GetCurrentContext();\ | 132 v8::Local<v8::Context> context = isolate->GetCurrentContext();\ | 
| 132 v8::Local<v8::Value> v = context->GetEmbedderData(1);\ | 133 v8::Local<v8::Value> v = context->GetEmbedderData(1);\ | 
| 133 ASSERT(!v.IsEmpty());\ | 134 ASSERT(!v.IsEmpty());\ | 
| 134 if(v.IsEmpty()) return;\ | 135 if(v.IsEmpty()) return;\ | 
| 135 v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(v);\ | 136 v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(v);\ | 
| 136 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value();\ | 137 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value();\ | 
| 137 IFXJS_Context* cc = pRuntime->GetCurrentContext();\ | 138 IFXJS_Context* cc = pRuntime->GetCurrentContext();\ | 
| 138 CJS_PropValue propValue(CJS_Value(isolate,value,VT_unknown));\ | 139 CJS_PropValue propValue(CJS_Value(isolate,value,VT_unknown));\ | 
| (...skipping 20 matching lines...) Expand all Loading... | |
| 159 }\ | 160 }\ | 
| 160 } | 161 } | 
| 161 | 162 | 
| 162 #define JS_STATIC_PROP(prop_name, class_name)\ | 163 #define JS_STATIC_PROP(prop_name, class_name)\ | 
| 163 JS_STATIC_PROP_GET(prop_name, class_name);\ | 164 JS_STATIC_PROP_GET(prop_name, class_name);\ | 
| 164 JS_STATIC_PROP_SET(prop_name, class_name) | 165 JS_STATIC_PROP_SET(prop_name, class_name) | 
| 165 | 166 | 
| 166 /* ========================================= METHOD CALLBACK =================== ======================== */ | 167 /* ========================================= METHOD CALLBACK =================== ======================== */ | 
| 167 | 168 | 
| 168 #define JS_STATIC_METHOD(method_name, class_name)\ | 169 #define JS_STATIC_METHOD(method_name, class_name)\ | 
| 169 » static void method_name##_static(JS_METHOD_ARGS)\ | 170 static void method_name##_static(const v8::FunctionCallbackInfo<v8::Value>& in fo) \ | 
| 170 {\ | 171 {\ | 
| 171 v8::Isolate* isolate = info.GetIsolate();\ | 172 v8::Isolate* isolate = info.GetIsolate();\ | 
| 172 v8::Local<v8::Context> context = isolate->GetCurrentContext();\ | 173 v8::Local<v8::Context> context = isolate->GetCurrentContext();\ | 
| 173 v8::Local<v8::Value> v = context->GetEmbedderData(1);\ | 174 v8::Local<v8::Value> v = context->GetEmbedderData(1);\ | 
| 174 ASSERT(!v.IsEmpty());\ | 175 ASSERT(!v.IsEmpty());\ | 
| 175 if(v.IsEmpty()) return;\ | 176 if(v.IsEmpty()) return;\ | 
| 176 v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(v);\ | 177 v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(v);\ | 
| 177 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value();\ | 178 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value();\ | 
| 178 IFXJS_Context* cc = pRuntime->GetCurrentContext();\ | 179 IFXJS_Context* cc = pRuntime->GetCurrentContext();\ | 
| 179 CJS_Parameters parameters;\ | 180 CJS_Parameters parameters;\ | 
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 514 pProperties = JS_Class_Properties;\ | 515 pProperties = JS_Class_Properties;\ | 
| 515 nSize = sizeof(JS_Class_Properties)/sizeof(JSPropertySpec)-1;\ | 516 nSize = sizeof(JS_Class_Properties)/sizeof(JSPropertySpec)-1;\ | 
| 516 }\ | 517 }\ | 
| 517 void js_class_name::GetMethods(JSMethodSpec*& pMethods, int& nSize)\ | 518 void js_class_name::GetMethods(JSMethodSpec*& pMethods, int& nSize)\ | 
| 518 {\ | 519 {\ | 
| 519 pMethods = JS_Class_Methods;\ | 520 pMethods = JS_Class_Methods;\ | 
| 520 nSize = sizeof(JS_Class_Methods)/sizeof(JSMethodSpec)-1;\ | 521 nSize = sizeof(JS_Class_Methods)/sizeof(JSMethodSpec)-1;\ | 
| 521 } | 522 } | 
| 522 | 523 | 
| 523 #define JS_SPECIAL_STATIC_METHOD(method_name, class_alternate, class_name)\ | 524 #define JS_SPECIAL_STATIC_METHOD(method_name, class_alternate, class_name)\ | 
| 524 » static void method_name##_static(JS_METHOD_ARGS)\ | 525 » static void method_name##_static(const v8::FunctionCallbackInfo<v8::Valu e>& info)\ | 
| 525 {\ | 526 {\ | 
| 526 v8::Isolate* isolate = info.GetIsolate();\ | 527 v8::Isolate* isolate = info.GetIsolate();\ | 
| 527 v8::Local<v8::Context> context = isolate->GetCurrentContext();\ | 528 v8::Local<v8::Context> context = isolate->GetCurrentContext();\ | 
| 528 v8::Local<v8::Value> v = context->GetEmbedderData(1);\ | 529 v8::Local<v8::Value> v = context->GetEmbedderData(1);\ | 
| 529 ASSERT(!v.IsEmpty());\ | 530 ASSERT(!v.IsEmpty());\ | 
| 530 if(v.IsEmpty()) return;\ | 531 if(v.IsEmpty()) return;\ | 
| 531 v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(v);\ | 532 v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(v);\ | 
| 532 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value();\ | 533 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value();\ | 
| 533 IFXJS_Context* cc = pRuntime->GetCurrentContext();\ | 534 IFXJS_Context* cc = pRuntime->GetCurrentContext();\ | 
| 534 CJS_Parameters parameters;\ | 535 CJS_Parameters parameters;\ | 
| (...skipping 22 matching lines...) Expand all Loading... | |
| 557 cbName.Format("%s.%s", #class_name, #method_name);\ | 558 cbName.Format("%s.%s", #class_name, #method_name);\ | 
| 558 JS_Error(NULL, CFX_WideString::FromLocal(cbName), sError);\ | 559 JS_Error(NULL, CFX_WideString::FromLocal(cbName), sError);\ | 
| 559 return ;\ | 560 return ;\ | 
| 560 }\ | 561 }\ | 
| 561 JS_Error(NULL, JS_WIDESTRING(method_name), L"Embeded object not found!" );\ | 562 JS_Error(NULL, JS_WIDESTRING(method_name), L"Embeded object not found!" );\ | 
| 562 return ;\ | 563 return ;\ | 
| 563 } | 564 } | 
| 564 | 565 | 
| 565 /* ======================================== GLOBAL METHODS ===================== ======================= */ | 566 /* ======================================== GLOBAL METHODS ===================== ======================= */ | 
| 566 #define JS_STATIC_GLOBAL_FUN(fun_name) \ | 567 #define JS_STATIC_GLOBAL_FUN(fun_name) \ | 
| 567 static void fun_name##_static(JS_METHOD_ARGS)\ | 568 static void fun_name##_static(const v8::FunctionCallbackInfo<v8::Value>& info)\ | 
| 568 {\ | 569 {\ | 
| 569 v8::Isolate* isolate = info.GetIsolate();\ | 570 v8::Isolate* isolate = info.GetIsolate();\ | 
| 570 v8::Local<v8::Context> context = isolate->GetCurrentContext();\ | 571 v8::Local<v8::Context> context = isolate->GetCurrentContext();\ | 
| 571 v8::Local<v8::Value> v = context->GetEmbedderData(1);\ | 572 v8::Local<v8::Value> v = context->GetEmbedderData(1);\ | 
| 572 ASSERT(!v.IsEmpty());\ | 573 ASSERT(!v.IsEmpty());\ | 
| 573 if(v.IsEmpty()) return;\ | 574 if(v.IsEmpty()) return;\ | 
| 574 v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(v);\ | 575 v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(v);\ | 
| 575 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value();\ | 576 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value();\ | 
| 576 IFXJS_Context* cc = pRuntime->GetCurrentContext();\ | 577 IFXJS_Context* cc = pRuntime->GetCurrentContext();\ | 
| 577 CJS_Parameters parameters;\ | 578 CJS_Parameters parameters;\ | 
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 641 #define VALUE_NAME_DATE L"date" | 642 #define VALUE_NAME_DATE L"date" | 
| 642 #define VALUE_NAME_OBJECT L"object" | 643 #define VALUE_NAME_OBJECT L"object" | 
| 643 #define VALUE_NAME_FXOBJ L"fxobj" | 644 #define VALUE_NAME_FXOBJ L"fxobj" | 
| 644 #define VALUE_NAME_NULL L"null" | 645 #define VALUE_NAME_NULL L"null" | 
| 645 #define VALUE_NAME_UNDEFINED L"undefined" | 646 #define VALUE_NAME_UNDEFINED L"undefined" | 
| 646 | 647 | 
| 647 #define CLASSNAME_ARRAY L"Array" | 648 #define CLASSNAME_ARRAY L"Array" | 
| 648 #define CLASSNAME_DATE L"Date" | 649 #define CLASSNAME_DATE L"Date" | 
| 649 #define CLASSNAME_STRING L"v8::String" | 650 #define CLASSNAME_STRING L"v8::String" | 
| 650 | 651 | 
| 651 extern const unsigned int JSCONST_nStringHash; | 652 FXJSVALUETYPE GET_VALUE_TYPE(v8::Handle<v8::Value> p); | 
| 652 extern const unsigned int JSCONST_nNumberHash; | |
| 653 extern const unsigned int JSCONST_nBoolHash; | |
| 654 extern const unsigned int JSCONST_nDateHash; | |
| 655 extern const unsigned int JSCONST_nObjectHash; | |
| 656 extern const unsigned int JSCONST_nFXobjHash; | |
| 657 extern const unsigned int JSCONST_nNullHash; | |
| 658 extern const unsigned int JSCONST_nUndefHash; | |
| 659 | |
| 660 static FXJSVALUETYPE GET_VALUE_TYPE(v8::Handle<v8::Value> p) | |
| 
 
brucedawson
2015/02/17 21:08:02
I wonder why GET_VALUE_TYPE was defined as static
 
 | |
| 661 { | |
| 662 | |
| 663 » » const unsigned int nHash = JS_CalcHash(JS_GetTypeof(p)); | |
| 664 | |
| 665 » » if (nHash == JSCONST_nUndefHash) | |
| 666 » » » return VT_undefined; | |
| 667 » » else if (nHash == JSCONST_nNullHash) | |
| 668 » » » return VT_null; | |
| 669 » » else if (nHash == JSCONST_nStringHash) | |
| 670 » » » return VT_string; | |
| 671 » » else if (nHash == JSCONST_nNumberHash) | |
| 672 » » » return VT_number; | |
| 673 » » else if (nHash == JSCONST_nBoolHash) | |
| 674 » » » return VT_boolean; | |
| 675 » » else if (nHash == JSCONST_nDateHash) | |
| 676 » » » return VT_date; | |
| 677 » » else if (nHash == JSCONST_nObjectHash) | |
| 678 » » » return VT_object;» » | |
| 679 » » else if (nHash == JSCONST_nFXobjHash) | |
| 680 » » » return VT_fxobject; | |
| 681 | |
| 682 » » /* | |
| 683 » » const char * sType = p->getTypeof()->toDchars(); | |
| 684 » » if (strcmp(sType,VALUE_NAME_STRING) == 0) | |
| 685 » » » return VT_string; | |
| 686 » » else if (strcmp(sType,VALUE_NAME_NUMBER) == 0) | |
| 687 » » » return VT_number; | |
| 688 » » else if (strcmp(sType,VALUE_NAME_BOOLEAN) == 0) | |
| 689 » » » return VT_boolean; | |
| 690 » » else if (strcmp(sType,VALUE_NAME_DATE) == 0) | |
| 691 » » » return VT_date; | |
| 692 » » else if (strcmp(sType,VALUE_NAME_OBJECT) == 0) | |
| 693 » » » return VT_object; | |
| 694 » » else if (strcmp(sType,VALUE_NAME_FXOBJ) == 0) | |
| 695 » » » return VT_object; | |
| 696 » » else if (strcmp(sType,VALUE_NAME_NULL) == 0) | |
| 697 » » » return VT_null; | |
| 698 » » else if (strcmp(sType,VALUE_NAME_UNDEFINED) == 0) | |
| 699 » » » return VT_undefined; | |
| 700 » » » */ | |
| 701 | |
| 702 » return VT_unknown; | |
| 703 } | |
| 704 | 653 | 
| 705 #endif //_JS_DEFINE_H_ | 654 #endif //_JS_DEFINE_H_ | 
| OLD | NEW |