Skip to content
Merged
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
7 changes: 7 additions & 0 deletions src/js/binaryen.js-extern-pre.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,10 @@
// we are building to ES6 (where it doesn't exist) and the .wasm blob is inlined
// see: https://github.com/emscripten-core/emscripten/issues/11792
var __dirname = "";

// FIXME: The Emscripten shell requires this function to be present, even though
// we are building to ESM (where it doesn't exist) and the result is not used
// see: https://github.com/emscripten-core/emscripten/pull/17851
function require() {
return {};
}
8 changes: 8 additions & 0 deletions src/js/binaryen.js-post.js
Original file line number Diff line number Diff line change
Expand Up @@ -2769,6 +2769,7 @@ function wrapModule(module, self = {}) {
Module['wrapModule'] = wrapModule;

// 'Relooper' interface
/** @constructor */
Module['Relooper'] = function(module) {
assert(module && typeof module === 'object' && module['ptr'] && module['block'] && module['if']); // guard against incorrect old API usage
const relooper = Module['_RelooperCreate'](module['ptr']);
Expand All @@ -2792,6 +2793,7 @@ Module['Relooper'] = function(module) {
};

// 'ExpressionRunner' interface
/** @constructor */
Module['ExpressionRunner'] = function(module, flags, maxDepth, maxLoopIterations) {
const runner = Module['_ExpressionRunnerCreate'](module['ptr'], flags, maxDepth, maxLoopIterations);
this['ptr'] = runner;
Expand Down Expand Up @@ -3562,6 +3564,7 @@ const thisPtr = Symbol();
function makeExpressionWrapper(ownStaticMembers) {
/**
* @constructor
* @extends Expression
*/
function SpecificExpression(expr) {
// can call the constructor without `new`
Expand Down Expand Up @@ -3594,6 +3597,7 @@ function deriveWrapperInstanceMembers(prototype, staticMembers) {
const member = staticMembers[memberName];
if (typeof member === "function") {
// Instance method calls the respective static method with `this` bound.
/** @this {Expression} */
prototype[memberName] = function(...args) {
return this.constructor[memberName](this[thisPtr], ...args);
};
Expand All @@ -3607,9 +3611,11 @@ function deriveWrapperInstanceMembers(prototype, staticMembers) {
const propertyName = memberName.charAt(index).toLowerCase() + memberName.substring(index + 1);
const setterIfAny = staticMembers["set" + memberName.substring(index)];
Object.defineProperty(prototype, propertyName, {
/** @this {Expression} */
get() {
return member(this[thisPtr]);
},
/** @this {Expression} */
set(value) {
if (setterIfAny) setterIfAny(this[thisPtr], value);
else throw Error("property '" + propertyName + "' has no setter");
Expand All @@ -3621,6 +3627,7 @@ function deriveWrapperInstanceMembers(prototype, staticMembers) {
}

// Base class of all expression wrappers
/** @constructor */
function Expression(expr) {
if (!expr) throw Error("expression reference must not be null");
this[thisPtr] = expr;
Expand Down Expand Up @@ -4867,6 +4874,7 @@ Module['I31Get'] = makeExpressionWrapper({

Module['Function'] = (() => {
// Closure compiler doesn't allow multiple `Function`s at top-level, so:
/** @constructor */
function Function(func) {
if (!(this instanceof Function)) {
if (!func) return null;
Expand Down