imports: add syscall/js API to zstdlib.go

The syscall/js API is not included in the GOROOT/api/go1.*.txt files
at this time, and so it needs to be added to mkstdlib.go explicitly.
Run the cmd/api command directly in the generator to determine the
syscall/js API.

Regenerate zstdlib.go with the updated generator, using Go 1.12.1.

Fixes golang/go#27590

Change-Id: I541588986d70f67f4917d9b34bdd57ca44f538f7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/170014
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
diff --git a/imports/mkstdlib.go b/imports/mkstdlib.go
index 5059ad4..c8865e5 100644
--- a/imports/mkstdlib.go
+++ b/imports/mkstdlib.go
@@ -14,6 +14,7 @@
 	"io/ioutil"
 	"log"
 	"os"
+	"os/exec"
 	"path/filepath"
 	"regexp"
 	"runtime"
@@ -59,6 +60,10 @@
 		mustOpen(api("go1.10.txt")),
 		mustOpen(api("go1.11.txt")),
 		mustOpen(api("go1.12.txt")),
+
+		// The API of the syscall/js package needs to be computed explicitly,
+		// because it's not included in the GOROOT/api/go1.*.txt files at this time.
+		syscallJSAPI(),
 	)
 	sc := bufio.NewScanner(f)
 
@@ -110,3 +115,18 @@
 		log.Fatal(err)
 	}
 }
+
+// syscallJSAPI returns the API of the syscall/js package.
+// It's computed from the contents of $(go env GOROOT)/src/syscall/js.
+func syscallJSAPI() io.Reader {
+	var exeSuffix string
+	if runtime.GOOS == "windows" {
+		exeSuffix = ".exe"
+	}
+	cmd := exec.Command("go"+exeSuffix, "run", "cmd/api", "-contexts", "js-wasm", "syscall/js")
+	out, err := cmd.Output()
+	if err != nil {
+		log.Fatalln(err)
+	}
+	return bytes.NewReader(out)
+}
diff --git a/imports/zstdlib.go b/imports/zstdlib.go
index c18a009..d81b8c5 100644
--- a/imports/zstdlib.go
+++ b/imports/zstdlib.go
@@ -9783,6 +9783,29 @@
 		"XP1_UNI_RECV":                                 true,
 		"XP1_UNI_SEND":                                 true,
 	},
+	"syscall/js": map[string]bool{
+		"Error":         true,
+		"Func":          true,
+		"FuncOf":        true,
+		"Global":        true,
+		"Null":          true,
+		"Type":          true,
+		"TypeBoolean":   true,
+		"TypeFunction":  true,
+		"TypeNull":      true,
+		"TypeNumber":    true,
+		"TypeObject":    true,
+		"TypeString":    true,
+		"TypeSymbol":    true,
+		"TypeUndefined": true,
+		"TypedArray":    true,
+		"TypedArrayOf":  true,
+		"Undefined":     true,
+		"Value":         true,
+		"ValueError":    true,
+		"ValueOf":       true,
+		"Wrapper":       true,
+	},
 	"testing": map[string]bool{
 		"AllocsPerRun":      true,
 		"B":                 true,