/// <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); }
/// <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(); } }
/// <summary> /// Retrieves a context's global object. /// </summary> /// <returns>A context's global object.</returns> public QuickJSValue GetGlobal() { return(QuickJSValue.Wrap(this, JS_GetGlobalObject(this.NativeInstance))); }