| 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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 void js_class_name::JSDestructor(JSFXObject obj) \ | 167 void js_class_name::JSDestructor(JSFXObject obj) \ |
| 168 {\ | 168 {\ |
| 169 js_class_name* pObj = (js_class_name*)JS_GetPrivate(NULL,obj);\ | 169 js_class_name* pObj = (js_class_name*)JS_GetPrivate(NULL,obj);\ |
| 170 ASSERT(pObj != NULL);\ | 170 ASSERT(pObj != NULL);\ |
| 171 pObj->ExitInstance();\ | 171 pObj->ExitInstance();\ |
| 172 delete pObj;\ | 172 delete pObj;\ |
| 173 }\ | 173 }\ |
| 174 \ | 174 \ |
| 175 int js_class_name::Init(IJS_Runtime* pRuntime, FXJSOBJTYPE eObjType)\ | 175 int js_class_name::Init(IJS_Runtime* pRuntime, FXJSOBJTYPE eObjType)\ |
| 176 {\ | 176 {\ |
| 177 » int nObjDefnID = JS_DefineObj(pRuntime, js_class_name::m_pClassName, eOb
jType, JSConstructor, JSDestructor, 0);\ | 177 » int nObjDefnID = JS_DefineObj(pRuntime, js_class_name::m_pClassName, eOb
jType, JSConstructor, JSDestructor);\ |
| 178 if (nObjDefnID >= 0)\ | 178 if (nObjDefnID >= 0)\ |
| 179 {\ | 179 {\ |
| 180 for (int j=0, szj=sizeof(JS_Class_Properties)/sizeof(JSPropertyS
pec)-1; j<szj; j++)\ | 180 for (int j=0, szj=sizeof(JS_Class_Properties)/sizeof(JSPropertyS
pec)-1; j<szj; j++)\ |
| 181 {\ | 181 {\ |
| 182 if (JS_DefineObjProperty(pRuntime, nObjDefnID, JS_Class_
Properties[j].pName, JS_Class_Properties[j].pPropGet, JS_Class_Properties[j].pPr
opPut) < 0) return -1;\ | 182 if (JS_DefineObjProperty(pRuntime, nObjDefnID, JS_Class_
Properties[j].pName, JS_Class_Properties[j].pPropGet, JS_Class_Properties[j].pPr
opPut) < 0) return -1;\ |
| 183 }\ | 183 }\ |
| 184 for (int k=0, szk=sizeof(JS_Class_Methods)/sizeof(JSMethodSpec)-
1; k<szk; k++)\ | 184 for (int k=0, szk=sizeof(JS_Class_Methods)/sizeof(JSMethodSpec)-
1; k<szk; k++)\ |
| 185 {\ | 185 {\ |
| 186 if (JS_DefineObjMethod(pRuntime, nObjDefnID,JS_Class_Met
hods[k].pName, JS_Class_Methods[k].pMethodCall) < 0) return -1;\ | 186 if (JS_DefineObjMethod(pRuntime, nObjDefnID,JS_Class_Met
hods[k].pName, JS_Class_Methods[k].pMethodCall) < 0) return -1;\ |
| 187 }\ | 187 }\ |
| 188 return nObjDefnID;\ | 188 return nObjDefnID;\ |
| 189 }\ | 189 }\ |
| 190 return -1;\ | 190 return -1;\ |
| 191 } | 191 } |
| 192 | 192 |
| 193 #define IMPLEMENT_JS_CLASS(js_class_name, class_name) IMPLEMENT_JS_CLASS_RICH(js
_class_name, class_name, class_name) | 193 #define IMPLEMENT_JS_CLASS(js_class_name, class_name) IMPLEMENT_JS_CLASS_RICH(js
_class_name, class_name, class_name) |
| 194 | 194 |
| 195 /* ======================================== CONST CLASS ========================
==================== */ | 195 /* ======================================== CONST CLASS ========================
==================== */ |
| 196 | 196 |
| 197 #define DECLARE_JS_CLASS_CONST() \ | 197 #define DECLARE_JS_CLASS_CONST() \ |
| 198 static int Init(IJS_Runtime* pRuntime, FXJSOBJTYPE eObjType);\ | 198 static int Init(IJS_Runtime* pRuntime, FXJSOBJTYPE eObjType);\ |
| 199 static JSConstSpec JS_Class_Consts[];\ | 199 static JSConstSpec JS_Class_Consts[];\ |
| 200 static const wchar_t* m_pClassName | 200 static const wchar_t* m_pClassName |
| 201 | 201 |
| 202 #define IMPLEMENT_JS_CLASS_CONST(js_class_name, class_name) \ | 202 #define IMPLEMENT_JS_CLASS_CONST(js_class_name, class_name) \ |
| 203 const wchar_t* js_class_name::m_pClassName = JS_WIDESTRING(class_name);\ | 203 const wchar_t* js_class_name::m_pClassName = JS_WIDESTRING(class_name);\ |
| 204 int js_class_name::Init(IJS_Runtime* pRuntime, FXJSOBJTYPE eObjType)\ | 204 int js_class_name::Init(IJS_Runtime* pRuntime, FXJSOBJTYPE eObjType)\ |
| 205 {\ | 205 {\ |
| 206 » int nObjDefnID = JS_DefineObj(pRuntime, js_class_name::m_pClassName, eOb
jType, NULL, NULL, 0);\ | 206 » int nObjDefnID = JS_DefineObj(pRuntime, js_class_name::m_pClassName, eOb
jType, NULL, NULL);\ |
| 207 if (nObjDefnID >=0)\ | 207 if (nObjDefnID >=0)\ |
| 208 {\ | 208 {\ |
| 209 for (int i=0, sz=sizeof(JS_Class_Consts)/sizeof(JSConstSpec)-1;
i<sz; i++)\ | 209 for (int i=0, sz=sizeof(JS_Class_Consts)/sizeof(JSConstSpec)-1;
i<sz; i++)\ |
| 210 {\ | 210 {\ |
| 211 if (JS_Class_Consts[i].t == 0)\ | 211 if (JS_Class_Consts[i].t == 0)\ |
| 212 {\ | 212 {\ |
| 213 if (JS_DefineObjConst(pRuntime, nObjDefnID, JS_C
lass_Consts[i].pName, JS_NewNumber(pRuntime,JS_Class_Consts[i].number)) < 0) ret
urn -1;\ | 213 if (JS_DefineObjConst(pRuntime, nObjDefnID, JS_C
lass_Consts[i].pName, JS_NewNumber(pRuntime,JS_Class_Consts[i].number)) < 0) ret
urn -1;\ |
| 214 }\ | 214 }\ |
| 215 else\ | 215 else\ |
| 216 {\ | 216 {\ |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 {\ | 337 {\ |
| 338 js_class_name* pObj = (js_class_name*)JS_GetPrivate(NULL,obj);\ | 338 js_class_name* pObj = (js_class_name*)JS_GetPrivate(NULL,obj);\ |
| 339 ASSERT(pObj != NULL);\ | 339 ASSERT(pObj != NULL);\ |
| 340 pObj->ExitInstance();\ | 340 pObj->ExitInstance();\ |
| 341 delete pObj;\ | 341 delete pObj;\ |
| 342 }\ | 342 }\ |
| 343 \ | 343 \ |
| 344 int js_class_name::Init(IJS_Runtime* pRuntime, FXJSOBJTYPE eObjType)\ | 344 int js_class_name::Init(IJS_Runtime* pRuntime, FXJSOBJTYPE eObjType)\ |
| 345 {\ | 345 {\ |
| 346 \ | 346 \ |
| 347 » int nObjDefnID = JS_DefineObj(pRuntime, js_class_name::m_pClassName, eOb
jType, JSConstructor, JSDestructor, 0);\ | 347 » int nObjDefnID = JS_DefineObj(pRuntime, js_class_name::m_pClassName, eOb
jType, JSConstructor, JSDestructor);\ |
| 348 \ | 348 \ |
| 349 if (nObjDefnID >= 0)\ | 349 if (nObjDefnID >= 0)\ |
| 350 {\ | 350 {\ |
| 351 for (int j=0, szj=sizeof(JS_Class_Properties)/sizeof(JSPropertyS
pec)-1; j<szj; j++)\ | 351 for (int j=0, szj=sizeof(JS_Class_Properties)/sizeof(JSPropertyS
pec)-1; j<szj; j++)\ |
| 352 {\ | 352 {\ |
| 353 if (JS_DefineObjProperty(pRuntime, nObjDefnID, JS_Class_
Properties[j].pName, JS_Class_Properties[j].pPropGet,JS_Class_Properties[j].pPro
pPut)<0)return -1;\ | 353 if (JS_DefineObjProperty(pRuntime, nObjDefnID, JS_Class_
Properties[j].pName, JS_Class_Properties[j].pPropGet,JS_Class_Properties[j].pPro
pPut)<0)return -1;\ |
| 354 }\ | 354 }\ |
| 355 \ | 355 \ |
| 356 for (int k=0, szk=sizeof(JS_Class_Methods)/sizeof(JSMethodSpec)-
1; k<szk; k++)\ | 356 for (int k=0, szk=sizeof(JS_Class_Methods)/sizeof(JSMethodSpec)-
1; k<szk; k++)\ |
| 357 {\ | 357 {\ |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 #define VALUE_NAME_BOOLEAN L"boolean" | 440 #define VALUE_NAME_BOOLEAN L"boolean" |
| 441 #define VALUE_NAME_DATE L"date" | 441 #define VALUE_NAME_DATE L"date" |
| 442 #define VALUE_NAME_OBJECT L"object" | 442 #define VALUE_NAME_OBJECT L"object" |
| 443 #define VALUE_NAME_FXOBJ L"fxobj" | 443 #define VALUE_NAME_FXOBJ L"fxobj" |
| 444 #define VALUE_NAME_NULL L"null" | 444 #define VALUE_NAME_NULL L"null" |
| 445 #define VALUE_NAME_UNDEFINED L"undefined" | 445 #define VALUE_NAME_UNDEFINED L"undefined" |
| 446 | 446 |
| 447 FXJSVALUETYPE GET_VALUE_TYPE(v8::Local<v8::Value> p); | 447 FXJSVALUETYPE GET_VALUE_TYPE(v8::Local<v8::Value> p); |
| 448 | 448 |
| 449 #endif // FPDFSDK_INCLUDE_JAVASCRIPT_JS_DEFINE_H_ | 449 #endif // FPDFSDK_INCLUDE_JAVASCRIPT_JS_DEFINE_H_ |
| OLD | NEW |