diff options
-rwxr-xr-x | test/gen-spec-js.py | 45 | ||||
-rw-r--r-- | test/gen-spec-js/action.txt | 12 | ||||
-rw-r--r-- | test/gen-spec-js/assert_exhaustion.txt | 8 | ||||
-rw-r--r-- | test/gen-spec-js/assert_malformed-quote.txt | 2 | ||||
-rw-r--r-- | test/gen-spec-js/assert_malformed.txt | 2 | ||||
-rw-r--r-- | test/gen-spec-js/assert_return.txt | 32 | ||||
-rw-r--r-- | test/gen-spec-js/assert_return_nan.txt | 36 | ||||
-rw-r--r-- | test/gen-spec-js/assert_trap.txt | 12 | ||||
-rw-r--r-- | test/gen-spec-js/assert_uninstantiable.txt | 2 | ||||
-rw-r--r-- | test/gen-spec-js/assert_unlinkable.txt | 2 | ||||
-rw-r--r-- | test/gen-spec-js/basic.txt | 8 | ||||
-rw-r--r-- | test/gen-spec-js/many-modules.txt | 31 | ||||
-rw-r--r-- | test/gen-spec-js/register.txt | 16 | ||||
-rw-r--r-- | test/gen-spec-prefix.js | 70 |
14 files changed, 199 insertions, 79 deletions
diff --git a/test/gen-spec-js.py b/test/gen-spec-js.py index 5e8d65ca..3937afad 100755 --- a/test/gen-spec-js.py +++ b/test/gen-spec-js.py @@ -378,15 +378,20 @@ class ModuleExtender(object): class JSWriter(object): - def __init__(self, base_dir, commands, out_file): + def __init__(self, base_dir, spec_json, out_file): self.base_dir = base_dir - self.commands = commands + self.source_filename = os.path.basename(spec_json['source_filename']) + self.commands = spec_json['commands'] self.out_file = out_file + self.module_idx = 0 def Write(self): for command in self.commands: self._WriteCommand(command) + def _WriteFileAndLine(self, command): + self.out_file.write('// %s:%d\n' % (self.source_filename, command['line'])) + def _WriteCommand(self, command): command_funcs = { 'module': self._WriteModuleCommand, @@ -406,20 +411,28 @@ class JSWriter(object): func = command_funcs.get(command['type']) if func is None: raise Error('Unexpected type: %s' % command['type']) + self._WriteFileAndLine(command) func(command) + self.out_file.write('\n') + + def _ModuleIdxName(self): + return '$%d' % self.module_idx def _WriteModuleCommand(self, command): + self.module_idx += 1 + idx_name = self._ModuleIdxName() + + self.out_file.write('let %s = instance("%s");\n' % + (idx_name, self._Module(command['filename']))) if 'name' in command: - self.out_file.write('let %s = ' % command['name']) - self.out_file.write('$$ = instance("%s");\n' % - self._Module(command['filename'])) + self.out_file.write('let %s = %s;\n' % (command['name'], idx_name)) def _WriteActionCommand(self, command): self.out_file.write('%s;\n' % self._Action(command['action'])) def _WriteRegisterCommand(self, command): - self.out_file.write('register("%s", %s)\n' % (command['as'], - command.get('name', '$$'))) + self.out_file.write('register("%s", %s)\n' % ( + command['as'], command.get('name', self._ModuleIdxName()))) def _WriteAssertModuleCommand(self, command): # Don't bother writing out text modules; they can't be parsed by JS. @@ -464,15 +477,15 @@ class JSWriter(object): def _Action(self, action): type_ = action['type'] - if type_ not in ('invoke', 'get'): - raise Error('Unexpected action type: %s' % type_) - - args = '' + module = action.get('module', self._ModuleIdxName()) + field = EscapeJSString(action['field']) if type_ == 'invoke': - args = '(%s)' % self._ConstantList(action.get('args', [])) - - return '%s.exports["%s"]%s' % (action.get('module', '$$'), - EscapeJSString(action['field']), args) + args = '[%s]' % self._ConstantList(action.get('args', [])) + return 'call(%s, "%s", %s)' % (module, field, args) + elif type_ == 'get': + return 'get(%s, "%s")' % (module, field) + else: + raise Error('Unexpected action type: %s' % type_) def main(args): @@ -529,7 +542,7 @@ def main(args): output.write(prefix_file.read()) output.write('\n') - JSWriter(json_dir, all_commands, output).Write() + JSWriter(json_dir, spec_json, output).Write() if options.output: out_file = open(options.output, 'w') diff --git a/test/gen-spec-js/action.txt b/test/gen-spec-js/action.txt index b2669cdf..ed26e5ef 100644 --- a/test/gen-spec-js/action.txt +++ b/test/gen-spec-js/action.txt @@ -11,7 +11,13 @@ (;; STDOUT ;;; // A deliberately empty file for testing. -$$ = instance("\x00\x61\x73\x6d\x01\x00\x00\x00\x01\x05\x01\x60\x01\x7f\x00\x02\x12\x01\x08\x73\x70\x65\x63\x74\x65\x73\x74\x05\x70\x72\x69\x6e\x74\x00\x00\x03\x02\x01\x00\x06\x06\x01\x7f\x00\x41\x0e\x0b\x07\x16\x02\x09\x70\x72\x69\x6e\x74\x5f\x69\x33\x32\x00\x01\x06\x67\x6c\x6f\x62\x61\x6c\x03\x00\x0a\x08\x01\x06\x00\x20\x00\x10\x00\x0b"); -$$.exports["print_i32"](1); -$$.exports["global"]; +// action.txt:3 +let $1 = instance("\x00\x61\x73\x6d\x01\x00\x00\x00\x01\x05\x01\x60\x01\x7f\x00\x02\x12\x01\x08\x73\x70\x65\x63\x74\x65\x73\x74\x05\x70\x72\x69\x6e\x74\x00\x00\x03\x02\x01\x00\x06\x06\x01\x7f\x00\x41\x0e\x0b\x07\x16\x02\x09\x70\x72\x69\x6e\x74\x5f\x69\x33\x32\x00\x01\x06\x67\x6c\x6f\x62\x61\x6c\x03\x00\x0a\x08\x01\x06\x00\x20\x00\x10\x00\x0b"); + +// action.txt:9 +call($1, "print_i32", [1]); + +// action.txt:10 +get($1, "global"); + ;;; STDOUT ;;) diff --git a/test/gen-spec-js/assert_exhaustion.txt b/test/gen-spec-js/assert_exhaustion.txt index 51ba3918..7fa1e718 100644 --- a/test/gen-spec-js/assert_exhaustion.txt +++ b/test/gen-spec-js/assert_exhaustion.txt @@ -8,6 +8,10 @@ (;; 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"]()); +// assert_exhaustion.txt:3 +let $1 = 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.txt:7 +assert_exhaustion(() => call($1, "foo", [])); + ;;; STDOUT ;;) diff --git a/test/gen-spec-js/assert_malformed-quote.txt b/test/gen-spec-js/assert_malformed-quote.txt index 57456a49..a842e29f 100644 --- a/test/gen-spec-js/assert_malformed-quote.txt +++ b/test/gen-spec-js/assert_malformed-quote.txt @@ -8,4 +8,6 @@ (;; STDOUT ;;; // A deliberately empty file for testing. +// assert_malformed-quote.txt:6 + ;;; STDOUT ;;) diff --git a/test/gen-spec-js/assert_malformed.txt b/test/gen-spec-js/assert_malformed.txt index e72e8ba2..1eb45521 100644 --- a/test/gen-spec-js/assert_malformed.txt +++ b/test/gen-spec-js/assert_malformed.txt @@ -6,5 +6,7 @@ (;; STDOUT ;;; // A deliberately empty file for testing. +// assert_malformed.txt:4 assert_malformed("\x00\x61\x73\x6d\xbc\x0a\x00\x00"); + ;;; STDOUT ;;) diff --git a/test/gen-spec-js/assert_return.txt b/test/gen-spec-js/assert_return.txt index 54b86416..7c65f340 100644 --- a/test/gen-spec-js/assert_return.txt +++ b/test/gen-spec-js/assert_return.txt @@ -37,12 +37,28 @@ (;; STDOUT ;;; // A deliberately empty file for testing. -$$ = instance("\x00\x61\x73\x6d\x01\x00\x00\x00\x01\x24\x07\x60\x00\x00\x60\x00\x01\x7f\x60\x02\x7f\x7f\x01\x7f\x60\x02\x7e\x7e\x01\x7e\x60\x02\x7d\x7d\x01\x7d\x60\x02\x7c\x7c\x01\x7c\x60\x00\x01\x7d\x03\x0a\x09\x00\x01\x02\x03\x04\x05\x06\x00\x00\x07\x56\x09\x09\x6e\x6f\x5f\x72\x65\x73\x75\x6c\x74\x00\x00\x02\x34\x32\x00\x01\x07\x69\x33\x32\x2e\x61\x64\x64\x00\x02\x07\x69\x36\x34\x2e\x61\x64\x64\x00\x03\x07\x66\x33\x32\x2e\x61\x64\x64\x00\x04\x07\x66\x36\x34\x2e\x61\x64\x64\x00\x05\x03\x6e\x61\x6e\x00\x06\x08\x61\x73\x73\x65\x72\x74\x5f\x30\x00\x07\x08\x61\x73\x73\x65\x72\x74\x5f\x31\x00\x08\x0a\x5a\x09\x02\x00\x0b\x04\x00\x41\x2a\x0b\x07\x00\x20\x00\x20\x01\x6a\x0b\x07\x00\x20\x00\x20\x01\x7c\x0b\x07\x00\x20\x00\x20\x01\x92\x0b\x07\x00\x20\x00\x20\x01\xa0\x0b\x07\x00\x43\x02\x00\x80\x7f\x0b\x13\x00\x02\x40\x42\x01\x42\x02\x10\x03\x42\x03\x51\x45\x0d\x00\x0f\x0b\x00\x0b\x14\x00\x02\x40\x10\x06\xbc\x43\x02\x00\x80\x7f\xbc\x46\x45\x0d\x00\x0f\x0b\x00\x0b"); -assert_return(() => $$.exports["no_result"]()); -assert_return(() => $$.exports["42"](), 42); -assert_return(() => $$.exports["i32.add"](1, 2), 3); -assert_return(() => $$.exports["assert_0"]()); -assert_return(() => $$.exports["f32.add"](f32(1.0), f32(2.0)), f32(3.0)); -assert_return(() => $$.exports["f64.add"](1.0, 2.0), 3.0); -assert_return(() => $$.exports["assert_1"]()); +// assert_return.txt:3 +let $1 = instance("\x00\x61\x73\x6d\x01\x00\x00\x00\x01\x24\x07\x60\x00\x00\x60\x00\x01\x7f\x60\x02\x7f\x7f\x01\x7f\x60\x02\x7e\x7e\x01\x7e\x60\x02\x7d\x7d\x01\x7d\x60\x02\x7c\x7c\x01\x7c\x60\x00\x01\x7d\x03\x0a\x09\x00\x01\x02\x03\x04\x05\x06\x00\x00\x07\x56\x09\x09\x6e\x6f\x5f\x72\x65\x73\x75\x6c\x74\x00\x00\x02\x34\x32\x00\x01\x07\x69\x33\x32\x2e\x61\x64\x64\x00\x02\x07\x69\x36\x34\x2e\x61\x64\x64\x00\x03\x07\x66\x33\x32\x2e\x61\x64\x64\x00\x04\x07\x66\x36\x34\x2e\x61\x64\x64\x00\x05\x03\x6e\x61\x6e\x00\x06\x08\x61\x73\x73\x65\x72\x74\x5f\x30\x00\x07\x08\x61\x73\x73\x65\x72\x74\x5f\x31\x00\x08\x0a\x5a\x09\x02\x00\x0b\x04\x00\x41\x2a\x0b\x07\x00\x20\x00\x20\x01\x6a\x0b\x07\x00\x20\x00\x20\x01\x7c\x0b\x07\x00\x20\x00\x20\x01\x92\x0b\x07\x00\x20\x00\x20\x01\xa0\x0b\x07\x00\x43\x02\x00\x80\x7f\x0b\x13\x00\x02\x40\x42\x01\x42\x02\x10\x03\x42\x03\x51\x45\x0d\x00\x0f\x0b\x00\x0b\x14\x00\x02\x40\x10\x06\xbc\x43\x02\x00\x80\x7f\xbc\x46\x45\x0d\x00\x0f\x0b\x00\x0b"); + +// assert_return.txt:24 +assert_return(() => call($1, "no_result", [])); + +// assert_return.txt:25 +assert_return(() => call($1, "42", []), 42); + +// assert_return.txt:27 +assert_return(() => call($1, "i32.add", [1, 2]), 3); + +// assert_return.txt:29 +assert_return(() => call($1, "assert_0", [])); + +// assert_return.txt:31 +assert_return(() => call($1, "f32.add", [f32(1.0), f32(2.0)]), f32(3.0)); + +// assert_return.txt:32 +assert_return(() => call($1, "f64.add", [1.0, 2.0]), 3.0); + +// assert_return.txt:35 +assert_return(() => call($1, "assert_1", [])); + ;;; STDOUT ;;) diff --git a/test/gen-spec-js/assert_return_nan.txt b/test/gen-spec-js/assert_return_nan.txt index b154c108..bc4cdd95 100644 --- a/test/gen-spec-js/assert_return_nan.txt +++ b/test/gen-spec-js/assert_return_nan.txt @@ -23,13 +23,31 @@ (;; STDOUT ;;; // A deliberately empty file for testing. -$$ = instance("\x00\x61\x73\x6d\x01\x00\x00\x00\x01\x16\x05\x60\x00\x01\x7d\x60\x01\x7d\x01\x7d\x60\x00\x01\x7c\x60\x01\x7c\x01\x7c\x60\x00\x00\x03\x0b\x0a\x00\x00\x01\x02\x02\x03\x04\x04\x04\x04\x07\x85\x01\x0a\x07\x66\x33\x32\x5f\x6e\x61\x6e\x00\x00\x10\x66\x33\x32\x5f\x6e\x61\x6e\x5f\x77\x69\x74\x68\x5f\x74\x61\x67\x00\x01\x0c\x66\x33\x32\x5f\x70\x61\x73\x73\x74\x68\x72\x75\x00\x02\x07\x66\x36\x34\x5f\x6e\x61\x6e\x00\x03\x10\x66\x36\x34\x5f\x6e\x61\x6e\x5f\x77\x69\x74\x68\x5f\x74\x61\x67\x00\x04\x0c\x66\x36\x34\x5f\x70\x61\x73\x73\x74\x68\x72\x75\x00\x05\x08\x61\x73\x73\x65\x72\x74\x5f\x30\x00\x06\x08\x61\x73\x73\x65\x72\x74\x5f\x31\x00\x07\x08\x61\x73\x73\x65\x72\x74\x5f\x32\x00\x08\x08\x61\x73\x73\x65\x72\x74\x5f\x33\x00\x09\x0a\xd3\x01\x0a\x07\x00\x43\x00\x00\xc0\x7f\x0b\x07\x00\x43\x34\x12\x80\x7f\x0b\x04\x00\x20\x00\x0b\x0b\x00\x44\x00\x00\x00\x00\x00\x00\xf8\x7f\x0b\x0b\x00\x44\x34\x12\x00\x00\x00\x00\xf0\x7f\x0b\x04\x00\x20\x00\x0b\x20\x00\x02\x40\x43\x00\x00\xc0\xff\x10\x02\xbc\x41\xff\xff\xff\xff\x07\x71\x41\x80\x80\x80\xfe\x07\x46\x45\x0d\x00\x0f\x0b\x00\x0b\x20\x00\x02\x40\x43\x34\x12\x80\x7f\x10\x02\xbc\x41\x80\x80\x80\xfe\x07\x71\x41\x80\x80\x80\xfe\x07\x46\x45\x0d\x00\x0f\x0b\x00\x0b\x2e\x00\x02\x40\x44\x00\x00\x00\x00\x00\x00\xf8\xff\x10\x05\xbd\x42\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x83\x42\x80\x80\x80\x80\x80\x80\x80\xfc\xff\x00\x51\x45\x0d\x00\x0f\x0b\x00\x0b\x2e\x00\x02\x40\x44\x34\x12\x00\x00\x00\x00\xf0\x7f\x10\x05\xbd\x42\x80\x80\x80\x80\x80\x80\x80\xfc\xff\x00\x83\x42\x80\x80\x80\x80\x80\x80\x80\xfc\xff\x00\x51\x45\x0d\x00\x0f\x0b\x00\x0b"); -assert_return_canonical_nan(() => $$.exports["f32_nan"]()); -assert_return_arithmetic_nan(() => $$.exports["f32_nan_with_tag"]()); -assert_return_canonical_nan(() => $$.exports["f64_nan"]()); -assert_return_arithmetic_nan(() => $$.exports["f64_nan_with_tag"]()); -assert_return(() => $$.exports["assert_0"]()); -assert_return(() => $$.exports["assert_1"]()); -assert_return(() => $$.exports["assert_2"]()); -assert_return(() => $$.exports["assert_3"]()); +// assert_return_nan.txt:3 +let $1 = instance("\x00\x61\x73\x6d\x01\x00\x00\x00\x01\x16\x05\x60\x00\x01\x7d\x60\x01\x7d\x01\x7d\x60\x00\x01\x7c\x60\x01\x7c\x01\x7c\x60\x00\x00\x03\x0b\x0a\x00\x00\x01\x02\x02\x03\x04\x04\x04\x04\x07\x85\x01\x0a\x07\x66\x33\x32\x5f\x6e\x61\x6e\x00\x00\x10\x66\x33\x32\x5f\x6e\x61\x6e\x5f\x77\x69\x74\x68\x5f\x74\x61\x67\x00\x01\x0c\x66\x33\x32\x5f\x70\x61\x73\x73\x74\x68\x72\x75\x00\x02\x07\x66\x36\x34\x5f\x6e\x61\x6e\x00\x03\x10\x66\x36\x34\x5f\x6e\x61\x6e\x5f\x77\x69\x74\x68\x5f\x74\x61\x67\x00\x04\x0c\x66\x36\x34\x5f\x70\x61\x73\x73\x74\x68\x72\x75\x00\x05\x08\x61\x73\x73\x65\x72\x74\x5f\x30\x00\x06\x08\x61\x73\x73\x65\x72\x74\x5f\x31\x00\x07\x08\x61\x73\x73\x65\x72\x74\x5f\x32\x00\x08\x08\x61\x73\x73\x65\x72\x74\x5f\x33\x00\x09\x0a\xd3\x01\x0a\x07\x00\x43\x00\x00\xc0\x7f\x0b\x07\x00\x43\x34\x12\x80\x7f\x0b\x04\x00\x20\x00\x0b\x0b\x00\x44\x00\x00\x00\x00\x00\x00\xf8\x7f\x0b\x0b\x00\x44\x34\x12\x00\x00\x00\x00\xf0\x7f\x0b\x04\x00\x20\x00\x0b\x20\x00\x02\x40\x43\x00\x00\xc0\xff\x10\x02\xbc\x41\xff\xff\xff\xff\x07\x71\x41\x80\x80\x80\xfe\x07\x46\x45\x0d\x00\x0f\x0b\x00\x0b\x20\x00\x02\x40\x43\x34\x12\x80\x7f\x10\x02\xbc\x41\x80\x80\x80\xfe\x07\x71\x41\x80\x80\x80\xfe\x07\x46\x45\x0d\x00\x0f\x0b\x00\x0b\x2e\x00\x02\x40\x44\x00\x00\x00\x00\x00\x00\xf8\xff\x10\x05\xbd\x42\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x83\x42\x80\x80\x80\x80\x80\x80\x80\xfc\xff\x00\x51\x45\x0d\x00\x0f\x0b\x00\x0b\x2e\x00\x02\x40\x44\x34\x12\x00\x00\x00\x00\xf0\x7f\x10\x05\xbd\x42\x80\x80\x80\x80\x80\x80\x80\xfc\xff\x00\x83\x42\x80\x80\x80\x80\x80\x80\x80\xfc\xff\x00\x51\x45\x0d\x00\x0f\x0b\x00\x0b"); + +// assert_return_nan.txt:12 +assert_return_canonical_nan(() => call($1, "f32_nan", [])); + +// assert_return_nan.txt:13 +assert_return_arithmetic_nan(() => call($1, "f32_nan_with_tag", [])); + +// assert_return_nan.txt:14 +assert_return_canonical_nan(() => call($1, "f64_nan", [])); + +// assert_return_nan.txt:15 +assert_return_arithmetic_nan(() => call($1, "f64_nan_with_tag", [])); + +// assert_return_nan.txt:18 +assert_return(() => call($1, "assert_0", [])); + +// assert_return_nan.txt:19 +assert_return(() => call($1, "assert_1", [])); + +// assert_return_nan.txt:20 +assert_return(() => call($1, "assert_2", [])); + +// assert_return_nan.txt:21 +assert_return(() => call($1, "assert_3", [])); + ;;; STDOUT ;;) diff --git a/test/gen-spec-js/assert_trap.txt b/test/gen-spec-js/assert_trap.txt index 2096245c..cf21ef49 100644 --- a/test/gen-spec-js/assert_trap.txt +++ b/test/gen-spec-js/assert_trap.txt @@ -12,7 +12,13 @@ (;; STDOUT ;;; // A deliberately empty file for testing. -$$ = instance("\x00\x61\x73\x6d\x01\x00\x00\x00\x01\x09\x02\x60\x00\x00\x60\x01\x7d\x01\x7f\x03\x04\x03\x00\x01\x00\x07\x28\x03\x0b\x75\x6e\x72\x65\x61\x63\x68\x61\x62\x6c\x65\x00\x00\x0b\x69\x33\x32\x2e\x74\x72\x75\x6e\x63\x5f\x73\x00\x01\x08\x61\x73\x73\x65\x72\x74\x5f\x30\x00\x02\x0a\x17\x03\x03\x00\x00\x0b\x05\x00\x20\x00\xa8\x0b\x0b\x00\x43\x00\x00\xc0\xff\x10\x01\x0c\x00\x0b"); -assert_trap(() => $$.exports["unreachable"]()); -assert_trap(() => $$.exports["assert_0"]()); +// assert_trap.txt:3 +let $1 = instance("\x00\x61\x73\x6d\x01\x00\x00\x00\x01\x09\x02\x60\x00\x00\x60\x01\x7d\x01\x7f\x03\x04\x03\x00\x01\x00\x07\x28\x03\x0b\x75\x6e\x72\x65\x61\x63\x68\x61\x62\x6c\x65\x00\x00\x0b\x69\x33\x32\x2e\x74\x72\x75\x6e\x63\x5f\x73\x00\x01\x08\x61\x73\x73\x65\x72\x74\x5f\x30\x00\x02\x0a\x17\x03\x03\x00\x00\x0b\x05\x00\x20\x00\xa8\x0b\x0b\x00\x43\x00\x00\xc0\xff\x10\x01\x0c\x00\x0b"); + +// assert_trap.txt:9 +assert_trap(() => call($1, "unreachable", [])); + +// assert_trap.txt:11 +assert_trap(() => call($1, "assert_0", [])); + ;;; STDOUT ;;) diff --git a/test/gen-spec-js/assert_uninstantiable.txt b/test/gen-spec-js/assert_uninstantiable.txt index 84d8c5e6..7f0024c0 100644 --- a/test/gen-spec-js/assert_uninstantiable.txt +++ b/test/gen-spec-js/assert_uninstantiable.txt @@ -8,5 +8,7 @@ (;; STDOUT ;;; // A deliberately empty file for testing. +// assert_uninstantiable.txt:4 assert_uninstantiable("\x00\x61\x73\x6d\x01\x00\x00\x00\x01\x04\x01\x60\x00\x00\x03\x02\x01\x00\x08\x01\x00\x0a\x05\x01\x03\x00\x00\x0b"); + ;;; STDOUT ;;) diff --git a/test/gen-spec-js/assert_unlinkable.txt b/test/gen-spec-js/assert_unlinkable.txt index 8c5f1699..591d222b 100644 --- a/test/gen-spec-js/assert_unlinkable.txt +++ b/test/gen-spec-js/assert_unlinkable.txt @@ -6,5 +6,7 @@ (;; STDOUT ;;; // A deliberately empty file for testing. +// assert_unlinkable.txt:4 assert_unlinkable("\x00\x61\x73\x6d\x01\x00\x00\x00\x01\x04\x01\x60\x00\x00\x02\x0b\x01\x03\x66\x6f\x6f\x03\x62\x61\x72\x00\x00"); + ;;; STDOUT ;;) diff --git a/test/gen-spec-js/basic.txt b/test/gen-spec-js/basic.txt index 57d542f8..d0827ef2 100644 --- a/test/gen-spec-js/basic.txt +++ b/test/gen-spec-js/basic.txt @@ -7,6 +7,10 @@ (;; STDOUT ;;; // A deliberately empty file for testing. -$$ = instance("\x00\x61\x73\x6d\x01\x00\x00\x00\x01\x05\x01\x60\x00\x01\x7f\x03\x02\x01\x00\x07\x06\x01\x02\x34\x32\x00\x00\x0a\x06\x01\x04\x00\x41\x2a\x0b"); -assert_return(() => $$.exports["42"](), 42); +// basic.txt:3 +let $1 = instance("\x00\x61\x73\x6d\x01\x00\x00\x00\x01\x05\x01\x60\x00\x01\x7f\x03\x02\x01\x00\x07\x06\x01\x02\x34\x32\x00\x00\x0a\x06\x01\x04\x00\x41\x2a\x0b"); + +// basic.txt:6 +assert_return(() => call($1, "42", []), 42); + ;;; STDOUT ;;) diff --git a/test/gen-spec-js/many-modules.txt b/test/gen-spec-js/many-modules.txt index c6179866..b585636d 100644 --- a/test/gen-spec-js/many-modules.txt +++ b/test/gen-spec-js/many-modules.txt @@ -11,11 +11,28 @@ (;; STDOUT ;;; // A deliberately empty file for testing. -let $A = $$ = instance("\x00\x61\x73\x6d\x01\x00\x00\x00\x01\x05\x01\x60\x00\x01\x7f\x03\x02\x01\x00\x07\x05\x01\x01\x66\x00\x00\x0a\x06\x01\x04\x00\x41\x01\x0b"); -let $B = $$ = instance("\x00\x61\x73\x6d\x01\x00\x00\x00\x01\x05\x01\x60\x00\x01\x7f\x03\x02\x01\x00\x07\x05\x01\x01\x66\x00\x00\x0a\x06\x01\x04\x00\x41\x02\x0b"); -let $C = $$ = instance("\x00\x61\x73\x6d\x01\x00\x00\x00\x01\x05\x01\x60\x00\x01\x7f\x03\x02\x01\x00\x07\x05\x01\x01\x66\x00\x00\x0a\x06\x01\x04\x00\x41\x03\x0b"); -assert_return(() => $$.exports["f"](), 3); -assert_return(() => $A.exports["f"](), 1); -assert_return(() => $B.exports["f"](), 2); -assert_return(() => $C.exports["f"](), 3); +// many-modules.txt:3 +let $1 = instance("\x00\x61\x73\x6d\x01\x00\x00\x00\x01\x05\x01\x60\x00\x01\x7f\x03\x02\x01\x00\x07\x05\x01\x01\x66\x00\x00\x0a\x06\x01\x04\x00\x41\x01\x0b"); +let $A = $1; + +// many-modules.txt:4 +let $2 = instance("\x00\x61\x73\x6d\x01\x00\x00\x00\x01\x05\x01\x60\x00\x01\x7f\x03\x02\x01\x00\x07\x05\x01\x01\x66\x00\x00\x0a\x06\x01\x04\x00\x41\x02\x0b"); +let $B = $2; + +// many-modules.txt:5 +let $3 = instance("\x00\x61\x73\x6d\x01\x00\x00\x00\x01\x05\x01\x60\x00\x01\x7f\x03\x02\x01\x00\x07\x05\x01\x01\x66\x00\x00\x0a\x06\x01\x04\x00\x41\x03\x0b"); +let $C = $3; + +// many-modules.txt:7 +assert_return(() => call($3, "f", []), 3); + +// many-modules.txt:8 +assert_return(() => call($A, "f", []), 1); + +// many-modules.txt:9 +assert_return(() => call($B, "f", []), 2); + +// many-modules.txt:10 +assert_return(() => call($C, "f", []), 3); + ;;; STDOUT ;;) diff --git a/test/gen-spec-js/register.txt b/test/gen-spec-js/register.txt index 79c0ebfa..f89a33a6 100644 --- a/test/gen-spec-js/register.txt +++ b/test/gen-spec-js/register.txt @@ -13,8 +13,16 @@ (;; STDOUT ;;; // A deliberately empty file for testing. -$$ = instance("\x00\x61\x73\x6d\x01\x00\x00\x00\x01\x05\x01\x60\x00\x01\x7f\x03\x02\x01\x00\x07\x05\x01\x01\x66\x00\x00\x0a\x06\x01\x04\x00\x41\x01\x0b"); -register("A", $$) -$$ = instance("\x00\x61\x73\x6d\x01\x00\x00\x00\x01\x05\x01\x60\x00\x01\x7f\x02\x07\x01\x01\x41\x01\x66\x00\x00\x03\x02\x01\x00\x07\x05\x01\x01\x67\x00\x01\x0a\x06\x01\x04\x00\x10\x00\x0b"); -assert_return(() => $$.exports["g"](), 1); +// register.txt:3 +let $1 = instance("\x00\x61\x73\x6d\x01\x00\x00\x00\x01\x05\x01\x60\x00\x01\x7f\x03\x02\x01\x00\x07\x05\x01\x01\x66\x00\x00\x0a\x06\x01\x04\x00\x41\x01\x0b"); + +// register.txt:6 +register("A", $1) + +// register.txt:8 +let $2 = instance("\x00\x61\x73\x6d\x01\x00\x00\x00\x01\x05\x01\x60\x00\x01\x7f\x02\x07\x01\x01\x41\x01\x66\x00\x00\x03\x02\x01\x00\x07\x05\x01\x01\x67\x00\x01\x0a\x06\x01\x04\x00\x10\x00\x0b"); + +// register.txt:12 +assert_return(() => call($2, "g", []), 1); + ;;; STDOUT ;;) diff --git a/test/gen-spec-prefix.js b/test/gen-spec-prefix.js index ed68c84d..0ce7ce46 100644 --- a/test/gen-spec-prefix.js +++ b/test/gen-spec-prefix.js @@ -1,9 +1,7 @@ /* Lovingly generated by gen-spec-js.py based on the wonderful content of * - * https://github.com/WebAssembly/spec/blob/master/interpreter/host/js.ml */ + * https://github.com/WebAssembly/spec/blob/master/interpreter/script/js.ml */ 'use strict'; -let soft_validate = true; - let spectest = { print: print || ((...xs) => console.log(...xs)), global: 666, @@ -11,18 +9,26 @@ let spectest = { memory: new WebAssembly.Memory({initial: 1, maximum: 2}),}; let registry = {spectest}; -let $$; function register(name, instance) { registry[name] = instance.exports; } -function module(bytes) { +function module(bytes, valid = true) { let buffer = new ArrayBuffer(bytes.length); let view = new Uint8Array(buffer); for (let i = 0; i < bytes.length; ++i) { view[i] = bytes.charCodeAt(i); } + let validated; + try { + validated = WebAssembly.validate(buffer); + } catch (e) { + throw new Error("Wasm validate throws"); + } + if (validated !== valid) { + throw new Error("Wasm validate failure" + (valid ? "" : " expected")); + } return new WebAssembly.Module(buffer); } @@ -30,29 +36,40 @@ function instance(bytes, imports = registry) { return new WebAssembly.Instance(module(bytes), imports); } +function instance(bytes, imports = registry) { + return new WebAssembly.Instance(module(bytes), imports); +} + +function call(instance, name, args) { + return instance.exports[name](...args); +} + +function get(instance, name) { + return instance.exports[name]; +} + +function exports(name, instance) { + return {[name]: instance.exports}; +} + +function run(action) { + action(); +} + function assert_malformed(bytes) { - try { module(bytes) } catch (e) { + try { module(bytes, false) } catch (e) { if (e instanceof WebAssembly.CompileError) return; } throw new Error("Wasm decoding failure expected"); } function assert_invalid(bytes) { - try { module(bytes) } catch (e) { + try { module(bytes, false) } catch (e) { if (e instanceof WebAssembly.CompileError) return; } throw new Error("Wasm validation failure expected"); } -function assert_soft_invalid(bytes) { - try { module(bytes) } catch (e) { - if (e instanceof WebAssembly.CompileError) return; - throw new Error("Wasm validation failure expected"); - } - if (soft_validate) - throw new Error("Wasm validation failure expected"); -} - function assert_unlinkable(bytes) { let mod = module(bytes); try { new WebAssembly.Instance(mod, registry) } catch (e) { @@ -76,6 +93,16 @@ function assert_trap(action) { throw new Error("Wasm trap expected"); } +let StackOverflow; +try { (function f() { 1 + f() })() } catch (e) { StackOverflow = e.constructor } + +function assert_exhaustion(action) { + try { action() } catch (e) { + if (e instanceof StackOverflow) return; + } + throw new Error("Wasm resource exhaustion expected"); +} + function assert_return(action, expected) { let actual = action(); if (!Object.is(actual, expected)) { @@ -93,19 +120,12 @@ function assert_return_canonical_nan(action) { } function assert_return_arithmetic_nan(action) { - let actual = action(); // Note that JS can't reliably distinguish different NaN values, - // so there's no good way to test that it's a canonical NaN. + // so there's no good way to test for specific bitpatterns here. + let actual = action(); if (!Number.isNaN(actual)) { throw new Error("Wasm return value NaN expected, got " + actual); }; } -function assert_exhaustion(action) { - try { action() } catch (e) { - if (e instanceof RangeError) return; - } - throw new Error("RangeError expected"); -} - let f32 = Math.fround; |