diff --git a/CHANGELOG.md b/CHANGELOG.md index e0a21c2c..e51ff4e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Support for creating a code cache from an UnboundScript which can be used to create an UnboundScript in other isolates to run a pre-compiled script in new contexts. - Included compile error location in `%+v` formatting of JSError +- Enable i18n support ### Changed - Removed error return value from NewIsolate which never fails diff --git a/deps/build.py b/deps/build.py index 58f88dd4..740218f5 100755 --- a/deps/build.py +++ b/deps/build.py @@ -64,7 +64,8 @@ treat_warnings_as_errors=false v8_embedder_string="-v8go" v8_enable_gdbjit=false -v8_enable_i18n_support=false +v8_enable_i18n_support=true +icu_use_data_file=false v8_enable_test_features=false v8_untrusted_code_mitigations=false exclude_unwind_tables=true diff --git a/deps/darwin_arm64/libv8.a b/deps/darwin_arm64/libv8.a index 14be24b7..b5889142 100644 Binary files a/deps/darwin_arm64/libv8.a and b/deps/darwin_arm64/libv8.a differ diff --git a/deps/darwin_x86_64/libv8.a b/deps/darwin_x86_64/libv8.a index e25fe2d8..e77e0ce1 100644 Binary files a/deps/darwin_x86_64/libv8.a and b/deps/darwin_x86_64/libv8.a differ diff --git a/deps/depot_tools b/deps/depot_tools index c54d00e9..2e486c0d 160000 --- a/deps/depot_tools +++ b/deps/depot_tools @@ -1 +1 @@ -Subproject commit c54d00e9f585cc389687b00418b47c2030fa25cd +Subproject commit 2e486c0d9d44e651a4def1d8397e4dfa1871ee65 diff --git a/deps/linux_x86_64/libv8.a b/deps/linux_x86_64/libv8.a index 2e7ef300..cf53908a 100644 Binary files a/deps/linux_x86_64/libv8.a and b/deps/linux_x86_64/libv8.a differ diff --git a/intl_test.go b/intl_test.go new file mode 100644 index 00000000..87bf2e6e --- /dev/null +++ b/intl_test.go @@ -0,0 +1,62 @@ +// Copyright 2021 the v8go contributors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package v8go_test + +import ( + "testing" + + v8 "rogchap.com/v8go" +) + +func TestIntlSupport(t *testing.T) { + t.Parallel() + + ctx := v8.NewContext(nil) + iso := ctx.Isolate() + defer iso.Dispose() + defer ctx.Close() + + v, err := ctx.RunScript("typeof Intl === 'object'", "test.js") + fatalIf(t, err) + if !v.Boolean() { + t.Fatalf("expected value to be true, but was false") + } + + v, err = ctx.RunScript("new Intl.NumberFormat()", "test.js") + fatalIf(t, err) + if v.String() != "[object Intl.NumberFormat]" { + t.Fatalf("expected value to be [object Intl.NumberFormat], but was %v", v) + } + + v, err = ctx.RunScript("new Intl.DateTimeFormat('es', { month: 'long' }).format(new Date(9E8))", "test.js") + fatalIf(t, err) + if v.String() != "enero" { + t.Fatalf("expected value to be enero, but was %v", v) + } + + // Example from the node.js documentation: + // https://github.com/nodejs/node/blob/2e2a6fecd9b1aaffcb932fcc415439f359c84fdd/doc/api/intl.md?plain=1#L175-L183 + script := `const hasFullICU = (() => { +try { + const january = new Date(9e8); + const spanish = new Intl.DateTimeFormat('es', { month: 'long' }); + return spanish.format(january) === 'enero'; +} catch (err) { + return false; +} +})(); hasFullICU` + + v, err = ctx.RunScript(script, "test.js") + fatalIf(t, err) + if !v.Boolean() { + t.Fatalf("expected value to be true, but was %v", v) + } + + v, err = ctx.RunScript("var number = 123456.789; new Intl.NumberFormat('de-DE').format(number)", "test.js") + fatalIf(t, err) + if v.String() != "123.456,789" { + t.Fatalf("expected value to be %v, but was %v", "123.456,789", v) + } +}