From c84eb29b7873f61a776abbc247378e4ec75936b3 Mon Sep 17 00:00:00 2001 From: pancake Date: Tue, 20 Dec 2022 12:16:06 +0100 Subject: [PATCH] js: use write() on the freestanding backend (#16704) --- vlib/builtin/js/builtin.js.v | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/vlib/builtin/js/builtin.js.v b/vlib/builtin/js/builtin.js.v index 818c25e0ec..87fc65f9f8 100644 --- a/vlib/builtin/js/builtin.js.v +++ b/vlib/builtin/js/builtin.js.v @@ -9,9 +9,10 @@ pub fn js_throw(s any) { for {} } -#let globalPrint; +#let globalPrint, globalWrite; $if js_freestanding { #globalPrint = globalThis.print + #globalWrite = (typeof globalThis.write === 'function')? write: globalThis.print } pub fn flush_stdout() { @@ -33,6 +34,8 @@ pub fn println(s string) { pub fn print(s string) { $if js_node { #$process.stdout.write(s.str) + } $else $if js_freestanding { + #globalWrite(s.str) } $else { panic('Cannot `print` in a browser, use `println` instead') }