mirror of
https://github.com/oven-sh/bun
synced 2026-02-13 12:29:07 +00:00
fix console.timeLog (#7089)
* fix console.timeLog * fix console.timeLog can log arguments * console timeLog test use bunEnv Co-authored-by: Ashcon Partovi <ashcon@partovi.net> * fix console timeLog test * Update console.timeLog Co-authored-by: dave caruso <me@paperdave.net> * Update test/js/web/console/console-timeLog.js Co-authored-by: Radhi Rasho <54078496+RadhiRasho@users.noreply.github.com> * Update console-timeLog.js * fix console-timeLog.js test * fix timeLog tests due to trailing comma PR --------- Co-authored-by: Ashcon Partovi <ashcon@partovi.net> Co-authored-by: dave caruso <me@paperdave.net> Co-authored-by: Radhi Rasho <54078496+RadhiRasho@users.noreply.github.com>
This commit is contained in:
Submodule src/bun.js/WebKit updated: 63d0e18c06...0aa1f6dfc9
@@ -86,7 +86,16 @@ void Zig::ConsoleClient::timeLog(JSGlobalObject* globalObject, const String& lab
|
||||
Ref<ScriptArguments>&& arguments)
|
||||
{
|
||||
auto input = label.tryGetUTF8().value();
|
||||
Zig__ConsoleClient__timeLog(this->m_client, globalObject, reinterpret_cast<const unsigned char*>(input.data()), input.length(), arguments.ptr());
|
||||
|
||||
auto args = arguments.ptr();
|
||||
JSC__JSValue jsArgs[255];
|
||||
auto count = std::min(args->argumentCount(), (size_t)255);
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
auto val = args->argumentAt(i);
|
||||
jsArgs[i] = JSC::JSValue::encode(val);
|
||||
}
|
||||
|
||||
Zig__ConsoleClient__timeLog(this->m_client, globalObject, reinterpret_cast<const unsigned char*>(input.data()), input.length(), jsArgs, count);
|
||||
}
|
||||
void Zig::ConsoleClient::timeEnd(JSGlobalObject* globalObject, const String& label)
|
||||
{
|
||||
@@ -100,4 +109,4 @@ void Zig::ConsoleClient::timeStamp(JSGlobalObject* globalObject, Ref<ScriptArgum
|
||||
void Zig::ConsoleClient::record(JSGlobalObject*, Ref<ScriptArguments>&&) {}
|
||||
void Zig::ConsoleClient::recordEnd(JSGlobalObject*, Ref<ScriptArguments>&&) {}
|
||||
void Zig::ConsoleClient::screenshot(JSGlobalObject*, Ref<ScriptArguments>&&) {}
|
||||
void Zig::ConsoleClient::warnUnimplemented(const String& method) {}
|
||||
void Zig::ConsoleClient::warnUnimplemented(const String& method) {}
|
||||
|
||||
@@ -3264,13 +3264,14 @@ pub const ZigConsoleClient = struct {
|
||||
// console
|
||||
_: ZigConsoleClient.Type,
|
||||
// global
|
||||
_: *JSGlobalObject,
|
||||
global: *JSGlobalObject,
|
||||
// chars
|
||||
chars: [*]const u8,
|
||||
// len
|
||||
len: usize,
|
||||
// args
|
||||
_: *ScriptArguments,
|
||||
args: [*]JSValue,
|
||||
args_len: usize,
|
||||
) callconv(.C) void {
|
||||
if (!pending_time_logs_loaded) {
|
||||
return;
|
||||
@@ -3282,13 +3283,32 @@ pub const ZigConsoleClient = struct {
|
||||
// then display it in milliseconds
|
||||
Output.printElapsed(@as(f64, @floatFromInt(value.read() / std.time.ns_per_us)) / std.time.us_per_ms);
|
||||
switch (len) {
|
||||
0 => Output.printErrorln("\n", .{}),
|
||||
else => Output.printErrorln(" {s}", .{chars[0..len]}),
|
||||
0 => {},
|
||||
else => Output.printError(" {s}", .{chars[0..len]}),
|
||||
}
|
||||
|
||||
Output.flush();
|
||||
|
||||
// TODO: print the arguments
|
||||
// print the arguments
|
||||
var fmt = ZigConsoleClient.Formatter{
|
||||
.remaining_values = &[_]JSValue{},
|
||||
.globalThis = global,
|
||||
.ordered_properties = false,
|
||||
.quote_strings = false,
|
||||
};
|
||||
var console = global.bunVM().console;
|
||||
var writer = console.error_writer.writer();
|
||||
const Writer = @TypeOf(writer);
|
||||
for (args[0..args_len]) |arg| {
|
||||
const tag = ZigConsoleClient.Formatter.Tag.get(arg, global);
|
||||
_ = writer.write(" ") catch 0;
|
||||
if (Output.enable_ansi_colors_stderr) {
|
||||
fmt.format(tag, Writer, writer, arg, global, true);
|
||||
} else {
|
||||
fmt.format(tag, Writer, writer, arg, global, false);
|
||||
}
|
||||
}
|
||||
_ = writer.write("\n") catch 0;
|
||||
writer.context.flush() catch {};
|
||||
}
|
||||
pub fn profile(
|
||||
// console
|
||||
|
||||
2
src/bun.js/bindings/headers.h
generated
2
src/bun.js/bindings/headers.h
generated
@@ -764,7 +764,7 @@ ZIG_DECL void Zig__ConsoleClient__screenshot(void* arg0, JSC__JSGlobalObject* ar
|
||||
ZIG_DECL void Zig__ConsoleClient__takeHeapSnapshot(void* arg0, JSC__JSGlobalObject* arg1, const unsigned char* arg2, size_t arg3);
|
||||
ZIG_DECL void Zig__ConsoleClient__time(void* arg0, JSC__JSGlobalObject* arg1, const unsigned char* arg2, size_t arg3);
|
||||
ZIG_DECL void Zig__ConsoleClient__timeEnd(void* arg0, JSC__JSGlobalObject* arg1, const unsigned char* arg2, size_t arg3);
|
||||
ZIG_DECL void Zig__ConsoleClient__timeLog(void* arg0, JSC__JSGlobalObject* arg1, const unsigned char* arg2, size_t arg3, ScriptArguments* arg4);
|
||||
ZIG_DECL void Zig__ConsoleClient__timeLog(void* arg0, JSC__JSGlobalObject* arg1, const unsigned char* arg2, size_t arg3, JSC__JSValue* arg4, size_t arg5);
|
||||
ZIG_DECL void Zig__ConsoleClient__timeStamp(void* arg0, JSC__JSGlobalObject* arg1, ScriptArguments* arg2);
|
||||
|
||||
#endif
|
||||
|
||||
18
test/js/web/console/console-timeLog.expected.txt
Normal file
18
test/js/web/console/console-timeLog.expected.txt
Normal file
@@ -0,0 +1,18 @@
|
||||
[0.00ms] label
|
||||
[0.06ms] label Hello World!
|
||||
[0.09ms] label a %s b c d
|
||||
[0.11ms] label 0 -0 123 -123 123.567 -123.567 Infinity -Infinity
|
||||
[0.14ms] label true false
|
||||
[0.15ms] label null undefined
|
||||
[0.17ms] label Symbol(Symbol Description)
|
||||
[0.22ms] label 2000-06-27T02:24:34.304Z
|
||||
[0.29ms] label [ 123, 456, 789 ]
|
||||
[0.34ms] label {
|
||||
name: "foo",
|
||||
}
|
||||
[0.37ms] label {
|
||||
a: 123,
|
||||
b: 456,
|
||||
c: 789,
|
||||
}
|
||||
[0.39ms] label
|
||||
13
test/js/web/console/console-timeLog.js
Normal file
13
test/js/web/console/console-timeLog.js
Normal file
@@ -0,0 +1,13 @@
|
||||
console.time("label");
|
||||
console.timeLog("label");
|
||||
console.timeLog("label", "Hello World!");
|
||||
console.timeLog("label", "a %s b", "c", "d");
|
||||
console.timeLog("label", 0, -0, 123, -123, 123.567, -123.567, Infinity, -Infinity);
|
||||
console.timeLog("label", true, false);
|
||||
console.timeLog("label", null, undefined);
|
||||
console.timeLog("label", Symbol("Symbol Description"));
|
||||
console.timeLog("label", new Date(Math.pow(2, 34) * 56));
|
||||
console.timeLog("label", [123, 456, 789]);
|
||||
console.timeLog("label", { name: "foo" });
|
||||
console.timeLog("label", { a: 123, b: 456, c: 789 });
|
||||
console.timeEnd("label");
|
||||
17
test/js/web/console/console-timeLog.test.ts
Normal file
17
test/js/web/console/console-timeLog.test.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { file, spawn } from "bun";
|
||||
import { expect, it } from "bun:test";
|
||||
import { bunExe, bunEnv } from "harness";
|
||||
|
||||
it("should log to console correctly", async () => {
|
||||
const { stderr, exited } = spawn({
|
||||
cmd: [bunExe(), import.meta.dir + "/console-timeLog.js"],
|
||||
stdin: null,
|
||||
stdout: "pipe",
|
||||
stderr: "pipe",
|
||||
env: bunEnv,
|
||||
});
|
||||
expect(await exited).toBe(0);
|
||||
const outText = await new Response(stderr).text();
|
||||
const expectedText = await new Response(file(import.meta.dir + "/console-timeLog.expected.txt")).text();
|
||||
expect(outText.replace(/^\[.+?s\] /gm, "")).toBe(expectedText.replace(/^\[.+?s\] /gm, ""));
|
||||
});
|
||||
Reference in New Issue
Block a user