Bug 1333011: Implement assert_exhaustion in the wast interpreter and reimport tests that use it; r=luke
authorBenjamin Bouvier <benj@benj.me>
Mon, 23 Jan 2017 11:24:52 +0100
changeset 465592 2b9cb8e74d7dca64ac87fc912aba8126a446a9fc
parent 465571 e465b90bf8e8c5257f5a1624f065889f10318bdd
child 465593 5988b2c740a45e221cc19537822477d72ce92452
push id42639
push usergpascutto@mozilla.com
push dateTue, 24 Jan 2017 11:10:35 +0000
reviewersluke
bugs1333011
milestone54.0a1
Bug 1333011: Implement assert_exhaustion in the wast interpreter and reimport tests that use it; r=luke MozReview-Commit-ID: KqZjS8oB4g0
js/src/jit-test/tests/wasm/spec/call.wast
js/src/jit-test/tests/wasm/spec/call_indirect.wast
js/src/jit-test/tests/wasm/spec/fac.wast
js/src/jit-test/tests/wasm/spec/skip-stack-guard-page.wast
js/src/jit-test/tests/wasm/wast.js
--- a/js/src/jit-test/tests/wasm/spec/call.wast
+++ b/js/src/jit-test/tests/wasm/spec/call.wast
@@ -136,18 +136,18 @@
 (assert_return (invoke "even" (i64.const 1)) (i32.const 99))
 (assert_return (invoke "even" (i64.const 100)) (i32.const 44))
 (assert_return (invoke "even" (i64.const 77)) (i32.const 99))
 (assert_return (invoke "odd" (i64.const 0)) (i32.const 99))
 (assert_return (invoke "odd" (i64.const 1)) (i32.const 44))
 (assert_return (invoke "odd" (i64.const 200)) (i32.const 99))
 (assert_return (invoke "odd" (i64.const 77)) (i32.const 44))
 
-(assert_trap (invoke "runaway") "call stack exhausted")
-(assert_trap (invoke "mutual-runaway") "call stack exhausted")
+(assert_exhaustion (invoke "runaway") "call stack exhausted")
+(assert_exhaustion (invoke "mutual-runaway") "call stack exhausted")
 
 
 ;; Invalid typing
 
 (assert_invalid
   (module
     (func $type-void-vs-num (i32.eqz (call 1)))
     (func)
--- a/js/src/jit-test/tests/wasm/spec/call_indirect.wast
+++ b/js/src/jit-test/tests/wasm/spec/call_indirect.wast
@@ -214,18 +214,18 @@
 (assert_return (invoke "even" (i32.const 1)) (i32.const 99))
 (assert_return (invoke "even" (i32.const 100)) (i32.const 44))
 (assert_return (invoke "even" (i32.const 77)) (i32.const 99))
 (assert_return (invoke "odd" (i32.const 0)) (i32.const 99))
 (assert_return (invoke "odd" (i32.const 1)) (i32.const 44))
 (assert_return (invoke "odd" (i32.const 200)) (i32.const 99))
 (assert_return (invoke "odd" (i32.const 77)) (i32.const 44))
 
-(assert_trap (invoke "runaway") "call stack exhausted")
-(assert_trap (invoke "mutual-runaway") "call stack exhausted")
+(assert_exhaustion (invoke "runaway") "call stack exhausted")
+(assert_exhaustion (invoke "mutual-runaway") "call stack exhausted")
 
 
 ;; Invalid typing
 
 (assert_invalid
   (module
     (type (func))
     (func $no-table (call_indirect 0 (i32.const 0)))
--- a/js/src/jit-test/tests/wasm/spec/fac.wast
+++ b/js/src/jit-test/tests/wasm/spec/fac.wast
@@ -77,9 +77,9 @@
   )
 )
 
 (assert_return (invoke "fac-rec" (i64.const 25)) (i64.const 7034535277573963776))
 (assert_return (invoke "fac-iter" (i64.const 25)) (i64.const 7034535277573963776))
 (assert_return (invoke "fac-rec-named" (i64.const 25)) (i64.const 7034535277573963776))
 (assert_return (invoke "fac-iter-named" (i64.const 25)) (i64.const 7034535277573963776))
 (assert_return (invoke "fac-opt" (i64.const 25)) (i64.const 7034535277573963776))
-(assert_trap (invoke "fac-rec" (i64.const 1073741824)) "call stack exhausted")
+(assert_exhaustion (invoke "fac-rec" (i64.const 1073741824)) "call stack exhausted")
--- a/js/src/jit-test/tests/wasm/spec/skip-stack-guard-page.wast
+++ b/js/src/jit-test/tests/wasm/spec/skip-stack-guard-page.wast
@@ -2267,18 +2267,18 @@
     (i64.store offset=0x41b align=1 (i32.const 0) (get_local 0x41b))
     (i64.store offset=0x41c align=1 (i32.const 0) (get_local 0x41c))
     (i64.store offset=0x41d align=1 (i32.const 0) (get_local 0x41d))
     (i64.store offset=0x41e align=1 (i32.const 0) (get_local 0x41e))
     (i64.store offset=0x41f align=1 (i32.const 0) (get_local 0x41f))
   )
 )
 
-(assert_trap (invoke "test-guard-page-skip" (i32.const 0)) "call stack exhausted")
-(assert_trap (invoke "test-guard-page-skip" (i32.const 100)) "call stack exhausted")
-(assert_trap (invoke "test-guard-page-skip" (i32.const 200)) "call stack exhausted")
-(assert_trap (invoke "test-guard-page-skip" (i32.const 300)) "call stack exhausted")
-(assert_trap (invoke "test-guard-page-skip" (i32.const 400)) "call stack exhausted")
-(assert_trap (invoke "test-guard-page-skip" (i32.const 500)) "call stack exhausted")
-(assert_trap (invoke "test-guard-page-skip" (i32.const 600)) "call stack exhausted")
-(assert_trap (invoke "test-guard-page-skip" (i32.const 700)) "call stack exhausted")
-(assert_trap (invoke "test-guard-page-skip" (i32.const 800)) "call stack exhausted")
-(assert_trap (invoke "test-guard-page-skip" (i32.const 900)) "call stack exhausted")
\ No newline at end of file
+(assert_exhaustion (invoke "test-guard-page-skip" (i32.const 0)) "call stack exhausted")
+(assert_exhaustion (invoke "test-guard-page-skip" (i32.const 100)) "call stack exhausted")
+(assert_exhaustion (invoke "test-guard-page-skip" (i32.const 200)) "call stack exhausted")
+(assert_exhaustion (invoke "test-guard-page-skip" (i32.const 300)) "call stack exhausted")
+(assert_exhaustion (invoke "test-guard-page-skip" (i32.const 400)) "call stack exhausted")
+(assert_exhaustion (invoke "test-guard-page-skip" (i32.const 500)) "call stack exhausted")
+(assert_exhaustion (invoke "test-guard-page-skip" (i32.const 600)) "call stack exhausted")
+(assert_exhaustion (invoke "test-guard-page-skip" (i32.const 700)) "call stack exhausted")
+(assert_exhaustion (invoke "test-guard-page-skip" (i32.const 800)) "call stack exhausted")
+(assert_exhaustion (invoke "test-guard-page-skip" (i32.const 900)) "call stack exhausted")
\ No newline at end of file
--- a/js/src/jit-test/tests/wasm/wast.js
+++ b/js/src/jit-test/tests/wasm/wast.js
@@ -273,16 +273,24 @@ function getModuleAndField(e) {
 
     let module = moduleCache.get(moduleName);
     let fieldName = e.list[nextArgIndex++].str;
     let rest = e.list.slice(nextArgIndex).map(exec);
 
     return [module, fieldName, rest];
 }
 
+let StackOverflowError = (function() {
+    try {
+        (function f() { f(); })();
+    } catch(e) {
+        return e.constructor;
+    }
+})();
+
 // Recursively execute the expression.
 function exec(e) {
     var exprName = e.list[0].str;
 
     if (exprName === "module") {
         let moduleText = e.toString();
 
         let moduleName = null;
@@ -475,16 +483,28 @@ function exec(e) {
             caught = true;
             if (err.toString().indexOf(errMsg) === -1)
                 warn(`expected error message "${errMsg}", got "${err}"`);
         }
         assert(caught, "assert_unlinkable exception not caught");
         return;
     }
 
+    if (exprName === 'assert_exhaustion') {
+        let caught = false;
+        try {
+            exec(e.list[1]);
+        } catch(err) {
+            caught = true;
+            assert(err instanceof StackOverflowError, "not a StackOverflowError");
+        }
+        assert(caught, "assert_exhaustion exception not caught");
+        return;
+    }
+
     if (!handleNonStandard(exprName, e)) {
         assert(false, "NYI: " + e);
     }
 }
 
 var args = typeof importedArgs !== 'undefined' ? importedArgs : scriptArgs;
 
 // Whether we should keep on executing tests if one of them failed or throw.