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
JsCell JsObject

Properties

NameDescription
IsCallableGets whether the object has a [[Call]] internal method.
IsConstructorGets whether the object has a [[Construct]] internal method.
OwnPropertyCountGets 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.cs

Gets whether the object has a [[Call]] internal method.

public bool IsCallable { get; }

Property value

bool

IsConstructor

JsObject.cs

Gets whether the object has a [[Construct]] internal method.

public bool IsConstructor { get; }

Property value

bool

OwnPropertyCount

JsObject.Public.cs

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.

public int OwnPropertyCount { get; }

Property value

int

Methods

NameDescription
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

key JsPropertyKey

Returns

bool

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.cs

Defines 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
key JsPropertyKey
getterFactory Func<JsValue>
setterFactory Func<JsValue>?
enumerable bool
configurable bool

DefineLazyAccessorProperty(JsPropertyKey, Func<object?, JsValue>, object?, Func<object?, JsValue>?, object?, bool, bool)

JsObject.Public.cs

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.

public void DefineLazyAccessorProperty(JsPropertyKey key, Func<object?, JsValue> getterFactory, object? getterState, Func<object?, JsValue>? setterFactory, object? setterState, bool enumerable, bool configurable)
Parameters
key JsPropertyKey
getterFactory Func<object?, JsValue>
getterState object?
setterFactory Func<object?, JsValue>?
setterState object?
enumerable bool
configurable bool

DefineLazyDataProperty overloads

DefineLazyDataProperty(JsPropertyKey, Func<JsValue>, bool, bool, bool)

JsObject.Public.cs

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).

public void DefineLazyDataProperty(JsPropertyKey key, Func<JsValue> factory, bool writable, bool enumerable, bool configurable)
Parameters
key JsPropertyKey
factory Func<JsValue>
writable bool
enumerable bool
configurable bool

DefineLazyDataProperty(JsPropertyKey, Func<object?, JsValue>, object?, bool, bool, bool)

JsObject.Public.cs

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.

public void DefineLazyDataProperty(JsPropertyKey key, Func<object?, JsValue> factory, object? state, bool writable, bool enumerable, bool configurable)
Parameters
key JsPropertyKey
factory Func<object?, JsValue>
state object?
writable bool
enumerable bool
configurable bool

DefineProperty(JsPropertyKey, JsPropertyDescriptor)

JsObject.Public.cs

[[DefineOwnProperty]]: returns false when the property cannot be defined.

public bool DefineProperty(JsPropertyKey key, in JsPropertyDescriptor descriptor)

Parameters

key JsPropertyKey
descriptor JsPropertyDescriptor

Returns

bool

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

key JsPropertyKey

Returns

bool

Exceptions

InvalidOperationException
No engine is entered on the thread, or the object belongs to another engine.

GetErrorStack()

JsObject.Public.cs

Gets the stack trace of an error object (its [[Stack]] internal slot, read by the stack accessor).

public string? GetErrorStack()

Returns

string?

GetIsExtensible()

JsObject.Public.cs

[[IsExtensible]]

public bool GetIsExtensible()

Returns

bool

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

IReadOnlyList<JsPropertyKey>

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
key JsPropertyKey
Returns

JsValue

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
key JsPropertyKey
receiver JsValue
Returns

JsValue

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

JsObject?

Exceptions

InvalidOperationException
No engine is entered on the thread, or the object belongs to another engine.

HasInternalSlot(JsInternalSlot)

JsObject.Public.cs

Gets whether the object has an internal slot of the built-in objects, without running code.

public bool HasInternalSlot(JsInternalSlot slot)

Parameters

slot JsInternalSlot

Returns

bool

MakePrototypeImmutable()

JsObject.Public.cs

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).

public void MakePrototypeImmutable()

Exceptions

InvalidOperationException
The object is a proxy: its handler defines its [[SetPrototypeOf]].

PreventObjectExtensions()

JsObject.Public.cs

[[PreventExtensions]]

public bool PreventObjectExtensions()

Returns

bool

Exceptions

InvalidOperationException
No engine is entered on the thread, or the object belongs to another engine.

ReserveProperties(int)

JsObject.Public.cs

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.

public void ReserveProperties(int count)

Parameters

count int

SetProperty 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
key JsPropertyKey
value JsValue
Returns

bool

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
key JsPropertyKey
value JsValue
receiver JsValue
Returns

bool

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.

public bool SetPrototype(JsObject? prototype)

Parameters

prototype JsObject?

Returns

bool

Exceptions

InvalidOperationException
No engine is entered on the thread, or the object or the prototype belongs to another engine.

TryGetDateValue(double)

JsObject.Public.cs

Gets the [[DateValue]] of a Date object (milliseconds since the Unix epoch, or NaN).

public bool TryGetDateValue(out double timeValue)

Parameters

timeValue double

Returns

bool

TryGetOwnProperty(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

key JsPropertyKey
descriptor JsPropertyDescriptor

Returns

bool

Exceptions

InvalidOperationException
No engine is entered on the thread, or the object belongs to another engine.

TryGetPrimitiveValue(JsValue)

JsObject.Public.cs

Gets the primitive value of a Boolean, Number, BigInt, String or Symbol object ([[BooleanData]]...).

public bool TryGetPrimitiveValue(out JsValue value)

Parameters

value JsValue

Returns

bool

TryGetPromiseState(JsPromiseState, JsValue, bool)

JsObject.Public.cs

Gets 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)

Parameters

state JsPromiseState
result JsValue
isHandled bool

Returns

bool

TrySetErrorStack(string)

JsObject.Public.cs

Sets the stack trace of an error object (e.g. a deserialized error); returns false when the object is not an error.

public bool TrySetErrorStack(string stack)

Parameters

stack string

Returns

bool