Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions builtins/web/console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -471,9 +471,9 @@ static bool console_out(JSContext *cx, unsigned argc, JS::Value *vp) {
static bool assert_(JSContext *cx, unsigned argc, JS::Value *vp) {
JS::CallArgs args = CallArgsFromVp(argc, vp);
args.rval().setUndefined();
auto condition = args.get(0).toBoolean();
auto condition = JS::ToBoolean(args.get(0));
// 1. If condition is true, return.
if (!condition) {
if (condition) {
return true;
}

Expand Down
16 changes: 16 additions & 0 deletions tests/e2e/console-assert/console-assert.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// https://console.spec.whatwg.org/#assert
// console.assert must stay SILENT when the condition is truthy and only log
// "Assertion failed" when the condition is falsy. The condition is coerced to
// a boolean, so non-boolean values must be accepted too.
addEventListener("fetch", (event) => {
console.log("a");
console.assert(true); // truthy -> silent
console.log("b");
console.assert(false); // falsy -> logs "Assertion failed"
console.log("c");
console.assert(1); // truthy non-boolean -> silent
console.log("d");
console.assert(0); // falsy non-boolean -> logs "Assertion failed"
console.log("e");
event.respondWith(new Response("ok"));
});
7 changes: 7 additions & 0 deletions tests/e2e/console-assert/expect_serve_stdout.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
stdout [0] :: Log: a
stdout [0] :: Log: b
stdout [0] :: Error: Assertion failed
stdout [0] :: Log: c
stdout [0] :: Log: d
stdout [0] :: Error: Assertion failed
stdout [0] :: Log: e
1 change: 1 addition & 0 deletions tests/tests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ function(integration_tests)
endfunction()

test_e2e(blob)
test_e2e(console-assert)
test_e2e(eventloop-stall)
test_e2e(headers)
test_e2e(runtime-err)
Expand Down
Loading