Beispiel #1
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);
        }
Beispiel #2
0
        private unsafe bool DefinePropertyInternal(byte *name, JSValue getter, JSValue setter, JSPropertyFlags flags)
        {
            JSContext context = Context.NativeInstance;

            if (name == null)
            {
                JS_FreeValue(context, getter);
                JS_FreeValue(context, setter);
                throw new ArgumentNullException(nameof(name));
            }

            JSAtom prop = JS_NewAtom(context, name);
            int    rv   = JS_DefinePropertyGetSet(context, this.NativeInstance, prop, getter, setter, flags & JSPropertyFlags.CWE);

            JS_FreeAtom(context, prop);
            if (rv == -1)
            {
                context.ThrowPendingException();
            }
            return(rv == 1);
        }