diff options
author | Linus Groh <mail@linusgroh.de> | 2020-03-30 13:41:17 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-03-30 14:43:58 +0200 |
commit | fb0401871cdd5613500a45493ea697adaf6fa1df (patch) | |
tree | 6299058a556d2a96276e9a7d815c29256b2ec637 /Libraries/LibJS/AST.cpp | |
parent | d4e3688f4f5338ce5995a4c9bcce1e0bb961845f (diff) | |
download | serenity-fb0401871cdd5613500a45493ea697adaf6fa1df.zip |
LibJS: Throw TypeError when calling non-function object
We now have "undefined is not a function" :^)
Diffstat (limited to 'Libraries/LibJS/AST.cpp')
-rw-r--r-- | Libraries/LibJS/AST.cpp | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/Libraries/LibJS/AST.cpp b/Libraries/LibJS/AST.cpp index b3daa4eb3b..a20b90d028 100644 --- a/Libraries/LibJS/AST.cpp +++ b/Libraries/LibJS/AST.cpp @@ -66,8 +66,9 @@ Value CallExpression::execute(Interpreter& interpreter) const if (interpreter.exception()) return {}; - ASSERT(callee.is_object()); - ASSERT(callee.as_object()->is_function()); + if (!callee.is_object() || !callee.as_object()->is_function()) + return interpreter.throw_exception<Error>("TypeError", String::format("%s is not a function", callee.to_string().characters())); + auto* function = static_cast<Function*>(callee.as_object()); auto& call_frame = interpreter.push_call_frame(); |