WebAssemby: builder doesn't do Memory section maximum correctly
authorjfbastien@apple.com <jfbastien@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 10 May 2017 18:22:31 +0000 (18:22 +0000)
committerjfbastien@apple.com <jfbastien@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 10 May 2017 18:22:31 +0000 (18:22 +0000)
https://bugs.webkit.org/show_bug.cgi?id=171931

Reviewed by Keith Miller.

* wasm/Builder.js:
(export.default.Builder.prototype._registerSectionBuilders.const.section.in.WASM.description.section.switch.section.case.string_appeared_here.this.section):
* wasm/Builder_WebAssemblyBinary.js:
(const.emitters.Memory):
* wasm/function-tests/memory-grow-invalid.js: Added.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@216598 268f45cc-cd09-0410-ab3c-d52691b4dbfc

JSTests/ChangeLog
JSTests/wasm/Builder.js
JSTests/wasm/Builder_WebAssemblyBinary.js
JSTests/wasm/function-tests/memory-grow-invalid.js [new file with mode: 0644]

index 537b159..8c84af6 100644 (file)
@@ -1,5 +1,18 @@
 2017-05-10  JF Bastien  <jfbastien@apple.com>
 
+        WebAssemby: builder doesn't do Memory section maximum correctly
+        https://bugs.webkit.org/show_bug.cgi?id=171931
+
+        Reviewed by Keith Miller.
+
+        * wasm/Builder.js:
+        (export.default.Builder.prototype._registerSectionBuilders.const.section.in.WASM.description.section.switch.section.case.string_appeared_here.this.section):
+        * wasm/Builder_WebAssemblyBinary.js:
+        (const.emitters.Memory):
+        * wasm/function-tests/memory-grow-invalid.js: Added.
+
+2017-05-10  JF Bastien  <jfbastien@apple.com>
+
         WebAssembly: support name section
         https://bugs.webkit.org/show_bug.cgi?id=171263
 
index dee786d..04adf8a 100644 (file)
@@ -517,8 +517,8 @@ export default class Builder {
                     const s = this._addSection(section);
                     const memoryBuilder = {
                         End: () => this,
-                        InitialMaxPages: (initial, max) => {
-                            s.data.push({ initial, max });
+                        InitialMaxPages: (initial, maximum) => {
+                            s.data.push({ initial, maximum });
                             return _errorHandlingProxyFor(memoryBuilder);
                         }
                     };
index 081de99..e949835 100644 (file)
@@ -154,12 +154,8 @@ const emitters = {
     Memory: (section, bin) => {
         // Flags, currently can only be [0,1]
         put(bin, "varuint1", section.data.length);
-        for (const memory of section.data) {
-            put(bin, "varuint32", memory.max ? 1 : 0);
-            put(bin, "varuint32", memory.initial);
-            if (memory.max)
-                put(bin, "varuint32", memory.max);
-        }
+        for (const memory of section.data)
+            putResizableLimits(bin, memory.initial, memory.maximum);
     },
 
     Global: (section, bin) => {
diff --git a/JSTests/wasm/function-tests/memory-grow-invalid.js b/JSTests/wasm/function-tests/memory-grow-invalid.js
new file mode 100644 (file)
index 0000000..ef62fd6
--- /dev/null
@@ -0,0 +1,29 @@
+import * as assert from '../assert.js';
+import Builder from '../Builder.js';
+
+const verbose = false;
+
+const initial = 0;
+const max = 0;
+
+const builder = (new Builder())
+    .Type().End()
+    .Function().End()
+    .Memory().InitialMaxPages(initial, max).End()
+    .Export().Function("current").Function("grow").End()
+    .Code()
+        .Function("current", { params: [], ret: "i32" }).CurrentMemory(0).Return().End()
+        .Function("grow", { params: ["i32"], ret: "i32" }).GetLocal(0).GrowMemory(0).Return().End()
+    .End();
+
+let instance = new WebAssembly.Instance(new WebAssembly.Module(builder.WebAssembly().get()));
+
+const current = instance.exports.current();
+const by = 2;
+const result = instance.exports.grow(current + by);
+if (verbose)
+    print(`Grow from ${current} (max ${max}) to ${current + by} returned ${result}, current now ${instance.exports.current()}`);
+
+assert.eq(result, -1);
+assert.eq(current, instance.exports.current());
+assert.le(instance.exports.current(), max);