cocos2d-x  3.0alpha1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
jsb_helper.h File Reference
#include <typeinfo>
#include <string>
#include <memory>
#include "jsapi.h"

Macros

#define JS_BINDED_CLASS_GLUE(klass)
#define JS_BINDED_CLASS_GLUE_IMPL(klass)
#define JS_BINDED_FUNC(klass, name)   JSBool name(JSContext *cx, unsigned argc, jsval *vp)
#define JS_BINDED_CONSTRUCTOR(klass)   static JSBool _js_constructor(JSContext *cx, unsigned argc, jsval *vp)
#define JS_BINDED_CONSTRUCTOR_IMPL(klass)   JSBool klass::_js_constructor(JSContext *cx, unsigned argc, jsval *vp)
#define JS_BINDED_FUNC_IMPL(klass, name)
#define JS_WRAP_OBJECT_IN_VAL(klass, cobj, out)
#define JS_BINDED_FUNC_FOR_DEF(klass, name)   JS_FN(#name, klass##_func_##name, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT)
#define JS_BINDED_PROP_GET(klass, propName)   JSBool _js_get_##propName(JSContext *cx, JS::HandleId id, JS::MutableHandleValue vp)
#define JS_BINDED_PROP_GET_IMPL(klass, propName)
#define JS_BINDED_PROP_SET(klass, propName)   JSBool _js_set_##propName(JSContext *cx, JS::HandleId id, JSBool strict, JS::MutableHandleValue vp)
#define JS_BINDED_PROP_SET_IMPL(klass, propName)
#define JS_BINDED_PROP_ACCESSOR(klass, propName)
#define JS_BINDED_PROP_DEF_GETTER(klass, propName)   {#propName, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, JSOP_WRAPPER(_js_get_##klass##_##propName), NULL}
#define JS_BINDED_PROP_DEF_ACCESSOR(klass, propName)   {#propName, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, JSOP_WRAPPER(_js_get_##klass##_##propName), JSOP_WRAPPER(_js_set_##klass##_##propName)}
#define JS_CREATE_UINT_WRAPPED(valOut, propName, val)
#define JS_GET_UINT_WRAPPED(inVal, propName, out)

Macro Definition Documentation

#define JS_BINDED_CLASS_GLUE (   klass)
Value:
static JSClass js_class; \
static JSObject* js_proto; \
static JSObject* js_parent; \
static void _js_register(JSContext* cx, JSObject* global);
var JS_BINDED_CLASS_GLUE (   var)
Value:
static JSClass js_class; \
static JSObject* js_proto; \
static JSObject* js_parent; \
static void _js_register(JSContext* cx, JSObject* global);
local JS_BINDED_CLASS_GLUE (   local)
Value:
static JSClass js_class; \
static JSObject* js_proto; \
static JSObject* js_parent; \
static void _js_register(JSContext* cx, JSObject* global);
#define JS_BINDED_CLASS_GLUE_IMPL (   klass)
Value:
JSClass klass::js_class = {}; \
JSObject* klass::js_proto = NULL; \
JSObject* klass::js_parent = NULL; \
#define JS_BINDED_CONSTRUCTOR (   klass)    static JSBool _js_constructor(JSContext *cx, unsigned argc, jsval *vp)
var JS_BINDED_CONSTRUCTOR (   var)    static JSBool _js_constructor(JSContext *cx, unsigned argc, jsval *vp)
local JS_BINDED_CONSTRUCTOR (   local)    static JSBool _js_constructor(JSContext *cx, unsigned argc, jsval *vp)
#define JS_BINDED_CONSTRUCTOR_IMPL (   klass)    JSBool klass::_js_constructor(JSContext *cx, unsigned argc, jsval *vp)
var JS_BINDED_CONSTRUCTOR_IMPL (   var)    JSBool klass::_js_constructor(JSContext *cx, unsigned argc, jsval *vp)
local JS_BINDED_CONSTRUCTOR_IMPL (   local)    JSBool klass::_js_constructor(JSContext *cx, unsigned argc, jsval *vp)
#define JS_BINDED_FUNC (   klass,
  name 
)    JSBool name(JSContext *cx, unsigned argc, jsval *vp)
#define JS_BINDED_FUNC_FOR_DEF (   klass,
  name 
)    JS_FN(#name, klass##_func_##name, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT)
var JS_BINDED_FUNC_FOR_DEF (   var,
  var 
)    JS_FN(#name, klass##_func_##name, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT)
local JS_BINDED_FUNC_FOR_DEF (   local,
  local 
)    JS_FN(#name, klass##_func_##name, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT)
#define JS_BINDED_FUNC_IMPL (   klass,
  name 
)
Value:
static JSBool klass##_func_##name(JSContext *cx, unsigned argc, jsval *vp) { \
JSObject* thisObj = JS_THIS_OBJECT(cx, vp); \
klass* obj = (klass*)JS_GetPrivate(thisObj); \
if (obj) { \
return obj->name(cx, argc, vp); \
} \
JS_ReportError(cx, "Invalid object call for function %s", #name); \
return JS_FALSE; \
} \
JSBool klass::name(JSContext *cx, unsigned argc, jsval *vp)
var JS_BINDED_FUNC_IMPL (   var,
  var 
)
Value:
static JSBool klass##_func_##name(JSContext *cx, unsigned argc, jsval *vp) { \
JSObject* thisObj = JS_THIS_OBJECT(cx, vp); \
klass* obj = (klass*)JS_GetPrivate(thisObj); \
if (obj) { \
return obj->name(cx, argc, vp); \
} \
JS_ReportError(cx, "Invalid object call for function %s", #name); \
return JS_FALSE; \
} \
JSBool klass::name(JSContext *cx, unsigned argc, jsval *vp)
local JS_BINDED_FUNC_IMPL (   local,
  local 
)
Value:
static JSBool klass##_func_##name(JSContext *cx, unsigned argc, jsval *vp) { \
JSObject* thisObj = JS_THIS_OBJECT(cx, vp); \
klass* obj = (klass*)JS_GetPrivate(thisObj); \
if (obj) { \
return obj->name(cx, argc, vp); \
} \
JS_ReportError(cx, "Invalid object call for function %s", #name); \
return JS_FALSE; \
} \
JSBool klass::name(JSContext *cx, unsigned argc, jsval *vp)
#define JS_BINDED_PROP_ACCESSOR (   klass,
  propName 
)
Value:
JS_BINDED_PROP_GET(klass, propName); \
JS_BINDED_PROP_SET(klass, propName);
var JS_BINDED_PROP_ACCESSOR (   var,
  var 
)
Value:
JS_BINDED_PROP_GET(klass, propName); \
JS_BINDED_PROP_SET(klass, propName);
local JS_BINDED_PROP_ACCESSOR (   local,
  local 
)
Value:
JS_BINDED_PROP_GET(klass, propName); \
JS_BINDED_PROP_SET(klass, propName);
#define JS_BINDED_PROP_DEF_ACCESSOR (   klass,
  propName 
)    {#propName, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, JSOP_WRAPPER(_js_get_##klass##_##propName), JSOP_WRAPPER(_js_set_##klass##_##propName)}
var JS_BINDED_PROP_DEF_ACCESSOR (   var,
  var 
)    {#propName, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, JSOP_WRAPPER(_js_get_##klass##_##propName), JSOP_WRAPPER(_js_set_##klass##_##propName)}
local JS_BINDED_PROP_DEF_ACCESSOR (   local,
  local 
)    {#propName, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, JSOP_WRAPPER(_js_get_##klass##_##propName), JSOP_WRAPPER(_js_set_##klass##_##propName)}
#define JS_BINDED_PROP_DEF_GETTER (   klass,
  propName 
)    {#propName, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, JSOP_WRAPPER(_js_get_##klass##_##propName), NULL}
var JS_BINDED_PROP_DEF_GETTER (   var,
  var 
)    {#propName, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, JSOP_WRAPPER(_js_get_##klass##_##propName), NULL}
local JS_BINDED_PROP_DEF_GETTER (   local,
  local 
)    {#propName, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, JSOP_WRAPPER(_js_get_##klass##_##propName), NULL}
#define JS_BINDED_PROP_GET (   klass,
  propName 
)    JSBool _js_get_##propName(JSContext *cx, JS::HandleId id, JS::MutableHandleValue vp)
var JS_BINDED_PROP_GET (   var,
  var 
)    JSBool _js_get_##propName(JSContext *cx, JS::HandleId id, JS::MutableHandleValue vp)
local JS_BINDED_PROP_GET (   local,
  local 
)    JSBool _js_get_##propName(JSContext *cx, JS::HandleId id, JS::MutableHandleValue vp)
#define JS_BINDED_PROP_GET_IMPL (   klass,
  propName 
)
Value:
static JSBool _js_get_##klass##_##propName(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp) { \
klass* cobj = (klass*)JS_GetPrivate(obj); \
if (cobj) { \
return cobj->_js_get_##propName(cx, id, vp); \
} \
JS_ReportError(cx, "Invalid getter call for property %s", #propName); \
return JS_FALSE; \
} \
JSBool klass::_js_get_##propName(JSContext *cx, JS::HandleId id, JS::MutableHandleValue vp)
var JS_BINDED_PROP_GET_IMPL (   var,
  var 
)
Value:
static JSBool _js_get_##klass##_##propName(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp) { \
klass* cobj = (klass*)JS_GetPrivate(obj); \
if (cobj) { \
return cobj->_js_get_##propName(cx, id, vp); \
} \
JS_ReportError(cx, "Invalid getter call for property %s", #propName); \
return JS_FALSE; \
} \
JSBool klass::_js_get_##propName(JSContext *cx, JS::HandleId id, JS::MutableHandleValue vp)
local JS_BINDED_PROP_GET_IMPL (   local,
  local 
)
Value:
static JSBool _js_get_##klass##_##propName(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp) { \
klass* cobj = (klass*)JS_GetPrivate(obj); \
if (cobj) { \
return cobj->_js_get_##propName(cx, id, vp); \
} \
JS_ReportError(cx, "Invalid getter call for property %s", #propName); \
return JS_FALSE; \
} \
JSBool klass::_js_get_##propName(JSContext *cx, JS::HandleId id, JS::MutableHandleValue vp)
#define JS_BINDED_PROP_SET (   klass,
  propName 
)    JSBool _js_set_##propName(JSContext *cx, JS::HandleId id, JSBool strict, JS::MutableHandleValue vp)
var JS_BINDED_PROP_SET (   var,
  var 
)    JSBool _js_set_##propName(JSContext *cx, JS::HandleId id, JSBool strict, JS::MutableHandleValue vp)
local JS_BINDED_PROP_SET (   local,
  local 
)    JSBool _js_set_##propName(JSContext *cx, JS::HandleId id, JSBool strict, JS::MutableHandleValue vp)
#define JS_BINDED_PROP_SET_IMPL (   klass,
  propName 
)
Value:
static JSBool _js_set_##klass##_##propName(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JSBool strict, JS::MutableHandleValue vp) { \
klass* cobj = (klass*)JS_GetPrivate(obj); \
if (cobj) { \
return cobj->_js_set_##propName(cx, id, strict, vp); \
} \
JS_ReportError(cx, "Invalid setter call for property %s", #propName); \
return JS_FALSE; \
} \
JSBool klass::_js_set_##propName(JSContext *cx, JS::HandleId id, JSBool strict, JS::MutableHandleValue vp)
var JS_BINDED_PROP_SET_IMPL (   var,
  var 
)
Value:
static JSBool _js_set_##klass##_##propName(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JSBool strict, JS::MutableHandleValue vp) { \
klass* cobj = (klass*)JS_GetPrivate(obj); \
if (cobj) { \
return cobj->_js_set_##propName(cx, id, strict, vp); \
} \
JS_ReportError(cx, "Invalid setter call for property %s", #propName); \
return JS_FALSE; \
} \
JSBool klass::_js_set_##propName(JSContext *cx, JS::HandleId id, JSBool strict, JS::MutableHandleValue vp)
local JS_BINDED_PROP_SET_IMPL (   local,
  local 
)
Value:
static JSBool _js_set_##klass##_##propName(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JSBool strict, JS::MutableHandleValue vp) { \
klass* cobj = (klass*)JS_GetPrivate(obj); \
if (cobj) { \
return cobj->_js_set_##propName(cx, id, strict, vp); \
} \
JS_ReportError(cx, "Invalid setter call for property %s", #propName); \
return JS_FALSE; \
} \
JSBool klass::_js_set_##propName(JSContext *cx, JS::HandleId id, JSBool strict, JS::MutableHandleValue vp)
#define JS_CREATE_UINT_WRAPPED (   valOut,
  propName,
  val 
)
Value:
do { \
JSObject* jsobj = JS_NewObject(cx, NULL, NULL, NULL); \
jsval propVal = UINT_TO_JSVAL(val); \
JS_SetProperty(cx, jsobj, "__" propName, &propVal); \
valOut = OBJECT_TO_JSVAL(jsobj); \
} while(0)
var JS_CREATE_UINT_WRAPPED (   var,
  var,
  var 
)
Value:
do { \
JSObject* jsobj = JS_NewObject(cx, NULL, NULL, NULL); \
jsval propVal = UINT_TO_JSVAL(val); \
JS_SetProperty(cx, jsobj, "__" propName, &propVal); \
valOut = OBJECT_TO_JSVAL(jsobj); \
} while(0)
local JS_CREATE_UINT_WRAPPED (   local,
  local,
  local 
)
Value:
do { \
JSObject* jsobj = JS_NewObject(cx, NULL, NULL, NULL); \
jsval propVal = UINT_TO_JSVAL(val); \
JS_SetProperty(cx, jsobj, "__" propName, &propVal); \
valOut = OBJECT_TO_JSVAL(jsobj); \
} while(0)
#define JS_GET_UINT_WRAPPED (   inVal,
  propName,
  out 
)
Value:
do { \
if (inVal.isObject()) {\
JSObject* jsobj = JSVAL_TO_OBJECT(inVal); \
jsval outVal; \
JS_GetProperty(cx, jsobj, "__" propName, &outVal); \
JS_ValueToECMAUint32(cx, outVal, &out); \
} else { \
int32_t tmp; \
JS_ValueToInt32(cx, inVal, &tmp); \
out = (uint32_t)tmp; \
} \
} while (0)
var JS_GET_UINT_WRAPPED (   var,
  var,
  var 
)
Value:
do { \
if (inVal.isObject()) {\
JSObject* jsobj = JSVAL_TO_OBJECT(inVal); \
jsval outVal; \
JS_GetProperty(cx, jsobj, "__" propName, &outVal); \
JS_ValueToECMAUint32(cx, outVal, &out); \
} else { \
int32_t tmp; \
JS_ValueToInt32(cx, inVal, &tmp); \
out = (uint32_t)tmp; \
} \
} while (0)
local JS_GET_UINT_WRAPPED (   local,
  local,
  local 
)
Value:
do { \
if (inVal.isObject()) {\
JSObject* jsobj = JSVAL_TO_OBJECT(inVal); \
jsval outVal; \
JS_GetProperty(cx, jsobj, "__" propName, &outVal); \
JS_ValueToECMAUint32(cx, outVal, &out); \
} else { \
int32_t tmp; \
JS_ValueToInt32(cx, inVal, &tmp); \
out = (uint32_t)tmp; \
} \
} while (0)
#define JS_WRAP_OBJECT_IN_VAL (   klass,
  cobj,
  out 
)
Value:
do { \
JSObject *obj = JS_NewObject(cx, &klass::js_class, klass::js_proto, klass::js_parent); \
if (obj) { \
JS_SetPrivate(obj, cobj); \
out = OBJECT_TO_JSVAL(obj); \
} \
} while(0) \
var JS_WRAP_OBJECT_IN_VAL (   var,
  var,
  var 
)
Value:
do { \
JSObject *obj = JS_NewObject(cx, &klass::js_class, klass::js_proto, klass::js_parent); \
if (obj) { \
JS_SetPrivate(obj, cobj); \
out = OBJECT_TO_JSVAL(obj); \
} \
} while(0) \
local JS_WRAP_OBJECT_IN_VAL (   local,
  local,
  local 
)
Value:
do { \
JSObject *obj = JS_NewObject(cx, &klass::js_class, klass::js_proto, klass::js_parent); \
if (obj) { \
JS_SetPrivate(obj, cobj); \
out = OBJECT_TO_JSVAL(obj); \
} \
} while(0) \