mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 03:27:45 +00:00
LibJS: Replace GlobalObject with VM in ShadowRealm AOs [Part 16/19]
This commit is contained in:
parent
d69eaf8be9
commit
ab6796691f
5 changed files with 22 additions and 28 deletions
|
@ -108,7 +108,7 @@ JS_DEFINE_NATIVE_FUNCTION(FunctionPrototype::bind)
|
||||||
auto arg_count = vm.argument_count() > 0 ? vm.argument_count() - 1 : 0;
|
auto arg_count = vm.argument_count() > 0 ? vm.argument_count() - 1 : 0;
|
||||||
|
|
||||||
// 5. Perform ? CopyNameAndLength(F, Target, "bound", argCount).
|
// 5. Perform ? CopyNameAndLength(F, Target, "bound", argCount).
|
||||||
TRY(copy_name_and_length(global_object, *function, target, "bound"sv, arg_count));
|
TRY(copy_name_and_length(vm, *function, target, "bound"sv, arg_count));
|
||||||
|
|
||||||
// 6. Return F.
|
// 6. Return F.
|
||||||
return function;
|
return function;
|
||||||
|
|
|
@ -34,10 +34,8 @@ void ShadowRealm::visit_edges(Visitor& visitor)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3.1.2 CopyNameAndLength ( F: a function object, Target: a function object, optional prefix: a String, optional argCount: a Number, ), https://tc39.es/proposal-shadowrealm/#sec-copynameandlength
|
// 3.1.2 CopyNameAndLength ( F: a function object, Target: a function object, optional prefix: a String, optional argCount: a Number, ), https://tc39.es/proposal-shadowrealm/#sec-copynameandlength
|
||||||
ThrowCompletionOr<void> copy_name_and_length(GlobalObject& global_object, FunctionObject& function, FunctionObject& target, Optional<StringView> prefix, Optional<unsigned> arg_count)
|
ThrowCompletionOr<void> copy_name_and_length(VM& vm, FunctionObject& function, FunctionObject& target, Optional<StringView> prefix, Optional<unsigned> arg_count)
|
||||||
{
|
{
|
||||||
auto& vm = global_object.vm();
|
|
||||||
|
|
||||||
// 1. If argCount is undefined, then set argCount to 0.
|
// 1. If argCount is undefined, then set argCount to 0.
|
||||||
if (!arg_count.has_value())
|
if (!arg_count.has_value())
|
||||||
arg_count = 0;
|
arg_count = 0;
|
||||||
|
@ -94,10 +92,8 @@ ThrowCompletionOr<void> copy_name_and_length(GlobalObject& global_object, Functi
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3.1.3 PerformShadowRealmEval ( sourceText: a String, callerRealm: a Realm Record, evalRealm: a Realm Record, ), https://tc39.es/proposal-shadowrealm/#sec-performshadowrealmeval
|
// 3.1.3 PerformShadowRealmEval ( sourceText: a String, callerRealm: a Realm Record, evalRealm: a Realm Record, ), https://tc39.es/proposal-shadowrealm/#sec-performshadowrealmeval
|
||||||
ThrowCompletionOr<Value> perform_shadow_realm_eval(GlobalObject& global_object, StringView source_text, Realm& caller_realm, Realm& eval_realm)
|
ThrowCompletionOr<Value> perform_shadow_realm_eval(VM& vm, StringView source_text, Realm& caller_realm, Realm& eval_realm)
|
||||||
{
|
{
|
||||||
auto& vm = global_object.vm();
|
|
||||||
|
|
||||||
// FIXME: Needs to be updated to latest ECMA-262. See: https://github.com/tc39/proposal-shadowrealm/issues/367
|
// FIXME: Needs to be updated to latest ECMA-262. See: https://github.com/tc39/proposal-shadowrealm/issues/367
|
||||||
// 1. Perform ? HostEnsureCanCompileStrings(callerRealm, evalRealm).
|
// 1. Perform ? HostEnsureCanCompileStrings(callerRealm, evalRealm).
|
||||||
TRY(vm.host_ensure_can_compile_strings(eval_realm));
|
TRY(vm.host_ensure_can_compile_strings(eval_realm));
|
||||||
|
@ -200,21 +196,20 @@ ThrowCompletionOr<Value> perform_shadow_realm_eval(GlobalObject& global_object,
|
||||||
return vm.throw_completion<TypeError>(ErrorType::ShadowRealmEvaluateAbruptCompletion);
|
return vm.throw_completion<TypeError>(ErrorType::ShadowRealmEvaluateAbruptCompletion);
|
||||||
|
|
||||||
// 22. Return ? GetWrappedValue(callerRealm, result.[[Value]]).
|
// 22. Return ? GetWrappedValue(callerRealm, result.[[Value]]).
|
||||||
return get_wrapped_value(global_object, caller_realm, *result.value());
|
return get_wrapped_value(vm, caller_realm, *result.value());
|
||||||
|
|
||||||
// NOTE: Also see "Editor's Note" in the spec regarding the TypeError above.
|
// NOTE: Also see "Editor's Note" in the spec regarding the TypeError above.
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3.1.4 ShadowRealmImportValue ( specifierString: a String, exportNameString: a String, callerRealm: a Realm Record, evalRealm: a Realm Record, evalContext: an execution context, ), https://tc39.es/proposal-shadowrealm/#sec-shadowrealmimportvalue
|
// 3.1.4 ShadowRealmImportValue ( specifierString: a String, exportNameString: a String, callerRealm: a Realm Record, evalRealm: a Realm Record, evalContext: an execution context, ), https://tc39.es/proposal-shadowrealm/#sec-shadowrealmimportvalue
|
||||||
ThrowCompletionOr<Value> shadow_realm_import_value(GlobalObject& global_object, String specifier_string, String export_name_string, Realm& caller_realm, Realm& eval_realm, ExecutionContext& eval_context)
|
ThrowCompletionOr<Value> shadow_realm_import_value(VM& vm, String specifier_string, String export_name_string, Realm& caller_realm, Realm& eval_realm, ExecutionContext& eval_context)
|
||||||
{
|
{
|
||||||
auto& vm = global_object.vm();
|
auto& realm = *vm.current_realm();
|
||||||
auto& realm = *global_object.associated_realm();
|
|
||||||
|
|
||||||
// 1. Assert: evalContext is an execution context associated to a ShadowRealm instance's [[ExecutionContext]].
|
// 1. Assert: evalContext is an execution context associated to a ShadowRealm instance's [[ExecutionContext]].
|
||||||
|
|
||||||
// 2. Let innerCapability be ! NewPromiseCapability(%Promise%).
|
// 2. Let innerCapability be ! NewPromiseCapability(%Promise%).
|
||||||
auto inner_capability = MUST(new_promise_capability(vm, global_object.promise_constructor()));
|
auto inner_capability = MUST(new_promise_capability(vm, realm.global_object().promise_constructor()));
|
||||||
|
|
||||||
// 3. Let runningContext be the running execution context.
|
// 3. Let runningContext be the running execution context.
|
||||||
// 4. If runningContext is not already suspended, suspend runningContext.
|
// 4. If runningContext is not already suspended, suspend runningContext.
|
||||||
|
@ -234,7 +229,7 @@ ThrowCompletionOr<Value> shadow_realm_import_value(GlobalObject& global_object,
|
||||||
// NOTE: We don't support this concept yet.
|
// NOTE: We don't support this concept yet.
|
||||||
|
|
||||||
// 9. Let steps be the steps of an ExportGetter function as described below.
|
// 9. Let steps be the steps of an ExportGetter function as described below.
|
||||||
auto steps = [string = move(export_name_string)](auto& vm, auto& global_object) -> ThrowCompletionOr<Value> {
|
auto steps = [string = move(export_name_string)](auto& vm, auto&) -> ThrowCompletionOr<Value> {
|
||||||
// 1. Assert: exports is a module namespace exotic object.
|
// 1. Assert: exports is a module namespace exotic object.
|
||||||
VERIFY(vm.argument(0).is_object());
|
VERIFY(vm.argument(0).is_object());
|
||||||
auto& exports = vm.argument(0).as_object();
|
auto& exports = vm.argument(0).as_object();
|
||||||
|
@ -261,7 +256,7 @@ ThrowCompletionOr<Value> shadow_realm_import_value(GlobalObject& global_object,
|
||||||
VERIFY(realm);
|
VERIFY(realm);
|
||||||
|
|
||||||
// 9. Return ? GetWrappedValue(realm, value).
|
// 9. Return ? GetWrappedValue(realm, value).
|
||||||
return get_wrapped_value(global_object, *realm, value);
|
return get_wrapped_value(vm, *realm, value);
|
||||||
};
|
};
|
||||||
|
|
||||||
// 10. Let onFulfilled be CreateBuiltinFunction(steps, 1, "", « [[ExportNameString]] », callerRealm).
|
// 10. Let onFulfilled be CreateBuiltinFunction(steps, 1, "", « [[ExportNameString]] », callerRealm).
|
||||||
|
@ -269,7 +264,7 @@ ThrowCompletionOr<Value> shadow_realm_import_value(GlobalObject& global_object,
|
||||||
auto* on_fulfilled = NativeFunction::create(realm, move(steps), 1, "", &caller_realm);
|
auto* on_fulfilled = NativeFunction::create(realm, move(steps), 1, "", &caller_realm);
|
||||||
|
|
||||||
// 12. Let promiseCapability be ! NewPromiseCapability(%Promise%).
|
// 12. Let promiseCapability be ! NewPromiseCapability(%Promise%).
|
||||||
auto promise_capability = MUST(new_promise_capability(vm, global_object.promise_constructor()));
|
auto promise_capability = MUST(new_promise_capability(vm, realm.global_object().promise_constructor()));
|
||||||
|
|
||||||
// NOTE: Even though the spec tells us to use %ThrowTypeError%, it's not observable if we actually do.
|
// 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).
|
// Throw a nicer TypeError forwarding the import error message instead (we know the argument is an Error object).
|
||||||
|
@ -282,10 +277,9 @@ ThrowCompletionOr<Value> shadow_realm_import_value(GlobalObject& global_object,
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3.1.5 GetWrappedValue ( callerRealm: a Realm Record, value: unknown, ), https://tc39.es/proposal-shadowrealm/#sec-getwrappedvalue
|
// 3.1.5 GetWrappedValue ( callerRealm: a Realm Record, value: unknown, ), https://tc39.es/proposal-shadowrealm/#sec-getwrappedvalue
|
||||||
ThrowCompletionOr<Value> get_wrapped_value(GlobalObject& global_object, Realm& caller_realm, Value value)
|
ThrowCompletionOr<Value> get_wrapped_value(VM& vm, Realm& caller_realm, Value value)
|
||||||
{
|
{
|
||||||
auto& vm = global_object.vm();
|
auto& realm = *vm.current_realm();
|
||||||
auto& realm = *global_object.associated_realm();
|
|
||||||
|
|
||||||
// 1. If Type(value) is Object, then
|
// 1. If Type(value) is Object, then
|
||||||
if (value.is_object()) {
|
if (value.is_object()) {
|
||||||
|
|
|
@ -33,9 +33,9 @@ private:
|
||||||
ExecutionContext m_execution_context; // [[ExecutionContext]]
|
ExecutionContext m_execution_context; // [[ExecutionContext]]
|
||||||
};
|
};
|
||||||
|
|
||||||
ThrowCompletionOr<void> copy_name_and_length(GlobalObject&, FunctionObject& function, FunctionObject& target, Optional<StringView> prefix = {}, Optional<unsigned> arg_count = {});
|
ThrowCompletionOr<void> copy_name_and_length(VM&, FunctionObject& function, FunctionObject& target, Optional<StringView> prefix = {}, Optional<unsigned> arg_count = {});
|
||||||
ThrowCompletionOr<Value> perform_shadow_realm_eval(GlobalObject&, StringView source_text, Realm& caller_realm, Realm& eval_realm);
|
ThrowCompletionOr<Value> perform_shadow_realm_eval(VM&, StringView source_text, Realm& caller_realm, Realm& eval_realm);
|
||||||
ThrowCompletionOr<Value> shadow_realm_import_value(GlobalObject&, String specifier_string, String export_name_string, Realm& caller_realm, Realm& eval_realm, ExecutionContext& eval_context);
|
ThrowCompletionOr<Value> shadow_realm_import_value(VM&, String specifier_string, String export_name_string, Realm& caller_realm, Realm& eval_realm, ExecutionContext& eval_context);
|
||||||
ThrowCompletionOr<Value> get_wrapped_value(GlobalObject&, Realm& caller_realm, Value);
|
ThrowCompletionOr<Value> get_wrapped_value(VM&, Realm& caller_realm, Value);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@ JS_DEFINE_NATIVE_FUNCTION(ShadowRealmPrototype::evaluate)
|
||||||
auto& eval_realm = object->shadow_realm();
|
auto& eval_realm = object->shadow_realm();
|
||||||
|
|
||||||
// 6. Return ? PerformShadowRealmEval(sourceText, callerRealm, evalRealm).
|
// 6. Return ? PerformShadowRealmEval(sourceText, callerRealm, evalRealm).
|
||||||
return perform_shadow_realm_eval(global_object, source_text.as_string().string(), *caller_realm, eval_realm);
|
return perform_shadow_realm_eval(vm, source_text.as_string().string(), *caller_realm, eval_realm);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3.4.2 ShadowRealm.prototype.importValue ( specifier, exportName ), https://tc39.es/proposal-shadowrealm/#sec-shadowrealm.prototype.importvalue
|
// 3.4.2 ShadowRealm.prototype.importValue ( specifier, exportName ), https://tc39.es/proposal-shadowrealm/#sec-shadowrealm.prototype.importvalue
|
||||||
|
@ -79,7 +79,7 @@ JS_DEFINE_NATIVE_FUNCTION(ShadowRealmPrototype::import_value)
|
||||||
auto& eval_context = object->execution_context();
|
auto& eval_context = object->execution_context();
|
||||||
|
|
||||||
// 8. Return ? ShadowRealmImportValue(specifierString, exportNameString, callerRealm, evalRealm, evalContext).
|
// 8. Return ? ShadowRealmImportValue(specifierString, exportNameString, callerRealm, evalRealm, evalContext).
|
||||||
return shadow_realm_import_value(global_object, move(specifier_string), export_name.as_string().string(), *caller_realm, eval_realm, eval_context);
|
return shadow_realm_import_value(vm, move(specifier_string), export_name.as_string().string(), *caller_realm, eval_realm, eval_context);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ ThrowCompletionOr<WrappedFunction*> WrappedFunction::create(Realm& realm, Realm&
|
||||||
auto* wrapped = vm.heap().allocate<WrappedFunction>(realm, caller_realm, target, prototype);
|
auto* wrapped = vm.heap().allocate<WrappedFunction>(realm, caller_realm, target, prototype);
|
||||||
|
|
||||||
// 7. Let result be CopyNameAndLength(wrapped, Target).
|
// 7. Let result be CopyNameAndLength(wrapped, Target).
|
||||||
auto result = copy_name_and_length(realm.global_object(), *wrapped, target);
|
auto result = copy_name_and_length(vm, *wrapped, target);
|
||||||
|
|
||||||
// 8. If result is an Abrupt Completion, throw a TypeError exception.
|
// 8. If result is an Abrupt Completion, throw a TypeError exception.
|
||||||
if (result.is_throw_completion())
|
if (result.is_throw_completion())
|
||||||
|
@ -106,14 +106,14 @@ ThrowCompletionOr<Value> ordinary_wrapped_function_call(WrappedFunction const& f
|
||||||
// 7. For each element arg of argumentsList, do
|
// 7. For each element arg of argumentsList, do
|
||||||
for (auto const& arg : arguments_list) {
|
for (auto const& arg : arguments_list) {
|
||||||
// a. Let wrappedValue be ? GetWrappedValue(targetRealm, arg).
|
// a. Let wrappedValue be ? GetWrappedValue(targetRealm, arg).
|
||||||
auto wrapped_value = TRY(get_wrapped_value(global_object, *target_realm, arg));
|
auto wrapped_value = TRY(get_wrapped_value(vm, *target_realm, arg));
|
||||||
|
|
||||||
// b. Append wrappedValue to wrappedArgs.
|
// b. Append wrappedValue to wrappedArgs.
|
||||||
wrapped_args.append(wrapped_value);
|
wrapped_args.append(wrapped_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 8. Let wrappedThisArgument to ? GetWrappedValue(targetRealm, thisArgument).
|
// 8. Let wrappedThisArgument to ? GetWrappedValue(targetRealm, thisArgument).
|
||||||
auto wrapped_this_argument = TRY(get_wrapped_value(global_object, *target_realm, this_argument));
|
auto wrapped_this_argument = TRY(get_wrapped_value(vm, *target_realm, this_argument));
|
||||||
|
|
||||||
// 9. Let result be the Completion Record of Call(target, wrappedThisArgument, wrappedArgs).
|
// 9. Let result be the Completion Record of Call(target, wrappedThisArgument, wrappedArgs).
|
||||||
auto result = call(global_object, &target, wrapped_this_argument, move(wrapped_args));
|
auto result = call(global_object, &target, wrapped_this_argument, move(wrapped_args));
|
||||||
|
@ -121,7 +121,7 @@ ThrowCompletionOr<Value> ordinary_wrapped_function_call(WrappedFunction const& f
|
||||||
// 10. If result.[[Type]] is normal or result.[[Type]] is return, then
|
// 10. If result.[[Type]] is normal or result.[[Type]] is return, then
|
||||||
if (!result.is_throw_completion()) {
|
if (!result.is_throw_completion()) {
|
||||||
// a. Return ? GetWrappedValue(callerRealm, result.[[Value]]).
|
// a. Return ? GetWrappedValue(callerRealm, result.[[Value]]).
|
||||||
return get_wrapped_value(global_object, *caller_realm, result.value());
|
return get_wrapped_value(vm, *caller_realm, result.value());
|
||||||
}
|
}
|
||||||
// 11. Else,
|
// 11. Else,
|
||||||
else {
|
else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue