Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a new JavaScript function in this context.
        /// </summary>
        /// <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="magic">A magic value.</param>
        /// <param name="data">An array containing data to be used by the method.</param>
        /// <returns>A value containing the new function.</returns>
        public unsafe JSValue CreateFunctionRaw(JSCFunctionData function, int argCount, int magic, JSValue[] data)
        {
            var     fn      = new QuickJSSafeDelegate(function);
            JSValue fnValue = JS_NewCFunctionData(this.NativeInstance, fn.GetPointer(), argCount, magic, data is null ? 0 : data.Length, data);

            if (JS_IsException(fnValue))
            {
                _context.ThrowPendingException();
            }
            else
            {
                _functions.Add(fn);
            }
            return(fnValue);
        }