]> Cypherpunks.ru repositories - gostls13.git/commitdiff
misc/wasm: check type of argument to Go.run
authorRichard Musiol <mail@richard-musiol.de>
Wed, 28 Oct 2020 23:07:04 +0000 (00:07 +0100)
committerRichard Musiol <neelance@gmail.com>
Mon, 2 Nov 2020 13:02:40 +0000 (13:02 +0000)
This results in a nicer error message if the argument to Go.run is
omitted or of the wrong type.

Fixes #37000

Change-Id: I7f36d007f41a79b2cea1cebf5cce127786341202
Reviewed-on: https://go-review.googlesource.com/c/go/+/266117
Trust: Richard Musiol <neelance@gmail.com>
Run-TryBot: Richard Musiol <neelance@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
misc/wasm/wasm_exec.js

index 3ea03c45b7ebf43f1f0a8673e56498ab78fd2a39..82041e6bb901bde57c43e689984e60a499573aca 100644 (file)
                }
 
                async run(instance) {
+                       if (!(instance instanceof WebAssembly.Instance)) {
+                               throw new Error("Go.run: WebAssembly.Instance expected");
+                       }
                        this._inst = instance;
                        this.mem = new DataView(this._inst.exports.mem.buffer);
                        this._values = [ // JS values that Go currently has references to, indexed by reference id