aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-11-27 07:28:30 -0800
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-11-27 07:28:30 -0800
commit1d9c98248893d9ad002ccdc6a83c1347adb68c22 (patch)
treedfd337331c555633e91d24ca841f43b8be37739b /src/bun.js
parent5e6e8ece4e692127f29224aaa00c33e0496bbabb (diff)
downloadbun-1d9c98248893d9ad002ccdc6a83c1347adb68c22.tar.gz
bun-1d9c98248893d9ad002ccdc6a83c1347adb68c22.tar.zst
bun-1d9c98248893d9ad002ccdc6a83c1347adb68c22.zip
[console.log] Fix printing latin1 supplement characters at runtime
Fixes https://github.com/oven-sh/bun/issues/1031#issuecomment-1236092120
Diffstat (limited to 'src/bun.js')
-rw-r--r--src/bun.js/bindings/exports.zig31
-rw-r--r--src/bun.js/bindings/headers-cpp.h2
-rw-r--r--src/bun.js/bindings/headers.h3
-rw-r--r--src/bun.js/bindings/headers.zig1
4 files changed, 22 insertions, 15 deletions
diff --git a/src/bun.js/bindings/exports.zig b/src/bun.js/bindings/exports.zig
index 917a62ee0..043fbdbc7 100644
--- a/src/bun.js/bindings/exports.zig
+++ b/src/bun.js/bindings/exports.zig
@@ -1869,19 +1869,11 @@ pub const ZigConsoleClient = struct {
switch (comptime Format) {
.StringPossiblyFormatted => {
- var str = ZigString.init("");
- value.toZigString(&str, this.globalThis);
+ var str = value.toSlice(this.globalThis, bun.default_allocator);
+ defer str.deinit();
this.addForNewLine(str.len);
-
- if (!str.is16Bit()) {
- const sliced = str.toSlice(bun.default_allocator);
- defer sliced.deinit();
- const slice = sliced.slice();
- this.writeWithFormatting(Writer, writer_, @TypeOf(slice), slice, this.globalThis, enable_ansi_colors);
- } else {
- // TODO: UTF16
- writer.print("{}", .{str});
- }
+ const slice = str.slice();
+ this.writeWithFormatting(Writer, writer_, @TypeOf(slice), slice, this.globalThis, enable_ansi_colors);
},
.String => {
var str = ZigString.init("");
@@ -1915,7 +1907,20 @@ pub const ZigConsoleClient = struct {
writer.print(comptime Output.prettyFmt("<r><red>", enable_ansi_colors), .{});
}
- writer.print("{}", .{str});
+ if (str.is16Bit()) {
+ // streaming print
+ writer.print("{s}", .{str});
+ } else if (strings.isAllASCII(str.slice())) {
+ // fast path
+ writer.writeAll(str.slice());
+ } else if (str.len > 0) {
+ // slow path
+ var buf = strings.allocateLatin1IntoUTF8(bun.default_allocator, []const u8, str.slice()) catch &[_]u8{};
+ if (buf.len > 0) {
+ defer bun.default_allocator.free(buf);
+ writer.writeAll(buf);
+ }
+ }
if (jsType == .RegExpObject and enable_ansi_colors) {
writer.print(comptime Output.prettyFmt("<r>", enable_ansi_colors), .{});
diff --git a/src/bun.js/bindings/headers-cpp.h b/src/bun.js/bindings/headers-cpp.h
index 684656083..216a45292 100644
--- a/src/bun.js/bindings/headers-cpp.h
+++ b/src/bun.js/bindings/headers-cpp.h
@@ -1,4 +1,4 @@
-//-- AUTOGENERATED FILE -- 1669352137
+//-- AUTOGENERATED FILE -- 1669539205
// clang-format off
#pragma once
diff --git a/src/bun.js/bindings/headers.h b/src/bun.js/bindings/headers.h
index 419a8965a..9d335ee90 100644
--- a/src/bun.js/bindings/headers.h
+++ b/src/bun.js/bindings/headers.h
@@ -1,5 +1,5 @@
// clang-format off
-//-- AUTOGENERATED FILE -- 1669352137
+//-- AUTOGENERATED FILE -- 1669539205
#pragma once
#include <stddef.h>
@@ -491,6 +491,7 @@ CPP_DECL bool JSC__JSValue__eqlCell(JSC__JSValue JSValue0, JSC__JSCell* arg1);
CPP_DECL bool JSC__JSValue__eqlValue(JSC__JSValue JSValue0, JSC__JSValue JSValue1);
CPP_DECL JSC__JSValue JSC__JSValue__fastGet_(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1, unsigned char arg2);
CPP_DECL void JSC__JSValue__forEach(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1, void* arg2, void (* ArgFn3)(JSC__VM* arg0, JSC__JSGlobalObject* arg1, void* arg2, JSC__JSValue JSValue3));
+CPP_DECL void JSC__JSValue__forEachProperty(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1, void* arg2, void (* ArgFn3)(JSC__JSGlobalObject* arg0, void* arg1, ZigString* arg2, JSC__JSValue JSValue3, bool arg4));
CPP_DECL JSC__JSValue JSC__JSValue__fromEntries(JSC__JSGlobalObject* arg0, ZigString* arg1, ZigString* arg2, size_t arg3, bool arg4);
CPP_DECL JSC__JSValue JSC__JSValue__fromInt64NoTruncate(JSC__JSGlobalObject* arg0, int64_t arg1);
CPP_DECL JSC__JSValue JSC__JSValue__fromUInt64NoTruncate(JSC__JSGlobalObject* arg0, uint64_t arg1);
diff --git a/src/bun.js/bindings/headers.zig b/src/bun.js/bindings/headers.zig
index 7b649f26f..20f767d73 100644
--- a/src/bun.js/bindings/headers.zig
+++ b/src/bun.js/bindings/headers.zig
@@ -284,6 +284,7 @@ pub extern fn JSC__JSValue__eqlCell(JSValue0: JSC__JSValue, arg1: [*c]JSC__JSCel
pub extern fn JSC__JSValue__eqlValue(JSValue0: JSC__JSValue, JSValue1: JSC__JSValue) bool;
pub extern fn JSC__JSValue__fastGet_(JSValue0: JSC__JSValue, arg1: ?*JSC__JSGlobalObject, arg2: u8) JSC__JSValue;
pub extern fn JSC__JSValue__forEach(JSValue0: JSC__JSValue, arg1: ?*JSC__JSGlobalObject, arg2: ?*anyopaque, ArgFn3: ?fn ([*c]JSC__VM, ?*JSC__JSGlobalObject, ?*anyopaque, JSC__JSValue) callconv(.C) void) void;
+pub extern fn JSC__JSValue__forEachProperty(JSValue0: JSC__JSValue, arg1: ?*JSC__JSGlobalObject, arg2: ?*anyopaque, ArgFn3: ?fn (?*JSC__JSGlobalObject, ?*anyopaque, [*c]ZigString, JSC__JSValue, bool) callconv(.C) void) void;
pub extern fn JSC__JSValue__fromEntries(arg0: ?*JSC__JSGlobalObject, arg1: [*c]ZigString, arg2: [*c]ZigString, arg3: usize, arg4: bool) JSC__JSValue;
pub extern fn JSC__JSValue__fromInt64NoTruncate(arg0: ?*JSC__JSGlobalObject, arg1: i64) JSC__JSValue;
pub extern fn JSC__JSValue__fromUInt64NoTruncate(arg0: ?*JSC__JSGlobalObject, arg1: u64) JSC__JSValue;