Beispiel #1
0
        /// <summary>
        /// Implementation of the argument marshaling.
        /// It's used by JSImport code generator and should not be used by developers in source code.
        /// </summary>
        public unsafe void ToManaged(out Task?value)
        {
            if (slot.Type == MarshalerType.None)
            {
                value = null;
                return;
            }

            GCHandle gcHandle = (GCHandle)slot.GCHandle;

            JSHostImplementation.TaskCallback?holder = (JSHostImplementation.TaskCallback?)gcHandle.Target;
            if (holder == null)
            {
                throw new NullReferenceException("JSHostImplementation.TaskCallback");
            }

            TaskCompletionSource tcs = new TaskCompletionSource(gcHandle);

            JSHostImplementation.ToManagedCallback callback = (JSMarshalerArgument * arguments_buffer) =>
            {
                ref JSMarshalerArgument arg_2 = ref arguments_buffer[3]; // set by caller when this is SetException call
                // arg_3 set by caller when this is SetResult call, un-used here
                if (arg_2.slot.Type != MarshalerType.None)
                {
                    arg_2.ToManaged(out Exception? fail);
                    tcs.SetException(fail !);
                }
                else
                {
                    tcs.SetResult();
                }
                // eventual exception is handled by caller
            };
Beispiel #2
0
        /// <summary>
        /// Implementation of the argument marshaling.
        /// It's used by JSImport code generator and should not be used by developers in source code.
        /// </summary>
        public unsafe void ToManaged(out Task?value)
        {
            if (slot.Type == MarshalerType.None)
            {
                value = null;
                return;
            }

            GCHandle gcHandle = (GCHandle)slot.GCHandle;

            JSHostImplementation.TaskCallback?holder = (JSHostImplementation.TaskCallback?)gcHandle.Target;
            if (holder == null)
            {
                throw new NullReferenceException("JSHostImplementation.TaskCallback");
            }

            TaskCompletionSource tcs = new TaskCompletionSource(gcHandle);

            JSHostImplementation.ToManagedCallback callback = (JSMarshalerArgument * arguments_buffer) =>
            {
                ref JSMarshalerArgument arg_exception = ref arguments_buffer[0];
                try
                {
                    if (arg_exception.slot.Type != MarshalerType.None)
                    {
                        arg_exception.ToManaged(out Exception? fail);
                        tcs.SetException(fail !);
                    }
                    else
                    {
                        tcs.SetResult();
                    }
                    arg_exception.slot.Type = MarshalerType.None;
                }
                catch (Exception ex)
                {
                    arg_exception.ToJS(ex);
                }
            };