From 23cba2617f81697a45ce93229066627986b5d5de Mon Sep 17 00:00:00 2001 From: dcode Date: Mon, 4 May 2020 20:57:19 +0200 Subject: [PATCH 1/2] Fix converge option --- src/module.ts | 6 +++--- tests/compiler/converge.json | 6 ++++++ tests/compiler/converge.optimized.wat | 9 +++++++++ tests/compiler/converge.ts | 1 + tests/compiler/converge.untouched.wat | 10 ++++++++++ 5 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 tests/compiler/converge.json create mode 100644 tests/compiler/converge.optimized.wat create mode 100644 tests/compiler/converge.ts create mode 100644 tests/compiler/converge.untouched.wat diff --git a/src/module.ts b/src/module.ts index 911a4a0d6e..92f35f4ac3 100644 --- a/src/module.ts +++ b/src/module.ts @@ -1629,7 +1629,7 @@ export class Module { binaryen._BinaryenModuleInterpret(this.ref); } - toBinary(sourceMapUrl: string | null): BinaryModule { + toBinary(sourceMapUrl: string | null = null): BinaryModule { var out = this.lit; // safe to reuse as long as.. assert(binaryen._BinaryenSizeofLiteral() >= 12); var cStr = allocString(sourceMapUrl); @@ -1642,7 +1642,7 @@ export class Module { var ret = new BinaryModule(); ret.output = readBuffer(binaryPtr, binaryLen); ret.sourceMap = readString(sourceMapPtr); - binaryen._free(cStr); + if (cStr) binaryen._free(cStr); binaryen._free(binaryPtr); if (sourceMapPtr) binaryen._free(sourceMapPtr); return ret; @@ -2329,7 +2329,7 @@ function stringLengthUTF8(str: string): usize { } function allocString(str: string | null): usize { - if (str === null) return 0; + if (str == null) return 0; var ptr = binaryen._malloc(stringLengthUTF8(str) + 1); // the following is based on Emscripten's stringToUTF8Array var idx = ptr; diff --git a/tests/compiler/converge.json b/tests/compiler/converge.json new file mode 100644 index 0000000000..47fbd0fb4f --- /dev/null +++ b/tests/compiler/converge.json @@ -0,0 +1,6 @@ +{ + "asc_flags": [ + "--runtime none", + "--converge" + ] +} \ No newline at end of file diff --git a/tests/compiler/converge.optimized.wat b/tests/compiler/converge.optimized.wat new file mode 100644 index 0000000000..46afa2e4ab --- /dev/null +++ b/tests/compiler/converge.optimized.wat @@ -0,0 +1,9 @@ +(module + (type $none_=>_none (func)) + (memory $0 0) + (export "memory" (memory $0)) + (export "test" (func $converge/test)) + (func $converge/test + nop + ) +) diff --git a/tests/compiler/converge.ts b/tests/compiler/converge.ts new file mode 100644 index 0000000000..4ffea18440 --- /dev/null +++ b/tests/compiler/converge.ts @@ -0,0 +1 @@ +export function test(): void {} diff --git a/tests/compiler/converge.untouched.wat b/tests/compiler/converge.untouched.wat new file mode 100644 index 0000000000..ce4bd8d183 --- /dev/null +++ b/tests/compiler/converge.untouched.wat @@ -0,0 +1,10 @@ +(module + (type $none_=>_none (func)) + (memory $0 0) + (table $0 1 funcref) + (export "memory" (memory $0)) + (export "test" (func $converge/test)) + (func $converge/test + nop + ) +) From a9411c0f7b8fc9f8adde867f9df31fd9b661b3e6 Mon Sep 17 00:00:00 2001 From: dcode Date: Mon, 4 May 2020 21:04:37 +0200 Subject: [PATCH 2/2] null checking --- src/module.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/module.ts b/src/module.ts index 92f35f4ac3..69d81f6025 100644 --- a/src/module.ts +++ b/src/module.ts @@ -2329,7 +2329,7 @@ function stringLengthUTF8(str: string): usize { } function allocString(str: string | null): usize { - if (str == null) return 0; + if (str === null) return 0; var ptr = binaryen._malloc(stringLengthUTF8(str) + 1); // the following is based on Emscripten's stringToUTF8Array var idx = ptr;