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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 JSMethod<class_alternate, &class_alternate::method_name>( \ | 160 JSMethod<class_alternate, &class_alternate::method_name>( \ |
161 #class_name, #method_name, info); \ | 161 #class_name, #method_name, info); \ |
162 } | 162 } |
163 | 163 |
164 /* ===================================== JS CLASS ==============================
================= */ | 164 /* ===================================== JS CLASS ==============================
================= */ |
165 | 165 |
166 #define DECLARE_JS_CLASS(js_class_name) \ | 166 #define DECLARE_JS_CLASS(js_class_name) \ |
167 static JSBool JSConstructor(IFXJS_Context* cc, JSFXObject obj,JSFXObject
global);\ | 167 static JSBool JSConstructor(IFXJS_Context* cc, JSFXObject obj,JSFXObject
global);\ |
168 static JSBool JSDestructor(JSFXObject obj);\ | 168 static JSBool JSDestructor(JSFXObject obj);\ |
169 static int Init(IJS_Runtime* pRuntime, FXJSOBJTYPE eObjType);\ | 169 static int Init(IJS_Runtime* pRuntime, FXJSOBJTYPE eObjType);\ |
170 static void GetConsts(JSConstSpec*& pConsts, int& nSize);\ | |
171 static void GetProperties(JSPropertySpec*& pProperties, int& nSize);\ | |
172 static void GetMethods(JSMethodSpec*& pMethods, int& nSize);\ | |
173 static JSConstSpec JS_Class_Consts[];\ | 170 static JSConstSpec JS_Class_Consts[];\ |
174 static JSPropertySpec JS_Class_Properties[];\ | 171 static JSPropertySpec JS_Class_Properties[];\ |
175 static JSMethodSpec JS_Class_Methods[];\ | 172 static JSMethodSpec JS_Class_Methods[];\ |
176 static const wchar_t* m_pClassName | 173 static const wchar_t* m_pClassName |
177 | 174 |
178 #define IMPLEMENT_JS_CLASS_RICH(js_class_name, class_alternate, class_name) \ | 175 #define IMPLEMENT_JS_CLASS_RICH(js_class_name, class_alternate, class_name) \ |
179 const wchar_t* js_class_name::m_pClassName = JS_WIDESTRING(class_name);\ | 176 const wchar_t* js_class_name::m_pClassName = JS_WIDESTRING(class_name);\ |
180 JSBool js_class_name::JSConstructor(IFXJS_Context* cc, JSFXObject obj, JSFXObjec
t global)\ | 177 JSBool js_class_name::JSConstructor(IFXJS_Context* cc, JSFXObject obj, JSFXObjec
t global)\ |
181 {\ | 178 {\ |
182 CJS_Object* pObj = FX_NEW js_class_name(obj);\ | 179 CJS_Object* pObj = FX_NEW js_class_name(obj);\ |
(...skipping 21 matching lines...) Expand all Loading... |
204 {\ | 201 {\ |
205 if (JS_DefineObjProperty(pRuntime, nObjDefnID, JS_Class_
Properties[j].pName, JS_Class_Properties[j].pPropGet, JS_Class_Properties[j].pPr
opPut) < 0) return -1;\ | 202 if (JS_DefineObjProperty(pRuntime, nObjDefnID, JS_Class_
Properties[j].pName, JS_Class_Properties[j].pPropGet, JS_Class_Properties[j].pPr
opPut) < 0) return -1;\ |
206 }\ | 203 }\ |
207 for (int k=0, szk=sizeof(JS_Class_Methods)/sizeof(JSMethodSpec)-
1; k<szk; k++)\ | 204 for (int k=0, szk=sizeof(JS_Class_Methods)/sizeof(JSMethodSpec)-
1; k<szk; k++)\ |
208 {\ | 205 {\ |
209 if (JS_DefineObjMethod(pRuntime, nObjDefnID,JS_Class_Met
hods[k].pName, JS_Class_Methods[k].pMethodCall, JS_Class_Methods[k].nParamNum) <
0) return -1;\ | 206 if (JS_DefineObjMethod(pRuntime, nObjDefnID,JS_Class_Met
hods[k].pName, JS_Class_Methods[k].pMethodCall, JS_Class_Methods[k].nParamNum) <
0) return -1;\ |
210 }\ | 207 }\ |
211 return nObjDefnID;\ | 208 return nObjDefnID;\ |
212 }\ | 209 }\ |
213 return -1;\ | 210 return -1;\ |
214 }\ | |
215 void js_class_name::GetConsts(JSConstSpec*& pConsts, int& nSize)\ | |
216 {\ | |
217 pConsts = JS_Class_Consts;\ | |
218 nSize = sizeof(JS_Class_Consts) / sizeof(JSConstSpec) - 1;\ | |
219 }\ | |
220 void js_class_name::GetProperties(JSPropertySpec*& pProperties, int& nSize)\ | |
221 {\ | |
222 pProperties = JS_Class_Properties;\ | |
223 nSize = sizeof(JS_Class_Properties) / sizeof(JSPropertySpec) - 1;\ | |
224 }\ | |
225 void js_class_name::GetMethods(JSMethodSpec*& pMethods, int& nSize)\ | |
226 {\ | |
227 pMethods = JS_Class_Methods;\ | |
228 nSize = sizeof(JS_Class_Methods) / sizeof(JSMethodSpec) - 1;\ | |
229 } | 211 } |
230 | 212 |
231 #define IMPLEMENT_JS_CLASS(js_class_name, class_name) IMPLEMENT_JS_CLASS_RICH(js
_class_name, class_name, class_name) | 213 #define IMPLEMENT_JS_CLASS(js_class_name, class_name) IMPLEMENT_JS_CLASS_RICH(js
_class_name, class_name, class_name) |
232 | 214 |
233 /* ======================================== CONST CLASS ========================
==================== */ | 215 /* ======================================== CONST CLASS ========================
==================== */ |
234 | 216 |
235 #define DECLARE_JS_CLASS_CONST() \ | 217 #define DECLARE_JS_CLASS_CONST() \ |
236 static int Init(IJS_Runtime* pRuntime, FXJSOBJTYPE eObjType);\ | 218 static int Init(IJS_Runtime* pRuntime, FXJSOBJTYPE eObjType);\ |
237 static void GetConsts(JSConstSpec*& pConsts, int& nSize);\ | |
238 static JSConstSpec JS_Class_Consts[];\ | 219 static JSConstSpec JS_Class_Consts[];\ |
239 static const wchar_t* m_pClassName | 220 static const wchar_t* m_pClassName |
240 | 221 |
241 #define IMPLEMENT_JS_CLASS_CONST(js_class_name, class_name) \ | 222 #define IMPLEMENT_JS_CLASS_CONST(js_class_name, class_name) \ |
242 const wchar_t* js_class_name::m_pClassName = JS_WIDESTRING(class_name);\ | 223 const wchar_t* js_class_name::m_pClassName = JS_WIDESTRING(class_name);\ |
243 int js_class_name::Init(IJS_Runtime* pRuntime, FXJSOBJTYPE eObjType)\ | 224 int js_class_name::Init(IJS_Runtime* pRuntime, FXJSOBJTYPE eObjType)\ |
244 {\ | 225 {\ |
245 int nObjDefnID = JS_DefineObj(pRuntime, js_class_name::m_pClassName, eOb
jType, NULL, NULL, 0);\ | 226 int nObjDefnID = JS_DefineObj(pRuntime, js_class_name::m_pClassName, eOb
jType, NULL, NULL, 0);\ |
246 if (nObjDefnID >=0)\ | 227 if (nObjDefnID >=0)\ |
247 {\ | 228 {\ |
248 for (int i=0, sz=sizeof(JS_Class_Consts)/sizeof(JSConstSpec)-1;
i<sz; i++)\ | 229 for (int i=0, sz=sizeof(JS_Class_Consts)/sizeof(JSConstSpec)-1;
i<sz; i++)\ |
249 {\ | 230 {\ |
250 if (JS_Class_Consts[i].t == 0)\ | 231 if (JS_Class_Consts[i].t == 0)\ |
251 {\ | 232 {\ |
252 if (JS_DefineObjConst(pRuntime, nObjDefnID, JS_C
lass_Consts[i].pName, JS_NewNumber(pRuntime,JS_Class_Consts[i].number)) < 0) ret
urn -1;\ | 233 if (JS_DefineObjConst(pRuntime, nObjDefnID, JS_C
lass_Consts[i].pName, JS_NewNumber(pRuntime,JS_Class_Consts[i].number)) < 0) ret
urn -1;\ |
253 }\ | 234 }\ |
254 else\ | 235 else\ |
255 {\ | 236 {\ |
256 if (JS_DefineObjConst(pRuntime, nObjDefnID, JS_Class_Con
sts[i].pName, JS_NewString(pRuntime,JS_Class_Consts[i].string)) < 0) return -1;\ | 237 if (JS_DefineObjConst(pRuntime, nObjDefnID, JS_Class_Con
sts[i].pName, JS_NewString(pRuntime,JS_Class_Consts[i].string)) < 0) return -1;\ |
257 }\ | 238 }\ |
258 }\ | 239 }\ |
259 return nObjDefnID;\ | 240 return nObjDefnID;\ |
260 }\ | 241 }\ |
261 return -1;\ | 242 return -1;\ |
262 }\ | |
263 void js_class_name::GetConsts(JSConstSpec*& pConsts, int& nSize)\ | |
264 {\ | |
265 pConsts = JS_Class_Consts;\ | |
266 nSize = sizeof(JS_Class_Consts)/sizeof(JSConstSpec)-1;\ | |
267 } | 243 } |
268 | 244 |
269 /* ===================================== SPECIAL JS CLASS ======================
========================= */ | 245 /* ===================================== SPECIAL JS CLASS ======================
========================= */ |
270 | 246 |
271 template <class Alt> | 247 template <class Alt> |
272 void JSSpecialPropQuery(const char *, v8::Local<v8::String> property,const v8::P
ropertyCallbackInfo<v8::Integer>& info) { | 248 void JSSpecialPropQuery(const char *, v8::Local<v8::String> property,const v8::P
ropertyCallbackInfo<v8::Integer>& info) { |
273 v8::Isolate* isolate = info.GetIsolate(); | 249 v8::Isolate* isolate = info.GetIsolate(); |
274 v8::String::Utf8Value utf8_value(property); | 250 v8::String::Utf8Value utf8_value(property); |
275 CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_value.len
gth()); | 251 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())); | 252 CJS_Object* pJSObj = reinterpret_cast<CJS_Object*>(JS_GetPrivate(isolate, info
.Holder())); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 if (!pObj->DelProperty(pRuntimeContext, propname.c_str(), sError)) { | 318 if (!pObj->DelProperty(pRuntimeContext, propname.c_str(), sError)) { |
343 CFX_ByteString cbName; | 319 CFX_ByteString cbName; |
344 cbName.Format("%s.%s", class_name, "DelProperty"); | 320 cbName.Format("%s.%s", class_name, "DelProperty"); |
345 // Probably a missing call to JS_Error(). | 321 // Probably a missing call to JS_Error(). |
346 } | 322 } |
347 } | 323 } |
348 | 324 |
349 #define DECLARE_SPECIAL_JS_CLASS(js_class_name) \ | 325 #define DECLARE_SPECIAL_JS_CLASS(js_class_name) \ |
350 static JSBool JSConstructor(IFXJS_Context* cc, JSFXObject obj, JSFXObjec
t global);\ | 326 static JSBool JSConstructor(IFXJS_Context* cc, JSFXObject obj, JSFXObjec
t global);\ |
351 static JSBool JSDestructor(JSFXObject obj);\ | 327 static JSBool JSDestructor(JSFXObject obj);\ |
352 static void GetConsts(JSConstSpec*& pConsts, int& nSize);\ | |
353 static void GetProperties(JSPropertySpec*& pProperties, int& nSize);\ | |
354 static void GetMethods(JSMethodSpec*& pMethods, int& nSize);\ | |
355 static JSConstSpec JS_Class_Consts[];\ | 328 static JSConstSpec JS_Class_Consts[];\ |
356 static JSPropertySpec JS_Class_Properties[];\ | 329 static JSPropertySpec JS_Class_Properties[];\ |
357 static JSMethodSpec JS_Class_Methods[];\ | 330 static JSMethodSpec JS_Class_Methods[];\ |
358 static int Init(IJS_Runtime* pRuntime, FXJSOBJTYPE eObjType);\ | 331 static int Init(IJS_Runtime* pRuntime, FXJSOBJTYPE eObjType);\ |
359 static const wchar_t* m_pClassName;\ | 332 static const wchar_t* m_pClassName;\ |
360 static void queryprop_##js_class_name##_static(v8::Local<v8::String> pro
perty,const v8::PropertyCallbackInfo<v8::Integer>& info);\ | 333 static void queryprop_##js_class_name##_static(v8::Local<v8::String> pro
perty,const v8::PropertyCallbackInfo<v8::Integer>& info);\ |
361 static void getprop_##js_class_name##_static(v8::Local<v8::String> prope
rty, const v8::PropertyCallbackInfo<v8::Value>& info);\ | 334 static void getprop_##js_class_name##_static(v8::Local<v8::String> prope
rty, const v8::PropertyCallbackInfo<v8::Value>& info);\ |
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);
\ | 335 static void putprop_##js_class_name##_static(v8::Local<v8::String> prope
rty,v8::Local<v8::Value> value,const v8::PropertyCallbackInfo<v8::Value>& info);
\ |
363 static void delprop_##js_class_name##_static(v8::Local<v8::String> prope
rty,const v8::PropertyCallbackInfo<v8::Boolean>& info) | 336 static void delprop_##js_class_name##_static(v8::Local<v8::String> prope
rty,const v8::PropertyCallbackInfo<v8::Boolean>& info) |
364 | 337 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 for (int k=0, szk=sizeof(JS_Class_Methods)/sizeof(JSMethodSpec)-
1; k<szk; k++)\ | 382 for (int k=0, szk=sizeof(JS_Class_Methods)/sizeof(JSMethodSpec)-
1; k<szk; k++)\ |
410 {\ | 383 {\ |
411 if (JS_DefineObjMethod(pRuntime, nObjDefnID,JS_Class_Met
hods[k].pName,JS_Class_Methods[k].pMethodCall,JS_Class_Methods[k].nParamNum)<0)r
eturn -1;\ | 384 if (JS_DefineObjMethod(pRuntime, nObjDefnID,JS_Class_Met
hods[k].pName,JS_Class_Methods[k].pMethodCall,JS_Class_Methods[k].nParamNum)<0)r
eturn -1;\ |
412 }\ | 385 }\ |
413 if (JS_DefineObjAllProperties(pRuntime, nObjDefnID, js_class_nam
e::queryprop_##js_class_name##_static, js_class_name::getprop_##js_class_name##_
static,js_class_name::putprop_##js_class_name##_static,js_class_name::delprop_##
js_class_name##_static)<0) return -1;\ | 386 if (JS_DefineObjAllProperties(pRuntime, nObjDefnID, js_class_nam
e::queryprop_##js_class_name##_static, js_class_name::getprop_##js_class_name##_
static,js_class_name::putprop_##js_class_name##_static,js_class_name::delprop_##
js_class_name##_static)<0) return -1;\ |
414 \ | 387 \ |
415 return nObjDefnID;\ | 388 return nObjDefnID;\ |
416 }\ | 389 }\ |
417 \ | 390 \ |
418 return -1;\ | 391 return -1;\ |
419 }\ | |
420 void js_class_name::GetConsts(JSConstSpec*& pConsts, int& nSize)\ | |
421 {\ | |
422 pConsts = JS_Class_Consts;\ | |
423 nSize = sizeof(JS_Class_Consts)/sizeof(JSConstSpec)-1;\ | |
424 }\ | |
425 void js_class_name::GetProperties(JSPropertySpec*& pProperties, int& nSize)\ | |
426 {\ | |
427 pProperties = JS_Class_Properties;\ | |
428 nSize = sizeof(JS_Class_Properties)/sizeof(JSPropertySpec)-1;\ | |
429 }\ | |
430 void js_class_name::GetMethods(JSMethodSpec*& pMethods, int& nSize)\ | |
431 {\ | |
432 pMethods = JS_Class_Methods;\ | |
433 nSize = sizeof(JS_Class_Methods)/sizeof(JSMethodSpec)-1;\ | |
434 } | 392 } |
435 | 393 |
436 /* ======================================== GLOBAL METHODS =====================
======================= */ | 394 /* ======================================== GLOBAL METHODS =====================
======================= */ |
437 | 395 |
438 template <FX_BOOL (*F)(IFXJS_Context*, const CJS_Parameters&, CJS_Value&, JS_Err
orString&)> | 396 template <FX_BOOL (*F)(IFXJS_Context*, const CJS_Parameters&, CJS_Value&, JS_Err
orString&)> |
439 void JSGlobalFunc(const char *func_name_string, | 397 void JSGlobalFunc(const char *func_name_string, |
440 const v8::FunctionCallbackInfo<v8::Value>& info) { | 398 const v8::FunctionCallbackInfo<v8::Value>& info) { |
441 v8::Isolate* isolate = info.GetIsolate(); | 399 v8::Isolate* isolate = info.GetIsolate(); |
442 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2); | 400 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2); |
443 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); | 401 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 #define VALUE_NAME_BOOLEAN L"boolean" | 468 #define VALUE_NAME_BOOLEAN L"boolean" |
511 #define VALUE_NAME_DATE L"date" | 469 #define VALUE_NAME_DATE L"date" |
512 #define VALUE_NAME_OBJECT L"object" | 470 #define VALUE_NAME_OBJECT L"object" |
513 #define VALUE_NAME_FXOBJ L"fxobj" | 471 #define VALUE_NAME_FXOBJ L"fxobj" |
514 #define VALUE_NAME_NULL L"null" | 472 #define VALUE_NAME_NULL L"null" |
515 #define VALUE_NAME_UNDEFINED L"undefined" | 473 #define VALUE_NAME_UNDEFINED L"undefined" |
516 | 474 |
517 FXJSVALUETYPE GET_VALUE_TYPE(v8::Handle<v8::Value> p); | 475 FXJSVALUETYPE GET_VALUE_TYPE(v8::Handle<v8::Value> p); |
518 | 476 |
519 #endif //_JS_DEFINE_H_ | 477 #endif //_JS_DEFINE_H_ |
OLD | NEW |