diff --git a/compiler/gen_js.v b/compiler/gen_js.v index 51ec16b9a7..2ac7c51784 100644 --- a/compiler/gen_js.v +++ b/compiler/gen_js.v @@ -46,6 +46,11 @@ fn types_to_c(types []Type, table &Table) string { sb.write(field.name) sb.writeln('; // $field.typ') } + sb.writeln(' +constructor(obj) { + obj && Object.assign(this, obj); +} +') sb.writeln('}\n') } return sb.str() diff --git a/compiler/main.v b/compiler/main.v index 3f365cf2fc..905a8d2fe7 100644 --- a/compiler/main.v +++ b/compiler/main.v @@ -258,8 +258,9 @@ fn (v mut V) compile() { // TODO //cgen.genln('i64 total_m = 0; // For counting total RAM allocated') //if v.pref.is_test { + $if !js { cgen.genln('int g_test_ok = 1; ') - //} + } if 'json' in v.table.imports { cgen.genln(' #define js_get(object, key) cJSON_GetObjectItemCaseSensitive((object), (key)) @@ -474,7 +475,7 @@ fn (v &V) v_files_from_dir(dir string) []string { if file.ends_with('_mac.v') && v.os != .mac { continue } - if file.ends_with('_js.v') { + if file.ends_with('_js.v') && v.os != .js { continue } if file.ends_with('_nix.v') && (v.os == .windows || v.os == .msvc) { diff --git a/vlib/builtin/js/string.v b/vlib/builtin/js/string.v index 0adb2b3db5..5a8451d5f3 100644 --- a/vlib/builtin/js/string.v +++ b/vlib/builtin/js/string.v @@ -309,10 +309,5 @@ pub fn (s string) hash() int { } pub fn (s string) bytes() []byte { - if s.len == 0 { - return []byte - } - mut buf := [byte(0)].repeat2(s.len) - C.memcpy(buf.data, s.str, s.len) - return buf + return []byte }