Skip to content

Commit c84eb29

Browse files
authored
js: use write() on the freestanding backend (#16704)
1 parent 11521a7 commit c84eb29

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

vlib/builtin/js/builtin.js.v

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ pub fn js_throw(s any) {
99
for {}
1010
}
1111

12-
#let globalPrint;
12+
#let globalPrint, globalWrite;
1313
$if js_freestanding {
1414
#globalPrint = globalThis.print
15+
#globalWrite = (typeof globalThis.write === 'function')? write: globalThis.print
1516
}
1617

1718
pub fn flush_stdout() {
@@ -33,6 +34,8 @@ pub fn println(s string) {
3334
pub fn print(s string) {
3435
$if js_node {
3536
#$process.stdout.write(s.str)
37+
} $else $if js_freestanding {
38+
#globalWrite(s.str)
3639
} $else {
3740
panic('Cannot `print` in a browser, use `println` instead')
3841
}

0 commit comments

Comments
 (0)