public unsafe void ToJS(Exception?value)
        {
            if (value == null)
            {
                slot.Type = MarshalerType.None;
            }
            else
            {
                Exception cpy = value;
                if (cpy is AggregateException ae && ae.InnerExceptions.Count == 1)
                {
                    cpy = ae.InnerExceptions[0];
                }

                var jse = cpy as JSException;
                if (jse != null && jse.jsException != null)
                {
                    // this is JSException roundtrip
                    if (jse.jsException.IsDisposed)
                    {
                        throw new ObjectDisposedException(nameof(value));
                    }
                    slot.Type     = MarshalerType.JSException;
                    slot.JSHandle = jse.jsException.JSHandle;
                }
                else
                {
                    ToJS(cpy.Message);
                    slot.Type     = MarshalerType.Exception;
                    slot.GCHandle = JSHostImplementation.GetJSOwnedObjectGCHandle(cpy);
                }
            }
        }
Ejemplo n.º 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 ToJS(ArraySegment <int> value)
        {
            if (value.Array == null)
            {
                slot.Type = MarshalerType.None;
                return;
            }
            slot.Type     = MarshalerType.ArraySegment;
            slot.GCHandle = JSHostImplementation.GetJSOwnedObjectGCHandle(value.Array, GCHandleType.Pinned);
            var refPtr = (IntPtr)Unsafe.AsPointer(ref MemoryMarshal.GetArrayDataReference(value.Array));

            slot.IntPtrValue = refPtr + (value.Offset * sizeof(int));
            slot.Length      = value.Count;
        }