Пример #1
0
        /// <summary>
        /// Get the builtin class prototype object.
        /// </summary>
        /// <param name="id">A JavaScript class identifier.</param>
        public QuickJSValue GetClassPrototype(JSClassID id)
        {
            if (!Runtime.IsRegisteredClass(id))
            {
                throw new ArgumentOutOfRangeException(nameof(id));
            }
            JSValue proto = JS_GetClassProto(this.NativeInstance, id);

            return(proto.Tag == JSTag.Object ? QuickJSValue.Wrap(this, proto) : null);
        }
Пример #2
0
        /// <summary>
        /// Converts the value of the specified <see cref="JSValue"/> to a value of a .NET type.
        /// </summary>
        /// <param name="value">The <see cref="JSValue"/> to convert.</param>
        /// <param name="freeValue">
        /// A value indicating that the <see cref="JSValue"/> should be freed.
        /// </param>
        /// <returns>
        /// An <see cref="Object"/> whose value is equivalent to <paramref name="value"/>.
        /// </returns>
        /// <exception cref="InvalidCastException">
        /// This conversion is not supported.
        /// </exception>
        protected internal virtual object ConvertJSValueToClrObject(JSValue value, bool freeValue)
        {
            switch (value.Tag)
            {
            case JSTag.Bool:
                return(value.ToBoolean());

            case JSTag.Null:
                return(null);

            case JSTag.String:
                string s = value.ToString(this.NativeInstance);
                if (freeValue)
                {
                    JS_FreeValue(this.NativeInstance, value);
                }
                return(s);

            case JSTag.Int:
                return(value.ToInt32());

            case JSTag.Float64:
                return(value.ToDouble());

            case JSTag.Undefined:
                return(QuickJSValue.Undefined);

            default:
                if (value.Tag <= JSTag.Object)
                {
                    return(QuickJSValue.Wrap(this, value));
                }
                if (freeValue)
                {
                    JS_FreeValue(this.NativeInstance, value);
                }
                throw new InvalidCastException();
            }
        }
Пример #3
0
 /// <summary>
 /// Retrieves a context&apos;s global object.
 /// </summary>
 /// <returns>A context&apos;s global object.</returns>
 public QuickJSValue GetGlobal()
 {
     return(QuickJSValue.Wrap(this, JS_GetGlobalObject(this.NativeInstance)));
 }