John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1 | // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 4 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
Dan Sinclair | f766ad2 | 2016-03-14 13:51:24 -0400 | [diff] [blame] | 7 | #ifndef FPDFSDK_JAVASCRIPT_JS_DEFINE_H_ |
| 8 | #define FPDFSDK_JAVASCRIPT_JS_DEFINE_H_ |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 9 | |
Dan Sinclair | 3ebd121 | 2016-03-09 09:59:23 -0500 | [diff] [blame] | 10 | #include <vector> |
| 11 | |
Dan Sinclair | f766ad2 | 2016-03-14 13:51:24 -0400 | [diff] [blame] | 12 | #include "fpdfsdk/javascript/JS_Object.h" |
| 13 | #include "fpdfsdk/javascript/JS_Value.h" |
| 14 | #include "fpdfsdk/javascript/resource.h" |
dsinclair | b3f2467 | 2016-07-12 10:42:14 -0700 | [diff] [blame] | 15 | #include "fxjs/include/fxjs_v8.h" |
Tom Sepez | a116045 | 2015-02-19 10:00:55 -0800 | [diff] [blame] | 16 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 17 | struct JSConstSpec { |
| 18 | const wchar_t* pName; |
| 19 | double number; |
thestig | fbe14b9 | 2016-05-02 13:31:10 -0700 | [diff] [blame] | 20 | const wchar_t* str; |
Dan Sinclair | f766ad2 | 2016-03-14 13:51:24 -0400 | [diff] [blame] | 21 | uint8_t t; // 0:double 1:str |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 22 | }; |
| 23 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 24 | struct JSPropertySpec { |
| 25 | const wchar_t* pName; |
| 26 | v8::AccessorGetterCallback pPropGet; |
| 27 | v8::AccessorSetterCallback pPropPut; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 28 | }; |
| 29 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 30 | struct JSMethodSpec { |
| 31 | const wchar_t* pName; |
| 32 | v8::FunctionCallback pMethodCall; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 33 | }; |
| 34 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 35 | #define JS_WIDESTRING(widestring) L## #widestring |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 36 | #define BEGIN_JS_STATIC_CONST(js_class_name) \ |
| 37 | JSConstSpec js_class_name::JS_Class_Consts[] = { |
| 38 | #define JS_STATIC_CONST_ENTRY_NUMBER(const_name, pValue) \ |
Nico Weber | 077f1a3 | 2015-08-06 15:08:57 -0700 | [diff] [blame] | 39 | { const_name, pValue, L"", 0 } \ |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 40 | , |
Tom Sepez | cd56a7d | 2015-10-06 11:45:28 -0700 | [diff] [blame] | 41 | |
Nico Weber | 077f1a3 | 2015-08-06 15:08:57 -0700 | [diff] [blame] | 42 | #define JS_STATIC_CONST_ENTRY_STRING(const_name, pValue) \ |
| 43 | { const_name, 0, pValue, 1 } \ |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 44 | , |
Tom Sepez | cd56a7d | 2015-10-06 11:45:28 -0700 | [diff] [blame] | 45 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 46 | #define END_JS_STATIC_CONST() \ |
| 47 | { 0, 0, 0, 0 } \ |
| 48 | } \ |
Dan Sinclair | 50cce60 | 2016-02-24 09:51:16 -0500 | [diff] [blame] | 49 | ; // NOLINT |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 50 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 51 | #define BEGIN_JS_STATIC_PROP(js_class_name) \ |
| 52 | JSPropertySpec js_class_name::JS_Class_Properties[] = { |
thestig | fbe14b9 | 2016-05-02 13:31:10 -0700 | [diff] [blame] | 53 | #define JS_STATIC_PROP_ENTRY(prop_name) \ |
| 54 | {JS_WIDESTRING(prop_name), get_##prop_name##_static, \ |
| 55 | set_##prop_name##_static}, // NOLINT |
Tom Sepez | cd56a7d | 2015-10-06 11:45:28 -0700 | [diff] [blame] | 56 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 57 | #define END_JS_STATIC_PROP() \ |
| 58 | { 0, 0, 0 } \ |
| 59 | } \ |
Dan Sinclair | 50cce60 | 2016-02-24 09:51:16 -0500 | [diff] [blame] | 60 | ; // NOLINT |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 61 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 62 | #define BEGIN_JS_STATIC_METHOD(js_class_name) \ |
| 63 | JSMethodSpec js_class_name::JS_Class_Methods[] = { |
| 64 | #define JS_STATIC_METHOD_ENTRY(method_name) \ |
| 65 | { JS_WIDESTRING(method_name), method_name##_static } \ |
| 66 | , |
Tom Sepez | cd56a7d | 2015-10-06 11:45:28 -0700 | [diff] [blame] | 67 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 68 | #define END_JS_STATIC_METHOD() \ |
| 69 | { 0, 0 } \ |
| 70 | } \ |
Dan Sinclair | 50cce60 | 2016-02-24 09:51:16 -0500 | [diff] [blame] | 71 | ; // NOLINT |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 72 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 73 | template <class C, |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 74 | FX_BOOL (C::*M)(IJS_Context*, CJS_PropValue&, CFX_WideString&)> |
Tom Sepez | a116045 | 2015-02-19 10:00:55 -0800 | [diff] [blame] | 75 | void JSPropGetter(const char* prop_name_string, |
| 76 | const char* class_name_string, |
| 77 | v8::Local<v8::String> property, |
| 78 | const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 79 | v8::Isolate* isolate = info.GetIsolate(); |
Tom Sepez | b8ec0a3 | 2015-11-20 14:23:02 -0800 | [diff] [blame] | 80 | CJS_Runtime* pRuntime = |
| 81 | static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(isolate)); |
Tom Sepez | bd7fabf | 2015-09-28 10:31:27 -0700 | [diff] [blame] | 82 | if (!pRuntime) |
Tom Sepez | a25fd09 | 2015-09-28 09:06:03 -0700 | [diff] [blame] | 83 | return; |
Tom Sepez | dfbf8e7 | 2015-10-14 14:17:26 -0700 | [diff] [blame] | 84 | IJS_Context* pContext = pRuntime->GetCurrentContext(); |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 85 | CJS_Object* pJSObj = (CJS_Object*)FXJS_GetPrivate(isolate, info.Holder()); |
Tom Sepez | a116045 | 2015-02-19 10:00:55 -0800 | [diff] [blame] | 86 | C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); |
Tom Sepez | 3a83266 | 2015-03-02 12:59:05 -0800 | [diff] [blame] | 87 | CFX_WideString sError; |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 88 | CJS_PropValue value(pRuntime); |
Tom Sepez | a25fd09 | 2015-09-28 09:06:03 -0700 | [diff] [blame] | 89 | value.StartGetting(); |
Tom Sepez | dfbf8e7 | 2015-10-14 14:17:26 -0700 | [diff] [blame] | 90 | if (!(pObj->*M)(pContext, value, sError)) { |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 91 | FXJS_Error(isolate, JSFormatErrorString(class_name_string, prop_name_string, |
| 92 | sError)); |
Tom Sepez | a116045 | 2015-02-19 10:00:55 -0800 | [diff] [blame] | 93 | return; |
| 94 | } |
tsepez | fbf52c2 | 2016-07-25 11:17:07 -0700 | [diff] [blame^] | 95 | info.GetReturnValue().Set(value.ToV8Value()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 96 | } |
| 97 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 98 | template <class C, |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 99 | FX_BOOL (C::*M)(IJS_Context*, CJS_PropValue&, CFX_WideString&)> |
Tom Sepez | a116045 | 2015-02-19 10:00:55 -0800 | [diff] [blame] | 100 | void JSPropSetter(const char* prop_name_string, |
| 101 | const char* class_name_string, |
| 102 | v8::Local<v8::String> property, |
| 103 | v8::Local<v8::Value> value, |
| 104 | const v8::PropertyCallbackInfo<void>& info) { |
| 105 | v8::Isolate* isolate = info.GetIsolate(); |
Tom Sepez | b8ec0a3 | 2015-11-20 14:23:02 -0800 | [diff] [blame] | 106 | CJS_Runtime* pRuntime = |
| 107 | static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(isolate)); |
Tom Sepez | bd7fabf | 2015-09-28 10:31:27 -0700 | [diff] [blame] | 108 | if (!pRuntime) |
Tom Sepez | a25fd09 | 2015-09-28 09:06:03 -0700 | [diff] [blame] | 109 | return; |
Tom Sepez | dfbf8e7 | 2015-10-14 14:17:26 -0700 | [diff] [blame] | 110 | IJS_Context* pContext = pRuntime->GetCurrentContext(); |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 111 | CJS_Object* pJSObj = (CJS_Object*)FXJS_GetPrivate(isolate, info.Holder()); |
Tom Sepez | a116045 | 2015-02-19 10:00:55 -0800 | [diff] [blame] | 112 | C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); |
Tom Sepez | 3a83266 | 2015-03-02 12:59:05 -0800 | [diff] [blame] | 113 | CFX_WideString sError; |
tsepez | 40faa79 | 2016-07-15 17:58:02 -0700 | [diff] [blame] | 114 | CJS_PropValue propValue(CJS_Value(pRuntime, value)); |
Tom Sepez | a25fd09 | 2015-09-28 09:06:03 -0700 | [diff] [blame] | 115 | propValue.StartSetting(); |
Tom Sepez | dfbf8e7 | 2015-10-14 14:17:26 -0700 | [diff] [blame] | 116 | if (!(pObj->*M)(pContext, propValue, sError)) { |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 117 | FXJS_Error(isolate, JSFormatErrorString(class_name_string, prop_name_string, |
| 118 | sError)); |
Tom Sepez | a116045 | 2015-02-19 10:00:55 -0800 | [diff] [blame] | 119 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 120 | } |
| 121 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 122 | #define JS_STATIC_PROP(prop_name, class_name) \ |
| 123 | static void get_##prop_name##_static( \ |
| 124 | v8::Local<v8::String> property, \ |
| 125 | const v8::PropertyCallbackInfo<v8::Value>& info) { \ |
| 126 | JSPropGetter<class_name, &class_name::prop_name>(#prop_name, #class_name, \ |
| 127 | property, info); \ |
| 128 | } \ |
| 129 | static void set_##prop_name##_static( \ |
| 130 | v8::Local<v8::String> property, v8::Local<v8::Value> value, \ |
| 131 | const v8::PropertyCallbackInfo<void>& info) { \ |
| 132 | JSPropSetter<class_name, &class_name::prop_name>(#prop_name, #class_name, \ |
| 133 | property, value, info); \ |
Tom Sepez | a116045 | 2015-02-19 10:00:55 -0800 | [diff] [blame] | 134 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 135 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 136 | template <class C, |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 137 | FX_BOOL (C::*M)(IJS_Context*, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 138 | const std::vector<CJS_Value>&, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 139 | CJS_Value&, |
| 140 | CFX_WideString&)> |
Tom Sepez | a116045 | 2015-02-19 10:00:55 -0800 | [diff] [blame] | 141 | void JSMethod(const char* method_name_string, |
| 142 | const char* class_name_string, |
| 143 | const v8::FunctionCallbackInfo<v8::Value>& info) { |
| 144 | v8::Isolate* isolate = info.GetIsolate(); |
Tom Sepez | b8ec0a3 | 2015-11-20 14:23:02 -0800 | [diff] [blame] | 145 | CJS_Runtime* pRuntime = |
| 146 | static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(isolate)); |
Tom Sepez | bd7fabf | 2015-09-28 10:31:27 -0700 | [diff] [blame] | 147 | if (!pRuntime) |
Tom Sepez | a25fd09 | 2015-09-28 09:06:03 -0700 | [diff] [blame] | 148 | return; |
Tom Sepez | dfbf8e7 | 2015-10-14 14:17:26 -0700 | [diff] [blame] | 149 | IJS_Context* pContext = pRuntime->GetCurrentContext(); |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 150 | std::vector<CJS_Value> parameters; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 151 | for (unsigned int i = 0; i < (unsigned int)info.Length(); i++) { |
tsepez | 40faa79 | 2016-07-15 17:58:02 -0700 | [diff] [blame] | 152 | parameters.push_back(CJS_Value(pRuntime, info[i])); |
Tom Sepez | a116045 | 2015-02-19 10:00:55 -0800 | [diff] [blame] | 153 | } |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 154 | CJS_Value valueRes(pRuntime); |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 155 | CJS_Object* pJSObj = (CJS_Object*)FXJS_GetPrivate(isolate, info.Holder()); |
Tom Sepez | a116045 | 2015-02-19 10:00:55 -0800 | [diff] [blame] | 156 | C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); |
Tom Sepez | 3a83266 | 2015-03-02 12:59:05 -0800 | [diff] [blame] | 157 | CFX_WideString sError; |
Tom Sepez | dfbf8e7 | 2015-10-14 14:17:26 -0700 | [diff] [blame] | 158 | if (!(pObj->*M)(pContext, parameters, valueRes, sError)) { |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 159 | FXJS_Error(isolate, JSFormatErrorString(class_name_string, |
| 160 | method_name_string, sError)); |
Tom Sepez | a116045 | 2015-02-19 10:00:55 -0800 | [diff] [blame] | 161 | return; |
| 162 | } |
Tom Sepez | f4ef3f9 | 2015-04-23 11:31:31 -0700 | [diff] [blame] | 163 | info.GetReturnValue().Set(valueRes.ToV8Value()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 164 | } |
| 165 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 166 | #define JS_STATIC_METHOD(method_name, class_name) \ |
| 167 | static void method_name##_static( \ |
| 168 | const v8::FunctionCallbackInfo<v8::Value>& info) { \ |
| 169 | JSMethod<class_name, &class_name::method_name>(#method_name, #class_name, \ |
| 170 | info); \ |
Tom Sepez | a116045 | 2015-02-19 10:00:55 -0800 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | #define JS_SPECIAL_STATIC_METHOD(method_name, class_alternate, class_name) \ |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 174 | static void method_name##_static( \ |
| 175 | const v8::FunctionCallbackInfo<v8::Value>& info) { \ |
| 176 | JSMethod<class_alternate, &class_alternate::method_name>( \ |
| 177 | #method_name, #class_name, info); \ |
Tom Sepez | a116045 | 2015-02-19 10:00:55 -0800 | [diff] [blame] | 178 | } |
| 179 | |
Tom Sepez | cd56a7d | 2015-10-06 11:45:28 -0700 | [diff] [blame] | 180 | // All JS classes have a name, an object defintion ID, and the ability to |
| 181 | // register themselves with FXJS_V8. We never make a BASE class on its own |
| 182 | // because it can't really do anything. |
| 183 | #define DECLARE_JS_CLASS_BASE_PART() \ |
| 184 | static const wchar_t* g_pClassName; \ |
| 185 | static int g_nObjDefnID; \ |
| 186 | static void DefineJSObjects(v8::Isolate* pIsolate, FXJSOBJTYPE eObjType); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 187 | |
Tom Sepez | cd56a7d | 2015-10-06 11:45:28 -0700 | [diff] [blame] | 188 | #define IMPLEMENT_JS_CLASS_BASE_PART(js_class_name, class_name) \ |
| 189 | const wchar_t* js_class_name::g_pClassName = JS_WIDESTRING(class_name); \ |
| 190 | int js_class_name::g_nObjDefnID = -1; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 191 | |
Tom Sepez | cd56a7d | 2015-10-06 11:45:28 -0700 | [diff] [blame] | 192 | // CONST classes provide constants, but not constructors, methods, or props. |
| 193 | #define DECLARE_JS_CLASS_CONST() \ |
| 194 | DECLARE_JS_CLASS_BASE_PART() \ |
| 195 | DECLARE_JS_CLASS_CONST_PART() |
| 196 | |
| 197 | #define IMPLEMENT_JS_CLASS_CONST(js_class_name, class_name) \ |
| 198 | IMPLEMENT_JS_CLASS_BASE_PART(js_class_name, class_name) \ |
| 199 | IMPLEMENT_JS_CLASS_CONST_PART(js_class_name, class_name) \ |
| 200 | void js_class_name::DefineJSObjects(v8::Isolate* pIsolate, \ |
| 201 | FXJSOBJTYPE eObjType) { \ |
| 202 | g_nObjDefnID = FXJS_DefineObj(pIsolate, js_class_name::g_pClassName, \ |
| 203 | eObjType, nullptr, nullptr); \ |
| 204 | DefineConsts(pIsolate); \ |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 205 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 206 | |
Tom Sepez | cd56a7d | 2015-10-06 11:45:28 -0700 | [diff] [blame] | 207 | #define DECLARE_JS_CLASS_CONST_PART() \ |
| 208 | static JSConstSpec JS_Class_Consts[]; \ |
| 209 | static void DefineConsts(v8::Isolate* pIsolate); |
| 210 | |
thestig | fbe14b9 | 2016-05-02 13:31:10 -0700 | [diff] [blame] | 211 | #define IMPLEMENT_JS_CLASS_CONST_PART(js_class_name, class_name) \ |
| 212 | void js_class_name::DefineConsts(v8::Isolate* pIsolate) { \ |
| 213 | for (size_t i = 0; i < FX_ArraySize(JS_Class_Consts) - 1; ++i) { \ |
| 214 | FXJS_DefineObjConst( \ |
| 215 | pIsolate, g_nObjDefnID, JS_Class_Consts[i].pName, \ |
| 216 | JS_Class_Consts[i].t == 0 \ |
| 217 | ? FXJS_NewNumber(pIsolate, JS_Class_Consts[i].number) \ |
| 218 | : FXJS_NewString(pIsolate, JS_Class_Consts[i].str)); \ |
| 219 | } \ |
Tom Sepez | cd56a7d | 2015-10-06 11:45:28 -0700 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | // Convenience macros for declaring classes without an alternate. |
| 223 | #define DECLARE_JS_CLASS() DECLARE_JS_CLASS_RICH() |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 224 | #define IMPLEMENT_JS_CLASS(js_class_name, class_name) \ |
| 225 | IMPLEMENT_JS_CLASS_RICH(js_class_name, class_name, class_name) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 226 | |
Tom Sepez | cd56a7d | 2015-10-06 11:45:28 -0700 | [diff] [blame] | 227 | // Rich JS classes provide constants, methods, properties, and the ability |
| 228 | // to construct native object state. |
| 229 | #define DECLARE_JS_CLASS_RICH() \ |
| 230 | DECLARE_JS_CLASS_BASE_PART() \ |
| 231 | DECLARE_JS_CLASS_CONST_PART() \ |
| 232 | DECLARE_JS_CLASS_RICH_PART() |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 233 | |
Tom Sepez | cd56a7d | 2015-10-06 11:45:28 -0700 | [diff] [blame] | 234 | #define IMPLEMENT_JS_CLASS_RICH(js_class_name, class_alternate, class_name) \ |
| 235 | IMPLEMENT_JS_CLASS_BASE_PART(js_class_name, class_name) \ |
| 236 | IMPLEMENT_JS_CLASS_CONST_PART(js_class_name, class_name) \ |
| 237 | IMPLEMENT_JS_CLASS_RICH_PART(js_class_name, class_alternate, class_name) \ |
| 238 | void js_class_name::DefineJSObjects(v8::Isolate* pIsolate, \ |
| 239 | FXJSOBJTYPE eObjType) { \ |
| 240 | g_nObjDefnID = FXJS_DefineObj(pIsolate, js_class_name::g_pClassName, \ |
| 241 | eObjType, JSConstructor, JSDestructor); \ |
| 242 | DefineConsts(pIsolate); \ |
| 243 | DefineProps(pIsolate); \ |
| 244 | DefineMethods(pIsolate); \ |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 245 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 246 | |
Tom Sepez | 3342090 | 2015-10-13 15:00:10 -0700 | [diff] [blame] | 247 | #define DECLARE_JS_CLASS_RICH_PART() \ |
| 248 | static void JSConstructor(IJS_Runtime* pRuntime, v8::Local<v8::Object> obj); \ |
| 249 | static void JSDestructor(v8::Local<v8::Object> obj); \ |
| 250 | static void DefineProps(v8::Isolate* pIsoalte); \ |
| 251 | static void DefineMethods(v8::Isolate* pIsoalte); \ |
| 252 | static JSPropertySpec JS_Class_Properties[]; \ |
Tom Sepez | cd56a7d | 2015-10-06 11:45:28 -0700 | [diff] [blame] | 253 | static JSMethodSpec JS_Class_Methods[]; |
| 254 | |
| 255 | #define IMPLEMENT_JS_CLASS_RICH_PART(js_class_name, class_alternate, \ |
| 256 | class_name) \ |
Tom Sepez | 3342090 | 2015-10-13 15:00:10 -0700 | [diff] [blame] | 257 | void js_class_name::JSConstructor(IJS_Runtime* pIRuntime, \ |
Tom Sepez | 7fed2e7 | 2015-10-07 13:09:38 -0700 | [diff] [blame] | 258 | v8::Local<v8::Object> obj) { \ |
Tom Sepez | cd56a7d | 2015-10-06 11:45:28 -0700 | [diff] [blame] | 259 | CJS_Object* pObj = new js_class_name(obj); \ |
| 260 | pObj->SetEmbedObject(new class_alternate(pObj)); \ |
| 261 | FXJS_SetPrivate(nullptr, obj, (void*)pObj); \ |
Tom Sepez | 3342090 | 2015-10-13 15:00:10 -0700 | [diff] [blame] | 262 | pObj->InitInstance(pIRuntime); \ |
Tom Sepez | cd56a7d | 2015-10-06 11:45:28 -0700 | [diff] [blame] | 263 | } \ |
| 264 | void js_class_name::JSDestructor(v8::Local<v8::Object> obj) { \ |
| 265 | js_class_name* pObj = (js_class_name*)FXJS_GetPrivate(nullptr, obj); \ |
| 266 | pObj->ExitInstance(); \ |
| 267 | delete pObj; \ |
| 268 | } \ |
| 269 | void js_class_name::DefineProps(v8::Isolate* pIsolate) { \ |
| 270 | for (size_t i = 0; i < FX_ArraySize(JS_Class_Properties) - 1; ++i) { \ |
| 271 | FXJS_DefineObjProperty( \ |
| 272 | pIsolate, g_nObjDefnID, JS_Class_Properties[i].pName, \ |
| 273 | JS_Class_Properties[i].pPropGet, JS_Class_Properties[i].pPropPut); \ |
| 274 | } \ |
| 275 | } \ |
| 276 | void js_class_name::DefineMethods(v8::Isolate* pIsolate) { \ |
| 277 | for (size_t i = 0; i < FX_ArraySize(JS_Class_Methods) - 1; ++i) { \ |
| 278 | FXJS_DefineObjMethod(pIsolate, g_nObjDefnID, JS_Class_Methods[i].pName, \ |
| 279 | JS_Class_Methods[i].pMethodCall); \ |
| 280 | } \ |
| 281 | } |
| 282 | |
| 283 | // Special JS classes implement methods, props, and queries, but not consts. |
| 284 | #define DECLARE_SPECIAL_JS_CLASS() \ |
| 285 | DECLARE_JS_CLASS_BASE_PART() \ |
| 286 | DECLARE_JS_CLASS_CONST_PART() \ |
| 287 | DECLARE_JS_CLASS_RICH_PART() \ |
| 288 | DECLARE_SPECIAL_JS_CLASS_PART() |
| 289 | |
| 290 | #define IMPLEMENT_SPECIAL_JS_CLASS(js_class_name, class_alternate, class_name) \ |
| 291 | IMPLEMENT_JS_CLASS_BASE_PART(js_class_name, class_name) \ |
| 292 | IMPLEMENT_JS_CLASS_CONST_PART(js_class_name, class_name) \ |
| 293 | IMPLEMENT_JS_CLASS_RICH_PART(js_class_name, class_alternate, class_name) \ |
| 294 | IMPLEMENT_SPECIAL_JS_CLASS_PART(js_class_name, class_alternate, class_name) \ |
| 295 | void js_class_name::DefineJSObjects(v8::Isolate* pIsolate, \ |
| 296 | FXJSOBJTYPE eObjType) { \ |
| 297 | g_nObjDefnID = FXJS_DefineObj(pIsolate, js_class_name::g_pClassName, \ |
| 298 | eObjType, JSConstructor, JSDestructor); \ |
| 299 | DefineConsts(pIsolate); \ |
| 300 | DefineProps(pIsolate); \ |
| 301 | DefineMethods(pIsolate); \ |
| 302 | DefineAllProperties(pIsolate); \ |
| 303 | } |
| 304 | |
| 305 | #define DECLARE_SPECIAL_JS_CLASS_PART() \ |
| 306 | static void queryprop_static( \ |
| 307 | v8::Local<v8::String> property, \ |
| 308 | const v8::PropertyCallbackInfo<v8::Integer>& info); \ |
| 309 | static void getprop_static(v8::Local<v8::String> property, \ |
| 310 | const v8::PropertyCallbackInfo<v8::Value>& info); \ |
| 311 | static void putprop_static(v8::Local<v8::String> property, \ |
| 312 | v8::Local<v8::Value> value, \ |
| 313 | const v8::PropertyCallbackInfo<v8::Value>& info); \ |
| 314 | static void delprop_static( \ |
| 315 | v8::Local<v8::String> property, \ |
| 316 | const v8::PropertyCallbackInfo<v8::Boolean>& info); \ |
| 317 | static void DefineAllProperties(v8::Isolate* pIsolate); |
| 318 | |
| 319 | #define IMPLEMENT_SPECIAL_JS_CLASS_PART(js_class_name, class_alternate, \ |
| 320 | class_name) \ |
| 321 | void js_class_name::queryprop_static( \ |
| 322 | v8::Local<v8::String> property, \ |
| 323 | const v8::PropertyCallbackInfo<v8::Integer>& info) { \ |
| 324 | JSSpecialPropQuery<class_alternate>(#class_name, property, info); \ |
| 325 | } \ |
| 326 | void js_class_name::getprop_static( \ |
| 327 | v8::Local<v8::String> property, \ |
| 328 | const v8::PropertyCallbackInfo<v8::Value>& info) { \ |
| 329 | JSSpecialPropGet<class_alternate>(#class_name, property, info); \ |
| 330 | } \ |
| 331 | void js_class_name::putprop_static( \ |
| 332 | v8::Local<v8::String> property, v8::Local<v8::Value> value, \ |
| 333 | const v8::PropertyCallbackInfo<v8::Value>& info) { \ |
| 334 | JSSpecialPropPut<class_alternate>(#class_name, property, value, info); \ |
| 335 | } \ |
| 336 | void js_class_name::delprop_static( \ |
| 337 | v8::Local<v8::String> property, \ |
| 338 | const v8::PropertyCallbackInfo<v8::Boolean>& info) { \ |
| 339 | JSSpecialPropDel<class_alternate>(#class_name, property, info); \ |
| 340 | } \ |
| 341 | void js_class_name::DefineAllProperties(v8::Isolate* pIsolate) { \ |
| 342 | FXJS_DefineObjAllProperties( \ |
| 343 | pIsolate, g_nObjDefnID, js_class_name::queryprop_static, \ |
| 344 | js_class_name::getprop_static, js_class_name::putprop_static, \ |
| 345 | js_class_name::delprop_static); \ |
| 346 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 347 | |
Tom Sepez | 2311b78 | 2015-02-23 10:22:51 -0800 | [diff] [blame] | 348 | template <class Alt> |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 349 | void JSSpecialPropQuery(const char*, |
| 350 | v8::Local<v8::String> property, |
| 351 | const v8::PropertyCallbackInfo<v8::Integer>& info) { |
Tom Sepez | 2311b78 | 2015-02-23 10:22:51 -0800 | [diff] [blame] | 352 | v8::Isolate* isolate = info.GetIsolate(); |
| 353 | v8::String::Utf8Value utf8_value(property); |
tsepez | 6fe7d21 | 2016-04-06 10:51:14 -0700 | [diff] [blame] | 354 | CFX_WideString propname = CFX_WideString::FromUTF8( |
| 355 | CFX_ByteStringC(*utf8_value, utf8_value.length())); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 356 | CJS_Object* pJSObj = |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 357 | reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder())); |
Tom Sepez | 2311b78 | 2015-02-23 10:22:51 -0800 | [diff] [blame] | 358 | Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); |
| 359 | FX_BOOL bRet = pObj->QueryProperty(propname.c_str()); |
| 360 | info.GetReturnValue().Set(bRet ? 4 : 0); |
| 361 | } |
| 362 | |
| 363 | template <class Alt> |
| 364 | void JSSpecialPropGet(const char* class_name, |
| 365 | v8::Local<v8::String> property, |
| 366 | const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 367 | v8::Isolate* isolate = info.GetIsolate(); |
Tom Sepez | b8ec0a3 | 2015-11-20 14:23:02 -0800 | [diff] [blame] | 368 | CJS_Runtime* pRuntime = |
| 369 | static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(isolate)); |
Tom Sepez | bd7fabf | 2015-09-28 10:31:27 -0700 | [diff] [blame] | 370 | if (!pRuntime) |
Tom Sepez | a25fd09 | 2015-09-28 09:06:03 -0700 | [diff] [blame] | 371 | return; |
Tom Sepez | dfbf8e7 | 2015-10-14 14:17:26 -0700 | [diff] [blame] | 372 | IJS_Context* pContext = pRuntime->GetCurrentContext(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 373 | CJS_Object* pJSObj = |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 374 | reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder())); |
Tom Sepez | 2311b78 | 2015-02-23 10:22:51 -0800 | [diff] [blame] | 375 | Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); |
| 376 | v8::String::Utf8Value utf8_value(property); |
tsepez | 6fe7d21 | 2016-04-06 10:51:14 -0700 | [diff] [blame] | 377 | CFX_WideString propname = CFX_WideString::FromUTF8( |
| 378 | CFX_ByteStringC(*utf8_value, utf8_value.length())); |
Tom Sepez | 3a83266 | 2015-03-02 12:59:05 -0800 | [diff] [blame] | 379 | CFX_WideString sError; |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 380 | CJS_PropValue value(pRuntime); |
Tom Sepez | 2311b78 | 2015-02-23 10:22:51 -0800 | [diff] [blame] | 381 | value.StartGetting(); |
Tom Sepez | dfbf8e7 | 2015-10-14 14:17:26 -0700 | [diff] [blame] | 382 | if (!pObj->DoProperty(pContext, propname.c_str(), value, sError)) { |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 383 | FXJS_Error(isolate, JSFormatErrorString(class_name, "GetProperty", sError)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 384 | return; |
Tom Sepez | 2311b78 | 2015-02-23 10:22:51 -0800 | [diff] [blame] | 385 | } |
tsepez | fbf52c2 | 2016-07-25 11:17:07 -0700 | [diff] [blame^] | 386 | info.GetReturnValue().Set(value.ToV8Value()); |
Tom Sepez | 2311b78 | 2015-02-23 10:22:51 -0800 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | template <class Alt> |
| 390 | void JSSpecialPropPut(const char* class_name, |
| 391 | v8::Local<v8::String> property, |
| 392 | v8::Local<v8::Value> value, |
| 393 | const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 394 | v8::Isolate* isolate = info.GetIsolate(); |
Tom Sepez | b8ec0a3 | 2015-11-20 14:23:02 -0800 | [diff] [blame] | 395 | CJS_Runtime* pRuntime = |
| 396 | static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(isolate)); |
Tom Sepez | bd7fabf | 2015-09-28 10:31:27 -0700 | [diff] [blame] | 397 | if (!pRuntime) |
Tom Sepez | a25fd09 | 2015-09-28 09:06:03 -0700 | [diff] [blame] | 398 | return; |
Tom Sepez | dfbf8e7 | 2015-10-14 14:17:26 -0700 | [diff] [blame] | 399 | IJS_Context* pContext = pRuntime->GetCurrentContext(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 400 | CJS_Object* pJSObj = |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 401 | reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder())); |
Tom Sepez | 2311b78 | 2015-02-23 10:22:51 -0800 | [diff] [blame] | 402 | Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); |
| 403 | v8::String::Utf8Value utf8_value(property); |
tsepez | 6fe7d21 | 2016-04-06 10:51:14 -0700 | [diff] [blame] | 404 | CFX_WideString propname = CFX_WideString::FromUTF8( |
| 405 | CFX_ByteStringC(*utf8_value, utf8_value.length())); |
Tom Sepez | 3a83266 | 2015-03-02 12:59:05 -0800 | [diff] [blame] | 406 | CFX_WideString sError; |
tsepez | 40faa79 | 2016-07-15 17:58:02 -0700 | [diff] [blame] | 407 | CJS_PropValue PropValue(CJS_Value(pRuntime, value)); |
Tom Sepez | 2311b78 | 2015-02-23 10:22:51 -0800 | [diff] [blame] | 408 | PropValue.StartSetting(); |
Tom Sepez | dfbf8e7 | 2015-10-14 14:17:26 -0700 | [diff] [blame] | 409 | if (!pObj->DoProperty(pContext, propname.c_str(), PropValue, sError)) { |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 410 | FXJS_Error(isolate, JSFormatErrorString(class_name, "PutProperty", sError)); |
Tom Sepez | 2311b78 | 2015-02-23 10:22:51 -0800 | [diff] [blame] | 411 | } |
| 412 | } |
| 413 | |
| 414 | template <class Alt> |
| 415 | void JSSpecialPropDel(const char* class_name, |
| 416 | v8::Local<v8::String> property, |
| 417 | const v8::PropertyCallbackInfo<v8::Boolean>& info) { |
| 418 | v8::Isolate* isolate = info.GetIsolate(); |
Tom Sepez | b8ec0a3 | 2015-11-20 14:23:02 -0800 | [diff] [blame] | 419 | IJS_Runtime* pRuntime = FXJS_GetRuntimeFromIsolate(isolate); |
Tom Sepez | bd7fabf | 2015-09-28 10:31:27 -0700 | [diff] [blame] | 420 | if (!pRuntime) |
Tom Sepez | a25fd09 | 2015-09-28 09:06:03 -0700 | [diff] [blame] | 421 | return; |
Tom Sepez | dfbf8e7 | 2015-10-14 14:17:26 -0700 | [diff] [blame] | 422 | IJS_Context* pContext = pRuntime->GetCurrentContext(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 423 | CJS_Object* pJSObj = |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 424 | reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder())); |
Tom Sepez | 2311b78 | 2015-02-23 10:22:51 -0800 | [diff] [blame] | 425 | Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); |
| 426 | v8::String::Utf8Value utf8_value(property); |
tsepez | 6fe7d21 | 2016-04-06 10:51:14 -0700 | [diff] [blame] | 427 | CFX_WideString propname = CFX_WideString::FromUTF8( |
| 428 | CFX_ByteStringC(*utf8_value, utf8_value.length())); |
Tom Sepez | 3a83266 | 2015-03-02 12:59:05 -0800 | [diff] [blame] | 429 | CFX_WideString sError; |
Tom Sepez | dfbf8e7 | 2015-10-14 14:17:26 -0700 | [diff] [blame] | 430 | if (!pObj->DelProperty(pContext, propname.c_str(), sError)) { |
Tom Sepez | 2311b78 | 2015-02-23 10:22:51 -0800 | [diff] [blame] | 431 | CFX_ByteString cbName; |
| 432 | cbName.Format("%s.%s", class_name, "DelProperty"); |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 433 | // Probably a missing call to JSFX_Error(). |
Tom Sepez | 2311b78 | 2015-02-23 10:22:51 -0800 | [diff] [blame] | 434 | } |
| 435 | } |
| 436 | |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 437 | template <FX_BOOL (*F)(IJS_Context*, |
| 438 | const std::vector<CJS_Value>&, |
| 439 | CJS_Value&, |
| 440 | CFX_WideString&)> |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 441 | void JSGlobalFunc(const char* func_name_string, |
Tom Sepez | a116045 | 2015-02-19 10:00:55 -0800 | [diff] [blame] | 442 | const v8::FunctionCallbackInfo<v8::Value>& info) { |
Tom Sepez | b8ec0a3 | 2015-11-20 14:23:02 -0800 | [diff] [blame] | 443 | CJS_Runtime* pRuntime = |
| 444 | static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(info.GetIsolate())); |
Tom Sepez | bd7fabf | 2015-09-28 10:31:27 -0700 | [diff] [blame] | 445 | if (!pRuntime) |
Tom Sepez | a25fd09 | 2015-09-28 09:06:03 -0700 | [diff] [blame] | 446 | return; |
Tom Sepez | dfbf8e7 | 2015-10-14 14:17:26 -0700 | [diff] [blame] | 447 | IJS_Context* pContext = pRuntime->GetCurrentContext(); |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 448 | std::vector<CJS_Value> parameters; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 449 | for (unsigned int i = 0; i < (unsigned int)info.Length(); i++) { |
tsepez | 40faa79 | 2016-07-15 17:58:02 -0700 | [diff] [blame] | 450 | parameters.push_back(CJS_Value(pRuntime, info[i])); |
Tom Sepez | a116045 | 2015-02-19 10:00:55 -0800 | [diff] [blame] | 451 | } |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 452 | CJS_Value valueRes(pRuntime); |
Tom Sepez | 3a83266 | 2015-03-02 12:59:05 -0800 | [diff] [blame] | 453 | CFX_WideString sError; |
Tom Sepez | dfbf8e7 | 2015-10-14 14:17:26 -0700 | [diff] [blame] | 454 | if (!(*F)(pContext, parameters, valueRes, sError)) { |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 455 | FXJS_Error(pRuntime->GetIsolate(), |
| 456 | JSFormatErrorString(func_name_string, nullptr, sError)); |
Tom Sepez | a116045 | 2015-02-19 10:00:55 -0800 | [diff] [blame] | 457 | return; |
| 458 | } |
Tom Sepez | f4ef3f9 | 2015-04-23 11:31:31 -0700 | [diff] [blame] | 459 | info.GetReturnValue().Set(valueRes.ToV8Value()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 460 | } |
| 461 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 462 | #define JS_STATIC_GLOBAL_FUN(fun_name) \ |
| 463 | static void fun_name##_static( \ |
| 464 | const v8::FunctionCallbackInfo<v8::Value>& info) { \ |
| 465 | JSGlobalFunc<fun_name>(#fun_name, info); \ |
Tom Sepez | a116045 | 2015-02-19 10:00:55 -0800 | [diff] [blame] | 466 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 467 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 468 | #define JS_STATIC_DECLARE_GLOBAL_FUN() \ |
| 469 | static JSMethodSpec global_methods[]; \ |
Tom Sepez | 142165e | 2015-09-11 13:21:50 -0700 | [diff] [blame] | 470 | static void DefineJSObjects(v8::Isolate* pIsolate) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 471 | |
| 472 | #define BEGIN_JS_STATIC_GLOBAL_FUN(js_class_name) \ |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 473 | JSMethodSpec js_class_name::global_methods[] = { |
| 474 | #define JS_STATIC_GLOBAL_FUN_ENTRY(method_name) \ |
| 475 | JS_STATIC_METHOD_ENTRY(method_name) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 476 | |
| 477 | #define END_JS_STATIC_GLOBAL_FUN() END_JS_STATIC_METHOD() |
| 478 | |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 479 | #define IMPLEMENT_JS_STATIC_GLOBAL_FUN(js_class_name) \ |
| 480 | void js_class_name::DefineJSObjects(v8::Isolate* pIsolate) { \ |
Tom Sepez | cd56a7d | 2015-10-06 11:45:28 -0700 | [diff] [blame] | 481 | for (size_t i = 0; i < FX_ArraySize(global_methods) - 1; ++i) { \ |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 482 | FXJS_DefineGlobalMethod(pIsolate, \ |
| 483 | js_class_name::global_methods[i].pName, \ |
| 484 | js_class_name::global_methods[i].pMethodCall); \ |
| 485 | } \ |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 486 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 487 | |
Dan Sinclair | f766ad2 | 2016-03-14 13:51:24 -0400 | [diff] [blame] | 488 | #endif // FPDFSDK_JAVASCRIPT_JS_DEFINE_H_ |