mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 20:15:17 +00:00
LibJS: Throw TypeError when calling non-function object
We now have "undefined is not a function" :^)
This commit is contained in:
parent
d4e3688f4f
commit
fb0401871c
Notes:
sideshowbarker
2024-07-19 08:03:07 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/fb0401871cd Pull-request: https://github.com/SerenityOS/serenity/pull/1537
2 changed files with 34 additions and 2 deletions
|
@ -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();
|
||||
|
|
31
Libraries/LibJS/Tests/function-TypeError.js
Normal file
31
Libraries/LibJS/Tests/function-TypeError.js
Normal file
|
@ -0,0 +1,31 @@
|
|||
function assert(x) { if (!x) throw 1; }
|
||||
|
||||
try {
|
||||
try {
|
||||
var b = true;
|
||||
b();
|
||||
} catch(e) {
|
||||
assert(e.name === "TypeError");
|
||||
assert(e.message === "true is not a function");
|
||||
}
|
||||
|
||||
try {
|
||||
var n = 100 + 20 + 3;
|
||||
n();
|
||||
} catch(e) {
|
||||
assert(e.name === "TypeError");
|
||||
assert(e.message === "123 is not a function");
|
||||
}
|
||||
|
||||
try {
|
||||
var o = {};
|
||||
o.a();
|
||||
} catch(e) {
|
||||
assert(e.name === "TypeError");
|
||||
assert(e.message === "undefined is not a function");
|
||||
}
|
||||
|
||||
console.log("PASS");
|
||||
} catch(e) {
|
||||
console.log("FAIL: " + e);
|
||||
}
|
Loading…
Add table
Reference in a new issue