diff --git a/misc/wasm/wasm_exec.js b/misc/wasm/wasm_exec.js index bc6f210242824c..4d642dfec61b0a 100644 --- a/misc/wasm/wasm_exec.js +++ b/misc/wasm/wasm_exec.js @@ -96,6 +96,7 @@ constructor() { this.argv = ["js"]; this.env = {}; + this.scope = globalThis; this.exit = (code) => { if (code !== 0) { console.warn("exit code:", code); diff --git a/misc/wasm/wasm_exec_node.js b/misc/wasm/wasm_exec_node.js index 986069087bc0bc..196288813d633f 100644 --- a/misc/wasm/wasm_exec_node.js +++ b/misc/wasm/wasm_exec_node.js @@ -23,6 +23,7 @@ require("./wasm_exec"); const go = new Go(); go.argv = process.argv.slice(2); go.env = Object.assign({ TMPDIR: require("os").tmpdir() }, process.env); +go.scope = {}; go.exit = process.exit; WebAssembly.instantiate(fs.readFileSync(process.argv[2]), go.importObject).then((result) => { process.on("exit", (code) => { // Node.js exits if no event handler is pending diff --git a/nfpm.yaml b/nfpm.yaml new file mode 100644 index 00000000000000..5386bd020735e5 --- /dev/null +++ b/nfpm.yaml @@ -0,0 +1,43 @@ +name: golang-trout +arch: amd64 +platform: linux +version: 1.23.alpha1+trout-1 +section: default +priority: extra +maintainer: Trout Software +description: | + The Go Programming Language. + . + Go is an open source programming language supported by Google + Easy to learn and get started with + Built-in concurrency and a robust standard library + Growing ecosystem of partners, communities, and tools + -- + This is a package for easy dev installation + +contents: + - src: bin + dst: /opt/go/bin + type: tree + - src: /opt/go/bin/go + dst: /usr/bin/go + type: symlink + - src: doc + dst: /opt/go/doc + type: tree + - src: lib + dst: /opt/go/lib + type: tree + - src: misc + dst: /opt/go/misc + type: tree + - src: pkg + dst: /opt/go/pkg + type: tree + - src: src + dst: /opt/go/src + type: tree + - src: VERSION + dst: /opt/go/VERSION + - src: go.env + dst: /opt/go/go.env \ No newline at end of file diff --git a/src/syscall/js/js.go b/src/syscall/js/js.go index 74c02cdbe64ada..23c398afc7f342 100644 --- a/src/syscall/js/js.go +++ b/src/syscall/js/js.go @@ -135,6 +135,12 @@ func Global() Value { return valueGlobal } +// Scope returns the Javascript object attached to the scope field of the Go class. +// If nothing has been explicitly set, behaves like [js.Global]. +func Scope() Value { + return jsGo.Get("scope") +} + // ValueOf returns x as a JavaScript value: // // | Go | JavaScript | diff --git a/src/syscall/js/js_test.go b/src/syscall/js/js_test.go index cc809ac107e16c..d16738db1fdabd 100644 --- a/src/syscall/js/js_test.go +++ b/src/syscall/js/js_test.go @@ -688,3 +688,19 @@ func TestGlobal(t *testing.T) { t.Errorf("got %#v, want %#v", got, js.Global()) } } + +func TestScope(t *testing.T) { + ident := js.FuncOf(func(this js.Value, args []js.Value) any { + return args[0] + }) + defer ident.Release() + + js.Scope().Set("key", "value") + if js.Scope().Get("key").String() != "value" { + t.Errorf("get key %s: got %#v", "key", js.Scope().Get("key")) + } + + if got := ident.Invoke(js.Scope()); got.Equal(js.Global()) { + t.Errorf("scope %#v mixed with global %#v", got, js.Global()) + } +}