Example #1
0
        public dynamic CreateObject(Action <dynamic> populator = null)
        {
            var wrapped = new WrappedObject(JSValue.CreateObject(underlyingContext));

            populator?.Invoke(wrapped);
            return(wrapped);
        }
Example #2
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);
        }
Example #3
0
 object IReflect.InvokeMember(string name, BindingFlags invokeAttr, Binder binder, object target, object [] args,
                              ParameterModifier [] modifiers, CultureInfo culture, string [] namedParameters)
 {
     handler(WrappedObject.Wrap <Event> (context, args [1]));
     return(null);
 }
Example #4
0
 void IEventListener.HandleEvent()
 {
     handler?.Invoke(WrappedObject.Wrap <Event> (JSContext.CurrentArguments [0]));
 }