aboutsummaryrefslogtreecommitdiffhomepage
path: root/targets/wasm_exec.js
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2019-03-06 17:53:47 +0100
committerRon Evans <[email protected]>2019-03-07 13:13:11 +0100
commit4ad9bd86430eb3ac705fccbbad0a86ddb542914b (patch)
tree0521a712620769d33731dd66a91f511fb5fcba20 /targets/wasm_exec.js
parent2a1dd986614eab4aa185fe72965f753ef06f9ec7 (diff)
downloadtinygo-4ad9bd86430eb3ac705fccbbad0a86ddb542914b.tar.gz
tinygo-4ad9bd86430eb3ac705fccbbad0a86ddb542914b.zip
wasm: ignore arguments and environment variables
The wasm_exec.js file copied from the main Go repository did write those values to address 4096 in linear memory, which led to memory corruption in linear memory. Remove these things for now, until they're actually supported, if support is ever added.
Diffstat (limited to 'targets/wasm_exec.js')
-rw-r--r--targets/wasm_exec.js44
1 files changed, 2 insertions, 42 deletions
diff --git a/targets/wasm_exec.js b/targets/wasm_exec.js
index 0fc923056..87522fa97 100644
--- a/targets/wasm_exec.js
+++ b/targets/wasm_exec.js
@@ -73,13 +73,6 @@
global.Go = class {
constructor() {
- this.argv = ["js"];
- this.env = {};
- this.exit = (code) => {
- if (code !== 0) {
- console.warn("exit code:", code);
- }
- };
this._callbackTimeouts = new Map();
this._nextCallbackTimeoutID = 1;
@@ -342,36 +335,6 @@
const mem = new DataView(this._inst.exports.memory.buffer)
- // Pass command line arguments and environment variables to WebAssembly by writing them to the linear memory.
- let offset = 4096;
-
- const strPtr = (str) => {
- let ptr = offset;
- new Uint8Array(mem.buffer, offset, str.length + 1).set(encoder.encode(str + "\0"));
- offset += str.length + (8 - (str.length % 8));
- return ptr;
- };
-
- const argc = this.argv.length;
-
- const argvPtrs = [];
- this.argv.forEach((arg) => {
- argvPtrs.push(strPtr(arg));
- });
-
- const keys = Object.keys(this.env).sort();
- argvPtrs.push(keys.length);
- keys.forEach((key) => {
- argvPtrs.push(strPtr(`${key}=${this.env[key]}`));
- });
-
- const argv = offset;
- argvPtrs.forEach((ptr) => {
- mem.setUint32(offset, ptr, true);
- mem.setUint32(offset + 4, 0, true);
- offset += 8;
- });
-
while (true) {
const callbackPromise = new Promise((resolve) => {
this._resolveCallbackPromise = () => {
@@ -381,7 +344,7 @@
setTimeout(resolve, 0); // make sure it is asynchronous
};
});
- this._inst.exports.cwa_main(argc, argv);
+ this._inst.exports.cwa_main();
if (this.exited) {
break;
}
@@ -413,15 +376,12 @@
}
if (isNodeJS) {
- if (process.argv.length < 3) {
+ if (process.argv.length != 3) {
process.stderr.write("usage: go_js_wasm_exec [wasm binary] [arguments]\n");
process.exit(1);
}
const go = new Go();
- go.argv = process.argv.slice(2);
- go.env = process.env;
- go.exit = process.exit;
WebAssembly.instantiate(fs.readFileSync(process.argv[2]), go.importObject).then((result) => {
process.on("exit", (code) => { // Node.js exits if no callback is pending
if (code === 0 && !go.exited) {