summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Smith <binjimin@gmail.com>2017-02-27 18:19:03 -0800
committerGitHub <noreply@github.com>2017-02-27 18:19:03 -0800
commitb44543c99c8f044f8106e3d46f055a9e2380d9fb (patch)
tree4b98802a440043fd22e359ef1a30d2c38c4e5e47
parentf94275a6cf1f9ef990ec47d97a1174765790d56c (diff)
downloadwabt-b44543c99c8f044f8106e3d46f055a9e2380d9fb.tar.gz
wabt-b44543c99c8f044f8106e3d46f055a9e2380d9fb.tar.bz2
wabt-b44543c99c8f044f8106e3d46f055a9e2380d9fb.zip
Update gen-spec-js to support assert_exhaustion (#313)
-rwxr-xr-xtest/gen-spec-js.py9
-rw-r--r--test/gen-spec-js/assert_exhaustion.txt13
-rw-r--r--test/gen-spec-prefix.js7
3 files changed, 24 insertions, 5 deletions
diff --git a/test/gen-spec-js.py b/test/gen-spec-js.py
index a715acc3..c8502f31 100755
--- a/test/gen-spec-js.py
+++ b/test/gen-spec-js.py
@@ -183,9 +183,7 @@ def IsValidJSCommand(command):
expected = command['expected']
return (IsValidJSAction(action) and
all(IsValidJSConstant(x) for x in expected))
- elif type_ == 'assert_return_nan':
- return IsValidJSAction(action)
- elif type_ == 'assert_trap':
+ elif type_ in ('assert_return_nan', 'assert_trap', 'assert_exhaustion'):
return IsValidJSAction(action)
@@ -200,7 +198,7 @@ def CollectInvalidModuleCommands(commands):
if module_name:
module_map[module_name] = pair
elif command['type'] in ('assert_return', 'assert_return_nan',
- 'assert_trap'):
+ 'assert_trap', 'assert_exhaustion'):
if IsValidJSCommand(command):
continue
@@ -270,7 +268,7 @@ class ModuleExtender(object):
# Change the command to assert_return, it won't return NaN anymore.
command['type'] = 'assert_return'
- elif command_type == 'assert_trap':
+ elif command_type in ('assert_trap', 'assert_exhaustion'):
self.lines.append('(func (export "%s")' % new_field)
self._Action(command['action'])
self.lines.extend(['br 0', ')'])
@@ -363,6 +361,7 @@ class JSWriter(object):
'assert_return': self._WriteAssertReturnCommand,
'assert_return_nan': self._WriteAssertActionCommand,
'assert_trap': self._WriteAssertActionCommand,
+ 'assert_exhaustion': self._WriteAssertActionCommand,
}
func = command_funcs.get(command['type'])
diff --git a/test/gen-spec-js/assert_exhaustion.txt b/test/gen-spec-js/assert_exhaustion.txt
new file mode 100644
index 00000000..51ba3918
--- /dev/null
+++ b/test/gen-spec-js/assert_exhaustion.txt
@@ -0,0 +1,13 @@
+;;; TOOL: run-gen-spec-js
+;;; FLAGS: --prefix=%(test_dir)s/gen-spec-empty-prefix.js
+(module
+ (func (export "foo")
+ call 0))
+
+(assert_exhaustion (invoke "foo") "so exhausted")
+(;; STDOUT ;;;
+// A deliberately empty file for testing.
+
+$$ = instance("\x00\x61\x73\x6d\x01\x00\x00\x00\x01\x04\x01\x60\x00\x00\x03\x02\x01\x00\x07\x07\x01\x03\x66\x6f\x6f\x00\x00\x0a\x06\x01\x04\x00\x10\x00\x0b");
+assert_exhaustion(() => $$.exports["foo"]());
+;;; STDOUT ;;)
diff --git a/test/gen-spec-prefix.js b/test/gen-spec-prefix.js
index 7806c477..36692dc0 100644
--- a/test/gen-spec-prefix.js
+++ b/test/gen-spec-prefix.js
@@ -90,4 +90,11 @@ function assert_return_nan(action) {
};
}
+function assert_exhaustion(action) {
+ try { action() } catch (e) {
+ if (e instanceof RangeError) return;
+ }
+ throw new Error("RangeError expected");
+}
+
let f32 = Math.fround;