Skip to content
Browse files

playground: add support for syscall/js package

Also modify the default "hello world" snippet to use it,
since it's a more general API.

Modernize slightly to handle variability in
environments better.

Updates #69
  • Loading branch information
dmitshur committed Dec 1, 2019
1 parent 9d23d21 commit 83a7ce439b42a9ec52baa636b94d8b33c6ce496f
Showing with 16 additions and 2 deletions.
  1. +1 −1 playground/playground.go
  2. +15 −1 playground/
@@ -54,7 +54,7 @@ func main() {
} else {
scope.Set("code", "package main\n\nimport (\n\t\"fmt\"\n\n\t\"\"\n)\n\nfunc main() {\n\tfmt.Println(\"Hello, playground\")\n\tjs.Global.Call(\"alert\", \"Hello, JavaScript\")\n\tprintln(\"Hello, JS console\")\n}\n")
scope.Set("code", "package main\n\nimport (\n\t\"fmt\"\n\t\"syscall/js\"\n)\n\nfunc main() {\n\tfmt.Println(\"Hello, playground\")\n\tjs.Global().Call(\"alert\", \"Hello, JavaScript\")\n\tprintln(\"Hello, JS console\")\n}\n")
scope.Set("imports", true)
@@ -10,6 +10,17 @@ cleanup() {

trap cleanup EXIT HUP INT TERM

# This script relies on GOPATH mode. The GOPATH workspace
# must contain both and
# repositories.
export GO111MODULE=off

# TODO: This script relies on $(go env GOROOT) not being user-writable.
# It can be improved to work even when $(go env GOROOT) is user-writable
# by making a GOROOT copy here, immediately chmod-ing it to be non-user-writable,
# and later on chmod-ing it be user-writable again.
# See

go install

go generate
@@ -33,10 +44,12 @@ mkdir -p pkg/
cp "$GOPATH"/pkg/*_js_min/ pkg/
cp "$GOPATH"/pkg/*_js_min/ pkg/

# Make a copy of GOROOT that is user-writeable,
# Make a copy of GOROOT that is user-writable,
# use it to build and copy out standard library packages.
echo "copying GOROOT from $(go env GOROOT) to $tmp/goroot"
cp -a "$(go env GOROOT)" "$tmp/goroot"
export GOROOT="$tmp/goroot"
unset GOPHERJS_GOROOT # force $GOROOT to be used
gopherjs install -m \
archive/tar \
archive/zip \
@@ -125,6 +138,7 @@ gopherjs install -m \
strconv \
strings \
sync/atomic \
syscall/js \
testing \
testing/iotest \
testing/quick \

0 comments on commit 83a7ce4

Please sign in to comment.
You can’t perform that action at this time.