Bug 1308056: wasm: add syntax for inline import/export in memories; r=luke
☠☠ backed out by 206a77f3fffb ☠ ☠
authorBenjamin Bouvier <benj@benj.me>
Fri, 07 Oct 2016 17:03:14 +0200
changeset 360369 5aaf29ab8c30d593674c97389a33e6e81f9b1358
parent 360368 27bec108f660f219747e0626cfa61a57cfce14f0
child 360370 8030f70a51308de1e8448e538817b86b7315721e
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-beta@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersluke
bugs1308056
milestone52.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1308056: wasm: add syntax for inline import/export in memories; r=luke MozReview-Commit-ID: Ijh7d0eqvuM
js/src/asmjs/WasmTextToBinary.cpp
js/src/jit-test/tests/wasm/text.js
--- a/js/src/asmjs/WasmTextToBinary.cpp
+++ b/js/src/asmjs/WasmTextToBinary.cpp
@@ -2744,16 +2744,46 @@ ParseLimits(WasmParseContext& c, Limits*
     Limits r = { initial.index(), maximum };
     *resizable = r;
     return true;
 }
 
 static bool
 ParseMemory(WasmParseContext& c, WasmToken token, AstModule* module)
 {
+    AstName name = c.ts.getIfName();
+
+    WasmToken openParen;
+    if (c.ts.getIf(WasmToken::OpenParen)) {
+        if (c.ts.getIf(WasmToken::Import)) {
+            InlineImport names;
+            if (!ParseInlineImport(c, &names))
+                return false;
+            if (!c.ts.match(WasmToken::CloseParen, c.error))
+                return false;
+
+            Limits memory;
+            if (!ParseLimits(c, &memory))
+                return false;
+
+            auto* imp = new(c.lifo) AstImport(name, names.module.text(), names.field.text(),
+                                              DefinitionKind::Memory, memory);
+            return imp && module->append(imp);
+        }
+
+        if (c.ts.getIf(WasmToken::Export)) {
+            if (!ParseInlineExport(c, DefinitionKind::Memory, module))
+                return false;
+            if (!c.ts.match(WasmToken::CloseParen, c.error))
+                return false;
+        } else {
+            c.ts.unget(openParen);
+        }
+    }
+
     if (c.ts.getIf(WasmToken::OpenParen)) {
         if (!c.ts.match(WasmToken::Data, c.error))
             return false;
 
         WasmToken text;
         size_t pages = 0;
         if (c.ts.getIf(WasmToken::Text, &text)) {
             AstExpr* offset = new(c.lifo) AstConst(Val(uint32_t(0)));
@@ -2849,16 +2879,19 @@ ParseImport(WasmParseContext& c, AstModu
     WasmToken fieldName;
     if (!c.ts.match(WasmToken::Text, &fieldName, c.error))
         return nullptr;
 
     AstRef sigRef;
     WasmToken openParen;
     if (c.ts.getIf(WasmToken::OpenParen, &openParen)) {
         if (c.ts.getIf(WasmToken::Memory)) {
+            if (name.empty())
+                name = c.ts.getIfName();
+
             Limits memory;
             if (!ParseLimits(c, &memory))
                 return nullptr;
             if (!c.ts.match(WasmToken::CloseParen, c.error))
                 return nullptr;
             return new(c.lifo) AstImport(name, moduleName.text(), fieldName.text(),
                                          DefinitionKind::Memory, memory);
         }
--- a/js/src/jit-test/tests/wasm/text.js
+++ b/js/src/jit-test/tests/wasm/text.js
@@ -107,10 +107,21 @@ wasmEvalText('(module (global $t (import
 assertErrorMessage(() => wasmEvalText(`
     (module
         (global (import "mod" "a") i32)
         (global (export "f1") i32 (i32.const 42))
         (global (import "mod" "b") i32)
     )
 `), SyntaxError, /import after global definition/);
 
+// Memory.
+assertErrorMessage(() => wasmEvalText('(module (memory (export)))'), SyntaxError, parsingError);
+assertErrorMessage(() => wasmEvalText('(module (memory (export "g")))'), SyntaxError, parsingError);
+wasmEvalText('(module (memory $t (export "g") 0))');
+
+const mem = new WebAssembly.Memory({ initial: 1 });
+assertErrorMessage(() => wasmEvalText('(module (memory $t (import) 1))'), SyntaxError, parsingError);
+assertErrorMessage(() => wasmEvalText('(module (memory $t (import "mod") 1))'), SyntaxError, parsingError);
+assertErrorMessage(() => wasmEvalText('(module (memory $t (import "mod" "field")))'), SyntaxError, parsingError);
+wasmEvalText('(module (memory $t (import "mod" "field") 1))', { mod: {field: mem} });
+
 // Note: the s-expression text format is temporary, this file is mostly just to
 // hold basic error smoke tests.