Skip to content

Commit 775330a

Browse files
authored
Reverts the public Memory.Pages API (#2174)
Signed-off-by: Takeshi Yoneda <[email protected]>
1 parent 5fe4445 commit 775330a

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

api/wasm.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -565,17 +565,12 @@ type Memory interface {
565565
// # Notes
566566
//
567567
// - This overflows (returns zero) if the memory has the maximum 65536 pages.
568-
// - Use Pages() to handle this corner case.
568+
// As a workaround until wazero v2 to fix the return type, use Grow(0) to obtain the current pages and
569+
// multiply by 65536.
569570
//
570571
// See https://www.w3.org/TR/2019/REC-wasm-core-1-20191205/#-hrefsyntax-instr-memorymathsfmemorysize%E2%91%A0
571572
Size() uint32
572573

573-
// Pages returns the number of pages in the memory. 1 Page corresponds to 65536 bytes,
574-
// which is called "Page Size" in WebAssembly.
575-
//
576-
// See https://www.w3.org/TR/2019/REC-wasm-core-1-20191205/#memory-instances%E2%91%A0
577-
Pages() (pages uint32)
578-
579574
// Grow increases memory by the delta in pages (65536 bytes per page).
580575
// The return val is the previous memory size in pages, or false if the
581576
// delta was ignored as it exceeds MemoryDefinition.Max.

internal/wasm/memory_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ func TestMemoryInstance_Grow_Size(t *testing.T) {
6868
require.Equal(t, uint32(5), res)
6969
require.Equal(t, uint32(9), m.Pages())
7070

71+
res, ok = m.Grow(0)
72+
require.True(t, ok)
73+
require.Equal(t, uint32(9), res)
74+
require.Equal(t, uint32(9), m.Pages())
75+
7176
// At this point, the page size equal 9,
7277
// so trying to grow two pages should result in failure.
7378
_, ok = m.Grow(2)

0 commit comments

Comments
 (0)