diff --git a/vlib/builtin/js/builtin.v b/vlib/builtin/js/builtin.v index c2287decb0..84b7eda78a 100644 --- a/vlib/builtin/js/builtin.v +++ b/vlib/builtin/js/builtin.v @@ -19,7 +19,7 @@ pub fn panic(s string) { } pub fn println(s string) { - #console.log(s) + #console.log(s.str) } pub fn eprintln(s string) { diff --git a/vlib/builtin/js/string.v b/vlib/builtin/js/string.v index 021cbc8220..c227748931 100644 --- a/vlib/builtin/js/string.v +++ b/vlib/builtin/js/string.v @@ -17,6 +17,15 @@ fn C.strlen(s byteptr) int fn todo() { } +pub fn tos(s byteptr) string { + len := 0 + #len = s.length; + return string{ + str: s + len: len + } +} + pub fn (a string) clone() string { return a diff --git a/vlib/compiler/gen_js.v b/vlib/compiler/gen_js.v index 461fa59815..06dc895745 100644 --- a/vlib/compiler/gen_js.v +++ b/vlib/compiler/gen_js.v @@ -214,22 +214,22 @@ fn type_default(typ string) string { return '{}' } // Default values for other types are not needed because of mandatory initialization - switch typ { - case 'bool': return '0' - case 'string': return '""' - case 'i8': return '0' - case 'i16': return '0' - case 'i64': return '0' - case 'u16': return '0' - case 'u32': return '0' - case 'u64': return '0' - case 'byte': return '0' - case 'int': return '0' - case 'rune': return '0' - case 'f32': return '0.0' - case 'f64': return '0.0' - case 'byteptr': return '0' - case 'voidptr': return '0' + match typ { + 'bool'{ return '0'} + 'string'{ return 'tos("")'} + 'i8'{ return '0'} + 'i16'{ return '0'} + 'i64'{ return '0'} + 'u16'{ return '0'} + 'u32'{ return '0'} + 'u64'{ return '0'} + 'byte'{ return '0'} + 'int'{ return '0'} + 'rune'{ return '0'} + 'f32'{ return '0.0'} + 'f64'{ return '0.0'} + 'byteptr'{ return '0'} + 'voidptr'{ return '0'} } return '{}' } diff --git a/vlib/compiler/parser.v b/vlib/compiler/parser.v index 0ff8619181..f00de855b0 100644 --- a/vlib/compiler/parser.v +++ b/vlib/compiler/parser.v @@ -2688,7 +2688,7 @@ fn (p mut Parser) string_expr() { p.gen("'$str'") } else if p.is_js { - p.gen('"$f"') + p.gen('tos("$f")') } else { p.gen('tos3("$f")')