Skip to content
This repository has been archived by the owner on Dec 22, 2021. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into merge-upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
ngzhian committed Feb 2, 2021
2 parents f5c5dcc + a21888d commit 7266523
Show file tree
Hide file tree
Showing 14 changed files with 446 additions and 37 deletions.
4 changes: 2 additions & 2 deletions document/core/exec/instructions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,7 @@ Memory Instructions

a. Let :math:`n` be the integer for which :math:`\bytes_{\iN}(n) = b^\ast`.

b. Let :math:`c` be the result of computing :math:`\extend\F{\_}\sx_{N,|t|}(n)`.
b. Let :math:`c` be the result of computing :math:`\extend^{\sx}_{N,|t|}(n)`.

13. Else:

Expand All @@ -990,7 +990,7 @@ Memory Instructions
\\[1ex]
\begin{array}{lcl@{\qquad}l}
S; F; (\I32.\CONST~i)~(t.\LOAD{N}\K{\_}\sx~\memarg) &\stepto&
S; F; (t.\CONST~\extend\F{\_}\sx_{N,|t|}(n))
S; F; (t.\CONST~\extend^{\sx}_{N,|t|}(n))
\end{array}
\\ \qquad
\begin{array}[t]{@{}r@{~}l@{}}
Expand Down
3 changes: 2 additions & 1 deletion document/js-api/index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -796,14 +796,15 @@ Each {{Table}} object has a \[[Table]] internal slot, which is a [=table address
1. Let |store| be the [=surrounding agent=]'s [=associated store=].
1. Let |result| be [=table_read=](|store|, |tableaddr|, |index|).
1. If |result| is [=error=], throw a {{RangeError}} exception.
1. If |result| is ε, return null.
1. Let |function| be the result of creating [=a new Exported Function=] from |result|.
1. Return |function|.
</div>

<div algorithm>
The <dfn method for="Table">set(|index|, |value|)</dfn> method, when invoked, performs the following steps:
1. Let |tableaddr| be **this**.\[[Table]].
1. If |value| is null, let |funcaddr| be an empty [=function element=].
1. If |value| is null, let |funcaddr| be ε.
1. Otherwise,
1. If |value| does not have a \[[FunctionAddress]] internal slot, throw a {{TypeError}} exception.
1. Let |funcaddr| be |value|.\[[FunctionAddress]].
Expand Down
22 changes: 16 additions & 6 deletions document/web-api/index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -253,17 +253,27 @@ application/wasm
<dt>Encoding Considerations:</dt>
<dd>binary</dd>
<dt>Security Considerations:</dt>
<dd>See see WebAssembly Core Security Considerations<br/>
https://www.w3.org/TR/wasm-core/#security-considerations%E2%91%A0</dd>
<dd>
<p>WebAssembly is a standard, a safe, portable, low-level code format. The
security considerations associated with executing WebAssembly code are
described in https://www.w3.org/TR/wasm-core/#security-considerations.</p>
<p>The WebAssembly format includes no integrity or privacy protection. If
such protection is needed it must be provided externally, e.g., through
the use of HTTPS.</p>
</dd>
<dt>Interoperability Considerations:</dt>
<dd>See see WebAssembly Core Conformance<br/>
<dd>See WebAssembly Core Conformance<br/>
https://www.w3.org/TR/wasm-core/#conformance</dd>
<dt>Published specification:</dt>
https://www.w3.org/TR/wasm-core-1/
<dd>https://www.w3.org/TR/wasm-core-1/
https://www.w3.org/TR/wasm-js-api-1/
https://www.w3.org/TR/wasm-web-api-1/
https://www.w3.org/TR/wasm-web-api-1/</dd>
<dt>Application Usage:</dt>
<dd>The application/wasm media type is already in use as the type used to describe WebAssembly files when sent over HTTP to be executed by browsers, which is a common scenario. Additionally, several WebAssembly runtimes that take advantage of the safety and portability while targeting efficient execution and compact representation.</dd>
<dd>The application/wasm media type is intended for use as the type used to
describe WebAssembly files when sent over HTTP to be executed by browsers,
which is a common scenario. Additionally, the type is used by several
WebAssembly runtimes that take advantage of the safety and portability
while targeting efficient execution and compact representation.</dd>
<dt>Fragment Identifier Considerations:</dt>
<dd>None</dd>
<dt>Restrictions on usage:</dt>
Expand Down
30 changes: 30 additions & 0 deletions interpreter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,36 @@ The `input` and `output` meta commands determine the requested file format from
The interpreter supports a "dry" mode (flag `-d`), in which modules are only validated. In this mode, all actions and assertions are ignored.
It also supports an "unchecked" mode (flag `-u`), in which module definitions are not validated before use.


### Spectest host module

When running scripts, the interpreter predefines a simple host module named `"spectest"` that has the following module type:
```
(module
(global (export "global_i32") i32)
(global (export "global_i64") i64)
(global (export "global_f32") f32)
(global (export "global_f64") f64)
(table (export "table") 10 20 funcref)
(memory (export "memory") 1 2)
(func (export "print"))
(func (export "print_i32") (param i32))
(func (export "print_i64") (param i64))
(func (export "print_f32") (param f32))
(func (export "print_f64") (param f64))
(func (export "print_i32_f32") (param i32 f32))
(func (export "print_f64_f64") (param f64 f64))
)
```
The `print` functions are assumes to print their respective argument values to stdout (followed by a newline) and can be used to produce observable output.

Note: This module predates the `register` command and should no longer be needed for new tests.
We might remove it in the future, so consider it deprecated.


### Binary Scripts

The grammar of binary scripts is a subset of the grammar for general scripts:
Expand Down
6 changes: 4 additions & 2 deletions interpreter/host/spectest.ml
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ let lookup name t =
match Utf8.encode name, t with
| "print", _ -> ExternFunc (func print (FuncType ([], [])))
| "print_i32", _ -> ExternFunc (func print (FuncType ([I32Type], [])))
| "print_i64", _ -> ExternFunc (func print (FuncType ([I64Type], [])))
| "print_f32", _ -> ExternFunc (func print (FuncType ([F32Type], [])))
| "print_f64", _ -> ExternFunc (func print (FuncType ([F64Type], [])))
| "print_i32_f32", _ ->
ExternFunc (func print (FuncType ([I32Type; F32Type], [])))
| "print_f64_f64", _ ->
ExternFunc (func print (FuncType ([F64Type; F64Type], [])))
| "print_f32", _ -> ExternFunc (func print (FuncType ([F32Type], [])))
| "print_f64", _ -> ExternFunc (func print (FuncType ([F64Type], [])))
| "global_i32", _ -> ExternGlobal (global (GlobalType (I32Type, Immutable)))
| "global_i64", _ -> ExternGlobal (global (GlobalType (I64Type, Immutable)))
| "global_f32", _ -> ExternGlobal (global (GlobalType (F32Type, Immutable)))
| "global_f64", _ -> ExternGlobal (global (GlobalType (F64Type, Immutable)))
| "table", _ -> ExternTable table
Expand Down
37 changes: 36 additions & 1 deletion test/core/binary.wast
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,24 @@
"zero flag expected"
)

;; No more than 2^32 locals.
;; Local number is unsigned 32 bit
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\01\04\01\60\00\00" ;; Type section
"\03\02\01\00" ;; Function section
"\0a\0c\01" ;; Code section

;; function 0
"\0a\02"
"\80\80\80\80\10\7f" ;; 0x100000000 i32
"\02\7e" ;; 0x00000002 i64
"\0b" ;; end
)
"integer too large"
)

;; No more than 2^32-1 locals.
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
Expand All @@ -367,6 +384,24 @@
"too many locals"
)

(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\01\06\01\60\02\7f\7f\00" ;; Type section: (param i32 i32)
"\03\02\01\00" ;; Function section
"\0a\1c\01" ;; Code section

;; function 0
"\1a\04"
"\80\80\80\80\04\7f" ;; 0x40000000 i32
"\80\80\80\80\04\7e" ;; 0x40000000 i64
"\80\80\80\80\04\7d" ;; 0x40000000 f32
"\80\80\80\80\04\7c" ;; 0x40000000 f64
"\0b" ;; end
)
"too many locals"
)

;; Local count can be 0.
(module binary
"\00asm" "\01\00\00\00"
Expand Down
35 changes: 35 additions & 0 deletions test/core/br_table.wast
Original file line number Diff line number Diff line change
Expand Up @@ -1464,6 +1464,16 @@
))
"type mismatch"
)
(assert_invalid
(module (func
(block (result i32)
(block (result i64)
(br_table 0 1 (i32.const 0) (i32.const 0))
)
)
))
"type mismatch"
)

(assert_invalid
(module (func $type-index-void-vs-i32
Expand Down Expand Up @@ -1552,6 +1562,31 @@
"type mismatch"
)

(assert_invalid
(module
(func (param i32) (result i32)
(loop (result i32)
(block (result i32)
(br_table 0 1 (i32.const 1) (local.get 0))
)
)
)
)
"type mismatch"
)
(assert_invalid
(module
(func (param i32) (result i32)
(block (result i32)
(loop (result i32)
(br_table 0 1 (i32.const 1) (local.get 0))
)
)
)
)
"type mismatch"
)


(assert_invalid
(module (func $unbound-label
Expand Down
60 changes: 60 additions & 0 deletions test/core/data.wast
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,40 @@
"type mismatch"
)

(assert_invalid
(module
(memory 1)
(data (offset (;empty instruction sequence;)))
)
"type mismatch"
)

(assert_invalid
(module
(memory 1)
(data (offset (i32.const 0) (i32.const 0)))
)
"type mismatch"
)

(assert_invalid
(module
(global (import "test" "global-i32") i32)
(memory 1)
(data (offset (global.get 0) (global.get 0)))
)
"type mismatch"
)

(assert_invalid
(module
(global (import "test" "global-i32") i32)
(memory 1)
(data (offset (global.get 0) (i32.const 0)))
)
"type mismatch"
)

(assert_invalid
(module
(memory 1)
Expand Down Expand Up @@ -396,3 +430,29 @@
;; (module (memory 1) (data (global.get $g)) (global $g (mut i32) (i32.const 0)))
;; "constant expression required"
;; )

(assert_invalid
(module
(memory 1)
(data (global.get 0))
)
"unknown global 0"
)

(assert_invalid
(module
(global (import "test" "global-i32") i32)
(memory 1)
(data (global.get 1))
)
"unknown global 1"
)

(assert_invalid
(module
(global (import "test" "global-mut-i32") (mut i32))
(memory 1)
(data (global.get 0))
)
"constant expression required"
)
61 changes: 61 additions & 0 deletions test/core/elem.wast
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,41 @@
"type mismatch"
)

(assert_invalid
(module
(table 1 funcref)
(elem (offset (;empty instruction sequence;)))
)
"type mismatch"
)

(assert_invalid
(module
(table 1 funcref)
(elem (offset (i32.const 0) (i32.const 0)))
)
"type mismatch"
)

(assert_invalid
(module
(global (import "test" "global-i32") i32)
(table 1 funcref)
(elem (offset (global.get 0) (global.get 0)))
)
"type mismatch"
)

(assert_invalid
(module
(global (import "test" "global-i32") i32)
(table 1 funcref)
(elem (offset (global.get 0) (i32.const 0)))
)
"type mismatch"
)


(assert_invalid
(module
(table 1 funcref)
Expand Down Expand Up @@ -300,6 +335,32 @@
;; "constant expression required"
;; )

(assert_invalid
(module
(table 1 funcref)
(elem (global.get 0))
)
"unknown global 0"
)

(assert_invalid
(module
(global (import "test" "global-i32") i32)
(table 1 funcref)
(elem (global.get 1))
)
"unknown global 1"
)

(assert_invalid
(module
(global (import "test" "global-mut-i32") (mut i32))
(table 1 funcref)
(elem (global.get 0))
)
"constant expression required"
)

;; Two elements target the same slot

(module
Expand Down
Loading

0 comments on commit 7266523

Please sign in to comment.