diff options
author | Linus Groh <mail@linusgroh.de> | 2023-04-13 15:26:41 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-04-14 09:59:29 +0200 |
commit | f345f72b5580428da62adcad1bbc65ba0bf58095 (patch) | |
tree | 886b27a4ecaee779f7d3e6c8520206abd4b1dd44 /Userland/Libraries | |
parent | e79f5b6e857d8f6b79eec5aad3d524237ea0a23b (diff) | |
download | serenity-f345f72b5580428da62adcad1bbc65ba0bf58095.zip |
LibJS: Port Value::to_object() to NonnullGCPtr
Diffstat (limited to 'Userland/Libraries')
24 files changed, 200 insertions, 200 deletions
diff --git a/Userland/Libraries/LibJS/AST.cpp b/Userland/Libraries/LibJS/AST.cpp index c21b6617f6..4a5c4f5626 100644 --- a/Userland/Libraries/LibJS/AST.cpp +++ b/Userland/Libraries/LibJS/AST.cpp @@ -619,13 +619,13 @@ Completion WithStatement::execute(Interpreter& interpreter) const auto value = TRY(m_object->execute(interpreter)).release_value(); // 2. Let obj be ? ToObject(? GetValue(value)). - auto* object = TRY(value.to_object(vm)); + auto object = TRY(value.to_object(vm)); // 3. Let oldEnv be the running execution context's LexicalEnvironment. auto old_environment = vm.running_execution_context().lexical_environment; // 4. Let newEnv be NewObjectEnvironment(obj, true, oldEnv). - auto new_environment = new_object_environment(*object, true, old_environment); + auto new_environment = new_object_environment(object, true, old_environment); // 5. Set the running execution context's LexicalEnvironment to newEnv. vm.running_execution_context().lexical_environment = new_environment; @@ -1155,7 +1155,7 @@ Completion ForInStatement::loop_evaluation(Interpreter& interpreter, Vector<Depr } // b. Let obj be ! ToObject(exprValue). - auto* object = MUST(rhs_result.to_object(vm)); + auto object = MUST(rhs_result.to_object(vm)); // 14.7.5.7 ForIn/OfBodyEvaluation ( lhs, stmt, iteratorRecord, iterationKind, lhsKind, labelSet [ , iteratorKind ] ), https://tc39.es/ecma262/#sec-runtime-semantics-forin-div-ofbodyevaluation-lhs-stmt-iterator-lhskind-labelset diff --git a/Userland/Libraries/LibJS/Bytecode/Op.cpp b/Userland/Libraries/LibJS/Bytecode/Op.cpp index 2b6d179fd7..fee29615e8 100644 --- a/Userland/Libraries/LibJS/Bytecode/Op.cpp +++ b/Userland/Libraries/LibJS/Bytecode/Op.cpp @@ -1,6 +1,6 @@ /* * Copyright (c) 2021, Andreas Kling <kling@serenityos.org> - * Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org> + * Copyright (c) 2021-2023, Linus Groh <linusg@serenityos.org> * Copyright (c) 2021, Gunnar Beutner <gbeutner@serenityos.org> * * SPDX-License-Identifier: BSD-2-Clause @@ -271,7 +271,7 @@ ThrowCompletionOr<void> IteratorToArray::execute_impl(Bytecode::Interpreter& int { auto& vm = interpreter.vm(); auto iterator_object = TRY(interpreter.accumulator().to_object(vm)); - auto iterator = object_to_iterator(vm, *iterator_object); + auto iterator = object_to_iterator(vm, iterator_object); auto array = MUST(Array::create(interpreter.realm(), 0)); size_t index = 0; @@ -340,7 +340,7 @@ ThrowCompletionOr<void> CopyObjectExcludingProperties::execute_impl(Bytecode::In auto& vm = interpreter.vm(); auto& realm = *vm.current_realm(); - auto* from_object = TRY(interpreter.reg(m_from_object).to_object(vm)); + auto from_object = TRY(interpreter.reg(m_from_object).to_object(vm)); auto to_object = Object::create(realm, realm.intrinsics().object_prototype()); @@ -431,7 +431,7 @@ ThrowCompletionOr<void> EnterObjectEnvironment::execute_impl(Bytecode::Interpret auto& old_environment = vm.running_execution_context().lexical_environment; interpreter.saved_lexical_environment_stack().append(old_environment); auto object = TRY(interpreter.accumulator().to_object(vm)); - vm.running_execution_context().lexical_environment = new_object_environment(*object, true, old_environment); + vm.running_execution_context().lexical_environment = new_object_environment(object, true, old_environment); return {}; } @@ -492,7 +492,7 @@ ThrowCompletionOr<void> SetVariable::execute_impl(Bytecode::Interpreter& interpr ThrowCompletionOr<void> GetById::execute_impl(Bytecode::Interpreter& interpreter) const { auto& vm = interpreter.vm(); - auto* object = TRY(interpreter.accumulator().to_object(vm)); + auto object = TRY(interpreter.accumulator().to_object(vm)); interpreter.accumulator() = TRY(object->get(interpreter.current_executable().get_identifier(m_property))); return {}; } @@ -500,7 +500,7 @@ ThrowCompletionOr<void> GetById::execute_impl(Bytecode::Interpreter& interpreter ThrowCompletionOr<void> PutById::execute_impl(Bytecode::Interpreter& interpreter) const { auto& vm = interpreter.vm(); - auto* object = TRY(interpreter.reg(m_base).to_object(vm)); + auto object = TRY(interpreter.reg(m_base).to_object(vm)); PropertyKey name = interpreter.current_executable().get_identifier(m_property); auto value = interpreter.accumulator(); return put_by_property_key(object, value, name, interpreter, m_kind); @@ -509,7 +509,7 @@ ThrowCompletionOr<void> PutById::execute_impl(Bytecode::Interpreter& interpreter ThrowCompletionOr<void> DeleteById::execute_impl(Bytecode::Interpreter& interpreter) const { auto& vm = interpreter.vm(); - auto* object = TRY(interpreter.accumulator().to_object(vm)); + auto object = TRY(interpreter.accumulator().to_object(vm)); auto const& identifier = interpreter.current_executable().get_identifier(m_property); bool strict = vm.in_strict_mode(); auto reference = Reference { object, identifier, {}, strict }; @@ -854,7 +854,7 @@ void Yield::replace_references_impl(BasicBlock const& from, BasicBlock const& to ThrowCompletionOr<void> GetByValue::execute_impl(Bytecode::Interpreter& interpreter) const { auto& vm = interpreter.vm(); - auto* object = TRY(interpreter.reg(m_base).to_object(vm)); + auto object = TRY(interpreter.reg(m_base).to_object(vm)); auto property_key = TRY(interpreter.accumulator().to_property_key(vm)); @@ -865,7 +865,7 @@ ThrowCompletionOr<void> GetByValue::execute_impl(Bytecode::Interpreter& interpre ThrowCompletionOr<void> PutByValue::execute_impl(Bytecode::Interpreter& interpreter) const { auto& vm = interpreter.vm(); - auto* object = TRY(interpreter.reg(m_base).to_object(vm)); + auto object = TRY(interpreter.reg(m_base).to_object(vm)); auto property_key = TRY(interpreter.reg(m_property).to_property_key(vm)); return put_by_property_key(object, interpreter.accumulator(), property_key, interpreter, m_kind); @@ -874,7 +874,7 @@ ThrowCompletionOr<void> PutByValue::execute_impl(Bytecode::Interpreter& interpre ThrowCompletionOr<void> DeleteByValue::execute_impl(Bytecode::Interpreter& interpreter) const { auto& vm = interpreter.vm(); - auto* object = TRY(interpreter.reg(m_base).to_object(vm)); + auto object = TRY(interpreter.reg(m_base).to_object(vm)); auto property_key = TRY(interpreter.accumulator().to_property_key(vm)); bool strict = vm.in_strict_mode(); auto reference = Reference { object, property_key, {}, strict }; @@ -917,14 +917,14 @@ ThrowCompletionOr<void> GetObjectPropertyIterator::execute_impl(Bytecode::Interp // Invariant 3 effectively allows the implementation to ignore newly added keys, and we do so (similar to other implementations). // Invariants 1 and 6 through 9 are implemented in `enumerable_own_property_names`, which implements the EnumerableOwnPropertyNames AO. auto& vm = interpreter.vm(); - auto* object = TRY(interpreter.accumulator().to_object(vm)); + auto object = TRY(interpreter.accumulator().to_object(vm)); // Note: While the spec doesn't explicitly require these to be ordered, it says that the values should be retrieved via OwnPropertyKeys, // so we just keep the order consistent anyway. OrderedHashTable<PropertyKey> properties; - HashTable<Object*> seen_objects; + HashTable<NonnullGCPtr<Object>> seen_objects; // Collect all keys immediately (invariant no. 5) - for (auto* object_to_check = object; object_to_check && !seen_objects.contains(object_to_check); object_to_check = TRY(object_to_check->internal_get_prototype_of())) { - seen_objects.set(object_to_check); + for (auto object_to_check = GCPtr { object.ptr() }; object_to_check && !seen_objects.contains(*object_to_check); object_to_check = TRY(object_to_check->internal_get_prototype_of())) { + seen_objects.set(*object_to_check); for (auto& key : TRY(object_to_check->enumerable_own_property_names(Object::PropertyKind::Key))) { properties.set(TRY(PropertyKey::from_value(vm, key))); } @@ -981,8 +981,8 @@ ThrowCompletionOr<void> GetObjectPropertyIterator::execute_impl(Bytecode::Interp ThrowCompletionOr<void> IteratorClose::execute_impl(Bytecode::Interpreter& interpreter) const { auto& vm = interpreter.vm(); - auto* iterator_object = TRY(interpreter.accumulator().to_object(vm)); - auto iterator = object_to_iterator(vm, *iterator_object); + auto iterator_object = TRY(interpreter.accumulator().to_object(vm)); + auto iterator = object_to_iterator(vm, iterator_object); // FIXME: Return the value of the resulting completion. (Note that m_completion_value can be empty!) TRY(iterator_close(vm, iterator, Completion { m_completion_type, m_completion_value, {} })); @@ -992,8 +992,8 @@ ThrowCompletionOr<void> IteratorClose::execute_impl(Bytecode::Interpreter& inter ThrowCompletionOr<void> IteratorNext::execute_impl(Bytecode::Interpreter& interpreter) const { auto& vm = interpreter.vm(); - auto* iterator_object = TRY(interpreter.accumulator().to_object(vm)); - auto iterator = object_to_iterator(vm, *iterator_object); + auto iterator_object = TRY(interpreter.accumulator().to_object(vm)); + auto iterator = object_to_iterator(vm, iterator_object); interpreter.accumulator() = TRY(iterator_next(vm, iterator)); return {}; @@ -1002,9 +1002,9 @@ ThrowCompletionOr<void> IteratorNext::execute_impl(Bytecode::Interpreter& interp ThrowCompletionOr<void> IteratorResultDone::execute_impl(Bytecode::Interpreter& interpreter) const { auto& vm = interpreter.vm(); - auto* iterator_result = TRY(interpreter.accumulator().to_object(vm)); + auto iterator_result = TRY(interpreter.accumulator().to_object(vm)); - auto complete = TRY(iterator_complete(vm, *iterator_result)); + auto complete = TRY(iterator_complete(vm, iterator_result)); interpreter.accumulator() = Value(complete); return {}; } @@ -1012,9 +1012,9 @@ ThrowCompletionOr<void> IteratorResultDone::execute_impl(Bytecode::Interpreter& ThrowCompletionOr<void> IteratorResultValue::execute_impl(Bytecode::Interpreter& interpreter) const { auto& vm = interpreter.vm(); - auto* iterator_result = TRY(interpreter.accumulator().to_object(vm)); + auto iterator_result = TRY(interpreter.accumulator().to_object(vm)); - interpreter.accumulator() = TRY(iterator_value(vm, *iterator_result)); + interpreter.accumulator() = TRY(iterator_value(vm, iterator_result)); return {}; } diff --git a/Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp b/Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp index 95b1efaaa8..4c96722975 100644 --- a/Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp @@ -236,10 +236,10 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayConstructor::from) // 6. NOTE: items is not an Iterable so assume it is an array-like object. // 7. Let arrayLike be ! ToObject(items). - auto* array_like = MUST(items.to_object(vm)); + auto array_like = MUST(items.to_object(vm)); // 8. Let len be ? LengthOfArrayLike(arrayLike). - auto length = TRY(length_of_array_like(vm, *array_like)); + auto length = TRY(length_of_array_like(vm, array_like)); GCPtr<Object> array; diff --git a/Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp b/Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp index 72c00bf416..fd3a9e4f1b 100644 --- a/Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp @@ -26,7 +26,7 @@ namespace JS { -static HashTable<Object*> s_array_join_seen_objects; +static HashTable<NonnullGCPtr<Object>> s_array_join_seen_objects; ArrayPrototype::ArrayPrototype(Realm& realm) : Array(realm.intrinsics().object_prototype()) @@ -152,8 +152,8 @@ static ThrowCompletionOr<Object*> array_species_create(VM& vm, Object& original_ // 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(vm)); - auto length = TRY(length_of_array_like(vm, *this_object)); + auto this_object = TRY(vm.this_value().to_object(vm)); + auto length = TRY(length_of_array_like(vm, this_object)); auto relative_index = TRY(vm.argument(0).to_integer_or_infinity(vm)); if (Value(relative_index).is_infinity()) return js_undefined(); @@ -172,9 +172,9 @@ 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(vm)); + auto this_object = TRY(vm.this_value().to_object(vm)); - auto* new_array = TRY(array_species_create(vm, *this_object, 0)); + auto* new_array = TRY(array_species_create(vm, this_object, 0)); size_t n = 0; @@ -230,8 +230,8 @@ 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(vm)); - auto length = TRY(length_of_array_like(vm, *this_object)); + auto this_object = TRY(vm.this_value().to_object(vm)); + auto length = TRY(length_of_array_like(vm, this_object)); auto relative_target = TRY(vm.argument(0).to_integer_or_infinity(vm)); @@ -298,7 +298,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::entries) { auto& realm = *vm.current_realm(); - auto* this_object = TRY(vm.this_value().to_object(vm)); + auto this_object = TRY(vm.this_value().to_object(vm)); return ArrayIterator::create(realm, this_object, Object::PropertyKind::KeyAndValue); } @@ -310,10 +310,10 @@ 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(vm)); + auto object = TRY(vm.this_value().to_object(vm)); // 2. Let len be ? LengthOfArrayLike(O). - auto length = TRY(length_of_array_like(vm, *object)); + auto length = TRY(length_of_array_like(vm, object)); // 3. If IsCallable(callbackfn) is false, throw a TypeError exception. if (!callback_function.is_function()) @@ -351,9 +351,9 @@ 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(vm)); + auto this_object = TRY(vm.this_value().to_object(vm)); - auto length = TRY(length_of_array_like(vm, *this_object)); + auto length = TRY(length_of_array_like(vm, this_object)); double relative_start = 0; double relative_end = length; @@ -396,17 +396,17 @@ 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(vm)); + auto object = TRY(vm.this_value().to_object(vm)); // 2. Let len be ? LengthOfArrayLike(O). - auto length = TRY(length_of_array_like(vm, *object)); + auto length = TRY(length_of_array_like(vm, object)); // 3. If IsCallable(callbackfn) is false, throw a TypeError exception. if (!callback_function.is_function()) return vm.throw_completion<TypeError>(ErrorType::NotAFunction, TRY_OR_THROW_OOM(vm, callback_function.to_string_without_side_effects())); // 4. Let A be ? ArraySpeciesCreate(O, 0). - auto* array = TRY(array_species_create(vm, *object, 0)); + auto* array = TRY(array_species_create(vm, object, 0)); // 5. Let k be 0. size_t k = 0; @@ -454,10 +454,10 @@ 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(vm)); + auto object = TRY(vm.this_value().to_object(vm)); // 2. Let len be ? LengthOfArrayLike(O). - auto length = TRY(length_of_array_like(vm, *object)); + auto length = TRY(length_of_array_like(vm, object)); // 3. If IsCallable(predicate) is false, throw a TypeError exception. if (!predicate.is_function()) @@ -493,10 +493,10 @@ 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(vm)); + auto object = TRY(vm.this_value().to_object(vm)); // 2. Let len be ? LengthOfArrayLike(O). - auto length = TRY(length_of_array_like(vm, *object)); + auto length = TRY(length_of_array_like(vm, object)); // 3. If IsCallable(predicate) is false, throw a TypeError exception. if (!predicate.is_function()) @@ -532,10 +532,10 @@ 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(vm)); + auto object = TRY(vm.this_value().to_object(vm)); // 2. Let len be ? LengthOfArrayLike(O). - auto length = TRY(length_of_array_like(vm, *object)); + auto length = TRY(length_of_array_like(vm, object)); // 3. If IsCallable(predicate) is false, throw a TypeError exception. if (!predicate.is_function()) @@ -571,10 +571,10 @@ 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(vm)); + auto object = TRY(vm.this_value().to_object(vm)); // 2. Let len be ? LengthOfArrayLike(O). - auto length = TRY(length_of_array_like(vm, *object)); + auto length = TRY(length_of_array_like(vm, object)); // 3. If IsCallable(predicate) is false, throw a TypeError exception. if (!predicate.is_function()) @@ -640,9 +640,9 @@ static ThrowCompletionOr<size_t> flatten_into_array(VM& vm, Object& new_array, O // 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(vm)); + auto this_object = TRY(vm.this_value().to_object(vm)); - auto length = TRY(length_of_array_like(vm, *this_object)); + auto length = TRY(length_of_array_like(vm, this_object)); double depth = 1; if (!vm.argument(0).is_undefined()) { @@ -650,9 +650,9 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::flat) depth = max(depth_num, 0.0); } - auto* new_array = TRY(array_species_create(vm, *this_object, 0)); + auto* new_array = TRY(array_species_create(vm, this_object, 0)); - TRY(flatten_into_array(vm, *new_array, *this_object, length, 0, depth)); + TRY(flatten_into_array(vm, *new_array, this_object, length, 0, depth)); return new_array; } @@ -663,20 +663,20 @@ 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(vm)); + auto object = TRY(vm.this_value().to_object(vm)); // 2. Let sourceLen be ? LengthOfArrayLike(O). - auto source_length = TRY(length_of_array_like(vm, *object)); + auto source_length = TRY(length_of_array_like(vm, object)); // 3. If IsCallable(mapperFunction) is false, throw a TypeError exception. if (!mapper_function.is_function()) return vm.throw_completion<TypeError>(ErrorType::NotAFunction, TRY_OR_THROW_OOM(vm, mapper_function.to_string_without_side_effects())); // 4. Let A be ? ArraySpeciesCreate(O, 0). - auto* array = TRY(array_species_create(vm, *object, 0)); + auto* array = TRY(array_species_create(vm, object, 0)); // 5. Perform ? FlattenIntoArray(A, O, sourceLen, 0, 1, mapperFunction, thisArg). - TRY(flatten_into_array(vm, *array, *object, source_length, 0, 1, &mapper_function.as_function(), this_arg)); + TRY(flatten_into_array(vm, *array, object, source_length, 0, 1, &mapper_function.as_function(), this_arg)); // 6. Return A. return array; @@ -689,10 +689,10 @@ 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(vm)); + auto object = TRY(vm.this_value().to_object(vm)); // 2. Let len be ? LengthOfArrayLike(O). - auto length = TRY(length_of_array_like(vm, *object)); + auto length = TRY(length_of_array_like(vm, object)); // 3. If IsCallable(callbackfn) is false, throw a TypeError exception. if (!callback_function.is_function()) @@ -760,10 +760,10 @@ 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(vm)); + auto this_object = TRY(vm.this_value().to_object(vm)); // 2. Let len be ? LengthOfArrayLike(O). - auto length = TRY(length_of_array_like(vm, *this_object)); + auto length = TRY(length_of_array_like(vm, this_object)); // 3. If IsCallable(callbackfn) is false, throw a TypeError exception. if (!callback_function.is_function()) @@ -816,10 +816,10 @@ 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(vm)); + auto this_object = TRY(vm.this_value().to_object(vm)); // 2. Let len be ? LengthOfArrayLike(O). - auto length = TRY(length_of_array_like(vm, *this_object)); + auto length = TRY(length_of_array_like(vm, this_object)); // 3. If IsCallable(callbackfn) is false, throw a TypeError exception. if (!callback_function.is_function()) @@ -883,8 +883,8 @@ 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(vm)); - auto length = TRY(length_of_array_like(vm, *this_object)); + auto this_object = TRY(vm.this_value().to_object(vm)); + auto length = TRY(length_of_array_like(vm, this_object)); if (length == 0) return Value(false); u64 from_index = 0; @@ -918,10 +918,10 @@ 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(vm)); + auto object = TRY(vm.this_value().to_object(vm)); // 2. Let len be ? LengthOfArrayLike(O). - auto length = TRY(length_of_array_like(vm, *object)); + auto length = TRY(length_of_array_like(vm, object)); // 3. If len is 0, return -1๐ฝ. if (length == 0) @@ -986,7 +986,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(vm)); + 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". @@ -998,7 +998,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::join) s_array_join_seen_objects.remove(this_object); }; - auto length = TRY(length_of_array_like(vm, *this_object)); + auto length = TRY(length_of_array_like(vm, this_object)); DeprecatedString separator = ","; if (!vm.argument(0).is_undefined()) separator = TRY(vm.argument(0).to_deprecated_string(vm)); @@ -1021,7 +1021,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::keys) { auto& realm = *vm.current_realm(); - auto* this_object = TRY(vm.this_value().to_object(vm)); + auto this_object = TRY(vm.this_value().to_object(vm)); return ArrayIterator::create(realm, this_object, Object::PropertyKind::Key); } @@ -1033,10 +1033,10 @@ 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(vm)); + auto object = TRY(vm.this_value().to_object(vm)); // 2. Let len be ? LengthOfArrayLike(O). - auto length = TRY(length_of_array_like(vm, *object)); + auto length = TRY(length_of_array_like(vm, object)); // 3. If len is 0, return -1๐ฝ. if (length == 0) @@ -1101,17 +1101,17 @@ 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(vm)); + auto object = TRY(vm.this_value().to_object(vm)); // 2. Let len be ? LengthOfArrayLike(O). - auto length = TRY(length_of_array_like(vm, *object)); + auto length = TRY(length_of_array_like(vm, object)); // 3. If IsCallable(callbackfn) is false, throw a TypeError exception. if (!callback_function.is_function()) return vm.throw_completion<TypeError>(ErrorType::NotAFunction, TRY_OR_THROW_OOM(vm, callback_function.to_string_without_side_effects())); // 4. Let A be ? ArraySpeciesCreate(O, len). - auto* array = TRY(array_species_create(vm, *object, length)); + auto* array = TRY(array_species_create(vm, object, length)); // 5. Let k be 0. // 6. Repeat, while k < len, @@ -1144,8 +1144,8 @@ 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(vm)); - auto length = TRY(length_of_array_like(vm, *this_object)); + auto this_object = TRY(vm.this_value().to_object(vm)); + auto length = TRY(length_of_array_like(vm, this_object)); if (length == 0) { TRY(this_object->set(vm.names.length, Value(0), Object::ShouldThrowExceptions::Yes)); return js_undefined(); @@ -1160,8 +1160,8 @@ 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(vm)); - auto length = TRY(length_of_array_like(vm, *this_object)); + auto this_object = TRY(vm.this_value().to_object(vm)); + auto length = TRY(length_of_array_like(vm, this_object)); auto argument_count = vm.argument_count(); auto new_length = length + argument_count; if (new_length > MAX_ARRAY_LIKE_INDEX) @@ -1180,10 +1180,10 @@ 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(vm)); + auto object = TRY(vm.this_value().to_object(vm)); // 2. Let len be ? LengthOfArrayLike(O). - auto length = TRY(length_of_array_like(vm, *object)); + auto length = TRY(length_of_array_like(vm, object)); // 3. If IsCallable(callbackfn) is false, throw a TypeError exception. if (!callback_function.is_function()) @@ -1262,10 +1262,10 @@ 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(vm)); + auto object = TRY(vm.this_value().to_object(vm)); // 2. Let len be ? LengthOfArrayLike(O). - auto length = TRY(length_of_array_like(vm, *object)); + auto length = TRY(length_of_array_like(vm, object)); // 3. If IsCallable(callbackfn) is false, throw a TypeError exception. if (!callback_function.is_function()) @@ -1340,8 +1340,8 @@ 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(vm)); - auto length = TRY(length_of_array_like(vm, *this_object)); + auto this_object = TRY(vm.this_value().to_object(vm)); + auto length = TRY(length_of_array_like(vm, this_object)); auto middle = length / 2; for (size_t lower = 0; lower < middle; ++lower) { @@ -1375,8 +1375,8 @@ 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(vm)); - auto length = TRY(length_of_array_like(vm, *this_object)); + auto this_object = TRY(vm.this_value().to_object(vm)); + auto length = TRY(length_of_array_like(vm, this_object)); if (length == 0) { TRY(this_object->set(vm.names.length, Value(0), Object::ShouldThrowExceptions::Yes)); return js_undefined(); @@ -1402,9 +1402,9 @@ 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(vm)); + auto this_object = TRY(vm.this_value().to_object(vm)); - auto initial_length = TRY(length_of_array_like(vm, *this_object)); + auto initial_length = TRY(length_of_array_like(vm, this_object)); auto relative_start = TRY(vm.argument(0).to_integer_or_infinity(vm)); @@ -1435,7 +1435,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::slice) auto count = max(final - actual_start, 0.0); - auto* new_array = TRY(array_species_create(vm, *this_object, count)); + auto* new_array = TRY(array_species_create(vm, this_object, count)); size_t index = 0; size_t k = actual_start; @@ -1462,10 +1462,10 @@ 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(vm)); + auto object = TRY(vm.this_value().to_object(vm)); // 2. Let len be ? LengthOfArrayLike(O). - auto length = TRY(length_of_array_like(vm, *object)); + auto length = TRY(length_of_array_like(vm, object)); // 3. If IsCallable(callbackfn) is false, throw a TypeError exception. if (!callback_function.is_function()) @@ -1565,10 +1565,10 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::sort) return vm.throw_completion<TypeError>(ErrorType::NotAFunction, TRY_OR_THROW_OOM(vm, comparefn.to_string_without_side_effects())); // 2. Let obj be ? ToObject(this value). - auto* object = TRY(vm.this_value().to_object(vm)); + auto object = TRY(vm.this_value().to_object(vm)); // 3. Let len be ? LengthOfArrayLike(obj). - auto length = TRY(length_of_array_like(vm, *object)); + auto length = TRY(length_of_array_like(vm, object)); // 4. Let SortCompare be a new Abstract Closure with parameters (x, y) that captures comparefn and performs the following steps when called: Function<ThrowCompletionOr<double>(Value, Value)> sort_compare = [&](auto x, auto y) -> ThrowCompletionOr<double> { @@ -1577,7 +1577,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::sort) }; // 5. Let sortedList be ? SortIndexedProperties(obj, len, SortCompare, skip-holes). - auto sorted_list = TRY(sort_indexed_properties(vm, *object, length, sort_compare, Holes::SkipHoles)); + auto sorted_list = TRY(sort_indexed_properties(vm, object, length, sort_compare, Holes::SkipHoles)); // 6. Let itemCount be the number of elements in sortedList. auto item_count = sorted_list.size(); @@ -1607,9 +1607,9 @@ 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(vm)); + auto this_object = TRY(vm.this_value().to_object(vm)); - auto initial_length = TRY(length_of_array_like(vm, *this_object)); + auto initial_length = TRY(length_of_array_like(vm, this_object)); auto relative_start = TRY(vm.argument(0).to_integer_or_infinity(vm)); @@ -1640,7 +1640,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::splice) if (new_length > MAX_ARRAY_LIKE_INDEX) return vm.throw_completion<TypeError>(ErrorType::ArrayMaxSize); - auto* removed_elements = TRY(array_species_create(vm, *this_object, actual_delete_count)); + auto* removed_elements = TRY(array_species_create(vm, this_object, actual_delete_count)); for (u64 i = 0; i < actual_delete_count; ++i) { auto from = actual_start + i; @@ -1699,7 +1699,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(vm)); + auto this_object = TRY(vm.this_value().to_object(vm)); if (s_array_join_seen_objects.contains(this_object)) return PrimitiveString::create(vm, String {}); @@ -1709,7 +1709,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::to_locale_string) }; // 2. Let len be ? ToLength(? Get(array, "length")). - auto length = TRY(length_of_array_like(vm, *this_object)); + auto length = TRY(length_of_array_like(vm, this_object)); // 3. Let separator be the implementation-defined list-separator String value appropriate for the host environment's current locale (such as ", "). constexpr auto separator = ","sv; @@ -1752,10 +1752,10 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::to_reversed) auto& realm = *vm.current_realm(); // 1. Let O be ? ToObject(this value). - auto* object = TRY(vm.this_value().to_object(vm)); + auto object = TRY(vm.this_value().to_object(vm)); // 2. Let len be ? LengthOfArrayLike(O). - auto length = TRY(length_of_array_like(vm, *object)); + auto length = TRY(length_of_array_like(vm, object)); // 3. Let A be ? ArrayCreate(๐ฝ(len)). auto array = TRY(Array::create(realm, length)); @@ -1794,10 +1794,10 @@ 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(vm)); + auto object = TRY(vm.this_value().to_object(vm)); // 3. Let len be ? LengthOfArrayLike(O). - auto length = TRY(length_of_array_like(vm, *object)); + auto length = TRY(length_of_array_like(vm, object)); // 4. Let A be ? ArrayCreate(๐ฝ(len)). auto array = TRY(Array::create(realm, length)); @@ -1809,7 +1809,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::to_sorted) }; // 6. Let sortedList be ? SortIndexedProperties(obj, len, SortCompare, read-through-holes). - auto sorted_list = TRY(sort_indexed_properties(vm, *object, length, sort_compare, Holes::ReadThroughHoles)); + auto sorted_list = TRY(sort_indexed_properties(vm, object, length, sort_compare, Holes::ReadThroughHoles)); // 7. Let j be 0. // 8. Repeat, while j < len, @@ -1833,10 +1833,10 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::to_spliced) auto skip_count = vm.argument(1); // 1. Let O be ? ToObject(this value). - auto* object = TRY(vm.this_value().to_object(vm)); + auto object = TRY(vm.this_value().to_object(vm)); // 2. Let len be ? LengthOfArrayLike(O). - auto length = TRY(length_of_array_like(vm, *object)); + auto length = TRY(length_of_array_like(vm, object)); // 3. Let relativeStart be ? ToIntegerOrInfinity(start). auto relative_start = TRY(start.to_integer_or_infinity(vm)); @@ -1961,7 +1961,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::to_string) auto& realm = *vm.current_realm(); // 1. Let array be ? ToObject(this value). - auto* array = TRY(vm.this_value().to_object(vm)); + auto array = TRY(vm.this_value().to_object(vm)); // 2. Let func be ? Get(array, "join"). auto func = TRY(array->get(vm.names.join)); @@ -1977,8 +1977,8 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::to_string) // 23.1.3.37 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(vm)); - auto length = TRY(length_of_array_like(vm, *this_object)); + auto this_object = TRY(vm.this_value().to_object(vm)); + auto length = TRY(length_of_array_like(vm, this_object)); auto arg_count = vm.argument_count(); size_t new_length = length + arg_count; if (arg_count > 0) { @@ -2011,7 +2011,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::values) { auto& realm = *vm.current_realm(); - auto* this_object = TRY(vm.this_value().to_object(vm)); + auto this_object = TRY(vm.this_value().to_object(vm)); return ArrayIterator::create(realm, this_object, Object::PropertyKind::Value); } @@ -2025,10 +2025,10 @@ 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(vm)); + auto object = TRY(vm.this_value().to_object(vm)); // 2. Let len be ? LengthOfArrayLike(O). - auto length = TRY(length_of_array_like(vm, *object)); + auto length = TRY(length_of_array_like(vm, object)); // 3. Let relativeIndex be ? ToIntegerOrInfinity(index). auto relative_index = TRY(index.to_integer_or_infinity(vm)); diff --git a/Userland/Libraries/LibJS/Runtime/GeneratorObject.cpp b/Userland/Libraries/LibJS/Runtime/GeneratorObject.cpp index ce2a6c4b80..d57d58ccbb 100644 --- a/Userland/Libraries/LibJS/Runtime/GeneratorObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/GeneratorObject.cpp @@ -27,8 +27,8 @@ ThrowCompletionOr<NonnullGCPtr<GeneratorObject>> GeneratorObject::create(Realm& } else { generating_function_prototype = TRY(generating_function->get(vm.names.prototype)); } - auto* generating_function_prototype_object = TRY(generating_function_prototype.to_object(vm)); - auto object = MUST_OR_THROW_OOM(realm.heap().allocate<GeneratorObject>(realm, realm, *generating_function_prototype_object, move(execution_context))); + auto generating_function_prototype_object = TRY(generating_function_prototype.to_object(vm)); + auto object = MUST_OR_THROW_OOM(realm.heap().allocate<GeneratorObject>(realm, realm, generating_function_prototype_object, move(execution_context))); object->m_generating_function = generating_function; object->m_frame = move(frame); object->m_previous_value = initial_value; diff --git a/Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.cpp b/Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.cpp index f8773d6eb5..fb181cbc69 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.cpp @@ -602,7 +602,7 @@ ThrowCompletionOr<Object*> coerce_options_to_object(VM& vm, Value options) } // 2. Return ? ToObject(options). - return TRY(options.to_object(vm)); + return TRY(options.to_object(vm)).ptr(); } // NOTE: 9.2.13 GetOption has been removed and is being pulled in from ECMA-262 in the Temporal proposal. diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.cpp index aa1e81aaf0..20252e7f6c 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.cpp @@ -73,7 +73,7 @@ ThrowCompletionOr<Object*> to_date_time_options(VM& vm, Value options_value, Opt auto& realm = *vm.current_realm(); // 1. If options is undefined, let options be null; otherwise let options be ? ToObject(options). - Object* options = nullptr; + GCPtr<Object> options; if (!options_value.is_undefined()) options = TRY(options_value.to_object(vm)); @@ -150,7 +150,7 @@ ThrowCompletionOr<Object*> to_date_time_options(VM& vm, Value options_value, Opt } // 13. Return options. - return options; + return options.ptr(); } // 11.5.2 DateTimeStyleFormat ( dateStyle, timeStyle, styles ), https://tc39.es/ecma402/#sec-date-time-style-format diff --git a/Userland/Libraries/LibJS/Runtime/Object.cpp b/Userland/Libraries/LibJS/Runtime/Object.cpp index 5414a94fb5..816447c03c 100644 --- a/Userland/Libraries/LibJS/Runtime/Object.cpp +++ b/Userland/Libraries/LibJS/Runtime/Object.cpp @@ -432,7 +432,7 @@ ThrowCompletionOr<void> Object::copy_data_properties(VM& vm, Value source, HashT if (source.is_nullish()) return {}; - auto* from_object = MUST(source.to_object(vm)); + 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(vm, next_key_value)); @@ -1201,7 +1201,7 @@ ThrowCompletionOr<Object*> Object::define_properties(Value properties) auto& vm = this->vm(); // 1. Let props be ? ToObject(Properties). - auto* props = TRY(properties.to_object(vm)); + auto props = TRY(properties.to_object(vm)); // 2. Let keys be ? props.[[OwnPropertyKeys]](). auto keys = TRY(props->internal_own_property_keys()); diff --git a/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp b/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp index cf81559b06..ce8866b6f1 100644 --- a/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp @@ -76,7 +76,7 @@ ThrowCompletionOr<NonnullGCPtr<Object>> ObjectConstructor::construct(FunctionObj auto value = vm.argument(0); if (value.is_nullish()) return Object::create(realm, realm.intrinsics().object_prototype()); - return *TRY(value.to_object(vm)); + return TRY(value.to_object(vm)); } enum class GetOwnPropertyKeysType { @@ -88,7 +88,7 @@ enum class GetOwnPropertyKeysType { static ThrowCompletionOr<MarkedVector<Value>> get_own_property_keys(VM& vm, Value value, GetOwnPropertyKeysType type) { // 1. Let obj be ? ToObject(O). - auto* object = TRY(value.to_object(vm)); + auto object = TRY(value.to_object(vm)); // 2. Let keys be ? obj.[[OwnPropertyKeys]](). auto keys = TRY(object->internal_own_property_keys()); @@ -131,7 +131,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(vm)); + auto object = TRY(vm.argument(0).to_object(vm)); // 2. Return ? obj.[[GetPrototypeOf]](). return TRY(object->internal_get_prototype_of()); @@ -258,7 +258,7 @@ 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(vm)); + 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(vm, descriptor); @@ -270,7 +270,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::get_own_property_descriptors) auto& realm = *vm.current_realm(); // 1. Let obj be ? ToObject(O). - auto* object = TRY(vm.argument(0).to_object(vm)); + auto object = TRY(vm.argument(0).to_object(vm)); // 2. Let ownKeys be ? obj.[[OwnPropertyKeys]](). auto own_keys = TRY(object->internal_own_property_keys()); @@ -333,7 +333,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::keys) { auto& realm = *vm.current_realm(); - auto* object = TRY(vm.argument(0).to_object(vm)); + 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); } @@ -343,7 +343,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::values) { auto& realm = *vm.current_realm(); - auto* object = TRY(vm.argument(0).to_object(vm)); + 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); } @@ -353,7 +353,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::entries) { auto& realm = *vm.current_realm(); - auto* object = TRY(vm.argument(0).to_object(vm)); + 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); } @@ -387,7 +387,7 @@ 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(vm)); + auto object = TRY(vm.argument(0).to_object(vm)); // 2. Let key be ? ToPropertyKey(P). auto key = TRY(vm.argument(1).to_property_key(vm)); @@ -400,7 +400,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(vm)); + auto to = TRY(vm.argument(0).to_object(vm)); // 2. If only one argument was passed, return to. if (vm.argument_count() == 1) @@ -415,7 +415,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::assign) continue; // i. Let from be ! ToObject(nextSource). - auto* from = MUST(next_source.to_object(vm)); + auto from = MUST(next_source.to_object(vm)); // ii. Let keys be ? from.[[OwnPropertyKeys]](). auto keys = TRY(from->internal_own_property_keys()); diff --git a/Userland/Libraries/LibJS/Runtime/ObjectPrototype.cpp b/Userland/Libraries/LibJS/Runtime/ObjectPrototype.cpp index 13ca16612a..7c13b1a583 100644 --- a/Userland/Libraries/LibJS/Runtime/ObjectPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/ObjectPrototype.cpp @@ -61,7 +61,7 @@ ThrowCompletionOr<bool> ObjectPrototype::internal_set_prototype_of(Object* proto JS_DEFINE_NATIVE_FUNCTION(ObjectPrototype::has_own_property) { auto property_key = TRY(vm.argument(0).to_property_key(vm)); - auto* this_object = TRY(vm.this_value().to_object(vm)); + auto this_object = TRY(vm.this_value().to_object(vm)); return Value(TRY(this_object->has_own_property(property_key))); } @@ -79,7 +79,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectPrototype::to_string) return MUST_OR_THROW_OOM(PrimitiveString::create(vm, "[object Null]"sv)); // 3. Let O be ! ToObject(this value). - auto* object = MUST(this_value.to_object(vm)); + auto object = MUST(this_value.to_object(vm)); // 4. Let isArray be ? IsArray(O). auto is_array = TRY(Value(object).is_array(vm)); @@ -96,22 +96,22 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectPrototype::to_string) else if (object->is_function()) builtin_tag = "Function"; // 8. Else if O has an [[ErrorData]] internal slot, let builtinTag be "Error". - else if (is<Error>(object)) + else if (is<Error>(*object)) builtin_tag = "Error"; // 9. Else if O has a [[BooleanData]] internal slot, let builtinTag be "Boolean". - else if (is<BooleanObject>(object)) + else if (is<BooleanObject>(*object)) builtin_tag = "Boolean"; // 10. Else if O has a [[NumberData]] internal slot, let builtinTag be "Number". - else if (is<NumberObject>(object)) + else if (is<NumberObject>(*object)) builtin_tag = "Number"; // 11. Else if O has a [[StringData]] internal slot, let builtinTag be "String". - else if (is<StringObject>(object)) + else if (is<StringObject>(*object)) builtin_tag = "String"; // 12. Else if O has a [[DateValue]] internal slot, let builtinTag be "Date". - else if (is<Date>(object)) + else if (is<Date>(*object)) builtin_tag = "Date"; // 13. Else if O has a [[RegExpMatcher]] internal slot, let builtinTag be "RegExp". - else if (is<RegExpObject>(object)) + else if (is<RegExpObject>(*object)) builtin_tag = "RegExp"; // 14. Else, let builtinTag be "Object". else @@ -152,7 +152,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectPrototype::property_is_enumerable) // 1. Let P be ? ToPropertyKey(V). 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(vm)); + 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. @@ -169,7 +169,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(vm)); + auto this_object = TRY(vm.this_value().to_object(vm)); for (;;) { object = TRY(object->internal_get_prototype_of()); @@ -183,7 +183,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(vm)); + auto object = TRY(vm.this_value().to_object(vm)); auto getter = vm.argument(1); if (!getter.is_function()) @@ -201,7 +201,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(vm)); + auto object = TRY(vm.this_value().to_object(vm)); auto setter = vm.argument(1); if (!setter.is_function()) @@ -219,7 +219,7 @@ 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(vm)); + auto object = GCPtr { TRY(vm.this_value().to_object(vm)) }; auto key = TRY(vm.argument(0).to_property_key(vm)); @@ -239,7 +239,7 @@ 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(vm)); + auto object = GCPtr { TRY(vm.this_value().to_object(vm)) }; auto key = TRY(vm.argument(0).to_property_key(vm)); @@ -259,7 +259,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(vm)); + auto object = TRY(vm.this_value().to_object(vm)); return TRY(object->internal_get_prototype_of()); } diff --git a/Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp b/Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp index 3c5404f142..a3e119f318 100644 --- a/Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp @@ -314,7 +314,7 @@ ThrowCompletionOr<NonnullGCPtr<Object>> PromiseConstructor::construct(FunctionOb JS_DEFINE_NATIVE_FUNCTION(PromiseConstructor::all) { // 1. Let C be the this value. - auto* constructor = TRY(vm.this_value().to_object(vm)); + auto constructor = TRY(vm.this_value().to_object(vm)); // 2. Let promiseCapability be ? NewPromiseCapability(C). auto promise_capability = TRY(new_promise_capability(vm, constructor)); @@ -348,7 +348,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(vm)); + auto constructor = TRY(vm.this_value().to_object(vm)); // 2. Let promiseCapability be ? NewPromiseCapability(C). auto promise_capability = TRY(new_promise_capability(vm, constructor)); @@ -382,7 +382,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(vm)); + auto constructor = TRY(vm.this_value().to_object(vm)); // 2. Let promiseCapability be ? NewPromiseCapability(C). auto promise_capability = TRY(new_promise_capability(vm, constructor)); @@ -416,7 +416,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(vm)); + auto constructor = TRY(vm.this_value().to_object(vm)); // 2. Let promiseCapability be ? NewPromiseCapability(C). auto promise_capability = TRY(new_promise_capability(vm, constructor)); @@ -452,7 +452,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(vm)); + auto constructor = TRY(vm.this_value().to_object(vm)); // 2. Let promiseCapability be ? NewPromiseCapability(C). auto promise_capability = TRY(new_promise_capability(vm, constructor)); diff --git a/Userland/Libraries/LibJS/Runtime/PrototypeObject.h b/Userland/Libraries/LibJS/Runtime/PrototypeObject.h index 35c5a95cc0..702b11d70a 100644 --- a/Userland/Libraries/LibJS/Runtime/PrototypeObject.h +++ b/Userland/Libraries/LibJS/Runtime/PrototypeObject.h @@ -40,10 +40,10 @@ public: // Use typed_this_object() when the spec coerces |this| value to an object. static ThrowCompletionOr<ObjectType*> typed_this_object(VM& vm) { - auto* this_object = TRY(vm.this_value().to_object(vm)); - if (!is<ObjectType>(this_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); + return static_cast<ObjectType*>(this_object.ptr()); } // Use typed_this_value() when the spec does not coerce |this| value to an object. diff --git a/Userland/Libraries/LibJS/Runtime/Reference.cpp b/Userland/Libraries/LibJS/Runtime/Reference.cpp index 358f9e6226..14f2fe4062 100644 --- a/Userland/Libraries/LibJS/Runtime/Reference.cpp +++ b/Userland/Libraries/LibJS/Runtime/Reference.cpp @@ -40,7 +40,7 @@ ThrowCompletionOr<void> Reference::put_value(VM& vm, Value 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(vm)); + auto base_obj = TRY(m_base_value.to_object(vm)); // b. If IsPrivateReference(V) is true, then if (is_private_reference()) { @@ -105,7 +105,7 @@ ThrowCompletionOr<Value> Reference::get_value(VM& vm) const // as things currently stand this does the "wrong thing" but // the error is unobservable - auto* base_obj = TRY(m_base_value.to_object(vm)); + auto base_obj = TRY(m_base_value.to_object(vm)); // i. Return ? PrivateGet(baseObj, V.[[ReferencedName]]). return base_obj->private_get(m_private_name); @@ -171,7 +171,7 @@ ThrowCompletionOr<bool> Reference::delete_(VM& vm) return vm.throw_completion<ReferenceError>(ErrorType::UnsupportedDeleteSuperProperty); // c. Let baseObj be ! ToObject(ref.[[Base]]). - auto* base_obj = MUST(m_base_value.to_object(vm)); + 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)); diff --git a/Userland/Libraries/LibJS/Runtime/RegExpStringIteratorPrototype.cpp b/Userland/Libraries/LibJS/Runtime/RegExpStringIteratorPrototype.cpp index eec552f1f3..2585fbd7f8 100644 --- a/Userland/Libraries/LibJS/Runtime/RegExpStringIteratorPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/RegExpStringIteratorPrototype.cpp @@ -51,7 +51,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpStringIteratorPrototype::next) return create_iterator_result_object(vm, match, false); } - auto* match_object = TRY(match.to_object(vm)); + 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_deprecated_string(vm)); if (match_string.is_empty()) { diff --git a/Userland/Libraries/LibJS/Runtime/StringConstructor.cpp b/Userland/Libraries/LibJS/Runtime/StringConstructor.cpp index 4c1ccdc1ae..716e0e6aa2 100644 --- a/Userland/Libraries/LibJS/Runtime/StringConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/StringConstructor.cpp @@ -148,13 +148,13 @@ JS_DEFINE_NATIVE_FUNCTION(StringConstructor::raw) auto substitution_count = vm.argument_count() > 0 ? vm.argument_count() - 1 : 0; // 2. Let cooked be ? ToObject(template). - auto* cooked = TRY(template_.to_object(vm)); + auto cooked = TRY(template_.to_object(vm)); // 3. Let literals be ? ToObject(? Get(cooked, "raw")). - auto* literals = TRY(TRY(cooked->get(vm.names.raw)).to_object(vm)); + auto literals = TRY(TRY(cooked->get(vm.names.raw)).to_object(vm)); // 4. Let literalCount be ? LengthOfArrayLike(literals). - auto literal_count = TRY(length_of_array_like(vm, *literals)); + auto literal_count = TRY(length_of_array_like(vm, literals)); // 5. If literalCount โค 0, return the empty String. if (literal_count == 0) diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp index f16dfa0ff0..5282c9d981 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp @@ -175,12 +175,12 @@ ThrowCompletionOr<PlainDate*> calendar_date_add(VM& vm, Object& calendar, Value auto added_date = TRY(call(vm, date_add ?: js_undefined(), &calendar, date, &duration, options ?: js_undefined())); // 6. Perform ? RequireInternalSlot(addedDate, [[InitializedTemporalDate]]). - auto* added_date_object = TRY(added_date.to_object(vm)); - if (!is<PlainDate>(added_date_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"); // 7. Return addedDate. - return static_cast<PlainDate*>(added_date_object); + return static_cast<PlainDate*>(added_date_object.ptr()); } // 12.2.7 CalendarDateUntil ( calendar, one, two, options [ , dateUntil ] ), https://tc39.es/proposal-temporal/#sec-temporal-calendardateuntil @@ -196,12 +196,12 @@ ThrowCompletionOr<Duration*> calendar_date_until(VM& vm, Object& calendar, Value auto duration = TRY(call(vm, date_until ?: js_undefined(), &calendar, one, two, &options)); // 4. Perform ? RequireInternalSlot(duration, [[InitializedTemporalDuration]]). - auto* duration_object = TRY(duration.to_object(vm)); - if (!is<Duration>(duration_object)) + auto duration_object = TRY(duration.to_object(vm)); + if (!is<Duration>(*duration_object)) return vm.throw_completion<TypeError>(ErrorType::NotAnObjectOfType, "Temporal.Duration"); // 5. Return duration. - return static_cast<Duration*>(duration_object); + return static_cast<Duration*>(duration_object.ptr()); } // 12.2.8 CalendarYear ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendaryear @@ -525,12 +525,12 @@ ThrowCompletionOr<PlainDate*> calendar_date_from_fields(VM& vm, Object& calendar 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(vm)); - if (!is<PlainDate>(date_object)) + auto date_object = TRY(date.to_object(vm)); + if (!is<PlainDate>(*date_object)) return vm.throw_completion<TypeError>(ErrorType::NotAnObjectOfType, "Temporal.PlainDate"); // 4. Return date. - return static_cast<PlainDate*>(date_object); + return static_cast<PlainDate*>(date_object.ptr()); } // 12.2.25 CalendarYearMonthFromFields ( calendar, fields [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal-calendaryearmonthfromfields @@ -542,12 +542,12 @@ ThrowCompletionOr<PlainYearMonth*> calendar_year_month_from_fields(VM& vm, Objec 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(vm)); - if (!is<PlainYearMonth>(year_month_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"); // 4. Return yearMonth. - return static_cast<PlainYearMonth*>(year_month_object); + return static_cast<PlainYearMonth*>(year_month_object.ptr()); } // 12.2.26 CalendarMonthDayFromFields ( calendar, fields [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal-calendarmonthdayfromfields @@ -559,12 +559,12 @@ ThrowCompletionOr<PlainMonthDay*> calendar_month_day_from_fields(VM& vm, Object& 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(vm)); - if (!is<PlainMonthDay>(month_day_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"); // 4. Return monthDay. - return static_cast<PlainMonthDay*>(month_day_object); + return static_cast<PlainMonthDay*>(month_day_object.ptr()); } // 12.2.27 MaybeFormatCalendarAnnotation ( calendarObject, showCalendar ), https://tc39.es/proposal-temporal/#sec-temporal-maybeformatcalendarannotation diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/CalendarPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/CalendarPrototype.cpp index 7713d20f86..ef3ebb3b26 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/CalendarPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/CalendarPrototype.cpp @@ -598,16 +598,16 @@ 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(vm)); + auto fields = TRY(vm.argument(0).to_object(vm)); // 4. Set additionalFields to ? ToObject(additionalFields). - auto* additional_fields = TRY(vm.argument(1).to_object(vm)); + auto additional_fields = TRY(vm.argument(1).to_object(vm)); // 5. Assert: calendar.[[Identifier]] is "iso8601". VERIFY(calendar->identifier() == "iso8601"sv); // 6. Return ? DefaultMergeCalendarFields(fields, additionalFields). - return TRY(default_merge_calendar_fields(vm, *fields, *additional_fields)); + return TRY(default_merge_calendar_fields(vm, fields, additional_fields)); } // 12.4.24 Temporal.Calendar.prototype.toString ( ), https://tc39.es/proposal-temporal/#sec-temporal.calendar.prototype.tostring diff --git a/Userland/Libraries/LibJS/Runtime/TypedArray.cpp b/Userland/Libraries/LibJS/Runtime/TypedArray.cpp index 5b8c8bfe96..ae4fa13a9e 100644 --- a/Userland/Libraries/LibJS/Runtime/TypedArray.cpp +++ b/Userland/Libraries/LibJS/Runtime/TypedArray.cpp @@ -20,11 +20,11 @@ namespace JS { ThrowCompletionOr<TypedArrayBase*> typed_array_from(VM& vm, Value typed_array_value) { - auto* this_object = TRY(typed_array_value.to_object(vm)); + auto this_object = TRY(typed_array_value.to_object(vm)); if (!this_object->is_typed_array()) return vm.throw_completion<TypeError>(ErrorType::NotAnObjectOfType, "TypedArray"); - return static_cast<TypedArrayBase*>(this_object); + return static_cast<TypedArrayBase*>(this_object.ptr()); } // 23.2.4.4 ValidateTypedArray ( O ), https://tc39.es/ecma262/#sec-validatetypedarray diff --git a/Userland/Libraries/LibJS/Runtime/TypedArrayConstructor.cpp b/Userland/Libraries/LibJS/Runtime/TypedArrayConstructor.cpp index a864d58357..53a2e43de9 100644 --- a/Userland/Libraries/LibJS/Runtime/TypedArrayConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/TypedArrayConstructor.cpp @@ -133,10 +133,10 @@ JS_DEFINE_NATIVE_FUNCTION(TypedArrayConstructor::from) // 7. NOTE: source is not an Iterable so assume it is already an array-like object. // 8. Let arrayLike be ! ToObject(source). - auto* array_like = MUST(source.to_object(vm)); + auto array_like = MUST(source.to_object(vm)); // 9. Let len be ? LengthOfArrayLike(arrayLike). - auto length = TRY(length_of_array_like(vm, *array_like)); + auto length = TRY(length_of_array_like(vm, array_like)); // 10. Let targetObj be ? TypedArrayCreate(C, ยซ ๐ฝ(len) ยป). MarkedVector<Value> arguments(vm.heap()); diff --git a/Userland/Libraries/LibJS/Runtime/TypedArrayPrototype.cpp b/Userland/Libraries/LibJS/Runtime/TypedArrayPrototype.cpp index 645b7c0ae5..67973c8b6e 100644 --- a/Userland/Libraries/LibJS/Runtime/TypedArrayPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/TypedArrayPrototype.cpp @@ -1259,10 +1259,10 @@ static ThrowCompletionOr<void> set_typed_array_from_array_like(VM& vm, TypedArra auto target_length = target.array_length(); // 4. Let src be ? ToObject(source). - auto* src = TRY(source.to_object(vm)); + auto src = TRY(source.to_object(vm)); // 5. Let srcLength be ? LengthOfArrayLike(src). - auto source_length = TRY(length_of_array_like(vm, *src)); + auto source_length = TRY(length_of_array_like(vm, src)); // 6. If targetOffset is +โ, throw a RangeError exception. if (isinf(target_offset)) @@ -1702,7 +1702,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(vm)); + auto object = TRY(vm.this_value().to_object(vm)); // 3. Perform ? ValidateTypedArray(O). auto* typed_array = TRY(validate_typed_array_from_this(vm)); @@ -1723,7 +1723,7 @@ JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::to_sorted) }; // 8. Let sortedList be ? SortIndexedProperties(O, len, SortCompare, read-through-holes). - auto sorted_list = TRY(sort_indexed_properties(vm, *object, length, sort_compare, Holes::ReadThroughHoles)); + auto sorted_list = TRY(sort_indexed_properties(vm, object, length, sort_compare, Holes::ReadThroughHoles)); // 9. Let j be 0. // 10. Repeat, while j < len, diff --git a/Userland/Libraries/LibJS/Runtime/VM.cpp b/Userland/Libraries/LibJS/Runtime/VM.cpp index 3ce4588b65..08b7994b32 100644 --- a/Userland/Libraries/LibJS/Runtime/VM.cpp +++ b/Userland/Libraries/LibJS/Runtime/VM.cpp @@ -347,7 +347,7 @@ ThrowCompletionOr<void> VM::property_binding_initialization(BindingPattern const auto& vm = *this; auto& realm = *vm.current_realm(); - auto* object = TRY(value.to_object(vm)); + auto object = TRY(value.to_object(vm)); HashTable<PropertyKey> seen_names; for (auto& property : binding.entries) { diff --git a/Userland/Libraries/LibJS/Runtime/Value.cpp b/Userland/Libraries/LibJS/Runtime/Value.cpp index 0c8de4df19..362fd94bbd 100644 --- a/Userland/Libraries/LibJS/Runtime/Value.cpp +++ b/Userland/Libraries/LibJS/Runtime/Value.cpp @@ -554,7 +554,7 @@ ThrowCompletionOr<Value> Value::to_primitive(VM& vm, PreferredType preferred_typ } // 7.1.18 ToObject ( argument ), https://tc39.es/ecma262/#sec-toobject -ThrowCompletionOr<Object*> Value::to_object(VM& vm) const +ThrowCompletionOr<NonnullGCPtr<Object>> Value::to_object(VM& vm) const { auto& realm = *vm.current_realm(); VERIFY(!is_empty()); @@ -562,7 +562,7 @@ ThrowCompletionOr<Object*> Value::to_object(VM& vm) const // Number if (is_number()) { // Return a new Number object whose [[NumberData]] internal slot is set to argument. See 21.1 for a description of Number objects. - return NumberObject::create(realm, as_double()).ptr(); + return NumberObject::create(realm, as_double()); } switch (m_value.tag) { @@ -575,23 +575,23 @@ ThrowCompletionOr<Object*> Value::to_object(VM& vm) const // Boolean case BOOLEAN_TAG: // Return a new Boolean object whose [[BooleanData]] internal slot is set to argument. See 20.3 for a description of Boolean objects. - return BooleanObject::create(realm, as_bool()).ptr(); + return BooleanObject::create(realm, as_bool()); // String case STRING_TAG: // Return a new String object whose [[StringData]] internal slot is set to argument. See 22.1 for a description of String objects. - return MUST_OR_THROW_OOM(StringObject::create(realm, const_cast<JS::PrimitiveString&>(as_string()), realm.intrinsics().string_prototype())).ptr(); + return MUST_OR_THROW_OOM(StringObject::create(realm, const_cast<JS::PrimitiveString&>(as_string()), realm.intrinsics().string_prototype())); // Symbol case SYMBOL_TAG: // Return a new Symbol object whose [[SymbolData]] internal slot is set to argument. See 20.4 for a description of Symbol objects. - return SymbolObject::create(realm, const_cast<JS::Symbol&>(as_symbol())).ptr(); + return SymbolObject::create(realm, const_cast<JS::Symbol&>(as_symbol())); // BigInt case BIGINT_TAG: // Return a new BigInt object whose [[BigIntData]] internal slot is set to argument. See 21.2 for a description of BigInt objects. - return BigIntObject::create(realm, const_cast<JS::BigInt&>(as_bigint())).ptr(); + return BigIntObject::create(realm, const_cast<JS::BigInt&>(as_bigint())); // Object case OBJECT_TAG: // Return argument. - return &const_cast<Object&>(as_object()); + return const_cast<Object&>(as_object()); default: VERIFY_NOT_REACHED(); } @@ -1221,7 +1221,7 @@ ThrowCompletionOr<Value> Value::get(VM& vm, PropertyKey const& property_key) con VERIFY(property_key.is_valid()); // 2. Let O be ? ToObject(V). - auto* object = TRY(to_object(vm)); + auto object = TRY(to_object(vm)); // 3. Return ? O.[[Get]](P, V). return TRY(object->internal_get(property_key, *this)); diff --git a/Userland/Libraries/LibJS/Runtime/Value.h b/Userland/Libraries/LibJS/Runtime/Value.h index 351b850556..0139637cb1 100644 --- a/Userland/Libraries/LibJS/Runtime/Value.h +++ b/Userland/Libraries/LibJS/Runtime/Value.h @@ -371,7 +371,7 @@ public: ThrowCompletionOr<Utf16String> to_utf16_string(VM&) const; ThrowCompletionOr<NonnullGCPtr<PrimitiveString>> to_primitive_string(VM&); ThrowCompletionOr<Value> to_primitive(VM&, PreferredType preferred_type = PreferredType::Default) const; - ThrowCompletionOr<Object*> to_object(VM&) const; + ThrowCompletionOr<NonnullGCPtr<Object>> to_object(VM&) const; ThrowCompletionOr<Value> to_numeric(VM&) const; ThrowCompletionOr<Value> to_number(VM&) const; ThrowCompletionOr<BigInt*> to_bigint(VM&) const; diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssembly.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssembly.cpp index 4ca72447d4..07ddd74a48 100644 --- a/Userland/Libraries/LibWeb/WebAssembly/WebAssembly.cpp +++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssembly.cpp @@ -160,7 +160,7 @@ JS::ThrowCompletionOr<size_t> instantiate_module(JS::VM& vm, Wasm::Module const& HashMap<Wasm::Linker::Name, Wasm::ExternValue> resolved_imports; auto import_argument = vm.argument(1); if (!import_argument.is_undefined()) { - auto* import_object = TRY(import_argument.to_object(vm)); + auto import_object = TRY(import_argument.to_object(vm)); dbgln("Trying to resolve stuff because import object was specified"); for (Wasm::Linker::Name const& import_name : linker.unresolved_imports()) { dbgln("Trying to resolve {}::{}", import_name.module, import_name.name); @@ -171,7 +171,7 @@ JS::ThrowCompletionOr<size_t> instantiate_module(JS::VM& vm, Wasm::Module const& auto object_or_error = value.to_object(vm); if (object_or_error.is_error()) break; - auto* object = object_or_error.release_value(); + auto object = object_or_error.release_value(); auto import_or_error = object->get(import_name.name); if (import_or_error.is_error()) break; |