Exemplo n.º 1
0
        unsafe static IntPtr Trampoline(IntPtr contextPtr, IntPtr function, IntPtr thisObject,
                                        IntPtr argumentCount, IntPtr *arguments, IntPtr exception)
        {
            var globalContextPtr = JSContextGetGlobalContext(contextPtr);
            var context          = JSContext.FromJSGlobalContextRef(globalContextPtr);

            var args = new WrappedObject [(int)argumentCount];

            for (int i = 0; i < args.Length; i++)
            {
                args [i] = new WrappedObject(JSValue.FromJSJSValueRef(arguments [i], context));
            }

            var retval = functionDelegates [function] (
                new WrappedObject(JSValue.FromJSJSValueRef(thisObject, context)),
                args);

            if (retval == null)
            {
                return(JSValue.Null(context).JSValueRefPtr);
            }

            if (retval is bool)
            {
                return(JSValue.From((bool)retval, context).JSValueRefPtr);
            }

            if (retval is int)
            {
                return(JSValue.From((int)retval, context).JSValueRefPtr);
            }

            if (retval is uint)
            {
                return(JSValue.From((uint)retval, context).JSValueRefPtr);
            }

            if (retval is double)
            {
                return(JSValue.From((double)retval, context).JSValueRefPtr);
            }

            if (retval is string)
            {
                return(JSValue.From((string)retval, context).JSValueRefPtr);
            }

            return(retval.UnderlyingJSValue.JSValueRefPtr);
        }
Exemplo n.º 2
0
 public JSException(IntPtr exceptionPtr, IntPtr contextPtr)
     : this(exceptionPtr, JSContext.FromJSGlobalContextRef(contextPtr))
 {
 }