diff options
author | Linus Groh <mail@linusgroh.de> | 2022-02-12 16:06:37 +0000 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-02-12 16:06:37 +0000 |
commit | c08a52dd9751a5e95628027c205887a136868fdd (patch) | |
tree | 8645b717bce7ab5e43f661a50a66f1b94224b2e7 | |
parent | 16aeb8b51da818b2e31c41f7f5aa171f5ccdc0af (diff) | |
download | serenity-c08a52dd9751a5e95628027c205887a136868fdd.zip |
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
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<void> copy_name_and_length(GlobalObject& global_object, FunctionObject& function, FunctionObject& target, StringView prefix, Optional<unsigned> 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<void> copy_name_and_length(GlobalObject& global_object, FunctionObject& function, FunctionObject& target, Optional<StringView> prefix, Optional<unsigned> arg_count) { auto& vm = global_object.vm(); @@ -87,7 +87,7 @@ ThrowCompletionOr<void> 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<void> copy_name_and_length(GlobalObject&, FunctionObject& function, FunctionObject& target, StringView prefix, Optional<unsigned> arg_count = {}); +ThrowCompletionOr<void> copy_name_and_length(GlobalObject&, 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> shadow_realm_import_value(GlobalObject&, 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); 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*> WrappedFunction::create(GlobalObject& global auto& prototype = *caller_realm.global_object().function_prototype(); auto* wrapped = global_object.heap().allocate<WrappedFunction>(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( |