Skip to content

Commit

Permalink
Add a test for mutating externref globals (#104)
Browse files Browse the repository at this point in the history
While `linking.wast` tests that we can link modules that are importing and
exporting mutable `externref` globals, there were no tests exercising
`global.{get,set}` on mutable `externref` globals.
  • Loading branch information
fitzgen authored Jul 16, 2020
1 parent 401c8eb commit 1e652dd
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions test/core/global.wast
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@
(global $y (mut i64) (i64.const -15))

(global $r externref (ref.null extern))
(global $mr (mut externref) (ref.null extern))
(global funcref (ref.null func))

(func (export "get-a") (result i32) (global.get $a))
(func (export "get-b") (result i64) (global.get $b))
(func (export "get-r") (result externref) (global.get $r))
(func (export "get-mr") (result externref) (global.get $mr))
(func (export "get-x") (result i32) (global.get $x))
(func (export "get-y") (result i64) (global.get $y))
(func (export "set-x") (param i32) (global.set $x (local.get 0)))
(func (export "set-y") (param i64) (global.set $y (local.get 0)))
(func (export "set-mr") (param externref) (global.set $mr (local.get 0)))

(func (export "get-1") (result f32) (global.get 1))
(func (export "get-2") (result f64) (global.get 2))
Expand Down Expand Up @@ -185,6 +188,7 @@
(assert_return (invoke "get-a") (i32.const -2))
(assert_return (invoke "get-b") (i64.const -5))
(assert_return (invoke "get-r") (ref.null extern))
(assert_return (invoke "get-mr") (ref.null extern))
(assert_return (invoke "get-x") (i32.const -12))
(assert_return (invoke "get-y") (i64.const -15))

Expand All @@ -197,11 +201,13 @@
(assert_return (invoke "set-y" (i64.const 7)))
(assert_return (invoke "set-5" (f32.const 8)))
(assert_return (invoke "set-6" (f64.const 9)))
(assert_return (invoke "set-mr" (ref.extern 10)))

(assert_return (invoke "get-x") (i32.const 6))
(assert_return (invoke "get-y") (i64.const 7))
(assert_return (invoke "get-5") (f32.const 8))
(assert_return (invoke "get-6") (f64.const 9))
(assert_return (invoke "get-mr") (ref.extern 10))

(assert_return (invoke "as-select-first") (i32.const 6))
(assert_return (invoke "as-select-mid") (i32.const 2))
Expand Down

0 comments on commit 1e652dd

Please sign in to comment.