Skip to content

Commit 3d2b4ba

Browse files
committed
Carry golang#56084 to Go 1.24.1
1 parent 339c903 commit 3d2b4ba

File tree

5 files changed

+67
-0
lines changed

5 files changed

+67
-0
lines changed

lib/wasm/wasm_exec.js

+1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
constructor() {
105105
this.argv = ["js"];
106106
this.env = {};
107+
this.scope = globalThis;
107108
this.exit = (code) => {
108109
if (code !== 0) {
109110
console.warn("exit code:", code);

lib/wasm/wasm_exec_node.js

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ require("./wasm_exec");
2424
const go = new Go();
2525
go.argv = process.argv.slice(2);
2626
go.env = Object.assign({ TMPDIR: require("os").tmpdir() }, process.env);
27+
go.scope = {};
2728
go.exit = process.exit;
2829
WebAssembly.instantiate(fs.readFileSync(process.argv[2]), go.importObject).then((result) => {
2930
process.on("exit", (code) => { // Node.js exits if no event handler is pending

nfpm.yaml

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: golang-trout
2+
arch: amd64
3+
platform: linux
4+
version: 1.23.alpha1+trout-1
5+
section: default
6+
priority: extra
7+
maintainer: Trout Software <[email protected]>
8+
description: |
9+
The Go Programming Language.
10+
.
11+
Go is an open source programming language supported by Google
12+
Easy to learn and get started with
13+
Built-in concurrency and a robust standard library
14+
Growing ecosystem of partners, communities, and tools
15+
--
16+
This is a package for easy dev installation
17+
18+
contents:
19+
- src: bin
20+
dst: /opt/go/bin
21+
type: tree
22+
- src: /opt/go/bin/go
23+
dst: /usr/bin/go
24+
type: symlink
25+
- src: doc
26+
dst: /opt/go/doc
27+
type: tree
28+
- src: lib
29+
dst: /opt/go/lib
30+
type: tree
31+
- src: misc
32+
dst: /opt/go/misc
33+
type: tree
34+
- src: pkg
35+
dst: /opt/go/pkg
36+
type: tree
37+
- src: src
38+
dst: /opt/go/src
39+
type: tree
40+
- src: VERSION
41+
dst: /opt/go/VERSION
42+
- src: go.env
43+
dst: /opt/go/go.env

src/syscall/js/js.go

+6
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@ func Global() Value {
135135
return valueGlobal
136136
}
137137

138+
// Scope returns the Javascript object attached to the scope field of the Go class.
139+
// If nothing has been explicitly set, behaves like [js.Global].
140+
func Scope() Value {
141+
return jsGo.Get("scope")
142+
}
143+
138144
// ValueOf returns x as a JavaScript value:
139145
//
140146
// | Go | JavaScript |

src/syscall/js/js_test.go

+16
Original file line numberDiff line numberDiff line change
@@ -733,3 +733,19 @@ func TestGlobal(t *testing.T) {
733733
t.Errorf("got %#v, want %#v", got, js.Global())
734734
}
735735
}
736+
737+
func TestScope(t *testing.T) {
738+
ident := js.FuncOf(func(this js.Value, args []js.Value) any {
739+
return args[0]
740+
})
741+
defer ident.Release()
742+
743+
js.Scope().Set("key", "value")
744+
if js.Scope().Get("key").String() != "value" {
745+
t.Errorf("get key %s: got %#v", "key", js.Scope().Get("key"))
746+
}
747+
748+
if got := ident.Invoke(js.Scope()); got.Equal(js.Global()) {
749+
t.Errorf("scope %#v mixed with global %#v", got, js.Global())
750+
}
751+
}

0 commit comments

Comments
 (0)