diff --git a/integration-tests/js-compute/fixtures/app/src/console.js b/integration-tests/js-compute/fixtures/app/src/console.js index 6d6370419c..7eeb534e43 100644 --- a/integration-tests/js-compute/fixtures/app/src/console.js +++ b/integration-tests/js-compute/fixtures/app/src/console.js @@ -14,7 +14,7 @@ routes.set("/console", () => { console.log('Set:',arg) arg = [1, 2, 3, [], 5] console.log('Array:',arg) - arg = { a: 1, b: 2, c: 3, d(){}, get f(){return 1}, g: function bar() {} } + arg = { a: 1, b: 2, c: 3, d(){}, get f(){return 1}, g: function bar() {}, h: Array.from } console.log('Object:',arg) arg = function () { } console.log('function:',arg) diff --git a/integration-tests/js-compute/fixtures/app/tests.json b/integration-tests/js-compute/fixtures/app/tests.json index ceeb7221a2..9324fd037d 100644 --- a/integration-tests/js-compute/fixtures/app/tests.json +++ b/integration-tests/js-compute/fixtures/app/tests.json @@ -1043,11 +1043,11 @@ }, "logs": [ "stdout :: Log: Happy birthday Aki and Yuki!", - "stdout :: Log: Map: Map(2) { { a: 1, b: { c: 2 } } => 2, [Function foo] => {} }", + "stdout :: Log: Map: Map(2) { { a: 1, b: { c: 2 } } => 2, [ function foo() {\n }] => {} }", "stdout :: Log: Set: Set(3) { { a: 1, b: { c: 2 } }, 2, 3 }", "stdout :: Log: Array: [1, 2, 3, [], 5]", - "stdout :: Log: Object: { a: 1, b: 2, c: 3, d: [Function d], f: [Getter], g: [Function bar] }", - "stdout :: Log: function: [Function]", + "stdout :: Log: Object: { a: 1, b: 2, c: 3, d: [ d() {\n }], f: [Getter], g: [ function bar() {\n}], h: [ function from() {\n[native code]\n}] }", + "stdout :: Log: function: [ function() {\n }]", "stdout :: Log: boolean: true", "stdout :: Log: undefined: undefined", "stdout :: Log: null: null", @@ -1055,7 +1055,7 @@ "stdout :: Log: Infinity: Infinity", "stdout :: Log: NaN: NaN", "stdout :: Log: Symbol: Symbol(\"wow\")", - "stdout :: Log: Error: (new Error(\"uh oh\", \"\", 40))", + "stdout :: Log: Error: (new Error(\"uh oh\", \"\", 7644))", "stdout :: Log: Number: 1", "stdout :: Log: Number: 1.111", "stdout :: Log: BigInt: 10n", @@ -1077,9 +1077,9 @@ "stdout :: Log: WeakSet: WeakSet { }", "stdout :: Log: Promise: Promise { }", "stdout :: Log: resolved promise: Promise { 9 }", - "stdout :: Log: rejected promise: Promise { (new Error(\"oops\", \"\", 85)) }", + "stdout :: Log: rejected promise: Promise { (new Error(\"oops\", \"\", 7689)) }", "stdout :: Log: Response: Response { redirected: false, type: \"default\", url: \"\", status: 200, ok: true, statusText: \"\", version: 2, headers: Headers {}, body: ReadableStream { locked: false }, bodyUsed: false }", - "stdout :: Log: Request: Request { method: \"POST\", url: \"https://www.fastly.com/\", version: 2, headers: Headers {}, body: null, bodyUsed: false }", + "stdout :: Log: Request: Request { method: \"POST\", url: \"https://www.fastly.com/\", version: 2, headers: Headers {}, backend: undefined, body: null, bodyUsed: false }", "stdout :: Log: ReadableStream: ReadableStream { locked: false }", "stdout :: Log: TransformStream: TransformStream { readable: ReadableStream { locked: false }, writable: WritableStream {} }", "stdout :: Log: WritableStream: WritableStream {}", diff --git a/runtime/js-compute-runtime/builtins/shared/console.cpp b/runtime/js-compute-runtime/builtins/shared/console.cpp index df3199dbfa..3a3092f31d 100644 --- a/runtime/js-compute-runtime/builtins/shared/console.cpp +++ b/runtime/js-compute-runtime/builtins/shared/console.cpp @@ -286,19 +286,16 @@ JS::Result ToSource(JSContext *cx, std::string &sourceOut, JS::Hand JS::RootedObject obj(cx, &val.toObject()); if (JS_ObjectIsFunction(obj)) { - sourceOut += "[Function"; + sourceOut += "["; std::string source; JS::Rooted fun(cx, JS_ValueToFunction(cx, val)); if (fun) { - JS::RootedString name(cx); - if (!JS_GetFunctionId(cx, fun, &name)) { + JS::RootedString result(cx, JS_DecompileFunction(cx, fun)); + if (!result) { return JS::Result(JS::Error()); } - if (!name) { - name = JS_AtomizeAndPinString(cx, ""); - } sourceOut += " "; - auto msg = core::encode(cx, name); + auto msg = core::encode(cx, result); if (!msg) { return JS::Result(JS::Error()); }