Skip to content

loader: Rename alloc -> new #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
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
Binary file modified loader/build/optimized.wasm
Binary file not shown.
10 changes: 5 additions & 5 deletions loader/tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const myModule = require("../index");
// Obtain the runtime helpers for
const {
// memory management
__allocString, __allocArray,
__newString, __newArray,
// garbage collection
__retain, __release,
// and interop
Expand Down Expand Up @@ -32,7 +32,7 @@ const {
console.log("Example 2:");

// Allocate a string in the module's memory and retain a reference to our allocation
const ptr = __retain(__allocString("Hello world (I am a JavaScript string)"));
const ptr = __retain(__newString("Hello world (I am a JavaScript string)"));

// Pass it to our WebAssembly export, which is going to print it using our custom console
myModule.sayHello(ptr);
Expand Down Expand Up @@ -68,7 +68,7 @@ const {
// Allocate a new array in WebAssembly memory and get a view on it. Note that
// we have to specify the runtime id of the array type we want to allocate, so
// we export its id (`idof<Int32Array>`) from the module to do so.
const ptr = __retain(__allocArray(myModule.Int32Array_ID, [ 1, 2, 3 ]));
const ptr = __retain(__newArray(myModule.Int32Array_ID, [ 1, 2, 3 ]));
const view = __getArrayView(ptr);
const copy = __getArray(ptr);

Expand All @@ -94,7 +94,7 @@ const {
// Note: Allocating an array of strings or other objects will automatically
// take care of retaining references to its elements, but the array itself
// must be dealt with as usual.
const inPtr = __retain(__allocArray(myModule.ArrayOfStrings_ID, [ "hello", "world" ].map(__allocString)));
const inPtr = __retain(__newArray(myModule.ArrayOfStrings_ID, [ "hello", "world" ].map(__newString)));

// Provide our array of lowercase strings to WebAssembly, and obtain the new
// array of uppercase strings before printing it.
Expand All @@ -117,7 +117,7 @@ const {
// let's call the `Player` constructor (this is also an allocation):
let player;
{
const namePtr = __retain(__allocString("Gordon Freeman"));
const namePtr = __retain(__newString("Gordon Freeman"));
player = new myModule.Game.Player(namePtr);
__release(namePtr);
}
Expand Down