JsObject Class
A JavaScript object. The internal methods (https://tc39.es/ecma262/#sec-object-internal-methods-and-internal-slots) implement the ordinary object behavior; the exotic objects (arrays, proxies, arguments, typed arrays...) override them.
public class JsObject : JsCell- Inheritance
JsCellJsObject
Properties
| Name | Description |
|---|---|
| IsCallable | Gets whether the object has a [[Call]] internal method. |
| IsConstructor | Gets whether the object has a [[Construct]] internal method. |
| OwnPropertyCount | Gets the number of own properties in the storage of the object, without running code (the elements of an array are not counted): a host that creates objects with the same properties in each realm can give it to JsObject.ReserveProperties for the next ones. It is 0 for an exotic object. |
IsCallable
JsObject.csIsConstructor
JsObject.csOwnPropertyCount
JsObject.Public.csGets the number of own properties in the storage of the object, without running code (the elements of an array are not counted): a host that creates objects with the same properties in each realm can give it to JsObject.ReserveProperties for the next ones. It is 0 for an exotic object.
public int OwnPropertyCount { get; }Property value
Methods
| Name | Description |
|---|---|
| ContainsProperty(JsPropertyKey) | [[HasProperty]]: whether the object or its prototype chain has the property. |
| DefineLazyAccessorProperty(JsPropertyKey, Func<JsValue>, Func<JsValue>?, bool, bool) | Defines an accessor property whose functions are created on first access; setterFactory is null when the property has no setter. |
| DefineLazyAccessorProperty(JsPropertyKey, Func<object?, JsValue>, object?, Func<object?, JsValue>?, object?, bool, bool) | Defines an accessor property whose functions are created on first access by the factories, which get their state; setterFactory is null when the property has no setter. |
| DefineLazyDataProperty(JsPropertyKey, Func<JsValue>, bool, bool, bool) | Defines a data property whose value is created on first access (e.g. the interfaces of a global object, most of which are never used). |
| DefineLazyDataProperty(JsPropertyKey, Func<object?, JsValue>, object?, bool, bool, bool) | Defines a data property whose value is created on first access by factory, which gets state: a static callback with a state does not allocate a closure per property. |
| DefineProperty(JsPropertyKey, JsPropertyDescriptor) | [[DefineOwnProperty]]: returns false when the property cannot be defined. |
| DeleteProperty(JsPropertyKey) | [[Delete]]: returns false when the property cannot be deleted. |
| GetErrorStack() | Gets the stack trace of an error object (its [[Stack]] internal slot, read by the stack accessor). |
| GetIsExtensible() | [[IsExtensible]] |
| GetOwnPropertyKeys() | [[OwnPropertyKeys]]: the keys of the own properties, in the order of the specification. |
| GetProperty(JsPropertyKey) | [[Get]]: the value of a property (https://tc39.es/ecma262/#sec-get-o-p). |
| GetProperty(JsPropertyKey, JsValue) | [[Get]] with a receiver (the this value of a getter). |
| GetPrototype() | [[GetPrototypeOf]] |
| HasInternalSlot(JsInternalSlot) | Gets whether the object has an internal slot of the built-in objects, without running code. |
| MakePrototypeImmutable() | Makes the object an immutable prototype exotic object (https://tc39.es/ecma262/#sec-immutable-prototype-exotic-objects): its [[SetPrototypeOf]] is SetImmutablePrototype, which only accepts the current prototype (e.g. the global object of a window and its prototype chain). |
| PreventObjectExtensions() | [[PreventExtensions]] |
| ReserveProperties(int) | Prepares the object for count more properties (e.g. a host that defines hundreds of properties on a global object): their storage is allocated once. It does not change the behavior of the object. |
| SetProperty(JsPropertyKey, JsValue) | [[Set]]: assigns a property; returns false when the assignment fails (e.g. a read-only property). |
| SetProperty(JsPropertyKey, JsValue, JsValue) | [[Set]] with a receiver. |
| SetPrototype(JsObject?) | [[SetPrototypeOf]]: returns false when the prototype cannot be changed. |
| TryGetDateValue(double) | Gets the [[DateValue]] of a Date object (milliseconds since the Unix epoch, or NaN). |
| TryGetOwnProperty(JsPropertyKey, JsPropertyDescriptor) | [[GetOwnProperty]]: returns false when the object has no such own property. |
| TryGetPrimitiveValue(JsValue) | Gets the primitive value of a Boolean, Number, BigInt, String or Symbol object ([[BooleanData]]...). |
| TryGetPromiseState(JsPromiseState, JsValue, bool) | Gets the state of a promise ([[PromiseState]], [[PromiseResult]] and [[PromiseIsHandled]]); returns false when the object is not a promise. |
| TrySetErrorStack(string) | Sets the stack trace of an error object (e.g. a deserialized error); returns false when the object is not an error. |
ContainsProperty(JsPropertyKey)
JsObject.Public.cs[[HasProperty]]: whether the object or its prototype chain has the property.
public bool ContainsProperty(JsPropertyKey key)Parameters
keyJsPropertyKey
Returns
Exceptions
InvalidOperationException- No engine is entered on the thread, or the object belongs to another engine.
DefineLazyAccessorProperty overloads
DefineLazyAccessorProperty(JsPropertyKey, Func<JsValue>, Func<JsValue>?, bool, bool)
JsObject.Public.csDefines an accessor property whose functions are created on first access; setterFactory is null when the property has no setter.
public void DefineLazyAccessorProperty(JsPropertyKey key, Func<JsValue> getterFactory, Func<JsValue>? setterFactory, bool enumerable, bool configurable)Parameters
keyJsPropertyKeygetterFactoryFunc<JsValue>setterFactoryFunc<JsValue>?enumerableboolconfigurablebool
DefineLazyAccessorProperty(JsPropertyKey, Func<object?, JsValue>, object?, Func<object?, JsValue>?, object?, bool, bool)
JsObject.Public.csDefines an accessor property whose functions are created on first access by the factories, which get their state; setterFactory is null when the property has no setter.
public void DefineLazyAccessorProperty(JsPropertyKey key, Func<object?, JsValue> getterFactory, object? getterState, Func<object?, JsValue>? setterFactory, object? setterState, bool enumerable, bool configurable)Parameters
keyJsPropertyKeygetterFactoryFunc<object?, JsValue>getterStateobject?setterFactoryFunc<object?, JsValue>?setterStateobject?enumerableboolconfigurablebool
DefineLazyDataProperty overloads
DefineLazyDataProperty(JsPropertyKey, Func<JsValue>, bool, bool, bool)
JsObject.Public.csDefines a data property whose value is created on first access (e.g. the interfaces of a global object, most of which are never used).
public void DefineLazyDataProperty(JsPropertyKey key, Func<JsValue> factory, bool writable, bool enumerable, bool configurable)Parameters
keyJsPropertyKeyfactoryFunc<JsValue>writableboolenumerableboolconfigurablebool
DefineLazyDataProperty(JsPropertyKey, Func<object?, JsValue>, object?, bool, bool, bool)
JsObject.Public.csDefines a data property whose value is created on first access by factory, which gets state: a static callback with a state does not allocate a closure per property.
public void DefineLazyDataProperty(JsPropertyKey key, Func<object?, JsValue> factory, object? state, bool writable, bool enumerable, bool configurable)Parameters
keyJsPropertyKeyfactoryFunc<object?, JsValue>stateobject?writableboolenumerableboolconfigurablebool
DefineProperty(JsPropertyKey, JsPropertyDescriptor)
JsObject.Public.cs[[DefineOwnProperty]]: returns false when the property cannot be defined.
public bool DefineProperty(JsPropertyKey key, in JsPropertyDescriptor descriptor)Parameters
keyJsPropertyKeydescriptorJsPropertyDescriptor
Returns
Exceptions
InvalidOperationException- No engine is entered on the thread, or the object or a value of the descriptor belongs to another engine.
DeleteProperty(JsPropertyKey)
JsObject.Public.cs[[Delete]]: returns false when the property cannot be deleted.
public bool DeleteProperty(JsPropertyKey key)Parameters
keyJsPropertyKey
Returns
Exceptions
InvalidOperationException- No engine is entered on the thread, or the object belongs to another engine.
GetErrorStack()
JsObject.Public.csGetIsExtensible()
JsObject.Public.cs[[IsExtensible]]
public bool GetIsExtensible()Returns
Exceptions
InvalidOperationException- No engine is entered on the thread, or the object belongs to another engine.
GetOwnPropertyKeys()
JsObject.Public.cs[[OwnPropertyKeys]]: the keys of the own properties, in the order of the specification.
public IReadOnlyList<JsPropertyKey> GetOwnPropertyKeys()Returns
Exceptions
InvalidOperationException- No engine is entered on the thread, or the object belongs to another engine.
GetProperty overloads
GetProperty(JsPropertyKey)
JsObject.Public.cs[[Get]]: the value of a property (https://tc39.es/ecma262/#sec-get-o-p).
public JsValue GetProperty(JsPropertyKey key)Parameters
keyJsPropertyKey
Returns
Exceptions
InvalidOperationException- No engine is entered on the thread, or the object belongs to another engine.
GetProperty(JsPropertyKey, JsValue)
JsObject.Public.cs[[Get]] with a receiver (the this value of a getter).
public JsValue GetProperty(JsPropertyKey key, JsValue receiver)Parameters
keyJsPropertyKeyreceiverJsValue
Returns
Exceptions
InvalidOperationException- No engine is entered on the thread, or the object belongs to another engine.
GetPrototype()
JsObject.Public.cs[[GetPrototypeOf]]
public JsObject? GetPrototype()Returns
Exceptions
InvalidOperationException- No engine is entered on the thread, or the object belongs to another engine.
HasInternalSlot(JsInternalSlot)
JsObject.Public.csGets whether the object has an internal slot of the built-in objects, without running code.
public bool HasInternalSlot(JsInternalSlot slot)MakePrototypeImmutable()
JsObject.Public.csMakes the object an immutable prototype exotic object (https://tc39.es/ecma262/#sec-immutable-prototype-exotic-objects): its [[SetPrototypeOf]] is SetImmutablePrototype, which only accepts the current prototype (e.g. the global object of a window and its prototype chain).
public void MakePrototypeImmutable()Exceptions
InvalidOperationException- The object is a proxy: its handler defines its [[SetPrototypeOf]].
PreventObjectExtensions()
JsObject.Public.cs[[PreventExtensions]]
public bool PreventObjectExtensions()Returns
Exceptions
InvalidOperationException- No engine is entered on the thread, or the object belongs to another engine.
ReserveProperties(int)
JsObject.Public.csSetProperty overloads
SetProperty(JsPropertyKey, JsValue)
JsObject.Public.cs[[Set]]: assigns a property; returns false when the assignment fails (e.g. a read-only property).
public bool SetProperty(JsPropertyKey key, JsValue value)Parameters
keyJsPropertyKeyvalueJsValue
Returns
Exceptions
InvalidOperationException- No engine is entered on the thread, or the object or the value belongs to another engine.
SetProperty(JsPropertyKey, JsValue, JsValue)
JsObject.Public.cs[[Set]] with a receiver.
public bool SetProperty(JsPropertyKey key, JsValue value, JsValue receiver)Parameters
keyJsPropertyKeyvalueJsValuereceiverJsValue
Returns
Exceptions
InvalidOperationException- No engine is entered on the thread, or the object or a value belongs to another engine.
SetPrototype(JsObject?)
JsObject.Public.cs[[SetPrototypeOf]]: returns false when the prototype cannot be changed.
Parameters
prototypeJsObject?
Returns
Exceptions
InvalidOperationException- No engine is entered on the thread, or the object or the prototype belongs to another engine.
TryGetDateValue(double)
JsObject.Public.csTryGetOwnProperty(JsPropertyKey, JsPropertyDescriptor)
JsObject.Public.cs[[GetOwnProperty]]: returns false when the object has no such own property.
public bool TryGetOwnProperty(JsPropertyKey key, out JsPropertyDescriptor descriptor)Parameters
keyJsPropertyKeydescriptorJsPropertyDescriptor
Returns
Exceptions
InvalidOperationException- No engine is entered on the thread, or the object belongs to another engine.
TryGetPrimitiveValue(JsValue)
JsObject.Public.csTryGetPromiseState(JsPromiseState, JsValue, bool)
JsObject.Public.csGets the state of a promise ([[PromiseState]], [[PromiseResult]] and [[PromiseIsHandled]]); returns false when the object is not a promise.
public bool TryGetPromiseState(out JsPromiseState state, out JsValue result, out bool isHandled)