Skip to content

Commit

Permalink
LibJS: Replace uses of MarkedValueList with MarkedVector<Value>
Browse files Browse the repository at this point in the history
This is effectively a drop-in replacement.
  • Loading branch information
linusg committed Feb 9, 2022
1 parent 1d32ac7 commit bc183db
Show file tree
Hide file tree
Showing 61 changed files with 143 additions and 142 deletions.
6 changes: 3 additions & 3 deletions Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2218,7 +2218,7 @@ class @wrapper_class@ : public @wrapper_base_class@ {
virtual JS::ThrowCompletionOr<bool> internal_define_own_property(JS::PropertyKey const&, JS::PropertyDescriptor const&) override;
virtual JS::ThrowCompletionOr<bool> internal_delete(JS::PropertyKey const&) override;
virtual JS::ThrowCompletionOr<bool> internal_prevent_extensions() override;
virtual JS::ThrowCompletionOr<JS::MarkedValueList> internal_own_property_keys() const override;
virtual JS::ThrowCompletionOr<JS::MarkedVector<JS::Value>> internal_own_property_keys() const override;
)~~~");
}

Expand Down Expand Up @@ -3053,12 +3053,12 @@ JS::ThrowCompletionOr<bool> @class_name@::internal_prevent_extensions()

// 3.9.6. [[OwnPropertyKeys]], https://webidl.spec.whatwg.org/#legacy-platform-object-ownpropertykeys
scoped_generator.append(R"~~~(
JS::ThrowCompletionOr<JS::MarkedValueList> @class_name@::internal_own_property_keys() const
JS::ThrowCompletionOr<JS::MarkedVector<JS::Value>> @class_name@::internal_own_property_keys() const
{
auto& vm = this->vm();
// 1. Let keys be a new empty list of ECMAScript String and Symbol values.
JS::MarkedValueList keys { heap() };
JS::MarkedVector<JS::Value> keys { heap() };
)~~~");

Expand Down
12 changes: 6 additions & 6 deletions Userland/Libraries/LibJS/AST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <AK/TemporaryChange.h>
#include <LibCrypto/BigInt/SignedBigInteger.h>
#include <LibJS/AST.h>
#include <LibJS/Heap/MarkedVector.h>
#include <LibJS/Interpreter.h>
#include <LibJS/Runtime/AbstractOperations.h>
#include <LibJS/Runtime/Accessor.h>
Expand All @@ -25,7 +26,6 @@
#include <LibJS/Runtime/FunctionEnvironment.h>
#include <LibJS/Runtime/GlobalObject.h>
#include <LibJS/Runtime/IteratorOperations.h>
#include <LibJS/Runtime/MarkedValueList.h>
#include <LibJS/Runtime/NativeFunction.h>
#include <LibJS/Runtime/ObjectEnvironment.h>
#include <LibJS/Runtime/PrimitiveString.h>
Expand Down Expand Up @@ -351,7 +351,7 @@ ThrowCompletionOr<CallExpression::ThisAndCallee> CallExpression::compute_this_an
}

// 13.3.8.1 Runtime Semantics: ArgumentListEvaluation, https://tc39.es/ecma262/#sec-runtime-semantics-argumentlistevaluation
static ThrowCompletionOr<void> argument_list_evaluation(Interpreter& interpreter, GlobalObject& global_object, Vector<CallExpression::Argument> const& arguments, MarkedValueList& list)
static ThrowCompletionOr<void> argument_list_evaluation(Interpreter& interpreter, GlobalObject& global_object, Vector<CallExpression::Argument> const& arguments, MarkedVector<Value>& list)
{
list.ensure_capacity(arguments.size());

Expand Down Expand Up @@ -383,7 +383,7 @@ Completion NewExpression::execute(Interpreter& interpreter, GlobalObject& global
// 3. If arguments is empty, let argList be a new empty List.
// 4. Else,
// a. Let argList be ? ArgumentListEvaluation of arguments.
MarkedValueList arg_list(vm.heap());
MarkedVector<Value> arg_list(vm.heap());
TRY(argument_list_evaluation(interpreter, global_object, m_arguments, arg_list));

// 5. If IsConstructor(constructor) is false, throw a TypeError exception.
Expand Down Expand Up @@ -421,7 +421,7 @@ Completion CallExpression::execute(Interpreter& interpreter, GlobalObject& globa

VERIFY(!callee.is_empty());

MarkedValueList arg_list(vm.heap());
MarkedVector<Value> arg_list(vm.heap());
TRY(argument_list_evaluation(interpreter, global_object, m_arguments, arg_list));

if (!callee.is_function())
Expand Down Expand Up @@ -458,7 +458,7 @@ Completion SuperCall::execute(Interpreter& interpreter, GlobalObject& global_obj
auto* func = get_super_constructor(interpreter.vm());

// 4. Let argList be ? ArgumentListEvaluation of Arguments.
MarkedValueList arg_list(vm.heap());
MarkedVector<Value> arg_list(vm.heap());
TRY(argument_list_evaluation(interpreter, global_object, m_arguments, arg_list));

// 5. If IsConstructor(func) is false, throw a TypeError exception.
Expand Down Expand Up @@ -3549,7 +3549,7 @@ Completion TaggedTemplateLiteral::execute(Interpreter& interpreter, GlobalObject
auto tag = TRY(m_tag->execute(interpreter, global_object)).release_value();
auto& expressions = m_template_literal->expressions();
auto* strings = MUST(Array::create(global_object, 0));
MarkedValueList arguments(vm.heap());
MarkedVector<Value> arguments(vm.heap());
arguments.append(strings);
for (size_t i = 0; i < expressions.size(); ++i) {
auto value = TRY(expressions[i].execute(interpreter, global_object)).release_value();
Expand Down
2 changes: 1 addition & 1 deletion Userland/Libraries/LibJS/Bytecode/Op.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ ThrowCompletionOr<void> Call::execute_impl(Bytecode::Interpreter& interpreter) c
if (!return_value_or_error.is_error())
return_value = return_value_or_error.release_value();
} else {
MarkedValueList argument_values { interpreter.vm().heap() };
MarkedVector<Value> argument_values { interpreter.vm().heap() };
for (size_t i = 0; i < m_argument_count; ++i)
argument_values.append(interpreter.reg(m_arguments[i]));

Expand Down
1 change: 1 addition & 0 deletions Userland/Libraries/LibJS/Heap/Heap.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <LibJS/Heap/CellAllocator.h>
#include <LibJS/Heap/Handle.h>
#include <LibJS/Heap/MarkedVector.h>
#include <LibJS/Runtime/MarkedValueList.h>
#include <LibJS/Runtime/Object.h>
#include <LibJS/Runtime/WeakContainer.h>

Expand Down
2 changes: 1 addition & 1 deletion Userland/Libraries/LibJS/Interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
#include <LibJS/Forward.h>
#include <LibJS/Heap/DeferGC.h>
#include <LibJS/Heap/Heap.h>
#include <LibJS/Heap/MarkedVector.h>
#include <LibJS/Runtime/Completion.h>
#include <LibJS/Runtime/DeclarativeEnvironment.h>
#include <LibJS/Runtime/ErrorTypes.h>
#include <LibJS/Runtime/GlobalEnvironment.h>
#include <LibJS/Runtime/GlobalObject.h>
#include <LibJS/Runtime/MarkedValueList.h>
#include <LibJS/Runtime/Realm.h>
#include <LibJS/Runtime/VM.h>
#include <LibJS/Runtime/Value.h>
Expand Down
2 changes: 1 addition & 1 deletion Userland/Libraries/LibJS/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class Parser {
};

// Needs to mess with m_state, and we're not going to expose a non-const getter for that :^)
friend ThrowCompletionOr<ECMAScriptFunctionObject*> FunctionConstructor::create_dynamic_function(GlobalObject&, FunctionObject&, FunctionObject*, FunctionKind, MarkedValueList const&);
friend ThrowCompletionOr<ECMAScriptFunctionObject*> FunctionConstructor::create_dynamic_function(GlobalObject&, FunctionObject&, FunctionObject*, FunctionKind, MarkedVector<Value> const&);

private:
friend class ScopePusher;
Expand Down
16 changes: 8 additions & 8 deletions Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ ThrowCompletionOr<Value> require_object_coercible(GlobalObject& global_object, V
}

// 7.3.14 Call ( F, V [ , argumentsList ] ), https://tc39.es/ecma262/#sec-call
ThrowCompletionOr<Value> call_impl(GlobalObject& global_object, Value function, Value this_value, Optional<MarkedValueList> arguments_list)
ThrowCompletionOr<Value> call_impl(GlobalObject& global_object, Value function, Value this_value, Optional<MarkedVector<Value>> arguments_list)
{
auto& vm = global_object.vm();

// 1. If argumentsList is not present, set argumentsList to a new empty List.
if (!arguments_list.has_value())
arguments_list = MarkedValueList { global_object.heap() };
arguments_list = MarkedVector<Value> { global_object.heap() };

// 2. If IsCallable(F) is false, throw a TypeError exception.
if (!function.is_function())
Expand All @@ -60,11 +60,11 @@ ThrowCompletionOr<Value> call_impl(GlobalObject& global_object, Value function,
return function.as_function().internal_call(this_value, move(*arguments_list));
}

ThrowCompletionOr<Value> call_impl(GlobalObject& global_object, FunctionObject& function, Value this_value, Optional<MarkedValueList> arguments_list)
ThrowCompletionOr<Value> call_impl(GlobalObject& global_object, FunctionObject& function, Value this_value, Optional<MarkedVector<Value>> arguments_list)
{
// 1. If argumentsList is not present, set argumentsList to a new empty List.
if (!arguments_list.has_value())
arguments_list = MarkedValueList { global_object.heap() };
arguments_list = MarkedVector<Value> { global_object.heap() };

// 2. If IsCallable(F) is false, throw a TypeError exception.
// Note: Called with a FunctionObject ref
Expand All @@ -74,15 +74,15 @@ ThrowCompletionOr<Value> call_impl(GlobalObject& global_object, FunctionObject&
}

// 7.3.15 Construct ( F [ , argumentsList [ , newTarget ] ] ), https://tc39.es/ecma262/#sec-construct
ThrowCompletionOr<Object*> construct_impl(GlobalObject& global_object, FunctionObject& function, Optional<MarkedValueList> arguments_list, FunctionObject* new_target)
ThrowCompletionOr<Object*> construct_impl(GlobalObject& global_object, FunctionObject& function, Optional<MarkedVector<Value>> arguments_list, FunctionObject* new_target)
{
// 1. If newTarget is not present, set newTarget to F.
if (!new_target)
new_target = &function;

// 2. If argumentsList is not present, set argumentsList to a new empty List.
if (!arguments_list.has_value())
arguments_list = MarkedValueList { global_object.heap() };
arguments_list = MarkedVector<Value> { global_object.heap() };

// 3. Return ? F.[[Construct]](argumentsList, newTarget).
return function.internal_construct(move(*arguments_list), *new_target);
Expand All @@ -97,7 +97,7 @@ ThrowCompletionOr<size_t> length_of_array_like(GlobalObject& global_object, Obje
}

// 7.3.20 CreateListFromArrayLike ( obj [ , elementTypes ] ), https://tc39.es/ecma262/#sec-createlistfromarraylike
ThrowCompletionOr<MarkedValueList> create_list_from_array_like(GlobalObject& global_object, Value value, Function<ThrowCompletionOr<void>(Value)> check_value)
ThrowCompletionOr<MarkedVector<Value>> create_list_from_array_like(GlobalObject& global_object, Value value, Function<ThrowCompletionOr<void>(Value)> check_value)
{
auto& vm = global_object.vm();
auto& heap = global_object.heap();
Expand All @@ -114,7 +114,7 @@ ThrowCompletionOr<MarkedValueList> create_list_from_array_like(GlobalObject& glo
auto length = TRY(length_of_array_like(global_object, array_like));

// 4. Let list be a new empty List.
auto list = MarkedValueList { heap };
auto list = MarkedVector<Value> { heap };

// 5. Let index be 0.
// 6. Repeat, while index < len,
Expand Down
27 changes: 14 additions & 13 deletions Userland/Libraries/LibJS/Runtime/AbstractOperations.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <LibCrypto/Forward.h>
#include <LibJS/AST.h>
#include <LibJS/Forward.h>
#include <LibJS/Heap/MarkedVector.h>
#include <LibJS/Runtime/FunctionObject.h>
#include <LibJS/Runtime/GlobalObject.h>
#include <LibJS/Runtime/PrivateEnvironment.h>
Expand All @@ -25,11 +26,11 @@ Environment& get_this_environment(VM&);
Object* get_super_constructor(VM&);
ThrowCompletionOr<Reference> make_super_property_reference(GlobalObject&, Value actual_this, PropertyKey const&, bool strict);
ThrowCompletionOr<Value> require_object_coercible(GlobalObject&, Value);
ThrowCompletionOr<Value> call_impl(GlobalObject&, Value function, Value this_value, Optional<MarkedValueList> = {});
ThrowCompletionOr<Value> call_impl(GlobalObject&, FunctionObject& function, Value this_value, Optional<MarkedValueList> = {});
ThrowCompletionOr<Object*> construct_impl(GlobalObject&, FunctionObject&, Optional<MarkedValueList> = {}, FunctionObject* new_target = nullptr);
ThrowCompletionOr<Value> call_impl(GlobalObject&, Value function, Value this_value, Optional<MarkedVector<Value>> = {});
ThrowCompletionOr<Value> call_impl(GlobalObject&, FunctionObject& function, Value this_value, Optional<MarkedVector<Value>> = {});
ThrowCompletionOr<Object*> construct_impl(GlobalObject&, FunctionObject&, Optional<MarkedVector<Value>> = {}, FunctionObject* new_target = nullptr);
ThrowCompletionOr<size_t> length_of_array_like(GlobalObject&, Object const&);
ThrowCompletionOr<MarkedValueList> create_list_from_array_like(GlobalObject&, Value, Function<ThrowCompletionOr<void>(Value)> = {});
ThrowCompletionOr<MarkedVector<Value>> create_list_from_array_like(GlobalObject&, Value, Function<ThrowCompletionOr<void>(Value)> = {});
ThrowCompletionOr<FunctionObject*> species_constructor(GlobalObject&, Object const&, FunctionObject& default_constructor);
ThrowCompletionOr<Realm*> get_function_realm(GlobalObject&, FunctionObject const&);
ThrowCompletionOr<void> initialize_bound_name(GlobalObject&, FlyString const&, Value, Environment*);
Expand All @@ -54,12 +55,12 @@ ThrowCompletionOr<Value> perform_eval(Value, GlobalObject&, CallerMode, EvalMode
ThrowCompletionOr<void> eval_declaration_instantiation(VM& vm, GlobalObject& global_object, Program const& program, Environment* variable_environment, Environment* lexical_environment, PrivateEnvironment* private_environment, bool strict);

// 7.3.14 Call ( F, V [ , argumentsList ] ), https://tc39.es/ecma262/#sec-call
ALWAYS_INLINE ThrowCompletionOr<Value> call(GlobalObject& global_object, Value function, Value this_value, MarkedValueList arguments_list)
ALWAYS_INLINE ThrowCompletionOr<Value> call(GlobalObject& global_object, Value function, Value this_value, MarkedVector<Value> arguments_list)
{
return call_impl(global_object, function, this_value, move(arguments_list));
}

ALWAYS_INLINE ThrowCompletionOr<Value> call(GlobalObject& global_object, Value function, Value this_value, Optional<MarkedValueList> arguments_list)
ALWAYS_INLINE ThrowCompletionOr<Value> call(GlobalObject& global_object, Value function, Value this_value, Optional<MarkedVector<Value>> arguments_list)
{
return call_impl(global_object, function, this_value, move(arguments_list));
}
Expand All @@ -68,20 +69,20 @@ template<typename... Args>
ALWAYS_INLINE ThrowCompletionOr<Value> call(GlobalObject& global_object, Value function, Value this_value, Args&&... args)
{
if constexpr (sizeof...(Args) > 0) {
MarkedValueList arguments_list { global_object.heap() };
MarkedVector<Value> arguments_list { global_object.heap() };
(..., arguments_list.append(forward<Args>(args)));
return call_impl(global_object, function, this_value, move(arguments_list));
}

return call_impl(global_object, function, this_value);
}

ALWAYS_INLINE ThrowCompletionOr<Value> call(GlobalObject& global_object, FunctionObject& function, Value this_value, MarkedValueList arguments_list)
ALWAYS_INLINE ThrowCompletionOr<Value> call(GlobalObject& global_object, FunctionObject& function, Value this_value, MarkedVector<Value> arguments_list)
{
return call_impl(global_object, function, this_value, move(arguments_list));
}

ALWAYS_INLINE ThrowCompletionOr<Value> call(GlobalObject& global_object, FunctionObject& function, Value this_value, Optional<MarkedValueList> arguments_list)
ALWAYS_INLINE ThrowCompletionOr<Value> call(GlobalObject& global_object, FunctionObject& function, Value this_value, Optional<MarkedVector<Value>> arguments_list)
{
return call_impl(global_object, function, this_value, move(arguments_list));
}
Expand All @@ -90,7 +91,7 @@ template<typename... Args>
ALWAYS_INLINE ThrowCompletionOr<Value> call(GlobalObject& global_object, FunctionObject& function, Value this_value, Args&&... args)
{
if constexpr (sizeof...(Args) > 0) {
MarkedValueList arguments_list { global_object.heap() };
MarkedVector<Value> arguments_list { global_object.heap() };
(..., arguments_list.append(forward<Args>(args)));
return call_impl(global_object, function, this_value, move(arguments_list));
}
Expand All @@ -103,20 +104,20 @@ template<typename... Args>
ALWAYS_INLINE ThrowCompletionOr<Object*> construct(GlobalObject& global_object, FunctionObject& function, Args&&... args)
{
if constexpr (sizeof...(Args) > 0) {
MarkedValueList arguments_list { global_object.heap() };
MarkedVector<Value> arguments_list { global_object.heap() };
(..., arguments_list.append(forward<Args>(args)));
return construct_impl(global_object, function, move(arguments_list));
}

return construct_impl(global_object, function);
}

ALWAYS_INLINE ThrowCompletionOr<Object*> construct(GlobalObject& global_object, FunctionObject& function, MarkedValueList arguments_list, FunctionObject* new_target = nullptr)
ALWAYS_INLINE ThrowCompletionOr<Object*> construct(GlobalObject& global_object, FunctionObject& function, MarkedVector<Value> arguments_list, FunctionObject* new_target = nullptr)
{
return construct_impl(global_object, function, move(arguments_list), new_target);
}

ALWAYS_INLINE ThrowCompletionOr<Object*> construct(GlobalObject& global_object, FunctionObject& function, Optional<MarkedValueList> arguments_list, FunctionObject* new_target = nullptr)
ALWAYS_INLINE ThrowCompletionOr<Object*> construct(GlobalObject& global_object, FunctionObject& function, Optional<MarkedVector<Value>> arguments_list, FunctionObject* new_target = nullptr)
{
return construct_impl(global_object, function, move(arguments_list), new_target);
}
Expand Down
2 changes: 1 addition & 1 deletion Userland/Libraries/LibJS/Runtime/Array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ ThrowCompletionOr<bool> Array::internal_delete(PropertyKey const& property_key)
}

// NON-STANDARD: Used to inject the ephemeral length property's key
ThrowCompletionOr<MarkedValueList> Array::internal_own_property_keys() const
ThrowCompletionOr<MarkedVector<Value>> Array::internal_own_property_keys() const
{
auto& vm = this->vm();
auto keys = TRY(Object::internal_own_property_keys());
Expand Down
4 changes: 2 additions & 2 deletions Userland/Libraries/LibJS/Runtime/Array.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Array : public Object {
template<typename T>
static Array* create_from(GlobalObject& global_object, Span<T const> elements, Function<Value(T const&)> map_fn)
{
auto values = MarkedValueList { global_object.heap() };
auto values = MarkedVector<Value> { global_object.heap() };
values.ensure_capacity(elements.size());
for (auto const& element : elements)
values.append(map_fn(element));
Expand All @@ -40,7 +40,7 @@ class Array : public Object {
virtual ThrowCompletionOr<Optional<PropertyDescriptor>> internal_get_own_property(PropertyKey const&) const override;
virtual ThrowCompletionOr<bool> internal_define_own_property(PropertyKey const&, PropertyDescriptor const&) override;
virtual ThrowCompletionOr<bool> internal_delete(PropertyKey const&) override;
virtual ThrowCompletionOr<MarkedValueList> internal_own_property_keys() const override;
virtual ThrowCompletionOr<MarkedVector<Value>> internal_own_property_keys() const override;

[[nodiscard]] bool length_is_writable() const { return m_length_writable; };

Expand Down
Loading

0 comments on commit bc183db

Please sign in to comment.