From 8159f45f6ee1ddc551df82a2102f6bc9bc9059af Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Wed, 29 Apr 2020 18:06:36 +0100 Subject: [PATCH] LibJS: Make String.prototype.slice() generic --- Libraries/LibJS/Runtime/StringPrototype.cpp | 6 ++---- Libraries/LibJS/Tests/String.prototype-generic-functions.js | 1 + 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Libraries/LibJS/Runtime/StringPrototype.cpp b/Libraries/LibJS/Runtime/StringPrototype.cpp index fda0f2cce6..6fe439fe0b 100644 --- a/Libraries/LibJS/Runtime/StringPrototype.cpp +++ b/Libraries/LibJS/Runtime/StringPrototype.cpp @@ -388,12 +388,10 @@ Value StringPrototype::includes(Interpreter& interpreter) Value StringPrototype::slice(Interpreter& interpreter) { - auto* string_object = string_object_from(interpreter); - if (!string_object) + auto string = string_from(interpreter); + if (string.is_null()) return {}; - auto& string = string_object->primitive_string().string(); - if (interpreter.argument_count() == 0) return js_string(interpreter, string); diff --git a/Libraries/LibJS/Tests/String.prototype-generic-functions.js b/Libraries/LibJS/Tests/String.prototype-generic-functions.js index 776fb208dd..2975f84a9c 100644 --- a/Libraries/LibJS/Tests/String.prototype-generic-functions.js +++ b/Libraries/LibJS/Tests/String.prototype-generic-functions.js @@ -16,6 +16,7 @@ try { "concat", "substring", "includes", + "slice", ]; genericStringPrototypeFunctions.forEach(name => {