mdn / sprints

Archived: MDN Web Docs issues are tracked in the content repository.
https://github.com/mdn/content
Creative Commons Zero v1.0 Universal
150 stars 142 forks source link

Add new example in WebAssembly.Memory documentation #3934

Closed kartva closed 3 years ago

kartva commented 3 years ago

Request type

Details

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory (Specifically: This)

Adding another example to the Examples section of the page. image

The (2nd) paragraph (of the 1st section) mentions there being two ways to access the Web Assembly Memory, specifically:

However, the paragraph talks about the second method and immediately swerves to a complete example showcasing the first. The second example is not explained.

Changes to be made:

There are two ways to get a WebAssembly.Memory object. The first way is to construct it from JavaScript. The following example creates a new WebAssembly Memory instance with an initial size of 10 pages (640KiB), and a maximum size of 100 pages (6.4MiB). Its buffer property will return an ArrayBuffer.

Fine the way it is.

The second way to get a WebAssembly.Memory object is to have it exported by a WebAssembly module. The following example (see memory.html on GitHub, and view it live also) fetches and instantiates the loaded memory.wasm byte code using the WebAssembly.instantiateStreaming() method, while importing the memory created in the line above. It then stores some values in that memory, then exports a function and uses it to sum some values.

Delete the first line.

Then add a new paragraph.

The second way to get a WebAssembly.Memory object is to have it exported by a WebAssembly module. This memory can be accessed in the exports property of the Web Assembly instance (after the memory is exported within the Web Assembly module).

Even a paragraph pointing someone in the right direction for the second method would be helpful, I think. There's not much need to make a full-blown example, since exporting Web Assembly memory is trivial (I think). Otherwise, we can include an S-expression that shows how to do it.

(memory (export "memory") 1)

This is my first time contributing here, please let me know if I did something wrong!

chrisdavidmills commented 3 years ago

Thanks for the report, @DesmondWillowbrook !

Your fix suggestion looks good to me. You are welcome to edit the page yourself, if you like.

kartva commented 3 years ago

Yes, I tried to do exactly that, but couldn't find where the page was hosted. Could you please point it out to me?

On Tue, Dec 1, 2020 at 2:08 PM Chris Mills notifications@github.com wrote:

Thanks for the report, @DesmondWillowbrook https://github.com/DesmondWillowbrook !

Your fix suggestion looks good to me. You are welcome to edit the page yourself, if you like.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/mdn/sprints/issues/3934#issuecomment-736313235, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMLJ6DV5T3VFKXKT4WJGSADSSSTOXANCNFSM4UIRLULA .

Cimeone commented 3 years ago

Here's a link to the page @DesmondWillowbrook, https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory, once you're signed in you'll be able to edit the page, let me know if instead you'd like me to do this for you!

kartva commented 3 years ago

I did it! I also added another shorter example to elucidate the usage. Should I make a complete example for the second method or is this much enough?

chrisdavidmills commented 3 years ago

@DesmondWillowbrook that looks great, thanks for your contribution!