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

Commit 92ee194

Browse files
authored
Merge pull request #442 from ngzhian/merge-upstream
Merge upstream
2 parents f5c5dcc + 7266523 commit 92ee194

File tree

14 files changed

+446
-37
lines changed

14 files changed

+446
-37
lines changed

document/core/exec/instructions.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -967,7 +967,7 @@ Memory Instructions
967967

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

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

972972
13. Else:
973973

@@ -990,7 +990,7 @@ Memory Instructions
990990
\\[1ex]
991991
\begin{array}{lcl@{\qquad}l}
992992
S; F; (\I32.\CONST~i)~(t.\LOAD{N}\K{\_}\sx~\memarg) &\stepto&
993-
S; F; (t.\CONST~\extend\F{\_}\sx_{N,|t|}(n))
993+
S; F; (t.\CONST~\extend^{\sx}_{N,|t|}(n))
994994
\end{array}
995995
\\ \qquad
996996
\begin{array}[t]{@{}r@{~}l@{}}

document/js-api/index.bs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -796,14 +796,15 @@ Each {{Table}} object has a \[[Table]] internal slot, which is a [=table address
796796
1. Let |store| be the [=surrounding agent=]'s [=associated store=].
797797
1. Let |result| be [=table_read=](|store|, |tableaddr|, |index|).
798798
1. If |result| is [=error=], throw a {{RangeError}} exception.
799+
1. If |result| is ε, return null.
799800
1. Let |function| be the result of creating [=a new Exported Function=] from |result|.
800801
1. Return |function|.
801802
</div>
802803

803804
<div algorithm>
804805
The <dfn method for="Table">set(|index|, |value|)</dfn> method, when invoked, performs the following steps:
805806
1. Let |tableaddr| be **this**.\[[Table]].
806-
1. If |value| is null, let |funcaddr| be an empty [=function element=].
807+
1. If |value| is null, let |funcaddr| be ε.
807808
1. Otherwise,
808809
1. If |value| does not have a \[[FunctionAddress]] internal slot, throw a {{TypeError}} exception.
809810
1. Let |funcaddr| be |value|.\[[FunctionAddress]].

document/web-api/index.bs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -253,17 +253,27 @@ application/wasm
253253
<dt>Encoding Considerations:</dt>
254254
<dd>binary</dd>
255255
<dt>Security Considerations:</dt>
256-
<dd>See see WebAssembly Core Security Considerations<br/>
257-
https://www.w3.org/TR/wasm-core/#security-considerations%E2%91%A0</dd>
256+
<dd>
257+
<p>WebAssembly is a standard, a safe, portable, low-level code format. The
258+
security considerations associated with executing WebAssembly code are
259+
described in https://www.w3.org/TR/wasm-core/#security-considerations.</p>
260+
<p>The WebAssembly format includes no integrity or privacy protection. If
261+
such protection is needed it must be provided externally, e.g., through
262+
the use of HTTPS.</p>
263+
</dd>
258264
<dt>Interoperability Considerations:</dt>
259-
<dd>See see WebAssembly Core Conformance<br/>
265+
<dd>See WebAssembly Core Conformance<br/>
260266
https://www.w3.org/TR/wasm-core/#conformance</dd>
261267
<dt>Published specification:</dt>
262-
https://www.w3.org/TR/wasm-core-1/
268+
<dd>https://www.w3.org/TR/wasm-core-1/
263269
https://www.w3.org/TR/wasm-js-api-1/
264-
https://www.w3.org/TR/wasm-web-api-1/
270+
https://www.w3.org/TR/wasm-web-api-1/</dd>
265271
<dt>Application Usage:</dt>
266-
<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>
272+
<dd>The application/wasm media type is intended for use as the type used to
273+
describe WebAssembly files when sent over HTTP to be executed by browsers,
274+
which is a common scenario. Additionally, the type is used by several
275+
WebAssembly runtimes that take advantage of the safety and portability
276+
while targeting efficient execution and compact representation.</dd>
267277
<dt>Fragment Identifier Considerations:</dt>
268278
<dd>None</dd>
269279
<dt>Restrictions on usage:</dt>

interpreter/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,36 @@ The `input` and `output` meta commands determine the requested file format from
363363
The interpreter supports a "dry" mode (flag `-d`), in which modules are only validated. In this mode, all actions and assertions are ignored.
364364
It also supports an "unchecked" mode (flag `-u`), in which module definitions are not validated before use.
365365

366+
367+
### Spectest host module
368+
369+
When running scripts, the interpreter predefines a simple host module named `"spectest"` that has the following module type:
370+
```
371+
(module
372+
(global (export "global_i32") i32)
373+
(global (export "global_i64") i64)
374+
(global (export "global_f32") f32)
375+
(global (export "global_f64") f64)
376+
377+
(table (export "table") 10 20 funcref)
378+
379+
(memory (export "memory") 1 2)
380+
381+
(func (export "print"))
382+
(func (export "print_i32") (param i32))
383+
(func (export "print_i64") (param i64))
384+
(func (export "print_f32") (param f32))
385+
(func (export "print_f64") (param f64))
386+
(func (export "print_i32_f32") (param i32 f32))
387+
(func (export "print_f64_f64") (param f64 f64))
388+
)
389+
```
390+
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.
391+
392+
Note: This module predates the `register` command and should no longer be needed for new tests.
393+
We might remove it in the future, so consider it deprecated.
394+
395+
366396
### Binary Scripts
367397

368398
The grammar of binary scripts is a subset of the grammar for general scripts:

interpreter/host/spectest.ml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,15 @@ let lookup name t =
3535
match Utf8.encode name, t with
3636
| "print", _ -> ExternFunc (func print (FuncType ([], [])))
3737
| "print_i32", _ -> ExternFunc (func print (FuncType ([I32Type], [])))
38+
| "print_i64", _ -> ExternFunc (func print (FuncType ([I64Type], [])))
39+
| "print_f32", _ -> ExternFunc (func print (FuncType ([F32Type], [])))
40+
| "print_f64", _ -> ExternFunc (func print (FuncType ([F64Type], [])))
3841
| "print_i32_f32", _ ->
3942
ExternFunc (func print (FuncType ([I32Type; F32Type], [])))
4043
| "print_f64_f64", _ ->
4144
ExternFunc (func print (FuncType ([F64Type; F64Type], [])))
42-
| "print_f32", _ -> ExternFunc (func print (FuncType ([F32Type], [])))
43-
| "print_f64", _ -> ExternFunc (func print (FuncType ([F64Type], [])))
4445
| "global_i32", _ -> ExternGlobal (global (GlobalType (I32Type, Immutable)))
46+
| "global_i64", _ -> ExternGlobal (global (GlobalType (I64Type, Immutable)))
4547
| "global_f32", _ -> ExternGlobal (global (GlobalType (F32Type, Immutable)))
4648
| "global_f64", _ -> ExternGlobal (global (GlobalType (F64Type, Immutable)))
4749
| "table", _ -> ExternTable table

test/core/binary.wast

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,24 @@
350350
"zero flag expected"
351351
)
352352

353-
;; No more than 2^32 locals.
353+
;; Local number is unsigned 32 bit
354+
(assert_malformed
355+
(module binary
356+
"\00asm" "\01\00\00\00"
357+
"\01\04\01\60\00\00" ;; Type section
358+
"\03\02\01\00" ;; Function section
359+
"\0a\0c\01" ;; Code section
360+
361+
;; function 0
362+
"\0a\02"
363+
"\80\80\80\80\10\7f" ;; 0x100000000 i32
364+
"\02\7e" ;; 0x00000002 i64
365+
"\0b" ;; end
366+
)
367+
"integer too large"
368+
)
369+
370+
;; No more than 2^32-1 locals.
354371
(assert_malformed
355372
(module binary
356373
"\00asm" "\01\00\00\00"
@@ -367,6 +384,24 @@
367384
"too many locals"
368385
)
369386

387+
(assert_malformed
388+
(module binary
389+
"\00asm" "\01\00\00\00"
390+
"\01\06\01\60\02\7f\7f\00" ;; Type section: (param i32 i32)
391+
"\03\02\01\00" ;; Function section
392+
"\0a\1c\01" ;; Code section
393+
394+
;; function 0
395+
"\1a\04"
396+
"\80\80\80\80\04\7f" ;; 0x40000000 i32
397+
"\80\80\80\80\04\7e" ;; 0x40000000 i64
398+
"\80\80\80\80\04\7d" ;; 0x40000000 f32
399+
"\80\80\80\80\04\7c" ;; 0x40000000 f64
400+
"\0b" ;; end
401+
)
402+
"too many locals"
403+
)
404+
370405
;; Local count can be 0.
371406
(module binary
372407
"\00asm" "\01\00\00\00"

test/core/br_table.wast

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,6 +1464,16 @@
14641464
))
14651465
"type mismatch"
14661466
)
1467+
(assert_invalid
1468+
(module (func
1469+
(block (result i32)
1470+
(block (result i64)
1471+
(br_table 0 1 (i32.const 0) (i32.const 0))
1472+
)
1473+
)
1474+
))
1475+
"type mismatch"
1476+
)
14671477

14681478
(assert_invalid
14691479
(module (func $type-index-void-vs-i32
@@ -1552,6 +1562,31 @@
15521562
"type mismatch"
15531563
)
15541564

1565+
(assert_invalid
1566+
(module
1567+
(func (param i32) (result i32)
1568+
(loop (result i32)
1569+
(block (result i32)
1570+
(br_table 0 1 (i32.const 1) (local.get 0))
1571+
)
1572+
)
1573+
)
1574+
)
1575+
"type mismatch"
1576+
)
1577+
(assert_invalid
1578+
(module
1579+
(func (param i32) (result i32)
1580+
(block (result i32)
1581+
(loop (result i32)
1582+
(br_table 0 1 (i32.const 1) (local.get 0))
1583+
)
1584+
)
1585+
)
1586+
)
1587+
"type mismatch"
1588+
)
1589+
15551590

15561591
(assert_invalid
15571592
(module (func $unbound-label

test/core/data.wast

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,40 @@
359359
"type mismatch"
360360
)
361361

362+
(assert_invalid
363+
(module
364+
(memory 1)
365+
(data (offset (;empty instruction sequence;)))
366+
)
367+
"type mismatch"
368+
)
369+
370+
(assert_invalid
371+
(module
372+
(memory 1)
373+
(data (offset (i32.const 0) (i32.const 0)))
374+
)
375+
"type mismatch"
376+
)
377+
378+
(assert_invalid
379+
(module
380+
(global (import "test" "global-i32") i32)
381+
(memory 1)
382+
(data (offset (global.get 0) (global.get 0)))
383+
)
384+
"type mismatch"
385+
)
386+
387+
(assert_invalid
388+
(module
389+
(global (import "test" "global-i32") i32)
390+
(memory 1)
391+
(data (offset (global.get 0) (i32.const 0)))
392+
)
393+
"type mismatch"
394+
)
395+
362396
(assert_invalid
363397
(module
364398
(memory 1)
@@ -396,3 +430,29 @@
396430
;; (module (memory 1) (data (global.get $g)) (global $g (mut i32) (i32.const 0)))
397431
;; "constant expression required"
398432
;; )
433+
434+
(assert_invalid
435+
(module
436+
(memory 1)
437+
(data (global.get 0))
438+
)
439+
"unknown global 0"
440+
)
441+
442+
(assert_invalid
443+
(module
444+
(global (import "test" "global-i32") i32)
445+
(memory 1)
446+
(data (global.get 1))
447+
)
448+
"unknown global 1"
449+
)
450+
451+
(assert_invalid
452+
(module
453+
(global (import "test" "global-mut-i32") (mut i32))
454+
(memory 1)
455+
(data (global.get 0))
456+
)
457+
"constant expression required"
458+
)

test/core/elem.wast

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,41 @@
262262
"type mismatch"
263263
)
264264

265+
(assert_invalid
266+
(module
267+
(table 1 funcref)
268+
(elem (offset (;empty instruction sequence;)))
269+
)
270+
"type mismatch"
271+
)
272+
273+
(assert_invalid
274+
(module
275+
(table 1 funcref)
276+
(elem (offset (i32.const 0) (i32.const 0)))
277+
)
278+
"type mismatch"
279+
)
280+
281+
(assert_invalid
282+
(module
283+
(global (import "test" "global-i32") i32)
284+
(table 1 funcref)
285+
(elem (offset (global.get 0) (global.get 0)))
286+
)
287+
"type mismatch"
288+
)
289+
290+
(assert_invalid
291+
(module
292+
(global (import "test" "global-i32") i32)
293+
(table 1 funcref)
294+
(elem (offset (global.get 0) (i32.const 0)))
295+
)
296+
"type mismatch"
297+
)
298+
299+
265300
(assert_invalid
266301
(module
267302
(table 1 funcref)
@@ -300,6 +335,32 @@
300335
;; "constant expression required"
301336
;; )
302337

338+
(assert_invalid
339+
(module
340+
(table 1 funcref)
341+
(elem (global.get 0))
342+
)
343+
"unknown global 0"
344+
)
345+
346+
(assert_invalid
347+
(module
348+
(global (import "test" "global-i32") i32)
349+
(table 1 funcref)
350+
(elem (global.get 1))
351+
)
352+
"unknown global 1"
353+
)
354+
355+
(assert_invalid
356+
(module
357+
(global (import "test" "global-mut-i32") (mut i32))
358+
(table 1 funcref)
359+
(elem (global.get 0))
360+
)
361+
"constant expression required"
362+
)
363+
303364
;; Two elements target the same slot
304365

305366
(module

0 commit comments

Comments
 (0)