mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 01:47:35 +00:00
LibJS: Remove GlobalObject from VM::throw_completion()
This is a continuation of the previous five commits. A first big step into the direction of no longer having to pass a realm (or currently, a global object) trough layers upon layers of AOs! Unlike the create() APIs we can safely assume that this is only ever called when a running execution context and therefore current realm exists. If not, you can always manually allocate the Error and put it in a Completion :^) In the spec, throw exceptions implicitly use the current realm's intrinsics as well: https://tc39.es/ecma262/#sec-throw-an-exception
This commit is contained in:
parent
5398dcc55e
commit
f3117d46dc
165 changed files with 892 additions and 900 deletions
|
@ -111,7 +111,7 @@ ThrowCompletionOr<Value> perform_shadow_realm_eval(GlobalObject& global_object,
|
|||
// b. If script is a List of errors, throw a SyntaxError exception.
|
||||
if (parser.has_errors()) {
|
||||
auto& error = parser.errors()[0];
|
||||
return vm.throw_completion<SyntaxError>(global_object, error.to_string());
|
||||
return vm.throw_completion<SyntaxError>(error.to_string());
|
||||
}
|
||||
|
||||
// c. If script Contains ScriptBody is false, return undefined.
|
||||
|
@ -197,7 +197,7 @@ ThrowCompletionOr<Value> perform_shadow_realm_eval(GlobalObject& global_object,
|
|||
|
||||
// 21. If result.[[Type]] is not normal, throw a TypeError exception.
|
||||
if (result.type() != Completion::Type::Normal)
|
||||
return vm.throw_completion<TypeError>(global_object, ErrorType::ShadowRealmEvaluateAbruptCompletion);
|
||||
return vm.throw_completion<TypeError>(ErrorType::ShadowRealmEvaluateAbruptCompletion);
|
||||
|
||||
// 22. Return ? GetWrappedValue(callerRealm, result.[[Value]]).
|
||||
return get_wrapped_value(global_object, caller_realm, *result.value());
|
||||
|
@ -251,7 +251,7 @@ ThrowCompletionOr<Value> shadow_realm_import_value(GlobalObject& global_object,
|
|||
|
||||
// 6. If hasOwn is false, throw a TypeError exception.
|
||||
if (!has_own)
|
||||
return vm.template throw_completion<TypeError>(global_object, ErrorType::MissingRequiredProperty, string);
|
||||
return vm.template throw_completion<TypeError>(ErrorType::MissingRequiredProperty, string);
|
||||
|
||||
// 7. Let value be ? Get(exports, string).
|
||||
auto value = TRY(exports.get(string));
|
||||
|
@ -273,8 +273,8 @@ ThrowCompletionOr<Value> shadow_realm_import_value(GlobalObject& global_object,
|
|||
|
||||
// NOTE: Even though the spec tells us to use %ThrowTypeError%, it's not observable if we actually do.
|
||||
// Throw a nicer TypeError forwarding the import error message instead (we know the argument is an Error object).
|
||||
auto* throw_type_error = NativeFunction::create(realm, {}, [](auto& vm, auto& global_object) -> ThrowCompletionOr<Value> {
|
||||
return vm.template throw_completion<TypeError>(global_object, vm.argument(0).as_object().get_without_side_effects(vm.names.message).as_string().string());
|
||||
auto* throw_type_error = NativeFunction::create(realm, {}, [](auto& vm, auto&) -> ThrowCompletionOr<Value> {
|
||||
return vm.template throw_completion<TypeError>(vm.argument(0).as_object().get_without_side_effects(vm.names.message).as_string().string());
|
||||
});
|
||||
|
||||
// 13. Return PerformPromiseThen(innerCapability.[[Promise]], onFulfilled, callerRealm.[[Intrinsics]].[[%ThrowTypeError%]], promiseCapability).
|
||||
|
@ -291,7 +291,7 @@ ThrowCompletionOr<Value> get_wrapped_value(GlobalObject& global_object, Realm& c
|
|||
if (value.is_object()) {
|
||||
// a. If IsCallable(value) is false, throw a TypeError exception.
|
||||
if (!value.is_function())
|
||||
return vm.throw_completion<TypeError>(global_object, ErrorType::ShadowRealmWrappedValueNonFunctionObject, value);
|
||||
return vm.throw_completion<TypeError>(ErrorType::ShadowRealmWrappedValueNonFunctionObject, value);
|
||||
|
||||
// b. Return ? WrappedFunctionCreate(callerRealm, value).
|
||||
return TRY(WrappedFunction::create(realm, caller_realm, value.as_function()));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue