From 6bb3f2c7c173480840f3dcb49801c2a144e80884 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Thu, 23 Jun 2022 17:28:35 -0700 Subject: [PATCH 01/11] feat: Extract memorySegment functions into individual functions --- src/js/binaryen.js-post.js | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/src/js/binaryen.js-post.js b/src/js/binaryen.js-post.js index f2e5c464e1c..9e11b7e4c63 100644 --- a/src/js/binaryen.js-post.js +++ b/src/js/binaryen.js-post.js @@ -2518,23 +2518,34 @@ function wrapModule(module, self = {}) { self['getNumMemorySegments'] = function() { return Module['_BinaryenGetNumMemorySegments'](module); }; + + self['memorySegment'] = { + 'offset'(id) { + return Module['_BinaryenGetMemorySegmentByteOffset'](module, id); + }, + 'data'(id) { + const size = Module['_BinaryenGetMemorySegmentByteLength'](module, id); + const ptr = _malloc(size); + Module['_BinaryenCopyMemorySegmentData'](module, id, ptr); + const res = new Uint8Array(size); + res.set(new Uint8Array(buffer, ptr, size)); + _free(ptr); + return res.buffer; + }, + 'passive'(id) { + return Boolean(Module['_BinaryenGetMemorySegmentPassive'](module, id)); + } + } + self['getMemorySegmentInfoByIndex'] = function(id) { - const passive = Boolean(Module['_BinaryenGetMemorySegmentPassive'](module, id)); + const passive = self['memorySegment']['passive'](id); let offset = null; if (!passive) { - offset = Module['_BinaryenGetMemorySegmentByteOffset'](module, id); + offset = self['memorySegment']['offset'](id) } return { 'offset': offset, - 'data': (function(){ - const size = Module['_BinaryenGetMemorySegmentByteLength'](module, id); - const ptr = _malloc(size); - Module['_BinaryenCopyMemorySegmentData'](module, id, ptr); - const res = new Uint8Array(size); - res.set(new Uint8Array(buffer, ptr, size)); - _free(ptr); - return res.buffer; - })(), + 'data': self['memorySegment']['data'](id), 'passive': passive }; }; From 08b157e7eac4db6decc355e5107066446334e998 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Fri, 8 Jul 2022 13:30:47 -0700 Subject: [PATCH 02/11] feat: Extract getMemoryInfo into individual functions --- src/js/binaryen.js-post.js | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/js/binaryen.js-post.js b/src/js/binaryen.js-post.js index 9e11b7e4c63..6c5217de6b5 100644 --- a/src/js/binaryen.js-post.js +++ b/src/js/binaryen.js-post.js @@ -709,6 +709,23 @@ function wrapModule(module, self = {}) { 'wait64'(ptr, expected, timeout) { return Module['_BinaryenAtomicWait'](module, ptr, expected, timeout, Module['i64']); } + }, + 'module'() { + return UTF8ToString(Module['_BinaryenMemoryImportGetModule'](module)); + }, + 'base'() { + return UTF8ToString(Module['_BinaryenMemoryImportGetBase'](module)); + }, + 'initial'() { + return Module['_BinaryenMemoryGetInitial'](module); + }, + 'shared'() { + return Boolean(Module['_BinaryenMemoryIsShared'](module)); + }, + 'max'() { + if (Module['_BinaryenMemoryHasMax'](module)) { + return Module['_BinaryenMemoryGetMax'](module); + } } } @@ -2505,13 +2522,14 @@ function wrapModule(module, self = {}) { }; self['getMemoryInfo'] = function() { var memoryInfo = { - 'module': UTF8ToString(Module['_BinaryenMemoryImportGetModule'](module)), - 'base': UTF8ToString(Module['_BinaryenMemoryImportGetBase'](module)), - 'initial': Module['_BinaryenMemoryGetInitial'](module), - 'shared': Boolean(Module['_BinaryenMemoryIsShared'](module)) + 'module': self['memory']['module'](), + 'base': self['memory']['base'](), + 'initial': self['memory']['initial'](), + 'shared': self['memory']['shared']() }; - if (Module['_BinaryenMemoryHasMax'](module)) { - memoryInfo['max'] = Module['_BinaryenMemoryGetMax'](module); + var max = self['memory']['max'](); + if (max) { + memoryInfo['max'] = max; } return memoryInfo; }; From bf1f31b8b450f9de35fdffd0efc9e9db7198006e Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Fri, 8 Jul 2022 13:41:01 -0700 Subject: [PATCH 03/11] feat: Extract getGlobalInfo into individual functions --- src/js/binaryen.js-post.js | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/src/js/binaryen.js-post.js b/src/js/binaryen.js-post.js index 6c5217de6b5..ed5db6b1a0f 100644 --- a/src/js/binaryen.js-post.js +++ b/src/js/binaryen.js-post.js @@ -3266,15 +3266,36 @@ Module['getFunctionInfo'] = function(func) { }; }; +Module['global'] = { + 'name'(global) { + return UTF8ToString(Module['_BinaryenGlobalGetName'](global)); + }, + 'module'(global) { + return UTF8ToString(Module['_BinaryenGlobalImportGetModule'](global)); + }, + 'base'(global) { + return UTF8ToString(Module['_BinaryenGlobalImportGetBase'](global)); + }, + 'type'(global) { + return Module['_BinaryenGlobalGetType'](global); + }, + 'mutable'(global) { + return Boolean(Module['_BinaryenGlobalIsMutable'](global)); + }, + 'init'(global) { + return Module['_BinaryenGlobalGetInitExpr'](global); + } +}; + // Obtains information about a 'Global' Module['getGlobalInfo'] = function(global) { return { - 'name': UTF8ToString(Module['_BinaryenGlobalGetName'](global)), - 'module': UTF8ToString(Module['_BinaryenGlobalImportGetModule'](global)), - 'base': UTF8ToString(Module['_BinaryenGlobalImportGetBase'](global)), - 'type': Module['_BinaryenGlobalGetType'](global), - 'mutable': Boolean(Module['_BinaryenGlobalIsMutable'](global)), - 'init': Module['_BinaryenGlobalGetInitExpr'](global) + 'name': Module['global']['name'](global), + 'module': Module['global']['module'](global), + 'base': Module['global']['base'](global), + 'type': Module['global']['type'](global), + 'mutable': Module['global']['mutable'](global), + 'init': Module['global']['init'](global) }; }; From 34f5b3d94bd032ce50a3875ce623e9fc33d80726 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Fri, 8 Jul 2022 13:41:39 -0700 Subject: [PATCH 04/11] feat: Extract getExportInfo into individual functions --- src/js/binaryen.js-post.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/js/binaryen.js-post.js b/src/js/binaryen.js-post.js index ed5db6b1a0f..3b07b03c4ea 100644 --- a/src/js/binaryen.js-post.js +++ b/src/js/binaryen.js-post.js @@ -3343,12 +3343,24 @@ Module['getTagInfo'] = function(tag) { }; }; +Module['export'] = { + 'kind'(export_) { + return Module['_BinaryenExportGetKind'](export_); + }, + 'name'(export_) { + return UTF8ToString(Module['_BinaryenExportGetName'](export_)); + }, + 'value'(export_) { + return UTF8ToString(Module['_BinaryenExportGetValue'](export_)); + } +} + // Obtains information about an 'Export' Module['getExportInfo'] = function(export_) { return { - 'kind': Module['_BinaryenExportGetKind'](export_), - 'name': UTF8ToString(Module['_BinaryenExportGetName'](export_)), - 'value': UTF8ToString(Module['_BinaryenExportGetValue'](export_)) + 'kind': Module['export']['kind'](export_), + 'name': Module['export']['name'](export_), + 'value': Module['export']['value'](export_) }; }; From 6a6bb6714643283a3647c0a2a67a51887e7aaaa9 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Fri, 8 Jul 2022 13:52:21 -0700 Subject: [PATCH 05/11] feat: FunctionImport and use the wrappers for getFunctionInfo --- src/js/binaryen.js-post.js | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/src/js/binaryen.js-post.js b/src/js/binaryen.js-post.js index 3b07b03c4ea..752f35c4cd6 100644 --- a/src/js/binaryen.js-post.js +++ b/src/js/binaryen.js-post.js @@ -3256,13 +3256,13 @@ Module['expandType'] = function(ty) { // Obtains information about a 'Function' Module['getFunctionInfo'] = function(func) { return { - 'name': UTF8ToString(Module['_BinaryenFunctionGetName'](func)), - 'module': UTF8ToString(Module['_BinaryenFunctionImportGetModule'](func)), - 'base': UTF8ToString(Module['_BinaryenFunctionImportGetBase'](func)), - 'params': Module['_BinaryenFunctionGetParams'](func), - 'results': Module['_BinaryenFunctionGetResults'](func), - 'vars': getAllNested(func, Module['_BinaryenFunctionGetNumVars'], Module['_BinaryenFunctionGetVar']), - 'body': Module['_BinaryenFunctionGetBody'](func) + 'name': Module['Function']['getName'](func), + 'module': Module['FunctionImport']['getModule'](func), + 'base': Module['FunctionImport']['getBase'](func), + 'params': Module['Function']['getParams'](func), + 'results': Module['Function']['getResults'](func), + 'vars': getAllNested(func, Module['Function']['getNumVars'], Module['Function']['getVar']), + 'body': Module['Function']['getBody'](func) }; }; @@ -4832,6 +4832,29 @@ Module['I31Get'] = makeExpressionWrapper({ // Function wrapper +Module['FunctionImport'] = (() => { + // Closure compiler doesn't allow multiple `Function`s at top-level, so: + function Function(func) { + if (!(this instanceof Function)) { + if (!func) return null; + return new Function(func); + } + if (!func) throw Error("function reference must not be null"); + this[thisPtr] = func; + } + Function['getModule'] = function(func) { + return UTF8ToString(Module['_BinaryenFunctionImportGetModule'](func)); + }; + Function['getBase'] = function(func) { + return UTF8ToString(Module['_BinaryenFunctionImportGetBase'](func)); + }; + deriveWrapperInstanceMembers(Function.prototype, Function); + Function.prototype['valueOf'] = function() { + return this[thisPtr]; + }; + return Function; +})(); + Module['Function'] = (() => { // Closure compiler doesn't allow multiple `Function`s at top-level, so: function Function(func) { From 7d19a7d0240a9624f66de93954c7cc457db69fd9 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Fri, 8 Jul 2022 14:00:58 -0700 Subject: [PATCH 06/11] Implement as wrappers --- src/js/binaryen.js-post.js | 137 +++++++++++++++++++++++++------------ 1 file changed, 94 insertions(+), 43 deletions(-) diff --git a/src/js/binaryen.js-post.js b/src/js/binaryen.js-post.js index 752f35c4cd6..9d874d5b55c 100644 --- a/src/js/binaryen.js-post.js +++ b/src/js/binaryen.js-post.js @@ -3266,36 +3266,15 @@ Module['getFunctionInfo'] = function(func) { }; }; -Module['global'] = { - 'name'(global) { - return UTF8ToString(Module['_BinaryenGlobalGetName'](global)); - }, - 'module'(global) { - return UTF8ToString(Module['_BinaryenGlobalImportGetModule'](global)); - }, - 'base'(global) { - return UTF8ToString(Module['_BinaryenGlobalImportGetBase'](global)); - }, - 'type'(global) { - return Module['_BinaryenGlobalGetType'](global); - }, - 'mutable'(global) { - return Boolean(Module['_BinaryenGlobalIsMutable'](global)); - }, - 'init'(global) { - return Module['_BinaryenGlobalGetInitExpr'](global); - } -}; - // Obtains information about a 'Global' Module['getGlobalInfo'] = function(global) { return { - 'name': Module['global']['name'](global), - 'module': Module['global']['module'](global), - 'base': Module['global']['base'](global), - 'type': Module['global']['type'](global), - 'mutable': Module['global']['mutable'](global), - 'init': Module['global']['init'](global) + 'name': Module['Global']['getName'](global), + 'module': Module['GlobalImport']['getModule'](global), + 'base': Module['GlobalImport']['getBase'](global), + 'type': Module['Global']['getType'](global), + 'mutable': Module['Global']['isMutable'](global), + 'init': Module['Global']['getInitExpr'](global) }; }; @@ -3343,24 +3322,12 @@ Module['getTagInfo'] = function(tag) { }; }; -Module['export'] = { - 'kind'(export_) { - return Module['_BinaryenExportGetKind'](export_); - }, - 'name'(export_) { - return UTF8ToString(Module['_BinaryenExportGetName'](export_)); - }, - 'value'(export_) { - return UTF8ToString(Module['_BinaryenExportGetValue'](export_)); - } -} - // Obtains information about an 'Export' Module['getExportInfo'] = function(export_) { return { - 'kind': Module['export']['kind'](export_), - 'name': Module['export']['name'](export_), - 'value': Module['export']['value'](export_) + 'kind': Module['export']['getKind'](export_), + 'name': Module['export']['getName'](export_), + 'value': Module['export']['getValue'](export_) }; }; @@ -4830,7 +4797,89 @@ Module['I31Get'] = makeExpressionWrapper({ } }); -// Function wrapper +// Export wrapper +Module['Export'] = (() => { + // Closure compiler doesn't allow multiple `Function`s at top-level, so: + function Function(func) { + if (!(this instanceof Function)) { + if (!func) return null; + return new Function(func); + } + if (!func) throw Error("function reference must not be null"); + this[thisPtr] = func; + } + Function['getKind'] = function(export_) { + return Module['_BinaryenExportGetKind'](export_); + }; + Function['getName'] = function(export_) { + return UTF8ToString(Module['_BinaryenExportGetName'](export_)); + }; + Function['getValue'] = function(export_) { + return UTF8ToString(Module['_BinaryenExportGetValue'](export_)); + }; + deriveWrapperInstanceMembers(Function.prototype, Function); + Function.prototype['valueOf'] = function() { + return this[thisPtr]; + }; + return Function; +})(); + +// GlobalImport wrapper +Module['GlobalImport'] = (() => { + // Closure compiler doesn't allow multiple `Function`s at top-level, so: + function Function(func) { + if (!(this instanceof Function)) { + if (!func) return null; + return new Function(func); + } + if (!func) throw Error("function reference must not be null"); + this[thisPtr] = func; + } + Function['getModule'] = function(global) { + return UTF8ToString(Module['_BinaryenGlobalImportGetModule'](global)); + }; + Function['getBase'] = function(global) { + return UTF8ToString(Module['_BinaryenGlobalImportGetBase'](global)); + }; + deriveWrapperInstanceMembers(Function.prototype, Function); + Function.prototype['valueOf'] = function() { + return this[thisPtr]; + }; + return Function; +})(); + +// Global wrapper + +Module['Global'] = (() => { + // Closure compiler doesn't allow multiple `Function`s at top-level, so: + function Function(func) { + if (!(this instanceof Function)) { + if (!func) return null; + return new Function(func); + } + if (!func) throw Error("function reference must not be null"); + this[thisPtr] = func; + } + Function['getName'] = function(global) { + return UTF8ToString(Module['_BinaryenGlobalGetName'](global)); + }; + Function['getType'] = function(global) { + return Module['_BinaryenGlobalGetType'](global); + }; + Function['isMutable'] = function(global) { + return Boolean(Module['_BinaryenGlobalIsMutable'](global)); + }; + Function['getInitExpr'] = function(global) { + return Module['_BinaryenGlobalGetInitExpr'](global); + }; + deriveWrapperInstanceMembers(Function.prototype, Function); + Function.prototype['valueOf'] = function() { + return this[thisPtr]; + }; + return Function; +})(); + +// FunctionImport wrapper Module['FunctionImport'] = (() => { // Closure compiler doesn't allow multiple `Function`s at top-level, so: @@ -4855,6 +4904,8 @@ Module['FunctionImport'] = (() => { return Function; })(); +// Function wrapper + Module['Function'] = (() => { // Closure compiler doesn't allow multiple `Function`s at top-level, so: function Function(func) { From b061058065581cb649f12c0f99b3d3ab4c77d86c Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Fri, 8 Jul 2022 14:09:15 -0700 Subject: [PATCH 07/11] feat: Extract getElementSegmentInfo into individual functions --- src/js/binaryen.js-post.js | 44 ++++++++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/src/js/binaryen.js-post.js b/src/js/binaryen.js-post.js index 9d874d5b55c..6d6212cbbd1 100644 --- a/src/js/binaryen.js-post.js +++ b/src/js/binaryen.js-post.js @@ -3296,17 +3296,16 @@ Module['getTableInfo'] = function(table) { }; Module['getElementSegmentInfo'] = function(segment) { - var segmentLength = Module['_BinaryenElementSegmentGetLength'](segment); + var segmentLength = Module['ElementSegment']['getLength'](segment); var names = new Array(segmentLength); for (let j = 0; j !== segmentLength; ++j) { - var ptr = Module['_BinaryenElementSegmentGetData'](segment, j); - names[j] = UTF8ToString(ptr); + names[j] = Module['ElementSegment']['getData'](segment, j); } return { - 'name': UTF8ToString(Module['_BinaryenElementSegmentGetName'](segment)), - 'table': UTF8ToString(Module['_BinaryenElementSegmentGetTable'](segment)), - 'offset': Module['_BinaryenElementSegmentGetOffset'](segment), + 'name': Module['ElementSegment']['getName'](segment), + 'table': Module['ElementSegment']['getTable'](segment), + 'offset': Module['ElementSegment']['getOffset'](segment), 'data': names } } @@ -4797,6 +4796,39 @@ Module['I31Get'] = makeExpressionWrapper({ } }); +// ElementSegment wrapper +Module['ElementSegment'] = (() => { + // Closure compiler doesn't allow multiple `Function`s at top-level, so: + function Function(func) { + if (!(this instanceof Function)) { + if (!func) return null; + return new Function(func); + } + if (!func) throw Error("function reference must not be null"); + this[thisPtr] = func; + } + Function['getLength'] = function(segment) { + Module['_BinaryenElementSegmentGetLength'](segment); + }; + Function['getData'] = function(segment, index) { + return UTF8ToString(Module['_BinaryenElementSegmentGetData'](segment, index)); + }; + Function['getName'] = function(segment) { + return UTF8ToString(Module['_BinaryenElementSegmentGetName'](segment)); + }; + Function['getTable'] = function(segment) { + return UTF8ToString(Module['_BinaryenElementSegmentGetTable'](segment)); + }; + Function['getOffset'] = function(segment) { + return Module['_BinaryenElementSegmentGetOffset'](segment); + }; + deriveWrapperInstanceMembers(Function.prototype, Function); + Function.prototype['valueOf'] = function() { + return this[thisPtr]; + }; + return Function; +})(); + // Export wrapper Module['Export'] = (() => { // Closure compiler doesn't allow multiple `Function`s at top-level, so: From 65366bca466c527a0be09351c6dd7f2bf020ac94 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Fri, 8 Jul 2022 14:12:08 -0700 Subject: [PATCH 08/11] fix export capitalization --- src/js/binaryen.js-post.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/js/binaryen.js-post.js b/src/js/binaryen.js-post.js index 6d6212cbbd1..570c046eb48 100644 --- a/src/js/binaryen.js-post.js +++ b/src/js/binaryen.js-post.js @@ -3324,9 +3324,9 @@ Module['getTagInfo'] = function(tag) { // Obtains information about an 'Export' Module['getExportInfo'] = function(export_) { return { - 'kind': Module['export']['getKind'](export_), - 'name': Module['export']['getName'](export_), - 'value': Module['export']['getValue'](export_) + 'kind': Module['Export']['getKind'](export_), + 'name': Module['Export']['getName'](export_), + 'value': Module['Export']['getValue'](export_) }; }; From e24858a2d969093b911cead1a792b1caba12105a Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Fri, 8 Jul 2022 14:13:06 -0700 Subject: [PATCH 09/11] fix a missing return --- src/js/binaryen.js-post.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/binaryen.js-post.js b/src/js/binaryen.js-post.js index 570c046eb48..0eb3c42cf29 100644 --- a/src/js/binaryen.js-post.js +++ b/src/js/binaryen.js-post.js @@ -4808,7 +4808,7 @@ Module['ElementSegment'] = (() => { this[thisPtr] = func; } Function['getLength'] = function(segment) { - Module['_BinaryenElementSegmentGetLength'](segment); + return Module['_BinaryenElementSegmentGetLength'](segment); }; Function['getData'] = function(segment, index) { return UTF8ToString(Module['_BinaryenElementSegmentGetData'](segment, index)); From 8dc92ea0859a40eb1928a05287b626945f54366b Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Tue, 12 Jul 2022 13:39:06 -0400 Subject: [PATCH 10/11] Return Infinity if no max memory --- src/js/binaryen.js-post.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/js/binaryen.js-post.js b/src/js/binaryen.js-post.js index 0eb3c42cf29..eddde103a03 100644 --- a/src/js/binaryen.js-post.js +++ b/src/js/binaryen.js-post.js @@ -725,6 +725,8 @@ function wrapModule(module, self = {}) { 'max'() { if (Module['_BinaryenMemoryHasMax'](module)) { return Module['_BinaryenMemoryGetMax'](module); + } else { + return Infinity; } } } From cfebb772b60d39eb1afb580affcf184447b31148 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Tue, 12 Jul 2022 13:42:23 -0400 Subject: [PATCH 11/11] Rename function constructors --- src/js/binaryen.js-post.js | 105 ++++++++++++++++++------------------- 1 file changed, 51 insertions(+), 54 deletions(-) diff --git a/src/js/binaryen.js-post.js b/src/js/binaryen.js-post.js index eddde103a03..74a71dc740e 100644 --- a/src/js/binaryen.js-post.js +++ b/src/js/binaryen.js-post.js @@ -4800,146 +4800,143 @@ Module['I31Get'] = makeExpressionWrapper({ // ElementSegment wrapper Module['ElementSegment'] = (() => { - // Closure compiler doesn't allow multiple `Function`s at top-level, so: - function Function(func) { - if (!(this instanceof Function)) { + // Closure compiler doesn't allow multiple `ElementSegment`s at top-level, so: + function ElementSegment(func) { + if (!(this instanceof ElementSegment)) { if (!func) return null; - return new Function(func); + return new ElementSegment(func); } if (!func) throw Error("function reference must not be null"); this[thisPtr] = func; } - Function['getLength'] = function(segment) { + ElementSegment['getLength'] = function(segment) { return Module['_BinaryenElementSegmentGetLength'](segment); }; - Function['getData'] = function(segment, index) { + ElementSegment['getData'] = function(segment, index) { return UTF8ToString(Module['_BinaryenElementSegmentGetData'](segment, index)); }; - Function['getName'] = function(segment) { + ElementSegment['getName'] = function(segment) { return UTF8ToString(Module['_BinaryenElementSegmentGetName'](segment)); }; - Function['getTable'] = function(segment) { + ElementSegment['getTable'] = function(segment) { return UTF8ToString(Module['_BinaryenElementSegmentGetTable'](segment)); }; - Function['getOffset'] = function(segment) { + ElementSegment['getOffset'] = function(segment) { return Module['_BinaryenElementSegmentGetOffset'](segment); }; - deriveWrapperInstanceMembers(Function.prototype, Function); - Function.prototype['valueOf'] = function() { + deriveWrapperInstanceMembers(ElementSegment.prototype, ElementSegment); + ElementSegment.prototype['valueOf'] = function() { return this[thisPtr]; }; - return Function; + return ElementSegment; })(); // Export wrapper Module['Export'] = (() => { - // Closure compiler doesn't allow multiple `Function`s at top-level, so: - function Function(func) { - if (!(this instanceof Function)) { + // Closure compiler doesn't allow multiple `Export`s at top-level, so: + function Export(func) { + if (!(this instanceof Export)) { if (!func) return null; - return new Function(func); + return new Export(func); } if (!func) throw Error("function reference must not be null"); this[thisPtr] = func; } - Function['getKind'] = function(export_) { + Export['getKind'] = function(export_) { return Module['_BinaryenExportGetKind'](export_); }; - Function['getName'] = function(export_) { + Export['getName'] = function(export_) { return UTF8ToString(Module['_BinaryenExportGetName'](export_)); }; - Function['getValue'] = function(export_) { + Export['getValue'] = function(export_) { return UTF8ToString(Module['_BinaryenExportGetValue'](export_)); }; - deriveWrapperInstanceMembers(Function.prototype, Function); - Function.prototype['valueOf'] = function() { + deriveWrapperInstanceMembers(Export.prototype, Export); + Export.prototype['valueOf'] = function() { return this[thisPtr]; }; - return Function; + return Export; })(); // GlobalImport wrapper Module['GlobalImport'] = (() => { - // Closure compiler doesn't allow multiple `Function`s at top-level, so: - function Function(func) { - if (!(this instanceof Function)) { + // Closure compiler doesn't allow multiple `GlobalImport`s at top-level, so: + function GlobalImport(func) { + if (!(this instanceof GlobalImport)) { if (!func) return null; - return new Function(func); + return new GlobalImport(func); } if (!func) throw Error("function reference must not be null"); this[thisPtr] = func; } - Function['getModule'] = function(global) { + GlobalImport['getModule'] = function(global) { return UTF8ToString(Module['_BinaryenGlobalImportGetModule'](global)); }; - Function['getBase'] = function(global) { + GlobalImport['getBase'] = function(global) { return UTF8ToString(Module['_BinaryenGlobalImportGetBase'](global)); }; - deriveWrapperInstanceMembers(Function.prototype, Function); - Function.prototype['valueOf'] = function() { + deriveWrapperInstanceMembers(GlobalImport.prototype, GlobalImport); + GlobalImport.prototype['valueOf'] = function() { return this[thisPtr]; }; - return Function; + return GlobalImport; })(); // Global wrapper - Module['Global'] = (() => { - // Closure compiler doesn't allow multiple `Function`s at top-level, so: - function Function(func) { - if (!(this instanceof Function)) { + // Closure compiler doesn't allow multiple `Global`s at top-level, so: + function Global(func) { + if (!(this instanceof Global)) { if (!func) return null; - return new Function(func); + return new Global(func); } if (!func) throw Error("function reference must not be null"); this[thisPtr] = func; } - Function['getName'] = function(global) { + Global['getName'] = function(global) { return UTF8ToString(Module['_BinaryenGlobalGetName'](global)); }; - Function['getType'] = function(global) { + Global['getType'] = function(global) { return Module['_BinaryenGlobalGetType'](global); }; - Function['isMutable'] = function(global) { + Global['isMutable'] = function(global) { return Boolean(Module['_BinaryenGlobalIsMutable'](global)); }; - Function['getInitExpr'] = function(global) { + Global['getInitExpr'] = function(global) { return Module['_BinaryenGlobalGetInitExpr'](global); }; - deriveWrapperInstanceMembers(Function.prototype, Function); - Function.prototype['valueOf'] = function() { + deriveWrapperInstanceMembers(Global.prototype, Global); + Global.prototype['valueOf'] = function() { return this[thisPtr]; }; - return Function; + return Global; })(); // FunctionImport wrapper - Module['FunctionImport'] = (() => { - // Closure compiler doesn't allow multiple `Function`s at top-level, so: - function Function(func) { - if (!(this instanceof Function)) { + // Closure compiler doesn't allow multiple `FunctionImport`s at top-level, so: + function FunctionImport(func) { + if (!(this instanceof FunctionImport)) { if (!func) return null; - return new Function(func); + return new FunctionImport(func); } if (!func) throw Error("function reference must not be null"); this[thisPtr] = func; } - Function['getModule'] = function(func) { + FunctionImport['getModule'] = function(func) { return UTF8ToString(Module['_BinaryenFunctionImportGetModule'](func)); }; - Function['getBase'] = function(func) { + FunctionImport['getBase'] = function(func) { return UTF8ToString(Module['_BinaryenFunctionImportGetBase'](func)); }; - deriveWrapperInstanceMembers(Function.prototype, Function); - Function.prototype['valueOf'] = function() { + deriveWrapperInstanceMembers(FunctionImport.prototype, FunctionImport); + FunctionImport.prototype['valueOf'] = function() { return this[thisPtr]; }; - return Function; + return FunctionImport; })(); // Function wrapper - Module['Function'] = (() => { // Closure compiler doesn't allow multiple `Function`s at top-level, so: function Function(func) {