Bug 1494602 - Better test cases for ref globals, using structs. r=jseward
authorLars T Hansen <lhansen@mozilla.com>
Thu, 26 Jul 2018 17:06:05 +0200
changeset 494904 96e94c1a5230c2d96cc6470dc0f28aa93351a6f2
parent 494903 16385c9bc942691a0a2f4a2d67c27e756791858b
child 494905 5f6fd031d3a63aba355463845998e004f8b6c34c
push id9984
push userffxbld-merge
push dateMon, 15 Oct 2018 21:07:35 +0000
treeherdermozilla-beta@183d27ea8570 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjseward
bugs1494602
milestone64.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 1494602 - Better test cases for ref globals, using structs. r=jseward
js/src/jit-test/tests/wasm/gc/ref-global.js
--- a/js/src/jit-test/tests/wasm/gc/ref-global.js
+++ b/js/src/jit-test/tests/wasm/gc/ref-global.js
@@ -33,16 +33,79 @@ if (!wasmGcEnabled())
     let mod = new WebAssembly.Module(bin);
     let ins = new WebAssembly.Instance(mod).exports;
 
     assertEq(ins.get(), null);
     ins.copy();                 // Should not crash
     ins.clear();                // Should not crash
 }
 
+// Global with struct type
+
+{
+    let bin = wasmTextToBinary(
+        `(module
+          (gc_feature_opt_in 1)
+
+          (type $point (struct
+                        (field $x f64)
+                        (field $y f64)))
+
+          (global $glob (mut (ref $point)) (ref.null (ref $point)))
+
+          (func (export "init")
+           (set_global $glob (struct.new $point (f64.const 0.5) (f64.const 2.75))))
+
+          (func (export "change")
+           (set_global $glob (struct.new $point (f64.const 3.5) (f64.const 37.25))))
+
+          (func (export "clear")
+           (set_global $glob (ref.null (ref $point))))
+
+          (func (export "x") (result f64)
+           (struct.get $point 0 (get_global $glob)))
+
+          (func (export "y") (result f64)
+           (struct.get $point 1 (get_global $glob))))`);
+
+    let mod = new WebAssembly.Module(bin);
+    let ins = new WebAssembly.Instance(mod).exports;
+
+    assertErrorMessage(() => ins.x(), WebAssembly.RuntimeError, /dereferencing null pointer/);
+
+    ins.init();
+    assertEq(ins.x(), 0.5);
+    assertEq(ins.y(), 2.75);
+
+    ins.change();
+    assertEq(ins.x(), 3.5);
+    assertEq(ins.y(), 37.25);
+
+    ins.clear();
+    assertErrorMessage(() => ins.x(), WebAssembly.RuntimeError, /dereferencing null pointer/);
+}
+
+// Global value of type anyref for initializer from a WebAssembly.Global,
+// just check that it works.
+{
+    let bin = wasmTextToBinary(
+        `(module
+          (gc_feature_opt_in 1)
+          (import $g "" "g" (global anyref))
+          (global $glob anyref (get_global $g))
+          (func (export "get") (result anyref)
+           (get_global $glob)))`);
+
+    let mod = new WebAssembly.Module(bin);
+    let obj = {zappa:37};
+    let g = new WebAssembly.Global({value: "anyref"}, obj);
+    let ins = new WebAssembly.Instance(mod, {"":{g}}).exports;
+    assertEq(ins.get(), obj);
+}
+
 // We can't import a global of a reference type because we don't have a good
 // notion of structural type compatibility yet.
 {
     let bin = wasmTextToBinary(
         `(module
           (gc_feature_opt_in 1)
           (type $box (struct (field $val i32)))
           (import "m" "g" (global (mut (ref $box)))))`);