public static JSValue JSB_NewCFunction(JSContext ctx, JSCFunction func, JSAtom atom, int length, JSCFunctionEnum cproto, int magic) { var fn = Marshal.GetFunctionPointerForDelegate(func); return(JSB_NewCFunction(ctx, fn, atom, length, cproto, magic)); }
public void AddMethod(bool bStatic, string name, JSCFunction func, int length) { var nameAtom = _register.GetAtom(name); var funcVal = JSApi.JSB_NewCFunction(_context, func, nameAtom, length, JSCFunctionEnum.JS_CFUNC_generic, 0); JSApi.JS_DefinePropertyValue(_context, bStatic ? _ctor : _proto, nameAtom, funcVal, JSPropFlags.DEFAULT); }
public void AddFunction(JSValue thisObject, string name, JSCFunction func, int length) { var nameAtom = GetAtom(name); var cfun = JSApi.JSB_NewCFunction(_ctx, func, nameAtom, length, JSCFunctionEnum.JS_CFUNC_generic, 0); JSApi.JS_DefinePropertyValue(_ctx, thisObject, nameAtom, cfun, JSPropFlags.JS_PROP_C_W_E); }
public static JSValue JS_NewCFunction2(JSContext ctx, JSCFunction func, string name, int length, JSCFunctionEnum cproto, int magic) { var fn = Marshal.GetFunctionPointerForDelegate(func); return(JS_NewCFunction2(ctx, fn, name, length, cproto, magic)); }
public unsafe JSValue CreateFunctionRaw(string name, JSCFunction function, int argCount) { fixed(byte *fnName = Utils.StringToManagedUTF8(name)) { return(CreateFunctionRawInternal(fnName, function, argCount)); } }
// self operator for type public void RegisterOperator(Type type, string op, JSCFunction func, int length) { int index; var decl = GetOperatorDecl(type, out index); decl.AddOperator(op, func, length); }
/// <summary> /// Creates a native function and assigns it as a property to this JS object. /// </summary> /// <param name="name">The name of the property to be defined or modified.</param> /// <param name="func">The function associated with the property.</param> /// <param name="argCount">The number of arguments the function expects to receive.</param> /// <param name="flags">A bitwise combination of the <see cref="JSPropertyFlags"/>.</param> /// <returns>true if the property has been defined or redefined; otherwise false.</returns> public unsafe bool DefineFunction(string name, JSCFunction func, int argCount, JSPropertyFlags flags) { fixed(byte *aName = Utils.StringToManagedUTF8(name)) { return(DefinePropertyInternal(aName, Context.CreateFunctionRawInternal(aName, func, argCount), flags)); } }
/// <summary> /// Creates a new JavaScript constructor function in this context. /// </summary> /// <param name="name">The name property of the new function object.</param> /// <param name="function">A delegate to the function that is to be exposed to JavaScript.</param> /// <param name="argCount">The number of arguments the function expects to receive.</param> /// <returns>A value containing the new function.</returns> public JSValue CreateConstructorRaw(string name, JSCFunction function, int argCount) { JSValue ctor = CreateFunctionRaw(name, function, argCount); JS_SetConstructorBit(this.NativeInstance, ctor, true); return(ctor); }
public void AddFunction(string name, JSCFunction func, int length) { var ctx = _register.GetContext(); var nameAtom = _register.GetAtom(name); var cfun = JSApi.JSB_NewCFunction(ctx, func, nameAtom, length, JSCFunctionEnum.JS_CFUNC_generic, 0); JSApi.JS_DefinePropertyValue(ctx, _nsValue, nameAtom, cfun, JSPropFlags.JS_PROP_C_W_E); }
public static JSValue JS_NewCFunction(JSContext ctx, JSCFunction func, string name, int length) { #if JSB_UNITYLESS GCHandle.Alloc(func); #endif var fn = Marshal.GetFunctionPointerForDelegate(func); return(JS_NewCFunction2(ctx, fn, name, length, JSCFunctionEnum.JS_CFUNC_generic, 0)); }
public void AddRawMethod(bool bStatic, string name, JSCFunction method) { var nameAtom = _register.GetAtom(name); var db = _register.GetTypeDB(); var funcVal = db.NewDynamicMethod(nameAtom, method); JSApi.JS_DefinePropertyValue(_context, bStatic ? _ctor : _proto, nameAtom, funcVal, JSPropFlags.DEFAULT); }
public static JSValue JSB_NewCFunction(JSContext ctx, JSCFunction func, JSAtom atom, int length, JSCFunctionEnum cproto, int magic) { #if JSB_UNITYLESS GCHandle.Alloc(func); #endif var fn = Marshal.GetFunctionPointerForDelegate(func); return(JSB_NewCFunction(ctx, fn, atom, length, cproto, magic)); }
public void AddStaticEvent(string name, JSCFunction adder, JSCFunction remover) { var nameAtom = _register.GetAtom(name); var op = JSApi.JS_NewObject(_context); var adderFunc = JSApi.JSB_NewCFunction(_context, adder, _register.GetAtom("on"), 1, JSCFunctionEnum.JS_CFUNC_generic, 0); JSApi.JS_SetProperty(_context, op, _register.GetAtom("on"), adderFunc); var removerFunc = JSApi.JSB_NewCFunction(_context, remover, _register.GetAtom("off"), 1, JSCFunctionEnum.JS_CFUNC_generic, 0); JSApi.JS_SetProperty(_context, op, _register.GetAtom("off"), removerFunc); JSApi.JS_SetProperty(_context, _ctor, nameAtom, op); }
public static JSValue js_new_event(JSContext ctx, object this_obj, JSCFunction adder, JSCFunction remover) { var context = ScriptEngine.GetContext(ctx); var ret = NewBridgeClassObject(ctx, this_obj); var adderFunc = JSApi.JSB_NewCFunction(ctx, adder, context.GetAtom("on"), 1, JSCFunctionEnum.JS_CFUNC_generic, 0); JSApi.JS_SetProperty(ctx, ret, context.GetAtom("on"), adderFunc); var removerFunc = JSApi.JSB_NewCFunction(ctx, remover, context.GetAtom("off"), 1, JSCFunctionEnum.JS_CFUNC_generic, 0); JSApi.JS_SetProperty(ctx, ret, context.GetAtom("off"), removerFunc); return(ret); // return JSApi.JS_ThrowInternalError(ctx, "invalid this_obj, unbound?"); }
internal unsafe JSValue CreateFunctionRawInternal(byte *name, JSCFunction function, int argCount) { var fn = new QuickJSSafeDelegate(function); JSValue fnValue = JS_NewCFunction2(this.NativeInstance, fn.GetPointer(), name, argCount, JSCFunctionEnum.Generic, 0); if (JS_IsException(fnValue)) { _context.ThrowPendingException(); } else { _functions.Add(fn); } return(fnValue); }
public void AddCrossOperator(string op, JSCFunction func, int length, bool bLeft, Type sideType) { var list = bLeft ? left : right; var count = list.Count; for (var i = 0; i < count; i++) { if (list[i].type == sideType) { list[i].operators.Add(new OperatorDef(op, func, length)); return; } } var newCrossDef = new CrossOperatorDef(sideType); newCrossDef.operators.Add(new OperatorDef(op, func, length)); list.Add(newCrossDef); _count++; }
public unsafe bool DefineProperty(string name, JSCFunction getter, JSCFunction setter, JSPropertyFlags flags) { JSValue getterVal, setterVal; getterVal = getter is null ? JSValue.Undefined : Context.CreateFunctionRaw("get_" + name, getter, 0); try { setterVal = setter is null ? JSValue.Undefined : Context.CreateFunctionRaw("set_" + name, setter, 1); } catch { JS_FreeValue(Context.NativeInstance, getterVal); throw; } fixed(byte *aName = Utils.StringToManagedUTF8(name)) { return(DefinePropertyInternal(aName, getterVal, setterVal, flags)); } }
// left/right operator for type public void RegisterOperator(Type type, string op, JSCFunction func, int length, bool left, Type sideType) { if (sideType == typeof(string) || (sideType.IsValueType && (sideType.IsPrimitive || sideType.IsEnum))) { int index; var decl = GetOperatorDecl(type, out index); decl.AddCrossOperator(op, func, length, left, sideType); } else { int index1, index2; var decl1 = GetOperatorDecl(type, out index1); var decl2 = GetOperatorDecl(sideType, out index2); if (index2 > index1) { decl2.AddCrossOperator(op, func, length, !left, type); } else { decl1.AddCrossOperator(op, func, length, left, sideType); } } }
/// <summary> /// Creates a native constructor function and assigns it as a property to the global object. /// </summary> /// <param name="name">The name property of the new function object.</param> /// <param name="function">A delegate to the function that is to be exposed to JavaScript.</param> /// <param name="argCount">The number of arguments the function expects to receive.</param> /// <param name="flags">A bitwise combination of the <see cref="JSPropertyFlags"/>.</param> /// <returns>true if the property has been defined or redefined; otherwise false.</returns> public unsafe bool DefineConstructor(string name, JSCFunction function, int argCount, JSPropertyFlags flags) { fixed(byte *fnName = Utils.StringToManagedUTF8(name)) { int rv = -1; JSValue globObj = JS_GetGlobalObject(this.NativeInstance); try { JSValue ctor = CreateFunctionRawInternal(fnName, function, argCount); JS_SetConstructorBit(this.NativeInstance, ctor, true); rv = JS_DefinePropertyValueStr(this.NativeInstance, globObj, fnName, ctor, flags & JSPropertyFlags.CWE); if (rv == -1) { this.NativeInstance.ThrowPendingException(); } } finally { JS_FreeValue(this.NativeInstance, globObj); } return(rv == 1); } }
public OperatorDef(string op, JSCFunction func, int length) { this.func = func; this.length = length; this.op = op; }
public void AddOperator(string op, JSCFunction func, int length) { self.Add(new OperatorDef(op, func, length)); }
/// <summary> /// 添加全局函数 /// </summary> public void AddFunction(string name, JSCFunction func, int length) { AddFunction(_globalObject, name, func, length); }
public unsafe QuickJSSafeDelegate(JSCFunction function) { _callback = function; _handler = sizeof(JSValue) == sizeof(ulong) ? (Delegate) new JSCFunction32(Impl8) : new JSCFunction(Impl16); }
public DynamicMethodInvoke(JSCFunction method) { _method = method; }
public void SetProperty(JSValue this_obj, string name, JSCFunction fn, int length = 0) { JSApi.JS_SetPropertyStr(this, this_obj, name, JSApi.JS_NewCFunction(this, fn, name, length)); }
public void AddFunction(string name, JSCFunction func) { AddMethod(true, name, func); }
public static JSValue JS_NewCFunction(JSContext ctx, JSCFunction func, string name, int length) { var fn = Marshal.GetFunctionPointerForDelegate(func); return(JS_NewCFunction2(ctx, fn, name, length, JSCFunctionEnum.JS_CFUNC_generic, 0)); }
public void AddFunction(string name, JSCFunction func, int length) { AddMethod(true, name, func, length); }
public void AddRightOperator(string op, JSCFunction func, int length, Type type) { _register.RegisterOperator(_type, op, func, length, false, type); }
public void AddSelfOperator(string op, JSCFunction func, int length) { _register.RegisterOperator(_type, op, func, length); }