mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 03:17:34 +00:00
LibJS: Add spec comments to Value::to_object()
This commit is contained in:
parent
9c10624278
commit
63f6099cc3
1 changed files with 18 additions and 1 deletions
|
@ -519,22 +519,39 @@ ThrowCompletionOr<Object*> Value::to_object(VM& vm) const
|
||||||
{
|
{
|
||||||
auto& realm = *vm.current_realm();
|
auto& realm = *vm.current_realm();
|
||||||
VERIFY(!is_empty());
|
VERIFY(!is_empty());
|
||||||
if (is_number())
|
|
||||||
|
// Number
|
||||||
|
if (is_number()) {
|
||||||
|
// Return a new Number object whose [[NumberData]] internal slot is set to argument. See 21.1 for a description of Number objects.
|
||||||
return NumberObject::create(realm, as_double());
|
return NumberObject::create(realm, as_double());
|
||||||
|
}
|
||||||
|
|
||||||
switch (m_value.tag) {
|
switch (m_value.tag) {
|
||||||
|
// Undefined
|
||||||
|
// Null
|
||||||
case UNDEFINED_TAG:
|
case UNDEFINED_TAG:
|
||||||
case NULL_TAG:
|
case NULL_TAG:
|
||||||
|
// Throw a TypeError exception.
|
||||||
return vm.throw_completion<TypeError>(ErrorType::ToObjectNullOrUndefined);
|
return vm.throw_completion<TypeError>(ErrorType::ToObjectNullOrUndefined);
|
||||||
|
// Boolean
|
||||||
case BOOLEAN_TAG:
|
case BOOLEAN_TAG:
|
||||||
|
// Return a new Boolean object whose [[BooleanData]] internal slot is set to argument. See 20.3 for a description of Boolean objects.
|
||||||
return BooleanObject::create(realm, as_bool());
|
return BooleanObject::create(realm, as_bool());
|
||||||
|
// String
|
||||||
case STRING_TAG:
|
case STRING_TAG:
|
||||||
|
// Return a new String object whose [[StringData]] internal slot is set to argument. See 22.1 for a description of String objects.
|
||||||
return StringObject::create(realm, const_cast<JS::PrimitiveString&>(as_string()), *realm.intrinsics().string_prototype());
|
return StringObject::create(realm, const_cast<JS::PrimitiveString&>(as_string()), *realm.intrinsics().string_prototype());
|
||||||
|
// Symbol
|
||||||
case SYMBOL_TAG:
|
case SYMBOL_TAG:
|
||||||
|
// Return a new Symbol object whose [[SymbolData]] internal slot is set to argument. See 20.4 for a description of Symbol objects.
|
||||||
return SymbolObject::create(realm, const_cast<JS::Symbol&>(as_symbol()));
|
return SymbolObject::create(realm, const_cast<JS::Symbol&>(as_symbol()));
|
||||||
|
// BigInt
|
||||||
case BIGINT_TAG:
|
case BIGINT_TAG:
|
||||||
|
// Return a new BigInt object whose [[BigIntData]] internal slot is set to argument. See 21.2 for a description of BigInt objects.
|
||||||
return BigIntObject::create(realm, const_cast<JS::BigInt&>(as_bigint()));
|
return BigIntObject::create(realm, const_cast<JS::BigInt&>(as_bigint()));
|
||||||
|
// Object
|
||||||
case OBJECT_TAG:
|
case OBJECT_TAG:
|
||||||
|
// Return argument.
|
||||||
return &const_cast<Object&>(as_object());
|
return &const_cast<Object&>(as_object());
|
||||||
default:
|
default:
|
||||||
VERIFY_NOT_REACHED();
|
VERIFY_NOT_REACHED();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue