From fe99e3458f11d1a01fa3ad5b68883dbcba3903af Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Fri, 31 May 2019 20:02:37 -0700 Subject: Add event section (#2151) This adds support for the event and the event section, as specified in https://github.com/WebAssembly/exception-handling/blob/master/proposals/Exceptions.md#changes-to-the-binary-model. Wasm events are features that suspend the current execution and transfer the control flow to a corresponding handler. Currently the only supported event kind is exceptions. For events, this includes support for - Binary file reading/writing - Wast file reading/writing - Binaryen.js API - Fuzzer - Validation - Metadce - Passes: metrics, minify-imports-and-exports, remove-unused-module-elements --- src/js/binaryen.js-post.js | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'src/js/binaryen.js-post.js') diff --git a/src/js/binaryen.js-post.js b/src/js/binaryen.js-post.js index 180d08bb5..d2703e425 100644 --- a/src/js/binaryen.js-post.js +++ b/src/js/binaryen.js-post.js @@ -84,6 +84,7 @@ Module['ExternalFunction'] = Module['_BinaryenExternalFunction'](); Module['ExternalTable'] = Module['_BinaryenExternalTable'](); Module['ExternalMemory'] = Module['_BinaryenExternalMemory'](); Module['ExternalGlobal'] = Module['_BinaryenExternalGlobal'](); +Module['ExternalEvent'] = Module['_BinaryenExternalEvent'](); // Features Module['Features'] = { @@ -1788,6 +1789,21 @@ function wrapModule(module, self) { return Module['_BinaryenRemoveGlobal'](module, strToStack(name)); }); } + self['addEvent'] = function(name, attribute, eventType) { + return preserveStack(function() { + return Module['_BinaryenAddEvent'](module, strToStack(name), attribute, eventType); + }); + }; + self['getEvent'] = function(name) { + return preserveStack(function() { + return Module['_BinaryenGetEvent'](module, strToStack(name)); + }); + }; + self['removeEvent'] = function(name) { + return preserveStack(function() { + return Module['_BinaryenRemoveEvent'](module, strToStack(name)); + }); + }; self['addFunctionImport'] = function(internalName, externalModuleName, externalBaseName, functionType) { return preserveStack(function() { return Module['_BinaryenAddFunctionImport'](module, strToStack(internalName), strToStack(externalModuleName), strToStack(externalBaseName), functionType); @@ -1808,6 +1824,11 @@ function wrapModule(module, self) { return Module['_BinaryenAddGlobalImport'](module, strToStack(internalName), strToStack(externalModuleName), strToStack(externalBaseName), globalType); }); }; + self['addEventImport'] = function(internalName, externalModuleName, externalBaseName, attribute, eventType) { + return preserveStack(function() { + return Module['_BinaryenAddEventImport'](module, strToStack(internalName), strToStack(externalModuleName), strToStack(externalBaseName), attribute, eventType); + }); + }; self['addExport'] = // deprecated self['addFunctionExport'] = function(internalName, externalName) { return preserveStack(function() { @@ -1829,6 +1850,11 @@ function wrapModule(module, self) { return Module['_BinaryenAddGlobalExport'](module, strToStack(internalName), strToStack(externalName)); }); }; + self['addEventExport'] = function(internalName, externalName) { + return preserveStack(function() { + return Module['_BinaryenAddEventExport'](module, strToStack(internalName), strToStack(externalName)); + }); + }; self['removeExport'] = function(externalName) { return preserveStack(function() { return Module['_BinaryenRemoveExport'](module, strToStack(externalName)); @@ -2354,6 +2380,17 @@ Module['getGlobalInfo'] = function(global) { }; }; +// Obtains information about a 'Event' +Module['getEventInfo'] = function(event_) { + return { + 'name': UTF8ToString(Module['_BinaryenEventGetName'](event_)), + 'module': UTF8ToString(Module['_BinaryenEventImportGetModule'](event_)), + 'base': UTF8ToString(Module['_BinaryenEventImportGetBase'](event_)), + 'attribute': Module['_BinaryenEventGetAttribute'](event_), + 'type': UTF8ToString(Module['_BinaryenEventGetType'](event_)) + }; +}; + // Obtains information about an 'Export' Module['getExportInfo'] = function(export_) { return { -- cgit v1.2.3