Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 38 additions & 3 deletions JS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ be loaded and run directly from an HTML `<script type='module'>` tag—and
any other Web API that loads ES6 modules via URL—as part of
[ES6 Module integration](Modules.md#integration-with-es6-modules).)

## Post-MVP JavaScript API

Some JavaScript APIs were added post-MVP and can be
[feature-tested](FeatureTest.md) together. These are grouped together,
and each group is denoted with one of the following symbols:

* ⚜

## Traps

Whenever WebAssembly semantics specify a [trap](Semantics.md#traps),
Expand Down Expand Up @@ -510,11 +518,12 @@ call one with the `new` operator.

A `WebAssembly.Memory` object contains a single [linear memory](Semantics.md#linear-memory)
which can be simultaneously referenced by multiple `Instance` objects. Each
`Memory` object has two internal slots:
`Memory` object has three internal slots:

* [[Memory]] : a [`Memory.memory`](https://github.com/WebAssembly/spec/blob/master/interpreter/spec/memory.mli)
* [[BufferObject]] : the current `ArrayBuffer` whose [[ArrayBufferByteLength]]
matches the current byte length of [[Memory]]
* [[Maximum]] : the `maximum` number of WebAssembly pages, or `undefined` if `maximum` is `None`

### `WebAssembly.Memory` Constructor

Expand Down Expand Up @@ -559,8 +568,10 @@ Any attempts to [`detach`](http://tc39.github.io/ecma262/#sec-detacharraybuffer)
the detachment performed by [`m.grow`](#webassemblymemoryprototypegrow) shall throw a
[`TypeError`](https://tc39.github.io/ecma262/#sec-native-error-types-used-in-this-standard-typeerror)

Return a new `WebAssembly.Memory` instance with [[Memory]] set to `m` and
[[BufferObject]] set to `buffer`.
Return a new `WebAssembly.Memory` instance with
[[Memory]] set to `m`,
[[BufferObject]] set to `buffer`, and
[[Maximum]] set to `undefined` if `maximum` is `None` or `maximum` otherwise.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the motivation for storing the maximum here, rather than looking it up in the store?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean "in the store"?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

He means that the memory instance m (living in the Wasm abstract store) already has this information, so the internal slot is redundant.


### `WebAssembly.Memory.prototype [ @@toStringTag ]` Property

Expand Down Expand Up @@ -608,6 +619,30 @@ accessor function performs the following steps:
If `this` is not a `WebAssembly.Memory`, a [`TypeError`](https://tc39.github.io/ecma262/#sec-native-error-types-used-in-this-standard-typeerror)
is thrown. Otherwise return `M.[[BufferObject]]`.

### `WebAssembly.Memory.prototype.byteLength`

[⚜](#Post-MVP-JavaScript-API)

This is an accessor property whose [[Set]] is Undefined and whose [[Get]]
accessor function performs the following steps:

Let `T` be the `this` value. If `T` is not a `WebAssembly.Memory`, a [`TypeError`](https://tc39.github.io/ecma262/#sec-native-error-types-used-in-this-standard-typeerror)
is thrown.

Return `T.[[BufferObject]].[[ArrayBufferByteLength]]`.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the motivation for this feature, when a user can do memory.buffer.byteLength? Is it more optimizable if you never access the ArrayBuffer, or something like that?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah creating the array buffer is expensive-ish. We can optimize it away, but that's being extra silly IMO.


### `WebAssembly.Memory.prototype.maximum`

[⚜](#Post-MVP-JavaScript-API)

This is an accessor property whose [[Set]] is Undefined and whose [[Get]]
accessor function performs the following steps:

Let `T` be the `this` value. If `T` is not a `WebAssembly.Memory`, a [`TypeError`](https://tc39.github.io/ecma262/#sec-native-error-types-used-in-this-standard-typeerror)
is thrown.

Return `T.[[Maximum]]`.

## `WebAssembly.Table` Objects

A `WebAssembly.Table` object contains a single [table](Semantics.md#table)
Expand Down