Beispiel #1
0
        /// <summary>
        /// Gets or sets the Array with the index specified by <paramref name="i" />.
        /// </summary>
        /// <param name="i">The index.</param>
        public object this[int i]
        {
            [MethodImpl(MethodImplOptions.NoInlining)] // https://github.com/dotnet/runtime/issues/71425
            get
            {
                this.AssertNotDisposed();

                Interop.Runtime.GetByIndexRef(JSHandle, i, out int exception, out object indexValue);

                if (exception != 0)
                {
                    throw new JSException((string)indexValue);
                }
                JSHostImplementation.ReleaseInFlight(indexValue);
                return(indexValue);
            }
            [MethodImpl(MethodImplOptions.NoInlining)] // https://github.com/dotnet/runtime/issues/71425
            set
            {
                this.AssertNotDisposed();

                Interop.Runtime.SetByIndexRef(JSHandle, i, value, out int exception, out object res);

                if (exception != 0)
                {
                    throw new JSException((string)res);
                }
            }
        }
Beispiel #2
0
 public static object Invoke(this JSObject self, string method, params object?[] args)
 {
     ArgumentNullException.ThrowIfNull(self);
     ObjectDisposedException.ThrowIf(self.IsDisposed, self);
     Interop.Runtime.InvokeJSWithArgsRef(self.JSHandle, method, args, out int exception, out object res);
     if (exception != 0)
     {
         throw new JSException((string)res);
     }
     JSHostImplementation.ReleaseInFlight(res);
     return(res);
 }
Beispiel #3
0
        public static object GetObjectProperty(this JSObject self, string name)
        {
            ArgumentNullException.ThrowIfNull(self);
            ObjectDisposedException.ThrowIf(self.IsDisposed, self);

            Interop.Runtime.GetObjectPropertyRef(self.JSHandle, name, out int exception, out object propertyValue);
            if (exception != 0)
            {
                throw new JSException((string)propertyValue);
            }
            JSHostImplementation.ReleaseInFlight(propertyValue);
            return(propertyValue);
        }
Beispiel #4
0
        public static object GetGlobalObject(string?str = null)
        {
            int exception;

            Interop.Runtime.GetGlobalObjectRef(str, out exception, out object jsObj);

            if (exception != 0)
            {
                throw new JSException($"Error obtaining a handle to global {str}");
            }

            JSHostImplementation.ReleaseInFlight(jsObj);
            return(jsObj);
        }
Beispiel #5
0
 /// <summary>
 ///   Invoke a named method of the object, or throws a JSException on error.
 /// </summary>
 /// <param name="self">thisArg</param>
 /// <param name="method">The name of the method to invoke.</param>
 /// <param name="args">The argument list to pass to the invoke command.</param>
 /// <returns>
 ///   <para>
 ///     The return value can either be a primitive (string, int, double), a JSObject for JavaScript objects, a
 ///     System.Threading.Tasks.Task(object) for JavaScript promises, an array of
 ///     a byte, int or double (for Javascript objects typed as ArrayBuffer) or a
 ///     System.Func to represent JavaScript functions.  The specific version of
 ///     the Func that will be returned depends on the parameters of the Javascript function
 ///     and return value.
 ///   </para>
 ///   <para>
 ///     The value of a returned promise (The Task(object) return) can in turn be any of the above
 ///     valuews.
 ///   </para>
 /// </returns>
 public static object Invoke(this JSObject self, string method, params object?[] args)
 {
     if (self == null)
     {
         throw new ArgumentNullException(nameof(self));
     }
     if (self.IsDisposed)
     {
         throw new ObjectDisposedException($"Cannot access a disposed {self.GetType().Name}.");
     }
     Interop.Runtime.InvokeJSWithArgsRef(self.JSHandle, method, args, out int exception, out object res);
     if (exception != 0)
     {
         throw new JSException((string)res);
     }
     JSHostImplementation.ReleaseInFlight(res);
     return(res);
 }
Beispiel #6
0
        /// <summary>
        ///   Returns the named property from the object, or throws a JSException on error.
        /// </summary>
        /// <param name="self">thisArg</param>
        /// <param name="name">The name of the property to lookup</param>
        /// <remarks>
        ///   This method can raise a JSException if fetching the property in Javascript raises an exception.
        /// </remarks>
        /// <returns>
        ///   <para>
        ///     The return value can either be a primitive (string, int, double), a
        ///     JSObject for JavaScript objects, a
        ///     System.Threading.Tasks.Task (object) for JavaScript promises, an array of
        ///     a byte, int or double (for Javascript objects typed as ArrayBuffer) or a
        ///     System.Func to represent JavaScript functions.  The specific version of
        ///     the Func that will be returned depends on the parameters of the Javascript function
        ///     and return value.
        ///   </para>
        ///   <para>
        ///     The value of a returned promise (The Task(object) return) can in turn be any of the above
        ///     valuews.
        ///   </para>
        /// </returns>
        public static object GetObjectProperty(this JSObject self, string name)
        {
            if (self == null)
            {
                throw new ArgumentNullException(nameof(self));
            }
            if (self.IsDisposed)
            {
                throw new ObjectDisposedException($"Cannot access a disposed {self.GetType().Name}.");
            }

            Interop.Runtime.GetObjectPropertyRef(self.JSHandle, name, out int exception, out object propertyValue);
            if (exception != 0)
            {
                throw new JSException((string)propertyValue);
            }
            JSHostImplementation.ReleaseInFlight(propertyValue);
            return(propertyValue);
        }