Skip to content
Open
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ full changeset diff at the end of each section.
Current Trunk
-------------

- [JS API] support `BinaryenStringConst` (#8951)
- [JS API] Merge `Module['readBinaryWithFeatures']` into `Module['readBinary']`

v131
----

Expand Down
19 changes: 6 additions & 13 deletions src/js/binaryen.js-post.js
Original file line number Diff line number Diff line change
Expand Up @@ -3368,30 +3368,23 @@ function handleFatalError(func) {
}
}

// Parses a binary to a module

// If building with Emscripten ASSERTIONS, there is a property added to
// Module to guard against users mistakening using the removed readBinary()
// API. We must defuse that carefully.
Object.defineProperty(Module, 'readBinary', { writable: true });

Module['readBinary'] = function(data) {
const buffer = _malloc(data.length);
HEAP8.set(data, buffer);
const ptr = handleFatalError(() => Module['_BinaryenModuleRead'](buffer, data.length));
_free(buffer);
return wrapModule(ptr);
};

Module['readBinaryWithFeatures'] = function(data, features) {
// Parses a binary to a module with the given feature set enabled. `features` defaults to MVP.
Module['readBinary'] = function(data, features) {
const buffer = _malloc(data.length);
HEAP8.set(data, buffer);
const ptr = handleFatalError(() => Module['_BinaryenModuleReadWithFeatures'](buffer, data.length, features));
const ptr = features === undefined
? handleFatalError(() => Module['_BinaryenModuleRead'](buffer, data.length))
: handleFatalError(() => Module['_BinaryenModuleReadWithFeatures'](buffer, data.length, features));
_free(buffer);
return wrapModule(ptr);
};

// Parses text format to a module with the given feature set enabled.
// Parses text format to a module with the given feature set enabled. `features` defaults to MVP.
Module['parseText'] = function(text, features) {
const buffer = _malloc(text.length + 1);
stringToAscii(text, buffer);
Expand Down
4 changes: 2 additions & 2 deletions test/binaryen.js/kitchen-sink.js
Original file line number Diff line number Diff line change
Expand Up @@ -1059,14 +1059,14 @@ function test_binaries_with_features() {
binaryen.setDebugInfo(false);
module.dispose();

module = binaryen.readBinaryWithFeatures(buffer, features);
module = binaryen.readBinary(buffer, features);

assert(module.validate());
console.log("module loaded from binary with features:");
console.log(module.emitText());
module.dispose();

module = binaryen.readBinaryWithFeatures(buffer, binaryen.Features.MVP);
module = binaryen.readBinary(buffer, binaryen.Features.MVP);
assert(!module.validate());
module.dispose();
}
Expand Down
Loading