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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 void js_class_name::JSDestructor(JSFXObject obj) \ | 176 void js_class_name::JSDestructor(JSFXObject obj) \ |
177 {\ | 177 {\ |
178 js_class_name* pObj = (js_class_name*)JS_GetPrivate(NULL,obj);\ | 178 js_class_name* pObj = (js_class_name*)JS_GetPrivate(NULL,obj);\ |
179 ASSERT(pObj != NULL);\ | 179 ASSERT(pObj != NULL);\ |
180 pObj->ExitInstance();\ | 180 pObj->ExitInstance();\ |
181 delete pObj;\ | 181 delete pObj;\ |
182 }\ | 182 }\ |
183 \ | 183 \ |
184 int js_class_name::Init(IJS_Runtime* pRuntime, FXJSOBJTYPE eObjType)\ | 184 int js_class_name::Init(IJS_Runtime* pRuntime, FXJSOBJTYPE eObjType)\ |
185 {\ | 185 {\ |
186 » int nObjDefnID = JS_DefineObj(pRuntime, js_class_name::m_pClassName, eOb
jType, JSConstructor, JSDestructor, 0);\ | 186 » int nObjDefnID = JS_DefineObj(pRuntime, js_class_name::m_pClassName, eOb
jType, JSConstructor, JSDestructor);\ |
187 if (nObjDefnID >= 0)\ | 187 if (nObjDefnID >= 0)\ |
188 {\ | 188 {\ |
189 for (int j=0, szj=sizeof(JS_Class_Properties)/sizeof(JSPropertyS
pec)-1; j<szj; j++)\ | 189 for (int j=0, szj=sizeof(JS_Class_Properties)/sizeof(JSPropertyS
pec)-1; j<szj; j++)\ |
190 {\ | 190 {\ |
191 if (JS_DefineObjProperty(pRuntime, nObjDefnID, JS_Class_
Properties[j].pName, JS_Class_Properties[j].pPropGet, JS_Class_Properties[j].pPr
opPut) < 0) return -1;\ | 191 if (JS_DefineObjProperty(pRuntime, nObjDefnID, JS_Class_
Properties[j].pName, JS_Class_Properties[j].pPropGet, JS_Class_Properties[j].pPr
opPut) < 0) return -1;\ |
192 }\ | 192 }\ |
193 for (int k=0, szk=sizeof(JS_Class_Methods)/sizeof(JSMethodSpec)-
1; k<szk; k++)\ | 193 for (int k=0, szk=sizeof(JS_Class_Methods)/sizeof(JSMethodSpec)-
1; k<szk; k++)\ |
194 {\ | 194 {\ |
195 if (JS_DefineObjMethod(pRuntime, nObjDefnID,JS_Class_Met
hods[k].pName, JS_Class_Methods[k].pMethodCall) < 0) return -1;\ | 195 if (JS_DefineObjMethod(pRuntime, nObjDefnID,JS_Class_Met
hods[k].pName, JS_Class_Methods[k].pMethodCall) < 0) return -1;\ |
196 }\ | 196 }\ |
197 return nObjDefnID;\ | 197 return nObjDefnID;\ |
198 }\ | 198 }\ |
199 return -1;\ | 199 return -1;\ |
200 } | 200 } |
201 | 201 |
202 #define IMPLEMENT_JS_CLASS(js_class_name, class_name) IMPLEMENT_JS_CLASS_RICH(js
_class_name, class_name, class_name) | 202 #define IMPLEMENT_JS_CLASS(js_class_name, class_name) IMPLEMENT_JS_CLASS_RICH(js
_class_name, class_name, class_name) |
203 | 203 |
204 /* ======================================== CONST CLASS ========================
==================== */ | 204 /* ======================================== CONST CLASS ========================
==================== */ |
205 | 205 |
206 #define DECLARE_JS_CLASS_CONST() \ | 206 #define DECLARE_JS_CLASS_CONST() \ |
207 static int Init(IJS_Runtime* pRuntime, FXJSOBJTYPE eObjType);\ | 207 static int Init(IJS_Runtime* pRuntime, FXJSOBJTYPE eObjType);\ |
208 static JSConstSpec JS_Class_Consts[];\ | 208 static JSConstSpec JS_Class_Consts[];\ |
209 static const wchar_t* m_pClassName | 209 static const wchar_t* m_pClassName |
210 | 210 |
211 #define IMPLEMENT_JS_CLASS_CONST(js_class_name, class_name) \ | 211 #define IMPLEMENT_JS_CLASS_CONST(js_class_name, class_name) \ |
212 const wchar_t* js_class_name::m_pClassName = JS_WIDESTRING(class_name);\ | 212 const wchar_t* js_class_name::m_pClassName = JS_WIDESTRING(class_name);\ |
213 int js_class_name::Init(IJS_Runtime* pRuntime, FXJSOBJTYPE eObjType)\ | 213 int js_class_name::Init(IJS_Runtime* pRuntime, FXJSOBJTYPE eObjType)\ |
214 {\ | 214 {\ |
215 » int nObjDefnID = JS_DefineObj(pRuntime, js_class_name::m_pClassName, eOb
jType, NULL, NULL, 0);\ | 215 » int nObjDefnID = JS_DefineObj(pRuntime, js_class_name::m_pClassName, eOb
jType, NULL, NULL);\ |
216 if (nObjDefnID >=0)\ | 216 if (nObjDefnID >=0)\ |
217 {\ | 217 {\ |
218 for (int i=0, sz=sizeof(JS_Class_Consts)/sizeof(JSConstSpec)-1;
i<sz; i++)\ | 218 for (int i=0, sz=sizeof(JS_Class_Consts)/sizeof(JSConstSpec)-1;
i<sz; i++)\ |
219 {\ | 219 {\ |
220 if (JS_Class_Consts[i].t == 0)\ | 220 if (JS_Class_Consts[i].t == 0)\ |
221 {\ | 221 {\ |
222 if (JS_DefineObjConst(pRuntime, nObjDefnID, JS_C
lass_Consts[i].pName, JS_NewNumber(pRuntime,JS_Class_Consts[i].number)) < 0) ret
urn -1;\ | 222 if (JS_DefineObjConst(pRuntime, nObjDefnID, JS_C
lass_Consts[i].pName, JS_NewNumber(pRuntime,JS_Class_Consts[i].number)) < 0) ret
urn -1;\ |
223 }\ | 223 }\ |
224 else\ | 224 else\ |
225 {\ | 225 {\ |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 {\ | 352 {\ |
353 js_class_name* pObj = (js_class_name*)JS_GetPrivate(NULL,obj);\ | 353 js_class_name* pObj = (js_class_name*)JS_GetPrivate(NULL,obj);\ |
354 ASSERT(pObj != NULL);\ | 354 ASSERT(pObj != NULL);\ |
355 pObj->ExitInstance();\ | 355 pObj->ExitInstance();\ |
356 delete pObj;\ | 356 delete pObj;\ |
357 }\ | 357 }\ |
358 \ | 358 \ |
359 int js_class_name::Init(IJS_Runtime* pRuntime, FXJSOBJTYPE eObjType)\ | 359 int js_class_name::Init(IJS_Runtime* pRuntime, FXJSOBJTYPE eObjType)\ |
360 {\ | 360 {\ |
361 \ | 361 \ |
362 » int nObjDefnID = JS_DefineObj(pRuntime, js_class_name::m_pClassName, eOb
jType, JSConstructor, JSDestructor, 0);\ | 362 » int nObjDefnID = JS_DefineObj(pRuntime, js_class_name::m_pClassName, eOb
jType, JSConstructor, JSDestructor);\ |
363 \ | 363 \ |
364 if (nObjDefnID >= 0)\ | 364 if (nObjDefnID >= 0)\ |
365 {\ | 365 {\ |
366 for (int j=0, szj=sizeof(JS_Class_Properties)/sizeof(JSPropertyS
pec)-1; j<szj; j++)\ | 366 for (int j=0, szj=sizeof(JS_Class_Properties)/sizeof(JSPropertyS
pec)-1; j<szj; j++)\ |
367 {\ | 367 {\ |
368 if (JS_DefineObjProperty(pRuntime, nObjDefnID, JS_Class_
Properties[j].pName, JS_Class_Properties[j].pPropGet,JS_Class_Properties[j].pPro
pPut)<0)return -1;\ | 368 if (JS_DefineObjProperty(pRuntime, nObjDefnID, JS_Class_
Properties[j].pName, JS_Class_Properties[j].pPropGet,JS_Class_Properties[j].pPro
pPut)<0)return -1;\ |
369 }\ | 369 }\ |
370 \ | 370 \ |
371 for (int k=0, szk=sizeof(JS_Class_Methods)/sizeof(JSMethodSpec)-
1; k<szk; k++)\ | 371 for (int k=0, szk=sizeof(JS_Class_Methods)/sizeof(JSMethodSpec)-
1; k<szk; k++)\ |
372 {\ | 372 {\ |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 #define VALUE_NAME_BOOLEAN L"boolean" | 459 #define VALUE_NAME_BOOLEAN L"boolean" |
460 #define VALUE_NAME_DATE L"date" | 460 #define VALUE_NAME_DATE L"date" |
461 #define VALUE_NAME_OBJECT L"object" | 461 #define VALUE_NAME_OBJECT L"object" |
462 #define VALUE_NAME_FXOBJ L"fxobj" | 462 #define VALUE_NAME_FXOBJ L"fxobj" |
463 #define VALUE_NAME_NULL L"null" | 463 #define VALUE_NAME_NULL L"null" |
464 #define VALUE_NAME_UNDEFINED L"undefined" | 464 #define VALUE_NAME_UNDEFINED L"undefined" |
465 | 465 |
466 FXJSVALUETYPE GET_VALUE_TYPE(v8::Local<v8::Value> p); | 466 FXJSVALUETYPE GET_VALUE_TYPE(v8::Local<v8::Value> p); |
467 | 467 |
468 #endif // FPDFSDK_INCLUDE_JAVASCRIPT_JS_DEFINE_H_ | 468 #endif // FPDFSDK_INCLUDE_JAVASCRIPT_JS_DEFINE_H_ |
OLD | NEW |