From f9287fca1e1641a082988c9a7d7384bbe0a2c814 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Sun, 14 Mar 2021 19:00:53 +0100 Subject: [PATCH] LibJS: Don't try to derive function source from ProxyObject There are three JS::Function types that are not ScriptFunction: NativeFunction, BoundFunction and ProxyObject. We were only checking for the first two when determining whether to reconstruct the function's source code, which was leading to a bad cast to ScriptFunction. Since only ScriptFunction has the [[SourceText]] internal slot, I simply swapped the branches here. Fixes #5775. --- Userland/Libraries/LibJS/Runtime/FunctionPrototype.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/FunctionPrototype.cpp b/Userland/Libraries/LibJS/Runtime/FunctionPrototype.cpp index 972c5021ea..4cdc25964f 100644 --- a/Userland/Libraries/LibJS/Runtime/FunctionPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/FunctionPrototype.cpp @@ -146,12 +146,11 @@ JS_DEFINE_NATIVE_FUNCTION(FunctionPrototype::to_string) String function_parameters = ""; String function_body; - if (is(this_object) || is(this_object)) { - function_body = String::formatted(" [{}]", this_object->class_name()); - } else { + if (is(this_object)) { + auto& script_function = static_cast(*this_object); StringBuilder parameters_builder; auto first = true; - for (auto& parameter : static_cast(this_object)->parameters()) { + for (auto& parameter : script_function.parameters()) { if (!first) parameters_builder.append(", "); first = false; @@ -166,6 +165,8 @@ JS_DEFINE_NATIVE_FUNCTION(FunctionPrototype::to_string) // auto& body = static_cast(this_object)->body(); // function_body = body.to_source(); function_body = " ???"; + } else { + function_body = String::formatted(" [{}]", this_object->class_name()); } auto function_source = String::formatted(