public void AddProperty(bool bStatic, string name, JSGetterCFunction getter, JSSetterCFunction setter) { var ctx = (JSContext)_context; var nameAtom = _register.GetAtom(name); var getterVal = JSApi.JS_UNDEFINED; var setterVal = JSApi.JS_UNDEFINED; var flags = JSPropFlags.JS_PROP_CONFIGURABLE | JSPropFlags.JS_PROP_ENUMERABLE; if (getter != null) { flags |= JSPropFlags.JS_PROP_HAS_GET; getterVal = JSApi.JSB_NewCFunction(ctx, getter, nameAtom); } if (setter != null) { flags |= JSPropFlags.JS_PROP_HAS_SET; flags |= JSPropFlags.JS_PROP_WRITABLE; setterVal = JSApi.JSB_NewCFunction(ctx, setter, nameAtom); } var rs = JSApi.JS_DefineProperty(ctx, bStatic ? _ctor : _proto, nameAtom, JSApi.JS_UNDEFINED, getterVal, setterVal, flags); if (rs != 1) { var logger = _register.GetLogger(); if (logger != null) { logger.Write(LogLevel.Error, "define property failed: {0}", ctx.GetExceptionString()); } } JSApi.JS_FreeValue(ctx, getterVal); JSApi.JS_FreeValue(ctx, setterVal); }
public static JSValue JSB_NewCFunction(JSContext ctx, JSGetterCFunction func, JSAtom atom) { #if JSB_UNITYLESS GCHandle.Alloc(func); #endif var fn = Marshal.GetFunctionPointerForDelegate(func); return(JSB_NewCFunction(ctx, fn, atom, 0, JSCFunctionEnum.JS_CFUNC_getter, 0)); }
public static JSValue JSB_NewCFunction(JSContext ctx, JSGetterCFunction func, JSAtom atom) { var fn = Marshal.GetFunctionPointerForDelegate(func); return(JSB_NewCFunction(ctx, fn, atom, 0, JSCFunctionEnum.JS_CFUNC_getter, 0)); }
public void AddField(bool bStatic, string name, JSGetterCFunction getter, JSSetterCFunction setter) { AddProperty(bStatic, name, getter, setter); }