예제 #1
0
        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));
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }
예제 #4
0
        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));
        }
예제 #5
0
 public unsafe JSValue CreateFunctionRaw(string name, JSCFunction function, int argCount)
 {
     fixed(byte *fnName = Utils.StringToManagedUTF8(name))
     {
         return(CreateFunctionRawInternal(fnName, function, argCount));
     }
 }
예제 #6
0
        // 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);
        }
예제 #7
0
 /// <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));
     }
 }
예제 #8
0
        /// <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);
        }
예제 #9
0
        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);
        }
예제 #10
0
파일: JSApi.cs 프로젝트: ialex32x/unity-jsb
        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));
        }
예제 #11
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);
        }
예제 #12
0
파일: JSApi.cs 프로젝트: ialex32x/unity-jsb
        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));
        }
예제 #13
0
        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);
        }
예제 #14
0
        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?");
        }
예제 #15
0
        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);
        }
예제 #16
0
        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++;
        }
예제 #17
0
        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));
            }
        }
예제 #18
0
 // 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);
         }
     }
 }
예제 #19
0
        /// <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);
            }
        }
예제 #20
0
 public OperatorDef(string op, JSCFunction func, int length)
 {
     this.func   = func;
     this.length = length;
     this.op     = op;
 }
예제 #21
0
 public void AddOperator(string op, JSCFunction func, int length)
 {
     self.Add(new OperatorDef(op, func, length));
 }
예제 #22
0
 /// <summary>
 /// 添加全局函数
 /// </summary>
 public void AddFunction(string name, JSCFunction func, int length)
 {
     AddFunction(_globalObject, name, func, length);
 }
예제 #23
0
 public unsafe QuickJSSafeDelegate(JSCFunction function)
 {
     _callback = function;
     _handler  = sizeof(JSValue) == sizeof(ulong) ? (Delegate) new JSCFunction32(Impl8) : new JSCFunction(Impl16);
 }
예제 #24
0
 public DynamicMethodInvoke(JSCFunction method)
 {
     _method = method;
 }
예제 #25
0
 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));
 }
예제 #26
0
 public void AddFunction(string name, JSCFunction func)
 {
     AddMethod(true, name, func);
 }
예제 #27
0
        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));
        }
예제 #28
0
 public void AddFunction(string name, JSCFunction func, int length)
 {
     AddMethod(true, name, func, length);
 }
예제 #29
0
 public void AddRightOperator(string op, JSCFunction func, int length, Type type)
 {
     _register.RegisterOperator(_type, op, func, length, false, type);
 }
예제 #30
0
 public void AddSelfOperator(string op, JSCFunction func, int length)
 {
     _register.RegisterOperator(_type, op, func, length);
 }