Skip to content

Commit a742d97

Browse files
Jake ChampionJakeChampion
authored andcommitted
allow arbitrary amount of parameters passed to the console methods
This gets us closer to following the spec at https://console.spec.whatwg.org/#logger
1 parent 8731609 commit a742d97

File tree

4 files changed

+43
-5
lines changed

4 files changed

+43
-5
lines changed

c-dependencies/js-compute-runtime/builtins/console.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,22 @@ namespace Console {
44
template <const char *prefix, uint8_t prefix_len>
55
static bool console_out(JSContext *cx, unsigned argc, JS::Value *vp) {
66
JS::CallArgs args = CallArgsFromVp(argc, vp);
7-
size_t msg_len;
8-
JS::UniqueChars msg = encode(cx, args.get(0), &msg_len);
9-
if (!msg)
10-
return false;
7+
std::string message = "";
8+
auto length = args.length();
9+
for (int i = 0; i < length; i++) {
10+
size_t msg_len;
11+
JS::UniqueChars msg = encode(cx, args.get(i), &msg_len);
12+
if (!msg)
13+
return false;
14+
if (message.length()) {
15+
message += " ";
16+
message += msg.get();
17+
} else {
18+
message += msg.get();
19+
}
20+
}
1121

12-
printf("%s: %s\n", prefix, msg.get());
22+
printf("%s: %s\n", prefix, message.c_str());
1323
fflush(stdout);
1424

1525
args.rval().setUndefined();
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
addEventListener("fetch", () => console.log("Happy", "birthday", "Aki", "and", "Yuki!"));
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# This file describes a Fastly Compute@Edge package. To learn more visit:
2+
# https://developer.fastly.com/reference/fastly-toml/
3+
4+
authors = ["[email protected]"]
5+
description = ""
6+
language = "other"
7+
manifest_version = 2
8+
name = "console"
9+
service_id = ""
10+
11+
[scripts]
12+
build = "../../../../target/release/js-compute-runtime"
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"GET /": {
3+
"environments": ["viceroy"],
4+
"downstream_request": {
5+
"method": "GET",
6+
"pathname": "/"
7+
},
8+
"downstream_response": {
9+
"status": 200
10+
},
11+
"logs": [
12+
"stdout :: Log: Happy birthday Aki and Yuki!"
13+
]
14+
}
15+
}

0 commit comments

Comments
 (0)