mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 17:27:35 +00:00
LibJS: Replace GlobalObject with VM in Value AOs [Part 4/19]
This is where the fun begins. :^)
This commit is contained in:
parent
f6c4a0f5d0
commit
a022e548b8
129 changed files with 1230 additions and 1325 deletions
|
@ -92,7 +92,7 @@ ThrowCompletionOr<size_t> length_of_array_like(GlobalObject& global_object, Obje
|
|||
{
|
||||
auto& vm = global_object.vm();
|
||||
auto result = TRY(object.get(vm.names.length));
|
||||
return result.to_length(global_object);
|
||||
return result.to_length(vm);
|
||||
}
|
||||
|
||||
// 7.3.20 CreateListFromArrayLike ( obj [ , elementTypes ] ), https://tc39.es/ecma262/#sec-createlistfromarraylike
|
||||
|
@ -1220,7 +1220,8 @@ CanonicalIndex canonical_numeric_index_string(PropertyKey const& property_key, C
|
|||
// 22.1.3.17.1 GetSubstitution ( matched, str, position, captures, namedCaptures, replacement ), https://tc39.es/ecma262/#sec-getsubstitution
|
||||
ThrowCompletionOr<String> get_substitution(GlobalObject& global_object, Utf16View const& matched, Utf16View const& str, size_t position, Span<Value> captures, Value named_captures, Value replacement)
|
||||
{
|
||||
auto replace_string = TRY(replacement.to_utf16_string(global_object));
|
||||
auto& vm = global_object.vm();
|
||||
auto replace_string = TRY(replacement.to_utf16_string(vm));
|
||||
auto replace_view = replace_string.view();
|
||||
|
||||
StringBuilder result;
|
||||
|
@ -1262,7 +1263,7 @@ ThrowCompletionOr<String> get_substitution(GlobalObject& global_object, Utf16Vie
|
|||
auto& value = captures[*capture_position - 1];
|
||||
|
||||
if (!value.is_undefined()) {
|
||||
auto value_string = TRY(value.to_string(global_object));
|
||||
auto value_string = TRY(value.to_string(vm));
|
||||
result.append(value_string);
|
||||
}
|
||||
|
||||
|
@ -1290,7 +1291,7 @@ ThrowCompletionOr<String> get_substitution(GlobalObject& global_object, Utf16Vie
|
|||
auto capture = TRY(named_captures.as_object().get(group_name));
|
||||
|
||||
if (!capture.is_undefined()) {
|
||||
auto capture_string = TRY(capture.to_string(global_object));
|
||||
auto capture_string = TRY(capture.to_string(vm));
|
||||
result.append(capture_string);
|
||||
}
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ ThrowCompletionOr<Object*> AggregateErrorConstructor::construct(FunctionObject&
|
|||
auto* aggregate_error = TRY(ordinary_create_from_constructor<AggregateError>(global_object, new_target, &GlobalObject::aggregate_error_prototype));
|
||||
|
||||
if (!vm.argument(1).is_undefined()) {
|
||||
auto message = TRY(vm.argument(1).to_string(global_object));
|
||||
auto message = TRY(vm.argument(1).to_string(vm));
|
||||
aggregate_error->create_non_enumerable_data_property_or_throw(vm.names.message, js_string(vm, message));
|
||||
}
|
||||
|
||||
|
|
|
@ -68,7 +68,6 @@ Array::Array(Object& prototype)
|
|||
// 10.4.2.4 ArraySetLength ( A, Desc ), https://tc39.es/ecma262/#sec-arraysetlength
|
||||
ThrowCompletionOr<bool> Array::set_length(PropertyDescriptor const& property_descriptor)
|
||||
{
|
||||
auto& global_object = this->global_object();
|
||||
auto& vm = this->vm();
|
||||
|
||||
// 1. If Desc does not have a [[Value]] field, then
|
||||
|
@ -79,9 +78,9 @@ ThrowCompletionOr<bool> Array::set_length(PropertyDescriptor const& property_des
|
|||
size_t new_length = indexed_properties().array_like_size();
|
||||
if (property_descriptor.value.has_value()) {
|
||||
// 3. Let newLen be ? ToUint32(Desc.[[Value]]).
|
||||
new_length = TRY(property_descriptor.value->to_u32(global_object));
|
||||
new_length = TRY(property_descriptor.value->to_u32(vm));
|
||||
// 4. Let numberLen be ? ToNumber(Desc.[[Value]]).
|
||||
auto number_length = TRY(property_descriptor.value->to_number(global_object));
|
||||
auto number_length = TRY(property_descriptor.value->to_number(vm));
|
||||
// 5. If newLen is not the same value as numberLen, throw a RangeError exception.
|
||||
if (new_length != number_length.as_double())
|
||||
return vm.throw_completion<RangeError>(ErrorType::InvalidLength, "array");
|
||||
|
@ -178,7 +177,7 @@ ThrowCompletionOr<double> compare_array_elements(GlobalObject& global_object, Va
|
|||
if (comparefn != nullptr) {
|
||||
// a. Let v be ? ToNumber(? Call(comparefn, undefined, « x, y »)).
|
||||
auto value = TRY(call(global_object, comparefn, js_undefined(), x, y));
|
||||
auto value_number = TRY(value.to_number(global_object));
|
||||
auto value_number = TRY(value.to_number(vm));
|
||||
|
||||
// b. If v is NaN, return +0𝔽.
|
||||
if (value_number.is_nan())
|
||||
|
@ -189,20 +188,20 @@ ThrowCompletionOr<double> compare_array_elements(GlobalObject& global_object, Va
|
|||
}
|
||||
|
||||
// 5. Let xString be ? ToString(x).
|
||||
auto* x_string = js_string(vm, TRY(x.to_string(global_object)));
|
||||
auto* x_string = js_string(vm, TRY(x.to_string(vm)));
|
||||
|
||||
// 6. Let yString be ? ToString(y).
|
||||
auto* y_string = js_string(vm, TRY(y.to_string(global_object)));
|
||||
auto* y_string = js_string(vm, TRY(y.to_string(vm)));
|
||||
|
||||
// 7. Let xSmaller be ! IsLessThan(xString, yString, true).
|
||||
auto x_smaller = MUST(is_less_than(global_object, x_string, y_string, true));
|
||||
auto x_smaller = MUST(is_less_than(vm, x_string, y_string, true));
|
||||
|
||||
// 8. If xSmaller is true, return -1𝔽.
|
||||
if (x_smaller == TriState::True)
|
||||
return -1;
|
||||
|
||||
// 9. Let ySmaller be ! IsLessThan(yString, xString, true).
|
||||
auto y_smaller = MUST(is_less_than(global_object, y_string, x_string, true));
|
||||
auto y_smaller = MUST(is_less_than(vm, y_string, x_string, true));
|
||||
|
||||
// 10. If ySmaller is true, return 1𝔽.
|
||||
if (y_smaller == TriState::True)
|
||||
|
|
|
@ -135,6 +135,7 @@ template<typename T>
|
|||
static ByteBuffer numeric_to_raw_bytes(GlobalObject& global_object, Value value, bool is_little_endian)
|
||||
{
|
||||
VERIFY(value.is_number() || value.is_bigint());
|
||||
auto& vm = global_object.vm();
|
||||
using UnderlyingBufferDataType = Conditional<IsSame<ClampedU8, T>, u8, T>;
|
||||
ByteBuffer raw_bytes = ByteBuffer::create_uninitialized(sizeof(UnderlyingBufferDataType)).release_value_but_fixme_should_propagate_errors(); // FIXME: Handle possible OOM situation.
|
||||
auto flip_if_needed = [&]() {
|
||||
|
@ -145,13 +146,13 @@ static ByteBuffer numeric_to_raw_bytes(GlobalObject& global_object, Value value,
|
|||
swap(raw_bytes[i], raw_bytes[sizeof(UnderlyingBufferDataType) - 1 - i]);
|
||||
};
|
||||
if constexpr (IsSame<UnderlyingBufferDataType, float>) {
|
||||
float raw_value = MUST(value.to_double(global_object));
|
||||
float raw_value = MUST(value.to_double(vm));
|
||||
ReadonlyBytes { &raw_value, sizeof(float) }.copy_to(raw_bytes);
|
||||
flip_if_needed();
|
||||
return raw_bytes;
|
||||
}
|
||||
if constexpr (IsSame<UnderlyingBufferDataType, double>) {
|
||||
double raw_value = MUST(value.to_double(global_object));
|
||||
double raw_value = MUST(value.to_double(vm));
|
||||
ReadonlyBytes { &raw_value, sizeof(double) }.copy_to(raw_bytes);
|
||||
flip_if_needed();
|
||||
return raw_bytes;
|
||||
|
@ -162,9 +163,9 @@ static ByteBuffer numeric_to_raw_bytes(GlobalObject& global_object, Value value,
|
|||
UnderlyingBufferDataType int_value;
|
||||
|
||||
if constexpr (IsSigned<UnderlyingBufferDataType>)
|
||||
int_value = MUST(value.to_bigint_int64(global_object));
|
||||
int_value = MUST(value.to_bigint_int64(vm));
|
||||
else
|
||||
int_value = MUST(value.to_bigint_uint64(global_object));
|
||||
int_value = MUST(value.to_bigint_uint64(vm));
|
||||
|
||||
ReadonlyBytes { &int_value, sizeof(UnderlyingBufferDataType) }.copy_to(raw_bytes);
|
||||
flip_if_needed();
|
||||
|
@ -173,20 +174,20 @@ static ByteBuffer numeric_to_raw_bytes(GlobalObject& global_object, Value value,
|
|||
UnderlyingBufferDataType int_value;
|
||||
if constexpr (IsSigned<UnderlyingBufferDataType>) {
|
||||
if constexpr (sizeof(UnderlyingBufferDataType) == 4)
|
||||
int_value = MUST(value.to_i32(global_object));
|
||||
int_value = MUST(value.to_i32(vm));
|
||||
else if constexpr (sizeof(UnderlyingBufferDataType) == 2)
|
||||
int_value = MUST(value.to_i16(global_object));
|
||||
int_value = MUST(value.to_i16(vm));
|
||||
else
|
||||
int_value = MUST(value.to_i8(global_object));
|
||||
int_value = MUST(value.to_i8(vm));
|
||||
} else {
|
||||
if constexpr (sizeof(UnderlyingBufferDataType) == 4)
|
||||
int_value = MUST(value.to_u32(global_object));
|
||||
int_value = MUST(value.to_u32(vm));
|
||||
else if constexpr (sizeof(UnderlyingBufferDataType) == 2)
|
||||
int_value = MUST(value.to_u16(global_object));
|
||||
int_value = MUST(value.to_u16(vm));
|
||||
else if constexpr (!IsSame<T, ClampedU8>)
|
||||
int_value = MUST(value.to_u8(global_object));
|
||||
int_value = MUST(value.to_u8(vm));
|
||||
else
|
||||
int_value = MUST(value.to_u8_clamp(global_object));
|
||||
int_value = MUST(value.to_u8_clamp(vm));
|
||||
}
|
||||
ReadonlyBytes { &int_value, sizeof(UnderlyingBufferDataType) }.copy_to(raw_bytes);
|
||||
if constexpr (sizeof(UnderlyingBufferDataType) % 2 == 0)
|
||||
|
|
|
@ -46,7 +46,7 @@ ThrowCompletionOr<Value> ArrayBufferConstructor::call()
|
|||
ThrowCompletionOr<Object*> ArrayBufferConstructor::construct(FunctionObject& new_target)
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
auto byte_length_or_error = vm.argument(0).to_index(global_object());
|
||||
auto byte_length_or_error = vm.argument(0).to_index(vm);
|
||||
|
||||
if (byte_length_or_error.is_error()) {
|
||||
auto error = byte_length_or_error.release_error();
|
||||
|
|
|
@ -49,7 +49,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayBufferPrototype::slice)
|
|||
auto length = array_buffer_object->byte_length();
|
||||
|
||||
// 6. Let relativeStart be ? ToIntegerOrInfinity(start).
|
||||
auto relative_start = TRY(vm.argument(0).to_integer_or_infinity(global_object));
|
||||
auto relative_start = TRY(vm.argument(0).to_integer_or_infinity(vm));
|
||||
|
||||
double first;
|
||||
// 7. If relativeStart is -∞, let first be 0.
|
||||
|
@ -63,7 +63,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayBufferPrototype::slice)
|
|||
first = min(relative_start, (double)length);
|
||||
|
||||
// 10. If end is undefined, let relativeEnd be len; else let relativeEnd be ? ToIntegerOrInfinity(end).
|
||||
auto relative_end = vm.argument(1).is_undefined() ? length : TRY(vm.argument(1).to_integer_or_infinity(global_object));
|
||||
auto relative_end = vm.argument(1).is_undefined() ? length : TRY(vm.argument(1).to_integer_or_infinity(vm));
|
||||
|
||||
double final;
|
||||
// 11. If relativeEnd is -∞, let final be 0.
|
||||
|
|
|
@ -66,7 +66,7 @@ ThrowCompletionOr<Object*> ArrayConstructor::construct(FunctionObject& new_targe
|
|||
MUST(array->create_data_property_or_throw(0, length));
|
||||
int_length = 1;
|
||||
} else {
|
||||
int_length = MUST(length.to_u32(global_object));
|
||||
int_length = MUST(length.to_u32(vm));
|
||||
if (int_length != length.as_double())
|
||||
return vm.throw_completion<RangeError>(ErrorType::InvalidLength, "array");
|
||||
}
|
||||
|
@ -99,7 +99,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayConstructor::from)
|
|||
auto this_arg = vm.argument(2);
|
||||
|
||||
auto items = vm.argument(0);
|
||||
auto using_iterator = TRY(items.get_method(global_object, *vm.well_known_symbol_iterator()));
|
||||
auto using_iterator = TRY(items.get_method(vm, *vm.well_known_symbol_iterator()));
|
||||
if (using_iterator) {
|
||||
Object* array;
|
||||
if (constructor.is_constructor())
|
||||
|
@ -142,7 +142,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayConstructor::from)
|
|||
}
|
||||
}
|
||||
|
||||
auto* array_like = MUST(items.to_object(global_object));
|
||||
auto* array_like = MUST(items.to_object(vm));
|
||||
|
||||
auto length = TRY(length_of_array_like(global_object, *array_like));
|
||||
|
||||
|
@ -171,7 +171,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayConstructor::from)
|
|||
JS_DEFINE_NATIVE_FUNCTION(ArrayConstructor::is_array)
|
||||
{
|
||||
auto value = vm.argument(0);
|
||||
return Value(TRY(value.is_array(global_object)));
|
||||
return Value(TRY(value.is_array(vm)));
|
||||
}
|
||||
|
||||
// 23.1.2.3 Array.of ( ...items ), https://tc39.es/ecma262/#sec-array.of
|
||||
|
|
|
@ -118,7 +118,7 @@ static ThrowCompletionOr<Object*> array_species_create(GlobalObject& global_obje
|
|||
auto& vm = global_object.vm();
|
||||
auto& realm = *global_object.associated_realm();
|
||||
|
||||
auto is_array = TRY(Value(&original_array).is_array(global_object));
|
||||
auto is_array = TRY(Value(&original_array).is_array(vm));
|
||||
|
||||
if (!is_array)
|
||||
return TRY(Array::create(realm, length));
|
||||
|
@ -152,9 +152,9 @@ static ThrowCompletionOr<Object*> array_species_create(GlobalObject& global_obje
|
|||
// 23.1.3.1 Array.prototype.at ( index ), https://tc39.es/ecma262/#sec-array.prototype.at
|
||||
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::at)
|
||||
{
|
||||
auto* this_object = TRY(vm.this_value().to_object(global_object));
|
||||
auto* this_object = TRY(vm.this_value().to_object(vm));
|
||||
auto length = TRY(length_of_array_like(global_object, *this_object));
|
||||
auto relative_index = TRY(vm.argument(0).to_integer_or_infinity(global_object));
|
||||
auto relative_index = TRY(vm.argument(0).to_integer_or_infinity(vm));
|
||||
if (Value(relative_index).is_infinity())
|
||||
return js_undefined();
|
||||
Checked<size_t> index { 0 };
|
||||
|
@ -172,7 +172,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::at)
|
|||
// 23.1.3.2 Array.prototype.concat ( ...items ), https://tc39.es/ecma262/#sec-array.prototype.concat
|
||||
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::concat)
|
||||
{
|
||||
auto* this_object = TRY(vm.this_value().to_object(global_object));
|
||||
auto* this_object = TRY(vm.this_value().to_object(vm));
|
||||
|
||||
auto* new_array = TRY(array_species_create(global_object, *this_object, 0));
|
||||
|
||||
|
@ -187,7 +187,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::concat)
|
|||
if (!spreadable.is_undefined())
|
||||
return spreadable.to_boolean();
|
||||
|
||||
return TRY(val.is_array(global_object));
|
||||
return TRY(val.is_array(vm));
|
||||
};
|
||||
|
||||
auto append_to_new_array = [&vm, &is_concat_spreadable, &new_array, &global_object, &n](Value arg) -> ThrowCompletionOr<void> {
|
||||
|
@ -230,10 +230,10 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::concat)
|
|||
// 23.1.3.4 Array.prototype.copyWithin ( target, start [ , end ] ), https://tc39.es/ecma262/#sec-array.prototype.copywithin
|
||||
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::copy_within)
|
||||
{
|
||||
auto* this_object = TRY(vm.this_value().to_object(global_object));
|
||||
auto* this_object = TRY(vm.this_value().to_object(vm));
|
||||
auto length = TRY(length_of_array_like(global_object, *this_object));
|
||||
|
||||
auto relative_target = TRY(vm.argument(0).to_integer_or_infinity(global_object));
|
||||
auto relative_target = TRY(vm.argument(0).to_integer_or_infinity(vm));
|
||||
|
||||
double to;
|
||||
if (relative_target < 0)
|
||||
|
@ -241,7 +241,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::copy_within)
|
|||
else
|
||||
to = min(relative_target, (double)length);
|
||||
|
||||
auto relative_start = TRY(vm.argument(1).to_integer_or_infinity(global_object));
|
||||
auto relative_start = TRY(vm.argument(1).to_integer_or_infinity(vm));
|
||||
|
||||
double from;
|
||||
if (relative_start < 0)
|
||||
|
@ -249,7 +249,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::copy_within)
|
|||
else
|
||||
from = min(relative_start, (double)length);
|
||||
|
||||
auto relative_end = vm.argument(2).is_undefined() ? length : TRY(vm.argument(2).to_integer_or_infinity(global_object));
|
||||
auto relative_end = vm.argument(2).is_undefined() ? length : TRY(vm.argument(2).to_integer_or_infinity(vm));
|
||||
|
||||
double final;
|
||||
if (relative_end < 0)
|
||||
|
@ -298,7 +298,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::entries)
|
|||
{
|
||||
auto& realm = *global_object.associated_realm();
|
||||
|
||||
auto* this_object = TRY(vm.this_value().to_object(global_object));
|
||||
auto* this_object = TRY(vm.this_value().to_object(vm));
|
||||
|
||||
return ArrayIterator::create(realm, this_object, Object::PropertyKind::KeyAndValue);
|
||||
}
|
||||
|
@ -310,7 +310,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::every)
|
|||
auto this_arg = vm.argument(1);
|
||||
|
||||
// 1. Let O be ? ToObject(this value).
|
||||
auto* object = TRY(vm.this_value().to_object(global_object));
|
||||
auto* object = TRY(vm.this_value().to_object(vm));
|
||||
|
||||
// 2. Let len be ? LengthOfArrayLike(O).
|
||||
auto length = TRY(length_of_array_like(global_object, *object));
|
||||
|
@ -351,7 +351,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::every)
|
|||
// 23.1.3.7 Array.prototype.fill ( value [ , start [ , end ] ] ), https://tc39.es/ecma262/#sec-array.prototype.fill
|
||||
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::fill)
|
||||
{
|
||||
auto* this_object = TRY(vm.this_value().to_object(global_object));
|
||||
auto* this_object = TRY(vm.this_value().to_object(vm));
|
||||
|
||||
auto length = TRY(length_of_array_like(global_object, *this_object));
|
||||
|
||||
|
@ -359,14 +359,14 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::fill)
|
|||
double relative_end = length;
|
||||
|
||||
if (vm.argument_count() >= 2) {
|
||||
relative_start = TRY(vm.argument(1).to_integer_or_infinity(global_object));
|
||||
relative_start = TRY(vm.argument(1).to_integer_or_infinity(vm));
|
||||
if (Value(relative_start).is_negative_infinity())
|
||||
relative_start = 0;
|
||||
}
|
||||
|
||||
// If end is undefined, let relativeEnd be len; else let relativeEnd be ? ToIntegerOrInfinity(end).
|
||||
if (vm.argument_count() >= 3 && !vm.argument(2).is_undefined()) {
|
||||
relative_end = TRY(vm.argument(2).to_integer_or_infinity(global_object));
|
||||
relative_end = TRY(vm.argument(2).to_integer_or_infinity(vm));
|
||||
if (Value(relative_end).is_negative_infinity())
|
||||
relative_end = 0;
|
||||
}
|
||||
|
@ -396,7 +396,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::filter)
|
|||
auto this_arg = vm.argument(1);
|
||||
|
||||
// 1. Let O be ? ToObject(this value).
|
||||
auto* object = TRY(vm.this_value().to_object(global_object));
|
||||
auto* object = TRY(vm.this_value().to_object(vm));
|
||||
|
||||
// 2. Let len be ? LengthOfArrayLike(O).
|
||||
auto length = TRY(length_of_array_like(global_object, *object));
|
||||
|
@ -454,7 +454,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::find)
|
|||
auto this_arg = vm.argument(1);
|
||||
|
||||
// 1. Let O be ? ToObject(this value).
|
||||
auto* object = TRY(vm.this_value().to_object(global_object));
|
||||
auto* object = TRY(vm.this_value().to_object(vm));
|
||||
|
||||
// 2. Let len be ? LengthOfArrayLike(O).
|
||||
auto length = TRY(length_of_array_like(global_object, *object));
|
||||
|
@ -493,7 +493,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::find_index)
|
|||
auto this_arg = vm.argument(1);
|
||||
|
||||
// 1. Let O be ? ToObject(this value).
|
||||
auto* object = TRY(vm.this_value().to_object(global_object));
|
||||
auto* object = TRY(vm.this_value().to_object(vm));
|
||||
|
||||
// 2. Let len be ? LengthOfArrayLike(O).
|
||||
auto length = TRY(length_of_array_like(global_object, *object));
|
||||
|
@ -532,7 +532,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::find_last)
|
|||
auto this_arg = vm.argument(1);
|
||||
|
||||
// 1. Let O be ? ToObject(this value).
|
||||
auto* object = TRY(vm.this_value().to_object(global_object));
|
||||
auto* object = TRY(vm.this_value().to_object(vm));
|
||||
|
||||
// 2. Let len be ? LengthOfArrayLike(O).
|
||||
auto length = TRY(length_of_array_like(global_object, *object));
|
||||
|
@ -571,7 +571,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::find_last_index)
|
|||
auto this_arg = vm.argument(1);
|
||||
|
||||
// 1. Let O be ? ToObject(this value).
|
||||
auto* object = TRY(vm.this_value().to_object(global_object));
|
||||
auto* object = TRY(vm.this_value().to_object(vm));
|
||||
|
||||
// 2. Let len be ? LengthOfArrayLike(O).
|
||||
auto length = TRY(length_of_array_like(global_object, *object));
|
||||
|
@ -619,7 +619,7 @@ static ThrowCompletionOr<size_t> flatten_into_array(GlobalObject& global_object,
|
|||
if (mapper_func)
|
||||
value = TRY(call(global_object, *mapper_func, this_arg, value, Value(j), &array));
|
||||
|
||||
if (depth > 0 && TRY(value.is_array(global_object))) {
|
||||
if (depth > 0 && TRY(value.is_array(vm))) {
|
||||
if (vm.did_reach_stack_space_limit())
|
||||
return vm.throw_completion<InternalError>(ErrorType::CallStackSizeExceeded);
|
||||
|
||||
|
@ -641,13 +641,13 @@ static ThrowCompletionOr<size_t> flatten_into_array(GlobalObject& global_object,
|
|||
// 23.1.3.13 Array.prototype.flat ( [ depth ] ), https://tc39.es/ecma262/#sec-array.prototype.flat
|
||||
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::flat)
|
||||
{
|
||||
auto* this_object = TRY(vm.this_value().to_object(global_object));
|
||||
auto* this_object = TRY(vm.this_value().to_object(vm));
|
||||
|
||||
auto length = TRY(length_of_array_like(global_object, *this_object));
|
||||
|
||||
double depth = 1;
|
||||
if (!vm.argument(0).is_undefined()) {
|
||||
auto depth_num = TRY(vm.argument(0).to_integer_or_infinity(global_object));
|
||||
auto depth_num = TRY(vm.argument(0).to_integer_or_infinity(vm));
|
||||
depth = max(depth_num, 0.0);
|
||||
}
|
||||
|
||||
|
@ -664,7 +664,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::flat_map)
|
|||
auto this_arg = vm.argument(1);
|
||||
|
||||
// 1. Let O be ? ToObject(this value).
|
||||
auto* object = TRY(vm.this_value().to_object(global_object));
|
||||
auto* object = TRY(vm.this_value().to_object(vm));
|
||||
|
||||
// 2. Let sourceLen be ? LengthOfArrayLike(O).
|
||||
auto source_length = TRY(length_of_array_like(global_object, *object));
|
||||
|
@ -690,7 +690,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::for_each)
|
|||
auto this_arg = vm.argument(1);
|
||||
|
||||
// 1. Let O be ? ToObject(this value).
|
||||
auto* object = TRY(vm.this_value().to_object(global_object));
|
||||
auto* object = TRY(vm.this_value().to_object(vm));
|
||||
|
||||
// 2. Let len be ? LengthOfArrayLike(O).
|
||||
auto length = TRY(length_of_array_like(global_object, *object));
|
||||
|
@ -761,7 +761,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::group)
|
|||
auto this_arg = vm.argument(1);
|
||||
|
||||
// 1. Let O be ? ToObject(this value).
|
||||
auto* this_object = TRY(vm.this_value().to_object(global_object));
|
||||
auto* this_object = TRY(vm.this_value().to_object(vm));
|
||||
|
||||
// 2. Let len be ? LengthOfArrayLike(O).
|
||||
auto length = TRY(length_of_array_like(global_object, *this_object));
|
||||
|
@ -784,7 +784,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::group)
|
|||
|
||||
// c. Let propertyKey be ? ToPropertyKey(? Call(callbackfn, thisArg, « kValue, 𝔽(k), O »)).
|
||||
auto property_key_value = TRY(call(global_object, callback_function.as_function(), this_arg, k_value, Value(index), this_object));
|
||||
auto property_key = TRY(property_key_value.to_property_key(global_object));
|
||||
auto property_key = TRY(property_key_value.to_property_key(vm));
|
||||
|
||||
// d. Perform AddValueToKeyedGroup(groups, propertyKey, kValue).
|
||||
add_value_to_keyed_group(global_object, groups, property_key, k_value);
|
||||
|
@ -817,7 +817,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::group_to_map)
|
|||
auto this_arg = vm.argument(1);
|
||||
|
||||
// 1. Let O be ? ToObject(this value).
|
||||
auto* this_object = TRY(vm.this_value().to_object(global_object));
|
||||
auto* this_object = TRY(vm.this_value().to_object(vm));
|
||||
|
||||
// 2. Let len be ? LengthOfArrayLike(O).
|
||||
auto length = TRY(length_of_array_like(global_object, *this_object));
|
||||
|
@ -884,13 +884,13 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::group_to_map)
|
|||
// 23.1.3.16 Array.prototype.includes ( searchElement [ , fromIndex ] ), https://tc39.es/ecma262/#sec-array.prototype.includes
|
||||
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::includes)
|
||||
{
|
||||
auto* this_object = TRY(vm.this_value().to_object(global_object));
|
||||
auto* this_object = TRY(vm.this_value().to_object(vm));
|
||||
auto length = TRY(length_of_array_like(global_object, *this_object));
|
||||
if (length == 0)
|
||||
return Value(false);
|
||||
u64 from_index = 0;
|
||||
if (vm.argument_count() >= 2) {
|
||||
auto from_argument = TRY(vm.argument(1).to_integer_or_infinity(global_object));
|
||||
auto from_argument = TRY(vm.argument(1).to_integer_or_infinity(vm));
|
||||
|
||||
if (Value(from_argument).is_positive_infinity() || from_argument >= length)
|
||||
return Value(false);
|
||||
|
@ -919,7 +919,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::index_of)
|
|||
auto from_index = vm.argument(1);
|
||||
|
||||
// 1. Let O be ? ToObject(this value).
|
||||
auto* object = TRY(vm.this_value().to_object(global_object));
|
||||
auto* object = TRY(vm.this_value().to_object(vm));
|
||||
|
||||
// 2. Let len be ? LengthOfArrayLike(O).
|
||||
auto length = TRY(length_of_array_like(global_object, *object));
|
||||
|
@ -929,7 +929,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::index_of)
|
|||
return Value(-1);
|
||||
|
||||
// 4. Let n be ? ToIntegerOrInfinity(fromIndex).
|
||||
auto n = TRY(from_index.to_integer_or_infinity(global_object));
|
||||
auto n = TRY(from_index.to_integer_or_infinity(vm));
|
||||
|
||||
// 5. Assert: If fromIndex is undefined, then n is 0.
|
||||
if (from_index.is_undefined())
|
||||
|
@ -987,7 +987,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::index_of)
|
|||
// 23.1.3.18 Array.prototype.join ( separator ), https://tc39.es/ecma262/#sec-array.prototype.join
|
||||
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::join)
|
||||
{
|
||||
auto* this_object = TRY(vm.this_value().to_object(global_object));
|
||||
auto* this_object = TRY(vm.this_value().to_object(vm));
|
||||
|
||||
// This is not part of the spec, but all major engines do some kind of circular reference checks.
|
||||
// FWIW: engine262, a "100% spec compliant" ECMA-262 impl, aborts with "too much recursion".
|
||||
|
@ -1002,7 +1002,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::join)
|
|||
auto length = TRY(length_of_array_like(global_object, *this_object));
|
||||
String separator = ",";
|
||||
if (!vm.argument(0).is_undefined())
|
||||
separator = TRY(vm.argument(0).to_string(global_object));
|
||||
separator = TRY(vm.argument(0).to_string(vm));
|
||||
StringBuilder builder;
|
||||
for (size_t i = 0; i < length; ++i) {
|
||||
if (i > 0)
|
||||
|
@ -1010,7 +1010,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::join)
|
|||
auto value = TRY(this_object->get(i));
|
||||
if (value.is_nullish())
|
||||
continue;
|
||||
auto string = TRY(value.to_string(global_object));
|
||||
auto string = TRY(value.to_string(vm));
|
||||
builder.append(string);
|
||||
}
|
||||
|
||||
|
@ -1022,7 +1022,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::keys)
|
|||
{
|
||||
auto& realm = *global_object.associated_realm();
|
||||
|
||||
auto* this_object = TRY(vm.this_value().to_object(global_object));
|
||||
auto* this_object = TRY(vm.this_value().to_object(vm));
|
||||
|
||||
return ArrayIterator::create(realm, this_object, Object::PropertyKind::Key);
|
||||
}
|
||||
|
@ -1034,7 +1034,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::last_index_of)
|
|||
auto from_index = vm.argument(1);
|
||||
|
||||
// 1. Let O be ? ToObject(this value).
|
||||
auto* object = TRY(vm.this_value().to_object(global_object));
|
||||
auto* object = TRY(vm.this_value().to_object(vm));
|
||||
|
||||
// 2. Let len be ? LengthOfArrayLike(O).
|
||||
auto length = TRY(length_of_array_like(global_object, *object));
|
||||
|
@ -1047,7 +1047,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::last_index_of)
|
|||
|
||||
// 4. If fromIndex is present, let n be ? ToIntegerOrInfinity(fromIndex); else let n be len - 1.
|
||||
if (vm.argument_count() >= 2)
|
||||
n = TRY(from_index.to_integer_or_infinity(global_object));
|
||||
n = TRY(from_index.to_integer_or_infinity(vm));
|
||||
else
|
||||
n = (double)length - 1;
|
||||
|
||||
|
@ -1102,7 +1102,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::map)
|
|||
auto this_arg = vm.argument(1);
|
||||
|
||||
// 1. Let O be ? ToObject(this value).
|
||||
auto* object = TRY(vm.this_value().to_object(global_object));
|
||||
auto* object = TRY(vm.this_value().to_object(vm));
|
||||
|
||||
// 2. Let len be ? LengthOfArrayLike(O).
|
||||
auto length = TRY(length_of_array_like(global_object, *object));
|
||||
|
@ -1145,7 +1145,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::map)
|
|||
// 23.1.3.22 Array.prototype.pop ( ), https://tc39.es/ecma262/#sec-array.prototype.pop
|
||||
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::pop)
|
||||
{
|
||||
auto* this_object = TRY(vm.this_value().to_object(global_object));
|
||||
auto* this_object = TRY(vm.this_value().to_object(vm));
|
||||
auto length = TRY(length_of_array_like(global_object, *this_object));
|
||||
if (length == 0) {
|
||||
TRY(this_object->set(vm.names.length, Value(0), Object::ShouldThrowExceptions::Yes));
|
||||
|
@ -1161,7 +1161,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::pop)
|
|||
// 23.1.3.23 Array.prototype.push ( ...items ), https://tc39.es/ecma262/#sec-array.prototype.push
|
||||
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::push)
|
||||
{
|
||||
auto* this_object = TRY(vm.this_value().to_object(global_object));
|
||||
auto* this_object = TRY(vm.this_value().to_object(vm));
|
||||
auto length = TRY(length_of_array_like(global_object, *this_object));
|
||||
auto argument_count = vm.argument_count();
|
||||
auto new_length = length + argument_count;
|
||||
|
@ -1181,7 +1181,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::reduce)
|
|||
auto initial_value = vm.argument(1);
|
||||
|
||||
// 1. Let O be ? ToObject(this value).
|
||||
auto* object = TRY(vm.this_value().to_object(global_object));
|
||||
auto* object = TRY(vm.this_value().to_object(vm));
|
||||
|
||||
// 2. Let len be ? LengthOfArrayLike(O).
|
||||
auto length = TRY(length_of_array_like(global_object, *object));
|
||||
|
@ -1263,7 +1263,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::reduce_right)
|
|||
auto initial_value = vm.argument(1);
|
||||
|
||||
// 1. Let O be ? ToObject(this value).
|
||||
auto* object = TRY(vm.this_value().to_object(global_object));
|
||||
auto* object = TRY(vm.this_value().to_object(vm));
|
||||
|
||||
// 2. Let len be ? LengthOfArrayLike(O).
|
||||
auto length = TRY(length_of_array_like(global_object, *object));
|
||||
|
@ -1341,7 +1341,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::reduce_right)
|
|||
// 23.1.3.26 Array.prototype.reverse ( ), https://tc39.es/ecma262/#sec-array.prototype.reverse
|
||||
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::reverse)
|
||||
{
|
||||
auto* this_object = TRY(vm.this_value().to_object(global_object));
|
||||
auto* this_object = TRY(vm.this_value().to_object(vm));
|
||||
auto length = TRY(length_of_array_like(global_object, *this_object));
|
||||
|
||||
auto middle = length / 2;
|
||||
|
@ -1376,7 +1376,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::reverse)
|
|||
// 23.1.3.27 Array.prototype.shift ( ), https://tc39.es/ecma262/#sec-array.prototype.shift
|
||||
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::shift)
|
||||
{
|
||||
auto* this_object = TRY(vm.this_value().to_object(global_object));
|
||||
auto* this_object = TRY(vm.this_value().to_object(vm));
|
||||
auto length = TRY(length_of_array_like(global_object, *this_object));
|
||||
if (length == 0) {
|
||||
TRY(this_object->set(vm.names.length, Value(0), Object::ShouldThrowExceptions::Yes));
|
||||
|
@ -1403,11 +1403,11 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::shift)
|
|||
// 23.1.3.28 Array.prototype.slice ( start, end ), https://tc39.es/ecma262/#sec-array.prototype.slice
|
||||
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::slice)
|
||||
{
|
||||
auto* this_object = TRY(vm.this_value().to_object(global_object));
|
||||
auto* this_object = TRY(vm.this_value().to_object(vm));
|
||||
|
||||
auto initial_length = TRY(length_of_array_like(global_object, *this_object));
|
||||
|
||||
auto relative_start = TRY(vm.argument(0).to_integer_or_infinity(global_object));
|
||||
auto relative_start = TRY(vm.argument(0).to_integer_or_infinity(vm));
|
||||
|
||||
double actual_start;
|
||||
|
||||
|
@ -1423,7 +1423,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::slice)
|
|||
if (vm.argument(1).is_undefined() || vm.argument(1).is_empty())
|
||||
relative_end = (double)initial_length;
|
||||
else
|
||||
relative_end = TRY(vm.argument(1).to_integer_or_infinity(global_object));
|
||||
relative_end = TRY(vm.argument(1).to_integer_or_infinity(vm));
|
||||
|
||||
double final;
|
||||
|
||||
|
@ -1463,7 +1463,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::some)
|
|||
auto this_arg = vm.argument(1);
|
||||
|
||||
// 1. Let O be ? ToObject(this value).
|
||||
auto* object = TRY(vm.this_value().to_object(global_object));
|
||||
auto* object = TRY(vm.this_value().to_object(vm));
|
||||
|
||||
// 2. Let len be ? LengthOfArrayLike(O).
|
||||
auto length = TRY(length_of_array_like(global_object, *object));
|
||||
|
@ -1569,7 +1569,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::sort)
|
|||
return vm.throw_completion<TypeError>(ErrorType::NotAFunction, comparefn.to_string_without_side_effects());
|
||||
|
||||
// 2. Let obj be ? ToObject(this value).
|
||||
auto* object = TRY(vm.this_value().to_object(global_object));
|
||||
auto* object = TRY(vm.this_value().to_object(vm));
|
||||
|
||||
// 3. Let len be ? LengthOfArrayLike(obj).
|
||||
auto length = TRY(length_of_array_like(global_object, *object));
|
||||
|
@ -1611,11 +1611,11 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::sort)
|
|||
// 23.1.3.31 Array.prototype.splice ( start, deleteCount, ...items ), https://tc39.es/ecma262/#sec-array.prototype.splice
|
||||
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::splice)
|
||||
{
|
||||
auto* this_object = TRY(vm.this_value().to_object(global_object));
|
||||
auto* this_object = TRY(vm.this_value().to_object(vm));
|
||||
|
||||
auto initial_length = TRY(length_of_array_like(global_object, *this_object));
|
||||
|
||||
auto relative_start = TRY(vm.argument(0).to_integer_or_infinity(global_object));
|
||||
auto relative_start = TRY(vm.argument(0).to_integer_or_infinity(vm));
|
||||
|
||||
if (Value(relative_start).is_negative_infinity())
|
||||
relative_start = 0;
|
||||
|
@ -1634,7 +1634,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::splice)
|
|||
actual_delete_count = initial_length - actual_start;
|
||||
} else if (vm.argument_count() >= 2) {
|
||||
insert_count = vm.argument_count() - 2;
|
||||
auto delete_count = TRY(vm.argument(1).to_integer_or_infinity(global_object));
|
||||
auto delete_count = TRY(vm.argument(1).to_integer_or_infinity(vm));
|
||||
auto temp = max(delete_count, 0);
|
||||
actual_delete_count = min(temp, initial_length - actual_start);
|
||||
}
|
||||
|
@ -1703,7 +1703,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::to_locale_string)
|
|||
auto options = vm.argument(1);
|
||||
|
||||
// 1. Let array be ? ToObject(this value).
|
||||
auto* this_object = TRY(vm.this_value().to_object(global_object));
|
||||
auto* this_object = TRY(vm.this_value().to_object(vm));
|
||||
|
||||
if (s_array_join_seen_objects.contains(this_object))
|
||||
return js_string(vm, "");
|
||||
|
@ -1736,10 +1736,10 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::to_locale_string)
|
|||
// c. If nextElement is not undefined or null, then
|
||||
if (!value.is_nullish()) {
|
||||
// i. Let S be ? ToString(? Invoke(nextElement, "toLocaleString", « locales, options »)).
|
||||
auto locale_string_result = TRY(value.invoke(global_object, vm.names.toLocaleString, locales, options));
|
||||
auto locale_string_result = TRY(value.invoke(vm, vm.names.toLocaleString, locales, options));
|
||||
|
||||
// ii. Set R to the string-concatenation of R and S.
|
||||
auto string = TRY(locale_string_result.to_string(global_object));
|
||||
auto string = TRY(locale_string_result.to_string(vm));
|
||||
builder.append(string);
|
||||
}
|
||||
|
||||
|
@ -1756,7 +1756,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::to_reversed)
|
|||
auto& realm = *global_object.associated_realm();
|
||||
|
||||
// 1. Let O be ? ToObject(this value).
|
||||
auto* object = TRY(vm.this_value().to_object(global_object));
|
||||
auto* object = TRY(vm.this_value().to_object(vm));
|
||||
|
||||
// 2. Let len be ? LengthOfArrayLike(O).
|
||||
auto length = TRY(length_of_array_like(global_object, *object));
|
||||
|
@ -1798,7 +1798,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::to_sorted)
|
|||
return vm.throw_completion<TypeError>(ErrorType::NotAFunction, comparefn);
|
||||
|
||||
// 2. Let O be ? ToObject(this value).
|
||||
auto* object = TRY(vm.this_value().to_object(global_object));
|
||||
auto* object = TRY(vm.this_value().to_object(vm));
|
||||
|
||||
// 3. Let len be ? LengthOfArrayLike(O).
|
||||
auto length = TRY(length_of_array_like(global_object, *object));
|
||||
|
@ -1837,13 +1837,13 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::to_spliced)
|
|||
auto delete_count = vm.argument(1);
|
||||
|
||||
// 1. Let O be ? ToObject(this value).
|
||||
auto* object = TRY(vm.this_value().to_object(global_object));
|
||||
auto* object = TRY(vm.this_value().to_object(vm));
|
||||
|
||||
// 2. Let len be ? LengthOfArrayLike(O).
|
||||
auto length = TRY(length_of_array_like(global_object, *object));
|
||||
|
||||
// 3. Let relativeStart be ? ToIntegerOrInfinity(start).
|
||||
auto relative_start = TRY(start.to_integer_or_infinity(global_object));
|
||||
auto relative_start = TRY(start.to_integer_or_infinity(vm));
|
||||
|
||||
size_t actual_start;
|
||||
|
||||
|
@ -1878,7 +1878,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::to_spliced)
|
|||
// 10. Else,
|
||||
else {
|
||||
// a. Let dc be ? ToIntegerOrInfinity(deleteCount).
|
||||
auto dc = TRY(delete_count.to_integer_or_infinity(global_object));
|
||||
auto dc = TRY(delete_count.to_integer_or_infinity(vm));
|
||||
|
||||
// b. Let actualDeleteCount be the result of clamping dc between 0 and len - actualStart.
|
||||
actual_delete_count = static_cast<size_t>(clamp(dc, 0, static_cast<double>(length - actual_start)));
|
||||
|
@ -1963,7 +1963,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::to_spliced)
|
|||
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::to_string)
|
||||
{
|
||||
// 1. Let array be ? ToObject(this value).
|
||||
auto* array = TRY(vm.this_value().to_object(global_object));
|
||||
auto* array = TRY(vm.this_value().to_object(vm));
|
||||
|
||||
// 2. Let func be ? Get(array, "join").
|
||||
auto func = TRY(array->get(vm.names.join));
|
||||
|
@ -1979,7 +1979,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::to_string)
|
|||
// 23.1.3.34 Array.prototype.unshift ( ...items ), https://tc39.es/ecma262/#sec-array.prototype.unshift
|
||||
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::unshift)
|
||||
{
|
||||
auto* this_object = TRY(vm.this_value().to_object(global_object));
|
||||
auto* this_object = TRY(vm.this_value().to_object(vm));
|
||||
auto length = TRY(length_of_array_like(global_object, *this_object));
|
||||
auto arg_count = vm.argument_count();
|
||||
size_t new_length = length + arg_count;
|
||||
|
@ -2013,7 +2013,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::values)
|
|||
{
|
||||
auto& realm = *global_object.associated_realm();
|
||||
|
||||
auto* this_object = TRY(vm.this_value().to_object(global_object));
|
||||
auto* this_object = TRY(vm.this_value().to_object(vm));
|
||||
|
||||
return ArrayIterator::create(realm, this_object, Object::PropertyKind::Value);
|
||||
}
|
||||
|
@ -2027,13 +2027,13 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::with)
|
|||
auto value = vm.argument(1);
|
||||
|
||||
// 1. Let O be ? ToObject(this value).
|
||||
auto* object = TRY(vm.this_value().to_object(global_object));
|
||||
auto* object = TRY(vm.this_value().to_object(vm));
|
||||
|
||||
// 2. Let len be ? LengthOfArrayLike(O).
|
||||
auto length = TRY(length_of_array_like(global_object, *object));
|
||||
|
||||
// 3. Let relativeIndex be ? ToIntegerOrInfinity(index).
|
||||
auto relative_index = TRY(index.to_integer_or_infinity(global_object));
|
||||
auto relative_index = TRY(index.to_integer_or_infinity(vm));
|
||||
|
||||
double actual_index;
|
||||
|
||||
|
|
|
@ -108,7 +108,7 @@ JS_DEFINE_NATIVE_FUNCTION(AsyncFromSyncIteratorPrototype::return_)
|
|||
|
||||
// 5. Let return be Completion(GetMethod(syncIterator, "return")).
|
||||
// 6. IfAbruptRejectPromise(return, promiseCapability).
|
||||
auto* return_method = TRY_OR_REJECT(global_object, promise_capability, Value(sync_iterator).get_method(global_object, vm.names.return_));
|
||||
auto* return_method = TRY_OR_REJECT(global_object, promise_capability, Value(sync_iterator).get_method(vm, vm.names.return_));
|
||||
|
||||
// 7. If return is undefined, then
|
||||
if (return_method == nullptr) {
|
||||
|
@ -161,7 +161,7 @@ JS_DEFINE_NATIVE_FUNCTION(AsyncFromSyncIteratorPrototype::throw_)
|
|||
|
||||
// 5. Let throw be Completion(GetMethod(syncIterator, "throw")).
|
||||
// 6. IfAbruptRejectPromise(throw, promiseCapability).
|
||||
auto* throw_method = TRY_OR_REJECT(global_object, promise_capability, Value(sync_iterator).get_method(global_object, vm.names.throw_));
|
||||
auto* throw_method = TRY_OR_REJECT(global_object, promise_capability, Value(sync_iterator).get_method(vm, vm.names.throw_));
|
||||
|
||||
// 7. If throw is undefined, then
|
||||
if (throw_method == nullptr) {
|
||||
|
|
|
@ -48,7 +48,7 @@ ThrowCompletionOr<Value> AsyncFunctionDriverWrapper::react_to_async_task_complet
|
|||
auto result = generator_result.release_value();
|
||||
VERIFY(result.is_object());
|
||||
|
||||
auto promise_value = TRY(result.get(global_object, vm.names.value));
|
||||
auto promise_value = TRY(result.get(vm, vm.names.value));
|
||||
if (!promise_value.is_object() || !is<Promise>(promise_value.as_object())) {
|
||||
auto promise = Promise::create(realm);
|
||||
promise->fulfill(promise_value);
|
||||
|
@ -56,7 +56,7 @@ ThrowCompletionOr<Value> AsyncFunctionDriverWrapper::react_to_async_task_complet
|
|||
}
|
||||
|
||||
auto* promise = static_cast<Promise*>(&promise_value.as_object());
|
||||
if (TRY(result.get(global_object, vm.names.done)).to_boolean())
|
||||
if (TRY(result.get(vm, vm.names.done)).to_boolean())
|
||||
return promise;
|
||||
|
||||
return promise->perform_then(m_on_fulfillment, m_on_rejection, PromiseCapability { promise, m_on_fulfillment, m_on_rejection });
|
||||
|
|
|
@ -56,7 +56,7 @@ static ThrowCompletionOr<size_t> validate_atomic_access(GlobalObject& global_obj
|
|||
auto length = typed_array.array_length();
|
||||
|
||||
// 2. Let accessIndex be ? ToIndex(requestIndex).
|
||||
auto access_index = TRY(request_index.to_index(global_object));
|
||||
auto access_index = TRY(request_index.to_index(vm));
|
||||
|
||||
// 3. Assert: accessIndex ≥ 0.
|
||||
|
||||
|
@ -89,10 +89,10 @@ static ThrowCompletionOr<Value> atomic_read_modify_write(GlobalObject& global_ob
|
|||
|
||||
// 3. If typedArray.[[ContentType]] is BigInt, let v be ? ToBigInt(value).
|
||||
if (typed_array.content_type() == TypedArrayBase::ContentType::BigInt)
|
||||
value_to_set = TRY(value.to_bigint(global_object));
|
||||
value_to_set = TRY(value.to_bigint(vm));
|
||||
// 4. Otherwise, let v be 𝔽(? ToIntegerOrInfinity(value)).
|
||||
else
|
||||
value_to_set = Value(TRY(value.to_integer_or_infinity(global_object)));
|
||||
value_to_set = Value(TRY(value.to_integer_or_infinity(vm)));
|
||||
|
||||
// 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
|
||||
if (buffer->is_detached())
|
||||
|
@ -208,18 +208,18 @@ static ThrowCompletionOr<Value> atomic_compare_exchange_impl(GlobalObject& globa
|
|||
// 4. If typedArray.[[ContentType]] is BigInt, then
|
||||
if (typed_array.content_type() == TypedArrayBase::ContentType::BigInt) {
|
||||
// a. Let expected be ? ToBigInt(expectedValue).
|
||||
expected = TRY(vm.argument(2).to_bigint(global_object));
|
||||
expected = TRY(vm.argument(2).to_bigint(vm));
|
||||
|
||||
// b. Let replacement be ? ToBigInt(replacementValue).
|
||||
replacement = TRY(vm.argument(3).to_bigint(global_object));
|
||||
replacement = TRY(vm.argument(3).to_bigint(vm));
|
||||
}
|
||||
// 5. Else,
|
||||
else {
|
||||
// a. Let expected be 𝔽(? ToIntegerOrInfinity(expectedValue)).
|
||||
expected = Value(TRY(vm.argument(2).to_integer_or_infinity(global_object)));
|
||||
expected = Value(TRY(vm.argument(2).to_integer_or_infinity(vm)));
|
||||
|
||||
// b. Let replacement be 𝔽(? ToIntegerOrInfinity(replacementValue)).
|
||||
replacement = Value(TRY(vm.argument(3).to_integer_or_infinity(global_object)));
|
||||
replacement = Value(TRY(vm.argument(3).to_integer_or_infinity(vm)));
|
||||
}
|
||||
|
||||
// 6. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
|
||||
|
@ -299,7 +299,7 @@ JS_DEFINE_NATIVE_FUNCTION(AtomicsObject::exchange)
|
|||
// 25.4.7 Atomics.isLockFree ( size ), https://tc39.es/ecma262/#sec-atomics.islockfree
|
||||
JS_DEFINE_NATIVE_FUNCTION(AtomicsObject::is_lock_free)
|
||||
{
|
||||
auto size = TRY(vm.argument(0).to_integer_or_infinity(global_object));
|
||||
auto size = TRY(vm.argument(0).to_integer_or_infinity(vm));
|
||||
if (size == 1)
|
||||
return Value(AK::atomic_is_lock_free<u8>());
|
||||
if (size == 2)
|
||||
|
@ -363,10 +363,10 @@ JS_DEFINE_NATIVE_FUNCTION(AtomicsObject::store)
|
|||
|
||||
// 3. If typedArray.[[ContentType]] is BigInt, let v be ? ToBigInt(value).
|
||||
if (typed_array->content_type() == TypedArrayBase::ContentType::BigInt)
|
||||
value_to_set = TRY(value.to_bigint(global_object));
|
||||
value_to_set = TRY(value.to_bigint(vm));
|
||||
// 4. Otherwise, let v be 𝔽(? ToIntegerOrInfinity(value)).
|
||||
else
|
||||
value_to_set = Value(TRY(value.to_integer_or_infinity(global_object)));
|
||||
value_to_set = Value(TRY(value.to_integer_or_infinity(vm)));
|
||||
|
||||
// 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
|
||||
if (typed_array->viewed_array_buffer()->is_detached())
|
||||
|
|
|
@ -46,14 +46,14 @@ ThrowCompletionOr<Value> BigIntConstructor::call()
|
|||
auto value = vm.argument(0);
|
||||
|
||||
// 2. Let prim be ? ToPrimitive(value, number).
|
||||
auto primitive = TRY(value.to_primitive(global_object, Value::PreferredType::Number));
|
||||
auto primitive = TRY(value.to_primitive(vm, Value::PreferredType::Number));
|
||||
|
||||
// 3. If Type(prim) is Number, return ? NumberToBigInt(prim).
|
||||
if (primitive.is_number())
|
||||
return TRY(number_to_bigint(global_object, primitive));
|
||||
|
||||
// 4. Otherwise, return ? ToBigInt(prim).
|
||||
return TRY(primitive.to_bigint(global_object));
|
||||
return TRY(primitive.to_bigint(vm));
|
||||
}
|
||||
|
||||
// 21.2.1.1 BigInt ( value ), https://tc39.es/ecma262/#sec-bigint-constructor-number-value
|
||||
|
@ -66,10 +66,10 @@ ThrowCompletionOr<Object*> BigIntConstructor::construct(FunctionObject&)
|
|||
JS_DEFINE_NATIVE_FUNCTION(BigIntConstructor::as_int_n)
|
||||
{
|
||||
// 1. Set bits to ? ToIndex(bits).
|
||||
auto bits = TRY(vm.argument(0).to_index(global_object));
|
||||
auto bits = TRY(vm.argument(0).to_index(vm));
|
||||
|
||||
// 2. Set bigint to ? ToBigInt(bigint).
|
||||
auto* bigint = TRY(vm.argument(1).to_bigint(global_object));
|
||||
auto* bigint = TRY(vm.argument(1).to_bigint(vm));
|
||||
|
||||
// 3. Let mod be ℝ(bigint) modulo 2^bits.
|
||||
// FIXME: For large values of `bits`, this can likely be improved with a SignedBigInteger API to
|
||||
|
@ -92,10 +92,10 @@ JS_DEFINE_NATIVE_FUNCTION(BigIntConstructor::as_int_n)
|
|||
JS_DEFINE_NATIVE_FUNCTION(BigIntConstructor::as_uint_n)
|
||||
{
|
||||
// 1. Set bits to ? ToIndex(bits).
|
||||
auto bits = TRY(vm.argument(0).to_index(global_object));
|
||||
auto bits = TRY(vm.argument(0).to_index(vm));
|
||||
|
||||
// 2. Set bigint to ? ToBigInt(bigint).
|
||||
auto* bigint = TRY(vm.argument(1).to_bigint(global_object));
|
||||
auto* bigint = TRY(vm.argument(1).to_bigint(vm));
|
||||
|
||||
// 3. Return the BigInt value that represents ℝ(bigint) modulo 2bits.
|
||||
// FIXME: For large values of `bits`, this can likely be improved with a SignedBigInteger API to
|
||||
|
|
|
@ -52,7 +52,7 @@ JS_DEFINE_NATIVE_FUNCTION(BigIntPrototype::to_string)
|
|||
auto* bigint = TRY(this_bigint_value(global_object, vm.this_value()));
|
||||
double radix = 10;
|
||||
if (!vm.argument(0).is_undefined()) {
|
||||
radix = TRY(vm.argument(0).to_integer_or_infinity(global_object));
|
||||
radix = TRY(vm.argument(0).to_integer_or_infinity(vm));
|
||||
if (radix < 2 || radix > 36)
|
||||
return vm.throw_completion<RangeError>(ErrorType::InvalidRadix);
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ ThrowCompletionOr<Object*> DataViewConstructor::construct(FunctionObject& new_ta
|
|||
|
||||
auto& array_buffer = static_cast<ArrayBuffer&>(buffer.as_object());
|
||||
|
||||
auto offset = TRY(vm.argument(1).to_index(global_object));
|
||||
auto offset = TRY(vm.argument(1).to_index(vm));
|
||||
|
||||
if (array_buffer.is_detached())
|
||||
return vm.throw_completion<TypeError>(ErrorType::DetachedArrayBuffer);
|
||||
|
@ -61,7 +61,7 @@ ThrowCompletionOr<Object*> DataViewConstructor::construct(FunctionObject& new_ta
|
|||
if (vm.argument(2).is_undefined()) {
|
||||
view_byte_length = buffer_byte_length - offset;
|
||||
} else {
|
||||
view_byte_length = TRY(vm.argument(2).to_index(global_object));
|
||||
view_byte_length = TRY(vm.argument(2).to_index(vm));
|
||||
auto const checked_add = AK::make_checked(view_byte_length) + AK::make_checked(offset);
|
||||
if (checked_add.has_overflow() || checked_add.value() > buffer_byte_length)
|
||||
return vm.throw_completion<RangeError>(ErrorType::InvalidLength, vm.names.DataView);
|
||||
|
|
|
@ -56,7 +56,7 @@ static ThrowCompletionOr<Value> get_view_value(GlobalObject& global_object, Valu
|
|||
{
|
||||
auto& vm = global_object.vm();
|
||||
auto* view = TRY(DataViewPrototype::typed_this_value(vm));
|
||||
auto get_index = TRY(request_index.to_index(global_object));
|
||||
auto get_index = TRY(request_index.to_index(vm));
|
||||
auto little_endian = is_little_endian.to_boolean();
|
||||
|
||||
auto buffer = view->viewed_array_buffer();
|
||||
|
@ -86,13 +86,13 @@ static ThrowCompletionOr<Value> set_view_value(GlobalObject& global_object, Valu
|
|||
{
|
||||
auto& vm = global_object.vm();
|
||||
auto* view = TRY(DataViewPrototype::typed_this_value(vm));
|
||||
auto get_index = TRY(request_index.to_index(global_object));
|
||||
auto get_index = TRY(request_index.to_index(vm));
|
||||
|
||||
Value number_value;
|
||||
if constexpr (IsIntegral<T> && sizeof(T) == 8)
|
||||
number_value = TRY(value.to_bigint(global_object));
|
||||
number_value = TRY(value.to_bigint(vm));
|
||||
else
|
||||
number_value = TRY(value.to_number(global_object));
|
||||
number_value = TRY(value.to_number(vm));
|
||||
|
||||
auto little_endian = is_little_endian.to_boolean();
|
||||
|
||||
|
|
|
@ -223,7 +223,7 @@ ThrowCompletionOr<Object*> DateConstructor::construct(FunctionObject& new_target
|
|||
// c. Else,
|
||||
else {
|
||||
// i. Let v be ? ToPrimitive(value).
|
||||
auto primitive = TRY(value.to_primitive(global_object));
|
||||
auto primitive = TRY(value.to_primitive(vm));
|
||||
|
||||
// ii. If Type(v) is String, then
|
||||
if (primitive.is_string()) {
|
||||
|
@ -234,7 +234,7 @@ ThrowCompletionOr<Object*> DateConstructor::construct(FunctionObject& new_target
|
|||
// iii. Else,
|
||||
else {
|
||||
// 1. Let tv be ? ToNumber(v).
|
||||
time_value = TRY(primitive.to_number(global_object)).as_double();
|
||||
time_value = TRY(primitive.to_number(vm)).as_double();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -245,12 +245,12 @@ ThrowCompletionOr<Object*> DateConstructor::construct(FunctionObject& new_target
|
|||
else {
|
||||
// a. Assert: numberOfArgs ≥ 2.
|
||||
// b. Let y be ? ToNumber(values[0]).
|
||||
auto year = TRY(vm.argument(0).to_number(global_object)).as_double();
|
||||
auto year = TRY(vm.argument(0).to_number(vm)).as_double();
|
||||
// c. Let m be ? ToNumber(values[1]).
|
||||
auto month = TRY(vm.argument(1).to_number(global_object)).as_double();
|
||||
auto month = TRY(vm.argument(1).to_number(vm)).as_double();
|
||||
|
||||
auto arg_or = [&vm, &global_object](size_t i, double fallback) -> ThrowCompletionOr<double> {
|
||||
return vm.argument_count() > i ? TRY(vm.argument(i).to_number(global_object)).as_double() : fallback;
|
||||
return vm.argument_count() > i ? TRY(vm.argument(i).to_number(vm)).as_double() : fallback;
|
||||
};
|
||||
|
||||
// d. If numberOfArgs > 2, let dt be ? ToNumber(values[2]); else let dt be 1𝔽.
|
||||
|
@ -304,7 +304,7 @@ JS_DEFINE_NATIVE_FUNCTION(DateConstructor::parse)
|
|||
if (!vm.argument_count())
|
||||
return js_nan();
|
||||
|
||||
auto date_string = TRY(vm.argument(0).to_string(global_object));
|
||||
auto date_string = TRY(vm.argument(0).to_string(vm));
|
||||
|
||||
return Value(parse_date_string(date_string));
|
||||
}
|
||||
|
@ -313,11 +313,11 @@ JS_DEFINE_NATIVE_FUNCTION(DateConstructor::parse)
|
|||
JS_DEFINE_NATIVE_FUNCTION(DateConstructor::utc)
|
||||
{
|
||||
auto arg_or = [&vm, &global_object](size_t i, double fallback) -> ThrowCompletionOr<double> {
|
||||
return vm.argument_count() > i ? TRY(vm.argument(i).to_number(global_object)).as_double() : fallback;
|
||||
return vm.argument_count() > i ? TRY(vm.argument(i).to_number(vm)).as_double() : fallback;
|
||||
};
|
||||
|
||||
// 1. Let y be ? ToNumber(year).
|
||||
auto year = TRY(vm.argument(0).to_number(global_object)).as_double();
|
||||
auto year = TRY(vm.argument(0).to_number(vm)).as_double();
|
||||
// 2. If month is present, let m be ? ToNumber(month); else let m be +0𝔽.
|
||||
auto month = TRY(arg_or(1, 0));
|
||||
// 3. If date is present, let dt be ? ToNumber(date); else let dt be 1𝔽.
|
||||
|
|
|
@ -362,7 +362,7 @@ static ThrowCompletionOr<double> argument_or_number(GlobalObject& global_object,
|
|||
auto& vm = global_object.vm();
|
||||
|
||||
if (vm.argument_count() > index)
|
||||
return TRY(vm.argument(index).to_number(global_object)).as_double();
|
||||
return TRY(vm.argument(index).to_number(vm)).as_double();
|
||||
|
||||
return fallback;
|
||||
}
|
||||
|
@ -372,7 +372,7 @@ static ThrowCompletionOr<Optional<double>> argument_or_empty(GlobalObject& globa
|
|||
auto& vm = global_object.vm();
|
||||
|
||||
if (vm.argument_count() > index)
|
||||
return TRY(vm.argument(index).to_number(global_object)).as_double();
|
||||
return TRY(vm.argument(index).to_number(vm)).as_double();
|
||||
|
||||
return Optional<double> {};
|
||||
}
|
||||
|
@ -384,7 +384,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_date)
|
|||
auto this_time = TRY(this_time_value(global_object, vm.this_value()));
|
||||
|
||||
// 2. Let dt be ? ToNumber(date).
|
||||
auto date = TRY(vm.argument(0).to_number(global_object)).as_double();
|
||||
auto date = TRY(vm.argument(0).to_number(vm)).as_double();
|
||||
|
||||
// 3. If t is NaN, return NaN.
|
||||
if (isnan(this_time))
|
||||
|
@ -418,7 +418,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_full_year)
|
|||
auto this_time = TRY(this_time_value(global_object, vm.this_value()));
|
||||
|
||||
// 2. Let y be ? ToNumber(year).
|
||||
auto year = TRY(vm.argument(0).to_number(global_object)).as_double();
|
||||
auto year = TRY(vm.argument(0).to_number(vm)).as_double();
|
||||
|
||||
// 3. If t is NaN, set t to +0𝔽; otherwise, set t to LocalTime(t).
|
||||
double time = 0;
|
||||
|
@ -453,7 +453,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_hours)
|
|||
auto this_time = TRY(this_time_value(global_object, vm.this_value()));
|
||||
|
||||
// 2. Let h be ? ToNumber(hour).
|
||||
auto hour = TRY(vm.argument(0).to_number(global_object)).as_double();
|
||||
auto hour = TRY(vm.argument(0).to_number(vm)).as_double();
|
||||
|
||||
// 3. If min is present, let m be ? ToNumber(min).
|
||||
auto minute = TRY(argument_or_empty(global_object, 1));
|
||||
|
@ -505,7 +505,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_milliseconds)
|
|||
auto this_time = TRY(this_time_value(global_object, vm.this_value()));
|
||||
|
||||
// 2. Set ms to ? ToNumber(ms).
|
||||
auto millisecond = TRY(vm.argument(0).to_number(global_object)).as_double();
|
||||
auto millisecond = TRY(vm.argument(0).to_number(vm)).as_double();
|
||||
|
||||
// 3. If t is NaN, return NaN.
|
||||
if (isnan(this_time))
|
||||
|
@ -540,7 +540,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_minutes)
|
|||
auto this_time = TRY(this_time_value(global_object, vm.this_value()));
|
||||
|
||||
// 2. Let m be ? ToNumber(min).
|
||||
auto minute = TRY(vm.argument(0).to_number(global_object)).as_double();
|
||||
auto minute = TRY(vm.argument(0).to_number(vm)).as_double();
|
||||
|
||||
// 3. If sec is present, let s be ? ToNumber(sec).
|
||||
auto second = TRY(argument_or_empty(global_object, 1));
|
||||
|
@ -587,7 +587,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_month)
|
|||
auto this_time = TRY(this_time_value(global_object, vm.this_value()));
|
||||
|
||||
// 2. Let m be ? ToNumber(month).
|
||||
auto month = TRY(vm.argument(0).to_number(global_object)).as_double();
|
||||
auto month = TRY(vm.argument(0).to_number(vm)).as_double();
|
||||
|
||||
// 3. If date is present, let dt be ? ToNumber(date).
|
||||
auto date = TRY(argument_or_empty(global_object, 1));
|
||||
|
@ -627,7 +627,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_seconds)
|
|||
auto this_time = TRY(this_time_value(global_object, vm.this_value()));
|
||||
|
||||
// 2. Let s be ? ToNumber(sec).
|
||||
auto second = TRY(vm.argument(0).to_number(global_object)).as_double();
|
||||
auto second = TRY(vm.argument(0).to_number(vm)).as_double();
|
||||
|
||||
// 3. If ms is present, let milli be ? ToNumber(ms).
|
||||
auto millisecond = TRY(argument_or_empty(global_object, 1));
|
||||
|
@ -668,7 +668,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_time)
|
|||
TRY(this_time_value(global_object, vm.this_value()));
|
||||
|
||||
// 2. Let t be ? ToNumber(time).
|
||||
auto time = TRY(vm.argument(0).to_number(global_object)).as_double();
|
||||
auto time = TRY(vm.argument(0).to_number(vm)).as_double();
|
||||
|
||||
// 3. Let v be TimeClip(t).
|
||||
time = time_clip(time);
|
||||
|
@ -688,7 +688,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_utc_date)
|
|||
auto time = TRY(this_time_value(global_object, vm.this_value()));
|
||||
|
||||
// 2. Let dt be ? ToNumber(date).
|
||||
auto date = TRY(vm.argument(0).to_number(global_object)).as_double();
|
||||
auto date = TRY(vm.argument(0).to_number(vm)).as_double();
|
||||
|
||||
// 3. If t is NaN, return NaN.
|
||||
if (isnan(time))
|
||||
|
@ -724,7 +724,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_utc_full_year)
|
|||
time = this_time;
|
||||
|
||||
// 3. Let y be ? ToNumber(year).
|
||||
auto year = TRY(vm.argument(0).to_number(global_object)).as_double();
|
||||
auto year = TRY(vm.argument(0).to_number(vm)).as_double();
|
||||
|
||||
// 4. If month is not present, let m be MonthFromTime(t); otherwise, let m be ? ToNumber(month).
|
||||
auto month = TRY(argument_or_number(global_object, 1, month_from_time(time)));
|
||||
|
@ -754,7 +754,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_utc_hours)
|
|||
auto time = TRY(this_time_value(global_object, vm.this_value()));
|
||||
|
||||
// 2. Let h be ? ToNumber(hour).
|
||||
auto hour = TRY(vm.argument(0).to_number(global_object)).as_double();
|
||||
auto hour = TRY(vm.argument(0).to_number(vm)).as_double();
|
||||
|
||||
// 3. If min is present, let m be ? ToNumber(min).
|
||||
auto minute = TRY(argument_or_empty(global_object, 1));
|
||||
|
@ -803,7 +803,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_utc_milliseconds)
|
|||
auto time = TRY(this_time_value(global_object, vm.this_value()));
|
||||
|
||||
// 2. Set ms to ? ToNumber(ms).
|
||||
auto millisecond = TRY(vm.argument(0).to_number(global_object)).as_double();
|
||||
auto millisecond = TRY(vm.argument(0).to_number(vm)).as_double();
|
||||
|
||||
// 3. If t is NaN, return NaN.
|
||||
if (isnan(time))
|
||||
|
@ -835,7 +835,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_utc_minutes)
|
|||
auto time = TRY(this_time_value(global_object, vm.this_value()));
|
||||
|
||||
// 2. Let m be ? ToNumber(min).
|
||||
auto minute = TRY(vm.argument(0).to_number(global_object)).as_double();
|
||||
auto minute = TRY(vm.argument(0).to_number(vm)).as_double();
|
||||
|
||||
// 3. If sec is present, let s be ? ToNumber(sec).
|
||||
auto second = TRY(argument_or_empty(global_object, 1));
|
||||
|
@ -879,7 +879,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_utc_month)
|
|||
auto time = TRY(this_time_value(global_object, vm.this_value()));
|
||||
|
||||
// 2. Let m be ? ToNumber(month).
|
||||
auto month = TRY(vm.argument(0).to_number(global_object)).as_double();
|
||||
auto month = TRY(vm.argument(0).to_number(vm)).as_double();
|
||||
|
||||
// 3. If date is present, let dt be ? ToNumber(date).
|
||||
auto date = TRY(argument_or_empty(global_object, 1));
|
||||
|
@ -916,7 +916,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_utc_seconds)
|
|||
auto time = TRY(this_time_value(global_object, vm.this_value()));
|
||||
|
||||
// 2. Let s be ? ToNumber(sec).
|
||||
auto second = TRY(vm.argument(0).to_number(global_object)).as_double();
|
||||
auto second = TRY(vm.argument(0).to_number(vm)).as_double();
|
||||
|
||||
// 3. If ms is present, let milli be ? ToNumber(ms).
|
||||
auto millisecond = TRY(argument_or_empty(global_object, 1));
|
||||
|
@ -980,12 +980,12 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_json)
|
|||
{
|
||||
auto this_value = vm.this_value();
|
||||
|
||||
auto time_value = TRY(this_value.to_primitive(global_object, Value::PreferredType::Number));
|
||||
auto time_value = TRY(this_value.to_primitive(vm, Value::PreferredType::Number));
|
||||
|
||||
if (time_value.is_number() && !time_value.is_finite_number())
|
||||
return js_null();
|
||||
|
||||
return TRY(this_value.invoke(global_object, vm.names.toISOString));
|
||||
return TRY(this_value.invoke(vm, vm.names.toISOString));
|
||||
}
|
||||
|
||||
static ThrowCompletionOr<Intl::DateTimeFormat*> construct_date_time_format(GlobalObject& global_object, Value locales, Value options)
|
||||
|
@ -1282,7 +1282,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_year)
|
|||
time = local_time(this_time);
|
||||
|
||||
// 3. Let y be ? ToNumber(year).
|
||||
auto year = TRY(vm.argument(0).to_number(global_object)).as_double();
|
||||
auto year = TRY(vm.argument(0).to_number(vm)).as_double();
|
||||
|
||||
auto* this_object = MUST(typed_this_object(vm));
|
||||
|
||||
|
|
|
@ -682,10 +682,10 @@ void ECMAScriptFunctionObject::ordinary_call_bind_this(ExecutionContext& callee_
|
|||
// b. Else,
|
||||
else {
|
||||
// i. Let thisValue be ! ToObject(thisArgument).
|
||||
this_value = MUST(this_argument.to_object(global_object()));
|
||||
this_value = MUST(this_argument.to_object(vm));
|
||||
|
||||
// ii. NOTE: ToObject produces wrapper objects using calleeRealm.
|
||||
// FIXME: It currently doesn't, as we pass the function's global object.
|
||||
VERIFY(vm.current_realm() == callee_realm);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ ThrowCompletionOr<Object*> ErrorConstructor::construct(FunctionObject& new_targe
|
|||
// 3. If message is not undefined, then
|
||||
if (!message.is_undefined()) {
|
||||
// a. Let msg be ? ToString(message).
|
||||
auto msg = TRY(message.to_string(global_object));
|
||||
auto msg = TRY(message.to_string(vm));
|
||||
|
||||
// b. Perform CreateNonEnumerableDataPropertyOrThrow(O, "message", msg).
|
||||
error->create_non_enumerable_data_property_or_throw(vm.names.message, js_string(vm, move(msg)));
|
||||
|
@ -103,7 +103,7 @@ ThrowCompletionOr<Object*> ErrorConstructor::construct(FunctionObject& new_targe
|
|||
/* 3. If message is not undefined, then */ \
|
||||
if (!message.is_undefined()) { \
|
||||
/* a. Let msg be ? ToString(message). */ \
|
||||
auto msg = TRY(message.to_string(global_object)); \
|
||||
auto msg = TRY(message.to_string(vm)); \
|
||||
\
|
||||
/* b. Perform CreateNonEnumerableDataPropertyOrThrow(O, "message", msg). */ \
|
||||
error->create_non_enumerable_data_property_or_throw(vm.names.message, js_string(vm, move(msg))); \
|
||||
|
|
|
@ -47,7 +47,7 @@ JS_DEFINE_NATIVE_FUNCTION(ErrorPrototype::to_string)
|
|||
// 4. If name is undefined, set name to "Error"; otherwise set name to ? ToString(name).
|
||||
auto name = name_property.is_undefined()
|
||||
? String { "Error"sv }
|
||||
: TRY(name_property.to_string(global_object));
|
||||
: TRY(name_property.to_string(vm));
|
||||
|
||||
// 5. Let msg be ? Get(O, "message").
|
||||
auto message_property = TRY(this_object->get(vm.names.message));
|
||||
|
@ -55,7 +55,7 @@ JS_DEFINE_NATIVE_FUNCTION(ErrorPrototype::to_string)
|
|||
// 6. If msg is undefined, set msg to the empty String; otherwise set msg to ? ToString(msg).
|
||||
auto message = message_property.is_undefined()
|
||||
? String::empty()
|
||||
: TRY(message_property.to_string(global_object));
|
||||
: TRY(message_property.to_string(vm));
|
||||
|
||||
// 7. If name is the empty String, return msg.
|
||||
if (name.is_empty())
|
||||
|
@ -88,12 +88,12 @@ JS_DEFINE_NATIVE_FUNCTION(ErrorPrototype::stack_getter)
|
|||
String name = "Error";
|
||||
auto name_property = TRY(error.get(vm.names.name));
|
||||
if (!name_property.is_undefined())
|
||||
name = TRY(name_property.to_string(global_object));
|
||||
name = TRY(name_property.to_string(vm));
|
||||
|
||||
String message = "";
|
||||
auto message_property = TRY(error.get(vm.names.message));
|
||||
if (!message_property.is_undefined())
|
||||
message = TRY(message_property.to_string(global_object));
|
||||
message = TRY(message_property.to_string(vm));
|
||||
|
||||
String header = name;
|
||||
if (!message.is_empty())
|
||||
|
|
|
@ -148,7 +148,7 @@ ThrowCompletionOr<ECMAScriptFunctionObject*> FunctionConstructor::create_dynamic
|
|||
|
||||
// ii. Let nextArgString be ? ToString(nextArg).
|
||||
// iii. Set P to the string-concatenation of P, "," (a comma), and nextArgString.
|
||||
parameters.append(TRY(next_arg.to_string(global_object)));
|
||||
parameters.append(TRY(next_arg.to_string(vm)));
|
||||
|
||||
// iv. Set k to k + 1.
|
||||
}
|
||||
|
@ -159,7 +159,7 @@ ThrowCompletionOr<ECMAScriptFunctionObject*> FunctionConstructor::create_dynamic
|
|||
}
|
||||
|
||||
// 13. Let bodyString be the string-concatenation of 0x000A (LINE FEED), ? ToString(bodyArg), and 0x000A (LINE FEED).
|
||||
auto body_string = String::formatted("\n{}\n", body_arg.has_value() ? TRY(body_arg->to_string(global_object)) : "");
|
||||
auto body_string = String::formatted("\n{}\n", body_arg.has_value() ? TRY(body_arg->to_string(vm)) : "");
|
||||
|
||||
// 14. Let sourceString be the string-concatenation of prefix, " anonymous(", P, 0x000A (LINE FEED), ") {", bodyString, and "}".
|
||||
// 15. Let sourceText be StringToCodePoints(sourceString).
|
||||
|
|
|
@ -175,7 +175,7 @@ JS_DEFINE_NATIVE_FUNCTION(FunctionPrototype::to_string)
|
|||
// 20.2.3.6 Function.prototype [ @@hasInstance ] ( V ), https://tc39.es/ecma262/#sec-function.prototype-@@hasinstance
|
||||
JS_DEFINE_NATIVE_FUNCTION(FunctionPrototype::symbol_has_instance)
|
||||
{
|
||||
return TRY(ordinary_has_instance(global_object, vm.argument(0), vm.this_value()));
|
||||
return TRY(ordinary_has_instance(vm, vm.argument(0), vm.this_value()));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ ThrowCompletionOr<GeneratorObject*> GeneratorObject::create(Realm& realm, Value
|
|||
} else {
|
||||
generating_function_prototype = TRY(generating_function->get(vm.names.prototype));
|
||||
}
|
||||
auto* generating_function_prototype_object = TRY(generating_function_prototype.to_object(realm.global_object()));
|
||||
auto* generating_function_prototype_object = TRY(generating_function_prototype.to_object(vm));
|
||||
auto object = realm.heap().allocate<GeneratorObject>(realm, realm, *generating_function_prototype_object, move(execution_context));
|
||||
object->m_generating_function = generating_function;
|
||||
object->m_frame = move(frame);
|
||||
|
@ -66,7 +66,7 @@ ThrowCompletionOr<Value> GeneratorObject::next_impl(VM& vm, GlobalObject& global
|
|||
auto generated_continuation = [&](Value value) -> ThrowCompletionOr<Bytecode::BasicBlock const*> {
|
||||
if (value.is_object()) {
|
||||
auto number_value = TRY(value.as_object().get("continuation"));
|
||||
return reinterpret_cast<Bytecode::BasicBlock const*>(static_cast<u64>(TRY(number_value.to_double(global_object))));
|
||||
return reinterpret_cast<Bytecode::BasicBlock const*>(static_cast<u64>(TRY(number_value.to_double(vm))));
|
||||
}
|
||||
return nullptr;
|
||||
};
|
||||
|
|
|
@ -379,13 +379,13 @@ JS_DEFINE_NATIVE_FUNCTION(GlobalObject::gc)
|
|||
// 19.2.3 isNaN ( number ), https://tc39.es/ecma262/#sec-isnan-number
|
||||
JS_DEFINE_NATIVE_FUNCTION(GlobalObject::is_nan)
|
||||
{
|
||||
return Value(TRY(vm.argument(0).to_number(global_object)).is_nan());
|
||||
return Value(TRY(vm.argument(0).to_number(vm)).is_nan());
|
||||
}
|
||||
|
||||
// 19.2.2 isFinite ( number ), https://tc39.es/ecma262/#sec-isfinite-number
|
||||
JS_DEFINE_NATIVE_FUNCTION(GlobalObject::is_finite)
|
||||
{
|
||||
return Value(TRY(vm.argument(0).to_number(global_object)).is_finite_number());
|
||||
return Value(TRY(vm.argument(0).to_number(vm)).is_finite_number());
|
||||
}
|
||||
|
||||
// 19.2.4 parseFloat ( string ), https://tc39.es/ecma262/#sec-parsefloat-string
|
||||
|
@ -393,10 +393,10 @@ JS_DEFINE_NATIVE_FUNCTION(GlobalObject::parse_float)
|
|||
{
|
||||
if (vm.argument(0).is_number())
|
||||
return vm.argument(0);
|
||||
auto input_string = TRY(vm.argument(0).to_string(global_object));
|
||||
auto input_string = TRY(vm.argument(0).to_string(vm));
|
||||
auto trimmed_string = MUST(trim_string(global_object, js_string(vm, input_string), TrimMode::Left));
|
||||
for (size_t length = trimmed_string.length(); length > 0; --length) {
|
||||
auto number = MUST(Value(js_string(vm, trimmed_string.substring(0, length))).to_number(global_object));
|
||||
auto number = MUST(Value(js_string(vm, trimmed_string.substring(0, length))).to_number(vm));
|
||||
if (!number.is_nan())
|
||||
return number;
|
||||
}
|
||||
|
@ -407,7 +407,7 @@ JS_DEFINE_NATIVE_FUNCTION(GlobalObject::parse_float)
|
|||
JS_DEFINE_NATIVE_FUNCTION(GlobalObject::parse_int)
|
||||
{
|
||||
// 1. Let inputString be ? ToString(string).
|
||||
auto input_string = TRY(vm.argument(0).to_string(global_object));
|
||||
auto input_string = TRY(vm.argument(0).to_string(vm));
|
||||
|
||||
// 2. Let S be ! TrimString(inputString, start).
|
||||
auto string = MUST(trim_string(global_object, js_string(vm, input_string), TrimMode::Left));
|
||||
|
@ -424,7 +424,7 @@ JS_DEFINE_NATIVE_FUNCTION(GlobalObject::parse_int)
|
|||
trimmed_view = trimmed_view.substring_view(1);
|
||||
|
||||
// 6. Let R be ℝ(? ToInt32(radix)).
|
||||
auto radix = TRY(vm.argument(1).to_i32(global_object));
|
||||
auto radix = TRY(vm.argument(1).to_i32(vm));
|
||||
|
||||
// 7. Let stripPrefix be true.
|
||||
auto strip_prefix = true;
|
||||
|
@ -614,7 +614,7 @@ static ThrowCompletionOr<String> decode(GlobalObject& global_object, String cons
|
|||
// 19.2.6.4 encodeURI ( uri ), https://tc39.es/ecma262/#sec-encodeuri-uri
|
||||
JS_DEFINE_NATIVE_FUNCTION(GlobalObject::encode_uri)
|
||||
{
|
||||
auto uri_string = TRY(vm.argument(0).to_string(global_object));
|
||||
auto uri_string = TRY(vm.argument(0).to_string(vm));
|
||||
auto encoded = TRY(encode(global_object, uri_string, ";/?:@&=+$,abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.!~*'()#"sv));
|
||||
return js_string(vm, move(encoded));
|
||||
}
|
||||
|
@ -622,7 +622,7 @@ JS_DEFINE_NATIVE_FUNCTION(GlobalObject::encode_uri)
|
|||
// 19.2.6.2 decodeURI ( encodedURI ), https://tc39.es/ecma262/#sec-decodeuri-encodeduri
|
||||
JS_DEFINE_NATIVE_FUNCTION(GlobalObject::decode_uri)
|
||||
{
|
||||
auto uri_string = TRY(vm.argument(0).to_string(global_object));
|
||||
auto uri_string = TRY(vm.argument(0).to_string(vm));
|
||||
auto decoded = TRY(decode(global_object, uri_string, ";/?:@&=+$,#"sv));
|
||||
return js_string(vm, move(decoded));
|
||||
}
|
||||
|
@ -630,7 +630,7 @@ JS_DEFINE_NATIVE_FUNCTION(GlobalObject::decode_uri)
|
|||
// 19.2.6.5 encodeURIComponent ( uriComponent ), https://tc39.es/ecma262/#sec-encodeuricomponent-uricomponent
|
||||
JS_DEFINE_NATIVE_FUNCTION(GlobalObject::encode_uri_component)
|
||||
{
|
||||
auto uri_string = TRY(vm.argument(0).to_string(global_object));
|
||||
auto uri_string = TRY(vm.argument(0).to_string(vm));
|
||||
auto encoded = TRY(encode(global_object, uri_string, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.!~*'()"sv));
|
||||
return js_string(vm, move(encoded));
|
||||
}
|
||||
|
@ -638,7 +638,7 @@ JS_DEFINE_NATIVE_FUNCTION(GlobalObject::encode_uri_component)
|
|||
// 19.2.6.3 decodeURIComponent ( encodedURIComponent ), https://tc39.es/ecma262/#sec-decodeuricomponent-encodeduricomponent
|
||||
JS_DEFINE_NATIVE_FUNCTION(GlobalObject::decode_uri_component)
|
||||
{
|
||||
auto uri_string = TRY(vm.argument(0).to_string(global_object));
|
||||
auto uri_string = TRY(vm.argument(0).to_string(vm));
|
||||
auto decoded = TRY(decode(global_object, uri_string, ""sv));
|
||||
return js_string(vm, move(decoded));
|
||||
}
|
||||
|
@ -646,7 +646,7 @@ JS_DEFINE_NATIVE_FUNCTION(GlobalObject::decode_uri_component)
|
|||
// B.2.1.1 escape ( string ), https://tc39.es/ecma262/#sec-escape-string
|
||||
JS_DEFINE_NATIVE_FUNCTION(GlobalObject::escape)
|
||||
{
|
||||
auto string = TRY(vm.argument(0).to_string(global_object));
|
||||
auto string = TRY(vm.argument(0).to_string(vm));
|
||||
StringBuilder escaped;
|
||||
for (auto code_point : utf8_to_utf16(string)) {
|
||||
if (code_point < 256) {
|
||||
|
@ -664,7 +664,7 @@ JS_DEFINE_NATIVE_FUNCTION(GlobalObject::escape)
|
|||
// B.2.1.2 unescape ( string ), https://tc39.es/ecma262/#sec-unescape-string
|
||||
JS_DEFINE_NATIVE_FUNCTION(GlobalObject::unescape)
|
||||
{
|
||||
auto string = TRY(vm.argument(0).to_string(global_object));
|
||||
auto string = TRY(vm.argument(0).to_string(vm));
|
||||
ssize_t length = string.length();
|
||||
StringBuilder unescaped(length);
|
||||
for (auto k = 0; k < length; ++k) {
|
||||
|
|
|
@ -202,15 +202,15 @@ template<>
|
|||
inline bool Object::fast_is<GlobalObject>() const { return is_global_object(); }
|
||||
|
||||
template<typename... Args>
|
||||
[[nodiscard]] ALWAYS_INLINE ThrowCompletionOr<Value> Value::invoke(GlobalObject& global_object, PropertyKey const& property_key, Args... args)
|
||||
[[nodiscard]] ALWAYS_INLINE ThrowCompletionOr<Value> Value::invoke(VM& vm, PropertyKey const& property_key, Args... args)
|
||||
{
|
||||
if constexpr (sizeof...(Args) > 0) {
|
||||
MarkedVector<Value> arglist { global_object.vm().heap() };
|
||||
MarkedVector<Value> arglist { vm.heap() };
|
||||
(..., arglist.append(move(args)));
|
||||
return invoke_internal(global_object, property_key, move(arglist));
|
||||
return invoke_internal(vm, property_key, move(arglist));
|
||||
}
|
||||
|
||||
return invoke_internal(global_object, property_key, Optional<MarkedVector<Value>> {});
|
||||
return invoke_internal(vm, property_key, Optional<MarkedVector<Value>> {});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -186,7 +186,6 @@ bool is_well_formed_unit_identifier(StringView unit_identifier)
|
|||
ThrowCompletionOr<Vector<String>> canonicalize_locale_list(VM& vm, Value locales)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. If locales is undefined, then
|
||||
if (locales.is_undefined()) {
|
||||
|
@ -206,12 +205,12 @@ ThrowCompletionOr<Vector<String>> canonicalize_locale_list(VM& vm, Value locales
|
|||
// 4. Else,
|
||||
else {
|
||||
// a. Let O be ? ToObject(locales).
|
||||
object = TRY(locales.to_object(global_object));
|
||||
object = TRY(locales.to_object(vm));
|
||||
}
|
||||
|
||||
// 5. Let len be ? ToLength(? Get(O, "length")).
|
||||
auto length_value = TRY(object->get(vm.names.length));
|
||||
auto length = TRY(length_value.to_length(global_object));
|
||||
auto length = TRY(length_value.to_length(vm));
|
||||
|
||||
// 6. Let k be 0.
|
||||
// 7. Repeat, while k < len,
|
||||
|
@ -241,7 +240,7 @@ ThrowCompletionOr<Vector<String>> canonicalize_locale_list(VM& vm, Value locales
|
|||
// iv. Else,
|
||||
else {
|
||||
// 1. Let tag be ? ToString(kValue).
|
||||
tag = TRY(key_value.to_string(global_object));
|
||||
tag = TRY(key_value.to_string(vm));
|
||||
}
|
||||
|
||||
// v. If ! IsStructurallyValidLanguageTag(tag) is false, throw a RangeError exception.
|
||||
|
@ -597,7 +596,6 @@ ThrowCompletionOr<Array*> supported_locales(VM& vm, Vector<String> const& reques
|
|||
ThrowCompletionOr<Object*> coerce_options_to_object(VM& vm, Value options)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. If options is undefined, then
|
||||
if (options.is_undefined()) {
|
||||
|
@ -606,7 +604,7 @@ ThrowCompletionOr<Object*> coerce_options_to_object(VM& vm, Value options)
|
|||
}
|
||||
|
||||
// 2. Return ? ToObject(options).
|
||||
return TRY(options.to_object(global_object));
|
||||
return TRY(options.to_object(vm));
|
||||
}
|
||||
|
||||
// NOTE: 9.2.13 GetOption has been removed and is being pulled in from ECMA-262 in the Temporal proposal.
|
||||
|
@ -614,9 +612,6 @@ ThrowCompletionOr<Object*> coerce_options_to_object(VM& vm, Value options)
|
|||
// 1.2.12 GetStringOrBooleanOption ( options, property, values, trueValue, falsyValue, fallback ), https://tc39.es/proposal-intl-numberformat-v3/out/negotiation/proposed.html#sec-getstringorbooleanoption
|
||||
ThrowCompletionOr<StringOrBoolean> get_string_or_boolean_option(VM& vm, Object const& options, PropertyKey const& property, Span<StringView const> values, StringOrBoolean true_value, StringOrBoolean falsy_value, StringOrBoolean fallback)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Let value be ? Get(options, property).
|
||||
auto value = TRY(options.get(property));
|
||||
|
||||
|
@ -636,7 +631,7 @@ ThrowCompletionOr<StringOrBoolean> get_string_or_boolean_option(VM& vm, Object c
|
|||
return falsy_value;
|
||||
|
||||
// 6. Let value be ? ToString(value).
|
||||
auto value_string = TRY(value.to_string(global_object));
|
||||
auto value_string = TRY(value.to_string(vm));
|
||||
|
||||
// 7. If values does not contain an element equal to value, return fallback.
|
||||
auto it = find(values.begin(), values.end(), value_string);
|
||||
|
@ -650,15 +645,12 @@ ThrowCompletionOr<StringOrBoolean> get_string_or_boolean_option(VM& vm, Object c
|
|||
// 9.2.14 DefaultNumberOption ( value, minimum, maximum, fallback ), https://tc39.es/ecma402/#sec-defaultnumberoption
|
||||
ThrowCompletionOr<Optional<int>> default_number_option(VM& vm, Value value, int minimum, int maximum, Optional<int> fallback)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. If value is undefined, return fallback.
|
||||
if (value.is_undefined())
|
||||
return fallback;
|
||||
|
||||
// 2. Set value to ? ToNumber(value).
|
||||
value = TRY(value.to_number(global_object));
|
||||
value = TRY(value.to_number(vm));
|
||||
|
||||
// 3. If value is NaN or less than minimum or greater than maximum, throw a RangeError exception.
|
||||
if (value.is_nan() || (value.as_double() < minimum) || (value.as_double() > maximum))
|
||||
|
|
|
@ -51,7 +51,6 @@ double compare_strings(Collator& collator, Utf8View const& x, Utf8View const& y)
|
|||
ThrowCompletionOr<Value> CollatorCompareFunction::call()
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
auto& global_object = this->global_object();
|
||||
|
||||
// 1. Let collator be F.[[Collator]].
|
||||
// 2. Assert: Type(collator) is Object and collator has an [[InitializedCollator]] internal slot.
|
||||
|
@ -59,9 +58,9 @@ ThrowCompletionOr<Value> CollatorCompareFunction::call()
|
|||
// 4. If y is not provided, let y be undefined.
|
||||
|
||||
// 5. Let X be ? ToString(x).
|
||||
auto x = TRY(vm.argument(0).to_string(global_object));
|
||||
auto x = TRY(vm.argument(0).to_string(vm));
|
||||
// 6. Let Y be ? ToString(y).
|
||||
auto y = TRY(vm.argument(1).to_string(global_object));
|
||||
auto y = TRY(vm.argument(1).to_string(vm));
|
||||
|
||||
// 7. Return CompareStrings(collator, X, Y).
|
||||
return compare_strings(m_collator, Utf8View(x), Utf8View(y));
|
||||
|
|
|
@ -17,9 +17,6 @@ namespace JS::Intl {
|
|||
// 10.1.2 InitializeCollator ( collator, locales, options ), https://tc39.es/ecma402/#sec-initializecollator
|
||||
static ThrowCompletionOr<Collator*> initialize_collator(VM& vm, Collator& collator, Value locales_value, Value options_value)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Let requestedLocales be ? CanonicalizeLocaleList(locales).
|
||||
auto requested_locales = TRY(canonicalize_locale_list(vm, locales_value));
|
||||
|
||||
|
@ -66,7 +63,7 @@ static ThrowCompletionOr<Collator*> initialize_collator(VM& vm, Collator& collat
|
|||
// a. Let numeric be ! ToString(numeric).
|
||||
// 15. Set opt.[[kn]] to numeric.
|
||||
if (!numeric.is_undefined())
|
||||
opt.kn = MUST(numeric.to_string(global_object));
|
||||
opt.kn = MUST(numeric.to_string(vm));
|
||||
|
||||
// 16. Let caseFirst be ? GetOption(options, "caseFirst", "string", « "upper", "lower", "false" », undefined).
|
||||
// 17. Set opt.[[kf]] to caseFirst.
|
||||
|
|
|
@ -67,12 +67,11 @@ StringView DateTimeFormat::style_to_string(Style style)
|
|||
ThrowCompletionOr<Object*> to_date_time_options(VM& vm, Value options_value, OptionRequired required, OptionDefaults defaults)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. If options is undefined, let options be null; otherwise let options be ? ToObject(options).
|
||||
Object* options = nullptr;
|
||||
if (!options_value.is_undefined())
|
||||
options = TRY(options_value.to_object(global_object));
|
||||
options = TRY(options_value.to_object(vm));
|
||||
|
||||
// 2. Let options be OrdinaryObjectCreate(options).
|
||||
options = Object::create(realm, options);
|
||||
|
|
|
@ -85,9 +85,6 @@ JS_DEFINE_NATIVE_FUNCTION(DateTimeFormatConstructor::supported_locales_of)
|
|||
// 11.1.2 InitializeDateTimeFormat ( dateTimeFormat, locales, options ), https://tc39.es/ecma402/#sec-initializedatetimeformat
|
||||
ThrowCompletionOr<DateTimeFormat*> initialize_date_time_format(VM& vm, DateTimeFormat& date_time_format, Value locales_value, Value options_value)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Let requestedLocales be ? CanonicalizeLocaleList(locales).
|
||||
auto requested_locales = TRY(canonicalize_locale_list(vm, locales_value));
|
||||
|
||||
|
@ -225,7 +222,7 @@ ThrowCompletionOr<DateTimeFormat*> initialize_date_time_format(VM& vm, DateTimeF
|
|||
// 31. Else,
|
||||
else {
|
||||
// a. Set timeZone to ? ToString(timeZone).
|
||||
time_zone = TRY(time_zone_value.to_string(global_object));
|
||||
time_zone = TRY(time_zone_value.to_string(vm));
|
||||
|
||||
// b. If the result of IsValidTimeZoneName(timeZone) is false, then
|
||||
if (!Temporal::is_valid_time_zone_name(time_zone)) {
|
||||
|
|
|
@ -54,7 +54,7 @@ ThrowCompletionOr<Value> DateTimeFormatFunction::call()
|
|||
// 4. Else,
|
||||
else {
|
||||
// a. Let x be ? ToNumber(date).
|
||||
date_value = TRY(date.to_number(global_object)).as_double();
|
||||
date_value = TRY(date.to_number(vm)).as_double();
|
||||
}
|
||||
|
||||
// 5. Return ? FormatDateTime(dtf, x).
|
||||
|
|
|
@ -81,7 +81,7 @@ JS_DEFINE_NATIVE_FUNCTION(DateTimeFormatPrototype::format_to_parts)
|
|||
// 4. Else,
|
||||
else {
|
||||
// a. Let x be ? ToNumber(date).
|
||||
date_value = TRY(date.to_number(global_object)).as_double();
|
||||
date_value = TRY(date.to_number(vm)).as_double();
|
||||
}
|
||||
|
||||
// 5. Return ? FormatDateTimeToParts(dtf, x).
|
||||
|
@ -105,10 +105,10 @@ JS_DEFINE_NATIVE_FUNCTION(DateTimeFormatPrototype::format_range)
|
|||
return vm.throw_completion<TypeError>(ErrorType::IsUndefined, "endDate"sv);
|
||||
|
||||
// 4. Let x be ? ToNumber(startDate).
|
||||
auto start_date_number = TRY(start_date.to_number(global_object)).as_double();
|
||||
auto start_date_number = TRY(start_date.to_number(vm)).as_double();
|
||||
|
||||
// 5. Let y be ? ToNumber(endDate).
|
||||
auto end_date_number = TRY(end_date.to_number(global_object)).as_double();
|
||||
auto end_date_number = TRY(end_date.to_number(vm)).as_double();
|
||||
|
||||
// 6. Return ? FormatDateTimeRange(dtf, x, y).
|
||||
auto formatted = TRY(format_date_time_range(vm, *date_time_format, start_date_number, end_date_number));
|
||||
|
@ -132,10 +132,10 @@ JS_DEFINE_NATIVE_FUNCTION(DateTimeFormatPrototype::format_range_to_parts)
|
|||
return vm.throw_completion<TypeError>(ErrorType::IsUndefined, "endDate"sv);
|
||||
|
||||
// 4. Let x be ? ToNumber(startDate).
|
||||
auto start_date_number = TRY(start_date.to_number(global_object)).as_double();
|
||||
auto start_date_number = TRY(start_date.to_number(vm)).as_double();
|
||||
|
||||
// 5. Let y be ? ToNumber(endDate).
|
||||
auto end_date_number = TRY(end_date.to_number(global_object)).as_double();
|
||||
auto end_date_number = TRY(end_date.to_number(vm)).as_double();
|
||||
|
||||
// 6. Return ? FormatDateTimeRangeToParts(dtf, x, y).
|
||||
return TRY(format_date_time_range_to_parts(vm, *date_time_format, start_date_number, end_date_number));
|
||||
|
|
|
@ -43,7 +43,7 @@ JS_DEFINE_NATIVE_FUNCTION(DisplayNamesPrototype::of)
|
|||
auto* display_names = TRY(typed_this_object(vm));
|
||||
|
||||
// 3. Let code be ? ToString(code).
|
||||
auto code_string = TRY(code.to_string(global_object));
|
||||
auto code_string = TRY(code.to_string(vm));
|
||||
code = js_string(vm, move(code_string));
|
||||
|
||||
// 4. Let code be ? CanonicalCodeForDisplayNames(displayNames.[[Type]], code).
|
||||
|
|
|
@ -112,7 +112,7 @@ JS_DEFINE_NATIVE_FUNCTION(Intl::supported_values_of)
|
|||
auto& realm = *global_object.associated_realm();
|
||||
|
||||
// 1. Let key be ? ToString(key).
|
||||
auto key = TRY(vm.argument(0).to_string(global_object));
|
||||
auto key = TRY(vm.argument(0).to_string(vm));
|
||||
|
||||
Span<StringView const> list;
|
||||
|
||||
|
|
|
@ -275,7 +275,7 @@ ThrowCompletionOr<Object*> LocaleConstructor::construct(FunctionObject& new_targ
|
|||
// 9. Else,
|
||||
else {
|
||||
// a. Let tag be ? ToString(tag).
|
||||
tag = TRY(tag_value.to_string(global_object));
|
||||
tag = TRY(tag_value.to_string(vm));
|
||||
}
|
||||
|
||||
// 10. Set options to ? CoerceOptionsToObject(options).
|
||||
|
@ -313,7 +313,7 @@ ThrowCompletionOr<Object*> LocaleConstructor::construct(FunctionObject& new_targ
|
|||
// 24. If kn is not undefined, set kn to ! ToString(kn).
|
||||
// 25. Set opt.[[kn]] to kn.
|
||||
if (!kn.is_undefined())
|
||||
opt.kn = TRY(kn.to_string(global_object));
|
||||
opt.kn = TRY(kn.to_string(vm));
|
||||
|
||||
// 26. Let numberingSystem be ? GetOption(options, "numberingSystem", "string", undefined, undefined).
|
||||
// 27. If numberingSystem is not undefined, then
|
||||
|
|
|
@ -1580,11 +1580,9 @@ int compute_exponent_for_magnitude(NumberFormat& number_format, int magnitude)
|
|||
// 1.1.18 ToIntlMathematicalValue ( value ), https://tc39.es/proposal-intl-numberformat-v3/out/numberformat/proposed.html#sec-tointlmathematicalvalue
|
||||
ThrowCompletionOr<MathematicalValue> to_intl_mathematical_value(VM& vm, Value value)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Let primValue be ? ToPrimitive(value, number).
|
||||
auto primitive_value = TRY(value.to_primitive(global_object, Value::PreferredType::Number));
|
||||
auto primitive_value = TRY(value.to_primitive(vm, Value::PreferredType::Number));
|
||||
|
||||
// 2. If Type(primValue) is BigInt, return the mathematical value of primValue.
|
||||
if (primitive_value.is_bigint())
|
||||
|
@ -1594,7 +1592,7 @@ ThrowCompletionOr<MathematicalValue> to_intl_mathematical_value(VM& vm, Value va
|
|||
// We short-circuit some of these steps to avoid known pitfalls.
|
||||
// See: https://github.com/tc39/proposal-intl-numberformat-v3/pull/82
|
||||
if (!primitive_value.is_string()) {
|
||||
auto number = TRY(primitive_value.to_number(global_object));
|
||||
auto number = TRY(primitive_value.to_number(vm));
|
||||
return number.as_double();
|
||||
}
|
||||
|
||||
|
@ -1606,7 +1604,7 @@ ThrowCompletionOr<MathematicalValue> to_intl_mathematical_value(VM& vm, Value va
|
|||
|
||||
// 5. If the grammar cannot interpret str as an expansion of StringNumericLiteral, return not-a-number.
|
||||
// 6. Let mv be the MV, a mathematical value, of ? ToNumber(str), as described in 7.1.4.1.1.
|
||||
auto mathematical_value = TRY(primitive_value.to_number(global_object)).as_double();
|
||||
auto mathematical_value = TRY(primitive_value.to_number(vm)).as_double();
|
||||
|
||||
// 7. If mv is 0 and the first non white space code point in str is -, return negative-zero.
|
||||
if (mathematical_value == 0.0 && string.view().trim_whitespace(TrimMode::Left).starts_with('-'))
|
||||
|
|
|
@ -41,7 +41,7 @@ JS_DEFINE_NATIVE_FUNCTION(PluralRulesPrototype::select)
|
|||
auto* plural_rules = TRY(typed_this_object(vm));
|
||||
|
||||
// 3. Let n be ? ToNumber(value).
|
||||
auto number = TRY(vm.argument(0).to_number(global_object));
|
||||
auto number = TRY(vm.argument(0).to_number(vm));
|
||||
|
||||
// 4. Return ! ResolvePlural(pr, n).
|
||||
auto plurality = resolve_plural(*plural_rules, number);
|
||||
|
@ -65,10 +65,10 @@ JS_DEFINE_NATIVE_FUNCTION(PluralRulesPrototype::select_range)
|
|||
return vm.throw_completion<TypeError>(ErrorType::IsUndefined, "end"sv);
|
||||
|
||||
// 4. Let x be ? ToNumber(start).
|
||||
auto x = TRY(start.to_number(global_object));
|
||||
auto x = TRY(start.to_number(vm));
|
||||
|
||||
// 5. Let y be ? ToNumber(end).
|
||||
auto y = TRY(end.to_number(global_object));
|
||||
auto y = TRY(end.to_number(vm));
|
||||
|
||||
// 6. Return ? ResolvePluralRange(pr, x, y).
|
||||
auto plurality = TRY(resolve_plural_range(vm, *plural_rules, x, y));
|
||||
|
|
|
@ -93,9 +93,6 @@ ThrowCompletionOr<Unicode::TimeUnit> singular_relative_time_unit(VM& vm, StringV
|
|||
// 17.5.2 PartitionRelativeTimePattern ( relativeTimeFormat, value, unit ), https://tc39.es/ecma402/#sec-PartitionRelativeTimePattern
|
||||
ThrowCompletionOr<Vector<PatternPartitionWithUnit>> partition_relative_time_pattern(VM& vm, RelativeTimeFormat& relative_time_format, double value, StringView unit)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Assert: relativeTimeFormat has an [[InitializedRelativeTimeFormat]] internal slot.
|
||||
// 2. Assert: Type(value) is Number.
|
||||
// 3. Assert: Type(unit) is String.
|
||||
|
@ -144,7 +141,7 @@ ThrowCompletionOr<Vector<PatternPartitionWithUnit>> partition_relative_time_patt
|
|||
// 16. If numeric is equal to "auto", then
|
||||
if (relative_time_format.numeric() == RelativeTimeFormat::Numeric::Auto) {
|
||||
// a. Let valueString be ToString(value).
|
||||
auto value_string = MUST(Value(value).to_string(global_object));
|
||||
auto value_string = MUST(Value(value).to_string(vm));
|
||||
|
||||
// b. If patterns has a field [[<valueString>]], then
|
||||
if (auto patterns = find_patterns_for_tense_or_number(value_string); !patterns.is_empty()) {
|
||||
|
|
|
@ -39,10 +39,10 @@ JS_DEFINE_NATIVE_FUNCTION(RelativeTimeFormatPrototype::format)
|
|||
auto* relative_time_format = TRY(typed_this_object(vm));
|
||||
|
||||
// 3. Let value be ? ToNumber(value).
|
||||
auto value = TRY(vm.argument(0).to_number(global_object));
|
||||
auto value = TRY(vm.argument(0).to_number(vm));
|
||||
|
||||
// 4. Let unit be ? ToString(unit).
|
||||
auto unit = TRY(vm.argument(1).to_string(global_object));
|
||||
auto unit = TRY(vm.argument(1).to_string(vm));
|
||||
|
||||
// 5. Return ? FormatRelativeTime(relativeTimeFormat, value, unit).
|
||||
auto formatted = TRY(format_relative_time(vm, *relative_time_format, value.as_double(), unit));
|
||||
|
@ -57,10 +57,10 @@ JS_DEFINE_NATIVE_FUNCTION(RelativeTimeFormatPrototype::format_to_parts)
|
|||
auto* relative_time_format = TRY(typed_this_object(vm));
|
||||
|
||||
// 3. Let value be ? ToNumber(value).
|
||||
auto value = TRY(vm.argument(0).to_number(global_object));
|
||||
auto value = TRY(vm.argument(0).to_number(vm));
|
||||
|
||||
// 4. Let unit be ? ToString(unit).
|
||||
auto unit = TRY(vm.argument(1).to_string(global_object));
|
||||
auto unit = TRY(vm.argument(1).to_string(vm));
|
||||
|
||||
// 5. Return ? FormatRelativeTimeToParts(relativeTimeFormat, value, unit).
|
||||
return TRY(format_relative_time_to_parts(vm, *relative_time_format, value.as_double(), unit));
|
||||
|
|
|
@ -65,7 +65,7 @@ JS_DEFINE_NATIVE_FUNCTION(SegmenterPrototype::segment)
|
|||
auto* segmenter = TRY(typed_this_object(vm));
|
||||
|
||||
// 3. Let string be ? ToString(string).
|
||||
auto string = TRY(vm.argument(0).to_utf16_string(global_object));
|
||||
auto string = TRY(vm.argument(0).to_utf16_string(vm));
|
||||
|
||||
// 4. Return ! CreateSegmentsObject(segmenter, string).
|
||||
return Segments::create(realm, *segmenter, move(string));
|
||||
|
|
|
@ -45,7 +45,7 @@ JS_DEFINE_NATIVE_FUNCTION(SegmentsPrototype::containing)
|
|||
auto length = string.length_in_code_units();
|
||||
|
||||
// 6. Let n be ? ToIntegerOrInfinity(index).
|
||||
auto n = TRY(vm.argument(0).to_integer_or_infinity(global_object));
|
||||
auto n = TRY(vm.argument(0).to_integer_or_infinity(vm));
|
||||
|
||||
// 7. If n < 0 or n ≥ len, return undefined.
|
||||
if (n < 0 || n >= length)
|
||||
|
|
|
@ -26,12 +26,12 @@ ThrowCompletionOr<Iterator> get_iterator(GlobalObject& global_object, Value valu
|
|||
// a. If hint is async, then
|
||||
if (hint == IteratorHint::Async) {
|
||||
// i. Set method to ? GetMethod(obj, @@asyncIterator).
|
||||
auto* async_method = TRY(value.get_method(global_object, *vm.well_known_symbol_async_iterator()));
|
||||
auto* async_method = TRY(value.get_method(vm, *vm.well_known_symbol_async_iterator()));
|
||||
|
||||
// ii. If method is undefined, then
|
||||
if (async_method == nullptr) {
|
||||
// 1. Let syncMethod be ? GetMethod(obj, @@iterator).
|
||||
auto* sync_method = TRY(value.get_method(global_object, *vm.well_known_symbol_iterator()));
|
||||
auto* sync_method = TRY(value.get_method(vm, *vm.well_known_symbol_iterator()));
|
||||
|
||||
// 2. Let syncIteratorRecord be ? GetIterator(obj, sync, syncMethod).
|
||||
auto sync_iterator_record = TRY(get_iterator(global_object, value, IteratorHint::Sync, sync_method));
|
||||
|
@ -44,7 +44,7 @@ ThrowCompletionOr<Iterator> get_iterator(GlobalObject& global_object, Value valu
|
|||
}
|
||||
// b. Otherwise, set method to ? GetMethod(obj, @@iterator).
|
||||
else {
|
||||
method = TRY(value.get_method(global_object, *vm.well_known_symbol_iterator()));
|
||||
method = TRY(value.get_method(vm, *vm.well_known_symbol_iterator()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -60,7 +60,7 @@ ThrowCompletionOr<Iterator> get_iterator(GlobalObject& global_object, Value valu
|
|||
return vm.throw_completion<TypeError>(ErrorType::NotIterable, value.to_string_without_side_effects());
|
||||
|
||||
// 5. Let nextMethod be ? GetV(iterator, "next").
|
||||
auto next_method = TRY(iterator.get(global_object, vm.names.next));
|
||||
auto next_method = TRY(iterator.get(vm, vm.names.next));
|
||||
|
||||
// 6. Let iteratorRecord be the Iterator Record { [[Iterator]]: iterator, [[NextMethod]]: nextMethod, [[Done]]: false }.
|
||||
auto iterator_record = Iterator { .iterator = &iterator.as_object(), .next_method = next_method, .done = false };
|
||||
|
@ -142,7 +142,7 @@ static Completion iterator_close_impl(GlobalObject& global_object, Iterator cons
|
|||
|
||||
// 3. Let innerResult be Completion(GetMethod(iterator, "return")).
|
||||
auto inner_result = ThrowCompletionOr<Value> { js_undefined() };
|
||||
auto get_method_result = Value(iterator).get_method(global_object, vm.names.return_);
|
||||
auto get_method_result = Value(iterator).get_method(vm, vm.names.return_);
|
||||
if (get_method_result.is_error())
|
||||
inner_result = get_method_result.release_error();
|
||||
|
||||
|
|
|
@ -45,6 +45,7 @@ void JSONObject::initialize(Realm& realm)
|
|||
// 25.5.2 JSON.stringify ( value [ , replacer [ , space ] ] ), https://tc39.es/ecma262/#sec-json.stringify
|
||||
ThrowCompletionOr<String> JSONObject::stringify_impl(GlobalObject& global_object, Value value, Value replacer, Value space)
|
||||
{
|
||||
auto& vm = global_object.vm();
|
||||
auto& realm = *global_object.associated_realm();
|
||||
|
||||
StringifyState state;
|
||||
|
@ -53,7 +54,7 @@ ThrowCompletionOr<String> JSONObject::stringify_impl(GlobalObject& global_object
|
|||
if (replacer.as_object().is_function()) {
|
||||
state.replacer_function = &replacer.as_function();
|
||||
} else {
|
||||
auto is_array = TRY(replacer.is_array(global_object));
|
||||
auto is_array = TRY(replacer.is_array(vm));
|
||||
if (is_array) {
|
||||
auto& replacer_object = replacer.as_object();
|
||||
auto replacer_length = TRY(length_of_array_like(global_object, replacer_object));
|
||||
|
@ -64,11 +65,11 @@ ThrowCompletionOr<String> JSONObject::stringify_impl(GlobalObject& global_object
|
|||
if (replacer_value.is_string()) {
|
||||
item = replacer_value.as_string().string();
|
||||
} else if (replacer_value.is_number()) {
|
||||
item = MUST(replacer_value.to_string(global_object));
|
||||
item = MUST(replacer_value.to_string(vm));
|
||||
} else if (replacer_value.is_object()) {
|
||||
auto& value_object = replacer_value.as_object();
|
||||
if (is<StringObject>(value_object) || is<NumberObject>(value_object))
|
||||
item = TRY(replacer_value.to_string(global_object));
|
||||
item = TRY(replacer_value.to_string(vm));
|
||||
}
|
||||
if (!item.is_null() && !list.contains_slow(item)) {
|
||||
list.append(item);
|
||||
|
@ -82,13 +83,13 @@ ThrowCompletionOr<String> JSONObject::stringify_impl(GlobalObject& global_object
|
|||
if (space.is_object()) {
|
||||
auto& space_object = space.as_object();
|
||||
if (is<NumberObject>(space_object))
|
||||
space = TRY(space.to_number(global_object));
|
||||
space = TRY(space.to_number(vm));
|
||||
else if (is<StringObject>(space_object))
|
||||
space = TRY(space.to_primitive_string(global_object));
|
||||
space = TRY(space.to_primitive_string(vm));
|
||||
}
|
||||
|
||||
if (space.is_number()) {
|
||||
auto space_mv = MUST(space.to_integer_or_infinity(global_object));
|
||||
auto space_mv = MUST(space.to_integer_or_infinity(vm));
|
||||
space_mv = min(10, space_mv);
|
||||
state.gap = space_mv < 1 ? String::empty() : String::repeated(' ', space_mv);
|
||||
} else if (space.is_string()) {
|
||||
|
@ -134,7 +135,7 @@ ThrowCompletionOr<String> JSONObject::serialize_json_property(GlobalObject& glob
|
|||
// 2. If Type(value) is Object or BigInt, then
|
||||
if (value.is_object() || value.is_bigint()) {
|
||||
// a. Let toJSON be ? GetV(value, "toJSON").
|
||||
auto to_json = TRY(value.get(global_object, vm.names.toJSON));
|
||||
auto to_json = TRY(value.get(vm, vm.names.toJSON));
|
||||
|
||||
// b. If IsCallable(toJSON) is true, then
|
||||
if (to_json.is_function()) {
|
||||
|
@ -156,12 +157,12 @@ ThrowCompletionOr<String> JSONObject::serialize_json_property(GlobalObject& glob
|
|||
// a. If value has a [[NumberData]] internal slot, then
|
||||
if (is<NumberObject>(value_object)) {
|
||||
// i. Set value to ? ToNumber(value).
|
||||
value = TRY(value.to_number(global_object));
|
||||
value = TRY(value.to_number(vm));
|
||||
}
|
||||
// b. Else if value has a [[StringData]] internal slot, then
|
||||
else if (is<StringObject>(value_object)) {
|
||||
// i. Set value to ? ToString(value).
|
||||
value = TRY(value.to_primitive_string(global_object));
|
||||
value = TRY(value.to_primitive_string(vm));
|
||||
}
|
||||
// c. Else if value has a [[BooleanData]] internal slot, then
|
||||
else if (is<BooleanObject>(value_object)) {
|
||||
|
@ -192,7 +193,7 @@ ThrowCompletionOr<String> JSONObject::serialize_json_property(GlobalObject& glob
|
|||
if (value.is_number()) {
|
||||
// a. If value is finite, return ! ToString(value).
|
||||
if (value.is_finite_number())
|
||||
return MUST(value.to_string(global_object));
|
||||
return MUST(value.to_string(vm));
|
||||
|
||||
// b. Return "null".
|
||||
return "null"sv;
|
||||
|
@ -205,7 +206,7 @@ ThrowCompletionOr<String> JSONObject::serialize_json_property(GlobalObject& glob
|
|||
// 11. If Type(value) is Object and IsCallable(value) is false, then
|
||||
if (value.is_object() && !value.is_function()) {
|
||||
// a. Let isArray be ? IsArray(value).
|
||||
auto is_array = TRY(value.is_array(global_object));
|
||||
auto is_array = TRY(value.is_array(vm));
|
||||
|
||||
// b. If isArray is true, return ? SerializeJSONArray(state, value).
|
||||
if (is_array)
|
||||
|
@ -396,7 +397,7 @@ JS_DEFINE_NATIVE_FUNCTION(JSONObject::parse)
|
|||
{
|
||||
auto& realm = *global_object.associated_realm();
|
||||
|
||||
auto string = TRY(vm.argument(0).to_string(global_object));
|
||||
auto string = TRY(vm.argument(0).to_string(vm));
|
||||
auto reviver = vm.argument(1);
|
||||
|
||||
auto json = JsonValue::from_string(string);
|
||||
|
@ -458,7 +459,7 @@ ThrowCompletionOr<Value> JSONObject::internalize_json_property(GlobalObject& glo
|
|||
auto& vm = global_object.vm();
|
||||
auto value = TRY(holder->get(name));
|
||||
if (value.is_object()) {
|
||||
auto is_array = TRY(value.is_array(global_object));
|
||||
auto is_array = TRY(value.is_array(vm));
|
||||
|
||||
auto& value_object = value.as_object();
|
||||
auto process_property = [&](PropertyKey const& key) -> ThrowCompletionOr<void> {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2020, Linus Groh <linusg@serenityos.org>
|
||||
* Copyright (c) 2020-2022, Linus Groh <linusg@serenityos.org>
|
||||
* Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
|
@ -78,7 +78,7 @@ void MathObject::initialize(Realm& realm)
|
|||
// 21.3.2.1 Math.abs ( x ), https://tc39.es/ecma262/#sec-math.abs
|
||||
JS_DEFINE_NATIVE_FUNCTION(MathObject::abs)
|
||||
{
|
||||
auto number = TRY(vm.argument(0).to_number(global_object));
|
||||
auto number = TRY(vm.argument(0).to_number(vm));
|
||||
if (number.is_nan())
|
||||
return js_nan();
|
||||
if (number.is_negative_zero())
|
||||
|
@ -98,7 +98,7 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::random)
|
|||
// 21.3.2.32 Math.sqrt ( x ), https://tc39.es/ecma262/#sec-math.sqrt
|
||||
JS_DEFINE_NATIVE_FUNCTION(MathObject::sqrt)
|
||||
{
|
||||
auto number = TRY(vm.argument(0).to_number(global_object));
|
||||
auto number = TRY(vm.argument(0).to_number(vm));
|
||||
if (number.is_nan())
|
||||
return js_nan();
|
||||
return Value(::sqrt(number.as_double()));
|
||||
|
@ -107,7 +107,7 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::sqrt)
|
|||
// 21.3.2.16 Math.floor ( x ), https://tc39.es/ecma262/#sec-math.floor
|
||||
JS_DEFINE_NATIVE_FUNCTION(MathObject::floor)
|
||||
{
|
||||
auto number = TRY(vm.argument(0).to_number(global_object));
|
||||
auto number = TRY(vm.argument(0).to_number(vm));
|
||||
if (number.is_nan())
|
||||
return js_nan();
|
||||
return Value(::floor(number.as_double()));
|
||||
|
@ -116,7 +116,7 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::floor)
|
|||
// 21.3.2.10 Math.ceil ( x ), https://tc39.es/ecma262/#sec-math.ceil
|
||||
JS_DEFINE_NATIVE_FUNCTION(MathObject::ceil)
|
||||
{
|
||||
auto number = TRY(vm.argument(0).to_number(global_object));
|
||||
auto number = TRY(vm.argument(0).to_number(vm));
|
||||
if (number.is_nan())
|
||||
return js_nan();
|
||||
auto number_double = number.as_double();
|
||||
|
@ -128,7 +128,7 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::ceil)
|
|||
// 21.3.2.28 Math.round ( x ), https://tc39.es/ecma262/#sec-math.round
|
||||
JS_DEFINE_NATIVE_FUNCTION(MathObject::round)
|
||||
{
|
||||
auto value = TRY(vm.argument(0).to_number(global_object)).as_double();
|
||||
auto value = TRY(vm.argument(0).to_number(vm)).as_double();
|
||||
double integer = ::ceil(value);
|
||||
if (integer - 0.5 > value)
|
||||
integer--;
|
||||
|
@ -140,7 +140,7 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::max)
|
|||
{
|
||||
Vector<Value> coerced;
|
||||
for (size_t i = 0; i < vm.argument_count(); ++i)
|
||||
coerced.append(TRY(vm.argument(i).to_number(global_object)));
|
||||
coerced.append(TRY(vm.argument(i).to_number(vm)));
|
||||
|
||||
auto highest = js_negative_infinity();
|
||||
for (auto& number : coerced) {
|
||||
|
@ -157,7 +157,7 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::min)
|
|||
{
|
||||
Vector<Value> coerced;
|
||||
for (size_t i = 0; i < vm.argument_count(); ++i)
|
||||
coerced.append(TRY(vm.argument(i).to_number(global_object)));
|
||||
coerced.append(TRY(vm.argument(i).to_number(vm)));
|
||||
|
||||
auto lowest = js_infinity();
|
||||
for (auto& number : coerced) {
|
||||
|
@ -172,7 +172,7 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::min)
|
|||
// 21.3.2.35 Math.trunc ( x ), https://tc39.es/ecma262/#sec-math.trunc
|
||||
JS_DEFINE_NATIVE_FUNCTION(MathObject::trunc)
|
||||
{
|
||||
auto number = TRY(vm.argument(0).to_number(global_object));
|
||||
auto number = TRY(vm.argument(0).to_number(vm));
|
||||
if (number.is_nan())
|
||||
return js_nan();
|
||||
if (number.as_double() < 0)
|
||||
|
@ -184,7 +184,7 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::trunc)
|
|||
JS_DEFINE_NATIVE_FUNCTION(MathObject::sin)
|
||||
{
|
||||
// 1. Let n be ? ToNumber(x).
|
||||
auto number = TRY(vm.argument(0).to_number(global_object));
|
||||
auto number = TRY(vm.argument(0).to_number(vm));
|
||||
// 2. If n is NaN, n is +0𝔽, or n is -0𝔽, return n.
|
||||
if (number.is_nan() || number.is_positive_zero() || number.is_negative_zero())
|
||||
return number;
|
||||
|
@ -201,7 +201,7 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::sin)
|
|||
JS_DEFINE_NATIVE_FUNCTION(MathObject::cos)
|
||||
{
|
||||
// 1. Let n be ? ToNumber(x).
|
||||
auto number = TRY(vm.argument(0).to_number(global_object));
|
||||
auto number = TRY(vm.argument(0).to_number(vm));
|
||||
|
||||
// 2. If n is NaN, n is +∞𝔽, or n is -∞𝔽, return NaN.
|
||||
if (number.is_nan() || number.is_infinity())
|
||||
|
@ -219,7 +219,7 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::cos)
|
|||
JS_DEFINE_NATIVE_FUNCTION(MathObject::tan)
|
||||
{
|
||||
// Let n be ? ToNumber(x).
|
||||
auto number = TRY(vm.argument(0).to_number(global_object));
|
||||
auto number = TRY(vm.argument(0).to_number(vm));
|
||||
|
||||
// 2. If n is NaN, n is +0𝔽, or n is -0𝔽, return n.
|
||||
if (number.is_nan() || number.is_positive_zero() || number.is_negative_zero())
|
||||
|
@ -236,15 +236,15 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::tan)
|
|||
// 21.3.2.26 Math.pow ( base, exponent ), https://tc39.es/ecma262/#sec-math.pow
|
||||
JS_DEFINE_NATIVE_FUNCTION(MathObject::pow)
|
||||
{
|
||||
auto base = TRY(vm.argument(0).to_number(global_object));
|
||||
auto exponent = TRY(vm.argument(1).to_number(global_object));
|
||||
return JS::exp(global_object, base, exponent);
|
||||
auto base = TRY(vm.argument(0).to_number(vm));
|
||||
auto exponent = TRY(vm.argument(1).to_number(vm));
|
||||
return JS::exp(vm, base, exponent);
|
||||
}
|
||||
|
||||
// 21.3.2.14 Math.exp ( x ), https://tc39.es/ecma262/#sec-math.exp
|
||||
JS_DEFINE_NATIVE_FUNCTION(MathObject::exp)
|
||||
{
|
||||
auto number = TRY(vm.argument(0).to_number(global_object));
|
||||
auto number = TRY(vm.argument(0).to_number(vm));
|
||||
if (number.is_nan())
|
||||
return js_nan();
|
||||
return Value(::exp(number.as_double()));
|
||||
|
@ -253,7 +253,7 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::exp)
|
|||
// 21.3.2.15 Math.expm1 ( x ), https://tc39.es/ecma262/#sec-math.expm1
|
||||
JS_DEFINE_NATIVE_FUNCTION(MathObject::expm1)
|
||||
{
|
||||
auto number = TRY(vm.argument(0).to_number(global_object));
|
||||
auto number = TRY(vm.argument(0).to_number(vm));
|
||||
if (number.is_nan())
|
||||
return js_nan();
|
||||
return Value(::expm1(number.as_double()));
|
||||
|
@ -262,7 +262,7 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::expm1)
|
|||
// 21.3.2.29 Math.sign ( x ), https://tc39.es/ecma262/#sec-math.sign
|
||||
JS_DEFINE_NATIVE_FUNCTION(MathObject::sign)
|
||||
{
|
||||
auto number = TRY(vm.argument(0).to_number(global_object));
|
||||
auto number = TRY(vm.argument(0).to_number(vm));
|
||||
if (number.is_positive_zero())
|
||||
return Value(0);
|
||||
if (number.is_negative_zero())
|
||||
|
@ -277,7 +277,7 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::sign)
|
|||
// 21.3.2.11 Math.clz32 ( x ), https://tc39.es/ecma262/#sec-math.clz32
|
||||
JS_DEFINE_NATIVE_FUNCTION(MathObject::clz32)
|
||||
{
|
||||
auto number = TRY(vm.argument(0).to_u32(global_object));
|
||||
auto number = TRY(vm.argument(0).to_u32(vm));
|
||||
if (number == 0)
|
||||
return Value(32);
|
||||
return Value(count_leading_zeroes(number));
|
||||
|
@ -286,7 +286,7 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::clz32)
|
|||
// 21.3.2.2 Math.acos ( x ), https://tc39.es/ecma262/#sec-math.acos
|
||||
JS_DEFINE_NATIVE_FUNCTION(MathObject::acos)
|
||||
{
|
||||
auto number = TRY(vm.argument(0).to_number(global_object));
|
||||
auto number = TRY(vm.argument(0).to_number(vm));
|
||||
if (number.is_nan() || number.as_double() > 1 || number.as_double() < -1)
|
||||
return js_nan();
|
||||
if (number.as_double() == 1)
|
||||
|
@ -297,7 +297,7 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::acos)
|
|||
// 21.3.2.3 Math.acosh ( x ), https://tc39.es/ecma262/#sec-math.acosh
|
||||
JS_DEFINE_NATIVE_FUNCTION(MathObject::acosh)
|
||||
{
|
||||
auto value = TRY(vm.argument(0).to_number(global_object)).as_double();
|
||||
auto value = TRY(vm.argument(0).to_number(vm)).as_double();
|
||||
if (value < 1)
|
||||
return js_nan();
|
||||
return Value(::acosh(value));
|
||||
|
@ -306,7 +306,7 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::acosh)
|
|||
// 21.3.2.4 Math.asin ( x ), https://tc39.es/ecma262/#sec-math.asin
|
||||
JS_DEFINE_NATIVE_FUNCTION(MathObject::asin)
|
||||
{
|
||||
auto number = TRY(vm.argument(0).to_number(global_object));
|
||||
auto number = TRY(vm.argument(0).to_number(vm));
|
||||
if (number.is_nan() || number.is_positive_zero() || number.is_negative_zero())
|
||||
return number;
|
||||
return Value(::asin(number.as_double()));
|
||||
|
@ -315,13 +315,13 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::asin)
|
|||
// 21.3.2.5 Math.asinh ( x ), https://tc39.es/ecma262/#sec-math.asinh
|
||||
JS_DEFINE_NATIVE_FUNCTION(MathObject::asinh)
|
||||
{
|
||||
return Value(::asinh(TRY(vm.argument(0).to_number(global_object)).as_double()));
|
||||
return Value(::asinh(TRY(vm.argument(0).to_number(vm)).as_double()));
|
||||
}
|
||||
|
||||
// 21.3.2.6 Math.atan ( x ), https://tc39.es/ecma262/#sec-math.atan
|
||||
JS_DEFINE_NATIVE_FUNCTION(MathObject::atan)
|
||||
{
|
||||
auto number = TRY(vm.argument(0).to_number(global_object));
|
||||
auto number = TRY(vm.argument(0).to_number(vm));
|
||||
if (number.is_nan() || number.is_positive_zero() || number.is_negative_zero())
|
||||
return number;
|
||||
if (number.is_positive_infinity())
|
||||
|
@ -334,7 +334,7 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::atan)
|
|||
// 21.3.2.7 Math.atanh ( x ), https://tc39.es/ecma262/#sec-math.atanh
|
||||
JS_DEFINE_NATIVE_FUNCTION(MathObject::atanh)
|
||||
{
|
||||
auto value = TRY(vm.argument(0).to_number(global_object)).as_double();
|
||||
auto value = TRY(vm.argument(0).to_number(vm)).as_double();
|
||||
if (value > 1 || value < -1)
|
||||
return js_nan();
|
||||
return Value(::atanh(value));
|
||||
|
@ -343,7 +343,7 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::atanh)
|
|||
// 21.3.2.21 Math.log1p ( x ), https://tc39.es/ecma262/#sec-math.log1p
|
||||
JS_DEFINE_NATIVE_FUNCTION(MathObject::log1p)
|
||||
{
|
||||
auto value = TRY(vm.argument(0).to_number(global_object)).as_double();
|
||||
auto value = TRY(vm.argument(0).to_number(vm)).as_double();
|
||||
if (value < -1)
|
||||
return js_nan();
|
||||
return Value(::log1p(value));
|
||||
|
@ -352,7 +352,7 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::log1p)
|
|||
// 21.3.2.9 Math.cbrt ( x ), https://tc39.es/ecma262/#sec-math.cbrt
|
||||
JS_DEFINE_NATIVE_FUNCTION(MathObject::cbrt)
|
||||
{
|
||||
return Value(::cbrt(TRY(vm.argument(0).to_number(global_object)).as_double()));
|
||||
return Value(::cbrt(TRY(vm.argument(0).to_number(vm)).as_double()));
|
||||
}
|
||||
|
||||
// 21.3.2.8 Math.atan2 ( y, x ), https://tc39.es/ecma262/#sec-math.atan2
|
||||
|
@ -360,8 +360,8 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::atan2)
|
|||
{
|
||||
auto constexpr three_quarters_pi = M_PI_4 + M_PI_2;
|
||||
|
||||
auto y = TRY(vm.argument(0).to_number(global_object));
|
||||
auto x = TRY(vm.argument(1).to_number(global_object));
|
||||
auto y = TRY(vm.argument(0).to_number(vm));
|
||||
auto x = TRY(vm.argument(1).to_number(vm));
|
||||
|
||||
if (y.is_nan() || x.is_nan())
|
||||
return js_nan();
|
||||
|
@ -417,7 +417,7 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::atan2)
|
|||
// 21.3.2.17 Math.fround ( x ), https://tc39.es/ecma262/#sec-math.fround
|
||||
JS_DEFINE_NATIVE_FUNCTION(MathObject::fround)
|
||||
{
|
||||
auto number = TRY(vm.argument(0).to_number(global_object));
|
||||
auto number = TRY(vm.argument(0).to_number(vm));
|
||||
if (number.is_nan())
|
||||
return js_nan();
|
||||
return Value((float)number.as_double());
|
||||
|
@ -428,7 +428,7 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::hypot)
|
|||
{
|
||||
Vector<Value> coerced;
|
||||
for (size_t i = 0; i < vm.argument_count(); ++i)
|
||||
coerced.append(TRY(vm.argument(i).to_number(global_object)));
|
||||
coerced.append(TRY(vm.argument(i).to_number(vm)));
|
||||
|
||||
for (auto& number : coerced) {
|
||||
if (number.is_positive_infinity() || number.is_negative_infinity())
|
||||
|
@ -454,15 +454,15 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::hypot)
|
|||
// 21.3.2.19 Math.imul ( x, y ), https://tc39.es/ecma262/#sec-math.imul
|
||||
JS_DEFINE_NATIVE_FUNCTION(MathObject::imul)
|
||||
{
|
||||
auto a = TRY(vm.argument(0).to_u32(global_object));
|
||||
auto b = TRY(vm.argument(1).to_u32(global_object));
|
||||
auto a = TRY(vm.argument(0).to_u32(vm));
|
||||
auto b = TRY(vm.argument(1).to_u32(vm));
|
||||
return Value(static_cast<i32>(a * b));
|
||||
}
|
||||
|
||||
// 21.3.2.20 Math.log ( x ), https://tc39.es/ecma262/#sec-math.log
|
||||
JS_DEFINE_NATIVE_FUNCTION(MathObject::log)
|
||||
{
|
||||
auto value = TRY(vm.argument(0).to_number(global_object)).as_double();
|
||||
auto value = TRY(vm.argument(0).to_number(vm)).as_double();
|
||||
if (value < 0)
|
||||
return js_nan();
|
||||
return Value(::log(value));
|
||||
|
@ -471,7 +471,7 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::log)
|
|||
// 21.3.2.23 Math.log2 ( x ), https://tc39.es/ecma262/#sec-math.log2
|
||||
JS_DEFINE_NATIVE_FUNCTION(MathObject::log2)
|
||||
{
|
||||
auto value = TRY(vm.argument(0).to_number(global_object)).as_double();
|
||||
auto value = TRY(vm.argument(0).to_number(vm)).as_double();
|
||||
if (value < 0)
|
||||
return js_nan();
|
||||
return Value(::log2(value));
|
||||
|
@ -480,7 +480,7 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::log2)
|
|||
// 21.3.2.22 Math.log10 ( x ), https://tc39.es/ecma262/#sec-math.log10
|
||||
JS_DEFINE_NATIVE_FUNCTION(MathObject::log10)
|
||||
{
|
||||
auto value = TRY(vm.argument(0).to_number(global_object)).as_double();
|
||||
auto value = TRY(vm.argument(0).to_number(vm)).as_double();
|
||||
if (value < 0)
|
||||
return js_nan();
|
||||
return Value(::log10(value));
|
||||
|
@ -489,7 +489,7 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::log10)
|
|||
// 21.3.2.31 Math.sinh ( x ), https://tc39.es/ecma262/#sec-math.sinh
|
||||
JS_DEFINE_NATIVE_FUNCTION(MathObject::sinh)
|
||||
{
|
||||
auto number = TRY(vm.argument(0).to_number(global_object));
|
||||
auto number = TRY(vm.argument(0).to_number(vm));
|
||||
if (number.is_nan())
|
||||
return js_nan();
|
||||
return Value(::sinh(number.as_double()));
|
||||
|
@ -499,7 +499,7 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::sinh)
|
|||
JS_DEFINE_NATIVE_FUNCTION(MathObject::cosh)
|
||||
{
|
||||
// 1. Let n be ? ToNumber(x).
|
||||
auto number = TRY(vm.argument(0).to_number(global_object));
|
||||
auto number = TRY(vm.argument(0).to_number(vm));
|
||||
|
||||
// 2. If n is NaN, return NaN.
|
||||
if (number.is_nan())
|
||||
|
@ -520,7 +520,7 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::cosh)
|
|||
// 21.3.2.34 Math.tanh ( x ), https://tc39.es/ecma262/#sec-math.tanh
|
||||
JS_DEFINE_NATIVE_FUNCTION(MathObject::tanh)
|
||||
{
|
||||
auto number = TRY(vm.argument(0).to_number(global_object));
|
||||
auto number = TRY(vm.argument(0).to_number(vm));
|
||||
if (number.is_nan())
|
||||
return js_nan();
|
||||
if (number.is_positive_infinity())
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2020-2021, Linus Groh <linusg@serenityos.org>
|
||||
* Copyright (c) 2020-2022, Linus Groh <linusg@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -63,7 +63,7 @@ static ThrowCompletionOr<Value> get_value_from_constructor_argument(GlobalObject
|
|||
|
||||
Value number;
|
||||
if (vm.argument_count() > 0) {
|
||||
auto primitive = TRY(vm.argument(0).to_numeric(global_object));
|
||||
auto primitive = TRY(vm.argument(0).to_numeric(vm));
|
||||
if (primitive.is_bigint()) {
|
||||
// FIXME: How should huge values be handled here?
|
||||
auto& big_integer = primitive.as_bigint().big_integer();
|
||||
|
|
|
@ -131,14 +131,14 @@ JS_DEFINE_NATIVE_FUNCTION(NumberPrototype::to_exponential)
|
|||
auto number_value = TRY(this_number_value(global_object, vm.this_value()));
|
||||
|
||||
// 2. Let f be ? ToIntegerOrInfinity(fractionDigits).
|
||||
auto fraction_digits = TRY(fraction_digits_value.to_integer_or_infinity(global_object));
|
||||
auto fraction_digits = TRY(fraction_digits_value.to_integer_or_infinity(vm));
|
||||
|
||||
// 3. Assert: If fractionDigits is undefined, then f is 0.
|
||||
VERIFY(!fraction_digits_value.is_undefined() || (fraction_digits == 0));
|
||||
|
||||
// 4. If x is not finite, return Number::toString(x).
|
||||
if (!number_value.is_finite_number())
|
||||
return js_string(vm, MUST(number_value.to_string(global_object)));
|
||||
return js_string(vm, MUST(number_value.to_string(vm)));
|
||||
|
||||
// 5. If f < 0 or f > 100, throw a RangeError exception.
|
||||
if (fraction_digits < 0 || fraction_digits > 100)
|
||||
|
@ -251,7 +251,7 @@ JS_DEFINE_NATIVE_FUNCTION(NumberPrototype::to_fixed)
|
|||
|
||||
// 2. Let f be ? ToIntegerOrInfinity(fractionDigits).
|
||||
// 3. Assert: If fractionDigits is undefined, then f is 0.
|
||||
auto fraction_digits = TRY(vm.argument(0).to_integer_or_infinity(global_object));
|
||||
auto fraction_digits = TRY(vm.argument(0).to_integer_or_infinity(vm));
|
||||
|
||||
// 4. If f is not finite, throw a RangeError exception.
|
||||
if (!Value(fraction_digits).is_finite_number())
|
||||
|
@ -263,7 +263,7 @@ JS_DEFINE_NATIVE_FUNCTION(NumberPrototype::to_fixed)
|
|||
|
||||
// 6. If x is not finite, return Number::toString(x).
|
||||
if (!number_value.is_finite_number())
|
||||
return js_string(vm, TRY(number_value.to_string(global_object)));
|
||||
return js_string(vm, TRY(number_value.to_string(vm)));
|
||||
|
||||
// 7. Set x to ℝ(x).
|
||||
auto number = number_value.as_double();
|
||||
|
@ -278,7 +278,7 @@ JS_DEFINE_NATIVE_FUNCTION(NumberPrototype::to_fixed)
|
|||
|
||||
// 10. If x ≥ 10^21, then
|
||||
if (fabs(number) >= 1e+21)
|
||||
return js_string(vm, MUST(number_value.to_string(global_object)));
|
||||
return js_string(vm, MUST(number_value.to_string(vm)));
|
||||
|
||||
// 11. Else,
|
||||
// a. Let n be an integer for which n / (10^f) - x is as close to zero as possible. If there are two such n, pick the larger n.
|
||||
|
@ -345,14 +345,14 @@ JS_DEFINE_NATIVE_FUNCTION(NumberPrototype::to_precision)
|
|||
|
||||
// 2. If precision is undefined, return ! ToString(x).
|
||||
if (precision_value.is_undefined())
|
||||
return js_string(vm, MUST(number_value.to_string(global_object)));
|
||||
return js_string(vm, MUST(number_value.to_string(vm)));
|
||||
|
||||
// 3. Let p be ? ToIntegerOrInfinity(precision).
|
||||
auto precision = TRY(precision_value.to_integer_or_infinity(global_object));
|
||||
auto precision = TRY(precision_value.to_integer_or_infinity(vm));
|
||||
|
||||
// 4. If x is not finite, return Number::toString(x).
|
||||
if (!number_value.is_finite_number())
|
||||
return js_string(vm, MUST(number_value.to_string(global_object)));
|
||||
return js_string(vm, MUST(number_value.to_string(vm)));
|
||||
|
||||
// 5. If p < 1 or p > 100, throw a RangeError exception.
|
||||
if ((precision < 1) || (precision > 100))
|
||||
|
@ -480,7 +480,7 @@ JS_DEFINE_NATIVE_FUNCTION(NumberPrototype::to_string)
|
|||
radix_mv = 10;
|
||||
// 3. Else, let radixMV be ? ToIntegerOrInfinity(radix).
|
||||
else
|
||||
radix_mv = TRY(vm.argument(0).to_integer_or_infinity(global_object));
|
||||
radix_mv = TRY(vm.argument(0).to_integer_or_infinity(vm));
|
||||
|
||||
// 4. If radixMV < 2 or radixMV > 36, throw a RangeError exception.
|
||||
if (radix_mv < 2 || radix_mv > 36)
|
||||
|
@ -488,7 +488,7 @@ JS_DEFINE_NATIVE_FUNCTION(NumberPrototype::to_string)
|
|||
|
||||
// 5. If radixMV = 10, return ! ToString(x).
|
||||
if (radix_mv == 10)
|
||||
return js_string(vm, MUST(number_value.to_string(global_object)));
|
||||
return js_string(vm, MUST(number_value.to_string(vm)));
|
||||
|
||||
// 6. Return the String representation of this Number value using the radix specified by radixMV. Letters a-z are used for digits with values 10 through 35. The precise algorithm is implementation-defined, however the algorithm should be a generalization of that specified in 6.1.6.1.20.
|
||||
if (number_value.is_positive_infinity())
|
||||
|
|
|
@ -262,7 +262,7 @@ ThrowCompletionOr<bool> Object::has_own_property(PropertyKey const& property_key
|
|||
// 7.3.16 SetIntegrityLevel ( O, level ), https://tc39.es/ecma262/#sec-setintegritylevel
|
||||
ThrowCompletionOr<bool> Object::set_integrity_level(IntegrityLevel level)
|
||||
{
|
||||
auto& global_object = this->global_object();
|
||||
auto& vm = this->vm();
|
||||
|
||||
// 1. Let status be ? O.[[PreventExtensions]]().
|
||||
auto status = TRY(internal_prevent_extensions());
|
||||
|
@ -278,7 +278,7 @@ ThrowCompletionOr<bool> Object::set_integrity_level(IntegrityLevel level)
|
|||
if (level == IntegrityLevel::Sealed) {
|
||||
// a. For each element k of keys, do
|
||||
for (auto& key : keys) {
|
||||
auto property_key = MUST(PropertyKey::from_value(global_object, key));
|
||||
auto property_key = MUST(PropertyKey::from_value(vm, key));
|
||||
|
||||
// i. Perform ? DefinePropertyOrThrow(O, k, PropertyDescriptor { [[Configurable]]: false }).
|
||||
TRY(define_property_or_throw(property_key, { .configurable = false }));
|
||||
|
@ -290,7 +290,7 @@ ThrowCompletionOr<bool> Object::set_integrity_level(IntegrityLevel level)
|
|||
|
||||
// b. For each element k of keys, do
|
||||
for (auto& key : keys) {
|
||||
auto property_key = MUST(PropertyKey::from_value(global_object, key));
|
||||
auto property_key = MUST(PropertyKey::from_value(vm, key));
|
||||
|
||||
// i. Let currentDesc be ? O.[[GetOwnProperty]](k).
|
||||
auto current_descriptor = TRY(internal_get_own_property(property_key));
|
||||
|
@ -324,6 +324,8 @@ ThrowCompletionOr<bool> Object::set_integrity_level(IntegrityLevel level)
|
|||
// 7.3.17 TestIntegrityLevel ( O, level ), https://tc39.es/ecma262/#sec-testintegritylevel
|
||||
ThrowCompletionOr<bool> Object::test_integrity_level(IntegrityLevel level) const
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
|
||||
// 1. Let extensible be ? IsExtensible(O).
|
||||
auto extensible = TRY(is_extensible());
|
||||
|
||||
|
@ -337,7 +339,7 @@ ThrowCompletionOr<bool> Object::test_integrity_level(IntegrityLevel level) const
|
|||
|
||||
// 5. For each element k of keys, do
|
||||
for (auto& key : keys) {
|
||||
auto property_key = MUST(PropertyKey::from_value(global_object(), key));
|
||||
auto property_key = MUST(PropertyKey::from_value(vm, key));
|
||||
|
||||
// a. Let currentDesc be ? O.[[GetOwnProperty]](k).
|
||||
auto current_descriptor = TRY(internal_get_own_property(property_key));
|
||||
|
@ -368,6 +370,7 @@ ThrowCompletionOr<MarkedVector<Value>> Object::enumerable_own_property_names(Pro
|
|||
// spec text have been replaced with `continue`s in the loop below.
|
||||
|
||||
auto& global_object = this->global_object();
|
||||
auto& vm = this->vm();
|
||||
auto& realm = *global_object.associated_realm();
|
||||
|
||||
// 1. Let ownKeys be ? O.[[OwnPropertyKeys]]().
|
||||
|
@ -381,7 +384,7 @@ ThrowCompletionOr<MarkedVector<Value>> Object::enumerable_own_property_names(Pro
|
|||
// a. If Type(key) is String, then
|
||||
if (!key.is_string())
|
||||
continue;
|
||||
auto property_key = MUST(PropertyKey::from_value(global_object, key));
|
||||
auto property_key = MUST(PropertyKey::from_value(vm, key));
|
||||
|
||||
// i. Let desc be ? O.[[GetOwnProperty]](key).
|
||||
auto descriptor = TRY(internal_get_own_property(property_key));
|
||||
|
@ -421,15 +424,15 @@ ThrowCompletionOr<MarkedVector<Value>> Object::enumerable_own_property_names(Pro
|
|||
}
|
||||
|
||||
// 7.3.26 CopyDataProperties ( target, source, excludedItems ), https://tc39.es/ecma262/#sec-copydataproperties
|
||||
ThrowCompletionOr<void> Object::copy_data_properties(Value source, HashTable<PropertyKey> const& seen_names, GlobalObject& global_object)
|
||||
ThrowCompletionOr<void> Object::copy_data_properties(VM& vm, Value source, HashTable<PropertyKey> const& seen_names)
|
||||
{
|
||||
if (source.is_nullish())
|
||||
return {};
|
||||
|
||||
auto* from_object = MUST(source.to_object(global_object));
|
||||
auto* from_object = MUST(source.to_object(vm));
|
||||
|
||||
for (auto& next_key_value : TRY(from_object->internal_own_property_keys())) {
|
||||
auto next_key = MUST(PropertyKey::from_value(global_object, next_key_value));
|
||||
auto next_key = MUST(PropertyKey::from_value(vm, next_key_value));
|
||||
if (seen_names.contains(next_key))
|
||||
continue;
|
||||
|
||||
|
@ -1121,9 +1124,10 @@ void Object::define_native_function(PropertyKey const& property_key, Function<Th
|
|||
ThrowCompletionOr<Object*> Object::define_properties(Value properties)
|
||||
{
|
||||
auto& global_object = this->global_object();
|
||||
auto& vm = this->vm();
|
||||
|
||||
// 1. Let props be ? ToObject(Properties).
|
||||
auto* props = TRY(properties.to_object(global_object));
|
||||
auto* props = TRY(properties.to_object(vm));
|
||||
|
||||
// 2. Let keys be ? props.[[OwnPropertyKeys]]().
|
||||
auto keys = TRY(props->internal_own_property_keys());
|
||||
|
@ -1138,7 +1142,7 @@ ThrowCompletionOr<Object*> Object::define_properties(Value properties)
|
|||
|
||||
// 4. For each element nextKey of keys, do
|
||||
for (auto& next_key : keys) {
|
||||
auto property_key = MUST(PropertyKey::from_value(global_object, next_key));
|
||||
auto property_key = MUST(PropertyKey::from_value(vm, next_key));
|
||||
|
||||
// a. Let propDesc be ? props.[[GetOwnProperty]](nextKey).
|
||||
auto property_descriptor = TRY(props->internal_get_own_property(property_key));
|
||||
|
|
|
@ -106,7 +106,7 @@ public:
|
|||
ThrowCompletionOr<bool> set_integrity_level(IntegrityLevel);
|
||||
ThrowCompletionOr<bool> test_integrity_level(IntegrityLevel) const;
|
||||
ThrowCompletionOr<MarkedVector<Value>> enumerable_own_property_names(PropertyKind kind) const;
|
||||
ThrowCompletionOr<void> copy_data_properties(Value source, HashTable<PropertyKey> const& seen_names, GlobalObject& global_object);
|
||||
ThrowCompletionOr<void> copy_data_properties(VM&, Value source, HashTable<PropertyKey> const& seen_names);
|
||||
|
||||
PrivateElement* private_element_find(PrivateName const& name);
|
||||
ThrowCompletionOr<void> private_field_add(PrivateName const& name, Value value);
|
||||
|
|
|
@ -75,7 +75,7 @@ ThrowCompletionOr<Object*> ObjectConstructor::construct(FunctionObject& new_targ
|
|||
auto value = vm.argument(0);
|
||||
if (value.is_nullish())
|
||||
return Object::create(realm, global_object.object_prototype());
|
||||
return value.to_object(global_object);
|
||||
return value.to_object(vm);
|
||||
}
|
||||
|
||||
enum class GetOwnPropertyKeysType {
|
||||
|
@ -89,7 +89,7 @@ static ThrowCompletionOr<MarkedVector<Value>> get_own_property_keys(GlobalObject
|
|||
auto& vm = global_object.vm();
|
||||
|
||||
// 1. Let obj be ? ToObject(O).
|
||||
auto* object = TRY(value.to_object(global_object));
|
||||
auto* object = TRY(value.to_object(vm));
|
||||
|
||||
// 2. Let keys be ? obj.[[OwnPropertyKeys]]().
|
||||
auto keys = TRY(object->internal_own_property_keys());
|
||||
|
@ -132,7 +132,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::get_own_property_symbols)
|
|||
JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::get_prototype_of)
|
||||
{
|
||||
// 1. Let obj be ? ToObject(O).
|
||||
auto* object = TRY(vm.argument(0).to_object(global_object));
|
||||
auto* object = TRY(vm.argument(0).to_object(vm));
|
||||
|
||||
// 2. Return ? obj.[[GetPrototypeOf]]().
|
||||
return TRY(object->internal_get_prototype_of());
|
||||
|
@ -235,7 +235,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::from_entries)
|
|||
auto key = TRY(iterator_value.as_object().get(0));
|
||||
auto value = TRY(iterator_value.as_object().get(1));
|
||||
|
||||
auto property_key = TRY(key.to_property_key(global_object));
|
||||
auto property_key = TRY(key.to_property_key(vm));
|
||||
MUST(object->create_data_property_or_throw(property_key, value));
|
||||
|
||||
return {};
|
||||
|
@ -259,8 +259,8 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::seal)
|
|||
// 20.1.2.8 Object.getOwnPropertyDescriptor ( O, P ), https://tc39.es/ecma262/#sec-object.getownpropertydescriptor
|
||||
JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::get_own_property_descriptor)
|
||||
{
|
||||
auto* object = TRY(vm.argument(0).to_object(global_object));
|
||||
auto key = TRY(vm.argument(1).to_property_key(global_object));
|
||||
auto* object = TRY(vm.argument(0).to_object(vm));
|
||||
auto key = TRY(vm.argument(1).to_property_key(vm));
|
||||
auto descriptor = TRY(object->internal_get_own_property(key));
|
||||
return from_property_descriptor(global_object, descriptor);
|
||||
}
|
||||
|
@ -271,7 +271,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::get_own_property_descriptors)
|
|||
auto& realm = *global_object.associated_realm();
|
||||
|
||||
// 1. Let obj be ? ToObject(O).
|
||||
auto* object = TRY(vm.argument(0).to_object(global_object));
|
||||
auto* object = TRY(vm.argument(0).to_object(vm));
|
||||
|
||||
// 2. Let ownKeys be ? obj.[[OwnPropertyKeys]]().
|
||||
auto own_keys = TRY(object->internal_own_property_keys());
|
||||
|
@ -281,7 +281,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::get_own_property_descriptors)
|
|||
|
||||
// 4. For each element key of ownKeys, do
|
||||
for (auto& key : own_keys) {
|
||||
auto property_key = MUST(PropertyKey::from_value(global_object, key));
|
||||
auto property_key = MUST(PropertyKey::from_value(vm, key));
|
||||
|
||||
// a. Let desc be ? obj.[[GetOwnProperty]](key).
|
||||
auto desc = TRY(object->internal_get_own_property(property_key));
|
||||
|
@ -303,7 +303,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::define_property)
|
|||
{
|
||||
if (!vm.argument(0).is_object())
|
||||
return vm.throw_completion<TypeError>(ErrorType::NotAnObject, vm.argument(0).to_string_without_side_effects());
|
||||
auto key = TRY(vm.argument(1).to_property_key(global_object));
|
||||
auto key = TRY(vm.argument(1).to_property_key(vm));
|
||||
auto descriptor = TRY(to_property_descriptor(global_object, vm.argument(2)));
|
||||
TRY(vm.argument(0).as_object().define_property_or_throw(key, descriptor));
|
||||
return vm.argument(0);
|
||||
|
@ -334,7 +334,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::keys)
|
|||
{
|
||||
auto& realm = *global_object.associated_realm();
|
||||
|
||||
auto* object = TRY(vm.argument(0).to_object(global_object));
|
||||
auto* object = TRY(vm.argument(0).to_object(vm));
|
||||
auto name_list = TRY(object->enumerable_own_property_names(PropertyKind::Key));
|
||||
return Array::create_from(realm, name_list);
|
||||
}
|
||||
|
@ -344,7 +344,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::values)
|
|||
{
|
||||
auto& realm = *global_object.associated_realm();
|
||||
|
||||
auto* object = TRY(vm.argument(0).to_object(global_object));
|
||||
auto* object = TRY(vm.argument(0).to_object(vm));
|
||||
auto name_list = TRY(object->enumerable_own_property_names(PropertyKind::Value));
|
||||
return Array::create_from(realm, name_list);
|
||||
}
|
||||
|
@ -354,7 +354,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::entries)
|
|||
{
|
||||
auto& realm = *global_object.associated_realm();
|
||||
|
||||
auto* object = TRY(vm.argument(0).to_object(global_object));
|
||||
auto* object = TRY(vm.argument(0).to_object(vm));
|
||||
auto name_list = TRY(object->enumerable_own_property_names(PropertyKind::KeyAndValue));
|
||||
return Array::create_from(realm, name_list);
|
||||
}
|
||||
|
@ -388,10 +388,10 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::create)
|
|||
JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::has_own)
|
||||
{
|
||||
// 1. Let obj be ? ToObject(O).
|
||||
auto* object = TRY(vm.argument(0).to_object(global_object));
|
||||
auto* object = TRY(vm.argument(0).to_object(vm));
|
||||
|
||||
// 2. Let key be ? ToPropertyKey(P).
|
||||
auto key = TRY(vm.argument(1).to_property_key(global_object));
|
||||
auto key = TRY(vm.argument(1).to_property_key(vm));
|
||||
|
||||
// 3. Return ? HasOwnProperty(obj, key).
|
||||
return Value(TRY(object->has_own_property(key)));
|
||||
|
@ -401,7 +401,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::has_own)
|
|||
JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::assign)
|
||||
{
|
||||
// 1. Let to be ? ToObject(target).
|
||||
auto* to = TRY(vm.argument(0).to_object(global_object));
|
||||
auto* to = TRY(vm.argument(0).to_object(vm));
|
||||
|
||||
// 2. If only one argument was passed, return to.
|
||||
if (vm.argument_count() == 1)
|
||||
|
@ -416,14 +416,14 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::assign)
|
|||
continue;
|
||||
|
||||
// i. Let from be ! ToObject(nextSource).
|
||||
auto* from = MUST(next_source.to_object(global_object));
|
||||
auto* from = MUST(next_source.to_object(vm));
|
||||
|
||||
// ii. Let keys be ? from.[[OwnPropertyKeys]]().
|
||||
auto keys = TRY(from->internal_own_property_keys());
|
||||
|
||||
// iii. For each element nextKey of keys, do
|
||||
for (auto& next_key : keys) {
|
||||
auto property_key = MUST(PropertyKey::from_value(global_object, next_key));
|
||||
auto property_key = MUST(PropertyKey::from_value(vm, next_key));
|
||||
|
||||
// 1. Let desc be ? from.[[GetOwnProperty]](nextKey).
|
||||
auto desc = TRY(from->internal_get_own_property(property_key));
|
||||
|
|
|
@ -58,8 +58,8 @@ ThrowCompletionOr<bool> ObjectPrototype::internal_set_prototype_of(Object* proto
|
|||
// 20.1.3.2 Object.prototype.hasOwnProperty ( V ), https://tc39.es/ecma262/#sec-object.prototype.hasownproperty
|
||||
JS_DEFINE_NATIVE_FUNCTION(ObjectPrototype::has_own_property)
|
||||
{
|
||||
auto property_key = TRY(vm.argument(0).to_property_key(global_object));
|
||||
auto* this_object = TRY(vm.this_value().to_object(global_object));
|
||||
auto property_key = TRY(vm.argument(0).to_property_key(vm));
|
||||
auto* this_object = TRY(vm.this_value().to_object(vm));
|
||||
return Value(TRY(this_object->has_own_property(property_key)));
|
||||
}
|
||||
|
||||
|
@ -77,10 +77,10 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectPrototype::to_string)
|
|||
return js_string(vm, "[object Null]");
|
||||
|
||||
// 3. Let O be ! ToObject(this value).
|
||||
auto* object = MUST(this_value.to_object(global_object));
|
||||
auto* object = MUST(this_value.to_object(vm));
|
||||
|
||||
// 4. Let isArray be ? IsArray(O).
|
||||
auto is_array = TRY(Value(object).is_array(global_object));
|
||||
auto is_array = TRY(Value(object).is_array(vm));
|
||||
|
||||
String builtin_tag;
|
||||
|
||||
|
@ -135,22 +135,22 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectPrototype::to_string)
|
|||
JS_DEFINE_NATIVE_FUNCTION(ObjectPrototype::to_locale_string)
|
||||
{
|
||||
auto this_value = vm.this_value();
|
||||
return this_value.invoke(global_object, vm.names.toString);
|
||||
return this_value.invoke(vm, vm.names.toString);
|
||||
}
|
||||
|
||||
// 20.1.3.7 Object.prototype.valueOf ( ), https://tc39.es/ecma262/#sec-object.prototype.valueof
|
||||
JS_DEFINE_NATIVE_FUNCTION(ObjectPrototype::value_of)
|
||||
{
|
||||
return TRY(vm.this_value().to_object(global_object));
|
||||
return TRY(vm.this_value().to_object(vm));
|
||||
}
|
||||
|
||||
// 20.1.3.4 Object.prototype.propertyIsEnumerable ( V ), https://tc39.es/ecma262/#sec-object.prototype.propertyisenumerable
|
||||
JS_DEFINE_NATIVE_FUNCTION(ObjectPrototype::property_is_enumerable)
|
||||
{
|
||||
// 1. Let P be ? ToPropertyKey(V).
|
||||
auto property_key = TRY(vm.argument(0).to_property_key(global_object));
|
||||
auto property_key = TRY(vm.argument(0).to_property_key(vm));
|
||||
// 2. Let O be ? ToObject(this value).
|
||||
auto* this_object = TRY(vm.this_value().to_object(global_object));
|
||||
auto* this_object = TRY(vm.this_value().to_object(vm));
|
||||
// 3. Let desc be ? O.[[GetOwnProperty]](P).
|
||||
auto property_descriptor = TRY(this_object->internal_get_own_property(property_key));
|
||||
// 4. If desc is undefined, return false.
|
||||
|
@ -167,7 +167,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectPrototype::is_prototype_of)
|
|||
if (!object_argument.is_object())
|
||||
return Value(false);
|
||||
auto* object = &object_argument.as_object();
|
||||
auto* this_object = TRY(vm.this_value().to_object(global_object));
|
||||
auto* this_object = TRY(vm.this_value().to_object(vm));
|
||||
|
||||
for (;;) {
|
||||
object = TRY(object->internal_get_prototype_of());
|
||||
|
@ -181,7 +181,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectPrototype::is_prototype_of)
|
|||
// B.2.2.2 Object.prototype.__defineGetter__ ( P, getter ), https://tc39.es/ecma262/#sec-object.prototype.__defineGetter__
|
||||
JS_DEFINE_NATIVE_FUNCTION(ObjectPrototype::define_getter)
|
||||
{
|
||||
auto* object = TRY(vm.this_value().to_object(global_object));
|
||||
auto* object = TRY(vm.this_value().to_object(vm));
|
||||
|
||||
auto getter = vm.argument(1);
|
||||
if (!getter.is_function())
|
||||
|
@ -189,7 +189,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectPrototype::define_getter)
|
|||
|
||||
auto descriptor = PropertyDescriptor { .get = &getter.as_function(), .enumerable = true, .configurable = true };
|
||||
|
||||
auto key = TRY(vm.argument(0).to_property_key(global_object));
|
||||
auto key = TRY(vm.argument(0).to_property_key(vm));
|
||||
|
||||
TRY(object->define_property_or_throw(key, descriptor));
|
||||
|
||||
|
@ -199,7 +199,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectPrototype::define_getter)
|
|||
// B.2.2.3 Object.prototype.__defineSetter__ ( P, getter ), https://tc39.es/ecma262/#sec-object.prototype.__defineSetter__
|
||||
JS_DEFINE_NATIVE_FUNCTION(ObjectPrototype::define_setter)
|
||||
{
|
||||
auto* object = TRY(vm.this_value().to_object(global_object));
|
||||
auto* object = TRY(vm.this_value().to_object(vm));
|
||||
|
||||
auto setter = vm.argument(1);
|
||||
if (!setter.is_function())
|
||||
|
@ -207,7 +207,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectPrototype::define_setter)
|
|||
|
||||
auto descriptor = PropertyDescriptor { .set = &setter.as_function(), .enumerable = true, .configurable = true };
|
||||
|
||||
auto key = TRY(vm.argument(0).to_property_key(global_object));
|
||||
auto key = TRY(vm.argument(0).to_property_key(vm));
|
||||
|
||||
TRY(object->define_property_or_throw(key, descriptor));
|
||||
|
||||
|
@ -217,9 +217,9 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectPrototype::define_setter)
|
|||
// B.2.2.4 Object.prototype.__lookupGetter__ ( P ), https://tc39.es/ecma262/#sec-object.prototype.__lookupGetter__
|
||||
JS_DEFINE_NATIVE_FUNCTION(ObjectPrototype::lookup_getter)
|
||||
{
|
||||
auto* object = TRY(vm.this_value().to_object(global_object));
|
||||
auto* object = TRY(vm.this_value().to_object(vm));
|
||||
|
||||
auto key = TRY(vm.argument(0).to_property_key(global_object));
|
||||
auto key = TRY(vm.argument(0).to_property_key(vm));
|
||||
|
||||
while (object) {
|
||||
auto desc = TRY(object->internal_get_own_property(key));
|
||||
|
@ -237,9 +237,9 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectPrototype::lookup_getter)
|
|||
// B.2.2.5 Object.prototype.__lookupSetter__ ( P ), https://tc39.es/ecma262/#sec-object.prototype.__lookupSetter__
|
||||
JS_DEFINE_NATIVE_FUNCTION(ObjectPrototype::lookup_setter)
|
||||
{
|
||||
auto* object = TRY(vm.this_value().to_object(global_object));
|
||||
auto* object = TRY(vm.this_value().to_object(vm));
|
||||
|
||||
auto key = TRY(vm.argument(0).to_property_key(global_object));
|
||||
auto key = TRY(vm.argument(0).to_property_key(vm));
|
||||
|
||||
while (object) {
|
||||
auto desc = TRY(object->internal_get_own_property(key));
|
||||
|
@ -257,7 +257,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectPrototype::lookup_setter)
|
|||
// B.2.2.1.1 get Object.prototype.__proto__, https://tc39.es/ecma262/#sec-get-object.prototype.__proto__
|
||||
JS_DEFINE_NATIVE_FUNCTION(ObjectPrototype::proto_getter)
|
||||
{
|
||||
auto* object = TRY(vm.this_value().to_object(global_object));
|
||||
auto* object = TRY(vm.this_value().to_object(vm));
|
||||
return TRY(object->internal_get_prototype_of());
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ static ThrowCompletionOr<Value> get_promise_resolve(GlobalObject& global_object,
|
|||
auto& vm = global_object.vm();
|
||||
|
||||
// 1. Let promiseResolve be ? Get(promiseConstructor, "resolve").
|
||||
auto promise_resolve = TRY(constructor.get(global_object, vm.names.resolve));
|
||||
auto promise_resolve = TRY(constructor.get(vm, vm.names.resolve));
|
||||
|
||||
// 2. If IsCallable(promiseResolve) is false, throw a TypeError exception.
|
||||
if (!promise_resolve.is_function())
|
||||
|
@ -146,7 +146,7 @@ static ThrowCompletionOr<Value> perform_promise_all(GlobalObject& global_object,
|
|||
on_fulfilled->define_direct_property(vm.names.name, js_string(vm, String::empty()), Attribute::Configurable);
|
||||
|
||||
// s. Perform ? Invoke(nextPromise, "then", « onFulfilled, resultCapability.[[Reject]] »).
|
||||
return next_promise.invoke(global_object, vm.names.then, on_fulfilled, result_capability.reject);
|
||||
return next_promise.invoke(vm, vm.names.then, on_fulfilled, result_capability.reject);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -190,7 +190,7 @@ static ThrowCompletionOr<Value> perform_promise_all_settled(GlobalObject& global
|
|||
on_rejected->define_direct_property(vm.names.name, js_string(vm, String::empty()), Attribute::Configurable);
|
||||
|
||||
// ab. Perform ? Invoke(nextPromise, "then", « onFulfilled, onRejected »).
|
||||
return next_promise.invoke(global_object, vm.names.then, on_fulfilled, on_rejected);
|
||||
return next_promise.invoke(vm, vm.names.then, on_fulfilled, on_rejected);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -226,7 +226,7 @@ static ThrowCompletionOr<Value> perform_promise_any(GlobalObject& global_object,
|
|||
on_rejected->define_direct_property(vm.names.name, js_string(vm, String::empty()), Attribute::Configurable);
|
||||
|
||||
// s. Perform ? Invoke(nextPromise, "then", « resultCapability.[[Resolve]], onRejected »).
|
||||
return next_promise.invoke(global_object, vm.names.then, result_capability.resolve, on_rejected);
|
||||
return next_promise.invoke(vm, vm.names.then, result_capability.resolve, on_rejected);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -243,7 +243,7 @@ static ThrowCompletionOr<Value> perform_promise_race(GlobalObject& global_object
|
|||
},
|
||||
[&](PromiseValueList&, RemainingElements&, Value next_promise, size_t) {
|
||||
// i. Perform ? Invoke(nextPromise, "then", « resultCapability.[[Resolve]], resultCapability.[[Reject]] »).
|
||||
return next_promise.invoke(global_object, vm.names.then, result_capability.resolve, result_capability.reject);
|
||||
return next_promise.invoke(vm, vm.names.then, result_capability.resolve, result_capability.reject);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -321,7 +321,7 @@ ThrowCompletionOr<Object*> PromiseConstructor::construct(FunctionObject& new_tar
|
|||
JS_DEFINE_NATIVE_FUNCTION(PromiseConstructor::all)
|
||||
{
|
||||
// 1. Let C be the this value.
|
||||
auto* constructor = TRY(vm.this_value().to_object(global_object));
|
||||
auto* constructor = TRY(vm.this_value().to_object(vm));
|
||||
|
||||
// 2. Let promiseCapability be ? NewPromiseCapability(C).
|
||||
auto promise_capability = TRY(new_promise_capability(global_object, constructor));
|
||||
|
@ -355,7 +355,7 @@ JS_DEFINE_NATIVE_FUNCTION(PromiseConstructor::all)
|
|||
JS_DEFINE_NATIVE_FUNCTION(PromiseConstructor::all_settled)
|
||||
{
|
||||
// 1. Let C be the this value.
|
||||
auto* constructor = TRY(vm.this_value().to_object(global_object));
|
||||
auto* constructor = TRY(vm.this_value().to_object(vm));
|
||||
|
||||
// 2. Let promiseCapability be ? NewPromiseCapability(C).
|
||||
auto promise_capability = TRY(new_promise_capability(global_object, constructor));
|
||||
|
@ -389,7 +389,7 @@ JS_DEFINE_NATIVE_FUNCTION(PromiseConstructor::all_settled)
|
|||
JS_DEFINE_NATIVE_FUNCTION(PromiseConstructor::any)
|
||||
{
|
||||
// 1. Let C be the this value.
|
||||
auto* constructor = TRY(vm.this_value().to_object(global_object));
|
||||
auto* constructor = TRY(vm.this_value().to_object(vm));
|
||||
|
||||
// 2. Let promiseCapability be ? NewPromiseCapability(C).
|
||||
auto promise_capability = TRY(new_promise_capability(global_object, constructor));
|
||||
|
@ -423,7 +423,7 @@ JS_DEFINE_NATIVE_FUNCTION(PromiseConstructor::any)
|
|||
JS_DEFINE_NATIVE_FUNCTION(PromiseConstructor::race)
|
||||
{
|
||||
// 1. Let C be the this value.
|
||||
auto* constructor = TRY(vm.this_value().to_object(global_object));
|
||||
auto* constructor = TRY(vm.this_value().to_object(vm));
|
||||
|
||||
// 2. Let promiseCapability be ? NewPromiseCapability(C).
|
||||
auto promise_capability = TRY(new_promise_capability(global_object, constructor));
|
||||
|
@ -459,7 +459,7 @@ JS_DEFINE_NATIVE_FUNCTION(PromiseConstructor::reject)
|
|||
auto reason = vm.argument(0);
|
||||
|
||||
// 1. Let C be the this value.
|
||||
auto* constructor = TRY(vm.this_value().to_object(global_object));
|
||||
auto* constructor = TRY(vm.this_value().to_object(vm));
|
||||
|
||||
// 2. Let promiseCapability be ? NewPromiseCapability(C).
|
||||
auto promise_capability = TRY(new_promise_capability(global_object, constructor));
|
||||
|
|
|
@ -64,7 +64,7 @@ JS_DEFINE_NATIVE_FUNCTION(PromisePrototype::catch_)
|
|||
auto this_value = vm.this_value();
|
||||
|
||||
// 2. Return ? Invoke(promise, "then", « undefined, onRejected »).
|
||||
return TRY(this_value.invoke(global_object, vm.names.then, js_undefined(), on_rejected));
|
||||
return TRY(this_value.invoke(vm, vm.names.then, js_undefined(), on_rejected));
|
||||
}
|
||||
|
||||
// 27.2.5.3 Promise.prototype.finally ( onFinally ), https://tc39.es/ecma262/#sec-promise.prototype.finally
|
||||
|
@ -123,7 +123,7 @@ JS_DEFINE_NATIVE_FUNCTION(PromisePrototype::finally)
|
|||
auto* value_thunk = NativeFunction::create(realm, move(return_value), 0, "");
|
||||
|
||||
// v. Return ? Invoke(promise, "then", « valueThunk »).
|
||||
return TRY(Value(promise).invoke(global_object, vm.names.then, value_thunk));
|
||||
return TRY(Value(promise).invoke(vm, vm.names.then, value_thunk));
|
||||
};
|
||||
|
||||
// b. Let thenFinally be CreateBuiltinFunction(thenFinallyClosure, 1, "", « »).
|
||||
|
@ -152,7 +152,7 @@ JS_DEFINE_NATIVE_FUNCTION(PromisePrototype::finally)
|
|||
auto* thrower = NativeFunction::create(realm, move(throw_reason), 0, "");
|
||||
|
||||
// v. Return ? Invoke(promise, "then", « thrower »).
|
||||
return TRY(Value(promise).invoke(global_object, vm.names.then, thrower));
|
||||
return TRY(Value(promise).invoke(vm, vm.names.then, thrower));
|
||||
};
|
||||
|
||||
// d. Let catchFinally be CreateBuiltinFunction(catchFinallyClosure, 1, "", « »).
|
||||
|
@ -160,7 +160,7 @@ JS_DEFINE_NATIVE_FUNCTION(PromisePrototype::finally)
|
|||
}
|
||||
|
||||
// 7. Return ? Invoke(promise, "then", « thenFinally, catchFinally »).
|
||||
return TRY(promise.invoke(global_object, vm.names.then, then_finally, catch_finally));
|
||||
return TRY(promise.invoke(vm, vm.names.then, then_finally, catch_finally));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ public:
|
|||
No,
|
||||
};
|
||||
|
||||
static ThrowCompletionOr<PropertyKey> from_value(GlobalObject& global_object, Value value)
|
||||
static ThrowCompletionOr<PropertyKey> from_value(VM& vm, Value value)
|
||||
{
|
||||
if (value.is_empty())
|
||||
return PropertyKey {};
|
||||
|
@ -34,7 +34,7 @@ public:
|
|||
return PropertyKey { value.as_symbol() };
|
||||
if (value.is_integral_number() && value.as_double() >= 0 && value.as_double() < NumericLimits<u32>::max())
|
||||
return static_cast<u32>(value.as_double());
|
||||
return TRY(value.to_string(global_object));
|
||||
return TRY(value.to_string(vm));
|
||||
}
|
||||
|
||||
PropertyKey() = default;
|
||||
|
|
|
@ -37,9 +37,7 @@ public:
|
|||
// Use typed_this_object() when the spec coerces |this| value to an object.
|
||||
static ThrowCompletionOr<ObjectType*> typed_this_object(VM& vm)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
auto* this_object = TRY(vm.this_value().to_object(global_object));
|
||||
auto* this_object = TRY(vm.this_value().to_object(vm));
|
||||
if (!is<ObjectType>(this_object))
|
||||
return vm.throw_completion<TypeError>(ErrorType::NotAnObjectOfType, PrototypeType::display_name());
|
||||
return static_cast<ObjectType*>(this_object);
|
||||
|
|
|
@ -56,7 +56,7 @@ ThrowCompletionOr<Object*> ProxyObject::internal_get_prototype_of() const
|
|||
// 4. Let target be O.[[ProxyTarget]].
|
||||
|
||||
// 5. Let trap be ? GetMethod(handler, "getPrototypeOf").
|
||||
auto trap = TRY(Value(&m_handler).get_method(global_object, vm.names.getPrototypeOf));
|
||||
auto trap = TRY(Value(&m_handler).get_method(vm, vm.names.getPrototypeOf));
|
||||
|
||||
// 6. If trap is undefined, then
|
||||
if (!trap) {
|
||||
|
@ -105,7 +105,7 @@ ThrowCompletionOr<bool> ProxyObject::internal_set_prototype_of(Object* prototype
|
|||
// 4. Let target be O.[[ProxyTarget]].
|
||||
|
||||
// 5. Let trap be ? GetMethod(handler, "setPrototypeOf").
|
||||
auto trap = TRY(Value(&m_handler).get_method(global_object, vm.names.setPrototypeOf));
|
||||
auto trap = TRY(Value(&m_handler).get_method(vm, vm.names.setPrototypeOf));
|
||||
|
||||
// 6. If trap is undefined, then
|
||||
if (!trap) {
|
||||
|
@ -154,7 +154,7 @@ ThrowCompletionOr<bool> ProxyObject::internal_is_extensible() const
|
|||
// 4. Let target be O.[[ProxyTarget]].
|
||||
|
||||
// 5. Let trap be ? GetMethod(handler, "isExtensible").
|
||||
auto trap = TRY(Value(&m_handler).get_method(global_object, vm.names.isExtensible));
|
||||
auto trap = TRY(Value(&m_handler).get_method(vm, vm.names.isExtensible));
|
||||
|
||||
// 6. If trap is undefined, then
|
||||
if (!trap) {
|
||||
|
@ -192,7 +192,7 @@ ThrowCompletionOr<bool> ProxyObject::internal_prevent_extensions()
|
|||
// 4. Let target be O.[[ProxyTarget]].
|
||||
|
||||
// 5. Let trap be ? GetMethod(handler, "preventExtensions").
|
||||
auto trap = TRY(Value(&m_handler).get_method(global_object, vm.names.preventExtensions));
|
||||
auto trap = TRY(Value(&m_handler).get_method(vm, vm.names.preventExtensions));
|
||||
|
||||
// 6. If trap is undefined, then
|
||||
if (!trap) {
|
||||
|
@ -235,7 +235,7 @@ ThrowCompletionOr<Optional<PropertyDescriptor>> ProxyObject::internal_get_own_pr
|
|||
// 4. Let target be O.[[ProxyTarget]].
|
||||
|
||||
// 5. Let trap be ? GetMethod(handler, "getOwnPropertyDescriptor").
|
||||
auto trap = TRY(Value(&m_handler).get_method(global_object, vm.names.getOwnPropertyDescriptor));
|
||||
auto trap = TRY(Value(&m_handler).get_method(vm, vm.names.getOwnPropertyDescriptor));
|
||||
|
||||
// 6. If trap is undefined, then
|
||||
if (!trap) {
|
||||
|
@ -327,7 +327,7 @@ ThrowCompletionOr<bool> ProxyObject::internal_define_own_property(PropertyKey co
|
|||
// 4. Let target be O.[[ProxyTarget]].
|
||||
|
||||
// 5. Let trap be ? GetMethod(handler, "defineProperty").
|
||||
auto trap = TRY(Value(&m_handler).get_method(global_object, vm.names.defineProperty));
|
||||
auto trap = TRY(Value(&m_handler).get_method(vm, vm.names.defineProperty));
|
||||
|
||||
// 6. If trap is undefined, then
|
||||
if (!trap) {
|
||||
|
@ -410,7 +410,7 @@ ThrowCompletionOr<bool> ProxyObject::internal_has_property(PropertyKey const& pr
|
|||
// 4. Let target be O.[[ProxyTarget]].
|
||||
|
||||
// 5. Let trap be ? GetMethod(handler, "has").
|
||||
auto trap = TRY(Value(&m_handler).get_method(global_object, vm.names.has));
|
||||
auto trap = TRY(Value(&m_handler).get_method(vm, vm.names.has));
|
||||
|
||||
// 6. If trap is undefined, then
|
||||
if (!trap) {
|
||||
|
@ -482,7 +482,7 @@ ThrowCompletionOr<Value> ProxyObject::internal_get(PropertyKey const& property_k
|
|||
return vm.throw_completion<InternalError>(ErrorType::CallStackSizeExceeded);
|
||||
|
||||
// 5. Let trap be ? GetMethod(handler, "get").
|
||||
auto trap = TRY(Value(&m_handler).get_method(global_object, vm.names.get));
|
||||
auto trap = TRY(Value(&m_handler).get_method(vm, vm.names.get));
|
||||
|
||||
// 6. If trap is undefined, then
|
||||
if (!trap) {
|
||||
|
@ -536,7 +536,7 @@ ThrowCompletionOr<bool> ProxyObject::internal_set(PropertyKey const& property_ke
|
|||
// 4. Let target be O.[[ProxyTarget]].
|
||||
|
||||
// 5. Let trap be ? GetMethod(handler, "set").
|
||||
auto trap = TRY(Value(&m_handler).get_method(global_object, vm.names.set));
|
||||
auto trap = TRY(Value(&m_handler).get_method(vm, vm.names.set));
|
||||
|
||||
// 6. If trap is undefined, then
|
||||
if (!trap) {
|
||||
|
@ -592,7 +592,7 @@ ThrowCompletionOr<bool> ProxyObject::internal_delete(PropertyKey const& property
|
|||
// 4. Let target be O.[[ProxyTarget]].
|
||||
|
||||
// 5. Let trap be ? GetMethod(handler, "deleteProperty").
|
||||
auto trap = TRY(Value(&m_handler).get_method(global_object, vm.names.deleteProperty));
|
||||
auto trap = TRY(Value(&m_handler).get_method(vm, vm.names.deleteProperty));
|
||||
|
||||
// 6. If trap is undefined, then
|
||||
if (!trap) {
|
||||
|
@ -645,7 +645,7 @@ ThrowCompletionOr<MarkedVector<Value>> ProxyObject::internal_own_property_keys()
|
|||
// 4. Let target be O.[[ProxyTarget]].
|
||||
|
||||
// 5. Let trap be ? GetMethod(handler, "ownKeys").
|
||||
auto trap = TRY(Value(&m_handler).get_method(global_object, vm.names.ownKeys));
|
||||
auto trap = TRY(Value(&m_handler).get_method(vm, vm.names.ownKeys));
|
||||
|
||||
// 6. If trap is undefined, then
|
||||
if (!trap) {
|
||||
|
@ -662,7 +662,7 @@ ThrowCompletionOr<MarkedVector<Value>> ProxyObject::internal_own_property_keys()
|
|||
auto& vm = global_object.vm();
|
||||
if (!value.is_string() && !value.is_symbol())
|
||||
return vm.throw_completion<TypeError>(ErrorType::ProxyOwnPropertyKeysNotStringOrSymbol);
|
||||
auto property_key = MUST(value.to_property_key(global_object));
|
||||
auto property_key = MUST(value.to_property_key(vm));
|
||||
unique_keys.set(property_key, AK::HashSetExistingEntryBehavior::Keep);
|
||||
return {};
|
||||
}));
|
||||
|
@ -688,7 +688,7 @@ ThrowCompletionOr<MarkedVector<Value>> ProxyObject::internal_own_property_keys()
|
|||
|
||||
// 16. For each element key of targetKeys, do
|
||||
for (auto& key : target_keys) {
|
||||
auto property_key = MUST(PropertyKey::from_value(global_object, key));
|
||||
auto property_key = MUST(PropertyKey::from_value(vm, key));
|
||||
|
||||
// a. Let desc be ? target.[[GetOwnProperty]](key).
|
||||
auto descriptor = TRY(m_target.internal_get_own_property(property_key));
|
||||
|
@ -775,7 +775,7 @@ ThrowCompletionOr<Value> ProxyObject::internal_call(Value this_argument, MarkedV
|
|||
// 4. Let target be O.[[ProxyTarget]].
|
||||
|
||||
// 5. Let trap be ? GetMethod(handler, "apply").
|
||||
auto trap = TRY(Value(&m_handler).get_method(global_object, vm.names.apply));
|
||||
auto trap = TRY(Value(&m_handler).get_method(vm, vm.names.apply));
|
||||
|
||||
// 6. If trap is undefined, then
|
||||
if (!trap) {
|
||||
|
@ -824,7 +824,7 @@ ThrowCompletionOr<Object*> ProxyObject::internal_construct(MarkedVector<Value> a
|
|||
// 5. Assert: IsConstructor(target) is true.
|
||||
|
||||
// 6. Let trap be ? GetMethod(handler, "construct").
|
||||
auto trap = TRY(Value(&m_handler).get_method(global_object, vm.names.construct));
|
||||
auto trap = TRY(Value(&m_handler).get_method(vm, vm.names.construct));
|
||||
|
||||
// 7. If trap is undefined, then
|
||||
if (!trap) {
|
||||
|
|
|
@ -41,7 +41,7 @@ ThrowCompletionOr<void> Reference::put_value(GlobalObject& global_object, Value
|
|||
// 5. If IsPropertyReference(V) is true, then
|
||||
if (is_property_reference()) {
|
||||
// a. Let baseObj be ? ToObject(V.[[Base]]).
|
||||
auto* base_obj = TRY(m_base_value.to_object(global_object));
|
||||
auto* base_obj = TRY(m_base_value.to_object(vm));
|
||||
|
||||
// b. If IsPrivateReference(V) is true, then
|
||||
if (is_private_reference()) {
|
||||
|
@ -86,6 +86,8 @@ Completion Reference::throw_reference_error(GlobalObject& global_object) const
|
|||
// 6.2.4.5 GetValue ( V ), https://tc39.es/ecma262/#sec-getvalue
|
||||
ThrowCompletionOr<Value> Reference::get_value(GlobalObject& global_object) const
|
||||
{
|
||||
auto& vm = global_object.vm();
|
||||
|
||||
// 1. ReturnIfAbrupt(V).
|
||||
// 2. If V is not a Reference Record, return V.
|
||||
|
||||
|
@ -105,7 +107,7 @@ ThrowCompletionOr<Value> Reference::get_value(GlobalObject& global_object) const
|
|||
// as things currently stand this does the "wrong thing" but
|
||||
// the error is unobservable
|
||||
|
||||
auto* base_obj = TRY(m_base_value.to_object(global_object));
|
||||
auto* base_obj = TRY(m_base_value.to_object(vm));
|
||||
|
||||
// i. Return ? PrivateGet(baseObj, V.[[ReferencedName]]).
|
||||
return base_obj->private_get(m_private_name);
|
||||
|
@ -123,7 +125,7 @@ ThrowCompletionOr<Value> Reference::get_value(GlobalObject& global_object) const
|
|||
else if (m_base_value.is_boolean())
|
||||
base_obj = global_object.boolean_prototype();
|
||||
else
|
||||
base_obj = TRY(m_base_value.to_object(global_object));
|
||||
base_obj = TRY(m_base_value.to_object(vm));
|
||||
|
||||
// c. Return ? baseObj.[[Get]](V.[[ReferencedName]], GetThisValue(V)).
|
||||
return base_obj->internal_get(m_name, get_this_value());
|
||||
|
@ -173,7 +175,7 @@ ThrowCompletionOr<bool> Reference::delete_(GlobalObject& global_object)
|
|||
return vm.throw_completion<ReferenceError>(ErrorType::UnsupportedDeleteSuperProperty);
|
||||
|
||||
// c. Let baseObj be ! ToObject(ref.[[Base]]).
|
||||
auto* base_obj = MUST(m_base_value.to_object(global_object));
|
||||
auto* base_obj = MUST(m_base_value.to_object(vm));
|
||||
|
||||
// d. Let deleteStatus be ? baseObj.[[Delete]](ref.[[ReferencedName]]).
|
||||
bool delete_status = TRY(base_obj->internal_delete(m_name));
|
||||
|
|
|
@ -99,7 +99,7 @@ JS_DEFINE_NATIVE_FUNCTION(ReflectObject::define_property)
|
|||
return vm.throw_completion<TypeError>(ErrorType::NotAnObject, target.to_string_without_side_effects());
|
||||
|
||||
// 2. Let key be ? ToPropertyKey(propertyKey).
|
||||
auto key = TRY(property_key.to_property_key(global_object));
|
||||
auto key = TRY(property_key.to_property_key(vm));
|
||||
|
||||
// 3. Let desc be ? ToPropertyDescriptor(attributes).
|
||||
auto descriptor = TRY(to_property_descriptor(global_object, attributes));
|
||||
|
@ -119,7 +119,7 @@ JS_DEFINE_NATIVE_FUNCTION(ReflectObject::delete_property)
|
|||
return vm.throw_completion<TypeError>(ErrorType::NotAnObject, target.to_string_without_side_effects());
|
||||
|
||||
// 2. Let key be ? ToPropertyKey(propertyKey).
|
||||
auto key = TRY(property_key.to_property_key(global_object));
|
||||
auto key = TRY(property_key.to_property_key(vm));
|
||||
|
||||
// 3. Return ? target.[[Delete]](key).
|
||||
return Value(TRY(target.as_object().internal_delete(key)));
|
||||
|
@ -137,7 +137,7 @@ JS_DEFINE_NATIVE_FUNCTION(ReflectObject::get)
|
|||
return vm.throw_completion<TypeError>(ErrorType::NotAnObject, target.to_string_without_side_effects());
|
||||
|
||||
// 2. Let key be ? ToPropertyKey(propertyKey).
|
||||
auto key = TRY(property_key.to_property_key(global_object));
|
||||
auto key = TRY(property_key.to_property_key(vm));
|
||||
|
||||
// 3. If receiver is not present, then
|
||||
if (vm.argument_count() < 3) {
|
||||
|
@ -160,7 +160,7 @@ JS_DEFINE_NATIVE_FUNCTION(ReflectObject::get_own_property_descriptor)
|
|||
return vm.throw_completion<TypeError>(ErrorType::NotAnObject, target.to_string_without_side_effects());
|
||||
|
||||
// 2. Let key be ? ToPropertyKey(propertyKey).
|
||||
auto key = TRY(property_key.to_property_key(global_object));
|
||||
auto key = TRY(property_key.to_property_key(vm));
|
||||
|
||||
// 3. Let desc be ? target.[[GetOwnProperty]](key).
|
||||
auto descriptor = TRY(target.as_object().internal_get_own_property(key));
|
||||
|
@ -193,7 +193,7 @@ JS_DEFINE_NATIVE_FUNCTION(ReflectObject::has)
|
|||
return vm.throw_completion<TypeError>(ErrorType::NotAnObject, target.to_string_without_side_effects());
|
||||
|
||||
// 2. Let key be ? ToPropertyKey(propertyKey).
|
||||
auto key = TRY(property_key.to_property_key(global_object));
|
||||
auto key = TRY(property_key.to_property_key(vm));
|
||||
|
||||
// 3. Return ? target.[[HasProperty]](key).
|
||||
return Value(TRY(target.as_object().internal_has_property(key)));
|
||||
|
@ -256,7 +256,7 @@ JS_DEFINE_NATIVE_FUNCTION(ReflectObject::set)
|
|||
return vm.throw_completion<TypeError>(ErrorType::NotAnObject, target.to_string_without_side_effects());
|
||||
|
||||
// 2. Let key be ? ToPropertyKey(propertyKey).
|
||||
auto key = TRY(property_key.to_property_key(global_object));
|
||||
auto key = TRY(property_key.to_property_key(vm));
|
||||
|
||||
// 3. If receiver is not present, then
|
||||
if (vm.argument_count() < 4) {
|
||||
|
|
|
@ -33,12 +33,11 @@ void RegExpConstructor::initialize(Realm& realm)
|
|||
ThrowCompletionOr<Value> RegExpConstructor::call()
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
auto& global_object = this->global_object();
|
||||
|
||||
auto pattern = vm.argument(0);
|
||||
auto flags = vm.argument(1);
|
||||
|
||||
bool pattern_is_regexp = TRY(pattern.is_regexp(global_object));
|
||||
bool pattern_is_regexp = TRY(pattern.is_regexp(vm));
|
||||
|
||||
if (pattern_is_regexp && flags.is_undefined()) {
|
||||
auto pattern_constructor = TRY(pattern.as_object().get(vm.names.constructor));
|
||||
|
@ -58,7 +57,7 @@ ThrowCompletionOr<Object*> RegExpConstructor::construct(FunctionObject&)
|
|||
auto pattern = vm.argument(0);
|
||||
auto flags = vm.argument(1);
|
||||
|
||||
bool pattern_is_regexp = TRY(pattern.is_regexp(global_object));
|
||||
bool pattern_is_regexp = TRY(pattern.is_regexp(vm));
|
||||
|
||||
Value pattern_value;
|
||||
Value flags_value;
|
||||
|
|
|
@ -162,7 +162,7 @@ ThrowCompletionOr<RegExpObject*> RegExpObject::regexp_initialize(GlobalObject& g
|
|||
if (flags.is_undefined()) {
|
||||
f = String::empty();
|
||||
} else {
|
||||
f = TRY(flags.to_string(global_object));
|
||||
f = TRY(flags.to_string(vm));
|
||||
}
|
||||
|
||||
String original_pattern;
|
||||
|
@ -172,7 +172,7 @@ ThrowCompletionOr<RegExpObject*> RegExpObject::regexp_initialize(GlobalObject& g
|
|||
original_pattern = String::empty();
|
||||
parsed_pattern = String::empty();
|
||||
} else {
|
||||
original_pattern = TRY(pattern.to_string(global_object));
|
||||
original_pattern = TRY(pattern.to_string(vm));
|
||||
bool unicode = f.find('u').has_value();
|
||||
bool unicode_sets = f.find('v').has_value();
|
||||
parsed_pattern = TRY(parse_regex_pattern(vm, original_pattern, unicode, unicode_sets));
|
||||
|
|
|
@ -58,7 +58,7 @@ static ThrowCompletionOr<void> increment_last_index(GlobalObject& global_object,
|
|||
|
||||
// Let thisIndex be ℝ(? ToLength(? Get(rx, "lastIndex"))).
|
||||
auto last_index_value = TRY(regexp_object.get(vm.names.lastIndex));
|
||||
auto last_index = TRY(last_index_value.to_length(global_object));
|
||||
auto last_index = TRY(last_index_value.to_length(vm));
|
||||
|
||||
// Let nextIndex be AdvanceStringIndex(S, thisIndex, fullUnicode).
|
||||
last_index = advance_string_index(string, last_index, unicode);
|
||||
|
@ -174,7 +174,7 @@ static ThrowCompletionOr<Value> regexp_builtin_exec(GlobalObject& global_object,
|
|||
// 1. Let length be the length of S.
|
||||
// 2. Let lastIndex be ℝ(? ToLength(? Get(R, "lastIndex"))).
|
||||
auto last_index_value = TRY(regexp_object.get(vm.names.lastIndex));
|
||||
auto last_index = TRY(last_index_value.to_length(global_object));
|
||||
auto last_index = TRY(last_index_value.to_length(vm));
|
||||
|
||||
auto& regex = regexp_object.regex();
|
||||
|
||||
|
@ -445,7 +445,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::exec)
|
|||
auto* regexp_object = TRY(typed_this_object(vm));
|
||||
|
||||
// 3. Let S be ? ToString(string).
|
||||
auto string = TRY(vm.argument(0).to_utf16_string(global_object));
|
||||
auto string = TRY(vm.argument(0).to_utf16_string(vm));
|
||||
|
||||
// 4. Return ? RegExpBuiltinExec(R, S).
|
||||
return TRY(regexp_builtin_exec(global_object, *regexp_object, move(string)));
|
||||
|
@ -500,7 +500,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_match)
|
|||
auto* regexp_object = TRY(this_object(vm));
|
||||
|
||||
// 3. Let S be ? ToString(string).
|
||||
auto string = TRY(vm.argument(0).to_utf16_string(global_object));
|
||||
auto string = TRY(vm.argument(0).to_utf16_string(vm));
|
||||
|
||||
// 4. Let global be ToBoolean(? Get(rx, "global")).
|
||||
bool global = TRY(regexp_object->get(vm.names.global)).to_boolean();
|
||||
|
@ -533,10 +533,10 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_match)
|
|||
// g. Repeat,
|
||||
while (true) {
|
||||
// i. Let result be ? RegExpExec(rx, S).
|
||||
auto result = TRY(regexp_exec(global_object, *regexp_object, string));
|
||||
auto result_value = TRY(regexp_exec(global_object, *regexp_object, string));
|
||||
|
||||
// ii. If result is null, then
|
||||
if (result.is_null()) {
|
||||
if (result_value.is_null()) {
|
||||
// 1. If n = 0, return null.
|
||||
if (n == 0)
|
||||
return js_null();
|
||||
|
@ -545,11 +545,14 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_match)
|
|||
return array;
|
||||
}
|
||||
|
||||
VERIFY(result_value.is_object());
|
||||
auto& result = result_value.as_object();
|
||||
|
||||
// iii. Else,
|
||||
|
||||
// 1. Let matchStr be ? ToString(? Get(result, "0")).
|
||||
auto match_value = TRY(result.get(global_object, 0));
|
||||
auto match_str = TRY(match_value.to_string(global_object));
|
||||
auto match_value = TRY(result.get(0));
|
||||
auto match_str = TRY(match_value.to_string(vm));
|
||||
|
||||
// 2. Perform ! CreateDataPropertyOrThrow(A, ! ToString(𝔽(n)), matchStr).
|
||||
MUST(array->create_data_property_or_throw(n, js_string(vm, match_str)));
|
||||
|
@ -576,14 +579,14 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_match_all)
|
|||
auto* regexp_object = TRY(this_object(vm));
|
||||
|
||||
// 3. Let S be ? ToString(string).
|
||||
auto string = TRY(vm.argument(0).to_utf16_string(global_object));
|
||||
auto string = TRY(vm.argument(0).to_utf16_string(vm));
|
||||
|
||||
// 4. Let C be ? SpeciesConstructor(R, %RegExp%).
|
||||
auto* constructor = TRY(species_constructor(global_object, *regexp_object, *global_object.regexp_constructor()));
|
||||
|
||||
// 5. Let flags be ? ToString(? Get(R, "flags")).
|
||||
auto flags_value = TRY(regexp_object->get(vm.names.flags));
|
||||
auto flags = TRY(flags_value.to_string(global_object));
|
||||
auto flags = TRY(flags_value.to_string(vm));
|
||||
|
||||
// Steps 9-12 are performed early so that flags can be moved.
|
||||
|
||||
|
@ -600,7 +603,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_match_all)
|
|||
|
||||
// 7. Let lastIndex be ? ToLength(? Get(R, "lastIndex")).
|
||||
auto last_index_value = TRY(regexp_object->get(vm.names.lastIndex));
|
||||
auto last_index = TRY(last_index_value.to_length(global_object));
|
||||
auto last_index = TRY(last_index_value.to_length(vm));
|
||||
|
||||
// 8. Perform ? Set(matcher, "lastIndex", lastIndex, true).
|
||||
TRY(matcher->set(vm.names.lastIndex, Value(last_index), Object::ShouldThrowExceptions::Yes));
|
||||
|
@ -621,7 +624,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_replace)
|
|||
auto* regexp_object = TRY(this_object(vm));
|
||||
|
||||
// 3. Let S be ? ToString(string).
|
||||
auto string = TRY(string_value.to_utf16_string(global_object));
|
||||
auto string = TRY(string_value.to_utf16_string(vm));
|
||||
|
||||
// 4. Let lengthS be the number of code unit elements in S.
|
||||
// 5. Let functionalReplace be IsCallable(replaceValue).
|
||||
|
@ -629,7 +632,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_replace)
|
|||
// 6. If functionalReplace is false, then
|
||||
if (!replace_value.is_function()) {
|
||||
// a. Set replaceValue to ? ToString(replaceValue).
|
||||
auto replace_string = TRY(replace_value.to_string(global_object));
|
||||
auto replace_string = TRY(replace_value.to_string(vm));
|
||||
replace_value = js_string(vm, move(replace_string));
|
||||
}
|
||||
|
||||
|
@ -651,7 +654,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_replace)
|
|||
}
|
||||
|
||||
// 9. Let results be a new empty List.
|
||||
MarkedVector<Value> results(vm.heap());
|
||||
MarkedVector<Object*> results(vm.heap());
|
||||
|
||||
// 10. Let done be false.
|
||||
// 11. Repeat, while done is false,
|
||||
|
@ -666,7 +669,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_replace)
|
|||
// c. Else,
|
||||
|
||||
// i. Append result to the end of results.
|
||||
results.append(result);
|
||||
results.append(&result.as_object());
|
||||
|
||||
// ii. If global is false, set done to true.
|
||||
if (!global)
|
||||
|
@ -675,8 +678,8 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_replace)
|
|||
// iii. Else,
|
||||
|
||||
// 1. Let matchStr be ? ToString(? Get(result, "0")).
|
||||
auto match_value = TRY(result.get(global_object, 0));
|
||||
auto match_str = TRY(match_value.to_string(global_object));
|
||||
auto match_value = TRY(result.get(vm, 0));
|
||||
auto match_str = TRY(match_value.to_string(vm));
|
||||
|
||||
// 2. If matchStr is the empty String, then
|
||||
if (match_str.is_empty()) {
|
||||
|
@ -694,21 +697,21 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_replace)
|
|||
// 14. For each element result of results, do
|
||||
for (auto& result : results) {
|
||||
// a. Let resultLength be ? LengthOfArrayLike(result).
|
||||
size_t result_length = TRY(length_of_array_like(global_object, result.as_object()));
|
||||
size_t result_length = TRY(length_of_array_like(global_object, *result));
|
||||
|
||||
// b. Let nCaptures be max(resultLength - 1, 0).
|
||||
size_t n_captures = result_length == 0 ? 0 : result_length - 1;
|
||||
|
||||
// c. Let matched be ? ToString(? Get(result, "0")).
|
||||
auto matched_value = TRY(result.get(global_object, 0));
|
||||
auto matched = TRY(matched_value.to_utf16_string(global_object));
|
||||
auto matched_value = TRY(result->get(0));
|
||||
auto matched = TRY(matched_value.to_utf16_string(vm));
|
||||
|
||||
// d. Let matchLength be the length of matched.
|
||||
auto matched_length = matched.length_in_code_units();
|
||||
|
||||
// e. Let position be ? ToIntegerOrInfinity(? Get(result, "index")).
|
||||
auto position_value = TRY(result.get(global_object, vm.names.index));
|
||||
double position = TRY(position_value.to_integer_or_infinity(global_object));
|
||||
auto position_value = TRY(result->get(vm.names.index));
|
||||
double position = TRY(position_value.to_integer_or_infinity(vm));
|
||||
|
||||
// f. Set position to the result of clamping position between 0 and lengthS.
|
||||
position = clamp(position, static_cast<double>(0), static_cast<double>(string.length_in_code_units()));
|
||||
|
@ -721,12 +724,12 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_replace)
|
|||
// i. Repeat, while n ≤ nCaptures,
|
||||
for (size_t n = 1; n <= n_captures; ++n) {
|
||||
// i. Let capN be ? Get(result, ! ToString(𝔽(n))).
|
||||
auto capture = TRY(result.get(global_object, n));
|
||||
auto capture = TRY(result->get(n));
|
||||
|
||||
// ii. If capN is not undefined, then
|
||||
if (!capture.is_undefined()) {
|
||||
// 1. Set capN to ? ToString(capN).
|
||||
capture = js_string(vm, TRY(capture.to_string(global_object)));
|
||||
capture = js_string(vm, TRY(capture.to_string(vm)));
|
||||
}
|
||||
|
||||
// iii. Append capN as the last element of captures.
|
||||
|
@ -737,7 +740,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_replace)
|
|||
}
|
||||
|
||||
// j. Let namedCaptures be ? Get(result, "groups").
|
||||
auto named_captures = TRY(result.get(global_object, vm.names.groups));
|
||||
auto named_captures = TRY(result->get(vm.names.groups));
|
||||
|
||||
String replacement;
|
||||
|
||||
|
@ -764,14 +767,14 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_replace)
|
|||
auto replace_result = TRY(call(global_object, replace_value.as_function(), js_undefined(), move(replacer_args)));
|
||||
|
||||
// vi. Let replacement be ? ToString(replValue).
|
||||
replacement = TRY(replace_result.to_string(global_object));
|
||||
replacement = TRY(replace_result.to_string(vm));
|
||||
}
|
||||
// l. Else,
|
||||
else {
|
||||
/// i. If namedCaptures is not undefined, then
|
||||
if (!named_captures.is_undefined()) {
|
||||
// 1. Set namedCaptures to ? ToObject(namedCaptures).
|
||||
named_captures = TRY(named_captures.to_object(global_object));
|
||||
named_captures = TRY(named_captures.to_object(vm));
|
||||
}
|
||||
|
||||
// ii. Let replacement be ? GetSubstitution(matched, S, position, captures, namedCaptures, replaceValue).
|
||||
|
@ -811,7 +814,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_search)
|
|||
auto* regexp_object = TRY(this_object(vm));
|
||||
|
||||
// 3. Let S be ? ToString(string).
|
||||
auto string = TRY(vm.argument(0).to_utf16_string(global_object));
|
||||
auto string = TRY(vm.argument(0).to_utf16_string(vm));
|
||||
|
||||
// 4. Let previousLastIndex be ? Get(rx, "lastIndex").
|
||||
auto previous_last_index = TRY(regexp_object->get(vm.names.lastIndex));
|
||||
|
@ -839,7 +842,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_search)
|
|||
return Value(-1);
|
||||
|
||||
// 10. Return ? Get(result, "index").
|
||||
return TRY(result.get(global_object, vm.names.index));
|
||||
return TRY(result.get(vm, vm.names.index));
|
||||
}
|
||||
|
||||
// 22.2.5.13 get RegExp.prototype.source, https://tc39.es/ecma262/#sec-get-regexp.prototype.source
|
||||
|
@ -876,14 +879,14 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_split)
|
|||
auto* regexp_object = TRY(this_object(vm));
|
||||
|
||||
// 3. Let S be ? ToString(string).
|
||||
auto string = TRY(vm.argument(0).to_utf16_string(global_object));
|
||||
auto string = TRY(vm.argument(0).to_utf16_string(vm));
|
||||
|
||||
// 4. Let C be ? SpeciesConstructor(rx, %RegExp%).
|
||||
auto* constructor = TRY(species_constructor(global_object, *regexp_object, *global_object.regexp_constructor()));
|
||||
|
||||
// 5. Let flags be ? ToString(? Get(rx, "flags")).
|
||||
auto flags_value = TRY(regexp_object->get(vm.names.flags));
|
||||
auto flags = TRY(flags_value.to_string(global_object));
|
||||
auto flags = TRY(flags_value.to_string(vm));
|
||||
|
||||
// 6. If flags contains "u", let unicodeMatching be true.
|
||||
// 7. Else, let unicodeMatching be false.
|
||||
|
@ -905,7 +908,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_split)
|
|||
// 13. If limit is undefined, let lim be 2^32 - 1; else let lim be ℝ(? ToUint32(limit)).
|
||||
auto limit = NumericLimits<u32>::max();
|
||||
if (!vm.argument(1).is_undefined())
|
||||
limit = TRY(vm.argument(1).to_u32(global_object));
|
||||
limit = TRY(vm.argument(1).to_u32(vm));
|
||||
|
||||
// 14. If lim is 0, return A.
|
||||
if (limit == 0)
|
||||
|
@ -952,7 +955,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_split)
|
|||
|
||||
// i. Let e be ℝ(? ToLength(? Get(splitter, "lastIndex"))).
|
||||
auto last_index_value = TRY(splitter->get(vm.names.lastIndex));
|
||||
auto last_index = TRY(last_index_value.to_length(global_object));
|
||||
auto last_index = TRY(last_index_value.to_length(vm));
|
||||
|
||||
// ii. Set e to min(e, size).
|
||||
last_index = min(last_index, string.length_in_code_units());
|
||||
|
@ -993,7 +996,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_split)
|
|||
for (size_t i = 1; i <= number_of_captures; ++i) {
|
||||
|
||||
// a. Let nextCapture be ? Get(z, ! ToString(𝔽(i))).
|
||||
auto next_capture = TRY(result.get(global_object, i));
|
||||
auto next_capture = TRY(result.get(vm, i));
|
||||
|
||||
// b. Perform ! CreateDataPropertyOrThrow(A, ! ToString(𝔽(lengthA)), nextCapture).
|
||||
MUST(array->create_data_property_or_throw(array_length, next_capture));
|
||||
|
@ -1030,7 +1033,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::test)
|
|||
auto* regexp_object = TRY(this_object(vm));
|
||||
|
||||
// 3. Let string be ? ToString(S).
|
||||
auto string = TRY(vm.argument(0).to_utf16_string(global_object));
|
||||
auto string = TRY(vm.argument(0).to_utf16_string(vm));
|
||||
|
||||
// 4. Let match be ? RegExpExec(R, string).
|
||||
auto match = TRY(regexp_exec(global_object, *regexp_object, move(string)));
|
||||
|
@ -1048,11 +1051,11 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::to_string)
|
|||
|
||||
// 3. Let pattern be ? ToString(? Get(R, "source")).
|
||||
auto source_attr = TRY(regexp_object->get(vm.names.source));
|
||||
auto pattern = TRY(source_attr.to_string(global_object));
|
||||
auto pattern = TRY(source_attr.to_string(vm));
|
||||
|
||||
// 4. Let flags be ? ToString(? Get(R, "flags")).
|
||||
auto flags_attr = TRY(regexp_object->get(vm.names.flags));
|
||||
auto flags = TRY(flags_attr.to_string(global_object));
|
||||
auto flags = TRY(flags_attr.to_string(vm));
|
||||
|
||||
// 5. Let result be the string-concatenation of "/", pattern, "/", and flags.
|
||||
// 6. Return result.
|
||||
|
|
|
@ -49,12 +49,12 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpStringIteratorPrototype::next)
|
|||
return create_iterator_result_object(global_object, match, false);
|
||||
}
|
||||
|
||||
auto* match_object = TRY(match.to_object(global_object));
|
||||
auto* match_object = TRY(match.to_object(vm));
|
||||
auto match_string_value = TRY(match_object->get(0));
|
||||
auto match_string = TRY(match_string_value.to_string(global_object));
|
||||
auto match_string = TRY(match_string_value.to_string(vm));
|
||||
if (match_string.is_empty()) {
|
||||
auto last_index_value = TRY(iterator->regexp_object().get(vm.names.lastIndex));
|
||||
auto last_index = TRY(last_index_value.to_length(global_object));
|
||||
auto last_index = TRY(last_index_value.to_length(vm));
|
||||
|
||||
last_index = advance_string_index(iterator->string().view(), last_index, iterator->unicode());
|
||||
|
||||
|
|
|
@ -66,7 +66,7 @@ ThrowCompletionOr<void> copy_name_and_length(GlobalObject& global_object, Functi
|
|||
// iii. Else,
|
||||
else {
|
||||
// 1. Let targetLenAsInt be ! ToIntegerOrInfinity(targetLen).
|
||||
auto target_length_as_int = MUST(target_length.to_integer_or_infinity(global_object));
|
||||
auto target_length_as_int = MUST(target_length.to_integer_or_infinity(vm));
|
||||
|
||||
// 2. Assert: targetLenAsInt is finite.
|
||||
VERIFY(!isinf(target_length_as_int));
|
||||
|
|
|
@ -63,7 +63,7 @@ JS_DEFINE_NATIVE_FUNCTION(ShadowRealmPrototype::import_value)
|
|||
auto* object = TRY(typed_this_object(vm));
|
||||
|
||||
// 3. Let specifierString be ? ToString(specifier).
|
||||
auto specifier_string = TRY(specifier.to_string(global_object));
|
||||
auto specifier_string = TRY(specifier.to_string(vm));
|
||||
|
||||
// 4. If Type(exportName) is not String, throw a TypeError exception.
|
||||
if (!export_name.is_string())
|
||||
|
|
|
@ -41,11 +41,12 @@ void StringConstructor::initialize(Realm& realm)
|
|||
// 22.1.1.1 String ( value ), https://tc39.es/ecma262/#sec-string-constructor-string-value
|
||||
ThrowCompletionOr<Value> StringConstructor::call()
|
||||
{
|
||||
if (!vm().argument_count())
|
||||
auto& vm = this->vm();
|
||||
if (!vm.argument_count())
|
||||
return js_string(heap(), "");
|
||||
if (vm().argument(0).is_symbol())
|
||||
return js_string(heap(), vm().argument(0).as_symbol().to_string());
|
||||
return TRY(vm().argument(0).to_primitive_string(global_object()));
|
||||
if (vm.argument(0).is_symbol())
|
||||
return js_string(vm, vm.argument(0).as_symbol().to_string());
|
||||
return TRY(vm.argument(0).to_primitive_string(vm));
|
||||
}
|
||||
|
||||
// 22.1.1.1 String ( value ), https://tc39.es/ecma262/#sec-string-constructor-string-value
|
||||
|
@ -59,7 +60,7 @@ ThrowCompletionOr<Object*> StringConstructor::construct(FunctionObject& new_targ
|
|||
if (!vm.argument_count())
|
||||
primitive_string = js_string(vm, "");
|
||||
else
|
||||
primitive_string = TRY(vm.argument(0).to_primitive_string(global_object));
|
||||
primitive_string = TRY(vm.argument(0).to_primitive_string(vm));
|
||||
auto* prototype = TRY(get_prototype_from_constructor(global_object, new_target, &GlobalObject::string_prototype));
|
||||
return StringObject::create(realm, *primitive_string, *prototype);
|
||||
}
|
||||
|
@ -67,9 +68,9 @@ ThrowCompletionOr<Object*> StringConstructor::construct(FunctionObject& new_targ
|
|||
// 22.1.2.4 String.raw ( template, ...substitutions ), https://tc39.es/ecma262/#sec-string.raw
|
||||
JS_DEFINE_NATIVE_FUNCTION(StringConstructor::raw)
|
||||
{
|
||||
auto* cooked = TRY(vm.argument(0).to_object(global_object));
|
||||
auto* cooked = TRY(vm.argument(0).to_object(vm));
|
||||
auto raw_value = TRY(cooked->get(vm.names.raw));
|
||||
auto* raw = TRY(raw_value.to_object(global_object));
|
||||
auto* raw = TRY(raw_value.to_object(vm));
|
||||
auto literal_segments = TRY(length_of_array_like(global_object, *raw));
|
||||
|
||||
if (literal_segments == 0)
|
||||
|
@ -81,7 +82,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringConstructor::raw)
|
|||
for (size_t i = 0; i < literal_segments; ++i) {
|
||||
auto next_key = String::number(i);
|
||||
auto next_segment_value = TRY(raw->get(next_key));
|
||||
auto next_segment = TRY(next_segment_value.to_string(global_object));
|
||||
auto next_segment = TRY(next_segment_value.to_string(vm));
|
||||
|
||||
builder.append(next_segment);
|
||||
|
||||
|
@ -90,7 +91,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringConstructor::raw)
|
|||
|
||||
if (i < number_of_substituions) {
|
||||
auto next = vm.argument(i + 1);
|
||||
auto next_sub = TRY(next.to_string(global_object));
|
||||
auto next_sub = TRY(next.to_string(vm));
|
||||
builder.append(next_sub);
|
||||
}
|
||||
}
|
||||
|
@ -104,7 +105,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringConstructor::from_char_code)
|
|||
string.ensure_capacity(vm.argument_count());
|
||||
|
||||
for (size_t i = 0; i < vm.argument_count(); ++i)
|
||||
string.append(TRY(vm.argument(i).to_u16(global_object)));
|
||||
string.append(TRY(vm.argument(i).to_u16(vm)));
|
||||
|
||||
return js_string(vm, Utf16String(move(string)));
|
||||
}
|
||||
|
@ -116,10 +117,10 @@ JS_DEFINE_NATIVE_FUNCTION(StringConstructor::from_code_point)
|
|||
string.ensure_capacity(vm.argument_count()); // This will be an under-estimate if any code point is > 0xffff.
|
||||
|
||||
for (size_t i = 0; i < vm.argument_count(); ++i) {
|
||||
auto next_code_point = TRY(vm.argument(i).to_number(global_object));
|
||||
auto next_code_point = TRY(vm.argument(i).to_number(vm));
|
||||
if (!next_code_point.is_integral_number())
|
||||
return vm.throw_completion<RangeError>(ErrorType::InvalidCodePoint, next_code_point.to_string_without_side_effects());
|
||||
auto code_point = TRY(next_code_point.to_i32(global_object));
|
||||
auto code_point = TRY(next_code_point.to_i32(vm));
|
||||
if (code_point < 0 || code_point > 0x10FFFF)
|
||||
return vm.throw_completion<RangeError>(ErrorType::InvalidCodePoint, next_code_point.to_string_without_side_effects());
|
||||
|
||||
|
|
|
@ -35,13 +35,13 @@ namespace JS {
|
|||
static ThrowCompletionOr<String> ak_string_from(VM& vm, GlobalObject& global_object)
|
||||
{
|
||||
auto this_value = TRY(require_object_coercible(global_object, vm.this_value()));
|
||||
return TRY(this_value.to_string(global_object));
|
||||
return TRY(this_value.to_string(vm));
|
||||
}
|
||||
|
||||
static ThrowCompletionOr<Utf16String> utf16_string_from(VM& vm, GlobalObject& global_object)
|
||||
{
|
||||
auto this_value = TRY(require_object_coercible(global_object, vm.this_value()));
|
||||
return TRY(this_value.to_utf16_string(global_object));
|
||||
return TRY(this_value.to_utf16_string(vm));
|
||||
}
|
||||
|
||||
// 22.1.3.21.1 SplitMatch ( S, q, R ), https://tc39.es/ecma262/#sec-splitmatch
|
||||
|
@ -179,7 +179,7 @@ static ThrowCompletionOr<PrimitiveString*> this_string_value(GlobalObject& globa
|
|||
JS_DEFINE_NATIVE_FUNCTION(StringPrototype::char_at)
|
||||
{
|
||||
auto string = TRY(utf16_string_from(vm, global_object));
|
||||
auto position = TRY(vm.argument(0).to_integer_or_infinity(global_object));
|
||||
auto position = TRY(vm.argument(0).to_integer_or_infinity(vm));
|
||||
if (position < 0 || position >= string.length_in_code_units())
|
||||
return js_string(vm, String::empty());
|
||||
|
||||
|
@ -190,7 +190,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::char_at)
|
|||
JS_DEFINE_NATIVE_FUNCTION(StringPrototype::char_code_at)
|
||||
{
|
||||
auto string = TRY(utf16_string_from(vm, global_object));
|
||||
auto position = TRY(vm.argument(0).to_integer_or_infinity(global_object));
|
||||
auto position = TRY(vm.argument(0).to_integer_or_infinity(vm));
|
||||
if (position < 0 || position >= string.length_in_code_units())
|
||||
return js_nan();
|
||||
|
||||
|
@ -201,7 +201,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::char_code_at)
|
|||
JS_DEFINE_NATIVE_FUNCTION(StringPrototype::code_point_at)
|
||||
{
|
||||
auto string = TRY(utf16_string_from(vm, global_object));
|
||||
auto position = TRY(vm.argument(0).to_integer_or_infinity(global_object));
|
||||
auto position = TRY(vm.argument(0).to_integer_or_infinity(vm));
|
||||
if (position < 0 || position >= string.length_in_code_units())
|
||||
return js_undefined();
|
||||
|
||||
|
@ -214,7 +214,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::repeat)
|
|||
{
|
||||
auto string = TRY(ak_string_from(vm, global_object));
|
||||
|
||||
auto n = TRY(vm.argument(0).to_integer_or_infinity(global_object));
|
||||
auto n = TRY(vm.argument(0).to_integer_or_infinity(vm));
|
||||
|
||||
if (n < 0)
|
||||
return vm.throw_completion<RangeError>(ErrorType::StringRepeatCountMustBe, "positive");
|
||||
|
@ -242,17 +242,17 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::starts_with)
|
|||
|
||||
auto search_string_value = vm.argument(0);
|
||||
|
||||
bool search_is_regexp = TRY(search_string_value.is_regexp(global_object));
|
||||
bool search_is_regexp = TRY(search_string_value.is_regexp(vm));
|
||||
if (search_is_regexp)
|
||||
return vm.throw_completion<TypeError>(ErrorType::IsNotA, "searchString", "string, but a regular expression");
|
||||
|
||||
auto search_string = TRY(search_string_value.to_utf16_string(global_object));
|
||||
auto search_string = TRY(search_string_value.to_utf16_string(vm));
|
||||
auto string_length = string.length_in_code_units();
|
||||
auto search_length = search_string.length_in_code_units();
|
||||
|
||||
size_t start = 0;
|
||||
if (!vm.argument(1).is_undefined()) {
|
||||
auto position = TRY(vm.argument(1).to_integer_or_infinity(global_object));
|
||||
auto position = TRY(vm.argument(1).to_integer_or_infinity(vm));
|
||||
start = clamp(position, static_cast<double>(0), static_cast<double>(string_length));
|
||||
}
|
||||
|
||||
|
@ -274,17 +274,17 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::ends_with)
|
|||
|
||||
auto search_string_value = vm.argument(0);
|
||||
|
||||
bool search_is_regexp = TRY(search_string_value.is_regexp(global_object));
|
||||
bool search_is_regexp = TRY(search_string_value.is_regexp(vm));
|
||||
if (search_is_regexp)
|
||||
return vm.throw_completion<TypeError>(ErrorType::IsNotA, "searchString", "string, but a regular expression");
|
||||
|
||||
auto search_string = TRY(search_string_value.to_utf16_string(global_object));
|
||||
auto search_string = TRY(search_string_value.to_utf16_string(vm));
|
||||
auto string_length = string.length_in_code_units();
|
||||
auto search_length = search_string.length_in_code_units();
|
||||
|
||||
size_t end = string_length;
|
||||
if (!vm.argument(1).is_undefined()) {
|
||||
auto position = TRY(vm.argument(1).to_integer_or_infinity(global_object));
|
||||
auto position = TRY(vm.argument(1).to_integer_or_infinity(vm));
|
||||
end = clamp(position, static_cast<double>(0), static_cast<double>(string_length));
|
||||
}
|
||||
|
||||
|
@ -304,13 +304,13 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::index_of)
|
|||
{
|
||||
auto string = TRY(utf16_string_from(vm, global_object));
|
||||
|
||||
auto search_string = TRY(vm.argument(0).to_utf16_string(global_object));
|
||||
auto search_string = TRY(vm.argument(0).to_utf16_string(vm));
|
||||
auto utf16_string_view = string.view();
|
||||
auto utf16_search_view = search_string.view();
|
||||
|
||||
size_t start = 0;
|
||||
if (vm.argument_count() > 1) {
|
||||
auto position = TRY(vm.argument(1).to_integer_or_infinity(global_object));
|
||||
auto position = TRY(vm.argument(1).to_integer_or_infinity(vm));
|
||||
start = clamp(position, static_cast<double>(0), static_cast<double>(utf16_string_view.length_in_code_units()));
|
||||
}
|
||||
|
||||
|
@ -446,13 +446,13 @@ static ThrowCompletionOr<Value> pad_string(GlobalObject& global_object, Utf16Str
|
|||
auto& vm = global_object.vm();
|
||||
auto string_length = string.length_in_code_units();
|
||||
|
||||
auto max_length = TRY(vm.argument(0).to_length(global_object));
|
||||
auto max_length = TRY(vm.argument(0).to_length(vm));
|
||||
if (max_length <= string_length)
|
||||
return js_string(vm, move(string));
|
||||
|
||||
Utf16String fill_string(Vector<u16, 1> { 0x20 });
|
||||
if (!vm.argument(1).is_undefined()) {
|
||||
fill_string = TRY(vm.argument(1).to_utf16_string(global_object));
|
||||
fill_string = TRY(vm.argument(1).to_utf16_string(vm));
|
||||
if (fill_string.is_empty())
|
||||
return js_string(vm, move(string));
|
||||
}
|
||||
|
@ -489,11 +489,13 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::pad_end)
|
|||
|
||||
ThrowCompletionOr<String> trim_string(GlobalObject& global_object, Value input_value, TrimMode where)
|
||||
{
|
||||
auto& vm = global_object.vm();
|
||||
|
||||
// 1. Let str be ? RequireObjectCoercible(string).
|
||||
auto input_string = TRY(require_object_coercible(global_object, input_value));
|
||||
|
||||
// 2. Let S be ? ToString(str).
|
||||
auto string = TRY(input_string.to_string(global_object));
|
||||
auto string = TRY(input_string.to_string(vm));
|
||||
|
||||
// 3. If where is start, let T be the String value that is a copy of S with leading white space removed.
|
||||
// 4. Else if where is end, let T be the String value that is a copy of S with trailing white space removed.
|
||||
|
@ -531,7 +533,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::concat)
|
|||
auto object = TRY(require_object_coercible(global_object, vm.this_value()));
|
||||
|
||||
// 2. Let S be ? ToString(O).
|
||||
auto* string = TRY(object.to_primitive_string(global_object));
|
||||
auto* string = TRY(object.to_primitive_string(vm));
|
||||
|
||||
// 3. Let R be S.
|
||||
auto* result = string;
|
||||
|
@ -539,7 +541,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::concat)
|
|||
// 4. For each element next of args, do
|
||||
for (size_t i = 0; i < vm.argument_count(); ++i) {
|
||||
// a. Let nextString be ? ToString(next).
|
||||
auto* next_string = TRY(vm.argument(i).to_primitive_string(global_object));
|
||||
auto* next_string = TRY(vm.argument(i).to_primitive_string(vm));
|
||||
|
||||
// b. Set R to the string-concatenation of R and nextString.
|
||||
result = js_rope_string(vm, *result, *next_string);
|
||||
|
@ -555,10 +557,10 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::substring)
|
|||
auto string = TRY(utf16_string_from(vm, global_object));
|
||||
auto string_length = static_cast<double>(string.length_in_code_units());
|
||||
|
||||
auto start = TRY(vm.argument(0).to_integer_or_infinity(global_object));
|
||||
auto start = TRY(vm.argument(0).to_integer_or_infinity(vm));
|
||||
auto end = string_length;
|
||||
if (!vm.argument(1).is_undefined())
|
||||
end = TRY(vm.argument(1).to_integer_or_infinity(global_object));
|
||||
end = TRY(vm.argument(1).to_integer_or_infinity(vm));
|
||||
|
||||
size_t final_start = clamp(start, static_cast<double>(0), string_length);
|
||||
size_t final_end = clamp(end, static_cast<double>(0), string_length);
|
||||
|
@ -575,7 +577,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::substr)
|
|||
auto string = TRY(utf16_string_from(vm, global_object));
|
||||
auto size = string.length_in_code_units();
|
||||
|
||||
auto int_start = TRY(vm.argument(0).to_integer_or_infinity(global_object));
|
||||
auto int_start = TRY(vm.argument(0).to_integer_or_infinity(vm));
|
||||
if (Value(int_start).is_negative_infinity())
|
||||
int_start = 0;
|
||||
else if (int_start < 0)
|
||||
|
@ -583,7 +585,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::substr)
|
|||
|
||||
auto length = vm.argument(1);
|
||||
|
||||
auto int_length = length.is_undefined() ? size : TRY(length.to_integer_or_infinity(global_object));
|
||||
auto int_length = length.is_undefined() ? size : TRY(length.to_integer_or_infinity(vm));
|
||||
if (Value(int_start).is_positive_infinity() || (int_length <= 0) || Value(int_length).is_positive_infinity())
|
||||
return js_string(vm, String::empty());
|
||||
|
||||
|
@ -602,15 +604,15 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::includes)
|
|||
|
||||
auto search_string_value = vm.argument(0);
|
||||
|
||||
bool search_is_regexp = TRY(search_string_value.is_regexp(global_object));
|
||||
bool search_is_regexp = TRY(search_string_value.is_regexp(vm));
|
||||
if (search_is_regexp)
|
||||
return vm.throw_completion<TypeError>(ErrorType::IsNotA, "searchString", "string, but a regular expression");
|
||||
|
||||
auto search_string = TRY(search_string_value.to_utf16_string(global_object));
|
||||
auto search_string = TRY(search_string_value.to_utf16_string(vm));
|
||||
|
||||
size_t start = 0;
|
||||
if (!vm.argument(1).is_undefined()) {
|
||||
auto position = TRY(vm.argument(1).to_integer_or_infinity(global_object));
|
||||
auto position = TRY(vm.argument(1).to_integer_or_infinity(vm));
|
||||
start = clamp(position, static_cast<double>(0), static_cast<double>(string.length_in_code_units()));
|
||||
}
|
||||
|
||||
|
@ -624,7 +626,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::slice)
|
|||
auto string = TRY(utf16_string_from(vm, global_object));
|
||||
auto string_length = static_cast<double>(string.length_in_code_units());
|
||||
|
||||
auto int_start = TRY(vm.argument(0).to_integer_or_infinity(global_object));
|
||||
auto int_start = TRY(vm.argument(0).to_integer_or_infinity(vm));
|
||||
if (Value(int_start).is_negative_infinity())
|
||||
int_start = 0;
|
||||
else if (int_start < 0)
|
||||
|
@ -634,7 +636,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::slice)
|
|||
|
||||
auto int_end = string_length;
|
||||
if (!vm.argument(1).is_undefined()) {
|
||||
int_end = TRY(vm.argument(1).to_integer_or_infinity(global_object));
|
||||
int_end = TRY(vm.argument(1).to_integer_or_infinity(vm));
|
||||
if (Value(int_end).is_negative_infinity())
|
||||
int_end = 0;
|
||||
else if (int_end < 0)
|
||||
|
@ -660,21 +662,21 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::split)
|
|||
auto limit_argument = vm.argument(1);
|
||||
|
||||
if (!separator_argument.is_nullish()) {
|
||||
auto splitter = TRY(separator_argument.get_method(global_object, *vm.well_known_symbol_split()));
|
||||
auto splitter = TRY(separator_argument.get_method(vm, *vm.well_known_symbol_split()));
|
||||
if (splitter)
|
||||
return TRY(call(global_object, *splitter, separator_argument, object, limit_argument));
|
||||
}
|
||||
|
||||
auto string = TRY(object.to_utf16_string(global_object));
|
||||
auto string = TRY(object.to_utf16_string(vm));
|
||||
|
||||
auto* array = MUST(Array::create(realm, 0));
|
||||
size_t array_length = 0;
|
||||
|
||||
auto limit = NumericLimits<u32>::max();
|
||||
if (!limit_argument.is_undefined())
|
||||
limit = TRY(limit_argument.to_u32(global_object));
|
||||
limit = TRY(limit_argument.to_u32(vm));
|
||||
|
||||
auto separator = TRY(separator_argument.to_utf16_string(global_object));
|
||||
auto separator = TRY(separator_argument.to_utf16_string(vm));
|
||||
|
||||
if (limit == 0)
|
||||
return array;
|
||||
|
@ -722,12 +724,12 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::last_index_of)
|
|||
{
|
||||
auto string = TRY(utf16_string_from(vm, global_object));
|
||||
|
||||
auto search_string = TRY(vm.argument(0).to_utf16_string(global_object));
|
||||
auto search_string = TRY(vm.argument(0).to_utf16_string(vm));
|
||||
auto string_length = string.length_in_code_units();
|
||||
auto search_length = search_string.length_in_code_units();
|
||||
|
||||
auto position = TRY(vm.argument(1).to_number(global_object));
|
||||
double pos = position.is_nan() ? static_cast<double>(INFINITY) : TRY(position.to_integer_or_infinity(global_object));
|
||||
auto position = TRY(vm.argument(1).to_number(vm));
|
||||
double pos = position.is_nan() ? static_cast<double>(INFINITY) : TRY(position.to_integer_or_infinity(vm));
|
||||
|
||||
size_t start = clamp(pos, static_cast<double>(0), static_cast<double>(string_length));
|
||||
Optional<size_t> last_index;
|
||||
|
@ -755,7 +757,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::at)
|
|||
auto string = TRY(utf16_string_from(vm, global_object));
|
||||
auto length = string.length_in_code_units();
|
||||
|
||||
auto relative_index = TRY(vm.argument(0).to_integer_or_infinity(global_object));
|
||||
auto relative_index = TRY(vm.argument(0).to_integer_or_infinity(vm));
|
||||
if (Value(relative_index).is_infinity())
|
||||
return js_undefined();
|
||||
|
||||
|
@ -778,7 +780,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::symbol_iterator)
|
|||
auto& realm = *global_object.associated_realm();
|
||||
|
||||
auto this_object = TRY(require_object_coercible(global_object, vm.this_value()));
|
||||
auto string = TRY(this_object.to_string(global_object));
|
||||
auto string = TRY(this_object.to_string(vm));
|
||||
return StringIterator::create(realm, string);
|
||||
}
|
||||
|
||||
|
@ -788,14 +790,14 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::match)
|
|||
auto this_object = TRY(require_object_coercible(global_object, vm.this_value()));
|
||||
auto regexp = vm.argument(0);
|
||||
if (!regexp.is_nullish()) {
|
||||
if (auto* matcher = TRY(regexp.get_method(global_object, *vm.well_known_symbol_match())))
|
||||
if (auto* matcher = TRY(regexp.get_method(vm, *vm.well_known_symbol_match())))
|
||||
return TRY(call(global_object, *matcher, regexp, this_object));
|
||||
}
|
||||
|
||||
auto string = TRY(this_object.to_utf16_string(global_object));
|
||||
auto string = TRY(this_object.to_utf16_string(vm));
|
||||
|
||||
auto* rx = TRY(regexp_create(global_object, regexp, js_undefined()));
|
||||
return TRY(Value(rx).invoke(global_object, *vm.well_known_symbol_match(), js_string(vm, move(string))));
|
||||
return TRY(Value(rx).invoke(vm, *vm.well_known_symbol_match(), js_string(vm, move(string))));
|
||||
}
|
||||
|
||||
// 22.1.3.13 String.prototype.matchAll ( regexp ), https://tc39.es/ecma262/#sec-string.prototype.matchall
|
||||
|
@ -804,22 +806,22 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::match_all)
|
|||
auto this_object = TRY(require_object_coercible(global_object, vm.this_value()));
|
||||
auto regexp = vm.argument(0);
|
||||
if (!regexp.is_nullish()) {
|
||||
auto is_regexp = TRY(regexp.is_regexp(global_object));
|
||||
auto is_regexp = TRY(regexp.is_regexp(vm));
|
||||
if (is_regexp) {
|
||||
auto flags = TRY(regexp.as_object().get("flags"));
|
||||
auto flags_object = TRY(require_object_coercible(global_object, flags));
|
||||
auto flags_string = TRY(flags_object.to_string(global_object));
|
||||
auto flags_string = TRY(flags_object.to_string(vm));
|
||||
if (!flags_string.contains('g'))
|
||||
return vm.throw_completion<TypeError>(ErrorType::StringNonGlobalRegExp);
|
||||
}
|
||||
if (auto* matcher = TRY(regexp.get_method(global_object, *vm.well_known_symbol_match_all())))
|
||||
if (auto* matcher = TRY(regexp.get_method(vm, *vm.well_known_symbol_match_all())))
|
||||
return TRY(call(global_object, *matcher, regexp, this_object));
|
||||
}
|
||||
|
||||
auto string = TRY(this_object.to_utf16_string(global_object));
|
||||
auto string = TRY(this_object.to_utf16_string(vm));
|
||||
|
||||
auto* rx = TRY(regexp_create(global_object, regexp, js_string(vm, "g")));
|
||||
return TRY(Value(rx).invoke(global_object, *vm.well_known_symbol_match_all(), js_string(vm, move(string))));
|
||||
return TRY(Value(rx).invoke(vm, *vm.well_known_symbol_match_all(), js_string(vm, move(string))));
|
||||
}
|
||||
|
||||
// 22.1.3.14 String.prototype.normalize ( [ form ] ), https://tc39.es/ecma262/#sec-string.prototype.normalize
|
||||
|
@ -834,7 +836,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::normalize)
|
|||
String form = "NFC";
|
||||
auto form_value = vm.argument(0);
|
||||
if (!form_value.is_undefined())
|
||||
form = TRY(form_value.to_string(global_object));
|
||||
form = TRY(form_value.to_string(vm));
|
||||
|
||||
// 5. If f is not one of "NFC", "NFD", "NFKC", or "NFKD", throw a RangeError exception.
|
||||
if (!form.is_one_of("NFC"sv, "NFD"sv, "NFKC"sv, "NFKD"sv))
|
||||
|
@ -855,15 +857,15 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::replace)
|
|||
auto replace_value = vm.argument(1);
|
||||
|
||||
if (!search_value.is_nullish()) {
|
||||
if (auto* replacer = TRY(search_value.get_method(global_object, *vm.well_known_symbol_replace())))
|
||||
if (auto* replacer = TRY(search_value.get_method(vm, *vm.well_known_symbol_replace())))
|
||||
return TRY(call(global_object, *replacer, search_value, this_object, replace_value));
|
||||
}
|
||||
|
||||
auto string = TRY(this_object.to_utf16_string(global_object));
|
||||
auto search_string = TRY(search_value.to_utf16_string(global_object));
|
||||
auto string = TRY(this_object.to_utf16_string(vm));
|
||||
auto search_string = TRY(search_value.to_utf16_string(vm));
|
||||
|
||||
if (!replace_value.is_function()) {
|
||||
auto replace_string = TRY(replace_value.to_utf16_string(global_object));
|
||||
auto replace_string = TRY(replace_value.to_utf16_string(vm));
|
||||
replace_value = js_string(vm, move(replace_string));
|
||||
}
|
||||
|
||||
|
@ -876,7 +878,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::replace)
|
|||
|
||||
if (replace_value.is_function()) {
|
||||
auto result = TRY(call(global_object, replace_value.as_function(), js_undefined(), js_string(vm, search_string), Value(position.value()), js_string(vm, string)));
|
||||
replacement = TRY(result.to_string(global_object));
|
||||
replacement = TRY(result.to_string(vm));
|
||||
} else {
|
||||
replacement = TRY(get_substitution(global_object, search_string.view(), string.view(), *position, {}, js_undefined(), replace_value));
|
||||
}
|
||||
|
@ -897,26 +899,26 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::replace_all)
|
|||
auto replace_value = vm.argument(1);
|
||||
|
||||
if (!search_value.is_nullish()) {
|
||||
bool is_regexp = TRY(search_value.is_regexp(global_object));
|
||||
bool is_regexp = TRY(search_value.is_regexp(vm));
|
||||
|
||||
if (is_regexp) {
|
||||
auto flags = TRY(search_value.as_object().get(vm.names.flags));
|
||||
auto flags_object = TRY(require_object_coercible(global_object, flags));
|
||||
auto flags_string = TRY(flags_object.to_string(global_object));
|
||||
auto flags_string = TRY(flags_object.to_string(vm));
|
||||
if (!flags_string.contains('g'))
|
||||
return vm.throw_completion<TypeError>(ErrorType::StringNonGlobalRegExp);
|
||||
}
|
||||
|
||||
auto* replacer = TRY(search_value.get_method(global_object, *vm.well_known_symbol_replace()));
|
||||
auto* replacer = TRY(search_value.get_method(vm, *vm.well_known_symbol_replace()));
|
||||
if (replacer)
|
||||
return TRY(call(global_object, *replacer, search_value, this_object, replace_value));
|
||||
}
|
||||
|
||||
auto string = TRY(this_object.to_utf16_string(global_object));
|
||||
auto search_string = TRY(search_value.to_utf16_string(global_object));
|
||||
auto string = TRY(this_object.to_utf16_string(vm));
|
||||
auto search_string = TRY(search_value.to_utf16_string(vm));
|
||||
|
||||
if (!replace_value.is_function()) {
|
||||
auto replace_string = TRY(replace_value.to_utf16_string(global_object));
|
||||
auto replace_string = TRY(replace_value.to_utf16_string(vm));
|
||||
replace_value = js_string(vm, move(replace_string));
|
||||
}
|
||||
|
||||
|
@ -941,7 +943,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::replace_all)
|
|||
|
||||
if (replace_value.is_function()) {
|
||||
auto result = TRY(call(global_object, replace_value.as_function(), js_undefined(), js_string(vm, search_string), Value(position), js_string(vm, string)));
|
||||
replacement = TRY(result.to_string(global_object));
|
||||
replacement = TRY(result.to_string(vm));
|
||||
} else {
|
||||
replacement = TRY(get_substitution(global_object, search_string.view(), string.view(), position, {}, js_undefined(), replace_value));
|
||||
}
|
||||
|
@ -964,14 +966,14 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::search)
|
|||
auto this_object = TRY(require_object_coercible(global_object, vm.this_value()));
|
||||
auto regexp = vm.argument(0);
|
||||
if (!regexp.is_nullish()) {
|
||||
if (auto* searcher = TRY(regexp.get_method(global_object, *vm.well_known_symbol_search())))
|
||||
if (auto* searcher = TRY(regexp.get_method(vm, *vm.well_known_symbol_search())))
|
||||
return TRY(call(global_object, *searcher, regexp, this_object));
|
||||
}
|
||||
|
||||
auto string = TRY(this_object.to_utf16_string(global_object));
|
||||
auto string = TRY(this_object.to_utf16_string(vm));
|
||||
|
||||
auto* rx = TRY(regexp_create(global_object, regexp, js_undefined()));
|
||||
return TRY(Value(rx).invoke(global_object, *vm.well_known_symbol_search(), js_string(vm, move(string))));
|
||||
return TRY(Value(rx).invoke(vm, *vm.well_known_symbol_search(), js_string(vm, move(string))));
|
||||
}
|
||||
|
||||
// B.2.2.2.1 CreateHTML ( string, tag, attribute, value ), https://tc39.es/ecma262/#sec-createhtml
|
||||
|
@ -979,12 +981,12 @@ static ThrowCompletionOr<Value> create_html(GlobalObject& global_object, Value s
|
|||
{
|
||||
auto& vm = global_object.vm();
|
||||
TRY(require_object_coercible(global_object, string));
|
||||
auto str = TRY(string.to_string(global_object));
|
||||
auto str = TRY(string.to_string(vm));
|
||||
StringBuilder builder;
|
||||
builder.append('<');
|
||||
builder.append(tag);
|
||||
if (!attribute.is_empty()) {
|
||||
auto value_string = TRY(value.to_string(global_object));
|
||||
auto value_string = TRY(value.to_string(vm));
|
||||
builder.append(' ');
|
||||
builder.append(attribute);
|
||||
builder.append("=\""sv);
|
||||
|
@ -1085,10 +1087,10 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::locale_compare)
|
|||
auto object = TRY(require_object_coercible(global_object, vm.this_value()));
|
||||
|
||||
// 2. Let S be ? ToString(O).
|
||||
auto string = TRY(object.to_string(global_object));
|
||||
auto string = TRY(object.to_string(vm));
|
||||
|
||||
// 3. Let thatValue be ? ToString(that).
|
||||
auto that_value = TRY(vm.argument(0).to_string(global_object));
|
||||
auto that_value = TRY(vm.argument(0).to_string(vm));
|
||||
|
||||
// 4. Let collator be ? Construct(%Collator%, « locales, options »).
|
||||
auto* collator = TRY(construct(global_object, *global_object.intl_collator_constructor(), vm.argument(1), vm.argument(2)));
|
||||
|
|
|
@ -38,9 +38,10 @@ void SymbolConstructor::initialize(Realm& realm)
|
|||
// 20.4.1.1 Symbol ( [ description ] ), https://tc39.es/ecma262/#sec-symbol-description
|
||||
ThrowCompletionOr<Value> SymbolConstructor::call()
|
||||
{
|
||||
if (vm().argument(0).is_undefined())
|
||||
return js_symbol(heap(), {}, false);
|
||||
return js_symbol(heap(), TRY(vm().argument(0).to_string(global_object())), false);
|
||||
auto& vm = this->vm();
|
||||
if (vm.argument(0).is_undefined())
|
||||
return js_symbol(vm, {}, false);
|
||||
return js_symbol(vm, TRY(vm.argument(0).to_string(vm)), false);
|
||||
}
|
||||
|
||||
// 20.4.1.1 Symbol ( [ description ] ), https://tc39.es/ecma262/#sec-symbol-description
|
||||
|
@ -52,7 +53,7 @@ ThrowCompletionOr<Object*> SymbolConstructor::construct(FunctionObject&)
|
|||
// 20.4.2.2 Symbol.for ( key ), https://tc39.es/ecma262/#sec-symbol.for
|
||||
JS_DEFINE_NATIVE_FUNCTION(SymbolConstructor::for_)
|
||||
{
|
||||
auto description = TRY(vm.argument(0).to_string(global_object));
|
||||
auto description = TRY(vm.argument(0).to_string(vm));
|
||||
return global_object.vm().get_global_symbol(description);
|
||||
}
|
||||
|
||||
|
|
|
@ -104,9 +104,6 @@ ThrowCompletionOr<Value> get_option(VM& vm, Object const& options, PropertyKey c
|
|||
{
|
||||
VERIFY(property.is_string());
|
||||
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Let value be ? Get(options, property).
|
||||
auto value = TRY(options.get(property));
|
||||
|
||||
|
@ -133,7 +130,7 @@ ThrowCompletionOr<Value> get_option(VM& vm, Object const& options, PropertyKey c
|
|||
// 6. Else if type is "number", then
|
||||
else if (type == OptionType::Number) {
|
||||
// a. Set value to ? ToNumber(value).
|
||||
value = TRY(value.to_number(global_object));
|
||||
value = TRY(value.to_number(vm));
|
||||
|
||||
// b. If value is NaN, throw a RangeError exception.
|
||||
if (value.is_nan())
|
||||
|
@ -145,7 +142,7 @@ ThrowCompletionOr<Value> get_option(VM& vm, Object const& options, PropertyKey c
|
|||
VERIFY(type == OptionType::String);
|
||||
|
||||
// b. Set value to ? ToString(value).
|
||||
value = TRY(value.to_primitive_string(global_object));
|
||||
value = TRY(value.to_primitive_string(vm));
|
||||
}
|
||||
|
||||
// 8. If values is not undefined and values does not contain an element equal to value, throw a RangeError exception.
|
||||
|
@ -327,9 +324,6 @@ ThrowCompletionOr<u64> to_temporal_date_time_rounding_increment(VM& vm, Object c
|
|||
// 13.14 ToSecondsStringPrecision ( normalizedOptions ), https://tc39.es/proposal-temporal/#sec-temporal-tosecondsstringprecision
|
||||
ThrowCompletionOr<SecondsStringPrecision> to_seconds_string_precision(VM& vm, Object const& normalized_options)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Let smallestUnit be ? GetTemporalUnit(normalizedOptions, "smallestUnit", time, undefined).
|
||||
auto smallest_unit = TRY(get_temporal_unit(vm, normalized_options, vm.names.smallestUnit, UnitGroup::Time, Optional<StringView> {}));
|
||||
|
||||
|
@ -378,7 +372,7 @@ ThrowCompletionOr<SecondsStringPrecision> to_seconds_string_precision(VM& vm, Ob
|
|||
// a. If fractionalDigitsVal is not undefined, then
|
||||
if (!fractional_digits_value.is_undefined()) {
|
||||
// i. If ? ToString(fractionalDigitsVal) is not "auto", throw a RangeError exception.
|
||||
if (TRY(fractional_digits_value.to_string(global_object)) != "auto"sv)
|
||||
if (TRY(fractional_digits_value.to_string(vm)) != "auto"sv)
|
||||
return vm.template throw_completion<RangeError>(ErrorType::OptionIsNotValidValue, fractional_digits_value, "fractionalSecondDigits"sv);
|
||||
}
|
||||
|
||||
|
@ -536,7 +530,6 @@ ThrowCompletionOr<Optional<String>> get_temporal_unit(VM& vm, Object const& norm
|
|||
ThrowCompletionOr<Value> to_relative_temporal_object(VM& vm, Object const& options)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Assert: Type(options) is Object.
|
||||
|
||||
|
@ -617,7 +610,7 @@ ThrowCompletionOr<Value> to_relative_temporal_object(VM& vm, Object const& optio
|
|||
// 7. Else,
|
||||
else {
|
||||
// a. Let string be ? ToString(value).
|
||||
auto string = TRY(value.to_string(global_object));
|
||||
auto string = TRY(value.to_string(vm));
|
||||
|
||||
// b. Let result be ? ParseTemporalRelativeToString(string).
|
||||
auto parsed_result = TRY(parse_temporal_relative_to_string(vm, string));
|
||||
|
@ -681,7 +674,7 @@ ThrowCompletionOr<Value> to_relative_temporal_object(VM& vm, Object const& optio
|
|||
if (offset_behavior == OffsetBehavior::Option) {
|
||||
// i. Set offsetString to ? ToString(offsetString).
|
||||
// NOTE: offsetString is not used after this path, so we don't need to put this into the original offset_string which is of type JS::Value.
|
||||
auto actual_offset_string = TRY(offset_string.to_string(global_object));
|
||||
auto actual_offset_string = TRY(offset_string.to_string(vm));
|
||||
|
||||
// ii. Let offsetNs be ? ParseTimeZoneOffsetString(offsetString).
|
||||
offset_ns = TRY(parse_time_zone_offset_string(vm, actual_offset_string));
|
||||
|
@ -728,7 +721,6 @@ StringView larger_of_two_temporal_units(StringView unit1, StringView unit2)
|
|||
ThrowCompletionOr<Object*> merge_largest_unit_option(VM& vm, Object const& options, String largest_unit)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Let merged be OrdinaryObjectCreate(null).
|
||||
auto* merged = Object::create(realm, nullptr);
|
||||
|
@ -738,7 +730,7 @@ ThrowCompletionOr<Object*> merge_largest_unit_option(VM& vm, Object const& optio
|
|||
|
||||
// 3. For each element nextKey of keys, do
|
||||
for (auto& key : keys) {
|
||||
auto next_key = MUST(PropertyKey::from_value(global_object, key));
|
||||
auto next_key = MUST(PropertyKey::from_value(vm, key));
|
||||
|
||||
// a. Let propValue be ? Get(options, nextKey).
|
||||
auto prop_value = TRY(options.get(next_key));
|
||||
|
@ -1729,7 +1721,6 @@ ThrowCompletionOr<double> to_positive_integer(VM& vm, Value argument)
|
|||
ThrowCompletionOr<Object*> prepare_temporal_fields(VM& vm, Object const& fields, Vector<String> const& field_names, Variant<PrepareTemporalFieldsPartial, Vector<StringView>> const& required_fields)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Let result be OrdinaryObjectCreate(null).
|
||||
auto* result = Object::create(realm, nullptr);
|
||||
|
@ -1766,7 +1757,7 @@ ThrowCompletionOr<Object*> prepare_temporal_fields(VM& vm, Object const& fields,
|
|||
else if (property.is_one_of("monthCode"sv, "offset"sv, "era"sv)) {
|
||||
// a. Assert: Conversion is ToString.
|
||||
// b. Set value to ? ToString(value).
|
||||
value = TRY(value.to_primitive_string(global_object));
|
||||
value = TRY(value.to_primitive_string(vm));
|
||||
}
|
||||
|
||||
// iii. Perform ! CreateDataPropertyOrThrow(result, property, value).
|
||||
|
|
|
@ -191,11 +191,8 @@ ThrowCompletionOr<Value> get_option(VM& vm, Object const& options, PropertyKey c
|
|||
template<typename... Args>
|
||||
ThrowCompletionOr<double> to_integer_throw_on_infinity(VM& vm, Value argument, ErrorType error_type, Args... args)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Let integer be ? ToIntegerOrInfinity(argument).
|
||||
auto integer = TRY(argument.to_integer_or_infinity(global_object));
|
||||
auto integer = TRY(argument.to_integer_or_infinity(vm));
|
||||
|
||||
// 2. If integer is -∞ or +∞ , then
|
||||
if (Value(integer).is_infinity()) {
|
||||
|
@ -211,11 +208,8 @@ ThrowCompletionOr<double> to_integer_throw_on_infinity(VM& vm, Value argument, E
|
|||
template<typename... Args>
|
||||
ThrowCompletionOr<double> to_integer_without_rounding(VM& vm, Value argument, ErrorType error_type, Args... args)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Let number be ? ToNumber(argument).
|
||||
auto number = TRY(argument.to_number(global_object));
|
||||
auto number = TRY(argument.to_number(vm));
|
||||
|
||||
// 2. If number is NaN, +0𝔽, or -0𝔽, return 0.
|
||||
if (number.is_nan() || number.is_positive_zero() || number.is_negative_zero())
|
||||
|
|
|
@ -106,7 +106,7 @@ ThrowCompletionOr<Vector<String>> calendar_fields(VM& vm, Object& calendar, Vect
|
|||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Let fields be ? GetMethod(calendar, "fields").
|
||||
auto fields = TRY(Value(&calendar).get_method(global_object, vm.names.fields));
|
||||
auto fields = TRY(Value(&calendar).get_method(vm, vm.names.fields));
|
||||
|
||||
// 2. Let fieldsArray be CreateArrayFromList(fieldNames).
|
||||
auto field_names_values = MarkedVector<Value> { vm.heap() };
|
||||
|
@ -136,7 +136,7 @@ ThrowCompletionOr<Object*> calendar_merge_fields(VM& vm, Object& calendar, Objec
|
|||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Let mergeFields be ? GetMethod(calendar, "mergeFields").
|
||||
auto* merge_fields = TRY(Value(&calendar).get_method(global_object, vm.names.mergeFields));
|
||||
auto* merge_fields = TRY(Value(&calendar).get_method(vm, vm.names.mergeFields));
|
||||
|
||||
// 2. If mergeFields is undefined, then
|
||||
if (!merge_fields) {
|
||||
|
@ -168,13 +168,13 @@ ThrowCompletionOr<PlainDate*> calendar_date_add(VM& vm, Object& calendar, Value
|
|||
|
||||
// 4. If dateAdd is not present, set dateAdd to ? GetMethod(calendar, "dateAdd").
|
||||
if (!date_add)
|
||||
date_add = TRY(Value(&calendar).get_method(global_object, vm.names.dateAdd));
|
||||
date_add = TRY(Value(&calendar).get_method(vm, vm.names.dateAdd));
|
||||
|
||||
// 5. Let addedDate be ? Call(dateAdd, calendar, « date, duration, options »).
|
||||
auto added_date = TRY(call(global_object, date_add ?: js_undefined(), &calendar, date, &duration, options ?: js_undefined()));
|
||||
|
||||
// 6. Perform ? RequireInternalSlot(addedDate, [[InitializedTemporalDate]]).
|
||||
auto* added_date_object = TRY(added_date.to_object(global_object));
|
||||
auto* added_date_object = TRY(added_date.to_object(vm));
|
||||
if (!is<PlainDate>(added_date_object))
|
||||
return vm.throw_completion<TypeError>(ErrorType::NotAnObjectOfType, "Temporal.PlainDate");
|
||||
|
||||
|
@ -192,13 +192,13 @@ ThrowCompletionOr<Duration*> calendar_date_until(VM& vm, Object& calendar, Value
|
|||
|
||||
// 2. If dateUntil is not present, set dateUntil to ? GetMethod(calendar, "dateUntil").
|
||||
if (!date_until)
|
||||
date_until = TRY(Value(&calendar).get_method(global_object, vm.names.dateUntil));
|
||||
date_until = TRY(Value(&calendar).get_method(vm, vm.names.dateUntil));
|
||||
|
||||
// 3. Let duration be ? Call(dateUntil, calendar, « one, two, options »).
|
||||
auto duration = TRY(call(global_object, date_until ?: js_undefined(), &calendar, one, two, &options));
|
||||
|
||||
// 4. Perform ? RequireInternalSlot(duration, [[InitializedTemporalDuration]]).
|
||||
auto* duration_object = TRY(duration.to_object(global_object));
|
||||
auto* duration_object = TRY(duration.to_object(vm));
|
||||
if (!is<Duration>(duration_object))
|
||||
return vm.throw_completion<TypeError>(ErrorType::NotAnObjectOfType, "Temporal.Duration");
|
||||
|
||||
|
@ -209,13 +209,10 @@ ThrowCompletionOr<Duration*> calendar_date_until(VM& vm, Object& calendar, Value
|
|||
// 12.2.8 CalendarYear ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendaryear
|
||||
ThrowCompletionOr<double> calendar_year(VM& vm, Object& calendar, Object& date_like)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Assert: Type(calendar) is Object.
|
||||
|
||||
// 2. Let result be ? Invoke(calendar, "year", « dateLike »).
|
||||
auto result = TRY(Value(&calendar).invoke(global_object, vm.names.year, &date_like));
|
||||
auto result = TRY(Value(&calendar).invoke(vm, vm.names.year, &date_like));
|
||||
|
||||
// 3. If result is undefined, throw a RangeError exception.
|
||||
if (result.is_undefined())
|
||||
|
@ -228,13 +225,10 @@ ThrowCompletionOr<double> calendar_year(VM& vm, Object& calendar, Object& date_l
|
|||
// 12.2.9 CalendarMonth ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendarmonth
|
||||
ThrowCompletionOr<double> calendar_month(VM& vm, Object& calendar, Object& date_like)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Assert: Type(calendar) is Object.
|
||||
|
||||
// 2. Let result be ? Invoke(calendar, "month", « dateLike »).
|
||||
auto result = TRY(Value(&calendar).invoke(global_object, vm.names.month, &date_like));
|
||||
auto result = TRY(Value(&calendar).invoke(vm, vm.names.month, &date_like));
|
||||
|
||||
// NOTE: Explicitly handled for a better error message similar to the other calendar property AOs
|
||||
if (result.is_undefined())
|
||||
|
@ -247,32 +241,26 @@ ThrowCompletionOr<double> calendar_month(VM& vm, Object& calendar, Object& date_
|
|||
// 12.2.10 CalendarMonthCode ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendarmonthcode
|
||||
ThrowCompletionOr<String> calendar_month_code(VM& vm, Object& calendar, Object& date_like)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Assert: Type(calendar) is Object.
|
||||
|
||||
// 2. Let result be ? Invoke(calendar, "monthCode", « dateLike »).
|
||||
auto result = TRY(Value(&calendar).invoke(global_object, vm.names.monthCode, &date_like));
|
||||
auto result = TRY(Value(&calendar).invoke(vm, vm.names.monthCode, &date_like));
|
||||
|
||||
// 3. If result is undefined, throw a RangeError exception.
|
||||
if (result.is_undefined())
|
||||
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidCalendarFunctionResult, vm.names.monthCode.as_string(), vm.names.undefined.as_string());
|
||||
|
||||
// 4. Return ? ToString(result).
|
||||
return result.to_string(global_object);
|
||||
return result.to_string(vm);
|
||||
}
|
||||
|
||||
// 12.2.11 CalendarDay ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendarday
|
||||
ThrowCompletionOr<double> calendar_day(VM& vm, Object& calendar, Object& date_like)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Assert: Type(calendar) is Object.
|
||||
|
||||
// 2. Let result be ? Invoke(calendar, "day", « dateLike »).
|
||||
auto result = TRY(Value(&calendar).invoke(global_object, vm.names.day, &date_like));
|
||||
auto result = TRY(Value(&calendar).invoke(vm, vm.names.day, &date_like));
|
||||
|
||||
// NOTE: Explicitly handled for a better error message similar to the other calendar property AOs
|
||||
if (result.is_undefined())
|
||||
|
@ -285,113 +273,86 @@ ThrowCompletionOr<double> calendar_day(VM& vm, Object& calendar, Object& date_li
|
|||
// 12.2.12 CalendarDayOfWeek ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendardayofweek
|
||||
ThrowCompletionOr<Value> calendar_day_of_week(VM& vm, Object& calendar, Object& date_like)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Assert: Type(calendar) is Object.
|
||||
|
||||
// 2. Return ? Invoke(calendar, "dayOfWeek", « dateLike »).
|
||||
return TRY(Value(&calendar).invoke(global_object, vm.names.dayOfWeek, &date_like));
|
||||
return TRY(Value(&calendar).invoke(vm, vm.names.dayOfWeek, &date_like));
|
||||
}
|
||||
|
||||
// 12.2.13 CalendarDayOfYear ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendardayofyear
|
||||
ThrowCompletionOr<Value> calendar_day_of_year(VM& vm, Object& calendar, Object& date_like)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Assert: Type(calendar) is Object.
|
||||
|
||||
// 2. Return ? Invoke(calendar, "dayOfYear", « dateLike »).
|
||||
return TRY(Value(&calendar).invoke(global_object, vm.names.dayOfYear, &date_like));
|
||||
return TRY(Value(&calendar).invoke(vm, vm.names.dayOfYear, &date_like));
|
||||
}
|
||||
|
||||
// 12.2.14 CalendarWeekOfYear ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendarweekofyear
|
||||
ThrowCompletionOr<Value> calendar_week_of_year(VM& vm, Object& calendar, Object& date_like)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Assert: Type(calendar) is Object.
|
||||
|
||||
// 2. Return ? Invoke(calendar, "weekOfYear", « dateLike »).
|
||||
return TRY(Value(&calendar).invoke(global_object, vm.names.weekOfYear, &date_like));
|
||||
return TRY(Value(&calendar).invoke(vm, vm.names.weekOfYear, &date_like));
|
||||
}
|
||||
|
||||
// 12.2.14 CalendarDaysInWeek ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendardaysinweek
|
||||
ThrowCompletionOr<Value> calendar_days_in_week(VM& vm, Object& calendar, Object& date_like)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Assert: Type(calendar) is Object.
|
||||
|
||||
// 2. Return ? Invoke(calendar, "daysInWeek", « dateLike »).
|
||||
return TRY(Value(&calendar).invoke(global_object, vm.names.daysInWeek, &date_like));
|
||||
return TRY(Value(&calendar).invoke(vm, vm.names.daysInWeek, &date_like));
|
||||
}
|
||||
|
||||
// 12.2.16 CalendarDaysInMonth ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendardaysinmonth
|
||||
ThrowCompletionOr<Value> calendar_days_in_month(VM& vm, Object& calendar, Object& date_like)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Assert: Type(calendar) is Object.
|
||||
|
||||
// 2. Return ? Invoke(calendar, "daysInMonth", « dateLike »).
|
||||
return TRY(Value(&calendar).invoke(global_object, vm.names.daysInMonth, &date_like));
|
||||
return TRY(Value(&calendar).invoke(vm, vm.names.daysInMonth, &date_like));
|
||||
}
|
||||
|
||||
// 12.2.17 CalendarDaysInYear ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendardaysinyear
|
||||
ThrowCompletionOr<Value> calendar_days_in_year(VM& vm, Object& calendar, Object& date_like)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Assert: Type(calendar) is Object.
|
||||
|
||||
// 2. Return ? Invoke(calendar, "daysInYear", « dateLike »).
|
||||
return TRY(Value(&calendar).invoke(global_object, vm.names.daysInYear, &date_like));
|
||||
return TRY(Value(&calendar).invoke(vm, vm.names.daysInYear, &date_like));
|
||||
}
|
||||
|
||||
// 12.2.18 CalendarMonthsInYear ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendarmonthsinyear
|
||||
ThrowCompletionOr<Value> calendar_months_in_year(VM& vm, Object& calendar, Object& date_like)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Assert: Type(calendar) is Object.
|
||||
|
||||
// 2. Return ? Invoke(calendar, "monthsInYear", « dateLike »).
|
||||
return TRY(Value(&calendar).invoke(global_object, vm.names.monthsInYear, &date_like));
|
||||
return TRY(Value(&calendar).invoke(vm, vm.names.monthsInYear, &date_like));
|
||||
}
|
||||
|
||||
// 12.2.29 CalendarInLeapYear ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendarinleapyear
|
||||
ThrowCompletionOr<Value> calendar_in_leap_year(VM& vm, Object& calendar, Object& date_like)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Assert: Type(calendar) is Object.
|
||||
|
||||
// 2. Return ? Invoke(calendar, "inLeapYear", « dateLike »).
|
||||
return TRY(Value(&calendar).invoke(global_object, vm.names.inLeapYear, &date_like));
|
||||
return TRY(Value(&calendar).invoke(vm, vm.names.inLeapYear, &date_like));
|
||||
}
|
||||
|
||||
// 15.6.1.1 CalendarEra ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendarera
|
||||
ThrowCompletionOr<Value> calendar_era(VM& vm, Object& calendar, Object& date_like)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Assert: Type(calendar) is Object.
|
||||
|
||||
// 2. Let result be ? Invoke(calendar, "era", « dateLike »).
|
||||
auto result = TRY(Value(&calendar).invoke(global_object, vm.names.era, &date_like));
|
||||
auto result = TRY(Value(&calendar).invoke(vm, vm.names.era, &date_like));
|
||||
|
||||
// 3. If result is not undefined, set result to ? ToString(result).
|
||||
if (!result.is_undefined())
|
||||
result = js_string(vm, TRY(result.to_string(global_object)));
|
||||
result = js_string(vm, TRY(result.to_string(vm)));
|
||||
|
||||
// 4. Return result.
|
||||
return result;
|
||||
|
@ -400,13 +361,10 @@ ThrowCompletionOr<Value> calendar_era(VM& vm, Object& calendar, Object& date_lik
|
|||
// 15.6.1.2 CalendarEraYear ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendarerayear
|
||||
ThrowCompletionOr<Value> calendar_era_year(VM& vm, Object& calendar, Object& date_like)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Assert: Type(calendar) is Object.
|
||||
|
||||
// 2. Let result be ? Invoke(calendar, "eraYear", « dateLike »).
|
||||
auto result = TRY(Value(&calendar).invoke(global_object, vm.names.eraYear, &date_like));
|
||||
auto result = TRY(Value(&calendar).invoke(vm, vm.names.eraYear, &date_like));
|
||||
|
||||
// 3. If result is not undefined, set result to ? ToIntegerThrowOnInfinity(result).
|
||||
if (!result.is_undefined())
|
||||
|
@ -419,9 +377,6 @@ ThrowCompletionOr<Value> calendar_era_year(VM& vm, Object& calendar, Object& dat
|
|||
// 12.2.20 ToTemporalCalendar ( temporalCalendarLike ), https://tc39.es/proposal-temporal/#sec-temporal-totemporalcalendar
|
||||
ThrowCompletionOr<Object*> to_temporal_calendar(VM& vm, Value temporal_calendar_like)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. If Type(temporalCalendarLike) is Object, then
|
||||
if (temporal_calendar_like.is_object()) {
|
||||
auto& temporal_calendar_like_object = temporal_calendar_like.as_object();
|
||||
|
@ -453,7 +408,7 @@ ThrowCompletionOr<Object*> to_temporal_calendar(VM& vm, Value temporal_calendar_
|
|||
}
|
||||
|
||||
// 2. Let identifier be ? ToString(temporalCalendarLike).
|
||||
auto identifier = TRY(temporal_calendar_like.to_string(global_object));
|
||||
auto identifier = TRY(temporal_calendar_like.to_string(vm));
|
||||
|
||||
// 3. If IsBuiltinCalendar(identifier) is false, then
|
||||
if (!is_builtin_calendar(identifier)) {
|
||||
|
@ -509,16 +464,13 @@ ThrowCompletionOr<Object*> get_temporal_calendar_with_iso_default(VM& vm, Object
|
|||
// 12.2.23 CalendarDateFromFields ( calendar, fields [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal-calendardatefromfields
|
||||
ThrowCompletionOr<PlainDate*> calendar_date_from_fields(VM& vm, Object& calendar, Object const& fields, Object const* options)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. If options is not present, set options to undefined.
|
||||
|
||||
// 2. Let date be ? Invoke(calendar, "dateFromFields", « fields, options »).
|
||||
auto date = TRY(Value(&calendar).invoke(global_object, vm.names.dateFromFields, &fields, options ?: js_undefined()));
|
||||
auto date = TRY(Value(&calendar).invoke(vm, vm.names.dateFromFields, &fields, options ?: js_undefined()));
|
||||
|
||||
// 3. Perform ? RequireInternalSlot(date, [[InitializedTemporalDate]]).
|
||||
auto* date_object = TRY(date.to_object(global_object));
|
||||
auto* date_object = TRY(date.to_object(vm));
|
||||
if (!is<PlainDate>(date_object))
|
||||
return vm.throw_completion<TypeError>(ErrorType::NotAnObjectOfType, "Temporal.PlainDate");
|
||||
|
||||
|
@ -529,16 +481,13 @@ ThrowCompletionOr<PlainDate*> calendar_date_from_fields(VM& vm, Object& calendar
|
|||
// 12.2.24 CalendarYearMonthFromFields ( calendar, fields [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal-calendaryearmonthfromfields
|
||||
ThrowCompletionOr<PlainYearMonth*> calendar_year_month_from_fields(VM& vm, Object& calendar, Object const& fields, Object const* options)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. If options is not present, set options to undefined.
|
||||
|
||||
// 2. Let yearMonth be ? Invoke(calendar, "yearMonthFromFields", « fields, options »).
|
||||
auto year_month = TRY(Value(&calendar).invoke(global_object, vm.names.yearMonthFromFields, &fields, options ?: js_undefined()));
|
||||
auto year_month = TRY(Value(&calendar).invoke(vm, vm.names.yearMonthFromFields, &fields, options ?: js_undefined()));
|
||||
|
||||
// 3. Perform ? RequireInternalSlot(yearMonth, [[InitializedTemporalYearMonth]]).
|
||||
auto* year_month_object = TRY(year_month.to_object(global_object));
|
||||
auto* year_month_object = TRY(year_month.to_object(vm));
|
||||
if (!is<PlainYearMonth>(year_month_object))
|
||||
return vm.throw_completion<TypeError>(ErrorType::NotAnObjectOfType, "Temporal.PlainYearMonth");
|
||||
|
||||
|
@ -549,16 +498,13 @@ ThrowCompletionOr<PlainYearMonth*> calendar_year_month_from_fields(VM& vm, Objec
|
|||
// 12.2.25 CalendarMonthDayFromFields ( calendar, fields [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal-calendarmonthdayfromfields
|
||||
ThrowCompletionOr<PlainMonthDay*> calendar_month_day_from_fields(VM& vm, Object& calendar, Object const& fields, Object const* options)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. If options is not present, set options to undefined.
|
||||
|
||||
// 2. Let monthDay be ? Invoke(calendar, "monthDayFromFields", « fields, options »).
|
||||
auto month_day = TRY(Value(&calendar).invoke(global_object, vm.names.monthDayFromFields, &fields, options ?: js_undefined()));
|
||||
auto month_day = TRY(Value(&calendar).invoke(vm, vm.names.monthDayFromFields, &fields, options ?: js_undefined()));
|
||||
|
||||
// 3. Perform ? RequireInternalSlot(monthDay, [[InitializedTemporalMonthDay]]).
|
||||
auto* month_day_object = TRY(month_day.to_object(global_object));
|
||||
auto* month_day_object = TRY(month_day.to_object(vm));
|
||||
if (!is<PlainMonthDay>(month_day_object))
|
||||
return vm.throw_completion<TypeError>(ErrorType::NotAnObjectOfType, "Temporal.PlainMonthDay");
|
||||
|
||||
|
@ -587,18 +533,15 @@ String format_calendar_annotation(StringView id, StringView show_calendar)
|
|||
// 12.2.27 CalendarEquals ( one, two ), https://tc39.es/proposal-temporal/#sec-temporal-calendarequals
|
||||
ThrowCompletionOr<bool> calendar_equals(VM& vm, Object& one, Object& two)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. If one and two are the same Object value, return true.
|
||||
if (&one == &two)
|
||||
return true;
|
||||
|
||||
// 2. Let calendarOne be ? ToString(one).
|
||||
auto calendar_one = TRY(Value(&one).to_string(global_object));
|
||||
auto calendar_one = TRY(Value(&one).to_string(vm));
|
||||
|
||||
// 3. Let calendarTwo be ? ToString(two).
|
||||
auto calendar_two = TRY(Value(&two).to_string(global_object));
|
||||
auto calendar_two = TRY(Value(&two).to_string(vm));
|
||||
|
||||
// 4. If calendarOne is calendarTwo, return true.
|
||||
if (calendar_one == calendar_two)
|
||||
|
@ -611,18 +554,15 @@ ThrowCompletionOr<bool> calendar_equals(VM& vm, Object& one, Object& two)
|
|||
// 12.2.28 ConsolidateCalendars ( one, two ), https://tc39.es/proposal-temporal/#sec-temporal-consolidatecalendars
|
||||
ThrowCompletionOr<Object*> consolidate_calendars(VM& vm, Object& one, Object& two)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. If one and two are the same Object value, return two.
|
||||
if (&one == &two)
|
||||
return &two;
|
||||
|
||||
// 2. Let calendarOne be ? ToString(one).
|
||||
auto calendar_one = TRY(Value(&one).to_string(global_object));
|
||||
auto calendar_one = TRY(Value(&one).to_string(vm));
|
||||
|
||||
// 3. Let calendarTwo be ? ToString(two).
|
||||
auto calendar_two = TRY(Value(&two).to_string(global_object));
|
||||
auto calendar_two = TRY(Value(&two).to_string(vm));
|
||||
|
||||
// 4. If calendarOne is calendarTwo, return two.
|
||||
if (calendar_one == calendar_two)
|
||||
|
@ -706,9 +646,6 @@ String build_iso_month_code(u8 month)
|
|||
// 12.2.32 ResolveISOMonth ( fields ), https://tc39.es/proposal-temporal/#sec-temporal-resolveisomonth
|
||||
ThrowCompletionOr<double> resolve_iso_month(VM& vm, Object const& fields)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Assert: fields is an ordinary object with no more and no less than the own data properties listed in Table 13.
|
||||
|
||||
// 2. Let month be ! Get(fields, "month").
|
||||
|
@ -745,7 +682,7 @@ ThrowCompletionOr<double> resolve_iso_month(VM& vm, Object const& fields)
|
|||
auto number_part = month_code_string.substring(1);
|
||||
|
||||
// 9. Set numberPart to ! ToIntegerOrInfinity(numberPart).
|
||||
auto number_part_integer = MUST(Value(js_string(vm, move(number_part))).to_integer_or_infinity(global_object));
|
||||
auto number_part_integer = MUST(Value(js_string(vm, move(number_part))).to_integer_or_infinity(vm));
|
||||
|
||||
// 10. If numberPart < 1 or numberPart > 12, throw a RangeError exception.
|
||||
if (number_part_integer < 1 || number_part_integer > 12)
|
||||
|
@ -970,7 +907,7 @@ ThrowCompletionOr<Object*> default_merge_calendar_fields(VM& vm, Object const& f
|
|||
for (auto& key : fields_keys) {
|
||||
// a. If key is not "month" or "monthCode", then
|
||||
if (key.as_string().string() != vm.names.month.as_string() && key.as_string().string() != vm.names.monthCode.as_string()) {
|
||||
auto property_key = MUST(PropertyKey::from_value(global_object, key));
|
||||
auto property_key = MUST(PropertyKey::from_value(vm, key));
|
||||
|
||||
// i. Let propValue be ? Get(fields, key).
|
||||
auto prop_value = TRY(fields.get(property_key));
|
||||
|
@ -991,7 +928,7 @@ ThrowCompletionOr<Object*> default_merge_calendar_fields(VM& vm, Object const& f
|
|||
|
||||
// 5. For each element key of additionalFieldsKeys, do
|
||||
for (auto& key : additional_fields_keys) {
|
||||
auto property_key = MUST(PropertyKey::from_value(global_object, key));
|
||||
auto property_key = MUST(PropertyKey::from_value(vm, key));
|
||||
|
||||
// a. Let propValue be ? Get(additionalFields, key).
|
||||
auto prop_value = TRY(additional_fields.get(property_key));
|
||||
|
|
|
@ -45,10 +45,9 @@ ThrowCompletionOr<Value> CalendarConstructor::call()
|
|||
ThrowCompletionOr<Object*> CalendarConstructor::construct(FunctionObject& new_target)
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
auto& global_object = this->global_object();
|
||||
|
||||
// 2. Set id to ? ToString(id).
|
||||
auto identifier = TRY(vm.argument(0).to_string(global_object));
|
||||
auto identifier = TRY(vm.argument(0).to_string(vm));
|
||||
|
||||
// 3. If IsBuiltinCalendar(id) is false, then
|
||||
if (!is_builtin_calendar(identifier)) {
|
||||
|
|
|
@ -70,7 +70,7 @@ JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::id_getter)
|
|||
auto* calendar = TRY(typed_this_object(vm));
|
||||
|
||||
// 3. Return ? ToString(calendar).
|
||||
return { js_string(vm, TRY(Value(calendar).to_string(global_object))) };
|
||||
return { js_string(vm, TRY(Value(calendar).to_string(vm))) };
|
||||
}
|
||||
|
||||
// 12.4.4 Temporal.Calendar.prototype.dateFromFields ( fields [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal.calendar.prototype.datefromfields
|
||||
|
@ -575,10 +575,10 @@ JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::merge_fields)
|
|||
auto* calendar = TRY(typed_this_object(vm));
|
||||
|
||||
// 3. Set fields to ? ToObject(fields).
|
||||
auto* fields = TRY(vm.argument(0).to_object(global_object));
|
||||
auto* fields = TRY(vm.argument(0).to_object(vm));
|
||||
|
||||
// 4. Set additionalFields to ? ToObject(additionalFields).
|
||||
auto* additional_fields = TRY(vm.argument(1).to_object(global_object));
|
||||
auto* additional_fields = TRY(vm.argument(1).to_object(vm));
|
||||
|
||||
// 5. Assert: calendar.[[Identifier]] is "iso8601".
|
||||
VERIFY(calendar->identifier() == "iso8601"sv);
|
||||
|
@ -606,7 +606,7 @@ JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::to_json)
|
|||
auto* calendar = TRY(typed_this_object(vm));
|
||||
|
||||
// 3. Return ? ToString(calendar).
|
||||
return js_string(vm, TRY(Value(calendar).to_string(global_object)));
|
||||
return js_string(vm, TRY(Value(calendar).to_string(vm)));
|
||||
}
|
||||
|
||||
// 15.6.2.6 Temporal.Calendar.prototype.era ( temporalDateLike ), https://tc39.es/proposal-temporal/#sec-temporal.calendar.prototype.era
|
||||
|
|
|
@ -139,13 +139,10 @@ ThrowCompletionOr<Duration*> to_temporal_duration(VM& vm, Value item)
|
|||
// 7.5.9 ToTemporalDurationRecord ( temporalDurationLike ), https://tc39.es/proposal-temporal/#sec-temporal-totemporaldurationrecord
|
||||
ThrowCompletionOr<DurationRecord> to_temporal_duration_record(VM& vm, Value temporal_duration_like)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. If Type(temporalDurationLike) is not Object, then
|
||||
if (!temporal_duration_like.is_object()) {
|
||||
// a. Let string be ? ToString(temporalDurationLike).
|
||||
auto string = TRY(temporal_duration_like.to_string(global_object));
|
||||
auto string = TRY(temporal_duration_like.to_string(vm));
|
||||
|
||||
// b. Return ? ParseTemporalDurationString(string).
|
||||
return parse_temporal_duration_string(vm, string);
|
||||
|
@ -566,7 +563,6 @@ ThrowCompletionOr<TimeDurationRecord> balance_duration(VM& vm, double days, doub
|
|||
ThrowCompletionOr<DateDurationRecord> unbalance_duration_relative(VM& vm, double years, double months, double weeks, double days, String const& largest_unit, Value relative_to)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. If largestUnit is "year", or years, months, weeks, and days are all 0, then
|
||||
if (largest_unit == "year"sv || (years == 0 && months == 0 && weeks == 0 && days == 0)) {
|
||||
|
@ -615,10 +611,10 @@ ThrowCompletionOr<DateDurationRecord> unbalance_duration_relative(VM& vm, double
|
|||
}
|
||||
|
||||
// b. Let dateAdd be ? GetMethod(calendar, "dateAdd").
|
||||
auto* date_add = TRY(Value(calendar).get_method(global_object, vm.names.dateAdd));
|
||||
auto* date_add = TRY(Value(calendar).get_method(vm, vm.names.dateAdd));
|
||||
|
||||
// c. Let dateUntil be ? GetMethod(calendar, "dateUntil").
|
||||
auto* date_until = TRY(Value(calendar).get_method(global_object, vm.names.dateUntil));
|
||||
auto* date_until = TRY(Value(calendar).get_method(vm, vm.names.dateUntil));
|
||||
|
||||
// d. Repeat, while years ≠ 0,
|
||||
while (years != 0) {
|
||||
|
@ -750,7 +746,6 @@ ThrowCompletionOr<DateDurationRecord> unbalance_duration_relative(VM& vm, double
|
|||
ThrowCompletionOr<DateDurationRecord> balance_duration_relative(VM& vm, double years, double months, double weeks, double days, String const& largest_unit, Value relative_to_value)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. If largestUnit is not one of "year", "month", or "week", or years, months, weeks, and days are all 0, then
|
||||
if (!largest_unit.is_one_of("year"sv, "month"sv, "week"sv) || (years == 0 && months == 0 && weeks == 0 && days == 0)) {
|
||||
|
@ -848,13 +843,13 @@ ThrowCompletionOr<DateDurationRecord> balance_duration_relative(VM& vm, double y
|
|||
}
|
||||
|
||||
// i. Let dateAdd be ? GetMethod(calendar, "dateAdd").
|
||||
auto* date_add = TRY(Value(&calendar).get_method(global_object, vm.names.dateAdd));
|
||||
auto* date_add = TRY(Value(&calendar).get_method(vm, vm.names.dateAdd));
|
||||
|
||||
// j. Set newRelativeTo to ? CalendarDateAdd(calendar, relativeTo, oneYear, undefined, dateAdd).
|
||||
new_relative_to = TRY(calendar_date_add(vm, calendar, relative_to, *one_year, nullptr, date_add));
|
||||
|
||||
// k. Let dateUntil be ? GetMethod(calendar, "dateUntil").
|
||||
auto* date_until = TRY(Value(&calendar).get_method(global_object, vm.names.dateUntil));
|
||||
auto* date_until = TRY(Value(&calendar).get_method(vm, vm.names.dateUntil));
|
||||
|
||||
// l. Let untilOptions be OrdinaryObjectCreate(null).
|
||||
auto* until_options = Object::create(realm, nullptr);
|
||||
|
@ -971,7 +966,6 @@ ThrowCompletionOr<DateDurationRecord> balance_duration_relative(VM& vm, double y
|
|||
ThrowCompletionOr<DurationRecord> add_duration(VM& vm, double years1, double months1, double weeks1, double days1, double hours1, double minutes1, double seconds1, double milliseconds1, double microseconds1, double nanoseconds1, double years2, double months2, double weeks2, double days2, double hours2, double minutes2, double seconds2, double milliseconds2, double microseconds2, double nanoseconds2, Value relative_to_value)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
VERIFY(all_of(AK::Array { years1, months1, weeks1, days1, hours1, minutes1, seconds1, milliseconds1, microseconds1, nanoseconds1, years2, months2, weeks2, days2, hours2, minutes2, seconds2, milliseconds2, microseconds2, nanoseconds2 }, [](auto value) { return value == trunc(value); }));
|
||||
|
||||
|
@ -1014,7 +1008,7 @@ ThrowCompletionOr<DurationRecord> add_duration(VM& vm, double years1, double mon
|
|||
auto* date_duration2 = MUST(create_temporal_duration(vm, years2, months2, weeks2, days2, 0, 0, 0, 0, 0, 0));
|
||||
|
||||
// d. Let dateAdd be ? GetMethod(calendar, "dateAdd").
|
||||
auto* date_add = TRY(Value(&calendar).get_method(global_object, vm.names.dateAdd));
|
||||
auto* date_add = TRY(Value(&calendar).get_method(vm, vm.names.dateAdd));
|
||||
|
||||
// e. Let intermediate be ? CalendarDateAdd(calendar, relativeTo, dateDuration1, undefined, dateAdd).
|
||||
auto* intermediate = TRY(calendar_date_add(vm, calendar, &relative_to, *date_duration1, nullptr, date_add));
|
||||
|
@ -1102,7 +1096,6 @@ ThrowCompletionOr<ZonedDateTime*> move_relative_zoned_date_time(VM& vm, ZonedDat
|
|||
ThrowCompletionOr<RoundedDuration> round_duration(VM& vm, double years, double months, double weeks, double days, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds, u32 increment, StringView unit, StringView rounding_mode, Object* relative_to_object)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
Object* calendar = nullptr;
|
||||
double fractional_seconds = 0;
|
||||
|
@ -1196,7 +1189,7 @@ ThrowCompletionOr<RoundedDuration> round_duration(VM& vm, double years, double m
|
|||
auto* years_duration = MUST(create_temporal_duration(vm, years, 0, 0, 0, 0, 0, 0, 0, 0, 0));
|
||||
|
||||
// b. Let dateAdd be ? GetMethod(calendar, "dateAdd").
|
||||
auto* date_add = TRY(Value(calendar).get_method(global_object, vm.names.dateAdd));
|
||||
auto* date_add = TRY(Value(calendar).get_method(vm, vm.names.dateAdd));
|
||||
|
||||
// c. Let yearsLater be ? CalendarDateAdd(calendar, relativeTo, yearsDuration, undefined, dateAdd).
|
||||
auto* years_later = TRY(calendar_date_add(vm, *calendar, relative_to, *years_duration, nullptr, date_add));
|
||||
|
@ -1286,7 +1279,7 @@ ThrowCompletionOr<RoundedDuration> round_duration(VM& vm, double years, double m
|
|||
auto* years_months = MUST(create_temporal_duration(vm, years, months, 0, 0, 0, 0, 0, 0, 0, 0));
|
||||
|
||||
// b. Let dateAdd be ? GetMethod(calendar, "dateAdd").
|
||||
auto* date_add = TRY(Value(calendar).get_method(global_object, vm.names.dateAdd));
|
||||
auto* date_add = TRY(Value(calendar).get_method(vm, vm.names.dateAdd));
|
||||
|
||||
// c. Let yearsMonthsLater be ? CalendarDateAdd(calendar, relativeTo, yearsMonths, undefined, dateAdd).
|
||||
auto* years_months_later = TRY(calendar_date_add(vm, *calendar, relative_to, *years_months, nullptr, date_add));
|
||||
|
|
|
@ -75,9 +75,6 @@ ThrowCompletionOr<Instant*> create_temporal_instant(VM& vm, BigInt const& epoch_
|
|||
// 8.5.3 ToTemporalInstant ( item ), https://tc39.es/proposal-temporal/#sec-temporal-totemporalinstant
|
||||
ThrowCompletionOr<Instant*> to_temporal_instant(VM& vm, Value item)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. If Type(item) is Object, then
|
||||
if (item.is_object()) {
|
||||
// a. If item has an [[InitializedTemporalInstant]] internal slot, then
|
||||
|
@ -96,7 +93,7 @@ ThrowCompletionOr<Instant*> to_temporal_instant(VM& vm, Value item)
|
|||
}
|
||||
|
||||
// 2. Let string be ? ToString(item).
|
||||
auto string = TRY(item.to_string(global_object));
|
||||
auto string = TRY(item.to_string(vm));
|
||||
|
||||
// 3. Let epochNanoseconds be ? ParseTemporalInstant(string).
|
||||
auto* epoch_nanoseconds = TRY(parse_temporal_instant(vm, string));
|
||||
|
|
|
@ -52,10 +52,9 @@ ThrowCompletionOr<Value> InstantConstructor::call()
|
|||
ThrowCompletionOr<Object*> InstantConstructor::construct(FunctionObject& new_target)
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
auto& global_object = this->global_object();
|
||||
|
||||
// 2. Let epochNanoseconds be ? ToBigInt(epochNanoseconds).
|
||||
auto* epoch_nanoseconds = TRY(vm.argument(0).to_bigint(global_object));
|
||||
auto* epoch_nanoseconds = TRY(vm.argument(0).to_bigint(vm));
|
||||
|
||||
// 3. If ! IsValidEpochNanoseconds(epochNanoseconds) is false, throw a RangeError exception.
|
||||
if (!is_valid_epoch_nanoseconds(*epoch_nanoseconds))
|
||||
|
@ -84,7 +83,7 @@ JS_DEFINE_NATIVE_FUNCTION(InstantConstructor::from)
|
|||
JS_DEFINE_NATIVE_FUNCTION(InstantConstructor::from_epoch_seconds)
|
||||
{
|
||||
// 1. Set epochSeconds to ? ToNumber(epochSeconds).
|
||||
auto epoch_seconds_value = TRY(vm.argument(0).to_number(global_object));
|
||||
auto epoch_seconds_value = TRY(vm.argument(0).to_number(vm));
|
||||
|
||||
// 2. Set epochSeconds to ? NumberToBigInt(epochSeconds).
|
||||
auto* epoch_seconds = TRY(number_to_bigint(global_object, epoch_seconds_value));
|
||||
|
@ -104,7 +103,7 @@ JS_DEFINE_NATIVE_FUNCTION(InstantConstructor::from_epoch_seconds)
|
|||
JS_DEFINE_NATIVE_FUNCTION(InstantConstructor::from_epoch_milliseconds)
|
||||
{
|
||||
// 1. Set epochMilliseconds to ? ToNumber(epochMilliseconds).
|
||||
auto epoch_milliseconds_value = TRY(vm.argument(0).to_number(global_object));
|
||||
auto epoch_milliseconds_value = TRY(vm.argument(0).to_number(vm));
|
||||
|
||||
// 2. Set epochMilliseconds to ? NumberToBigInt(epochMilliseconds).
|
||||
auto* epoch_milliseconds = TRY(number_to_bigint(global_object, epoch_milliseconds_value));
|
||||
|
@ -124,7 +123,7 @@ JS_DEFINE_NATIVE_FUNCTION(InstantConstructor::from_epoch_milliseconds)
|
|||
JS_DEFINE_NATIVE_FUNCTION(InstantConstructor::from_epoch_microseconds)
|
||||
{
|
||||
// 1. Set epochMicroseconds to ? ToBigInt(epochMicroseconds).
|
||||
auto* epoch_microseconds = TRY(vm.argument(0).to_bigint(global_object));
|
||||
auto* epoch_microseconds = TRY(vm.argument(0).to_bigint(vm));
|
||||
|
||||
// 2. Let epochNanoseconds be epochMicroseconds × 1000ℤ.
|
||||
auto* epoch_nanoseconds = js_bigint(vm, epoch_microseconds->big_integer().multiplied_by(Crypto::UnsignedBigInteger { 1'000 }));
|
||||
|
@ -141,7 +140,7 @@ JS_DEFINE_NATIVE_FUNCTION(InstantConstructor::from_epoch_microseconds)
|
|||
JS_DEFINE_NATIVE_FUNCTION(InstantConstructor::from_epoch_nanoseconds)
|
||||
{
|
||||
// 1. Set epochNanoseconds to ? ToBigInt(epochNanoseconds).
|
||||
auto* epoch_nanoseconds = TRY(vm.argument(0).to_bigint(global_object));
|
||||
auto* epoch_nanoseconds = TRY(vm.argument(0).to_bigint(vm));
|
||||
|
||||
// 2. If ! IsValidEpochNanoseconds(epochNanoseconds) is false, throw a RangeError exception.
|
||||
if (!is_valid_epoch_nanoseconds(*epoch_nanoseconds))
|
||||
|
|
|
@ -83,9 +83,6 @@ ThrowCompletionOr<PlainDate*> create_temporal_date(VM& vm, i32 iso_year, u8 iso_
|
|||
// 3.5.2 ToTemporalDate ( item [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal-totemporaldate
|
||||
ThrowCompletionOr<PlainDate*> to_temporal_date(VM& vm, Value item, Object const* options)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. If options is not present, set options to undefined.
|
||||
// 2. Assert: Type(options) is Object or Undefined.
|
||||
|
||||
|
@ -143,7 +140,7 @@ ThrowCompletionOr<PlainDate*> to_temporal_date(VM& vm, Value item, Object const*
|
|||
(void)TRY(to_temporal_overflow(vm, options));
|
||||
|
||||
// 5. Let string be ? ToString(item).
|
||||
auto string = TRY(item.to_string(global_object));
|
||||
auto string = TRY(item.to_string(vm));
|
||||
|
||||
// 6. Let result be ? ParseTemporalDateString(string).
|
||||
auto result = TRY(parse_temporal_date_string(vm, string));
|
||||
|
@ -419,9 +416,6 @@ String pad_iso_year(i32 y)
|
|||
// 3.5.8 TemporalDateToString ( temporalDate, showCalendar ), https://tc39.es/proposal-temporal/#sec-temporal-temporaldatetostring
|
||||
ThrowCompletionOr<String> temporal_date_to_string(VM& vm, PlainDate& temporal_date, StringView show_calendar)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Assert: Type(temporalDate) is Object.
|
||||
// 2. Assert: temporalDate has an [[InitializedTemporalDate]] internal slot.
|
||||
|
||||
|
@ -435,7 +429,7 @@ ThrowCompletionOr<String> temporal_date_to_string(VM& vm, PlainDate& temporal_da
|
|||
auto day = String::formatted("{:02}", temporal_date.iso_day());
|
||||
|
||||
// 6. Let calendarID be ? ToString(temporalDate.[[Calendar]]).
|
||||
auto calendar_id = TRY(Value(&temporal_date.calendar()).to_string(global_object));
|
||||
auto calendar_id = TRY(Value(&temporal_date.calendar()).to_string(vm));
|
||||
|
||||
// 7. Let calendar be ! FormatCalendarAnnotation(calendarID, showCalendar).
|
||||
auto calendar = format_calendar_annotation(calendar_id, show_calendar);
|
||||
|
|
|
@ -127,9 +127,6 @@ ThrowCompletionOr<ISODateTime> interpret_temporal_date_time_fields(VM& vm, Objec
|
|||
// 5.5.4 ToTemporalDateTime ( item [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal-totemporaldatetime
|
||||
ThrowCompletionOr<PlainDateTime*> to_temporal_date_time(VM& vm, Value item, Object const* options)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. If options is not present, set options to undefined.
|
||||
// 2. Assert: Type(options) is Object or Undefined.
|
||||
|
||||
|
@ -189,7 +186,7 @@ ThrowCompletionOr<PlainDateTime*> to_temporal_date_time(VM& vm, Value item, Obje
|
|||
(void)TRY(to_temporal_overflow(vm, options));
|
||||
|
||||
// b. Let string be ? ToString(item).
|
||||
auto string = TRY(item.to_string(global_object));
|
||||
auto string = TRY(item.to_string(vm));
|
||||
|
||||
// c. Let result be ? ParseTemporalDateTimeString(string).
|
||||
result = TRY(parse_temporal_date_time_string(vm, string));
|
||||
|
@ -274,9 +271,6 @@ ThrowCompletionOr<PlainDateTime*> create_temporal_date_time(VM& vm, i32 iso_year
|
|||
// 5.5.7 TemporalDateTimeToString ( isoYear, isoMonth, isoDay, hour, minute, second, millisecond, microsecond, nanosecond, calendar, precision, showCalendar ), https://tc39.es/proposal-temporal/#sec-temporal-temporaldatetimetostring
|
||||
ThrowCompletionOr<String> temporal_date_time_to_string(VM& vm, i32 iso_year, u8 iso_month, u8 iso_day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond, Value calendar, Variant<StringView, u8> const& precision, StringView show_calendar)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Assert: isoYear, isoMonth, isoDay, hour, minute, second, millisecond, microsecond, and nanosecond are integers.
|
||||
|
||||
// 2. Let year be ! PadISOYear(isoYear).
|
||||
|
@ -289,7 +283,7 @@ ThrowCompletionOr<String> temporal_date_time_to_string(VM& vm, i32 iso_year, u8
|
|||
auto seconds = format_seconds_string_part(second, millisecond, microsecond, nanosecond, precision);
|
||||
|
||||
// 8. Let calendarID be ? ToString(calendar).
|
||||
auto calendar_id = TRY(calendar.to_string(global_object));
|
||||
auto calendar_id = TRY(calendar.to_string(vm));
|
||||
|
||||
// 9. Let calendarString be ! FormatCalendarAnnotation(calendarID, showCalendar).
|
||||
auto calendar_string = format_calendar_annotation(calendar_id, show_calendar);
|
||||
|
|
|
@ -36,9 +36,6 @@ void PlainMonthDay::visit_edges(Visitor& visitor)
|
|||
// 10.5.1 ToTemporalMonthDay ( item [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal-totemporalmonthday
|
||||
ThrowCompletionOr<PlainMonthDay*> to_temporal_month_day(VM& vm, Value item, Object const* options)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. If options is not present, set options to undefined.
|
||||
// 2. Assert: Type(options) is Object or Undefined.
|
||||
|
||||
|
@ -122,7 +119,7 @@ ThrowCompletionOr<PlainMonthDay*> to_temporal_month_day(VM& vm, Value item, Obje
|
|||
(void)TRY(to_temporal_overflow(vm, options));
|
||||
|
||||
// 6. Let string be ? ToString(item).
|
||||
auto string = TRY(item.to_string(global_object));
|
||||
auto string = TRY(item.to_string(vm));
|
||||
|
||||
// 7. Let result be ? ParseTemporalMonthDayString(string).
|
||||
auto result = TRY(parse_temporal_month_day_string(vm, string));
|
||||
|
@ -179,9 +176,6 @@ ThrowCompletionOr<PlainMonthDay*> create_temporal_month_day(VM& vm, u8 iso_month
|
|||
// 10.5.3 TemporalMonthDayToString ( monthDay, showCalendar ), https://tc39.es/proposal-temporal/#sec-temporal-temporalmonthdaytostring
|
||||
ThrowCompletionOr<String> temporal_month_day_to_string(VM& vm, PlainMonthDay& month_day, StringView show_calendar)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Assert: Type(monthDay) is Object.
|
||||
// 2. Assert: monthDay has an [[InitializedTemporalMonthDay]] internal slot.
|
||||
|
||||
|
@ -191,7 +185,7 @@ ThrowCompletionOr<String> temporal_month_day_to_string(VM& vm, PlainMonthDay& mo
|
|||
auto result = String::formatted("{:02}-{:02}", month_day.iso_month(), month_day.iso_day());
|
||||
|
||||
// 6. Let calendarID be ? ToString(monthDay.[[Calendar]]).
|
||||
auto calendar_id = TRY(Value(&month_day.calendar()).to_string(global_object));
|
||||
auto calendar_id = TRY(Value(&month_day.calendar()).to_string(vm));
|
||||
|
||||
// 7. If showCalendar is "always" or if calendarID is not "iso8601", then
|
||||
if (show_calendar == "always"sv || calendar_id != "iso8601"sv) {
|
||||
|
|
|
@ -77,9 +77,6 @@ TimeDurationRecord difference_time(VM& vm, u8 hour1, u8 minute1, u8 second1, u16
|
|||
// 4.5.2 ToTemporalTime ( item [ , overflow ] ), https://tc39.es/proposal-temporal/#sec-temporal-totemporaltime
|
||||
ThrowCompletionOr<PlainTime*> to_temporal_time(VM& vm, Value item, Optional<StringView> overflow)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. If overflow is not present, set overflow to "constrain".
|
||||
if (!overflow.has_value())
|
||||
overflow = "constrain"sv;
|
||||
|
@ -124,7 +121,7 @@ ThrowCompletionOr<PlainTime*> to_temporal_time(VM& vm, Value item, Optional<Stri
|
|||
auto* calendar = TRY(get_temporal_calendar_with_iso_default(vm, item_object));
|
||||
|
||||
// e. If ? ToString(calendar) is not "iso8601", then
|
||||
auto calendar_identifier = TRY(Value(calendar).to_string(global_object));
|
||||
auto calendar_identifier = TRY(Value(calendar).to_string(vm));
|
||||
if (calendar_identifier != "iso8601"sv) {
|
||||
// i. Throw a RangeError exception.
|
||||
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidCalendarIdentifier, calendar_identifier);
|
||||
|
@ -139,7 +136,7 @@ ThrowCompletionOr<PlainTime*> to_temporal_time(VM& vm, Value item, Optional<Stri
|
|||
// 4. Else,
|
||||
else {
|
||||
// a. Let string be ? ToString(item).
|
||||
auto string = TRY(item.to_string(global_object));
|
||||
auto string = TRY(item.to_string(vm));
|
||||
|
||||
// b. Let result be ? ParseTemporalTimeString(string).
|
||||
result = TRY(parse_temporal_time_string(vm, string));
|
||||
|
|
|
@ -35,9 +35,6 @@ void PlainYearMonth::visit_edges(Visitor& visitor)
|
|||
// 9.5.1 ToTemporalYearMonth ( item [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal-totemporalyearmonth
|
||||
ThrowCompletionOr<PlainYearMonth*> to_temporal_year_month(VM& vm, Value item, Object const* options)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. If options is not present, set options to undefined.
|
||||
// 2. Assert: Type(options) is Object or Undefined.
|
||||
|
||||
|
@ -68,7 +65,7 @@ ThrowCompletionOr<PlainYearMonth*> to_temporal_year_month(VM& vm, Value item, Ob
|
|||
(void)TRY(to_temporal_overflow(vm, options));
|
||||
|
||||
// 5. Let string be ? ToString(item).
|
||||
auto string = TRY(item.to_string(global_object));
|
||||
auto string = TRY(item.to_string(vm));
|
||||
|
||||
// 6. Let result be ? ParseTemporalYearMonthString(string).
|
||||
auto result = TRY(parse_temporal_year_month_string(vm, string));
|
||||
|
@ -220,9 +217,6 @@ ThrowCompletionOr<PlainYearMonth*> create_temporal_year_month(VM& vm, i32 iso_ye
|
|||
// 9.5.7 TemporalYearMonthToString ( yearMonth, showCalendar ), https://tc39.es/proposal-temporal/#sec-temporal-temporalyearmonthtostring
|
||||
ThrowCompletionOr<String> temporal_year_month_to_string(VM& vm, PlainYearMonth& year_month, StringView show_calendar)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Assert: Type(yearMonth) is Object.
|
||||
// 2. Assert: yearMonth has an [[InitializedTemporalYearMonth]] internal slot.
|
||||
|
||||
|
@ -232,7 +226,7 @@ ThrowCompletionOr<String> temporal_year_month_to_string(VM& vm, PlainYearMonth&
|
|||
auto result = String::formatted("{}-{:02}", pad_iso_year(year_month.iso_year()), year_month.iso_month());
|
||||
|
||||
// 6. Let calendarID be ? ToString(yearMonth.[[Calendar]]).
|
||||
auto calendar_id = TRY(Value(&year_month.calendar()).to_string(global_object));
|
||||
auto calendar_id = TRY(Value(&year_month.calendar()).to_string(vm));
|
||||
|
||||
// 7. If showCalendar is "always" or if calendarID is not "iso8601", then
|
||||
if (show_calendar == "always"sv || calendar_id != "iso8601") {
|
||||
|
@ -311,7 +305,6 @@ ThrowCompletionOr<Duration*> difference_temporal_plain_year_month(VM& vm, Differ
|
|||
ThrowCompletionOr<PlainYearMonth*> add_duration_to_or_subtract_duration_from_plain_year_month(VM& vm, ArithmeticOperation operation, PlainYearMonth& year_month, Value temporal_duration_like, Value options_value)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Let duration be ? ToTemporalDuration(temporalDurationLike).
|
||||
auto* duration = TRY(to_temporal_duration(vm, temporal_duration_like));
|
||||
|
@ -373,7 +366,7 @@ ThrowCompletionOr<PlainYearMonth*> add_duration_to_or_subtract_duration_from_pla
|
|||
|
||||
// 16. For each element entry of entries, do
|
||||
for (auto& entry : entries) {
|
||||
auto key = MUST(entry.as_array().get_without_side_effects(0).to_property_key(global_object));
|
||||
auto key = MUST(entry.as_array().get_without_side_effects(0).to_property_key(vm));
|
||||
auto value = entry.as_array().get_without_side_effects(1);
|
||||
|
||||
// a. Perform ! CreateDataPropertyOrThrow(optionsCopy, entry[0], entry[1]).
|
||||
|
|
|
@ -418,9 +418,6 @@ String format_iso_time_zone_offset_string(double offset_nanoseconds)
|
|||
// 11.6.10 ToTemporalTimeZone ( temporalTimeZoneLike ), https://tc39.es/proposal-temporal/#sec-temporal-totemporaltimezone
|
||||
ThrowCompletionOr<Object*> to_temporal_time_zone(VM& vm, Value temporal_time_zone_like)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. If Type(temporalTimeZoneLike) is Object, then
|
||||
if (temporal_time_zone_like.is_object()) {
|
||||
// a. If temporalTimeZoneLike has an [[InitializedTemporalZonedDateTime]] internal slot, then
|
||||
|
@ -444,7 +441,7 @@ ThrowCompletionOr<Object*> to_temporal_time_zone(VM& vm, Value temporal_time_zon
|
|||
}
|
||||
|
||||
// 2. Let identifier be ? ToString(temporalTimeZoneLike).
|
||||
auto identifier = TRY(temporal_time_zone_like.to_string(global_object));
|
||||
auto identifier = TRY(temporal_time_zone_like.to_string(vm));
|
||||
|
||||
// 3. Let parseResult be ? ParseTemporalTimeZoneString(identifier).
|
||||
auto parse_result = TRY(parse_temporal_time_zone_string(vm, identifier));
|
||||
|
@ -483,7 +480,7 @@ ThrowCompletionOr<double> get_offset_nanoseconds_for(VM& vm, Value time_zone, In
|
|||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Let getOffsetNanosecondsFor be ? GetMethod(timeZone, "getOffsetNanosecondsFor").
|
||||
auto* get_offset_nanoseconds_for = TRY(time_zone.get_method(global_object, vm.names.getOffsetNanosecondsFor));
|
||||
auto* get_offset_nanoseconds_for = TRY(time_zone.get_method(vm, vm.names.getOffsetNanosecondsFor));
|
||||
|
||||
// 2. Let offsetNanoseconds be ? Call(getOffsetNanosecondsFor, timeZone, « instant »).
|
||||
auto offset_nanoseconds_value = TRY(call(global_object, get_offset_nanoseconds_for, time_zone, &instant));
|
||||
|
@ -674,7 +671,7 @@ ThrowCompletionOr<MarkedVector<Instant*>> get_possible_instants_for(VM& vm, Valu
|
|||
// 1. Assert: dateTime has an [[InitializedTemporalDateTime]] internal slot.
|
||||
|
||||
// 2. Let possibleInstants be ? Invoke(timeZone, "getPossibleInstantsFor", « dateTime »).
|
||||
auto possible_instants = TRY(time_zone.invoke(global_object, vm.names.getPossibleInstantsFor, &date_time));
|
||||
auto possible_instants = TRY(time_zone.invoke(vm, vm.names.getPossibleInstantsFor, &date_time));
|
||||
|
||||
// 3. Let iteratorRecord be ? GetIterator(possibleInstants, sync).
|
||||
auto iterator = TRY(get_iterator(global_object, possible_instants, IteratorHint::Sync));
|
||||
|
@ -716,18 +713,15 @@ ThrowCompletionOr<MarkedVector<Instant*>> get_possible_instants_for(VM& vm, Valu
|
|||
// 11.6.17 TimeZoneEquals ( one, two ), https://tc39.es/proposal-temporal/#sec-temporal-timezoneequals
|
||||
ThrowCompletionOr<bool> time_zone_equals(VM& vm, Object& one, Object& two)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. If one and two are the same Object value, return true.
|
||||
if (&one == &two)
|
||||
return true;
|
||||
|
||||
// 2. Let timeZoneOne be ? ToString(one).
|
||||
auto time_zone_one = TRY(Value(&one).to_string(global_object));
|
||||
auto time_zone_one = TRY(Value(&one).to_string(vm));
|
||||
|
||||
// 3. Let timeZoneTwo be ? ToString(two).
|
||||
auto time_zone_two = TRY(Value(&two).to_string(global_object));
|
||||
auto time_zone_two = TRY(Value(&two).to_string(vm));
|
||||
|
||||
// 4. If timeZoneOne is timeZoneTwo, return true.
|
||||
if (time_zone_one == time_zone_two)
|
||||
|
|
|
@ -45,10 +45,9 @@ ThrowCompletionOr<Value> TimeZoneConstructor::call()
|
|||
ThrowCompletionOr<Object*> TimeZoneConstructor::construct(FunctionObject& new_target)
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
auto& global_object = this->global_object();
|
||||
|
||||
// 2. Set identifier to ? ToString(identifier).
|
||||
auto identifier = TRY(vm.argument(0).to_string(global_object));
|
||||
auto identifier = TRY(vm.argument(0).to_string(vm));
|
||||
|
||||
// 3. Let parseResult be ParseText(StringToCodePoints(identifier), TimeZoneNumericUTCOffset).
|
||||
// 4. If parseResult is a List of errors, then
|
||||
|
|
|
@ -52,7 +52,7 @@ JS_DEFINE_NATIVE_FUNCTION(TimeZonePrototype::id_getter)
|
|||
auto* time_zone = TRY(typed_this_object(vm));
|
||||
|
||||
// 3. Return ? ToString(timeZone).
|
||||
return js_string(vm, TRY(Value(time_zone).to_string(global_object)));
|
||||
return js_string(vm, TRY(Value(time_zone).to_string(vm)));
|
||||
}
|
||||
|
||||
// 11.4.4 Temporal.TimeZone.prototype.getOffsetNanosecondsFor ( instant ), https://tc39.es/proposal-temporal/#sec-temporal.timezone.prototype.getoffsetnanosecondsfor
|
||||
|
@ -243,7 +243,7 @@ JS_DEFINE_NATIVE_FUNCTION(TimeZonePrototype::to_json)
|
|||
auto* time_zone = TRY(typed_this_object(vm));
|
||||
|
||||
// 3. Return ? ToString(timeZone).
|
||||
return js_string(vm, TRY(Value(time_zone).to_string(global_object)));
|
||||
return js_string(vm, TRY(Value(time_zone).to_string(vm)));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -120,9 +120,6 @@ ThrowCompletionOr<BigInt const*> interpret_iso_date_time_offset(VM& vm, i32 year
|
|||
// 6.5.2 ToTemporalZonedDateTime ( item [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal-totemporalzoneddatetime
|
||||
ThrowCompletionOr<ZonedDateTime*> to_temporal_zoned_date_time(VM& vm, Value item, Object const* options)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. If options is not present, set options to undefined.
|
||||
// 2. Assert: Type(options) is Object or Undefined.
|
||||
|
||||
|
@ -179,7 +176,7 @@ ThrowCompletionOr<ZonedDateTime*> to_temporal_zoned_date_time(VM& vm, Value item
|
|||
// k. Else,
|
||||
else {
|
||||
// i. Set offsetString to ? ToString(offsetString).
|
||||
offset_string = TRY(offset_string_value.to_string(global_object));
|
||||
offset_string = TRY(offset_string_value.to_string(vm));
|
||||
}
|
||||
|
||||
// l. Let result be ? InterpretTemporalDateTimeFields(calendar, fields, options).
|
||||
|
@ -191,7 +188,7 @@ ThrowCompletionOr<ZonedDateTime*> to_temporal_zoned_date_time(VM& vm, Value item
|
|||
(void)TRY(to_temporal_overflow(vm, options));
|
||||
|
||||
// b. Let string be ? ToString(item).
|
||||
auto string = TRY(item.to_string(global_object));
|
||||
auto string = TRY(item.to_string(vm));
|
||||
|
||||
// c. Let result be ? ParseTemporalZonedDateTimeString(string).
|
||||
auto parsed_result = TRY(parse_temporal_zoned_date_time_string(vm, string));
|
||||
|
@ -293,9 +290,6 @@ ThrowCompletionOr<ZonedDateTime*> create_temporal_zoned_date_time(VM& vm, BigInt
|
|||
// 6.5.4 TemporalZonedDateTimeToString ( zonedDateTime, precision, showCalendar, showTimeZone, showOffset [ , increment, unit, roundingMode ] ), https://tc39.es/proposal-temporal/#sec-temporal-temporalzoneddatetimetostring
|
||||
ThrowCompletionOr<String> temporal_zoned_date_time_to_string(VM& vm, ZonedDateTime& zoned_date_time, Variant<StringView, u8> const& precision, StringView show_calendar, StringView show_time_zone, StringView show_offset, Optional<u64> increment, Optional<StringView> unit, Optional<StringView> rounding_mode)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. If increment is not present, set increment to 1.
|
||||
if (!increment.has_value())
|
||||
increment = 1;
|
||||
|
@ -352,14 +346,14 @@ ThrowCompletionOr<String> temporal_zoned_date_time_to_string(VM& vm, ZonedDateTi
|
|||
// 13. Else,
|
||||
else {
|
||||
// a. Let timeZoneID be ? ToString(timeZone).
|
||||
auto time_zone_id = TRY(Value(&time_zone).to_string(global_object));
|
||||
auto time_zone_id = TRY(Value(&time_zone).to_string(vm));
|
||||
|
||||
// b. Let timeZoneString be the string-concatenation of the code unit 0x005B (LEFT SQUARE BRACKET), timeZoneID, and the code unit 0x005D (RIGHT SQUARE BRACKET).
|
||||
time_zone_string = String::formatted("[{}]", time_zone_id);
|
||||
}
|
||||
|
||||
// 14. Let calendarID be ? ToString(zonedDateTime.[[Calendar]]).
|
||||
auto calendar_id = TRY(Value(&zoned_date_time.calendar()).to_string(global_object));
|
||||
auto calendar_id = TRY(Value(&zoned_date_time.calendar()).to_string(vm));
|
||||
|
||||
// 15. Let calendarString be ! FormatCalendarAnnotation(calendarID, showCalendar).
|
||||
auto calendar_string = format_calendar_annotation(calendar_id, show_calendar);
|
||||
|
|
|
@ -51,10 +51,9 @@ ThrowCompletionOr<Value> ZonedDateTimeConstructor::call()
|
|||
ThrowCompletionOr<Object*> ZonedDateTimeConstructor::construct(FunctionObject& new_target)
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
auto& global_object = this->global_object();
|
||||
|
||||
// 2. Set epochNanoseconds to ? ToBigInt(epochNanoseconds).
|
||||
auto* epoch_nanoseconds = TRY(vm.argument(0).to_bigint(global_object));
|
||||
auto* epoch_nanoseconds = TRY(vm.argument(0).to_bigint(vm));
|
||||
|
||||
// 3. If ! IsValidEpochNanoseconds(epochNanoseconds) is false, throw a RangeError exception.
|
||||
if (!is_valid_epoch_nanoseconds(*epoch_nanoseconds))
|
||||
|
|
|
@ -21,7 +21,7 @@ ThrowCompletionOr<TypedArrayBase*> typed_array_from(GlobalObject& global_object,
|
|||
{
|
||||
auto& vm = global_object.vm();
|
||||
|
||||
auto* this_object = TRY(typed_array_value.to_object(global_object));
|
||||
auto* this_object = TRY(typed_array_value.to_object(vm));
|
||||
if (!this_object->is_typed_array())
|
||||
return vm.throw_completion<TypeError>(ErrorType::NotAnObjectOfType, "TypedArray");
|
||||
|
||||
|
@ -58,7 +58,7 @@ static ThrowCompletionOr<void> initialize_typed_array_from_array_buffer(GlobalOb
|
|||
auto element_size = typed_array.element_size();
|
||||
|
||||
// 2. Let offset be ? ToIndex(byteOffset).
|
||||
auto offset = TRY(byte_offset.to_index(global_object));
|
||||
auto offset = TRY(byte_offset.to_index(vm));
|
||||
|
||||
// 3. If offset modulo elementSize ≠ 0, throw a RangeError exception.
|
||||
if (offset % element_size != 0)
|
||||
|
@ -69,7 +69,7 @@ static ThrowCompletionOr<void> initialize_typed_array_from_array_buffer(GlobalOb
|
|||
// 4. If length is not undefined, then
|
||||
if (!length.is_undefined()) {
|
||||
// a. Let newLength be ? ToIndex(length).
|
||||
new_length = TRY(length.to_index(global_object));
|
||||
new_length = TRY(length.to_index(vm));
|
||||
}
|
||||
|
||||
// 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
|
||||
|
@ -374,7 +374,7 @@ ThrowCompletionOr<double> compare_typed_array_elements(GlobalObject& global_obje
|
|||
if (comparefn != nullptr) {
|
||||
// a. Let v be ? ToNumber(? Call(comparefn, undefined, « x, y »)).
|
||||
auto value = TRY(call(global_object, comparefn, js_undefined(), x, y));
|
||||
auto value_number = TRY(value.to_number(global_object));
|
||||
auto value_number = TRY(value.to_number(vm));
|
||||
|
||||
// b. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
|
||||
if (buffer.is_detached())
|
||||
|
@ -536,7 +536,7 @@ void TypedArrayBase::visit_edges(Visitor& visitor)
|
|||
TRY(initialize_typed_array_from_array_buffer(global_object, *typed_array, array_buffer, \
|
||||
vm.argument(1), vm.argument(2))); \
|
||||
} else { \
|
||||
auto iterator = TRY(first_argument.get_method(global_object, *vm.well_known_symbol_iterator())); \
|
||||
auto iterator = TRY(first_argument.get_method(vm, *vm.well_known_symbol_iterator())); \
|
||||
if (iterator) { \
|
||||
auto values = TRY(iterable_to_list(global_object, first_argument, iterator)); \
|
||||
TRY(initialize_typed_array_from_list(global_object, *typed_array, values)); \
|
||||
|
@ -547,7 +547,7 @@ void TypedArrayBase::visit_edges(Visitor& visitor)
|
|||
return typed_array; \
|
||||
} \
|
||||
\
|
||||
auto array_length_or_error = first_argument.to_index(global_object); \
|
||||
auto array_length_or_error = first_argument.to_index(vm); \
|
||||
if (array_length_or_error.is_error()) { \
|
||||
auto error = array_length_or_error.release_error(); \
|
||||
if (error.value()->is_object() && is<RangeError>(error.value()->as_object())) { \
|
||||
|
|
|
@ -132,16 +132,16 @@ template<typename T>
|
|||
inline ThrowCompletionOr<void> integer_indexed_element_set(TypedArrayBase& typed_array, CanonicalIndex property_index, Value value)
|
||||
{
|
||||
VERIFY(!value.is_empty());
|
||||
auto& global_object = typed_array.global_object();
|
||||
auto& vm = typed_array.vm();
|
||||
|
||||
Value num_value;
|
||||
|
||||
// 1. If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value).
|
||||
if (typed_array.content_type() == TypedArrayBase::ContentType::BigInt)
|
||||
num_value = TRY(value.to_bigint(global_object));
|
||||
num_value = TRY(value.to_bigint(vm));
|
||||
// 2. Otherwise, let numValue be ? ToNumber(value).
|
||||
else
|
||||
num_value = TRY(value.to_number(global_object));
|
||||
num_value = TRY(value.to_number(vm));
|
||||
|
||||
// 3. If IsValidIntegerIndex(O, index) is true, then
|
||||
// NOTE: Inverted for flattened logic.
|
||||
|
@ -487,7 +487,10 @@ ThrowCompletionOr<double> compare_typed_array_elements(GlobalObject& global_obje
|
|||
virtual ThrowCompletionOr<Object*> construct(FunctionObject& new_target) override; \
|
||||
\
|
||||
private: \
|
||||
virtual bool has_constructor() const override { return true; } \
|
||||
virtual bool has_constructor() const override \
|
||||
{ \
|
||||
return true; \
|
||||
} \
|
||||
};
|
||||
|
||||
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, Type) \
|
||||
|
|
|
@ -68,7 +68,7 @@ JS_DEFINE_NATIVE_FUNCTION(TypedArrayConstructor::from)
|
|||
auto source = vm.argument(0);
|
||||
auto this_arg = vm.argument(2);
|
||||
|
||||
auto using_iterator = TRY(source.get_method(global_object, *vm.well_known_symbol_iterator()));
|
||||
auto using_iterator = TRY(source.get_method(vm, *vm.well_known_symbol_iterator()));
|
||||
if (using_iterator) {
|
||||
auto values = TRY(iterable_to_list(global_object, source, using_iterator));
|
||||
|
||||
|
@ -89,7 +89,7 @@ JS_DEFINE_NATIVE_FUNCTION(TypedArrayConstructor::from)
|
|||
return target_object;
|
||||
}
|
||||
|
||||
auto array_like = MUST(source.to_object(global_object));
|
||||
auto array_like = MUST(source.to_object(vm));
|
||||
auto length = TRY(length_of_array_like(global_object, *array_like));
|
||||
|
||||
MarkedVector<Value> arguments(vm.heap());
|
||||
|
|
|
@ -169,7 +169,7 @@ JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::at)
|
|||
{
|
||||
auto* typed_array = TRY(validate_typed_array_from_this(global_object));
|
||||
auto length = typed_array->array_length();
|
||||
auto relative_index = TRY(vm.argument(0).to_integer_or_infinity(global_object));
|
||||
auto relative_index = TRY(vm.argument(0).to_integer_or_infinity(vm));
|
||||
if (Value(relative_index).is_infinity())
|
||||
return js_undefined();
|
||||
Checked<size_t> index { 0 };
|
||||
|
@ -226,7 +226,7 @@ JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::copy_within)
|
|||
auto length = typed_array->array_length();
|
||||
|
||||
// 4. Let relativeTarget be ? ToIntegerOrInfinity(target).
|
||||
auto relative_target = TRY(vm.argument(0).to_integer_or_infinity(global_object));
|
||||
auto relative_target = TRY(vm.argument(0).to_integer_or_infinity(vm));
|
||||
|
||||
double to;
|
||||
if (Value(relative_target).is_negative_infinity()) {
|
||||
|
@ -241,7 +241,7 @@ JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::copy_within)
|
|||
}
|
||||
|
||||
// 8. Let relativeStart be ? ToIntegerOrInfinity(start).
|
||||
auto relative_start = TRY(vm.argument(1).to_integer_or_infinity(global_object));
|
||||
auto relative_start = TRY(vm.argument(1).to_integer_or_infinity(vm));
|
||||
|
||||
double from;
|
||||
if (Value(relative_start).is_negative_infinity()) {
|
||||
|
@ -261,7 +261,7 @@ JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::copy_within)
|
|||
if (vm.argument(2).is_undefined())
|
||||
relative_end = length;
|
||||
else
|
||||
relative_end = TRY(vm.argument(2).to_integer_or_infinity(global_object));
|
||||
relative_end = TRY(vm.argument(2).to_integer_or_infinity(vm));
|
||||
|
||||
double final;
|
||||
if (Value(relative_end).is_negative_infinity()) {
|
||||
|
@ -415,11 +415,11 @@ JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::fill)
|
|||
|
||||
Value value;
|
||||
if (typed_array->content_type() == TypedArrayBase::ContentType::BigInt)
|
||||
value = TRY(vm.argument(0).to_bigint(global_object));
|
||||
value = TRY(vm.argument(0).to_bigint(vm));
|
||||
else
|
||||
value = TRY(vm.argument(0).to_number(global_object));
|
||||
value = TRY(vm.argument(0).to_number(vm));
|
||||
|
||||
auto relative_start = TRY(vm.argument(1).to_integer_or_infinity(global_object));
|
||||
auto relative_start = TRY(vm.argument(1).to_integer_or_infinity(vm));
|
||||
|
||||
u32 k;
|
||||
if (Value(relative_start).is_negative_infinity())
|
||||
|
@ -433,7 +433,7 @@ JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::fill)
|
|||
if (vm.argument(2).is_undefined())
|
||||
relative_end = length;
|
||||
else
|
||||
relative_end = TRY(vm.argument(2).to_integer_or_infinity(global_object));
|
||||
relative_end = TRY(vm.argument(2).to_integer_or_infinity(vm));
|
||||
|
||||
u32 final;
|
||||
if (Value(relative_end).is_negative_infinity())
|
||||
|
@ -591,7 +591,7 @@ JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::includes)
|
|||
if (length == 0)
|
||||
return Value(false);
|
||||
|
||||
auto n = TRY(vm.argument(1).to_integer_or_infinity(global_object));
|
||||
auto n = TRY(vm.argument(1).to_integer_or_infinity(vm));
|
||||
|
||||
auto value_n = Value(n);
|
||||
if (value_n.is_positive_infinity())
|
||||
|
@ -630,7 +630,7 @@ JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::index_of)
|
|||
if (length == 0)
|
||||
return Value(-1);
|
||||
|
||||
auto n = TRY(vm.argument(1).to_integer_or_infinity(global_object));
|
||||
auto n = TRY(vm.argument(1).to_integer_or_infinity(vm));
|
||||
|
||||
auto value_n = Value(n);
|
||||
if (value_n.is_positive_infinity())
|
||||
|
@ -669,7 +669,7 @@ JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::join)
|
|||
auto length = typed_array->array_length();
|
||||
String separator = ",";
|
||||
if (!vm.argument(0).is_undefined())
|
||||
separator = TRY(vm.argument(0).to_string(global_object));
|
||||
separator = TRY(vm.argument(0).to_string(vm));
|
||||
|
||||
StringBuilder builder;
|
||||
for (size_t i = 0; i < length; ++i) {
|
||||
|
@ -678,7 +678,7 @@ JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::join)
|
|||
auto value = TRY(typed_array->get(i));
|
||||
if (value.is_nullish())
|
||||
continue;
|
||||
auto string = TRY(value.to_string(global_object));
|
||||
auto string = TRY(value.to_string(vm));
|
||||
builder.append(string);
|
||||
}
|
||||
|
||||
|
@ -706,7 +706,7 @@ JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::last_index_of)
|
|||
|
||||
double n;
|
||||
if (vm.argument_count() > 1)
|
||||
n = TRY(vm.argument(1).to_integer_or_infinity(global_object));
|
||||
n = TRY(vm.argument(1).to_integer_or_infinity(vm));
|
||||
else
|
||||
n = length - 1;
|
||||
|
||||
|
@ -1026,7 +1026,7 @@ static ThrowCompletionOr<void> set_typed_array_from_array_like(GlobalObject& glo
|
|||
auto target_length = target.array_length();
|
||||
|
||||
// 4. Let src be ? ToObject(source).
|
||||
auto* src = TRY(source.to_object(global_object));
|
||||
auto* src = TRY(source.to_object(vm));
|
||||
|
||||
// 5. Let srcLength be ? LengthOfArrayLike(src).
|
||||
auto source_length = TRY(length_of_array_like(global_object, *src));
|
||||
|
@ -1081,7 +1081,7 @@ JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::set)
|
|||
// 3. Assert: target has a [[ViewedArrayBuffer]] internal slot.
|
||||
|
||||
// 4. Let targetOffset be ? ToIntegerOrInfinity(offset).
|
||||
auto target_offset = TRY(vm.argument(1).to_integer_or_infinity(global_object));
|
||||
auto target_offset = TRY(vm.argument(1).to_integer_or_infinity(vm));
|
||||
|
||||
// 5. If targetOffset < 0, throw a RangeError exception.
|
||||
if (target_offset < 0)
|
||||
|
@ -1118,7 +1118,7 @@ JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::slice)
|
|||
auto length = typed_array->array_length();
|
||||
|
||||
// 4. Let relativeStart be ? ToIntegerOrInfinity(start).
|
||||
auto relative_start = TRY(start.to_integer_or_infinity(global_object));
|
||||
auto relative_start = TRY(start.to_integer_or_infinity(vm));
|
||||
|
||||
i32 k = 0;
|
||||
|
||||
|
@ -1138,7 +1138,7 @@ JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::slice)
|
|||
if (end.is_undefined())
|
||||
relative_end = length;
|
||||
else
|
||||
relative_end = TRY(end.to_integer_or_infinity(global_object));
|
||||
relative_end = TRY(end.to_integer_or_infinity(vm));
|
||||
|
||||
i32 final = 0;
|
||||
|
||||
|
@ -1283,7 +1283,7 @@ JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::sort)
|
|||
if (!compare_fn.is_undefined()) {
|
||||
// i. Let v be ? ToNumber(? Call(comparefn, undefined, « x, y »)).
|
||||
auto result = TRY(call(global_object, compare_fn.as_function(), js_undefined(), x, y));
|
||||
auto value = TRY(result.to_number(global_object));
|
||||
auto value = TRY(result.to_number(vm));
|
||||
|
||||
// ii. If v is NaN, return +0𝔽.
|
||||
if (value.is_nan())
|
||||
|
@ -1364,7 +1364,7 @@ JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::subarray)
|
|||
auto source_length = typed_array->array_length();
|
||||
|
||||
// 6. Let relativeBegin be ? ToIntegerOrInfinity(begin).
|
||||
auto relative_begin = TRY(begin.to_integer_or_infinity(global_object));
|
||||
auto relative_begin = TRY(begin.to_integer_or_infinity(vm));
|
||||
|
||||
i32 begin_index = 0;
|
||||
|
||||
|
@ -1384,7 +1384,7 @@ JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::subarray)
|
|||
if (end.is_undefined())
|
||||
relative_end = source_length;
|
||||
else
|
||||
relative_end = TRY(end.to_integer_or_infinity(global_object));
|
||||
relative_end = TRY(end.to_integer_or_infinity(vm));
|
||||
|
||||
i32 end_index = 0;
|
||||
|
||||
|
@ -1462,8 +1462,8 @@ JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::to_locale_string)
|
|||
// c. If nextElement is not undefined or null, then
|
||||
if (!next_element.is_nullish()) {
|
||||
// i. Let S be ? ToString(? Invoke(nextElement, "toLocaleString", « locales, options »)).
|
||||
auto locale_string_value = TRY(next_element.invoke(global_object, vm.names.toLocaleString, locales, options));
|
||||
auto locale_string = TRY(locale_string_value.to_string(global_object));
|
||||
auto locale_string_value = TRY(next_element.invoke(vm, vm.names.toLocaleString, locales, options));
|
||||
auto locale_string = TRY(locale_string_value.to_string(vm));
|
||||
|
||||
// ii. Set R to the string-concatenation of R and S.
|
||||
builder.append(locale_string);
|
||||
|
@ -1522,7 +1522,7 @@ JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::to_sorted)
|
|||
return vm.throw_completion<TypeError>(ErrorType::NotAFunction, comparefn);
|
||||
|
||||
// 2. Let O be the this value.
|
||||
auto* object = TRY(vm.this_value().to_object(global_object));
|
||||
auto* object = TRY(vm.this_value().to_object(vm));
|
||||
|
||||
// 3. Perform ? ValidateTypedArray(O).
|
||||
auto* typed_array = TRY(validate_typed_array_from_this(global_object));
|
||||
|
@ -1574,7 +1574,7 @@ JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::with)
|
|||
auto length = typed_array->array_length();
|
||||
|
||||
// 4. Let relativeIndex be ? ToIntegerOrInfinity(index).
|
||||
auto relative_index = TRY(index.to_integer_or_infinity(global_object));
|
||||
auto relative_index = TRY(index.to_integer_or_infinity(vm));
|
||||
|
||||
double actual_index = 0;
|
||||
// 5. If relativeIndex ≥ 0, let actualIndex be relativeIndex.
|
||||
|
@ -1585,10 +1585,10 @@ JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::with)
|
|||
|
||||
// 7. If O.[[ContentType]] is BigInt, set value to ? ToBigInt(value).
|
||||
if (typed_array->content_type() == TypedArrayBase::ContentType::BigInt)
|
||||
value = TRY(value.to_bigint(global_object));
|
||||
value = TRY(value.to_bigint(vm));
|
||||
// 8. Else, set value to ? ToNumber(value).
|
||||
else
|
||||
value = TRY(value.to_number(global_object));
|
||||
value = TRY(value.to_number(vm));
|
||||
|
||||
// 9. If ! IsValidIntegerIndex(O, 𝔽(actualIndex)) is false, throw a RangeError exception.
|
||||
if (!is_valid_integer_index(*typed_array, CanonicalIndex(CanonicalIndex::Type::Index, actual_index)))
|
||||
|
|
|
@ -314,8 +314,9 @@ ThrowCompletionOr<void> VM::binding_initialization(NonnullRefPtr<BindingPattern>
|
|||
// 14.3.3.1 Runtime Semantics: PropertyBindingInitialization, https://tc39.es/ecma262/#sec-destructuring-binding-patterns-runtime-semantics-propertybindinginitialization
|
||||
ThrowCompletionOr<void> VM::property_binding_initialization(BindingPattern const& binding, Value value, Environment* environment, GlobalObject& global_object)
|
||||
{
|
||||
auto& vm = *this;
|
||||
auto& realm = *global_object.associated_realm();
|
||||
auto* object = TRY(value.to_object(global_object));
|
||||
auto* object = TRY(value.to_object(vm));
|
||||
|
||||
HashTable<PropertyKey> seen_names;
|
||||
for (auto& property : binding.entries) {
|
||||
|
@ -335,7 +336,7 @@ ThrowCompletionOr<void> VM::property_binding_initialization(BindingPattern const
|
|||
auto* rest_object = Object::create(realm, global_object.object_prototype());
|
||||
VERIFY(rest_object);
|
||||
|
||||
TRY(rest_object->copy_data_properties(object, seen_names, global_object));
|
||||
TRY(rest_object->copy_data_properties(vm, object, seen_names));
|
||||
if (!environment)
|
||||
return assignment_target.put_value(global_object, rest_object);
|
||||
else
|
||||
|
@ -349,7 +350,7 @@ ThrowCompletionOr<void> VM::property_binding_initialization(BindingPattern const
|
|||
},
|
||||
[&](NonnullRefPtr<Expression> const& expression) -> ThrowCompletionOr<PropertyKey> {
|
||||
auto result = TRY(expression->execute(interpreter())).release_value();
|
||||
return result.to_property_key(global_object);
|
||||
return result.to_property_key(vm);
|
||||
}));
|
||||
|
||||
seen_names.set(name);
|
||||
|
|
|
@ -195,10 +195,8 @@ static String double_to_string(double d)
|
|||
}
|
||||
|
||||
// 7.2.2 IsArray ( argument ), https://tc39.es/ecma262/#sec-isarray
|
||||
ThrowCompletionOr<bool> Value::is_array(GlobalObject& global_object) const
|
||||
ThrowCompletionOr<bool> Value::is_array(VM& vm) const
|
||||
{
|
||||
auto& vm = global_object.vm();
|
||||
|
||||
if (!is_object())
|
||||
return false;
|
||||
auto& object = as_object();
|
||||
|
@ -208,7 +206,7 @@ ThrowCompletionOr<bool> Value::is_array(GlobalObject& global_object) const
|
|||
auto& proxy = static_cast<ProxyObject const&>(object);
|
||||
if (proxy.is_revoked())
|
||||
return vm.throw_completion<TypeError>(ErrorType::ProxyRevoked);
|
||||
return Value(&proxy.target()).is_array(global_object);
|
||||
return Value(&proxy.target()).is_array(vm);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -253,12 +251,11 @@ bool Value::is_constructor() const
|
|||
}
|
||||
|
||||
// 7.2.8 IsRegExp ( argument ), https://tc39.es/ecma262/#sec-isregexp
|
||||
ThrowCompletionOr<bool> Value::is_regexp(GlobalObject& global_object) const
|
||||
ThrowCompletionOr<bool> Value::is_regexp(VM& vm) const
|
||||
{
|
||||
if (!is_object())
|
||||
return false;
|
||||
|
||||
auto& vm = global_object.vm();
|
||||
auto matcher = TRY(as_object().get(*vm.well_known_symbol_match()));
|
||||
if (!matcher.is_undefined())
|
||||
return matcher.to_boolean();
|
||||
|
@ -326,21 +323,20 @@ String Value::to_string_without_side_effects() const
|
|||
}
|
||||
}
|
||||
|
||||
ThrowCompletionOr<PrimitiveString*> Value::to_primitive_string(GlobalObject& global_object)
|
||||
ThrowCompletionOr<PrimitiveString*> Value::to_primitive_string(VM& vm)
|
||||
{
|
||||
if (is_string())
|
||||
return &as_string();
|
||||
auto string = TRY(to_string(global_object));
|
||||
return js_string(global_object.heap(), string);
|
||||
auto string = TRY(to_string(vm));
|
||||
return js_string(vm, string);
|
||||
}
|
||||
|
||||
// 7.1.17 ToString ( argument ), https://tc39.es/ecma262/#sec-tostring
|
||||
ThrowCompletionOr<String> Value::to_string(GlobalObject& global_object) const
|
||||
ThrowCompletionOr<String> Value::to_string(VM& vm) const
|
||||
{
|
||||
if (is_double())
|
||||
return double_to_string(m_value.as_double);
|
||||
|
||||
auto& vm = global_object.vm();
|
||||
switch (m_value.tag) {
|
||||
case UNDEFINED_TAG:
|
||||
return "undefined"sv;
|
||||
|
@ -357,20 +353,20 @@ ThrowCompletionOr<String> Value::to_string(GlobalObject& global_object) const
|
|||
case BIGINT_TAG:
|
||||
return as_bigint().big_integer().to_base(10);
|
||||
case OBJECT_TAG: {
|
||||
auto primitive_value = TRY(to_primitive(global_object, PreferredType::String));
|
||||
return primitive_value.to_string(global_object);
|
||||
auto primitive_value = TRY(to_primitive(vm, PreferredType::String));
|
||||
return primitive_value.to_string(vm);
|
||||
}
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
}
|
||||
|
||||
ThrowCompletionOr<Utf16String> Value::to_utf16_string(GlobalObject& global_object) const
|
||||
ThrowCompletionOr<Utf16String> Value::to_utf16_string(VM& vm) const
|
||||
{
|
||||
if (is_string())
|
||||
return as_string().utf16_string();
|
||||
|
||||
auto utf8_string = TRY(to_string(global_object));
|
||||
auto utf8_string = TRY(to_string(vm));
|
||||
return Utf16String(utf8_string);
|
||||
}
|
||||
|
||||
|
@ -408,7 +404,7 @@ bool Value::to_boolean() const
|
|||
}
|
||||
|
||||
// 7.1.1 ToPrimitive ( input [ , preferredType ] ), https://tc39.es/ecma262/#sec-toprimitive
|
||||
ThrowCompletionOr<Value> Value::to_primitive(GlobalObject& global_object, PreferredType preferred_type) const
|
||||
ThrowCompletionOr<Value> Value::to_primitive(VM& vm, PreferredType preferred_type) const
|
||||
{
|
||||
auto get_hint_for_preferred_type = [&]() -> String {
|
||||
switch (preferred_type) {
|
||||
|
@ -423,8 +419,9 @@ ThrowCompletionOr<Value> Value::to_primitive(GlobalObject& global_object, Prefer
|
|||
}
|
||||
};
|
||||
if (is_object()) {
|
||||
auto& vm = global_object.vm();
|
||||
auto to_primitive_method = TRY(get_method(global_object, *vm.well_known_symbol_to_primitive()));
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
auto to_primitive_method = TRY(get_method(vm, *vm.well_known_symbol_to_primitive()));
|
||||
if (to_primitive_method) {
|
||||
auto hint = get_hint_for_preferred_type();
|
||||
auto result = TRY(call(global_object, *to_primitive_method, *this, js_string(vm, hint)));
|
||||
|
@ -440,9 +437,9 @@ ThrowCompletionOr<Value> Value::to_primitive(GlobalObject& global_object, Prefer
|
|||
}
|
||||
|
||||
// 7.1.18 ToObject ( argument ), https://tc39.es/ecma262/#sec-toobject
|
||||
ThrowCompletionOr<Object*> Value::to_object(GlobalObject& global_object) const
|
||||
ThrowCompletionOr<Object*> Value::to_object(VM& vm) const
|
||||
{
|
||||
auto& realm = *global_object.associated_realm();
|
||||
auto& realm = *vm.current_realm();
|
||||
VERIFY(!is_empty());
|
||||
if (is_number())
|
||||
return NumberObject::create(realm, as_double());
|
||||
|
@ -450,11 +447,11 @@ ThrowCompletionOr<Object*> Value::to_object(GlobalObject& global_object) const
|
|||
switch (m_value.tag) {
|
||||
case UNDEFINED_TAG:
|
||||
case NULL_TAG:
|
||||
return global_object.vm().throw_completion<TypeError>(ErrorType::ToObjectNullOrUndefined);
|
||||
return vm.throw_completion<TypeError>(ErrorType::ToObjectNullOrUndefined);
|
||||
case BOOLEAN_TAG:
|
||||
return BooleanObject::create(realm, as_bool());
|
||||
case STRING_TAG:
|
||||
return StringObject::create(realm, const_cast<JS::PrimitiveString&>(as_string()), *global_object.string_prototype());
|
||||
return StringObject::create(realm, const_cast<JS::PrimitiveString&>(as_string()), *realm.global_object().string_prototype());
|
||||
case SYMBOL_TAG:
|
||||
return SymbolObject::create(realm, const_cast<JS::Symbol&>(as_symbol()));
|
||||
case BIGINT_TAG:
|
||||
|
@ -467,16 +464,16 @@ ThrowCompletionOr<Object*> Value::to_object(GlobalObject& global_object) const
|
|||
}
|
||||
|
||||
// 7.1.3 ToNumeric ( value ), https://tc39.es/ecma262/#sec-tonumeric
|
||||
FLATTEN ThrowCompletionOr<Value> Value::to_numeric(GlobalObject& global_object) const
|
||||
FLATTEN ThrowCompletionOr<Value> Value::to_numeric(VM& vm) const
|
||||
{
|
||||
auto primitive = TRY(to_primitive(global_object, Value::PreferredType::Number));
|
||||
auto primitive = TRY(to_primitive(vm, Value::PreferredType::Number));
|
||||
if (primitive.is_bigint())
|
||||
return primitive;
|
||||
return primitive.to_number(global_object);
|
||||
return primitive.to_number(vm);
|
||||
}
|
||||
|
||||
// 7.1.4 ToNumber ( argument ), https://tc39.es/ecma262/#sec-tonumber
|
||||
ThrowCompletionOr<Value> Value::to_number(GlobalObject& global_object) const
|
||||
ThrowCompletionOr<Value> Value::to_number(VM& vm) const
|
||||
{
|
||||
VERIFY(!is_empty());
|
||||
if (is_number())
|
||||
|
@ -509,12 +506,12 @@ ThrowCompletionOr<Value> Value::to_number(GlobalObject& global_object) const
|
|||
return Value(parsed_double);
|
||||
}
|
||||
case SYMBOL_TAG:
|
||||
return global_object.vm().throw_completion<TypeError>(ErrorType::Convert, "symbol", "number");
|
||||
return vm.throw_completion<TypeError>(ErrorType::Convert, "symbol", "number");
|
||||
case BIGINT_TAG:
|
||||
return global_object.vm().throw_completion<TypeError>(ErrorType::Convert, "BigInt", "number");
|
||||
return vm.throw_completion<TypeError>(ErrorType::Convert, "BigInt", "number");
|
||||
case OBJECT_TAG: {
|
||||
auto primitive = TRY(to_primitive(global_object, PreferredType::Number));
|
||||
return primitive.to_number(global_object);
|
||||
auto primitive = TRY(to_primitive(vm, PreferredType::Number));
|
||||
return primitive.to_number(vm);
|
||||
}
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
|
@ -522,10 +519,9 @@ ThrowCompletionOr<Value> Value::to_number(GlobalObject& global_object) const
|
|||
}
|
||||
|
||||
// 7.1.13 ToBigInt ( argument ), https://tc39.es/ecma262/#sec-tobigint
|
||||
ThrowCompletionOr<BigInt*> Value::to_bigint(GlobalObject& global_object) const
|
||||
ThrowCompletionOr<BigInt*> Value::to_bigint(VM& vm) const
|
||||
{
|
||||
auto& vm = global_object.vm();
|
||||
auto primitive = TRY(to_primitive(global_object, PreferredType::Number));
|
||||
auto primitive = TRY(to_primitive(vm, PreferredType::Number));
|
||||
|
||||
VERIFY(!primitive.is_empty());
|
||||
if (primitive.is_number())
|
||||
|
@ -544,7 +540,7 @@ ThrowCompletionOr<BigInt*> Value::to_bigint(GlobalObject& global_object) const
|
|||
return &primitive.as_bigint();
|
||||
case STRING_TAG: {
|
||||
// 1. Let n be ! StringToBigInt(prim).
|
||||
auto bigint = primitive.string_to_bigint(global_object);
|
||||
auto bigint = primitive.string_to_bigint(vm);
|
||||
|
||||
// 2. If n is undefined, throw a SyntaxError exception.
|
||||
if (!bigint.has_value())
|
||||
|
@ -606,7 +602,7 @@ static Optional<BigIntParseResult> parse_bigint_text(StringView text)
|
|||
}
|
||||
|
||||
// 7.1.14 StringToBigInt ( str ), https://tc39.es/ecma262/#sec-stringtobigint
|
||||
Optional<BigInt*> Value::string_to_bigint(GlobalObject& global_object) const
|
||||
Optional<BigInt*> Value::string_to_bigint(VM& vm) const
|
||||
{
|
||||
VERIFY(is_string());
|
||||
|
||||
|
@ -627,43 +623,43 @@ Optional<BigInt*> Value::string_to_bigint(GlobalObject& global_object) const
|
|||
bigint.negate();
|
||||
|
||||
// 6. Return ℤ(mv).
|
||||
return js_bigint(global_object.vm(), move(bigint));
|
||||
return js_bigint(vm, move(bigint));
|
||||
}
|
||||
|
||||
// 7.1.15 ToBigInt64 ( argument ), https://tc39.es/ecma262/#sec-tobigint64
|
||||
ThrowCompletionOr<i64> Value::to_bigint_int64(GlobalObject& global_object) const
|
||||
ThrowCompletionOr<i64> Value::to_bigint_int64(VM& vm) const
|
||||
{
|
||||
auto* bigint = TRY(to_bigint(global_object));
|
||||
auto* bigint = TRY(to_bigint(vm));
|
||||
return static_cast<i64>(bigint->big_integer().to_u64());
|
||||
}
|
||||
|
||||
// 7.1.16 ToBigUint64 ( argument ), https://tc39.es/ecma262/#sec-tobiguint64
|
||||
ThrowCompletionOr<u64> Value::to_bigint_uint64(GlobalObject& global_object) const
|
||||
ThrowCompletionOr<u64> Value::to_bigint_uint64(VM& vm) const
|
||||
{
|
||||
auto* bigint = TRY(to_bigint(global_object));
|
||||
auto* bigint = TRY(to_bigint(vm));
|
||||
return bigint->big_integer().to_u64();
|
||||
}
|
||||
|
||||
ThrowCompletionOr<double> Value::to_double(GlobalObject& global_object) const
|
||||
ThrowCompletionOr<double> Value::to_double(VM& vm) const
|
||||
{
|
||||
return TRY(to_number(global_object)).as_double();
|
||||
return TRY(to_number(vm)).as_double();
|
||||
}
|
||||
|
||||
// 7.1.19 ToPropertyKey ( argument ), https://tc39.es/ecma262/#sec-topropertykey
|
||||
ThrowCompletionOr<PropertyKey> Value::to_property_key(GlobalObject& global_object) const
|
||||
ThrowCompletionOr<PropertyKey> Value::to_property_key(VM& vm) const
|
||||
{
|
||||
if (is_int32() && as_i32() >= 0)
|
||||
return PropertyKey { as_i32() };
|
||||
auto key = TRY(to_primitive(global_object, PreferredType::String));
|
||||
auto key = TRY(to_primitive(vm, PreferredType::String));
|
||||
if (key.is_symbol())
|
||||
return &key.as_symbol();
|
||||
return TRY(key.to_string(global_object));
|
||||
return TRY(key.to_string(vm));
|
||||
}
|
||||
|
||||
ThrowCompletionOr<i32> Value::to_i32_slow_case(GlobalObject& global_object) const
|
||||
ThrowCompletionOr<i32> Value::to_i32_slow_case(VM& vm) const
|
||||
{
|
||||
VERIFY(!is_int32());
|
||||
double value = TRY(to_number(global_object)).as_double();
|
||||
double value = TRY(to_number(vm)).as_double();
|
||||
if (!isfinite(value) || value == 0)
|
||||
return 0;
|
||||
auto abs = fabs(value);
|
||||
|
@ -677,17 +673,17 @@ ThrowCompletionOr<i32> Value::to_i32_slow_case(GlobalObject& global_object) cons
|
|||
return static_cast<i32>(int32bit);
|
||||
}
|
||||
|
||||
ThrowCompletionOr<i32> Value::to_i32(GlobalObject& global_object) const
|
||||
ThrowCompletionOr<i32> Value::to_i32(VM& vm) const
|
||||
{
|
||||
if (is_int32())
|
||||
return as_i32();
|
||||
return to_i32_slow_case(global_object);
|
||||
return to_i32_slow_case(vm);
|
||||
}
|
||||
|
||||
// 7.1.7 ToUint32 ( argument ), https://tc39.es/ecma262/#sec-touint32
|
||||
ThrowCompletionOr<u32> Value::to_u32(GlobalObject& global_object) const
|
||||
ThrowCompletionOr<u32> Value::to_u32(VM& vm) const
|
||||
{
|
||||
double value = TRY(to_number(global_object)).as_double();
|
||||
double value = TRY(to_number(vm)).as_double();
|
||||
if (!isfinite(value) || value == 0)
|
||||
return 0;
|
||||
auto int_val = floor(fabs(value));
|
||||
|
@ -700,9 +696,9 @@ ThrowCompletionOr<u32> Value::to_u32(GlobalObject& global_object) const
|
|||
}
|
||||
|
||||
// 7.1.8 ToInt16 ( argument ), https://tc39.es/ecma262/#sec-toint16
|
||||
ThrowCompletionOr<i16> Value::to_i16(GlobalObject& global_object) const
|
||||
ThrowCompletionOr<i16> Value::to_i16(VM& vm) const
|
||||
{
|
||||
double value = TRY(to_number(global_object)).as_double();
|
||||
double value = TRY(to_number(vm)).as_double();
|
||||
if (!isfinite(value) || value == 0)
|
||||
return 0;
|
||||
auto abs = fabs(value);
|
||||
|
@ -717,9 +713,9 @@ ThrowCompletionOr<i16> Value::to_i16(GlobalObject& global_object) const
|
|||
}
|
||||
|
||||
// 7.1.9 ToUint16 ( argument ), https://tc39.es/ecma262/#sec-touint16
|
||||
ThrowCompletionOr<u16> Value::to_u16(GlobalObject& global_object) const
|
||||
ThrowCompletionOr<u16> Value::to_u16(VM& vm) const
|
||||
{
|
||||
double value = TRY(to_number(global_object)).as_double();
|
||||
double value = TRY(to_number(vm)).as_double();
|
||||
if (!isfinite(value) || value == 0)
|
||||
return 0;
|
||||
auto int_val = floor(fabs(value));
|
||||
|
@ -732,9 +728,9 @@ ThrowCompletionOr<u16> Value::to_u16(GlobalObject& global_object) const
|
|||
}
|
||||
|
||||
// 7.1.10 ToInt8 ( argument ), https://tc39.es/ecma262/#sec-toint8
|
||||
ThrowCompletionOr<i8> Value::to_i8(GlobalObject& global_object) const
|
||||
ThrowCompletionOr<i8> Value::to_i8(VM& vm) const
|
||||
{
|
||||
double value = TRY(to_number(global_object)).as_double();
|
||||
double value = TRY(to_number(vm)).as_double();
|
||||
if (!isfinite(value) || value == 0)
|
||||
return 0;
|
||||
auto abs = fabs(value);
|
||||
|
@ -749,9 +745,9 @@ ThrowCompletionOr<i8> Value::to_i8(GlobalObject& global_object) const
|
|||
}
|
||||
|
||||
// 7.1.11 ToUint8 ( argument ), https://tc39.es/ecma262/#sec-touint8
|
||||
ThrowCompletionOr<u8> Value::to_u8(GlobalObject& global_object) const
|
||||
ThrowCompletionOr<u8> Value::to_u8(VM& vm) const
|
||||
{
|
||||
double value = TRY(to_number(global_object)).as_double();
|
||||
double value = TRY(to_number(vm)).as_double();
|
||||
if (!isfinite(value) || value == 0)
|
||||
return 0;
|
||||
auto int_val = floor(fabs(value));
|
||||
|
@ -764,9 +760,9 @@ ThrowCompletionOr<u8> Value::to_u8(GlobalObject& global_object) const
|
|||
}
|
||||
|
||||
// 7.1.12 ToUint8Clamp ( argument ), https://tc39.es/ecma262/#sec-touint8clamp
|
||||
ThrowCompletionOr<u8> Value::to_u8_clamp(GlobalObject& global_object) const
|
||||
ThrowCompletionOr<u8> Value::to_u8_clamp(VM& vm) const
|
||||
{
|
||||
auto number = TRY(to_number(global_object));
|
||||
auto number = TRY(to_number(vm));
|
||||
if (number.is_nan())
|
||||
return 0;
|
||||
double value = number.as_double();
|
||||
|
@ -785,9 +781,9 @@ ThrowCompletionOr<u8> Value::to_u8_clamp(GlobalObject& global_object) const
|
|||
}
|
||||
|
||||
// 7.1.20 ToLength ( argument ), https://tc39.es/ecma262/#sec-tolength
|
||||
ThrowCompletionOr<size_t> Value::to_length(GlobalObject& global_object) const
|
||||
ThrowCompletionOr<size_t> Value::to_length(VM& vm) const
|
||||
{
|
||||
auto len = TRY(to_integer_or_infinity(global_object));
|
||||
auto len = TRY(to_integer_or_infinity(vm));
|
||||
if (len <= 0)
|
||||
return 0;
|
||||
// FIXME: The spec says that this function's output range is 0 - 2^53-1. But we don't want to overflow the size_t.
|
||||
|
@ -796,25 +792,23 @@ ThrowCompletionOr<size_t> Value::to_length(GlobalObject& global_object) const
|
|||
}
|
||||
|
||||
// 7.1.22 ToIndex ( argument ), https://tc39.es/ecma262/#sec-toindex
|
||||
ThrowCompletionOr<size_t> Value::to_index(GlobalObject& global_object) const
|
||||
ThrowCompletionOr<size_t> Value::to_index(VM& vm) const
|
||||
{
|
||||
auto& vm = global_object.vm();
|
||||
|
||||
if (is_undefined())
|
||||
return 0;
|
||||
auto integer_index = TRY(to_integer_or_infinity(global_object));
|
||||
auto integer_index = TRY(to_integer_or_infinity(vm));
|
||||
if (integer_index < 0)
|
||||
return vm.throw_completion<RangeError>(ErrorType::InvalidIndex);
|
||||
auto index = MUST(Value(integer_index).to_length(global_object));
|
||||
auto index = MUST(Value(integer_index).to_length(vm));
|
||||
if (integer_index != index)
|
||||
return vm.throw_completion<RangeError>(ErrorType::InvalidIndex);
|
||||
return index;
|
||||
}
|
||||
|
||||
// 7.1.5 ToIntegerOrInfinity ( argument ), https://tc39.es/ecma262/#sec-tointegerorinfinity
|
||||
ThrowCompletionOr<double> Value::to_integer_or_infinity(GlobalObject& global_object) const
|
||||
ThrowCompletionOr<double> Value::to_integer_or_infinity(VM& vm) const
|
||||
{
|
||||
auto number = TRY(to_number(global_object));
|
||||
auto number = TRY(to_number(vm));
|
||||
if (number.is_nan() || number.as_double() == 0)
|
||||
return 0;
|
||||
if (number.is_infinity())
|
||||
|
@ -854,28 +848,26 @@ double to_integer_or_infinity(double number)
|
|||
}
|
||||
|
||||
// 7.3.3 GetV ( V, P ), https://tc39.es/ecma262/#sec-getv
|
||||
ThrowCompletionOr<Value> Value::get(GlobalObject& global_object, PropertyKey const& property_key) const
|
||||
ThrowCompletionOr<Value> Value::get(VM& vm, PropertyKey const& property_key) const
|
||||
{
|
||||
// 1. Assert: IsPropertyKey(P) is true.
|
||||
VERIFY(property_key.is_valid());
|
||||
|
||||
// 2. Let O be ? ToObject(V).
|
||||
auto* object = TRY(to_object(global_object));
|
||||
auto* object = TRY(to_object(vm));
|
||||
|
||||
// 3. Return ? O.[[Get]](P, V).
|
||||
return TRY(object->internal_get(property_key, *this));
|
||||
}
|
||||
|
||||
// 7.3.11 GetMethod ( V, P ), https://tc39.es/ecma262/#sec-getmethod
|
||||
ThrowCompletionOr<FunctionObject*> Value::get_method(GlobalObject& global_object, PropertyKey const& property_key) const
|
||||
ThrowCompletionOr<FunctionObject*> Value::get_method(VM& vm, PropertyKey const& property_key) const
|
||||
{
|
||||
auto& vm = global_object.vm();
|
||||
|
||||
// 1. Assert: IsPropertyKey(P) is true.
|
||||
VERIFY(property_key.is_valid());
|
||||
|
||||
// 2. Let func be ? GetV(V, P).
|
||||
auto function = TRY(get(global_object, property_key));
|
||||
auto function = TRY(get(vm, property_key));
|
||||
|
||||
// 3. If func is either undefined or null, return undefined.
|
||||
if (function.is_nullish())
|
||||
|
@ -890,63 +882,62 @@ ThrowCompletionOr<FunctionObject*> Value::get_method(GlobalObject& global_object
|
|||
}
|
||||
|
||||
// 13.10 Relational Operators, https://tc39.es/ecma262/#sec-relational-operators
|
||||
ThrowCompletionOr<Value> greater_than(GlobalObject& global_object, Value lhs, Value rhs)
|
||||
ThrowCompletionOr<Value> greater_than(VM& vm, Value lhs, Value rhs)
|
||||
{
|
||||
if (lhs.is_int32() && rhs.is_int32())
|
||||
return lhs.as_i32() > rhs.as_i32();
|
||||
|
||||
TriState relation = TRY(is_less_than(global_object, lhs, rhs, false));
|
||||
TriState relation = TRY(is_less_than(vm, lhs, rhs, false));
|
||||
if (relation == TriState::Unknown)
|
||||
return Value(false);
|
||||
return Value(relation == TriState::True);
|
||||
}
|
||||
|
||||
// 13.10 Relational Operators, https://tc39.es/ecma262/#sec-relational-operators
|
||||
ThrowCompletionOr<Value> greater_than_equals(GlobalObject& global_object, Value lhs, Value rhs)
|
||||
ThrowCompletionOr<Value> greater_than_equals(VM& vm, Value lhs, Value rhs)
|
||||
{
|
||||
if (lhs.is_int32() && rhs.is_int32())
|
||||
return lhs.as_i32() >= rhs.as_i32();
|
||||
|
||||
TriState relation = TRY(is_less_than(global_object, lhs, rhs, true));
|
||||
TriState relation = TRY(is_less_than(vm, lhs, rhs, true));
|
||||
if (relation == TriState::Unknown || relation == TriState::True)
|
||||
return Value(false);
|
||||
return Value(true);
|
||||
}
|
||||
|
||||
// 13.10 Relational Operators, https://tc39.es/ecma262/#sec-relational-operators
|
||||
ThrowCompletionOr<Value> less_than(GlobalObject& global_object, Value lhs, Value rhs)
|
||||
ThrowCompletionOr<Value> less_than(VM& vm, Value lhs, Value rhs)
|
||||
{
|
||||
if (lhs.is_int32() && rhs.is_int32())
|
||||
return lhs.as_i32() < rhs.as_i32();
|
||||
|
||||
TriState relation = TRY(is_less_than(global_object, lhs, rhs, true));
|
||||
TriState relation = TRY(is_less_than(vm, lhs, rhs, true));
|
||||
if (relation == TriState::Unknown)
|
||||
return Value(false);
|
||||
return Value(relation == TriState::True);
|
||||
}
|
||||
|
||||
// 13.10 Relational Operators, https://tc39.es/ecma262/#sec-relational-operators
|
||||
ThrowCompletionOr<Value> less_than_equals(GlobalObject& global_object, Value lhs, Value rhs)
|
||||
ThrowCompletionOr<Value> less_than_equals(VM& vm, Value lhs, Value rhs)
|
||||
{
|
||||
if (lhs.is_int32() && rhs.is_int32())
|
||||
return lhs.as_i32() <= rhs.as_i32();
|
||||
|
||||
TriState relation = TRY(is_less_than(global_object, lhs, rhs, false));
|
||||
TriState relation = TRY(is_less_than(vm, lhs, rhs, false));
|
||||
if (relation == TriState::Unknown || relation == TriState::True)
|
||||
return Value(false);
|
||||
return Value(true);
|
||||
}
|
||||
|
||||
// 13.12 Binary Bitwise Operators, https://tc39.es/ecma262/#sec-binary-bitwise-operators
|
||||
ThrowCompletionOr<Value> bitwise_and(GlobalObject& global_object, Value lhs, Value rhs)
|
||||
ThrowCompletionOr<Value> bitwise_and(VM& vm, Value lhs, Value rhs)
|
||||
{
|
||||
auto& vm = global_object.vm();
|
||||
auto lhs_numeric = TRY(lhs.to_numeric(global_object));
|
||||
auto rhs_numeric = TRY(rhs.to_numeric(global_object));
|
||||
auto lhs_numeric = TRY(lhs.to_numeric(vm));
|
||||
auto rhs_numeric = TRY(rhs.to_numeric(vm));
|
||||
if (both_number(lhs_numeric, rhs_numeric)) {
|
||||
if (!lhs_numeric.is_finite_number() || !rhs_numeric.is_finite_number())
|
||||
return Value(0);
|
||||
return Value(TRY(lhs_numeric.to_i32(global_object)) & TRY(rhs_numeric.to_i32(global_object)));
|
||||
return Value(TRY(lhs_numeric.to_i32(vm)) & TRY(rhs_numeric.to_i32(vm)));
|
||||
}
|
||||
if (both_bigint(lhs_numeric, rhs_numeric))
|
||||
return Value(js_bigint(vm, lhs_numeric.as_bigint().big_integer().bitwise_and(rhs_numeric.as_bigint().big_integer())));
|
||||
|
@ -954,11 +945,10 @@ ThrowCompletionOr<Value> bitwise_and(GlobalObject& global_object, Value lhs, Val
|
|||
}
|
||||
|
||||
// 13.12 Binary Bitwise Operators, https://tc39.es/ecma262/#sec-binary-bitwise-operators
|
||||
ThrowCompletionOr<Value> bitwise_or(GlobalObject& global_object, Value lhs, Value rhs)
|
||||
ThrowCompletionOr<Value> bitwise_or(VM& vm, Value lhs, Value rhs)
|
||||
{
|
||||
auto& vm = global_object.vm();
|
||||
auto lhs_numeric = TRY(lhs.to_numeric(global_object));
|
||||
auto rhs_numeric = TRY(rhs.to_numeric(global_object));
|
||||
auto lhs_numeric = TRY(lhs.to_numeric(vm));
|
||||
auto rhs_numeric = TRY(rhs.to_numeric(vm));
|
||||
if (both_number(lhs_numeric, rhs_numeric)) {
|
||||
if (!lhs_numeric.is_finite_number() && !rhs_numeric.is_finite_number())
|
||||
return Value(0);
|
||||
|
@ -966,7 +956,7 @@ ThrowCompletionOr<Value> bitwise_or(GlobalObject& global_object, Value lhs, Valu
|
|||
return rhs_numeric;
|
||||
if (!rhs_numeric.is_finite_number())
|
||||
return lhs_numeric;
|
||||
return Value(TRY(lhs_numeric.to_i32(global_object)) | TRY(rhs_numeric.to_i32(global_object)));
|
||||
return Value(TRY(lhs_numeric.to_i32(vm)) | TRY(rhs_numeric.to_i32(vm)));
|
||||
}
|
||||
if (both_bigint(lhs_numeric, rhs_numeric))
|
||||
return Value(js_bigint(vm, lhs_numeric.as_bigint().big_integer().bitwise_or(rhs_numeric.as_bigint().big_integer())));
|
||||
|
@ -974,11 +964,10 @@ ThrowCompletionOr<Value> bitwise_or(GlobalObject& global_object, Value lhs, Valu
|
|||
}
|
||||
|
||||
// 13.12 Binary Bitwise Operators, https://tc39.es/ecma262/#sec-binary-bitwise-operators
|
||||
ThrowCompletionOr<Value> bitwise_xor(GlobalObject& global_object, Value lhs, Value rhs)
|
||||
ThrowCompletionOr<Value> bitwise_xor(VM& vm, Value lhs, Value rhs)
|
||||
{
|
||||
auto& vm = global_object.vm();
|
||||
auto lhs_numeric = TRY(lhs.to_numeric(global_object));
|
||||
auto rhs_numeric = TRY(rhs.to_numeric(global_object));
|
||||
auto lhs_numeric = TRY(lhs.to_numeric(vm));
|
||||
auto rhs_numeric = TRY(rhs.to_numeric(vm));
|
||||
if (both_number(lhs_numeric, rhs_numeric)) {
|
||||
if (!lhs_numeric.is_finite_number() && !rhs_numeric.is_finite_number())
|
||||
return Value(0);
|
||||
|
@ -986,7 +975,7 @@ ThrowCompletionOr<Value> bitwise_xor(GlobalObject& global_object, Value lhs, Val
|
|||
return rhs_numeric;
|
||||
if (!rhs_numeric.is_finite_number())
|
||||
return lhs_numeric;
|
||||
return Value(TRY(lhs_numeric.to_i32(global_object)) ^ TRY(rhs_numeric.to_i32(global_object)));
|
||||
return Value(TRY(lhs_numeric.to_i32(vm)) ^ TRY(rhs_numeric.to_i32(vm)));
|
||||
}
|
||||
if (both_bigint(lhs_numeric, rhs_numeric))
|
||||
return Value(js_bigint(vm, lhs_numeric.as_bigint().big_integer().bitwise_xor(rhs_numeric.as_bigint().big_integer())));
|
||||
|
@ -994,26 +983,24 @@ ThrowCompletionOr<Value> bitwise_xor(GlobalObject& global_object, Value lhs, Val
|
|||
}
|
||||
|
||||
// 13.5.6 Bitwise NOT Operator ( ~ ), https://tc39.es/ecma262/#sec-bitwise-not-operator
|
||||
ThrowCompletionOr<Value> bitwise_not(GlobalObject& global_object, Value lhs)
|
||||
ThrowCompletionOr<Value> bitwise_not(VM& vm, Value lhs)
|
||||
{
|
||||
auto& vm = global_object.vm();
|
||||
auto lhs_numeric = TRY(lhs.to_numeric(global_object));
|
||||
auto lhs_numeric = TRY(lhs.to_numeric(vm));
|
||||
if (lhs_numeric.is_number())
|
||||
return Value(~TRY(lhs_numeric.to_i32(global_object)));
|
||||
return Value(~TRY(lhs_numeric.to_i32(vm)));
|
||||
return Value(js_bigint(vm, lhs_numeric.as_bigint().big_integer().bitwise_not()));
|
||||
}
|
||||
|
||||
// 13.5.4 Unary + Operator, https://tc39.es/ecma262/#sec-unary-plus-operator
|
||||
ThrowCompletionOr<Value> unary_plus(GlobalObject& global_object, Value lhs)
|
||||
ThrowCompletionOr<Value> unary_plus(VM& vm, Value lhs)
|
||||
{
|
||||
return TRY(lhs.to_number(global_object));
|
||||
return TRY(lhs.to_number(vm));
|
||||
}
|
||||
|
||||
// 13.5.5 Unary - Operator, https://tc39.es/ecma262/#sec-unary-minus-operator
|
||||
ThrowCompletionOr<Value> unary_minus(GlobalObject& global_object, Value lhs)
|
||||
ThrowCompletionOr<Value> unary_minus(VM& vm, Value lhs)
|
||||
{
|
||||
auto& vm = global_object.vm();
|
||||
auto lhs_numeric = TRY(lhs.to_numeric(global_object));
|
||||
auto lhs_numeric = TRY(lhs.to_numeric(vm));
|
||||
if (lhs_numeric.is_number()) {
|
||||
if (lhs_numeric.is_nan())
|
||||
return js_nan();
|
||||
|
@ -1027,19 +1014,18 @@ ThrowCompletionOr<Value> unary_minus(GlobalObject& global_object, Value lhs)
|
|||
}
|
||||
|
||||
// 13.9.1 The Left Shift Operator ( << ), https://tc39.es/ecma262/#sec-left-shift-operator
|
||||
ThrowCompletionOr<Value> left_shift(GlobalObject& global_object, Value lhs, Value rhs)
|
||||
ThrowCompletionOr<Value> left_shift(VM& vm, Value lhs, Value rhs)
|
||||
{
|
||||
auto& vm = global_object.vm();
|
||||
auto lhs_numeric = TRY(lhs.to_numeric(global_object));
|
||||
auto rhs_numeric = TRY(rhs.to_numeric(global_object));
|
||||
auto lhs_numeric = TRY(lhs.to_numeric(vm));
|
||||
auto rhs_numeric = TRY(rhs.to_numeric(vm));
|
||||
if (both_number(lhs_numeric, rhs_numeric)) {
|
||||
if (!lhs_numeric.is_finite_number())
|
||||
return Value(0);
|
||||
if (!rhs_numeric.is_finite_number())
|
||||
return lhs_numeric;
|
||||
// Ok, so this performs toNumber() again but that "can't" throw
|
||||
auto lhs_i32 = MUST(lhs_numeric.to_i32(global_object));
|
||||
auto rhs_u32 = MUST(rhs_numeric.to_u32(global_object)) % 32;
|
||||
auto lhs_i32 = MUST(lhs_numeric.to_i32(vm));
|
||||
auto rhs_u32 = MUST(rhs_numeric.to_u32(vm)) % 32;
|
||||
return Value(lhs_i32 << rhs_u32);
|
||||
}
|
||||
if (both_bigint(lhs_numeric, rhs_numeric)) {
|
||||
|
@ -1053,72 +1039,69 @@ ThrowCompletionOr<Value> left_shift(GlobalObject& global_object, Value lhs, Valu
|
|||
}
|
||||
|
||||
// 13.9.2 The Signed Right Shift Operator ( >> ), https://tc39.es/ecma262/#sec-signed-right-shift-operator
|
||||
ThrowCompletionOr<Value> right_shift(GlobalObject& global_object, Value lhs, Value rhs)
|
||||
ThrowCompletionOr<Value> right_shift(VM& vm, Value lhs, Value rhs)
|
||||
{
|
||||
auto& vm = global_object.vm();
|
||||
auto lhs_numeric = TRY(lhs.to_numeric(global_object));
|
||||
auto rhs_numeric = TRY(rhs.to_numeric(global_object));
|
||||
auto lhs_numeric = TRY(lhs.to_numeric(vm));
|
||||
auto rhs_numeric = TRY(rhs.to_numeric(vm));
|
||||
if (both_number(lhs_numeric, rhs_numeric)) {
|
||||
if (!lhs_numeric.is_finite_number())
|
||||
return Value(0);
|
||||
if (!rhs_numeric.is_finite_number())
|
||||
return lhs_numeric;
|
||||
auto lhs_i32 = MUST(lhs_numeric.to_i32(global_object));
|
||||
auto rhs_u32 = MUST(rhs_numeric.to_u32(global_object)) % 32;
|
||||
auto lhs_i32 = MUST(lhs_numeric.to_i32(vm));
|
||||
auto rhs_u32 = MUST(rhs_numeric.to_u32(vm)) % 32;
|
||||
return Value(lhs_i32 >> rhs_u32);
|
||||
}
|
||||
if (both_bigint(lhs_numeric, rhs_numeric)) {
|
||||
auto rhs_negated = rhs_numeric.as_bigint().big_integer();
|
||||
rhs_negated.negate();
|
||||
return left_shift(global_object, lhs, js_bigint(vm, rhs_negated));
|
||||
return left_shift(vm, lhs, js_bigint(vm, rhs_negated));
|
||||
}
|
||||
return vm.throw_completion<TypeError>(ErrorType::BigIntBadOperatorOtherType, "right-shift");
|
||||
}
|
||||
|
||||
// 13.9.3 The Unsigned Right Shift Operator ( >>> ), https://tc39.es/ecma262/#sec-unsigned-right-shift-operator
|
||||
ThrowCompletionOr<Value> unsigned_right_shift(GlobalObject& global_object, Value lhs, Value rhs)
|
||||
ThrowCompletionOr<Value> unsigned_right_shift(VM& vm, Value lhs, Value rhs)
|
||||
{
|
||||
auto& vm = global_object.vm();
|
||||
auto lhs_numeric = TRY(lhs.to_numeric(global_object));
|
||||
auto rhs_numeric = TRY(rhs.to_numeric(global_object));
|
||||
auto lhs_numeric = TRY(lhs.to_numeric(vm));
|
||||
auto rhs_numeric = TRY(rhs.to_numeric(vm));
|
||||
if (both_number(lhs_numeric, rhs_numeric)) {
|
||||
if (!lhs_numeric.is_finite_number())
|
||||
return Value(0);
|
||||
if (!rhs_numeric.is_finite_number())
|
||||
return lhs_numeric;
|
||||
// Ok, so this performs toNumber() again but that "can't" throw
|
||||
auto lhs_u32 = MUST(lhs_numeric.to_u32(global_object));
|
||||
auto rhs_u32 = MUST(rhs_numeric.to_u32(global_object)) % 32;
|
||||
auto lhs_u32 = MUST(lhs_numeric.to_u32(vm));
|
||||
auto rhs_u32 = MUST(rhs_numeric.to_u32(vm)) % 32;
|
||||
return Value(lhs_u32 >> rhs_u32);
|
||||
}
|
||||
return vm.throw_completion<TypeError>(ErrorType::BigIntBadOperator, "unsigned right-shift");
|
||||
}
|
||||
|
||||
// 13.8.1 The Addition Operator ( + ), https://tc39.es/ecma262/#sec-addition-operator-plus
|
||||
ThrowCompletionOr<Value> add(GlobalObject& global_object, Value lhs, Value rhs)
|
||||
ThrowCompletionOr<Value> add(VM& vm, Value lhs, Value rhs)
|
||||
{
|
||||
if (both_number(lhs, rhs)) {
|
||||
if (lhs.is_int32() && rhs.is_int32()) {
|
||||
Checked<i32> result;
|
||||
result = MUST(lhs.to_i32(global_object));
|
||||
result += MUST(rhs.to_i32(global_object));
|
||||
result = MUST(lhs.to_i32(vm));
|
||||
result += MUST(rhs.to_i32(vm));
|
||||
if (!result.has_overflow())
|
||||
return Value(result.value());
|
||||
}
|
||||
return Value(lhs.as_double() + rhs.as_double());
|
||||
}
|
||||
auto& vm = global_object.vm();
|
||||
auto lhs_primitive = TRY(lhs.to_primitive(global_object));
|
||||
auto rhs_primitive = TRY(rhs.to_primitive(global_object));
|
||||
auto lhs_primitive = TRY(lhs.to_primitive(vm));
|
||||
auto rhs_primitive = TRY(rhs.to_primitive(vm));
|
||||
|
||||
if (lhs_primitive.is_string() || rhs_primitive.is_string()) {
|
||||
auto lhs_string = TRY(lhs_primitive.to_primitive_string(global_object));
|
||||
auto rhs_string = TRY(rhs_primitive.to_primitive_string(global_object));
|
||||
return js_rope_string(global_object.vm(), *lhs_string, *rhs_string);
|
||||
auto lhs_string = TRY(lhs_primitive.to_primitive_string(vm));
|
||||
auto rhs_string = TRY(rhs_primitive.to_primitive_string(vm));
|
||||
return js_rope_string(vm, *lhs_string, *rhs_string);
|
||||
}
|
||||
|
||||
auto lhs_numeric = TRY(lhs_primitive.to_numeric(global_object));
|
||||
auto rhs_numeric = TRY(rhs_primitive.to_numeric(global_object));
|
||||
auto lhs_numeric = TRY(lhs_primitive.to_numeric(vm));
|
||||
auto rhs_numeric = TRY(rhs_primitive.to_numeric(vm));
|
||||
if (both_number(lhs_numeric, rhs_numeric))
|
||||
return Value(lhs_numeric.as_double() + rhs_numeric.as_double());
|
||||
if (both_bigint(lhs_numeric, rhs_numeric))
|
||||
|
@ -1127,11 +1110,10 @@ ThrowCompletionOr<Value> add(GlobalObject& global_object, Value lhs, Value rhs)
|
|||
}
|
||||
|
||||
// 13.8.2 The Subtraction Operator ( - ), https://tc39.es/ecma262/#sec-subtraction-operator-minus
|
||||
ThrowCompletionOr<Value> sub(GlobalObject& global_object, Value lhs, Value rhs)
|
||||
ThrowCompletionOr<Value> sub(VM& vm, Value lhs, Value rhs)
|
||||
{
|
||||
auto& vm = global_object.vm();
|
||||
auto lhs_numeric = TRY(lhs.to_numeric(global_object));
|
||||
auto rhs_numeric = TRY(rhs.to_numeric(global_object));
|
||||
auto lhs_numeric = TRY(lhs.to_numeric(vm));
|
||||
auto rhs_numeric = TRY(rhs.to_numeric(vm));
|
||||
if (both_number(lhs_numeric, rhs_numeric)) {
|
||||
double lhsd = lhs_numeric.as_double();
|
||||
double rhsd = rhs_numeric.as_double();
|
||||
|
@ -1144,11 +1126,10 @@ ThrowCompletionOr<Value> sub(GlobalObject& global_object, Value lhs, Value rhs)
|
|||
}
|
||||
|
||||
// 13.7 Multiplicative Operators, https://tc39.es/ecma262/#sec-multiplicative-operators
|
||||
ThrowCompletionOr<Value> mul(GlobalObject& global_object, Value lhs, Value rhs)
|
||||
ThrowCompletionOr<Value> mul(VM& vm, Value lhs, Value rhs)
|
||||
{
|
||||
auto& vm = global_object.vm();
|
||||
auto lhs_numeric = TRY(lhs.to_numeric(global_object));
|
||||
auto rhs_numeric = TRY(rhs.to_numeric(global_object));
|
||||
auto lhs_numeric = TRY(lhs.to_numeric(vm));
|
||||
auto rhs_numeric = TRY(rhs.to_numeric(vm));
|
||||
if (both_number(lhs_numeric, rhs_numeric))
|
||||
return Value(lhs_numeric.as_double() * rhs_numeric.as_double());
|
||||
if (both_bigint(lhs_numeric, rhs_numeric))
|
||||
|
@ -1157,11 +1138,10 @@ ThrowCompletionOr<Value> mul(GlobalObject& global_object, Value lhs, Value rhs)
|
|||
}
|
||||
|
||||
// 13.7 Multiplicative Operators, https://tc39.es/ecma262/#sec-multiplicative-operators
|
||||
ThrowCompletionOr<Value> div(GlobalObject& global_object, Value lhs, Value rhs)
|
||||
ThrowCompletionOr<Value> div(VM& vm, Value lhs, Value rhs)
|
||||
{
|
||||
auto& vm = global_object.vm();
|
||||
auto lhs_numeric = TRY(lhs.to_numeric(global_object));
|
||||
auto rhs_numeric = TRY(rhs.to_numeric(global_object));
|
||||
auto lhs_numeric = TRY(lhs.to_numeric(vm));
|
||||
auto rhs_numeric = TRY(rhs.to_numeric(vm));
|
||||
if (both_number(lhs_numeric, rhs_numeric))
|
||||
return Value(lhs_numeric.as_double() / rhs_numeric.as_double());
|
||||
if (both_bigint(lhs_numeric, rhs_numeric)) {
|
||||
|
@ -1173,11 +1153,10 @@ ThrowCompletionOr<Value> div(GlobalObject& global_object, Value lhs, Value rhs)
|
|||
}
|
||||
|
||||
// 13.7 Multiplicative Operators, https://tc39.es/ecma262/#sec-multiplicative-operators
|
||||
ThrowCompletionOr<Value> mod(GlobalObject& global_object, Value lhs, Value rhs)
|
||||
ThrowCompletionOr<Value> mod(VM& vm, Value lhs, Value rhs)
|
||||
{
|
||||
auto& vm = global_object.vm();
|
||||
auto lhs_numeric = TRY(lhs.to_numeric(global_object));
|
||||
auto rhs_numeric = TRY(rhs.to_numeric(global_object));
|
||||
auto lhs_numeric = TRY(lhs.to_numeric(vm));
|
||||
auto rhs_numeric = TRY(rhs.to_numeric(vm));
|
||||
if (both_number(lhs_numeric, rhs_numeric)) {
|
||||
// 6.1.6.1.6 Number::remainder ( n, d ), https://tc39.es/ecma262/#sec-numeric-types-number-remainder
|
||||
// The ECMA specification is describing the mathematical definition of modulus
|
||||
|
@ -1247,11 +1226,10 @@ static Value exp_double(Value base, Value exponent)
|
|||
}
|
||||
|
||||
// 13.6 Exponentiation Operator, https://tc39.es/ecma262/#sec-exp-operator
|
||||
ThrowCompletionOr<Value> exp(GlobalObject& global_object, Value lhs, Value rhs)
|
||||
ThrowCompletionOr<Value> exp(VM& vm, Value lhs, Value rhs)
|
||||
{
|
||||
auto& vm = global_object.vm();
|
||||
auto lhs_numeric = TRY(lhs.to_numeric(global_object));
|
||||
auto rhs_numeric = TRY(rhs.to_numeric(global_object));
|
||||
auto lhs_numeric = TRY(lhs.to_numeric(vm));
|
||||
auto rhs_numeric = TRY(rhs.to_numeric(vm));
|
||||
if (both_number(lhs_numeric, rhs_numeric))
|
||||
return exp_double(lhs_numeric, rhs_numeric);
|
||||
if (both_bigint(lhs_numeric, rhs_numeric)) {
|
||||
|
@ -1262,41 +1240,41 @@ ThrowCompletionOr<Value> exp(GlobalObject& global_object, Value lhs, Value rhs)
|
|||
return vm.throw_completion<TypeError>(ErrorType::BigIntBadOperatorOtherType, "exponentiation");
|
||||
}
|
||||
|
||||
ThrowCompletionOr<Value> in(GlobalObject& global_object, Value lhs, Value rhs)
|
||||
ThrowCompletionOr<Value> in(VM& vm, Value lhs, Value rhs)
|
||||
{
|
||||
if (!rhs.is_object())
|
||||
return global_object.vm().throw_completion<TypeError>(ErrorType::InOperatorWithObject);
|
||||
auto lhs_property_key = TRY(lhs.to_property_key(global_object));
|
||||
return vm.throw_completion<TypeError>(ErrorType::InOperatorWithObject);
|
||||
auto lhs_property_key = TRY(lhs.to_property_key(vm));
|
||||
return Value(TRY(rhs.as_object().has_property(lhs_property_key)));
|
||||
}
|
||||
|
||||
// 13.10.2 InstanceofOperator ( V, target ), https://tc39.es/ecma262/#sec-instanceofoperator
|
||||
ThrowCompletionOr<Value> instance_of(GlobalObject& global_object, Value lhs, Value rhs)
|
||||
ThrowCompletionOr<Value> instance_of(VM& vm, Value lhs, Value rhs)
|
||||
{
|
||||
auto& vm = global_object.vm();
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
if (!rhs.is_object())
|
||||
return vm.throw_completion<TypeError>(ErrorType::NotAnObject, rhs.to_string_without_side_effects());
|
||||
auto has_instance_method = TRY(rhs.get_method(global_object, *vm.well_known_symbol_has_instance()));
|
||||
auto has_instance_method = TRY(rhs.get_method(vm, *vm.well_known_symbol_has_instance()));
|
||||
if (has_instance_method) {
|
||||
auto has_instance_result = TRY(call(global_object, *has_instance_method, rhs, lhs));
|
||||
return Value(has_instance_result.to_boolean());
|
||||
}
|
||||
if (!rhs.is_function())
|
||||
return vm.throw_completion<TypeError>(ErrorType::NotAFunction, rhs.to_string_without_side_effects());
|
||||
return TRY(ordinary_has_instance(global_object, lhs, rhs));
|
||||
return TRY(ordinary_has_instance(vm, lhs, rhs));
|
||||
}
|
||||
|
||||
// 7.3.22 OrdinaryHasInstance ( C, O ), https://tc39.es/ecma262/#sec-ordinaryhasinstance
|
||||
ThrowCompletionOr<Value> ordinary_has_instance(GlobalObject& global_object, Value lhs, Value rhs)
|
||||
ThrowCompletionOr<Value> ordinary_has_instance(VM& vm, Value lhs, Value rhs)
|
||||
{
|
||||
auto& vm = global_object.vm();
|
||||
if (!rhs.is_function())
|
||||
return Value(false);
|
||||
auto& rhs_function = rhs.as_function();
|
||||
|
||||
if (is<BoundFunction>(rhs_function)) {
|
||||
auto& bound_target = static_cast<BoundFunction const&>(rhs_function);
|
||||
return instance_of(global_object, lhs, Value(&bound_target.bound_target_function()));
|
||||
return instance_of(vm, lhs, Value(&bound_target.bound_target_function()));
|
||||
}
|
||||
|
||||
if (!lhs.is_object())
|
||||
|
@ -1393,7 +1371,7 @@ bool is_strictly_equal(Value lhs, Value rhs)
|
|||
}
|
||||
|
||||
// 7.2.14 IsLooselyEqual ( x, y ), https://tc39.es/ecma262/#sec-islooselyequal
|
||||
ThrowCompletionOr<bool> is_loosely_equal(GlobalObject& global_object, Value lhs, Value rhs)
|
||||
ThrowCompletionOr<bool> is_loosely_equal(VM& vm, Value lhs, Value rhs)
|
||||
{
|
||||
// 1. If Type(x) is the same as Type(y), then
|
||||
if (same_type_for_equality(lhs, rhs)) {
|
||||
|
@ -1421,47 +1399,47 @@ ThrowCompletionOr<bool> is_loosely_equal(GlobalObject& global_object, Value lhs,
|
|||
|
||||
// 5. If Type(x) is Number and Type(y) is String, return ! IsLooselyEqual(x, ! ToNumber(y)).
|
||||
if (lhs.is_number() && rhs.is_string())
|
||||
return is_loosely_equal(global_object, lhs, MUST(rhs.to_number(global_object)));
|
||||
return is_loosely_equal(vm, lhs, MUST(rhs.to_number(vm)));
|
||||
|
||||
// 6. If Type(x) is String and Type(y) is Number, return ! IsLooselyEqual(! ToNumber(x), y).
|
||||
if (lhs.is_string() && rhs.is_number())
|
||||
return is_loosely_equal(global_object, MUST(lhs.to_number(global_object)), rhs);
|
||||
return is_loosely_equal(vm, MUST(lhs.to_number(vm)), rhs);
|
||||
|
||||
// 7. If Type(x) is BigInt and Type(y) is String, then
|
||||
if (lhs.is_bigint() && rhs.is_string()) {
|
||||
// a. Let n be StringToBigInt(y).
|
||||
auto bigint = rhs.string_to_bigint(global_object);
|
||||
auto bigint = rhs.string_to_bigint(vm);
|
||||
|
||||
// b. If n is undefined, return false.
|
||||
if (!bigint.has_value())
|
||||
return false;
|
||||
|
||||
// c. Return ! IsLooselyEqual(x, n).
|
||||
return is_loosely_equal(global_object, lhs, *bigint);
|
||||
return is_loosely_equal(vm, lhs, *bigint);
|
||||
}
|
||||
|
||||
// 8. If Type(x) is String and Type(y) is BigInt, return ! IsLooselyEqual(y, x).
|
||||
if (lhs.is_string() && rhs.is_bigint())
|
||||
return is_loosely_equal(global_object, rhs, lhs);
|
||||
return is_loosely_equal(vm, rhs, lhs);
|
||||
|
||||
// 9. If Type(x) is Boolean, return ! IsLooselyEqual(! ToNumber(x), y).
|
||||
if (lhs.is_boolean())
|
||||
return is_loosely_equal(global_object, MUST(lhs.to_number(global_object)), rhs);
|
||||
return is_loosely_equal(vm, MUST(lhs.to_number(vm)), rhs);
|
||||
|
||||
// 10. If Type(y) is Boolean, return ! IsLooselyEqual(x, ! ToNumber(y)).
|
||||
if (rhs.is_boolean())
|
||||
return is_loosely_equal(global_object, lhs, MUST(rhs.to_number(global_object)));
|
||||
return is_loosely_equal(vm, lhs, MUST(rhs.to_number(vm)));
|
||||
|
||||
// 11. If Type(x) is either String, Number, BigInt, or Symbol and Type(y) is Object, return ! IsLooselyEqual(x, ? ToPrimitive(y)).
|
||||
if ((lhs.is_string() || lhs.is_number() || lhs.is_bigint() || lhs.is_symbol()) && rhs.is_object()) {
|
||||
auto rhs_primitive = TRY(rhs.to_primitive(global_object));
|
||||
return is_loosely_equal(global_object, lhs, rhs_primitive);
|
||||
auto rhs_primitive = TRY(rhs.to_primitive(vm));
|
||||
return is_loosely_equal(vm, lhs, rhs_primitive);
|
||||
}
|
||||
|
||||
// 12. If Type(x) is Object and Type(y) is either String, Number, BigInt, or Symbol, return ! IsLooselyEqual(? ToPrimitive(x), y).
|
||||
if (lhs.is_object() && (rhs.is_string() || rhs.is_number() || rhs.is_bigint() || rhs.is_symbol())) {
|
||||
auto lhs_primitive = TRY(lhs.to_primitive(global_object));
|
||||
return is_loosely_equal(global_object, lhs_primitive, rhs);
|
||||
auto lhs_primitive = TRY(lhs.to_primitive(vm));
|
||||
return is_loosely_equal(vm, lhs_primitive, rhs);
|
||||
}
|
||||
|
||||
// 13. If Type(x) is BigInt and Type(y) is Number, or if Type(x) is Number and Type(y) is BigInt, then
|
||||
|
@ -1474,9 +1452,9 @@ ThrowCompletionOr<bool> is_loosely_equal(GlobalObject& global_object, Value lhs,
|
|||
if ((lhs.is_number() && !lhs.is_integral_number()) || (rhs.is_number() && !rhs.is_integral_number()))
|
||||
return false;
|
||||
if (lhs.is_number())
|
||||
return Crypto::SignedBigInteger { MUST(lhs.to_i32(global_object)) } == rhs.as_bigint().big_integer();
|
||||
return Crypto::SignedBigInteger { MUST(lhs.to_i32(vm)) } == rhs.as_bigint().big_integer();
|
||||
else
|
||||
return Crypto::SignedBigInteger { MUST(rhs.to_i32(global_object)) } == lhs.as_bigint().big_integer();
|
||||
return Crypto::SignedBigInteger { MUST(rhs.to_i32(vm)) } == lhs.as_bigint().big_integer();
|
||||
}
|
||||
|
||||
// 14. Return false.
|
||||
|
@ -1484,17 +1462,17 @@ ThrowCompletionOr<bool> is_loosely_equal(GlobalObject& global_object, Value lhs,
|
|||
}
|
||||
|
||||
// 7.2.13 IsLessThan ( x, y, LeftFirst ), https://tc39.es/ecma262/#sec-islessthan
|
||||
ThrowCompletionOr<TriState> is_less_than(GlobalObject& global_object, Value lhs, Value rhs, bool left_first)
|
||||
ThrowCompletionOr<TriState> is_less_than(VM& vm, Value lhs, Value rhs, bool left_first)
|
||||
{
|
||||
Value x_primitive;
|
||||
Value y_primitive;
|
||||
|
||||
if (left_first) {
|
||||
x_primitive = TRY(lhs.to_primitive(global_object, Value::PreferredType::Number));
|
||||
y_primitive = TRY(rhs.to_primitive(global_object, Value::PreferredType::Number));
|
||||
x_primitive = TRY(lhs.to_primitive(vm, Value::PreferredType::Number));
|
||||
y_primitive = TRY(rhs.to_primitive(vm, Value::PreferredType::Number));
|
||||
} else {
|
||||
y_primitive = TRY(lhs.to_primitive(global_object, Value::PreferredType::Number));
|
||||
x_primitive = TRY(rhs.to_primitive(global_object, Value::PreferredType::Number));
|
||||
y_primitive = TRY(lhs.to_primitive(vm, Value::PreferredType::Number));
|
||||
x_primitive = TRY(rhs.to_primitive(vm, Value::PreferredType::Number));
|
||||
}
|
||||
|
||||
if (x_primitive.is_string() && y_primitive.is_string()) {
|
||||
|
@ -1524,7 +1502,7 @@ ThrowCompletionOr<TriState> is_less_than(GlobalObject& global_object, Value lhs,
|
|||
}
|
||||
|
||||
if (x_primitive.is_bigint() && y_primitive.is_string()) {
|
||||
auto y_bigint = y_primitive.string_to_bigint(global_object);
|
||||
auto y_bigint = y_primitive.string_to_bigint(vm);
|
||||
if (!y_bigint.has_value())
|
||||
return TriState::Unknown;
|
||||
|
||||
|
@ -1534,7 +1512,7 @@ ThrowCompletionOr<TriState> is_less_than(GlobalObject& global_object, Value lhs,
|
|||
}
|
||||
|
||||
if (x_primitive.is_string() && y_primitive.is_bigint()) {
|
||||
auto x_bigint = x_primitive.string_to_bigint(global_object);
|
||||
auto x_bigint = x_primitive.string_to_bigint(vm);
|
||||
if (!x_bigint.has_value())
|
||||
return TriState::Unknown;
|
||||
|
||||
|
@ -1543,8 +1521,8 @@ ThrowCompletionOr<TriState> is_less_than(GlobalObject& global_object, Value lhs,
|
|||
return TriState::False;
|
||||
}
|
||||
|
||||
auto x_numeric = TRY(x_primitive.to_numeric(global_object));
|
||||
auto y_numeric = TRY(y_primitive.to_numeric(global_object));
|
||||
auto x_numeric = TRY(x_primitive.to_numeric(vm));
|
||||
auto y_numeric = TRY(y_primitive.to_numeric(vm));
|
||||
|
||||
if (x_numeric.is_nan() || y_numeric.is_nan())
|
||||
return TriState::Unknown;
|
||||
|
@ -1574,12 +1552,12 @@ ThrowCompletionOr<TriState> is_less_than(GlobalObject& global_object, Value lhs,
|
|||
bool x_lower_than_y;
|
||||
if (x_numeric.is_number()) {
|
||||
x_lower_than_y = x_numeric.is_integral_number()
|
||||
? Crypto::SignedBigInteger { MUST(x_numeric.to_i32(global_object)) } < y_numeric.as_bigint().big_integer()
|
||||
: (Crypto::SignedBigInteger { MUST(x_numeric.to_i32(global_object)) } < y_numeric.as_bigint().big_integer() || Crypto::SignedBigInteger { MUST(x_numeric.to_i32(global_object)) + 1 } < y_numeric.as_bigint().big_integer());
|
||||
? Crypto::SignedBigInteger { MUST(x_numeric.to_i32(vm)) } < y_numeric.as_bigint().big_integer()
|
||||
: (Crypto::SignedBigInteger { MUST(x_numeric.to_i32(vm)) } < y_numeric.as_bigint().big_integer() || Crypto::SignedBigInteger { MUST(x_numeric.to_i32(vm)) + 1 } < y_numeric.as_bigint().big_integer());
|
||||
} else {
|
||||
x_lower_than_y = y_numeric.is_integral_number()
|
||||
? x_numeric.as_bigint().big_integer() < Crypto::SignedBigInteger { MUST(y_numeric.to_i32(global_object)) }
|
||||
: (x_numeric.as_bigint().big_integer() < Crypto::SignedBigInteger { MUST(y_numeric.to_i32(global_object)) } || x_numeric.as_bigint().big_integer() < Crypto::SignedBigInteger { MUST(y_numeric.to_i32(global_object)) + 1 });
|
||||
? x_numeric.as_bigint().big_integer() < Crypto::SignedBigInteger { MUST(y_numeric.to_i32(vm)) }
|
||||
: (x_numeric.as_bigint().big_integer() < Crypto::SignedBigInteger { MUST(y_numeric.to_i32(vm)) } || x_numeric.as_bigint().big_integer() < Crypto::SignedBigInteger { MUST(y_numeric.to_i32(vm)) + 1 });
|
||||
}
|
||||
if (x_lower_than_y)
|
||||
return TriState::True;
|
||||
|
@ -1588,10 +1566,11 @@ ThrowCompletionOr<TriState> is_less_than(GlobalObject& global_object, Value lhs,
|
|||
}
|
||||
|
||||
// 7.3.21 Invoke ( V, P [ , argumentsList ] ), https://tc39.es/ecma262/#sec-invoke
|
||||
ThrowCompletionOr<Value> Value::invoke_internal(GlobalObject& global_object, PropertyKey const& property_key, Optional<MarkedVector<Value>> arguments)
|
||||
ThrowCompletionOr<Value> Value::invoke_internal(VM& vm, PropertyKey const& property_key, Optional<MarkedVector<Value>> arguments)
|
||||
{
|
||||
auto& vm = global_object.vm();
|
||||
auto property = TRY(get(global_object, property_key));
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
auto property = TRY(get(vm, property_key));
|
||||
if (!property.is_function())
|
||||
return vm.throw_completion<TypeError>(ErrorType::NotAFunction, property.to_string_without_side_effects());
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2020-2021, Linus Groh <linusg@serenityos.org>
|
||||
* Copyright (c) 2020-2022, Linus Groh <linusg@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -141,10 +141,10 @@ public:
|
|||
bool is_bigint() const { return m_value.tag == BIGINT_TAG; };
|
||||
bool is_nullish() const { return (m_value.tag & IS_NULLISH_EXTRACT_PATTERN) == IS_NULLISH_PATTERN; }
|
||||
bool is_cell() const { return (m_value.tag & IS_CELL_PATTERN) == IS_CELL_PATTERN; }
|
||||
ThrowCompletionOr<bool> is_array(GlobalObject&) const;
|
||||
ThrowCompletionOr<bool> is_array(VM&) const;
|
||||
bool is_function() const;
|
||||
bool is_constructor() const;
|
||||
ThrowCompletionOr<bool> is_regexp(GlobalObject&) const;
|
||||
ThrowCompletionOr<bool> is_regexp(VM&) const;
|
||||
|
||||
bool is_nan() const
|
||||
{
|
||||
|
@ -353,35 +353,35 @@ public:
|
|||
|
||||
u64 encoded() const { return m_value.encoded; }
|
||||
|
||||
ThrowCompletionOr<String> to_string(GlobalObject&) const;
|
||||
ThrowCompletionOr<Utf16String> to_utf16_string(GlobalObject&) const;
|
||||
ThrowCompletionOr<PrimitiveString*> to_primitive_string(GlobalObject&);
|
||||
ThrowCompletionOr<Value> to_primitive(GlobalObject&, PreferredType preferred_type = PreferredType::Default) const;
|
||||
ThrowCompletionOr<Object*> to_object(GlobalObject&) const;
|
||||
ThrowCompletionOr<Value> to_numeric(GlobalObject&) const;
|
||||
ThrowCompletionOr<Value> to_number(GlobalObject&) const;
|
||||
ThrowCompletionOr<BigInt*> to_bigint(GlobalObject&) const;
|
||||
ThrowCompletionOr<i64> to_bigint_int64(GlobalObject&) const;
|
||||
ThrowCompletionOr<u64> to_bigint_uint64(GlobalObject&) const;
|
||||
ThrowCompletionOr<double> to_double(GlobalObject&) const;
|
||||
ThrowCompletionOr<PropertyKey> to_property_key(GlobalObject&) const;
|
||||
ThrowCompletionOr<i32> to_i32(GlobalObject& global_object) const;
|
||||
ThrowCompletionOr<u32> to_u32(GlobalObject&) const;
|
||||
ThrowCompletionOr<i16> to_i16(GlobalObject&) const;
|
||||
ThrowCompletionOr<u16> to_u16(GlobalObject&) const;
|
||||
ThrowCompletionOr<i8> to_i8(GlobalObject&) const;
|
||||
ThrowCompletionOr<u8> to_u8(GlobalObject&) const;
|
||||
ThrowCompletionOr<u8> to_u8_clamp(GlobalObject&) const;
|
||||
ThrowCompletionOr<size_t> to_length(GlobalObject&) const;
|
||||
ThrowCompletionOr<size_t> to_index(GlobalObject&) const;
|
||||
ThrowCompletionOr<double> to_integer_or_infinity(GlobalObject&) const;
|
||||
ThrowCompletionOr<String> to_string(VM&) const;
|
||||
ThrowCompletionOr<Utf16String> to_utf16_string(VM&) const;
|
||||
ThrowCompletionOr<PrimitiveString*> to_primitive_string(VM&);
|
||||
ThrowCompletionOr<Value> to_primitive(VM&, PreferredType preferred_type = PreferredType::Default) const;
|
||||
ThrowCompletionOr<Object*> to_object(VM&) const;
|
||||
ThrowCompletionOr<Value> to_numeric(VM&) const;
|
||||
ThrowCompletionOr<Value> to_number(VM&) const;
|
||||
ThrowCompletionOr<BigInt*> to_bigint(VM&) const;
|
||||
ThrowCompletionOr<i64> to_bigint_int64(VM&) const;
|
||||
ThrowCompletionOr<u64> to_bigint_uint64(VM&) const;
|
||||
ThrowCompletionOr<double> to_double(VM&) const;
|
||||
ThrowCompletionOr<PropertyKey> to_property_key(VM&) const;
|
||||
ThrowCompletionOr<i32> to_i32(VM&) const;
|
||||
ThrowCompletionOr<u32> to_u32(VM&) const;
|
||||
ThrowCompletionOr<i16> to_i16(VM&) const;
|
||||
ThrowCompletionOr<u16> to_u16(VM&) const;
|
||||
ThrowCompletionOr<i8> to_i8(VM&) const;
|
||||
ThrowCompletionOr<u8> to_u8(VM&) const;
|
||||
ThrowCompletionOr<u8> to_u8_clamp(VM&) const;
|
||||
ThrowCompletionOr<size_t> to_length(VM&) const;
|
||||
ThrowCompletionOr<size_t> to_index(VM&) const;
|
||||
ThrowCompletionOr<double> to_integer_or_infinity(VM&) const;
|
||||
bool to_boolean() const;
|
||||
|
||||
ThrowCompletionOr<Value> get(GlobalObject&, PropertyKey const&) const;
|
||||
ThrowCompletionOr<FunctionObject*> get_method(GlobalObject&, PropertyKey const&) const;
|
||||
ThrowCompletionOr<Value> get(VM&, PropertyKey const&) const;
|
||||
ThrowCompletionOr<FunctionObject*> get_method(VM&, PropertyKey const&) const;
|
||||
|
||||
String to_string_without_side_effects() const;
|
||||
Optional<BigInt*> string_to_bigint(GlobalObject& global_object) const;
|
||||
Optional<BigInt*> string_to_bigint(VM&) const;
|
||||
|
||||
Value value_or(Value fallback) const
|
||||
{
|
||||
|
@ -395,7 +395,7 @@ public:
|
|||
bool operator==(Value const&) const;
|
||||
|
||||
template<typename... Args>
|
||||
[[nodiscard]] ALWAYS_INLINE ThrowCompletionOr<Value> invoke(GlobalObject& global_object, PropertyKey const& property_key, Args... args);
|
||||
[[nodiscard]] ALWAYS_INLINE ThrowCompletionOr<Value> invoke(VM&, PropertyKey const& property_key, Args... args);
|
||||
|
||||
private:
|
||||
Value(u64 tag, u64 val)
|
||||
|
@ -447,9 +447,9 @@ private:
|
|||
return reinterpret_cast<PointerType*>(ptr_val);
|
||||
}
|
||||
|
||||
[[nodiscard]] ThrowCompletionOr<Value> invoke_internal(GlobalObject& global_object, PropertyKey const&, Optional<MarkedVector<Value>> arguments);
|
||||
[[nodiscard]] ThrowCompletionOr<Value> invoke_internal(VM&, PropertyKey const&, Optional<MarkedVector<Value>> arguments);
|
||||
|
||||
ThrowCompletionOr<i32> to_i32_slow_case(GlobalObject&) const;
|
||||
ThrowCompletionOr<i32> to_i32_slow_case(VM&) const;
|
||||
|
||||
union {
|
||||
double as_double;
|
||||
|
@ -462,11 +462,11 @@ private:
|
|||
|
||||
friend Value js_undefined();
|
||||
friend Value js_null();
|
||||
friend ThrowCompletionOr<Value> greater_than(GlobalObject&, Value lhs, Value rhs);
|
||||
friend ThrowCompletionOr<Value> greater_than_equals(GlobalObject&, Value lhs, Value rhs);
|
||||
friend ThrowCompletionOr<Value> less_than(GlobalObject&, Value lhs, Value rhs);
|
||||
friend ThrowCompletionOr<Value> less_than_equals(GlobalObject&, Value lhs, Value rhs);
|
||||
friend ThrowCompletionOr<Value> add(GlobalObject&, Value lhs, Value rhs);
|
||||
friend ThrowCompletionOr<Value> greater_than(VM&, Value lhs, Value rhs);
|
||||
friend ThrowCompletionOr<Value> greater_than_equals(VM&, Value lhs, Value rhs);
|
||||
friend ThrowCompletionOr<Value> less_than(VM&, Value lhs, Value rhs);
|
||||
friend ThrowCompletionOr<Value> less_than_equals(VM&, Value lhs, Value rhs);
|
||||
friend ThrowCompletionOr<Value> add(VM&, Value lhs, Value rhs);
|
||||
friend bool same_value_non_numeric(Value lhs, Value rhs);
|
||||
};
|
||||
|
||||
|
@ -501,35 +501,35 @@ inline void Cell::Visitor::visit(Value value)
|
|||
visit_impl(value.as_cell());
|
||||
}
|
||||
|
||||
ThrowCompletionOr<Value> greater_than(GlobalObject&, Value lhs, Value rhs);
|
||||
ThrowCompletionOr<Value> greater_than_equals(GlobalObject&, Value lhs, Value rhs);
|
||||
ThrowCompletionOr<Value> less_than(GlobalObject&, Value lhs, Value rhs);
|
||||
ThrowCompletionOr<Value> less_than_equals(GlobalObject&, Value lhs, Value rhs);
|
||||
ThrowCompletionOr<Value> bitwise_and(GlobalObject&, Value lhs, Value rhs);
|
||||
ThrowCompletionOr<Value> bitwise_or(GlobalObject&, Value lhs, Value rhs);
|
||||
ThrowCompletionOr<Value> bitwise_xor(GlobalObject&, Value lhs, Value rhs);
|
||||
ThrowCompletionOr<Value> bitwise_not(GlobalObject&, Value);
|
||||
ThrowCompletionOr<Value> unary_plus(GlobalObject&, Value);
|
||||
ThrowCompletionOr<Value> unary_minus(GlobalObject&, Value);
|
||||
ThrowCompletionOr<Value> left_shift(GlobalObject&, Value lhs, Value rhs);
|
||||
ThrowCompletionOr<Value> right_shift(GlobalObject&, Value lhs, Value rhs);
|
||||
ThrowCompletionOr<Value> unsigned_right_shift(GlobalObject&, Value lhs, Value rhs);
|
||||
ThrowCompletionOr<Value> add(GlobalObject&, Value lhs, Value rhs);
|
||||
ThrowCompletionOr<Value> sub(GlobalObject&, Value lhs, Value rhs);
|
||||
ThrowCompletionOr<Value> mul(GlobalObject&, Value lhs, Value rhs);
|
||||
ThrowCompletionOr<Value> div(GlobalObject&, Value lhs, Value rhs);
|
||||
ThrowCompletionOr<Value> mod(GlobalObject&, Value lhs, Value rhs);
|
||||
ThrowCompletionOr<Value> exp(GlobalObject&, Value lhs, Value rhs);
|
||||
ThrowCompletionOr<Value> in(GlobalObject&, Value lhs, Value rhs);
|
||||
ThrowCompletionOr<Value> instance_of(GlobalObject&, Value lhs, Value rhs);
|
||||
ThrowCompletionOr<Value> ordinary_has_instance(GlobalObject&, Value lhs, Value rhs);
|
||||
ThrowCompletionOr<Value> greater_than(VM&, Value lhs, Value rhs);
|
||||
ThrowCompletionOr<Value> greater_than_equals(VM&, Value lhs, Value rhs);
|
||||
ThrowCompletionOr<Value> less_than(VM&, Value lhs, Value rhs);
|
||||
ThrowCompletionOr<Value> less_than_equals(VM&, Value lhs, Value rhs);
|
||||
ThrowCompletionOr<Value> bitwise_and(VM&, Value lhs, Value rhs);
|
||||
ThrowCompletionOr<Value> bitwise_or(VM&, Value lhs, Value rhs);
|
||||
ThrowCompletionOr<Value> bitwise_xor(VM&, Value lhs, Value rhs);
|
||||
ThrowCompletionOr<Value> bitwise_not(VM&, Value);
|
||||
ThrowCompletionOr<Value> unary_plus(VM&, Value);
|
||||
ThrowCompletionOr<Value> unary_minus(VM&, Value);
|
||||
ThrowCompletionOr<Value> left_shift(VM&, Value lhs, Value rhs);
|
||||
ThrowCompletionOr<Value> right_shift(VM&, Value lhs, Value rhs);
|
||||
ThrowCompletionOr<Value> unsigned_right_shift(VM&, Value lhs, Value rhs);
|
||||
ThrowCompletionOr<Value> add(VM&, Value lhs, Value rhs);
|
||||
ThrowCompletionOr<Value> sub(VM&, Value lhs, Value rhs);
|
||||
ThrowCompletionOr<Value> mul(VM&, Value lhs, Value rhs);
|
||||
ThrowCompletionOr<Value> div(VM&, Value lhs, Value rhs);
|
||||
ThrowCompletionOr<Value> mod(VM&, Value lhs, Value rhs);
|
||||
ThrowCompletionOr<Value> exp(VM&, Value lhs, Value rhs);
|
||||
ThrowCompletionOr<Value> in(VM&, Value lhs, Value rhs);
|
||||
ThrowCompletionOr<Value> instance_of(VM&, Value lhs, Value rhs);
|
||||
ThrowCompletionOr<Value> ordinary_has_instance(VM&, Value lhs, Value rhs);
|
||||
|
||||
ThrowCompletionOr<bool> is_loosely_equal(GlobalObject&, Value lhs, Value rhs);
|
||||
ThrowCompletionOr<bool> is_loosely_equal(VM&, Value lhs, Value rhs);
|
||||
bool is_strictly_equal(Value lhs, Value rhs);
|
||||
bool same_value(Value lhs, Value rhs);
|
||||
bool same_value_zero(Value lhs, Value rhs);
|
||||
bool same_value_non_numeric(Value lhs, Value rhs);
|
||||
ThrowCompletionOr<TriState> is_less_than(GlobalObject&, Value lhs, Value rhs, bool left_first);
|
||||
ThrowCompletionOr<TriState> is_less_than(VM&, Value lhs, Value rhs, bool left_first);
|
||||
|
||||
double to_integer_or_infinity(double);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue