From 3f28808c61e54ad69fb25bf3844de0149350e8a0 Mon Sep 17 00:00:00 2001 From: Jacques Nadeau Date: Thu, 12 Jan 2023 14:59:16 -0800 Subject: [PATCH] Fixes to support newest stable v8. - Update github workflow to use go 18 & 19 - Update github workflow to use macos-latest - Update github build workflow to use ubuntu 22.04 - Add gitignore for jetbrains and .gclient_previous files - Switch cgo build to C++17 and enable sandbox at build time - Update test with update to date error message - Remove no longer supported build flag. - Move initialization to v8go.go and include flag set to avoid flag freezing - Reorder initialization so allocator is initialized after v8 (required by latest v8) --- .github/workflows/test.yml | 4 ++-- .github/workflows/v8build.yml | 6 +++--- .gitignore | 4 ++-- cgo.go | 2 +- context_test.go | 2 +- deps/build.py | 1 - isolate.go | 4 +--- v8go.cc | 8 +++++--- v8go.go | 9 +++++++++ 9 files changed, 24 insertions(+), 16 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5018ed4c..c5ee4d40 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,11 +12,11 @@ jobs: name: Tests on ${{ matrix.go-version }} ${{ matrix.platform }} strategy: matrix: - go-version: [1.16.8, 1.17.1] + go-version: [1.18.10, 1.19.5] # We use macos-11 over macos-latest because macos-latest defaults to Catalina(10.15) and not Big Sur(11.0) # We can switch to macos-latest whenever Big Sur becomes the default # See https://github.com/actions/virtual-environments#available-environments - platform: [ubuntu-latest, macos-11] + platform: [ubuntu-latest, macos-latest] runs-on: ${{ matrix.platform }} steps: diff --git a/.github/workflows/v8build.yml b/.github/workflows/v8build.yml index b9cd7ea4..560a8f5c 100644 --- a/.github/workflows/v8build.yml +++ b/.github/workflows/v8build.yml @@ -14,7 +14,7 @@ jobs: # # We need xcode 12.4 or newer to cross compile between arm64/amd64 # https://github.com/actions/virtual-environments/blob/main/images/macos/macos-11-Readme.md#xcode - platform: [ubuntu-18.04, macos-11] + platform: [ubuntu-22.04, macos-11] arch: [x86_64, arm64] runs-on: ${{ matrix.platform }} steps: @@ -27,10 +27,10 @@ jobs: run: cd deps/depot_tools && git config --unset-all remote.origin.fetch; git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* shell: bash - name: Install g++-aarch64-linux-gnu - if: matrix.platform == 'ubuntu-18.04' && matrix.arch == 'arm64' + if: matrix.platform == 'ubuntu-22.04' && matrix.arch == 'arm64' run: sudo apt update && sudo apt install g++-aarch64-linux-gnu -y - name: Build V8 linux - if: matrix.platform == 'ubuntu-18.04' + if: matrix.platform == 'ubuntu-22.04' run: cd deps && ./build.py --no-clang --arch ${{ matrix.arch }} - name: Build V8 macOS if: matrix.platform == 'macos-11' diff --git a/.gitignore b/.gitignore index f676dd07..530cd503 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,7 @@ .gclient_entries deps/darwin-x86_64/libv8_debug.a - +deps/.gclient_previous* c.out - +.idea/* /v8go.test diff --git a/cgo.go b/cgo.go index a8d2a878..4346cbcb 100644 --- a/cgo.go +++ b/cgo.go @@ -6,7 +6,7 @@ package v8go //go:generate clang-format -i --verbose -style=Chromium v8go.h v8go.cc -// #cgo CXXFLAGS: -fno-rtti -fPIC -std=c++14 -DV8_COMPRESS_POINTERS -DV8_31BIT_SMIS_ON_64BIT_ARCH -I${SRCDIR}/deps/include -Wall +// #cgo CXXFLAGS: -fno-rtti -fPIC -std=c++17 -DV8_COMPRESS_POINTERS -DV8_31BIT_SMIS_ON_64BIT_ARCH -I${SRCDIR}/deps/include -Wall -DV8_ENABLE_SANDBOX // #cgo LDFLAGS: -pthread -lv8 // #cgo darwin,amd64 LDFLAGS: -L${SRCDIR}/deps/darwin_x86_64 // #cgo darwin,arm64 LDFLAGS: -L${SRCDIR}/deps/darwin_arm64 diff --git a/context_test.go b/context_test.go index 10dad5d8..7f9de592 100644 --- a/context_test.go +++ b/context_test.go @@ -48,7 +48,7 @@ func TestJSExceptions(t *testing.T) { origin string err string }{ - {"SyntaxError", "bad js syntax", "syntax.js", "SyntaxError: Unexpected identifier"}, + {"SyntaxError", "bad js syntax", "syntax.js", "SyntaxError: Unexpected identifier 'js'"}, {"ReferenceError", "add()", "add.js", "ReferenceError: add is not defined"}, } diff --git a/deps/build.py b/deps/build.py index 740218f5..805585bd 100755 --- a/deps/build.py +++ b/deps/build.py @@ -67,7 +67,6 @@ 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/isolate.go b/isolate.go index 661fbec0..6e7f9de6 100644 --- a/isolate.go +++ b/isolate.go @@ -52,9 +52,7 @@ type HeapStatistics struct { // An *Isolate can be used as a v8go.ContextOption to create a new // Context, rather than creating a new default Isolate. func NewIsolate() *Isolate { - v8once.Do(func() { - C.Init() - }) + initializeIfNecessary() iso := &Isolate{ ptr: C.NewIsolate(), cbs: make(map[int]FunctionCallback), diff --git a/v8go.cc b/v8go.cc index e55bf45f..53820f02 100644 --- a/v8go.cc +++ b/v8go.cc @@ -18,7 +18,7 @@ using namespace v8; auto default_platform = platform::NewDefaultPlatform(); -auto default_allocator = ArrayBuffer::Allocator::NewDefaultAllocator(); +ArrayBuffer::Allocator* default_allocator; const int ScriptCompilerNoCompileOptions = ScriptCompiler::kNoCompileOptions; const int ScriptCompilerConsumeCodeCache = ScriptCompiler::kConsumeCodeCache; @@ -149,6 +149,8 @@ void Init() { #endif V8::InitializePlatform(default_platform.get()); V8::Initialize(); + + default_allocator = ArrayBuffer::Allocator::NewDefaultAllocator(); return; } @@ -243,7 +245,7 @@ RtnUnboundScript IsolateCompileUnboundScript(IsolatePtr iso, opts.cachedData.length); } - ScriptOrigin script_origin(ogn); + ScriptOrigin script_origin(iso, ogn); ScriptCompiler::Source source(src, script_origin, cached_data); @@ -634,7 +636,7 @@ RtnValue RunScript(ContextPtr ctx, const char* source, const char* origin) { return rtn; } - ScriptOrigin script_origin(ogn); + ScriptOrigin script_origin(iso, ogn); Local