Esempio n. 1
0
 /// <summary>
 /// Defines a new property directly on an object, or modifies an existing property on an object.
 /// </summary>
 /// <param name="name">The name of the property to be defined or modified.</param>
 /// <param name="value">The value associated with the property.</param>
 /// <param name="flags">A bitwise combination of the <see cref="JSPropertyFlags"/>.</param>
 /// <returns>true if the property has been defined or redefined; otherwise false.</returns>
 public bool DefineProperty(string name, QuickJSValue value, JSPropertyFlags flags)
 {
     if (value is null)
     {
         return(DefineProperty(name, JSValue.Null, flags));
     }
     else
     {
         if (!Context.IsCompatibleWith(value.Context))
         {
             throw new ArgumentOutOfRangeException(nameof(value));
         }
         return(DefineProperty(name, value.GetNativeInstance(), flags));
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Assigns a <see cref="QuickJSValue"/> value to a property of an object.
 /// </summary>
 /// <param name="index">The index of the property to set.</param>
 /// <param name="value">The value to assign to the property.</param>
 /// <returns>On success, returns true; otherwise, false.</returns>
 public bool SetProperty(int index, QuickJSValue value)
 {
     if (value is null)
     {
         return(SetProperty(index, JSValue.Null));
     }
     else
     {
         if (!Context.IsCompatibleWith(value.Context))
         {
             throw new ArgumentOutOfRangeException(nameof(value));
         }
         return(SetProperty(index, value.GetNativeInstance()));
     }
 }
Esempio n. 3
0
 /// <summary>
 /// Sets the class prototype object.
 /// </summary>
 /// <param name="id">A JavaScript class identifier.</param>
 /// <param name="proto">A prototype object or null.</param>
 /// <param name="disposeProto">true if <paramref name="proto"/> should be disposed of.</param>
 public void SetClassPrototype(JSClassID id, QuickJSValue proto, bool disposeProto)
 {
     if (!Runtime.IsRegisteredClass(id))
     {
         throw new ArgumentOutOfRangeException(nameof(id));
     }
     if (proto is null)
     {
         JS_SetClassProto(this.NativeInstance, id, JSValue.Null);
     }
     else
     {
         JS_SetClassProto(this.NativeInstance, id, proto.GetNativeInstance());
         if (disposeProto)
         {
             proto.Dispose();
         }
     }
 }