mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 23:17:46 +00:00
LibJS: Propagate errors from Intrinsics initialization
This commit is contained in:
parent
af118f2a67
commit
53852452b2
6 changed files with 15 additions and 13 deletions
|
@ -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);
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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() };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue