From c08a52dd9751a5e95628027c205887a136868fdd Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Sat, 12 Feb 2022 16:06:37 +0000 Subject: [PATCH] LibJS: Remove the name prefix for wrapped functions This is a normative change in the ShadowRealm spec. See: https://github.com/tc39/proposal-shadowrealm/commit/4ca634a --- Userland/Libraries/LibJS/Runtime/ShadowRealm.cpp | 6 +++--- Userland/Libraries/LibJS/Runtime/ShadowRealm.h | 2 +- Userland/Libraries/LibJS/Runtime/WrappedFunction.cpp | 4 ++-- .../builtins/ShadowRealm/ShadowRealm.prototype.evaluate.js | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/ShadowRealm.cpp b/Userland/Libraries/LibJS/Runtime/ShadowRealm.cpp index 25da802af7..90bac0c2cc 100644 --- a/Userland/Libraries/LibJS/Runtime/ShadowRealm.cpp +++ b/Userland/Libraries/LibJS/Runtime/ShadowRealm.cpp @@ -32,8 +32,8 @@ void ShadowRealm::visit_edges(Visitor& visitor) visitor.visit(&m_shadow_realm); } -// 3.1.2 CopyNameAndLength ( F: a function object, Target: a function object, prefix: a String, optional argCount: a Number, ), https://tc39.es/proposal-shadowrealm/#sec-copynameandlength -ThrowCompletionOr copy_name_and_length(GlobalObject& global_object, FunctionObject& function, FunctionObject& target, StringView prefix, Optional arg_count) +// 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 copy_name_and_length(GlobalObject& global_object, FunctionObject& function, FunctionObject& target, Optional prefix, Optional arg_count) { auto& vm = global_object.vm(); @@ -87,7 +87,7 @@ ThrowCompletionOr copy_name_and_length(GlobalObject& global_object, Functi target_name = js_string(vm, String::empty()); // 8. Perform ! SetFunctionName(F, targetName, prefix). - function.set_function_name({ target_name.as_string().string() }, prefix); + function.set_function_name({ target_name.as_string().string() }, move(prefix)); return {}; } diff --git a/Userland/Libraries/LibJS/Runtime/ShadowRealm.h b/Userland/Libraries/LibJS/Runtime/ShadowRealm.h index a2c21b4914..a66886a9d9 100644 --- a/Userland/Libraries/LibJS/Runtime/ShadowRealm.h +++ b/Userland/Libraries/LibJS/Runtime/ShadowRealm.h @@ -33,7 +33,7 @@ private: ExecutionContext m_execution_context; // [[ExecutionContext]] }; -ThrowCompletionOr copy_name_and_length(GlobalObject&, FunctionObject& function, FunctionObject& target, StringView prefix, Optional arg_count = {}); +ThrowCompletionOr copy_name_and_length(GlobalObject&, FunctionObject& function, FunctionObject& target, Optional prefix = {}, Optional arg_count = {}); ThrowCompletionOr perform_shadow_realm_eval(GlobalObject&, StringView source_text, Realm& caller_realm, Realm& eval_realm); ThrowCompletionOr shadow_realm_import_value(GlobalObject&, String specifier_string, String export_name_string, Realm& caller_realm, Realm& eval_realm, ExecutionContext& eval_context); ThrowCompletionOr get_wrapped_value(GlobalObject&, Realm& caller_realm, Value); diff --git a/Userland/Libraries/LibJS/Runtime/WrappedFunction.cpp b/Userland/Libraries/LibJS/Runtime/WrappedFunction.cpp index a7edbeee0a..d15269de49 100644 --- a/Userland/Libraries/LibJS/Runtime/WrappedFunction.cpp +++ b/Userland/Libraries/LibJS/Runtime/WrappedFunction.cpp @@ -24,8 +24,8 @@ ThrowCompletionOr WrappedFunction::create(GlobalObject& global auto& prototype = *caller_realm.global_object().function_prototype(); auto* wrapped = global_object.heap().allocate(global_object, caller_realm, target, prototype); - // 7. Let result be CopyNameAndLength(wrapped, Target, "wrapped"). - auto result = copy_name_and_length(global_object, *wrapped, target, "wrapped"sv); + // 7. Let result be CopyNameAndLength(wrapped, Target). + auto result = copy_name_and_length(global_object, *wrapped, target); // 8. If result is an Abrupt Completion, throw a TypeError exception. if (result.is_throw_completion()) diff --git a/Userland/Libraries/LibJS/Tests/builtins/ShadowRealm/ShadowRealm.prototype.evaluate.js b/Userland/Libraries/LibJS/Tests/builtins/ShadowRealm/ShadowRealm.prototype.evaluate.js index e4d508380d..d441e68b9a 100644 --- a/Userland/Libraries/LibJS/Tests/builtins/ShadowRealm/ShadowRealm.prototype.evaluate.js +++ b/Userland/Libraries/LibJS/Tests/builtins/ShadowRealm/ShadowRealm.prototype.evaluate.js @@ -46,8 +46,8 @@ describe("normal behavior", () => { expect(typeof wrappedFunction).toBe("function"); expect(Object.getPrototypeOf(wrappedFunction)).toBe(Function.prototype); - expect(shadowRealm.evaluate("(function () {})").name).toBe("wrapped "); - expect(shadowRealm.evaluate("(function foo() {})").name).toBe("wrapped foo"); + expect(shadowRealm.evaluate("(function () {})").name).toBe(""); + expect(shadowRealm.evaluate("(function foo() {})").name).toBe("foo"); expect(shadowRealm.evaluate("(function () {})")).toHaveLength(0); expect(shadowRealm.evaluate("(function (foo, bar) {})")).toHaveLength(2); expect(