summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS
diff options
context:
space:
mode:
authorLuke Wilde <lukew@serenityos.org>2023-02-27 22:42:40 +0000
committerLinus Groh <mail@linusgroh.de>2023-02-27 23:57:08 +0000
commit53852452b2a31cb0b26ff2af0c232e3e85465e59 (patch)
tree68178ba2d263576f06a872108722e4ea0c835f22 /Userland/Libraries/LibJS
parentaf118f2a679a7f21ca9389d1e2ae79f33fbf896a (diff)
downloadserenity-53852452b2a31cb0b26ff2af0c232e3e85465e59.zip
LibJS: Propagate errors from Intrinsics initialization
Diffstat (limited to 'Userland/Libraries/LibJS')
-rw-r--r--Userland/Libraries/LibJS/Contrib/Test262/$262Object.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intrinsics.cpp12
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intrinsics.h4
-rw-r--r--Userland/Libraries/LibJS/Runtime/Realm.cpp6
-rw-r--r--Userland/Libraries/LibJS/Runtime/Realm.h2
-rw-r--r--Userland/Libraries/LibJS/Runtime/ShadowRealmConstructor.cpp2
6 files changed, 15 insertions, 13 deletions
diff --git a/Userland/Libraries/LibJS/Contrib/Test262/$262Object.cpp b/Userland/Libraries/LibJS/Contrib/Test262/$262Object.cpp
index 26dd2266f3..148fa807fb 100644
--- a/Userland/Libraries/LibJS/Contrib/Test262/$262Object.cpp
+++ b/Userland/Libraries/LibJS/Contrib/Test262/$262Object.cpp
@@ -60,7 +60,7 @@ JS_DEFINE_NATIVE_FUNCTION($262Object::clear_kept_objects)
JS_DEFINE_NATIVE_FUNCTION($262Object::create_realm)
{
- auto realm = Realm::create(vm);
+ auto realm = MUST_OR_THROW_OOM(Realm::create(vm));
auto realm_global_object = vm.heap().allocate_without_realm<GlobalObject>(*realm);
VERIFY(realm_global_object);
realm->set_global_object(realm_global_object, nullptr);
diff --git a/Userland/Libraries/LibJS/Runtime/Intrinsics.cpp b/Userland/Libraries/LibJS/Runtime/Intrinsics.cpp
index aa88e07431..426386674d 100644
--- a/Userland/Libraries/LibJS/Runtime/Intrinsics.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intrinsics.cpp
@@ -136,7 +136,7 @@ static void initialize_constructor(VM& vm, PropertyKey const& property_key, Obje
}
// 9.3.2 CreateIntrinsics ( realmRec ), https://tc39.es/ecma262/#sec-createintrinsics
-NonnullGCPtr<Intrinsics> Intrinsics::create(Realm& realm)
+ThrowCompletionOr<NonnullGCPtr<Intrinsics>> Intrinsics::create(Realm& realm)
{
auto& vm = realm.vm();
@@ -158,7 +158,7 @@ NonnullGCPtr<Intrinsics> Intrinsics::create(Realm& realm)
// is the specified value of the function's [[Prototype]] internal slot. The
// creation of the intrinsics and their properties must be ordered to avoid
// any dependencies upon objects that have not yet been created.
- intrinsics->initialize_intrinsics(realm);
+ MUST_OR_THROW_OOM(intrinsics->initialize_intrinsics(realm));
// 3. Perform AddRestrictedFunctionProperties(realmRec.[[Intrinsics]].[[%Function.prototype%]], realmRec).
add_restricted_function_properties(static_cast<FunctionObject&>(*realm.intrinsics().function_prototype()), realm);
@@ -167,7 +167,7 @@ NonnullGCPtr<Intrinsics> Intrinsics::create(Realm& realm)
return *intrinsics;
}
-void Intrinsics::initialize_intrinsics(Realm& realm)
+ThrowCompletionOr<void> Intrinsics::initialize_intrinsics(Realm& realm)
{
auto& vm = this->vm();
@@ -184,8 +184,8 @@ void Intrinsics::initialize_intrinsics(Realm& realm)
m_new_ordinary_function_prototype_object_shape->add_property_without_transition(vm.names.constructor, Attribute::Writable | Attribute::Configurable);
// Normally Heap::allocate() takes care of this, but these are allocated via allocate_without_realm().
- static_cast<FunctionPrototype*>(m_function_prototype)->initialize(realm);
- static_cast<ObjectPrototype*>(m_object_prototype)->initialize(realm);
+ MUST_OR_THROW_OOM(static_cast<FunctionPrototype*>(m_function_prototype)->initialize(realm));
+ MUST_OR_THROW_OOM(static_cast<ObjectPrototype*>(m_object_prototype)->initialize(realm));
#define __JS_ENUMERATE(ClassName, snake_name) \
VERIFY(!m_##snake_name##_prototype); \
@@ -255,6 +255,8 @@ void Intrinsics::initialize_intrinsics(Realm& realm)
m_json_parse_function = &json_object()->get_without_side_effects(vm.names.parse).as_function();
m_json_stringify_function = &json_object()->get_without_side_effects(vm.names.stringify).as_function();
m_object_prototype_to_string_function = &object_prototype()->get_without_side_effects(vm.names.toString).as_function();
+
+ return {};
}
template<typename T>
diff --git a/Userland/Libraries/LibJS/Runtime/Intrinsics.h b/Userland/Libraries/LibJS/Runtime/Intrinsics.h
index a0820fe614..cce9d9829b 100644
--- a/Userland/Libraries/LibJS/Runtime/Intrinsics.h
+++ b/Userland/Libraries/LibJS/Runtime/Intrinsics.h
@@ -15,7 +15,7 @@ class Intrinsics final : public Cell {
JS_CELL(Intrinsics, Cell);
public:
- static NonnullGCPtr<Intrinsics> create(Realm&);
+ static ThrowCompletionOr<NonnullGCPtr<Intrinsics>> create(Realm&);
Shape* empty_object_shape() { return m_empty_object_shape; }
@@ -98,7 +98,7 @@ private:
virtual void visit_edges(Visitor&) override;
- void initialize_intrinsics(Realm&);
+ ThrowCompletionOr<void> initialize_intrinsics(Realm&);
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
void initialize_##snake_name();
diff --git a/Userland/Libraries/LibJS/Runtime/Realm.cpp b/Userland/Libraries/LibJS/Runtime/Realm.cpp
index e5c3bf0ea3..c642387dfc 100644
--- a/Userland/Libraries/LibJS/Runtime/Realm.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Realm.cpp
@@ -15,13 +15,13 @@
namespace JS {
// 9.3.1 CreateRealm ( ), https://tc39.es/ecma262/#sec-createrealm
-NonnullGCPtr<Realm> Realm::create(VM& vm)
+ThrowCompletionOr<NonnullGCPtr<Realm>> Realm::create(VM& vm)
{
// 1. Let realmRec be a new Realm Record.
auto realm = vm.heap().allocate_without_realm<Realm>();
// 2. Perform CreateIntrinsics(realmRec).
- Intrinsics::create(*realm);
+ MUST_OR_THROW_OOM(Intrinsics::create(*realm));
// 3. Set realmRec.[[GlobalObject]] to undefined.
// 4. Set realmRec.[[GlobalEnv]] to undefined.
@@ -37,7 +37,7 @@ ThrowCompletionOr<NonnullOwnPtr<ExecutionContext>> Realm::initialize_host_define
DeferGC defer_gc(vm.heap());
// 1. Let realm be CreateRealm().
- auto realm = Realm::create(vm);
+ auto realm = MUST_OR_THROW_OOM(Realm::create(vm));
// 2. Let newContext be a new execution context.
auto new_context = make<ExecutionContext>(vm.heap());
diff --git a/Userland/Libraries/LibJS/Runtime/Realm.h b/Userland/Libraries/LibJS/Runtime/Realm.h
index e56f58f107..33a9666612 100644
--- a/Userland/Libraries/LibJS/Runtime/Realm.h
+++ b/Userland/Libraries/LibJS/Runtime/Realm.h
@@ -29,7 +29,7 @@ public:
virtual void visit_edges(Cell::Visitor&) { }
};
- static NonnullGCPtr<Realm> create(VM&);
+ static ThrowCompletionOr<NonnullGCPtr<Realm>> create(VM&);
static ThrowCompletionOr<NonnullOwnPtr<ExecutionContext>> initialize_host_defined_realm(VM&, Function<Object*(Realm&)> create_global_object, Function<Object*(Realm&)> create_global_this_value);
void set_global_object(Object* global_object, Object* this_value);
diff --git a/Userland/Libraries/LibJS/Runtime/ShadowRealmConstructor.cpp b/Userland/Libraries/LibJS/Runtime/ShadowRealmConstructor.cpp
index e4a9f65319..bfd28289c2 100644
--- a/Userland/Libraries/LibJS/Runtime/ShadowRealmConstructor.cpp
+++ b/Userland/Libraries/LibJS/Runtime/ShadowRealmConstructor.cpp
@@ -44,7 +44,7 @@ ThrowCompletionOr<NonnullGCPtr<Object>> ShadowRealmConstructor::construct(Functi
auto& vm = this->vm();
// 3. Let realmRec be CreateRealm().
- auto realm = Realm::create(vm);
+ auto realm = MUST_OR_THROW_OOM(Realm::create(vm));
// 5. Let context be a new execution context.
auto context = ExecutionContext { vm.heap() };