From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- devtools/client/shared/vendor/D3_LICENSE | 26 + devtools/client/shared/vendor/DAGRE_D3_LICENSE | 19 + .../client/shared/vendor/FLUENT_REACT_UPGRADING | 33 + devtools/client/shared/vendor/MD5_LICENSE | 27 + devtools/client/shared/vendor/MD5_UPGRADING.md | 29 + .../shared/vendor/REACT_PROP_TYPES_UPGRADING.md | 37 + devtools/client/shared/vendor/REACT_REDUX_LICENSE | 21 + .../client/shared/vendor/REACT_REDUX_UPGRADING.md | 36 + .../client/shared/vendor/REACT_ROUTER_DOM_LICENSE | 21 + .../shared/vendor/REACT_ROUTER_DOM_UPGRADING.md | 23 + devtools/client/shared/vendor/REACT_UPGRADING.md | 160 + devtools/client/shared/vendor/REDUX_LICENSE | 21 + devtools/client/shared/vendor/REDUX_UPGRADING.md | 32 + devtools/client/shared/vendor/RESELECT_LICENSE | 21 + devtools/client/shared/vendor/RESELECT_UPGRADING | 12 + devtools/client/shared/vendor/WASMPARSER_UPGRADING | 14 + devtools/client/shared/vendor/WHATWG_URL_LICENSE | 21 + devtools/client/shared/vendor/WasmDis.js | 2020 ++ devtools/client/shared/vendor/WasmParser.js | 3883 ++++ devtools/client/shared/vendor/dagre-d3.js | 4560 ++++ devtools/client/shared/vendor/fluent-react.js | 686 + devtools/client/shared/vendor/immutable.js | 4997 +++++ devtools/client/shared/vendor/jszip.js | 11367 ++++++++++ devtools/client/shared/vendor/md5.js | 7 + devtools/client/shared/vendor/micromatch/LICENSE | 21 + .../client/shared/vendor/micromatch/UPGRADE.md | 17 + .../client/shared/vendor/micromatch/micromatch.js | 5424 +++++ devtools/client/shared/vendor/micromatch/moz.build | 9 + .../shared/vendor/micromatch/package-lock.json | 4497 ++++ .../client/shared/vendor/micromatch/package.json | 26 + .../shared/vendor/micromatch/webpack.config.js | 20 + devtools/client/shared/vendor/moz.build | 43 + devtools/client/shared/vendor/react-dev.js | 3155 +++ devtools/client/shared/vendor/react-dom-dev.js | 21413 +++++++++++++++++++ .../client/shared/vendor/react-dom-factories.js | 195 + .../client/shared/vendor/react-dom-server-dev.js | 3801 ++++ devtools/client/shared/vendor/react-dom-server.js | 2188 ++ .../shared/vendor/react-dom-test-utils-dev.js | 1302 ++ .../client/shared/vendor/react-dom-test-utils.js | 1150 + devtools/client/shared/vendor/react-dom.js | 16370 ++++++++++++++ .../client/shared/vendor/react-prop-types-dev.js | 1363 ++ devtools/client/shared/vendor/react-prop-types.js | 1363 ++ devtools/client/shared/vendor/react-redux.js | 2089 ++ devtools/client/shared/vendor/react-router-dom.js | 3788 ++++ .../shared/vendor/react-test-renderer-shallow.js | 955 + .../client/shared/vendor/react-test-renderer.js | 10580 +++++++++ devtools/client/shared/vendor/react.js | 2240 ++ devtools/client/shared/vendor/redux.js | 715 + devtools/client/shared/vendor/reselect.js | 291 + .../shared/vendor/source-map/GITHUB_CHANGESET | 1 + devtools/client/shared/vendor/source-map/LICENSE | 28 + .../shared/vendor/source-map/lib/array-set.js | 100 + .../shared/vendor/source-map/lib/base64-vlq.js | 94 + .../client/shared/vendor/source-map/lib/base64.js | 19 + .../shared/vendor/source-map/lib/binary-search.js | 113 + .../shared/vendor/source-map/lib/mapping-list.js | 83 + .../shared/vendor/source-map/lib/mappings.wasm | Bin 0 -> 48526 bytes .../client/shared/vendor/source-map/lib/moz.build | 21 + .../shared/vendor/source-map/lib/read-wasm.js | 46 + .../vendor/source-map/lib/source-map-consumer.js | 1078 + .../vendor/source-map/lib/source-map-generator.js | 439 + .../shared/vendor/source-map/lib/source-node.js | 430 + .../client/shared/vendor/source-map/lib/url.js | 21 + .../client/shared/vendor/source-map/lib/util.js | 444 + .../client/shared/vendor/source-map/lib/wasm.js | 138 + devtools/client/shared/vendor/source-map/moz.build | 13 + .../client/shared/vendor/source-map/source-map.js | 10 + devtools/client/shared/vendor/source-map/update.sh | 38 + devtools/client/shared/vendor/whatwg-url.js | 8588 ++++++++ 69 files changed, 122792 insertions(+) create mode 100644 devtools/client/shared/vendor/D3_LICENSE create mode 100644 devtools/client/shared/vendor/DAGRE_D3_LICENSE create mode 100644 devtools/client/shared/vendor/FLUENT_REACT_UPGRADING create mode 100644 devtools/client/shared/vendor/MD5_LICENSE create mode 100644 devtools/client/shared/vendor/MD5_UPGRADING.md create mode 100644 devtools/client/shared/vendor/REACT_PROP_TYPES_UPGRADING.md create mode 100644 devtools/client/shared/vendor/REACT_REDUX_LICENSE create mode 100644 devtools/client/shared/vendor/REACT_REDUX_UPGRADING.md create mode 100644 devtools/client/shared/vendor/REACT_ROUTER_DOM_LICENSE create mode 100644 devtools/client/shared/vendor/REACT_ROUTER_DOM_UPGRADING.md create mode 100644 devtools/client/shared/vendor/REACT_UPGRADING.md create mode 100644 devtools/client/shared/vendor/REDUX_LICENSE create mode 100644 devtools/client/shared/vendor/REDUX_UPGRADING.md create mode 100644 devtools/client/shared/vendor/RESELECT_LICENSE create mode 100644 devtools/client/shared/vendor/RESELECT_UPGRADING create mode 100644 devtools/client/shared/vendor/WASMPARSER_UPGRADING create mode 100644 devtools/client/shared/vendor/WHATWG_URL_LICENSE create mode 100644 devtools/client/shared/vendor/WasmDis.js create mode 100644 devtools/client/shared/vendor/WasmParser.js create mode 100644 devtools/client/shared/vendor/dagre-d3.js create mode 100644 devtools/client/shared/vendor/fluent-react.js create mode 100644 devtools/client/shared/vendor/immutable.js create mode 100644 devtools/client/shared/vendor/jszip.js create mode 100644 devtools/client/shared/vendor/md5.js create mode 100755 devtools/client/shared/vendor/micromatch/LICENSE create mode 100644 devtools/client/shared/vendor/micromatch/UPGRADE.md create mode 100644 devtools/client/shared/vendor/micromatch/micromatch.js create mode 100644 devtools/client/shared/vendor/micromatch/moz.build create mode 100644 devtools/client/shared/vendor/micromatch/package-lock.json create mode 100644 devtools/client/shared/vendor/micromatch/package.json create mode 100644 devtools/client/shared/vendor/micromatch/webpack.config.js create mode 100644 devtools/client/shared/vendor/moz.build create mode 100644 devtools/client/shared/vendor/react-dev.js create mode 100644 devtools/client/shared/vendor/react-dom-dev.js create mode 100644 devtools/client/shared/vendor/react-dom-factories.js create mode 100644 devtools/client/shared/vendor/react-dom-server-dev.js create mode 100644 devtools/client/shared/vendor/react-dom-server.js create mode 100644 devtools/client/shared/vendor/react-dom-test-utils-dev.js create mode 100644 devtools/client/shared/vendor/react-dom-test-utils.js create mode 100644 devtools/client/shared/vendor/react-dom.js create mode 100644 devtools/client/shared/vendor/react-prop-types-dev.js create mode 100644 devtools/client/shared/vendor/react-prop-types.js create mode 100644 devtools/client/shared/vendor/react-redux.js create mode 100644 devtools/client/shared/vendor/react-router-dom.js create mode 100644 devtools/client/shared/vendor/react-test-renderer-shallow.js create mode 100644 devtools/client/shared/vendor/react-test-renderer.js create mode 100644 devtools/client/shared/vendor/react.js create mode 100644 devtools/client/shared/vendor/redux.js create mode 100644 devtools/client/shared/vendor/reselect.js create mode 100644 devtools/client/shared/vendor/source-map/GITHUB_CHANGESET create mode 100644 devtools/client/shared/vendor/source-map/LICENSE create mode 100644 devtools/client/shared/vendor/source-map/lib/array-set.js create mode 100644 devtools/client/shared/vendor/source-map/lib/base64-vlq.js create mode 100644 devtools/client/shared/vendor/source-map/lib/base64.js create mode 100644 devtools/client/shared/vendor/source-map/lib/binary-search.js create mode 100644 devtools/client/shared/vendor/source-map/lib/mapping-list.js create mode 100644 devtools/client/shared/vendor/source-map/lib/mappings.wasm create mode 100644 devtools/client/shared/vendor/source-map/lib/moz.build create mode 100644 devtools/client/shared/vendor/source-map/lib/read-wasm.js create mode 100644 devtools/client/shared/vendor/source-map/lib/source-map-consumer.js create mode 100644 devtools/client/shared/vendor/source-map/lib/source-map-generator.js create mode 100644 devtools/client/shared/vendor/source-map/lib/source-node.js create mode 100644 devtools/client/shared/vendor/source-map/lib/url.js create mode 100644 devtools/client/shared/vendor/source-map/lib/util.js create mode 100644 devtools/client/shared/vendor/source-map/lib/wasm.js create mode 100644 devtools/client/shared/vendor/source-map/moz.build create mode 100644 devtools/client/shared/vendor/source-map/source-map.js create mode 100755 devtools/client/shared/vendor/source-map/update.sh create mode 100644 devtools/client/shared/vendor/whatwg-url.js (limited to 'devtools/client/shared/vendor') diff --git a/devtools/client/shared/vendor/D3_LICENSE b/devtools/client/shared/vendor/D3_LICENSE new file mode 100644 index 0000000000..fb7d95d70b --- /dev/null +++ b/devtools/client/shared/vendor/D3_LICENSE @@ -0,0 +1,26 @@ +Copyright (c) 2014, Michael Bostock +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* The name Michael Bostock may not be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL MICHAEL BOSTOCK BE LIABLE FOR ANY DIRECT, +INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, +EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/devtools/client/shared/vendor/DAGRE_D3_LICENSE b/devtools/client/shared/vendor/DAGRE_D3_LICENSE new file mode 100644 index 0000000000..1d64ed68ce --- /dev/null +++ b/devtools/client/shared/vendor/DAGRE_D3_LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2013 Chris Pettitt + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/devtools/client/shared/vendor/FLUENT_REACT_UPGRADING b/devtools/client/shared/vendor/FLUENT_REACT_UPGRADING new file mode 100644 index 0000000000..9aeb6a2a82 --- /dev/null +++ b/devtools/client/shared/vendor/FLUENT_REACT_UPGRADING @@ -0,0 +1,33 @@ +[//]: # ( + This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. +) + +# Upgrading @fluent/react + +## Getting the Source + +```bash +git clone https://github.com/projectfluent/fluent.js +cd fluent.js +``` + +Then checkout the version/tag you want, e.g. `@fluent/react@0.10.0`. + +## Building fluent-react + +```bash +npm install +cd fluent-gecko +make fluent-react.js +cp dist/fluent-react.js /devtools/client/shared/vendor/fluent-react.js +``` + +## Patching fluent-react + +- Open `fluent-react.js` +- Replace `require('react')` with `require('resource://devtools/client/shared/vendor/react.js')` +- Replace `require('prop-types')` with `require('resource://devtools/client/shared/vendor/react-prop-types.js')` + +## Update the version: + +The current version is 0.10.0. Update this version number everywhere in this file. diff --git a/devtools/client/shared/vendor/MD5_LICENSE b/devtools/client/shared/vendor/MD5_LICENSE new file mode 100644 index 0000000000..f476d11e7d --- /dev/null +++ b/devtools/client/shared/vendor/MD5_LICENSE @@ -0,0 +1,27 @@ +Copyright © 2011-2012, Paul Vorbach. +Copyright © 2009, Jeff Mott. + +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. +* Redistributions in binary form must reproduce the above copyright notice, this + list of conditions and the following disclaimer in the documentation and/or + other materials provided with the distribution. +* Neither the name Crypto-JS nor the names of its contributors may be used to + endorse or promote products derived from this software without specific prior + written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/devtools/client/shared/vendor/MD5_UPGRADING.md b/devtools/client/shared/vendor/MD5_UPGRADING.md new file mode 100644 index 0000000000..b3f9b51611 --- /dev/null +++ b/devtools/client/shared/vendor/MD5_UPGRADING.md @@ -0,0 +1,29 @@ +[//]: # ( +This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. +) + +# Upgrading MD5 + +## Introduction + +We are using the md5 module to compute hashes within the source map worker. +From there we don't have easy access to privileged APIs... + +## Instructions + +```bash + $ wget https://github.com/pvorb/node-md5/archive/refs/tags/v2.3.0.tar.gz + $ tar zxvf v2.3.0.tar.gz + $ cd node-md5-2.3.0/ +``` + +Here edit webpack.config.js to set `libraryTarget: "umd"`, +otherwise it is packed into a script bundle instead of being kept as a commonjs. + + +```bash + $ yarn webpack + $ cp dist/md5.min.js ../md5.js # this will copy it to devtools/client/shared/vendor/md5.js + $ cd .. + $ rm -rf v2.3.0.tar.gz node-md5-2.3.0 +``` diff --git a/devtools/client/shared/vendor/REACT_PROP_TYPES_UPGRADING.md b/devtools/client/shared/vendor/REACT_PROP_TYPES_UPGRADING.md new file mode 100644 index 0000000000..71db97622e --- /dev/null +++ b/devtools/client/shared/vendor/REACT_PROP_TYPES_UPGRADING.md @@ -0,0 +1,37 @@ +[//]: # ( + This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. +) + +# Upgrading react-prop-types + +## Getting the Source + +```bash +git clone git@github.com:facebook/prop-types.git +cd prop-types +``` + +## Building + +```bash +npm install +NODE_ENV=development browserify index.js -t envify --standalone PropTypes -o react-prop-types-dev.js +NODE_ENV=production browserify index.js -t envify --standalone PropTypes -o react-prop-types.js +``` + +## Copying files to your Firefox repo + +```bash +mv react-prop-types.js /firefox/repo/devtools/client/shared/vendor/react-prop-types.js +mv react-prop-types-dev.js /firefox/repo/devtools/client/shared/vendor/react-prop-types-dev.js +``` + +## Adding Version Info + +Add the version to the top of `react-prop-types.js` and `react-prop-types-dev.js`. + +```js + /** + * react-prop-types v15.6.0 + */ +``` diff --git a/devtools/client/shared/vendor/REACT_REDUX_LICENSE b/devtools/client/shared/vendor/REACT_REDUX_LICENSE new file mode 100644 index 0000000000..af2353dca4 --- /dev/null +++ b/devtools/client/shared/vendor/REACT_REDUX_LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2015 Dan Abramov + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/devtools/client/shared/vendor/REACT_REDUX_UPGRADING.md b/devtools/client/shared/vendor/REACT_REDUX_UPGRADING.md new file mode 100644 index 0000000000..2c8786b179 --- /dev/null +++ b/devtools/client/shared/vendor/REACT_REDUX_UPGRADING.md @@ -0,0 +1,36 @@ +[//]: # ( + This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. +) + +# Upgrading react-redux + +## Getting the Source + +```bash +git clone https://github.com/reactjs/react-redux +cd react-redux +git checkout v5.0.7 # checkout the right version tag +``` + +## Building + +```bash +npm install +npm run build:umd +cp dist/react-redux.js /devtools/client/shared/vendor/react-redux.js +``` + +We no longer need the react-redux repo so feel free to delete it. + +## Patching react-redux + +- open `react-redux.js` +- Add the version number to the top of the file: + ``` + /** + * react-redux v5.0.7 + */ + ``` +- Replace all instances of `'react'` with `'resource://devtools/client/shared/vendor/react.js'` (including the quotes). +- Replace all instances of `'redux'` with `'resource://devtools/client/shared/vendor/redux.js'` (including the quotes). +- Replace all instances of `Function('return this')()` with `globalThis`. See Bug 1473549. diff --git a/devtools/client/shared/vendor/REACT_ROUTER_DOM_LICENSE b/devtools/client/shared/vendor/REACT_ROUTER_DOM_LICENSE new file mode 100644 index 0000000000..dc15fe3fd4 --- /dev/null +++ b/devtools/client/shared/vendor/REACT_ROUTER_DOM_LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) React Training 2016-2018 + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/devtools/client/shared/vendor/REACT_ROUTER_DOM_UPGRADING.md b/devtools/client/shared/vendor/REACT_ROUTER_DOM_UPGRADING.md new file mode 100644 index 0000000000..8bd9a8b0c5 --- /dev/null +++ b/devtools/client/shared/vendor/REACT_ROUTER_DOM_UPGRADING.md @@ -0,0 +1,23 @@ +[//]: # ( + This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. +) + +Follow this steps to upgrade the `react-router-dom` library: + +1. Clone the repository (note: this is a monorepository, it includes other libraries too): + `git clone git@github.com:ReactTraining/react-router.git` + +2. Install build dependencies: + `cd react-router` + `npm install` + +3. Run a build : + `npm run build` + +4. Grab the UMD build of `react-router-dom`, which is located in `packages/react-router-dom/umd/react-router-dom.js` and copy it into Firefox source tree. + +5. Edit `react-router-dom.js` and change `require('react')` for `require('resource://devtools/client/shared/vendor/react.js')` + +6. Update the version below: + +The current version is 4.3.1 diff --git a/devtools/client/shared/vendor/REACT_UPGRADING.md b/devtools/client/shared/vendor/REACT_UPGRADING.md new file mode 100644 index 0000000000..95034f2da5 --- /dev/null +++ b/devtools/client/shared/vendor/REACT_UPGRADING.md @@ -0,0 +1,160 @@ +[//]: # ( +This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. +) + +# Upgrading React + +## Introduction + +We use a version of React that has a few minor tweaks. We want to use an un-minified production version anyway so you need to build React yourself. + +## First, Upgrade react-prop-types.js + +You should start by upgrading our prop-types library to match the latest version of React. Please follow the instructions in `devtools/client/shared/vendor/REACT_PROP_TYPES_UPGRADING.md` before continuing. + +## Getting the Source + +```bash +git clone https://github.com/facebook/react.git +cd react +git checkout v16.8.6 # or the version you are targetting +``` + +## Preparing to Build + +We need to disable minification and tree shaking as they overcomplicate the upgrade process without adding any benefits. + +- Open `scripts/rollup/build.js` +- Find a method called `function getRollupOutputOptions()` +- After `sourcemap: false` add `treeshake: false` and `freeze: false` +- Remove `freeze: !isProduction,` from the same section. +- Change this: + + ```js + // Apply dead code elimination and/or minification. + isProduction && + ``` + + To this: + + ```js + { + transformBundle(source) { + return ( + source.replace(/['"]react['"]/g, + "'resource://devtools/client/shared/vendor/react.js'") + .replace(/createElementNS\(['"]http:\/\/www\.w3\.org\/1999\/xhtml['"], ['"]resource://devtools\/client\/shared\/vendor\/react.js['"]\)/g, + "createElementNS('http://www.w3.org/1999/xhtml', 'react'") + .replace(/['"]react-dom['"]/g, + "'resource://devtools/client/shared/vendor/react-dom.js'") + .replace(/rendererPackageName:\s['"]resource://devtools\/client\/shared\/vendor\/react-dom.js['"]/g, + "rendererPackageName: 'react-dom'") + .replace(/ocument\.createElement\(/g, + "ocument.createElementNS('http://www.w3.org/1999/xhtml', ") + ); + }, + }, + // Apply dead code elimination and/or minification. + false && + ``` + + - Find `await createBundle` and remove all bundles in that block except for `UMD_DEV`, `UMD_PROD` and `NODE_DEV`. + +## Building + +```bash +npm install --global yarn +yarn +yarn build +``` + +### Copy the Files Into your Firefox Repo + +```bash +cd +cp build/dist/react.production.min.js /devtools/client/shared/vendor/react.js +cp build/dist/react-dom.production.min.js /devtools/client/shared/vendor/react-dom.js +cp build/dist/react-dom-server.browser.production.min.js /devtools/client/shared/vendor/react-dom-server.js +cp build/dist/react-dom-test-utils.production.min.js /devtools/client/shared/vendor/react-dom-test-utils.js +cp build/dist/react.development.js /devtools/client/shared/vendor/react-dev.js +cp build/dist/react-dom.development.js /devtools/client/shared/vendor/react-dom-dev.js +cp build/dist/react-dom-server.browser.development.js /devtools/client/shared/vendor/react-dom-server-dev.js +cp build/dist/react-dom-test-utils.development.js /devtools/client/shared/vendor/react-dom-test-utils-dev.js +cp build/dist/react-test-renderer-shallow.production.min.js /devtools/client/shared/vendor/react-test-renderer-shallow.js +cp build/dist/react-test-renderer.production.min.js /devtools/client/shared/vendor/react-test-renderer.js +``` + +From this point we will no longer need your react repository so feel free to delete it. + +## Debugger + +### Update React + +- Open `devtools/client/debugger/package.json` +- Under `dependencies` update `react` and `react-dom` to the required version. +- Under `devDependencies` you may also need to update `enzyme`, `enzyme-adapter-react-16` and `enzyme-to-json` to versions compatible with the new react version. + +### Build the debugger + +#### Check your .mozconfig + +- Ensure you are not in debug mode (`ac_add_options --disable-debug`). +- Ensure you are not using the debug version of react (`ac_add_options --disable-debug-js-modules`). + +#### First build Firefox + +```bash +cd # where sourcedir is the root of your Firefox repo. +./mach build +``` + +#### Now update the debugger source + +```bash +# Go to the debugger folder. +cd devtools/client/debugger + +# Remove all node_modules folders. +find . -name "node_modules" -exec rm -rf '{}' + + +# Install the new react and enzyme modules. +yarn +``` + +### Run the debugger tests + +#### First run locally + +```bash +node bin/try-runner.js +``` + +If there any failures fix them. + +**NOTE: If there are any jest failures you will get better output by running the jest tests directly using:** + +```bash +yarn test +``` + +If any tests fail then fix them. + +#### Commit your changes + +Use `hg commit` or `hg amend` to commit your changes. + +#### Push to try + +Just because the tests run fine locally they may still fail on try. You should first ensure that `node bin/try-runner.js` passes on try: + +```bash +cd # where sourcedir is the root of your Firefox repo. +`./mach try fuzzy` +``` + +- When the interface appears type `debugger`. +- Press ``. + +Once these tests pass on try then push to try as normal e.g. `./mach try -b do -p all -u all -t all -e all`. + +If try passes then go celebrate otherwise you are on your own. diff --git a/devtools/client/shared/vendor/REDUX_LICENSE b/devtools/client/shared/vendor/REDUX_LICENSE new file mode 100644 index 0000000000..af2353dca4 --- /dev/null +++ b/devtools/client/shared/vendor/REDUX_LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2015 Dan Abramov + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/devtools/client/shared/vendor/REDUX_UPGRADING.md b/devtools/client/shared/vendor/REDUX_UPGRADING.md new file mode 100644 index 0000000000..232c17e655 --- /dev/null +++ b/devtools/client/shared/vendor/REDUX_UPGRADING.md @@ -0,0 +1,32 @@ +[//]: # ( + This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. +) + +# Upgrading redux + +## Getting the Source + +```bash +git clone https://github.com/reactjs/redux +cd redux +git checkout v4.0.5 # checkout the right version tag +``` + +## Building + +```bash +npm install +npm run build +cp dist/redux.js /devtools/client/shared/vendor/redux.js +``` + +## Patching react-redux + +- open `redux.js` +- Add the version number to the top of the file: + ``` + /** + * react-redux v4.0.5 + */ + ``` +- Replace all instances of `Function('return this')()` with `globalThis`. See Bug 1473549. \ No newline at end of file diff --git a/devtools/client/shared/vendor/RESELECT_LICENSE b/devtools/client/shared/vendor/RESELECT_LICENSE new file mode 100644 index 0000000000..964e056d8c --- /dev/null +++ b/devtools/client/shared/vendor/RESELECT_LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2015-2018 Reselect Contributors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/devtools/client/shared/vendor/RESELECT_UPGRADING b/devtools/client/shared/vendor/RESELECT_UPGRADING new file mode 100644 index 0000000000..5bb76178bf --- /dev/null +++ b/devtools/client/shared/vendor/RESELECT_UPGRADING @@ -0,0 +1,12 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +Follow these steps when adding/upgrading the reselect.js module: + +1. git clone https://github.com/reactjs/reselect - clone the repo +2. yarn && yarn run build - compile the sources to a compiled JS module file +3. cp dist/reselect.js $DEST_DIR - copy the compiled file to Firefox source tree + +The current version is 4.1.5 (last update in bug 1758973) diff --git a/devtools/client/shared/vendor/WASMPARSER_UPGRADING b/devtools/client/shared/vendor/WASMPARSER_UPGRADING new file mode 100644 index 0000000000..52f8c2ddbf --- /dev/null +++ b/devtools/client/shared/vendor/WASMPARSER_UPGRADING @@ -0,0 +1,14 @@ +# wasmparser version + +Current version is: 5.4.0 + +# Upgrade process + +1. Pull latest release from npm and extract WasmDis.js and WasmParser.js, e.g. + +``` +curl https://registry.npmjs.org/wasmparser/-/wasmparser-5.6.0.tgz | tar -zx --strip-components 3 package/dist/cjs/{WasmDis,WasmParser}.js +``` + +2. Remove reference to source maps (last line) + diff --git a/devtools/client/shared/vendor/WHATWG_URL_LICENSE b/devtools/client/shared/vendor/WHATWG_URL_LICENSE new file mode 100644 index 0000000000..54dfac39d9 --- /dev/null +++ b/devtools/client/shared/vendor/WHATWG_URL_LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2015–2016 Sebastian Mayr + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/devtools/client/shared/vendor/WasmDis.js b/devtools/client/shared/vendor/WasmDis.js new file mode 100644 index 0000000000..e9d01f4880 --- /dev/null +++ b/devtools/client/shared/vendor/WasmDis.js @@ -0,0 +1,2020 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +Object.defineProperty(exports, "__esModule", { value: true }); +exports.DevToolsNameGenerator = exports.DevToolsNameResolver = exports.NameSectionReader = exports.WasmDisassembler = exports.LabelMode = exports.NumericNameResolver = exports.DefaultNameResolver = void 0; +/* Copyright 2016 Mozilla Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +var WasmParser_js_1 = require("./WasmParser.js"); +var NAME_SECTION_NAME = "name"; +var INVALID_NAME_SYMBOLS_REGEX = /[^0-9A-Za-z!#$%&'*+.:<=>?@^_`|~\/\-]/; +var INVALID_NAME_SYMBOLS_REGEX_GLOBAL = new RegExp(INVALID_NAME_SYMBOLS_REGEX.source, "g"); +function formatFloat32(n) { + if (n === 0) + return 1 / n < 0 ? "-0.0" : "0.0"; + if (isFinite(n)) + return n.toString(); + if (!isNaN(n)) + return n < 0 ? "-inf" : "inf"; + var view = new DataView(new ArrayBuffer(8)); + view.setFloat32(0, n, true); + var data = view.getInt32(0, true); + var payload = data & 0x7fffff; + var canonicalBits = 4194304; // 0x800..0 + if (data > 0 && payload === canonicalBits) + return "nan"; + // canonical NaN; + else if (payload === canonicalBits) + return "-nan"; + return (data < 0 ? "-" : "+") + "nan:0x" + payload.toString(16); +} +function formatFloat64(n) { + if (n === 0) + return 1 / n < 0 ? "-0.0" : "0.0"; + if (isFinite(n)) + return n.toString(); + if (!isNaN(n)) + return n < 0 ? "-inf" : "inf"; + var view = new DataView(new ArrayBuffer(8)); + view.setFloat64(0, n, true); + var data1 = view.getUint32(0, true); + var data2 = view.getInt32(4, true); + var payload = data1 + (data2 & 0xfffff) * 4294967296; + var canonicalBits = 524288 * 4294967296; // 0x800..0 + if (data2 > 0 && payload === canonicalBits) + return "nan"; + // canonical NaN; + else if (payload === canonicalBits) + return "-nan"; + return (data2 < 0 ? "-" : "+") + "nan:0x" + payload.toString(16); +} +function formatI32Array(bytes, count) { + var dv = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength); + var result = []; + for (var i = 0; i < count; i++) + result.push("0x".concat(formatHex(dv.getInt32(i << 2, true), 8))); + return result.join(" "); +} +function formatI8Array(bytes, count) { + var dv = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength); + var result = []; + for (var i = 0; i < count; i++) + result.push("".concat(dv.getInt8(i))); + return result.join(" "); +} +function memoryAddressToString(address, code) { + var defaultAlignFlags; + switch (code) { + case 64768 /* OperatorCode.v128_load */: + case 64769 /* OperatorCode.i16x8_load8x8_s */: + case 64770 /* OperatorCode.i16x8_load8x8_u */: + case 64771 /* OperatorCode.i32x4_load16x4_s */: + case 64772 /* OperatorCode.i32x4_load16x4_u */: + case 64773 /* OperatorCode.i64x2_load32x2_s */: + case 64774 /* OperatorCode.i64x2_load32x2_u */: + case 64775 /* OperatorCode.v8x16_load_splat */: + case 64776 /* OperatorCode.v16x8_load_splat */: + case 64777 /* OperatorCode.v32x4_load_splat */: + case 64778 /* OperatorCode.v64x2_load_splat */: + case 64779 /* OperatorCode.v128_store */: + defaultAlignFlags = 4; + break; + case 41 /* OperatorCode.i64_load */: + case 55 /* OperatorCode.i64_store */: + case 43 /* OperatorCode.f64_load */: + case 57 /* OperatorCode.f64_store */: + case 65026 /* OperatorCode.memory_atomic_wait64 */: + case 65041 /* OperatorCode.i64_atomic_load */: + case 65048 /* OperatorCode.i64_atomic_store */: + case 65055 /* OperatorCode.i64_atomic_rmw_add */: + case 65062 /* OperatorCode.i64_atomic_rmw_sub */: + case 65069 /* OperatorCode.i64_atomic_rmw_and */: + case 65076 /* OperatorCode.i64_atomic_rmw_or */: + case 65083 /* OperatorCode.i64_atomic_rmw_xor */: + case 65090 /* OperatorCode.i64_atomic_rmw_xchg */: + case 65097 /* OperatorCode.i64_atomic_rmw_cmpxchg */: + case 64861 /* OperatorCode.v128_load64_zero */: + defaultAlignFlags = 3; + break; + case 40 /* OperatorCode.i32_load */: + case 52 /* OperatorCode.i64_load32_s */: + case 53 /* OperatorCode.i64_load32_u */: + case 54 /* OperatorCode.i32_store */: + case 62 /* OperatorCode.i64_store32 */: + case 42 /* OperatorCode.f32_load */: + case 56 /* OperatorCode.f32_store */: + case 65024 /* OperatorCode.memory_atomic_notify */: + case 65025 /* OperatorCode.memory_atomic_wait32 */: + case 65040 /* OperatorCode.i32_atomic_load */: + case 65046 /* OperatorCode.i64_atomic_load32_u */: + case 65047 /* OperatorCode.i32_atomic_store */: + case 65053 /* OperatorCode.i64_atomic_store32 */: + case 65054 /* OperatorCode.i32_atomic_rmw_add */: + case 65060 /* OperatorCode.i64_atomic_rmw32_add_u */: + case 65061 /* OperatorCode.i32_atomic_rmw_sub */: + case 65067 /* OperatorCode.i64_atomic_rmw32_sub_u */: + case 65068 /* OperatorCode.i32_atomic_rmw_and */: + case 65074 /* OperatorCode.i64_atomic_rmw32_and_u */: + case 65075 /* OperatorCode.i32_atomic_rmw_or */: + case 65081 /* OperatorCode.i64_atomic_rmw32_or_u */: + case 65082 /* OperatorCode.i32_atomic_rmw_xor */: + case 65088 /* OperatorCode.i64_atomic_rmw32_xor_u */: + case 65089 /* OperatorCode.i32_atomic_rmw_xchg */: + case 65095 /* OperatorCode.i64_atomic_rmw32_xchg_u */: + case 65096 /* OperatorCode.i32_atomic_rmw_cmpxchg */: + case 65102 /* OperatorCode.i64_atomic_rmw32_cmpxchg_u */: + case 64860 /* OperatorCode.v128_load32_zero */: + defaultAlignFlags = 2; + break; + case 46 /* OperatorCode.i32_load16_s */: + case 47 /* OperatorCode.i32_load16_u */: + case 50 /* OperatorCode.i64_load16_s */: + case 51 /* OperatorCode.i64_load16_u */: + case 59 /* OperatorCode.i32_store16 */: + case 61 /* OperatorCode.i64_store16 */: + case 65043 /* OperatorCode.i32_atomic_load16_u */: + case 65045 /* OperatorCode.i64_atomic_load16_u */: + case 65050 /* OperatorCode.i32_atomic_store16 */: + case 65052 /* OperatorCode.i64_atomic_store16 */: + case 65057 /* OperatorCode.i32_atomic_rmw16_add_u */: + case 65059 /* OperatorCode.i64_atomic_rmw16_add_u */: + case 65064 /* OperatorCode.i32_atomic_rmw16_sub_u */: + case 65066 /* OperatorCode.i64_atomic_rmw16_sub_u */: + case 65071 /* OperatorCode.i32_atomic_rmw16_and_u */: + case 65073 /* OperatorCode.i64_atomic_rmw16_and_u */: + case 65078 /* OperatorCode.i32_atomic_rmw16_or_u */: + case 65080 /* OperatorCode.i64_atomic_rmw16_or_u */: + case 65085 /* OperatorCode.i32_atomic_rmw16_xor_u */: + case 65087 /* OperatorCode.i64_atomic_rmw16_xor_u */: + case 65092 /* OperatorCode.i32_atomic_rmw16_xchg_u */: + case 65094 /* OperatorCode.i64_atomic_rmw16_xchg_u */: + case 65099 /* OperatorCode.i32_atomic_rmw16_cmpxchg_u */: + case 65101 /* OperatorCode.i64_atomic_rmw16_cmpxchg_u */: + defaultAlignFlags = 1; + break; + case 44 /* OperatorCode.i32_load8_s */: + case 45 /* OperatorCode.i32_load8_u */: + case 48 /* OperatorCode.i64_load8_s */: + case 49 /* OperatorCode.i64_load8_u */: + case 58 /* OperatorCode.i32_store8 */: + case 60 /* OperatorCode.i64_store8 */: + case 65042 /* OperatorCode.i32_atomic_load8_u */: + case 65044 /* OperatorCode.i64_atomic_load8_u */: + case 65049 /* OperatorCode.i32_atomic_store8 */: + case 65051 /* OperatorCode.i64_atomic_store8 */: + case 65056 /* OperatorCode.i32_atomic_rmw8_add_u */: + case 65058 /* OperatorCode.i64_atomic_rmw8_add_u */: + case 65063 /* OperatorCode.i32_atomic_rmw8_sub_u */: + case 65065 /* OperatorCode.i64_atomic_rmw8_sub_u */: + case 65070 /* OperatorCode.i32_atomic_rmw8_and_u */: + case 65072 /* OperatorCode.i64_atomic_rmw8_and_u */: + case 65077 /* OperatorCode.i32_atomic_rmw8_or_u */: + case 65079 /* OperatorCode.i64_atomic_rmw8_or_u */: + case 65084 /* OperatorCode.i32_atomic_rmw8_xor_u */: + case 65086 /* OperatorCode.i64_atomic_rmw8_xor_u */: + case 65091 /* OperatorCode.i32_atomic_rmw8_xchg_u */: + case 65093 /* OperatorCode.i64_atomic_rmw8_xchg_u */: + case 65098 /* OperatorCode.i32_atomic_rmw8_cmpxchg_u */: + case 65100 /* OperatorCode.i64_atomic_rmw8_cmpxchg_u */: + defaultAlignFlags = 0; + break; + } + if (address.flags == defaultAlignFlags) + // hide default flags + return !address.offset ? null : "offset=".concat(address.offset); + if (!address.offset) + // hide default offset + return "align=".concat(1 << address.flags); + return "offset=".concat(address.offset | 0, " align=").concat(1 << address.flags); +} +function limitsToString(limits) { + return (limits.initial + (limits.maximum !== undefined ? " " + limits.maximum : "")); +} +var paddingCache = ["0", "00", "000"]; +function formatHex(n, width) { + var s = (n >>> 0).toString(16).toUpperCase(); + if (width === undefined || s.length >= width) + return s; + var paddingIndex = width - s.length - 1; + while (paddingIndex >= paddingCache.length) + paddingCache.push(paddingCache[paddingCache.length - 1] + "0"); + return paddingCache[paddingIndex] + s; +} +var IndentIncrement = " "; +function isValidName(name) { + return !INVALID_NAME_SYMBOLS_REGEX.test(name); +} +var DefaultNameResolver = /** @class */ (function () { + function DefaultNameResolver() { + } + DefaultNameResolver.prototype.getTypeName = function (index, isRef) { + return "$type" + index; + }; + DefaultNameResolver.prototype.getTableName = function (index, isRef) { + return "$table" + index; + }; + DefaultNameResolver.prototype.getMemoryName = function (index, isRef) { + return "$memory" + index; + }; + DefaultNameResolver.prototype.getGlobalName = function (index, isRef) { + return "$global" + index; + }; + DefaultNameResolver.prototype.getElementName = function (index, isRef) { + return "$elem".concat(index); + }; + DefaultNameResolver.prototype.getTagName = function (index, isRef) { + return "$event".concat(index); + }; + DefaultNameResolver.prototype.getFunctionName = function (index, isImport, isRef) { + return (isImport ? "$import" : "$func") + index; + }; + DefaultNameResolver.prototype.getVariableName = function (funcIndex, index, isRef) { + return "$var" + index; + }; + DefaultNameResolver.prototype.getFieldName = function (typeIndex, index, isRef) { + return "$field" + index; + }; + DefaultNameResolver.prototype.getLabel = function (index) { + return "$label" + index; + }; + return DefaultNameResolver; +}()); +exports.DefaultNameResolver = DefaultNameResolver; +var EMPTY_STRING_ARRAY = []; +var DevToolsExportMetadata = /** @class */ (function () { + function DevToolsExportMetadata(functionExportNames, globalExportNames, memoryExportNames, tableExportNames, eventExportNames) { + this._functionExportNames = functionExportNames; + this._globalExportNames = globalExportNames; + this._memoryExportNames = memoryExportNames; + this._tableExportNames = tableExportNames; + this._eventExportNames = eventExportNames; + } + DevToolsExportMetadata.prototype.getFunctionExportNames = function (index) { + var _a; + return (_a = this._functionExportNames[index]) !== null && _a !== void 0 ? _a : EMPTY_STRING_ARRAY; + }; + DevToolsExportMetadata.prototype.getGlobalExportNames = function (index) { + var _a; + return (_a = this._globalExportNames[index]) !== null && _a !== void 0 ? _a : EMPTY_STRING_ARRAY; + }; + DevToolsExportMetadata.prototype.getMemoryExportNames = function (index) { + var _a; + return (_a = this._memoryExportNames[index]) !== null && _a !== void 0 ? _a : EMPTY_STRING_ARRAY; + }; + DevToolsExportMetadata.prototype.getTableExportNames = function (index) { + var _a; + return (_a = this._tableExportNames[index]) !== null && _a !== void 0 ? _a : EMPTY_STRING_ARRAY; + }; + DevToolsExportMetadata.prototype.getTagExportNames = function (index) { + var _a; + return (_a = this._eventExportNames[index]) !== null && _a !== void 0 ? _a : EMPTY_STRING_ARRAY; + }; + return DevToolsExportMetadata; +}()); +var NumericNameResolver = /** @class */ (function () { + function NumericNameResolver() { + } + NumericNameResolver.prototype.getTypeName = function (index, isRef) { + return isRef ? "" + index : "(;".concat(index, ";)"); + }; + NumericNameResolver.prototype.getTableName = function (index, isRef) { + return isRef ? "" + index : "(;".concat(index, ";)"); + }; + NumericNameResolver.prototype.getMemoryName = function (index, isRef) { + return isRef ? "" + index : "(;".concat(index, ";)"); + }; + NumericNameResolver.prototype.getGlobalName = function (index, isRef) { + return isRef ? "" + index : "(;".concat(index, ";)"); + }; + NumericNameResolver.prototype.getElementName = function (index, isRef) { + return isRef ? "" + index : "(;".concat(index, ";)"); + }; + NumericNameResolver.prototype.getTagName = function (index, isRef) { + return isRef ? "" + index : "(;".concat(index, ";)"); + }; + NumericNameResolver.prototype.getFunctionName = function (index, isImport, isRef) { + return isRef ? "" + index : "(;".concat(index, ";)"); + }; + NumericNameResolver.prototype.getVariableName = function (funcIndex, index, isRef) { + return isRef ? "" + index : "(;".concat(index, ";)"); + }; + NumericNameResolver.prototype.getFieldName = function (typeIndex, index, isRef) { + return isRef ? "" : index + "(;".concat(index, ";)"); + }; + NumericNameResolver.prototype.getLabel = function (index) { + return null; + }; + return NumericNameResolver; +}()); +exports.NumericNameResolver = NumericNameResolver; +var LabelMode; +(function (LabelMode) { + LabelMode[LabelMode["Depth"] = 0] = "Depth"; + LabelMode[LabelMode["WhenUsed"] = 1] = "WhenUsed"; + LabelMode[LabelMode["Always"] = 2] = "Always"; +})(LabelMode = exports.LabelMode || (exports.LabelMode = {})); +var WasmDisassembler = /** @class */ (function () { + function WasmDisassembler() { + this._skipTypes = true; + this._exportMetadata = null; + this._lines = []; + this._offsets = []; + this._buffer = ""; + this._indent = null; + this._indentLevel = 0; + this._addOffsets = false; + this._done = false; + this._currentPosition = 0; + this._nameResolver = new DefaultNameResolver(); + this._labelMode = LabelMode.WhenUsed; + this._functionBodyOffsets = []; + this._currentFunctionBodyOffset = 0; + this._currentSectionId = -1 /* SectionCode.Unknown */; + this._logFirstInstruction = false; + this._reset(); + } + WasmDisassembler.prototype._reset = function () { + this._types = []; + this._funcIndex = 0; + this._funcTypes = []; + this._importCount = 0; + this._globalCount = 0; + this._memoryCount = 0; + this._eventCount = 0; + this._tableCount = 0; + this._elementCount = 0; + this._expression = []; + this._backrefLabels = null; + this._labelIndex = 0; + }; + Object.defineProperty(WasmDisassembler.prototype, "addOffsets", { + get: function () { + return this._addOffsets; + }, + set: function (value) { + if (this._currentPosition) + throw new Error("Cannot switch addOffsets during processing."); + this._addOffsets = value; + }, + enumerable: false, + configurable: true + }); + Object.defineProperty(WasmDisassembler.prototype, "skipTypes", { + get: function () { + return this._skipTypes; + }, + set: function (skipTypes) { + if (this._currentPosition) + throw new Error("Cannot switch skipTypes during processing."); + this._skipTypes = skipTypes; + }, + enumerable: false, + configurable: true + }); + Object.defineProperty(WasmDisassembler.prototype, "labelMode", { + get: function () { + return this._labelMode; + }, + set: function (value) { + if (this._currentPosition) + throw new Error("Cannot switch labelMode during processing."); + this._labelMode = value; + }, + enumerable: false, + configurable: true + }); + Object.defineProperty(WasmDisassembler.prototype, "exportMetadata", { + get: function () { + return this._exportMetadata; + }, + set: function (exportMetadata) { + if (this._currentPosition) + throw new Error("Cannot switch exportMetadata during processing."); + this._exportMetadata = exportMetadata; + }, + enumerable: false, + configurable: true + }); + Object.defineProperty(WasmDisassembler.prototype, "nameResolver", { + get: function () { + return this._nameResolver; + }, + set: function (resolver) { + if (this._currentPosition) + throw new Error("Cannot switch nameResolver during processing."); + this._nameResolver = resolver; + }, + enumerable: false, + configurable: true + }); + WasmDisassembler.prototype.appendBuffer = function (s) { + this._buffer += s; + }; + WasmDisassembler.prototype.newLine = function () { + if (this.addOffsets) + this._offsets.push(this._currentPosition); + this._lines.push(this._buffer); + this._buffer = ""; + }; + WasmDisassembler.prototype.logStartOfFunctionBodyOffset = function () { + if (this.addOffsets) { + this._currentFunctionBodyOffset = this._currentPosition; + } + }; + WasmDisassembler.prototype.logEndOfFunctionBodyOffset = function () { + if (this.addOffsets) { + this._functionBodyOffsets.push({ + start: this._currentFunctionBodyOffset, + end: this._currentPosition, + }); + } + }; + WasmDisassembler.prototype.typeIndexToString = function (typeIndex) { + if (typeIndex >= 0) + return this._nameResolver.getTypeName(typeIndex, true); + switch (typeIndex) { + case -16 /* TypeKind.funcref */: + return "func"; + case -17 /* TypeKind.externref */: + return "extern"; + case -18 /* TypeKind.anyref */: + return "any"; + case -19 /* TypeKind.eqref */: + return "eq"; + case -22 /* TypeKind.i31ref */: + return "i31"; + case -25 /* TypeKind.structref */: + return "struct"; + case -26 /* TypeKind.arrayref */: + return "array"; + case -24 /* TypeKind.nullfuncref */: + return "nofunc"; + case -23 /* TypeKind.nullexternref */: + return "noextern"; + case -27 /* TypeKind.nullref */: + return "none"; + } + }; + WasmDisassembler.prototype.typeToString = function (type) { + switch (type.kind) { + case -1 /* TypeKind.i32 */: + return "i32"; + case -2 /* TypeKind.i64 */: + return "i64"; + case -3 /* TypeKind.f32 */: + return "f32"; + case -4 /* TypeKind.f64 */: + return "f64"; + case -5 /* TypeKind.v128 */: + return "v128"; + case -6 /* TypeKind.i8 */: + return "i8"; + case -7 /* TypeKind.i16 */: + return "i16"; + case -16 /* TypeKind.funcref */: + return "funcref"; + case -17 /* TypeKind.externref */: + return "externref"; + case -18 /* TypeKind.anyref */: + return "anyref"; + case -19 /* TypeKind.eqref */: + return "eqref"; + case -22 /* TypeKind.i31ref */: + return "i31ref"; + case -25 /* TypeKind.structref */: + return "structref"; + case -26 /* TypeKind.arrayref */: + return "arrayref"; + case -24 /* TypeKind.nullfuncref */: + return "nullfuncref"; + case -23 /* TypeKind.nullexternref */: + return "nullexternref"; + case -27 /* TypeKind.nullref */: + return "nullref"; + case -21 /* TypeKind.ref */: + return "(ref ".concat(this.typeIndexToString(type.ref_index), ")"); + case -20 /* TypeKind.ref_null */: + return "(ref null ".concat(this.typeIndexToString(type.ref_index), ")"); + default: + throw new Error("Unexpected type ".concat(JSON.stringify(type))); + } + }; + WasmDisassembler.prototype.maybeMut = function (type, mutability) { + return mutability ? "(mut ".concat(type, ")") : type; + }; + WasmDisassembler.prototype.globalTypeToString = function (type) { + var typeStr = this.typeToString(type.contentType); + return this.maybeMut(typeStr, !!type.mutability); + }; + WasmDisassembler.prototype.printFuncType = function (typeIndex) { + var type = this._types[typeIndex]; + if (type.params.length > 0) { + this.appendBuffer(" (param"); + for (var i = 0; i < type.params.length; i++) { + this.appendBuffer(" "); + this.appendBuffer(this.typeToString(type.params[i])); + } + this.appendBuffer(")"); + } + if (type.returns.length > 0) { + this.appendBuffer(" (result"); + for (var i = 0; i < type.returns.length; i++) { + this.appendBuffer(" "); + this.appendBuffer(this.typeToString(type.returns[i])); + } + this.appendBuffer(")"); + } + }; + WasmDisassembler.prototype.printStructType = function (typeIndex) { + var type = this._types[typeIndex]; + if (type.fields.length === 0) + return; + for (var i = 0; i < type.fields.length; i++) { + var fieldType = this.maybeMut(this.typeToString(type.fields[i]), type.mutabilities[i]); + var fieldName = this._nameResolver.getFieldName(typeIndex, i, false); + this.appendBuffer(" (field ".concat(fieldName, " ").concat(fieldType, ")")); + } + }; + WasmDisassembler.prototype.printArrayType = function (typeIndex) { + var type = this._types[typeIndex]; + this.appendBuffer(" (field "); + this.appendBuffer(this.maybeMut(this.typeToString(type.elementType), type.mutability)); + }; + WasmDisassembler.prototype.printBlockType = function (type) { + if (type.kind === -64 /* TypeKind.empty_block_type */) { + return; + } + if (type.kind === 0 /* TypeKind.unspecified */) { + if (this._types[type.index].form == -32 /* TypeKind.func */) { + return this.printFuncType(type.index); + } + else { + // Encoding error. + this.appendBuffer(" (type ".concat(type.index, ")")); + return; + } + } + this.appendBuffer(" (result "); + this.appendBuffer(this.typeToString(type)); + this.appendBuffer(")"); + }; + WasmDisassembler.prototype.printString = function (b) { + this.appendBuffer('"'); + for (var i = 0; i < b.length; i++) { + var byte = b[i]; + if (byte < 0x20 || + byte >= 0x7f || + byte == /* " */ 0x22 || + byte == /* \ */ 0x5c) { + this.appendBuffer("\\" + (byte >> 4).toString(16) + (byte & 15).toString(16)); + } + else { + this.appendBuffer(String.fromCharCode(byte)); + } + } + this.appendBuffer('"'); + }; + WasmDisassembler.prototype.printExpression = function (expression) { + for (var _i = 0, expression_1 = expression; _i < expression_1.length; _i++) { + var operator = expression_1[_i]; + this.appendBuffer("("); + this.printOperator(operator); + this.appendBuffer(")"); + } + }; + // extraDepthOffset is used by "delegate" instructions. + WasmDisassembler.prototype.useLabel = function (depth, extraDepthOffset) { + if (extraDepthOffset === void 0) { extraDepthOffset = 0; } + if (!this._backrefLabels) { + return "" + depth; + } + var i = this._backrefLabels.length - depth - 1 - extraDepthOffset; + if (i < 0) { + return "" + depth; + } + var backrefLabel = this._backrefLabels[i]; + if (!backrefLabel.useLabel) { + backrefLabel.useLabel = true; + backrefLabel.label = this._nameResolver.getLabel(this._labelIndex); + var line = this._lines[backrefLabel.line]; + this._lines[backrefLabel.line] = + line.substring(0, backrefLabel.position) + + " " + + backrefLabel.label + + line.substring(backrefLabel.position); + this._labelIndex++; + } + return backrefLabel.label || "" + depth; + }; + WasmDisassembler.prototype.printOperator = function (operator) { + var code = operator.code; + this.appendBuffer(WasmParser_js_1.OperatorCodeNames[code]); + switch (code) { + case 2 /* OperatorCode.block */: + case 3 /* OperatorCode.loop */: + case 4 /* OperatorCode.if */: + case 6 /* OperatorCode.try */: + if (this._labelMode !== LabelMode.Depth) { + var backrefLabel_1 = { + line: this._lines.length, + position: this._buffer.length, + useLabel: false, + label: null, + }; + if (this._labelMode === LabelMode.Always) { + backrefLabel_1.useLabel = true; + backrefLabel_1.label = this._nameResolver.getLabel(this._labelIndex++); + if (backrefLabel_1.label) { + this.appendBuffer(" "); + this.appendBuffer(backrefLabel_1.label); + } + } + this._backrefLabels.push(backrefLabel_1); + } + this.printBlockType(operator.blockType); + break; + case 11 /* OperatorCode.end */: + if (this._labelMode === LabelMode.Depth) { + break; + } + var backrefLabel = this._backrefLabels.pop(); + if (backrefLabel.label) { + this.appendBuffer(" "); + this.appendBuffer(backrefLabel.label); + } + break; + case 12 /* OperatorCode.br */: + case 13 /* OperatorCode.br_if */: + case 212 /* OperatorCode.br_on_null */: + case 214 /* OperatorCode.br_on_non_null */: + this.appendBuffer(" "); + this.appendBuffer(this.useLabel(operator.brDepth)); + break; + case 64322 /* OperatorCode.br_on_cast_ */: + case 64323 /* OperatorCode.br_on_cast_fail_ */: + case 64326 /* OperatorCode.br_on_cast__ */: + case 64327 /* OperatorCode.br_on_cast_fail__ */: + this.appendBuffer(" "); + this.appendBuffer(this.typeIndexToString(operator.refType)); + this.appendBuffer(" "); + this.appendBuffer(this.useLabel(operator.brDepth)); + break; + case 64334 /* OperatorCode.br_on_cast */: + case 64335 /* OperatorCode.br_on_cast_fail */: + this.appendBuffer(" flags=" + operator.literal); + this.appendBuffer(" "); + this.appendBuffer(this.typeIndexToString(operator.srcType)); + this.appendBuffer(" "); + this.appendBuffer(this.typeIndexToString(operator.refType)); + this.appendBuffer(" "); + this.appendBuffer(this.useLabel(operator.brDepth)); + break; + case 14 /* OperatorCode.br_table */: + for (var i = 0; i < operator.brTable.length; i++) { + this.appendBuffer(" "); + this.appendBuffer(this.useLabel(operator.brTable[i])); + } + break; + case 9 /* OperatorCode.rethrow */: + this.appendBuffer(" "); + this.appendBuffer(this.useLabel(operator.relativeDepth)); + break; + case 24 /* OperatorCode.delegate */: + this.appendBuffer(" "); + this.appendBuffer(this.useLabel(operator.relativeDepth, 1)); + break; + case 7 /* OperatorCode.catch */: + case 8 /* OperatorCode.throw */: + var tagName = this._nameResolver.getTagName(operator.tagIndex, true); + this.appendBuffer(" ".concat(tagName)); + break; + case 208 /* OperatorCode.ref_null */: + this.appendBuffer(" "); + this.appendBuffer(this.typeIndexToString(operator.refType)); + break; + case 16 /* OperatorCode.call */: + case 18 /* OperatorCode.return_call */: + case 210 /* OperatorCode.ref_func */: + var funcName = this._nameResolver.getFunctionName(operator.funcIndex, operator.funcIndex < this._importCount, true); + this.appendBuffer(" ".concat(funcName)); + break; + case 17 /* OperatorCode.call_indirect */: + case 19 /* OperatorCode.return_call_indirect */: + this.printFuncType(operator.typeIndex); + break; + case 28 /* OperatorCode.select_with_type */: { + var selectType = this.typeToString(operator.selectType); + this.appendBuffer(" ".concat(selectType)); + break; + } + case 32 /* OperatorCode.local_get */: + case 33 /* OperatorCode.local_set */: + case 34 /* OperatorCode.local_tee */: + var paramName = this._nameResolver.getVariableName(this._funcIndex, operator.localIndex, true); + this.appendBuffer(" ".concat(paramName)); + break; + case 35 /* OperatorCode.global_get */: + case 36 /* OperatorCode.global_set */: + var globalName = this._nameResolver.getGlobalName(operator.globalIndex, true); + this.appendBuffer(" ".concat(globalName)); + break; + case 40 /* OperatorCode.i32_load */: + case 41 /* OperatorCode.i64_load */: + case 42 /* OperatorCode.f32_load */: + case 43 /* OperatorCode.f64_load */: + case 44 /* OperatorCode.i32_load8_s */: + case 45 /* OperatorCode.i32_load8_u */: + case 46 /* OperatorCode.i32_load16_s */: + case 47 /* OperatorCode.i32_load16_u */: + case 48 /* OperatorCode.i64_load8_s */: + case 49 /* OperatorCode.i64_load8_u */: + case 50 /* OperatorCode.i64_load16_s */: + case 51 /* OperatorCode.i64_load16_u */: + case 52 /* OperatorCode.i64_load32_s */: + case 53 /* OperatorCode.i64_load32_u */: + case 54 /* OperatorCode.i32_store */: + case 55 /* OperatorCode.i64_store */: + case 56 /* OperatorCode.f32_store */: + case 57 /* OperatorCode.f64_store */: + case 58 /* OperatorCode.i32_store8 */: + case 59 /* OperatorCode.i32_store16 */: + case 60 /* OperatorCode.i64_store8 */: + case 61 /* OperatorCode.i64_store16 */: + case 62 /* OperatorCode.i64_store32 */: + case 65024 /* OperatorCode.memory_atomic_notify */: + case 65025 /* OperatorCode.memory_atomic_wait32 */: + case 65026 /* OperatorCode.memory_atomic_wait64 */: + case 65040 /* OperatorCode.i32_atomic_load */: + case 65041 /* OperatorCode.i64_atomic_load */: + case 65042 /* OperatorCode.i32_atomic_load8_u */: + case 65043 /* OperatorCode.i32_atomic_load16_u */: + case 65044 /* OperatorCode.i64_atomic_load8_u */: + case 65045 /* OperatorCode.i64_atomic_load16_u */: + case 65046 /* OperatorCode.i64_atomic_load32_u */: + case 65047 /* OperatorCode.i32_atomic_store */: + case 65048 /* OperatorCode.i64_atomic_store */: + case 65049 /* OperatorCode.i32_atomic_store8 */: + case 65050 /* OperatorCode.i32_atomic_store16 */: + case 65051 /* OperatorCode.i64_atomic_store8 */: + case 65052 /* OperatorCode.i64_atomic_store16 */: + case 65053 /* OperatorCode.i64_atomic_store32 */: + case 65054 /* OperatorCode.i32_atomic_rmw_add */: + case 65055 /* OperatorCode.i64_atomic_rmw_add */: + case 65056 /* OperatorCode.i32_atomic_rmw8_add_u */: + case 65057 /* OperatorCode.i32_atomic_rmw16_add_u */: + case 65058 /* OperatorCode.i64_atomic_rmw8_add_u */: + case 65059 /* OperatorCode.i64_atomic_rmw16_add_u */: + case 65060 /* OperatorCode.i64_atomic_rmw32_add_u */: + case 65061 /* OperatorCode.i32_atomic_rmw_sub */: + case 65062 /* OperatorCode.i64_atomic_rmw_sub */: + case 65063 /* OperatorCode.i32_atomic_rmw8_sub_u */: + case 65064 /* OperatorCode.i32_atomic_rmw16_sub_u */: + case 65065 /* OperatorCode.i64_atomic_rmw8_sub_u */: + case 65066 /* OperatorCode.i64_atomic_rmw16_sub_u */: + case 65067 /* OperatorCode.i64_atomic_rmw32_sub_u */: + case 65068 /* OperatorCode.i32_atomic_rmw_and */: + case 65069 /* OperatorCode.i64_atomic_rmw_and */: + case 65070 /* OperatorCode.i32_atomic_rmw8_and_u */: + case 65071 /* OperatorCode.i32_atomic_rmw16_and_u */: + case 65072 /* OperatorCode.i64_atomic_rmw8_and_u */: + case 65073 /* OperatorCode.i64_atomic_rmw16_and_u */: + case 65074 /* OperatorCode.i64_atomic_rmw32_and_u */: + case 65075 /* OperatorCode.i32_atomic_rmw_or */: + case 65076 /* OperatorCode.i64_atomic_rmw_or */: + case 65077 /* OperatorCode.i32_atomic_rmw8_or_u */: + case 65078 /* OperatorCode.i32_atomic_rmw16_or_u */: + case 65079 /* OperatorCode.i64_atomic_rmw8_or_u */: + case 65080 /* OperatorCode.i64_atomic_rmw16_or_u */: + case 65081 /* OperatorCode.i64_atomic_rmw32_or_u */: + case 65082 /* OperatorCode.i32_atomic_rmw_xor */: + case 65083 /* OperatorCode.i64_atomic_rmw_xor */: + case 65084 /* OperatorCode.i32_atomic_rmw8_xor_u */: + case 65085 /* OperatorCode.i32_atomic_rmw16_xor_u */: + case 65086 /* OperatorCode.i64_atomic_rmw8_xor_u */: + case 65087 /* OperatorCode.i64_atomic_rmw16_xor_u */: + case 65088 /* OperatorCode.i64_atomic_rmw32_xor_u */: + case 65089 /* OperatorCode.i32_atomic_rmw_xchg */: + case 65090 /* OperatorCode.i64_atomic_rmw_xchg */: + case 65091 /* OperatorCode.i32_atomic_rmw8_xchg_u */: + case 65092 /* OperatorCode.i32_atomic_rmw16_xchg_u */: + case 65093 /* OperatorCode.i64_atomic_rmw8_xchg_u */: + case 65094 /* OperatorCode.i64_atomic_rmw16_xchg_u */: + case 65095 /* OperatorCode.i64_atomic_rmw32_xchg_u */: + case 65096 /* OperatorCode.i32_atomic_rmw_cmpxchg */: + case 65097 /* OperatorCode.i64_atomic_rmw_cmpxchg */: + case 65098 /* OperatorCode.i32_atomic_rmw8_cmpxchg_u */: + case 65099 /* OperatorCode.i32_atomic_rmw16_cmpxchg_u */: + case 65100 /* OperatorCode.i64_atomic_rmw8_cmpxchg_u */: + case 65101 /* OperatorCode.i64_atomic_rmw16_cmpxchg_u */: + case 65102 /* OperatorCode.i64_atomic_rmw32_cmpxchg_u */: + case 64768 /* OperatorCode.v128_load */: + case 64769 /* OperatorCode.i16x8_load8x8_s */: + case 64770 /* OperatorCode.i16x8_load8x8_u */: + case 64771 /* OperatorCode.i32x4_load16x4_s */: + case 64772 /* OperatorCode.i32x4_load16x4_u */: + case 64773 /* OperatorCode.i64x2_load32x2_s */: + case 64774 /* OperatorCode.i64x2_load32x2_u */: + case 64775 /* OperatorCode.v8x16_load_splat */: + case 64776 /* OperatorCode.v16x8_load_splat */: + case 64777 /* OperatorCode.v32x4_load_splat */: + case 64778 /* OperatorCode.v64x2_load_splat */: + case 64779 /* OperatorCode.v128_store */: + case 64860 /* OperatorCode.v128_load32_zero */: + case 64861 /* OperatorCode.v128_load64_zero */: + var memoryAddress = memoryAddressToString(operator.memoryAddress, operator.code); + if (memoryAddress !== null) { + this.appendBuffer(" "); + this.appendBuffer(memoryAddress); + } + break; + case 63 /* OperatorCode.memory_size */: + case 64 /* OperatorCode.memory_grow */: + break; + case 65 /* OperatorCode.i32_const */: + this.appendBuffer(" ".concat(operator.literal.toString())); + break; + case 66 /* OperatorCode.i64_const */: + this.appendBuffer(" ".concat(operator.literal.toString())); + break; + case 67 /* OperatorCode.f32_const */: + this.appendBuffer(" ".concat(formatFloat32(operator.literal))); + break; + case 68 /* OperatorCode.f64_const */: + this.appendBuffer(" ".concat(formatFloat64(operator.literal))); + break; + case 64780 /* OperatorCode.v128_const */: + this.appendBuffer(" i32x4 ".concat(formatI32Array(operator.literal, 4))); + break; + case 64781 /* OperatorCode.i8x16_shuffle */: + this.appendBuffer(" ".concat(formatI8Array(operator.lines, 16))); + break; + case 64789 /* OperatorCode.i8x16_extract_lane_s */: + case 64790 /* OperatorCode.i8x16_extract_lane_u */: + case 64791 /* OperatorCode.i8x16_replace_lane */: + case 64792 /* OperatorCode.i16x8_extract_lane_s */: + case 64793 /* OperatorCode.i16x8_extract_lane_u */: + case 64794 /* OperatorCode.i16x8_replace_lane */: + case 64795 /* OperatorCode.i32x4_extract_lane */: + case 64796 /* OperatorCode.i32x4_replace_lane */: + case 64799 /* OperatorCode.f32x4_extract_lane */: + case 64800 /* OperatorCode.f32x4_replace_lane */: + case 64797 /* OperatorCode.i64x2_extract_lane */: + case 64798 /* OperatorCode.i64x2_replace_lane */: + case 64801 /* OperatorCode.f64x2_extract_lane */: + case 64802 /* OperatorCode.f64x2_replace_lane */: + this.appendBuffer(" ".concat(operator.lineIndex)); + break; + case 64520 /* OperatorCode.memory_init */: + case 64521 /* OperatorCode.data_drop */: + this.appendBuffer(" ".concat(operator.segmentIndex)); + break; + case 64525 /* OperatorCode.elem_drop */: + var elementName = this._nameResolver.getElementName(operator.segmentIndex, true); + this.appendBuffer(" ".concat(elementName)); + break; + case 38 /* OperatorCode.table_set */: + case 37 /* OperatorCode.table_get */: + case 64529 /* OperatorCode.table_fill */: { + var tableName = this._nameResolver.getTableName(operator.tableIndex, true); + this.appendBuffer(" ".concat(tableName)); + break; + } + case 64526 /* OperatorCode.table_copy */: { + // Table index might be omitted and defaults to 0. + if (operator.tableIndex !== 0 || operator.destinationIndex !== 0) { + var tableName = this._nameResolver.getTableName(operator.tableIndex, true); + var destinationName = this._nameResolver.getTableName(operator.destinationIndex, true); + this.appendBuffer(" ".concat(destinationName, " ").concat(tableName)); + } + break; + } + case 64524 /* OperatorCode.table_init */: { + // Table index might be omitted and defaults to 0. + if (operator.tableIndex !== 0) { + var tableName = this._nameResolver.getTableName(operator.tableIndex, true); + this.appendBuffer(" ".concat(tableName)); + } + var elementName_1 = this._nameResolver.getElementName(operator.segmentIndex, true); + this.appendBuffer(" ".concat(elementName_1)); + break; + } + case 64259 /* OperatorCode.struct_get */: + case 64260 /* OperatorCode.struct_get_s */: + case 64261 /* OperatorCode.struct_get_u */: + case 64262 /* OperatorCode.struct_set */: { + var refType = this.typeIndexToString(operator.refType); + var fieldName = this._nameResolver.getFieldName(operator.refType, operator.fieldIndex, true); + this.appendBuffer(" ".concat(refType, " ").concat(fieldName)); + break; + } + case 64304 /* OperatorCode.rtt_canon */: + case 64305 /* OperatorCode.rtt_sub */: + case 64306 /* OperatorCode.rtt_fresh_sub */: + case 64321 /* OperatorCode.ref_cast */: + case 64329 /* OperatorCode.ref_cast_null */: + case 64320 /* OperatorCode.ref_test */: + case 64328 /* OperatorCode.ref_test_null */: + case 64264 /* OperatorCode.struct_new_default */: + case 64258 /* OperatorCode.struct_new_default_with_rtt */: + case 64263 /* OperatorCode.struct_new */: + case 64257 /* OperatorCode.struct_new_with_rtt */: + case 64284 /* OperatorCode.array_new_default */: + case 64274 /* OperatorCode.array_new_default_with_rtt */: + case 64283 /* OperatorCode.array_new */: + case 64273 /* OperatorCode.array_new_with_rtt */: + case 64275 /* OperatorCode.array_get */: + case 64276 /* OperatorCode.array_get_s */: + case 64277 /* OperatorCode.array_get_u */: + case 64278 /* OperatorCode.array_set */: + case 64279 /* OperatorCode.array_len_ */: { + var refType = this.typeIndexToString(operator.refType); + this.appendBuffer(" ".concat(refType)); + break; + } + case 64280 /* OperatorCode.array_copy */: { + var dstType = this.typeIndexToString(operator.refType); + var srcType = this.typeIndexToString(operator.srcType); + this.appendBuffer(" ".concat(dstType, " ").concat(srcType)); + break; + } + case 64282 /* OperatorCode.array_new_fixed */: { + var refType = this.typeIndexToString(operator.refType); + var length_1 = operator.len; + this.appendBuffer(" ".concat(refType, " ").concat(length_1)); + break; + } + } + }; + WasmDisassembler.prototype.printImportSource = function (info) { + this.printString(info.module); + this.appendBuffer(" "); + this.printString(info.field); + }; + WasmDisassembler.prototype.increaseIndent = function () { + this._indent += IndentIncrement; + this._indentLevel++; + }; + WasmDisassembler.prototype.decreaseIndent = function () { + this._indent = this._indent.slice(0, -IndentIncrement.length); + this._indentLevel--; + }; + WasmDisassembler.prototype.disassemble = function (reader) { + var _this = this; + var done = this.disassembleChunk(reader); + if (!done) + return null; + var lines = this._lines; + if (this._addOffsets) { + lines = lines.map(function (line, index) { + var position = formatHex(_this._offsets[index], 4); + return line + " ;; @" + position; + }); + } + lines.push(""); // we need '\n' after last line + var result = lines.join("\n"); + this._lines.length = 0; + this._offsets.length = 0; + this._functionBodyOffsets.length = 0; + return result; + }; + WasmDisassembler.prototype.getResult = function () { + var linesReady = this._lines.length; + if (this._backrefLabels && this._labelMode === LabelMode.WhenUsed) { + this._backrefLabels.some(function (backrefLabel) { + if (backrefLabel.useLabel) + return false; + linesReady = backrefLabel.line; + return true; + }); + } + if (linesReady === 0) { + return { + lines: [], + offsets: this._addOffsets ? [] : undefined, + done: this._done, + functionBodyOffsets: this._addOffsets ? [] : undefined, + }; + } + if (linesReady === this._lines.length) { + var result_1 = { + lines: this._lines, + offsets: this._addOffsets ? this._offsets : undefined, + done: this._done, + functionBodyOffsets: this._addOffsets + ? this._functionBodyOffsets + : undefined, + }; + this._lines = []; + if (this._addOffsets) { + this._offsets = []; + this._functionBodyOffsets = []; + } + return result_1; + } + var result = { + lines: this._lines.splice(0, linesReady), + offsets: this._addOffsets + ? this._offsets.splice(0, linesReady) + : undefined, + done: false, + functionBodyOffsets: this._addOffsets + ? this._functionBodyOffsets + : undefined, + }; + if (this._backrefLabels) { + this._backrefLabels.forEach(function (backrefLabel) { + backrefLabel.line -= linesReady; + }); + } + return result; + }; + WasmDisassembler.prototype.disassembleChunk = function (reader, offsetInModule) { + var _this = this; + if (offsetInModule === void 0) { offsetInModule = 0; } + if (this._done) + throw new Error("Invalid state: disassembly process was already finished."); + while (true) { + this._currentPosition = reader.position + offsetInModule; + if (!reader.read()) + return false; + switch (reader.state) { + case 2 /* BinaryReaderState.END_WASM */: + this.appendBuffer(")"); + this.newLine(); + this._reset(); + if (!reader.hasMoreBytes()) { + this._done = true; + return true; + } + break; + case -1 /* BinaryReaderState.ERROR */: + throw reader.error; + case 1 /* BinaryReaderState.BEGIN_WASM */: + this.appendBuffer("(module"); + this.newLine(); + break; + case 4 /* BinaryReaderState.END_SECTION */: + this._currentSectionId = -1 /* SectionCode.Unknown */; + break; + case 3 /* BinaryReaderState.BEGIN_SECTION */: + var sectionInfo = reader.result; + switch (sectionInfo.id) { + case 1 /* SectionCode.Type */: + case 2 /* SectionCode.Import */: + case 7 /* SectionCode.Export */: + case 6 /* SectionCode.Global */: + case 3 /* SectionCode.Function */: + case 8 /* SectionCode.Start */: + case 10 /* SectionCode.Code */: + case 5 /* SectionCode.Memory */: + case 11 /* SectionCode.Data */: + case 4 /* SectionCode.Table */: + case 9 /* SectionCode.Element */: + case 13 /* SectionCode.Tag */: + this._currentSectionId = sectionInfo.id; + this._indent = " "; + this._indentLevel = 0; + break; // reading known section; + default: + reader.skipSection(); + break; + } + break; + case 15 /* BinaryReaderState.MEMORY_SECTION_ENTRY */: + var memoryInfo = reader.result; + var memoryIndex = this._memoryCount++; + var memoryName = this._nameResolver.getMemoryName(memoryIndex, false); + this.appendBuffer(" (memory ".concat(memoryName)); + if (this._exportMetadata !== null) { + for (var _i = 0, _a = this._exportMetadata.getMemoryExportNames(memoryIndex); _i < _a.length; _i++) { + var exportName = _a[_i]; + this.appendBuffer(" (export ".concat(JSON.stringify(exportName), ")")); + } + } + this.appendBuffer(" ".concat(limitsToString(memoryInfo.limits))); + if (memoryInfo.shared) { + this.appendBuffer(" shared"); + } + this.appendBuffer(")"); + this.newLine(); + break; + case 23 /* BinaryReaderState.TAG_SECTION_ENTRY */: + var tagInfo = reader.result; + var tagIndex = this._eventCount++; + var tagName = this._nameResolver.getTagName(tagIndex, false); + this.appendBuffer(" (tag ".concat(tagName)); + if (this._exportMetadata !== null) { + for (var _b = 0, _c = this._exportMetadata.getTagExportNames(tagIndex); _b < _c.length; _b++) { + var exportName = _c[_b]; + this.appendBuffer(" (export ".concat(JSON.stringify(exportName), ")")); + } + } + this.printFuncType(tagInfo.typeIndex); + this.appendBuffer(")"); + this.newLine(); + break; + case 14 /* BinaryReaderState.TABLE_SECTION_ENTRY */: + var tableInfo = reader.result; + var tableIndex = this._tableCount++; + var tableName = this._nameResolver.getTableName(tableIndex, false); + this.appendBuffer(" (table ".concat(tableName)); + if (this._exportMetadata !== null) { + for (var _d = 0, _e = this._exportMetadata.getTableExportNames(tableIndex); _d < _e.length; _d++) { + var exportName = _e[_d]; + this.appendBuffer(" (export ".concat(JSON.stringify(exportName), ")")); + } + } + this.appendBuffer(" ".concat(limitsToString(tableInfo.limits), " ").concat(this.typeToString(tableInfo.elementType), ")")); + this.newLine(); + break; + case 17 /* BinaryReaderState.EXPORT_SECTION_ENTRY */: + // Skip printing exports here when we have export metadata + // which we can use to print export information inline. + if (this._exportMetadata === null) { + var exportInfo = reader.result; + this.appendBuffer(" (export "); + this.printString(exportInfo.field); + this.appendBuffer(" "); + switch (exportInfo.kind) { + case 0 /* ExternalKind.Function */: + var funcName = this._nameResolver.getFunctionName(exportInfo.index, exportInfo.index < this._importCount, true); + this.appendBuffer("(func ".concat(funcName, ")")); + break; + case 1 /* ExternalKind.Table */: + var tableName = this._nameResolver.getTableName(exportInfo.index, true); + this.appendBuffer("(table ".concat(tableName, ")")); + break; + case 2 /* ExternalKind.Memory */: + var memoryName = this._nameResolver.getMemoryName(exportInfo.index, true); + this.appendBuffer("(memory ".concat(memoryName, ")")); + break; + case 3 /* ExternalKind.Global */: + var globalName = this._nameResolver.getGlobalName(exportInfo.index, true); + this.appendBuffer("(global ".concat(globalName, ")")); + break; + case 4 /* ExternalKind.Tag */: + var tagName = this._nameResolver.getTagName(exportInfo.index, true); + this.appendBuffer("(tag ".concat(tagName, ")")); + break; + default: + throw new Error("Unsupported export ".concat(exportInfo.kind)); + } + this.appendBuffer(")"); + this.newLine(); + } + break; + case 12 /* BinaryReaderState.IMPORT_SECTION_ENTRY */: + var importInfo = reader.result; + switch (importInfo.kind) { + case 0 /* ExternalKind.Function */: + this._importCount++; + var funcIndex = this._funcIndex++; + var funcName = this._nameResolver.getFunctionName(funcIndex, true, false); + this.appendBuffer(" (func ".concat(funcName)); + if (this._exportMetadata !== null) { + for (var _f = 0, _g = this._exportMetadata.getFunctionExportNames(funcIndex); _f < _g.length; _f++) { + var exportName = _g[_f]; + this.appendBuffer(" (export ".concat(JSON.stringify(exportName), ")")); + } + } + this.appendBuffer(" (import "); + this.printImportSource(importInfo); + this.appendBuffer(")"); + this.printFuncType(importInfo.funcTypeIndex); + this.appendBuffer(")"); + break; + case 3 /* ExternalKind.Global */: + var globalImportInfo = importInfo.type; + var globalIndex = this._globalCount++; + var globalName = this._nameResolver.getGlobalName(globalIndex, false); + this.appendBuffer(" (global ".concat(globalName)); + if (this._exportMetadata !== null) { + for (var _h = 0, _j = this._exportMetadata.getGlobalExportNames(globalIndex); _h < _j.length; _h++) { + var exportName = _j[_h]; + this.appendBuffer(" (export ".concat(JSON.stringify(exportName), ")")); + } + } + this.appendBuffer(" (import "); + this.printImportSource(importInfo); + this.appendBuffer(") ".concat(this.globalTypeToString(globalImportInfo), ")")); + break; + case 2 /* ExternalKind.Memory */: + var memoryImportInfo = importInfo.type; + var memoryIndex = this._memoryCount++; + var memoryName = this._nameResolver.getMemoryName(memoryIndex, false); + this.appendBuffer(" (memory ".concat(memoryName)); + if (this._exportMetadata !== null) { + for (var _k = 0, _l = this._exportMetadata.getMemoryExportNames(memoryIndex); _k < _l.length; _k++) { + var exportName = _l[_k]; + this.appendBuffer(" (export ".concat(JSON.stringify(exportName), ")")); + } + } + this.appendBuffer(" (import "); + this.printImportSource(importInfo); + this.appendBuffer(") ".concat(limitsToString(memoryImportInfo.limits))); + if (memoryImportInfo.shared) { + this.appendBuffer(" shared"); + } + this.appendBuffer(")"); + break; + case 1 /* ExternalKind.Table */: + var tableImportInfo = importInfo.type; + var tableIndex = this._tableCount++; + var tableName = this._nameResolver.getTableName(tableIndex, false); + this.appendBuffer(" (table ".concat(tableName)); + if (this._exportMetadata !== null) { + for (var _m = 0, _o = this._exportMetadata.getTableExportNames(tableIndex); _m < _o.length; _m++) { + var exportName = _o[_m]; + this.appendBuffer(" (export ".concat(JSON.stringify(exportName), ")")); + } + } + this.appendBuffer(" (import "); + this.printImportSource(importInfo); + this.appendBuffer(") ".concat(limitsToString(tableImportInfo.limits), " ").concat(this.typeToString(tableImportInfo.elementType), ")")); + break; + case 4 /* ExternalKind.Tag */: + var eventImportInfo = importInfo.type; + var tagIndex = this._eventCount++; + var tagName = this._nameResolver.getTagName(tagIndex, false); + this.appendBuffer(" (tag ".concat(tagName)); + if (this._exportMetadata !== null) { + for (var _p = 0, _q = this._exportMetadata.getTagExportNames(tagIndex); _p < _q.length; _p++) { + var exportName = _q[_p]; + this.appendBuffer(" (export ".concat(JSON.stringify(exportName), ")")); + } + } + this.appendBuffer(" (import "); + this.printImportSource(importInfo); + this.appendBuffer(")"); + this.printFuncType(eventImportInfo.typeIndex); + this.appendBuffer(")"); + break; + default: + throw new Error("NYI other import types: ".concat(importInfo.kind)); + } + this.newLine(); + break; + case 33 /* BinaryReaderState.BEGIN_ELEMENT_SECTION_ENTRY */: + var elementSegment = reader.result; + var elementIndex = this._elementCount++; + var elementName = this._nameResolver.getElementName(elementIndex, false); + this.appendBuffer(" (elem ".concat(elementName)); + switch (elementSegment.mode) { + case 0 /* ElementMode.Active */: + if (elementSegment.tableIndex !== 0) { + var tableName_1 = this._nameResolver.getTableName(elementSegment.tableIndex, false); + this.appendBuffer(" (table ".concat(tableName_1, ")")); + } + break; + case 1 /* ElementMode.Passive */: + break; + case 2 /* ElementMode.Declarative */: + this.appendBuffer(" declare"); + break; + } + break; + case 35 /* BinaryReaderState.END_ELEMENT_SECTION_ENTRY */: + this.appendBuffer(")"); + this.newLine(); + break; + case 34 /* BinaryReaderState.ELEMENT_SECTION_ENTRY_BODY */: + var elementSegmentBody = reader.result; + this.appendBuffer(" ".concat(this.typeToString(elementSegmentBody.elementType))); + break; + case 39 /* BinaryReaderState.BEGIN_GLOBAL_SECTION_ENTRY */: + var globalInfo = reader.result; + var globalIndex = this._globalCount++; + var globalName = this._nameResolver.getGlobalName(globalIndex, false); + this.appendBuffer(" (global ".concat(globalName)); + if (this._exportMetadata !== null) { + for (var _r = 0, _s = this._exportMetadata.getGlobalExportNames(globalIndex); _r < _s.length; _r++) { + var exportName = _s[_r]; + this.appendBuffer(" (export ".concat(JSON.stringify(exportName), ")")); + } + } + this.appendBuffer(" ".concat(this.globalTypeToString(globalInfo.type))); + break; + case 40 /* BinaryReaderState.END_GLOBAL_SECTION_ENTRY */: + this.appendBuffer(")"); + this.newLine(); + break; + case 11 /* BinaryReaderState.TYPE_SECTION_ENTRY */: + var typeEntry = reader.result; + var typeIndex = this._types.length; + this._types.push(typeEntry); + if (!this._skipTypes) { + var typeName = this._nameResolver.getTypeName(typeIndex, false); + var superTypeName = undefined; + if (typeEntry.supertypes !== undefined) { + superTypeName = typeEntry.supertypes + .map(function (ty) { return _this.typeIndexToString(ty); }) + .join("+"); + } + this.appendBuffer(this._indent); + this.appendBuffer("(type ".concat(typeName, " ")); + var subtype = typeEntry.supertypes || typeEntry.final; + if (subtype) { + this.appendBuffer("(sub "); + if (typeEntry.final) + this.appendBuffer("final "); + if (typeEntry.supertypes) { + this.appendBuffer(typeEntry.supertypes + .map(function (ty) { return _this.typeIndexToString(ty); }) + .join(" ")); + this.appendBuffer(" "); + } + } + if (typeEntry.form === -32 /* TypeKind.func */) { + this.appendBuffer("(func"); + this.printFuncType(typeIndex); + this.appendBuffer(")"); + } + else if (typeEntry.form === -33 /* TypeKind.struct */) { + this.appendBuffer("(struct"); + this.printStructType(typeIndex); + this.appendBuffer(")"); + } + else if (typeEntry.form === -34 /* TypeKind.array */) { + this.appendBuffer("(array"); + this.printArrayType(typeIndex); + this.appendBuffer(")"); + } + else { + throw new Error("Unknown type form: ".concat(typeEntry.form)); + } + if (subtype) { + this.appendBuffer(")"); + } + this.appendBuffer(")"); + this.newLine(); + } + break; + case 22 /* BinaryReaderState.START_SECTION_ENTRY */: + var startEntry = reader.result; + var funcName = this._nameResolver.getFunctionName(startEntry.index, startEntry.index < this._importCount, true); + this.appendBuffer(" (start ".concat(funcName, ")")); + this.newLine(); + break; + case 36 /* BinaryReaderState.BEGIN_DATA_SECTION_ENTRY */: + this.appendBuffer(" (data"); + break; + case 37 /* BinaryReaderState.DATA_SECTION_ENTRY_BODY */: + var body = reader.result; + this.appendBuffer(" "); + this.printString(body.data); + break; + case 38 /* BinaryReaderState.END_DATA_SECTION_ENTRY */: + this.appendBuffer(")"); + this.newLine(); + break; + case 25 /* BinaryReaderState.BEGIN_INIT_EXPRESSION_BODY */: + case 44 /* BinaryReaderState.BEGIN_OFFSET_EXPRESSION_BODY */: + this._expression = []; + break; + case 26 /* BinaryReaderState.INIT_EXPRESSION_OPERATOR */: + case 45 /* BinaryReaderState.OFFSET_EXPRESSION_OPERATOR */: + var operator = reader.result; + if (operator.code !== 11 /* OperatorCode.end */) { + this._expression.push(operator); + } + break; + case 46 /* BinaryReaderState.END_OFFSET_EXPRESSION_BODY */: + if (this._expression.length > 1) { + this.appendBuffer(" (offset "); + this.printExpression(this._expression); + this.appendBuffer(")"); + } + else { + this.appendBuffer(" "); + this.printExpression(this._expression); + } + this._expression = []; + break; + case 27 /* BinaryReaderState.END_INIT_EXPRESSION_BODY */: + if (this._expression.length > 1 && + this._currentSectionId === 9 /* SectionCode.Element */) { + this.appendBuffer(" (item "); + this.printExpression(this._expression); + this.appendBuffer(")"); + } + else { + this.appendBuffer(" "); + this.printExpression(this._expression); + } + this._expression = []; + break; + case 13 /* BinaryReaderState.FUNCTION_SECTION_ENTRY */: + this._funcTypes.push(reader.result.typeIndex); + break; + case 28 /* BinaryReaderState.BEGIN_FUNCTION_BODY */: + var func = reader.result; + var type = this._types[this._funcTypes[this._funcIndex - this._importCount]]; + this.appendBuffer(" (func "); + this.appendBuffer(this._nameResolver.getFunctionName(this._funcIndex, false, false)); + if (this._exportMetadata !== null) { + for (var _t = 0, _u = this._exportMetadata.getFunctionExportNames(this._funcIndex); _t < _u.length; _t++) { + var exportName = _u[_t]; + this.appendBuffer(" (export ".concat(JSON.stringify(exportName), ")")); + } + } + for (var i = 0; i < type.params.length; i++) { + var paramName = this._nameResolver.getVariableName(this._funcIndex, i, false); + this.appendBuffer(" (param ".concat(paramName, " ").concat(this.typeToString(type.params[i]), ")")); + } + for (var i = 0; i < type.returns.length; i++) { + this.appendBuffer(" (result ".concat(this.typeToString(type.returns[i]), ")")); + } + this.newLine(); + var localIndex = type.params.length; + if (func.locals.length > 0) { + this.appendBuffer(" "); + for (var _v = 0, _w = func.locals; _v < _w.length; _v++) { + var l = _w[_v]; + for (var i = 0; i < l.count; i++) { + var paramName = this._nameResolver.getVariableName(this._funcIndex, localIndex++, false); + this.appendBuffer(" (local ".concat(paramName, " ").concat(this.typeToString(l.type), ")")); + } + } + this.newLine(); + } + this._indent = " "; + this._indentLevel = 0; + this._labelIndex = 0; + this._backrefLabels = this._labelMode === LabelMode.Depth ? null : []; + this._logFirstInstruction = true; + break; + case 30 /* BinaryReaderState.CODE_OPERATOR */: + if (this._logFirstInstruction) { + this.logStartOfFunctionBodyOffset(); + this._logFirstInstruction = false; + } + var operator = reader.result; + if (operator.code == 11 /* OperatorCode.end */ && this._indentLevel == 0) { + // reached of the function, closing function body + this.appendBuffer(" )"); + this.newLine(); + break; + } + switch (operator.code) { + case 11 /* OperatorCode.end */: + case 5 /* OperatorCode.else */: + case 7 /* OperatorCode.catch */: + case 25 /* OperatorCode.catch_all */: + case 10 /* OperatorCode.unwind */: + case 24 /* OperatorCode.delegate */: + this.decreaseIndent(); + break; + } + this.appendBuffer(this._indent); + this.printOperator(operator); + this.newLine(); + switch (operator.code) { + case 4 /* OperatorCode.if */: + case 2 /* OperatorCode.block */: + case 3 /* OperatorCode.loop */: + case 5 /* OperatorCode.else */: + case 6 /* OperatorCode.try */: + case 7 /* OperatorCode.catch */: + case 25 /* OperatorCode.catch_all */: + case 10 /* OperatorCode.unwind */: + this.increaseIndent(); + break; + } + break; + case 31 /* BinaryReaderState.END_FUNCTION_BODY */: + this._funcIndex++; + this._backrefLabels = null; + this.logEndOfFunctionBodyOffset(); + // See case BinaryReaderState.CODE_OPERATOR for closing of body + break; + case 47 /* BinaryReaderState.BEGIN_REC_GROUP */: + if (!this._skipTypes) { + this.appendBuffer(" (rec"); + this.newLine(); + this.increaseIndent(); + } + break; + case 48 /* BinaryReaderState.END_REC_GROUP */: + if (!this._skipTypes) { + this.decreaseIndent(); + this.appendBuffer(" )"); + this.newLine(); + } + break; + default: + throw new Error("Expectected state: ".concat(reader.state)); + } + } + }; + return WasmDisassembler; +}()); +exports.WasmDisassembler = WasmDisassembler; +var UNKNOWN_FUNCTION_PREFIX = "unknown"; +var NameSectionNameResolver = /** @class */ (function (_super) { + __extends(NameSectionNameResolver, _super); + function NameSectionNameResolver(functionNames, localNames, tagNames, typeNames, tableNames, memoryNames, globalNames, fieldNames) { + var _this = _super.call(this) || this; + _this._functionNames = functionNames; + _this._localNames = localNames; + _this._tagNames = tagNames; + _this._typeNames = typeNames; + _this._tableNames = tableNames; + _this._memoryNames = memoryNames; + _this._globalNames = globalNames; + _this._fieldNames = fieldNames; + return _this; + } + NameSectionNameResolver.prototype.getTypeName = function (index, isRef) { + var name = this._typeNames[index]; + if (!name) + return _super.prototype.getTypeName.call(this, index, isRef); + return isRef ? "$".concat(name) : "$".concat(name, " (;").concat(index, ";)"); + }; + NameSectionNameResolver.prototype.getTableName = function (index, isRef) { + var name = this._tableNames[index]; + if (!name) + return _super.prototype.getTableName.call(this, index, isRef); + return isRef ? "$".concat(name) : "$".concat(name, " (;").concat(index, ";)"); + }; + NameSectionNameResolver.prototype.getMemoryName = function (index, isRef) { + var name = this._memoryNames[index]; + if (!name) + return _super.prototype.getMemoryName.call(this, index, isRef); + return isRef ? "$".concat(name) : "$".concat(name, " (;").concat(index, ";)"); + }; + NameSectionNameResolver.prototype.getGlobalName = function (index, isRef) { + var name = this._globalNames[index]; + if (!name) + return _super.prototype.getGlobalName.call(this, index, isRef); + return isRef ? "$".concat(name) : "$".concat(name, " (;").concat(index, ";)"); + }; + NameSectionNameResolver.prototype.getTagName = function (index, isRef) { + var name = this._tagNames[index]; + if (!name) + return _super.prototype.getTagName.call(this, index, isRef); + return isRef ? "$".concat(name) : "$".concat(name, " (;").concat(index, ";)"); + }; + NameSectionNameResolver.prototype.getFunctionName = function (index, isImport, isRef) { + var name = this._functionNames[index]; + if (!name) + return "$".concat(UNKNOWN_FUNCTION_PREFIX).concat(index); + return isRef ? "$".concat(name) : "$".concat(name, " (;").concat(index, ";)"); + }; + NameSectionNameResolver.prototype.getVariableName = function (funcIndex, index, isRef) { + var name = this._localNames[funcIndex] && this._localNames[funcIndex][index]; + if (!name) + return _super.prototype.getVariableName.call(this, funcIndex, index, isRef); + return isRef ? "$".concat(name) : "$".concat(name, " (;").concat(index, ";)"); + }; + NameSectionNameResolver.prototype.getFieldName = function (typeIndex, index, isRef) { + var name = this._fieldNames[typeIndex] && this._fieldNames[typeIndex][index]; + if (!name) + return _super.prototype.getFieldName.call(this, typeIndex, index, isRef); + return isRef ? "$".concat(name) : "$".concat(name, " (;").concat(index, ";)"); + }; + return NameSectionNameResolver; +}(DefaultNameResolver)); +var NameSectionReader = /** @class */ (function () { + function NameSectionReader() { + this._done = false; + this._functionsCount = 0; + this._functionImportsCount = 0; + this._functionNames = null; + this._functionLocalNames = null; + this._tagNames = null; + this._typeNames = null; + this._tableNames = null; + this._memoryNames = null; + this._globalNames = null; + this._fieldNames = null; + this._hasNames = false; + } + NameSectionReader.prototype.read = function (reader) { + var _this = this; + if (this._done) + throw new Error("Invalid state: disassembly process was already finished."); + while (true) { + if (!reader.read()) + return false; + switch (reader.state) { + case 2 /* BinaryReaderState.END_WASM */: + if (!reader.hasMoreBytes()) { + this._done = true; + return true; + } + break; + case -1 /* BinaryReaderState.ERROR */: + throw reader.error; + case 1 /* BinaryReaderState.BEGIN_WASM */: + this._functionsCount = 0; + this._functionImportsCount = 0; + this._functionNames = []; + this._functionLocalNames = []; + this._tagNames = []; + this._typeNames = []; + this._tableNames = []; + this._memoryNames = []; + this._globalNames = []; + this._fieldNames = []; + this._hasNames = false; + break; + case 4 /* BinaryReaderState.END_SECTION */: + break; + case 3 /* BinaryReaderState.BEGIN_SECTION */: + var sectionInfo = reader.result; + if (sectionInfo.id === 0 /* SectionCode.Custom */ && + (0, WasmParser_js_1.bytesToString)(sectionInfo.name) === NAME_SECTION_NAME) { + break; + } + if (sectionInfo.id === 3 /* SectionCode.Function */ || + sectionInfo.id === 2 /* SectionCode.Import */) { + break; + } + reader.skipSection(); + break; + case 12 /* BinaryReaderState.IMPORT_SECTION_ENTRY */: + var importInfo = reader.result; + if (importInfo.kind === 0 /* ExternalKind.Function */) + this._functionImportsCount++; + break; + case 13 /* BinaryReaderState.FUNCTION_SECTION_ENTRY */: + this._functionsCount++; + break; + case 19 /* BinaryReaderState.NAME_SECTION_ENTRY */: + var nameInfo = reader.result; + if (nameInfo.type === 1 /* NameType.Function */) { + var names = nameInfo.names; + names.forEach(function (_a) { + var index = _a.index, name = _a.name; + _this._functionNames[index] = (0, WasmParser_js_1.bytesToString)(name); + }); + this._hasNames = true; + } + else if (nameInfo.type === 2 /* NameType.Local */) { + var funcs = nameInfo.funcs; + funcs.forEach(function (_a) { + var index = _a.index, locals = _a.locals; + var localNames = (_this._functionLocalNames[index] = []); + locals.forEach(function (_a) { + var index = _a.index, name = _a.name; + localNames[index] = (0, WasmParser_js_1.bytesToString)(name); + }); + }); + this._hasNames = true; + } + else if (nameInfo.type === 11 /* NameType.Tag */) { + var names = nameInfo.names; + names.forEach(function (_a) { + var index = _a.index, name = _a.name; + _this._tagNames[index] = (0, WasmParser_js_1.bytesToString)(name); + }); + this._hasNames = true; + } + else if (nameInfo.type === 4 /* NameType.Type */) { + var names = nameInfo.names; + names.forEach(function (_a) { + var index = _a.index, name = _a.name; + _this._typeNames[index] = (0, WasmParser_js_1.bytesToString)(name); + }); + this._hasNames = true; + } + else if (nameInfo.type === 5 /* NameType.Table */) { + var names = nameInfo.names; + names.forEach(function (_a) { + var index = _a.index, name = _a.name; + _this._tableNames[index] = (0, WasmParser_js_1.bytesToString)(name); + }); + this._hasNames = true; + } + else if (nameInfo.type === 6 /* NameType.Memory */) { + var names = nameInfo.names; + names.forEach(function (_a) { + var index = _a.index, name = _a.name; + _this._memoryNames[index] = (0, WasmParser_js_1.bytesToString)(name); + }); + this._hasNames = true; + } + else if (nameInfo.type === 7 /* NameType.Global */) { + var names = nameInfo.names; + names.forEach(function (_a) { + var index = _a.index, name = _a.name; + _this._globalNames[index] = (0, WasmParser_js_1.bytesToString)(name); + }); + this._hasNames = true; + } + else if (nameInfo.type === 10 /* NameType.Field */) { + var types = nameInfo.types; + types.forEach(function (_a) { + var index = _a.index, fields = _a.fields; + var fieldNames = (_this._fieldNames[index] = []); + fields.forEach(function (_a) { + var index = _a.index, name = _a.name; + fieldNames[index] = (0, WasmParser_js_1.bytesToString)(name); + }); + }); + } + break; + default: + throw new Error("Expectected state: ".concat(reader.state)); + } + } + }; + NameSectionReader.prototype.hasValidNames = function () { + return this._hasNames; + }; + NameSectionReader.prototype.getNameResolver = function () { + if (!this.hasValidNames()) + throw new Error("Has no valid name section"); + // Fix bad names. + var functionNamesLength = this._functionImportsCount + this._functionsCount; + var functionNames = this._functionNames.slice(0, functionNamesLength); + var usedNameAt = Object.create(null); + for (var i = 0; i < functionNames.length; i++) { + var name_1 = functionNames[i]; + if (!name_1) + continue; + var goodName = !(name_1 in usedNameAt) && + isValidName(name_1) && + name_1.indexOf(UNKNOWN_FUNCTION_PREFIX) !== 0; + if (!goodName) { + if (usedNameAt[name_1] >= 0) { + // Remove all non-unique names. + functionNames[usedNameAt[name_1]] = null; + usedNameAt[name_1] = -1; + } + functionNames[i] = null; + continue; + } + usedNameAt[name_1] = i; + } + return new NameSectionNameResolver(functionNames, this._functionLocalNames, this._tagNames, this._typeNames, this._tableNames, this._memoryNames, this._globalNames, this._fieldNames); + }; + return NameSectionReader; +}()); +exports.NameSectionReader = NameSectionReader; +var DevToolsNameResolver = /** @class */ (function (_super) { + __extends(DevToolsNameResolver, _super); + function DevToolsNameResolver(functionNames, localNames, tagNames, typeNames, tableNames, memoryNames, globalNames, fieldNames) { + return _super.call(this, functionNames, localNames, tagNames, typeNames, tableNames, memoryNames, globalNames, fieldNames) || this; + } + DevToolsNameResolver.prototype.getFunctionName = function (index, isImport, isRef) { + var name = this._functionNames[index]; + if (!name) + return isImport ? "$import".concat(index) : "$func".concat(index); + return isRef ? "$".concat(name) : "$".concat(name, " (;").concat(index, ";)"); + }; + return DevToolsNameResolver; +}(NameSectionNameResolver)); +exports.DevToolsNameResolver = DevToolsNameResolver; +var DevToolsNameGenerator = /** @class */ (function () { + function DevToolsNameGenerator() { + this._done = false; + this._functionImportsCount = 0; + this._memoryImportsCount = 0; + this._tableImportsCount = 0; + this._globalImportsCount = 0; + this._tagImportsCount = 0; + this._functionNames = null; + this._functionLocalNames = null; + this._tagNames = null; + this._memoryNames = null; + this._typeNames = null; + this._tableNames = null; + this._globalNames = null; + this._fieldNames = null; + this._functionExportNames = null; + this._globalExportNames = null; + this._memoryExportNames = null; + this._tableExportNames = null; + this._tagExportNames = null; + } + DevToolsNameGenerator.prototype._addExportName = function (exportNames, index, name) { + var names = exportNames[index]; + if (names) { + names.push(name); + } + else { + exportNames[index] = [name]; + } + }; + DevToolsNameGenerator.prototype._setName = function (names, index, name, isNameSectionName) { + if (!name) + return; + if (isNameSectionName) { + if (!isValidName(name)) + return; + names[index] = name; + } + else if (!names[index]) { + names[index] = name.replace(INVALID_NAME_SYMBOLS_REGEX_GLOBAL, "_"); + } + }; + DevToolsNameGenerator.prototype.read = function (reader) { + var _this = this; + if (this._done) + throw new Error("Invalid state: disassembly process was already finished."); + while (true) { + if (!reader.read()) + return false; + switch (reader.state) { + case 2 /* BinaryReaderState.END_WASM */: + if (!reader.hasMoreBytes()) { + this._done = true; + return true; + } + break; + case -1 /* BinaryReaderState.ERROR */: + throw reader.error; + case 1 /* BinaryReaderState.BEGIN_WASM */: + this._functionImportsCount = 0; + this._memoryImportsCount = 0; + this._tableImportsCount = 0; + this._globalImportsCount = 0; + this._tagImportsCount = 0; + this._functionNames = []; + this._functionLocalNames = []; + this._tagNames = []; + this._memoryNames = []; + this._typeNames = []; + this._tableNames = []; + this._globalNames = []; + this._fieldNames = []; + this._functionExportNames = []; + this._globalExportNames = []; + this._memoryExportNames = []; + this._tableExportNames = []; + this._tagExportNames = []; + break; + case 4 /* BinaryReaderState.END_SECTION */: + break; + case 3 /* BinaryReaderState.BEGIN_SECTION */: + var sectionInfo = reader.result; + if (sectionInfo.id === 0 /* SectionCode.Custom */ && + (0, WasmParser_js_1.bytesToString)(sectionInfo.name) === NAME_SECTION_NAME) { + break; + } + switch (sectionInfo.id) { + case 2 /* SectionCode.Import */: + case 7 /* SectionCode.Export */: + break; // reading known section; + default: + reader.skipSection(); + break; + } + break; + case 12 /* BinaryReaderState.IMPORT_SECTION_ENTRY */: + var importInfo = reader.result; + var importName = "".concat((0, WasmParser_js_1.bytesToString)(importInfo.module), ".").concat((0, WasmParser_js_1.bytesToString)(importInfo.field)); + switch (importInfo.kind) { + case 0 /* ExternalKind.Function */: + this._setName(this._functionNames, this._functionImportsCount++, importName, false); + break; + case 1 /* ExternalKind.Table */: + this._setName(this._tableNames, this._tableImportsCount++, importName, false); + break; + case 2 /* ExternalKind.Memory */: + this._setName(this._memoryNames, this._memoryImportsCount++, importName, false); + break; + case 3 /* ExternalKind.Global */: + this._setName(this._globalNames, this._globalImportsCount++, importName, false); + break; + case 4 /* ExternalKind.Tag */: + this._setName(this._tagNames, this._tagImportsCount++, importName, false); + default: + throw new Error("Unsupported export ".concat(importInfo.kind)); + } + break; + case 19 /* BinaryReaderState.NAME_SECTION_ENTRY */: + var nameInfo = reader.result; + if (nameInfo.type === 1 /* NameType.Function */) { + var names = nameInfo.names; + names.forEach(function (_a) { + var index = _a.index, name = _a.name; + _this._setName(_this._functionNames, index, (0, WasmParser_js_1.bytesToString)(name), true); + }); + } + else if (nameInfo.type === 2 /* NameType.Local */) { + var funcs = nameInfo.funcs; + funcs.forEach(function (_a) { + var index = _a.index, locals = _a.locals; + var localNames = (_this._functionLocalNames[index] = []); + locals.forEach(function (_a) { + var index = _a.index, name = _a.name; + localNames[index] = (0, WasmParser_js_1.bytesToString)(name); + }); + }); + } + else if (nameInfo.type === 11 /* NameType.Tag */) { + var names = nameInfo.names; + names.forEach(function (_a) { + var index = _a.index, name = _a.name; + _this._setName(_this._tagNames, index, (0, WasmParser_js_1.bytesToString)(name), true); + }); + } + else if (nameInfo.type === 4 /* NameType.Type */) { + var names = nameInfo.names; + names.forEach(function (_a) { + var index = _a.index, name = _a.name; + _this._setName(_this._typeNames, index, (0, WasmParser_js_1.bytesToString)(name), true); + }); + } + else if (nameInfo.type === 5 /* NameType.Table */) { + var names = nameInfo.names; + names.forEach(function (_a) { + var index = _a.index, name = _a.name; + _this._setName(_this._tableNames, index, (0, WasmParser_js_1.bytesToString)(name), true); + }); + } + else if (nameInfo.type === 6 /* NameType.Memory */) { + var names = nameInfo.names; + names.forEach(function (_a) { + var index = _a.index, name = _a.name; + _this._setName(_this._memoryNames, index, (0, WasmParser_js_1.bytesToString)(name), true); + }); + } + else if (nameInfo.type === 7 /* NameType.Global */) { + var names = nameInfo.names; + names.forEach(function (_a) { + var index = _a.index, name = _a.name; + _this._setName(_this._globalNames, index, (0, WasmParser_js_1.bytesToString)(name), true); + }); + } + else if (nameInfo.type === 10 /* NameType.Field */) { + var types = nameInfo.types; + types.forEach(function (_a) { + var index = _a.index, fields = _a.fields; + var fieldNames = (_this._fieldNames[index] = []); + fields.forEach(function (_a) { + var index = _a.index, name = _a.name; + fieldNames[index] = (0, WasmParser_js_1.bytesToString)(name); + }); + }); + } + break; + case 17 /* BinaryReaderState.EXPORT_SECTION_ENTRY */: + var exportInfo = reader.result; + var exportName = (0, WasmParser_js_1.bytesToString)(exportInfo.field); + switch (exportInfo.kind) { + case 0 /* ExternalKind.Function */: + this._addExportName(this._functionExportNames, exportInfo.index, exportName); + this._setName(this._functionNames, exportInfo.index, exportName, false); + break; + case 3 /* ExternalKind.Global */: + this._addExportName(this._globalExportNames, exportInfo.index, exportName); + this._setName(this._globalNames, exportInfo.index, exportName, false); + break; + case 2 /* ExternalKind.Memory */: + this._addExportName(this._memoryExportNames, exportInfo.index, exportName); + this._setName(this._memoryNames, exportInfo.index, exportName, false); + break; + case 1 /* ExternalKind.Table */: + this._addExportName(this._tableExportNames, exportInfo.index, exportName); + this._setName(this._tableNames, exportInfo.index, exportName, false); + break; + case 4 /* ExternalKind.Tag */: + this._addExportName(this._tagExportNames, exportInfo.index, exportName); + this._setName(this._tagNames, exportInfo.index, exportName, false); + break; + default: + throw new Error("Unsupported export ".concat(exportInfo.kind)); + } + break; + default: + throw new Error("Expectected state: ".concat(reader.state)); + } + } + }; + DevToolsNameGenerator.prototype.getExportMetadata = function () { + return new DevToolsExportMetadata(this._functionExportNames, this._globalExportNames, this._memoryExportNames, this._tableExportNames, this._tagExportNames); + }; + DevToolsNameGenerator.prototype.getNameResolver = function () { + return new DevToolsNameResolver(this._functionNames, this._functionLocalNames, this._tagNames, this._typeNames, this._tableNames, this._memoryNames, this._globalNames, this._fieldNames); + }; + return DevToolsNameGenerator; +}()); +exports.DevToolsNameGenerator = DevToolsNameGenerator; diff --git a/devtools/client/shared/vendor/WasmParser.js b/devtools/client/shared/vendor/WasmParser.js new file mode 100644 index 0000000000..05b80c25e8 --- /dev/null +++ b/devtools/client/shared/vendor/WasmParser.js @@ -0,0 +1,3883 @@ +"use strict"; +/* Copyright 2016 Mozilla Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +Object.defineProperty(exports, "__esModule", { value: true }); +exports.bytesToString = exports.BinaryReader = exports.Int64 = exports.TagAttribute = exports.ElementMode = exports.DataMode = exports.BinaryReaderState = exports.NameType = exports.LinkingType = exports.RelocType = exports.RefType = exports.Type = exports.FuncDef = exports.FieldDef = exports.TypeKind = exports.ExternalKind = exports.OperatorCodeNames = exports.OperatorCode = exports.SectionCode = void 0; +// See https://github.com/WebAssembly/design/blob/master/BinaryEncoding.md +var WASM_MAGIC_NUMBER = 0x6d736100; +var WASM_SUPPORTED_EXPERIMENTAL_VERSION = 0xd; +var WASM_SUPPORTED_VERSION = 0x1; +var SectionCode; +(function (SectionCode) { + SectionCode[SectionCode["Unknown"] = -1] = "Unknown"; + SectionCode[SectionCode["Custom"] = 0] = "Custom"; + SectionCode[SectionCode["Type"] = 1] = "Type"; + SectionCode[SectionCode["Import"] = 2] = "Import"; + SectionCode[SectionCode["Function"] = 3] = "Function"; + SectionCode[SectionCode["Table"] = 4] = "Table"; + SectionCode[SectionCode["Memory"] = 5] = "Memory"; + SectionCode[SectionCode["Global"] = 6] = "Global"; + SectionCode[SectionCode["Export"] = 7] = "Export"; + SectionCode[SectionCode["Start"] = 8] = "Start"; + SectionCode[SectionCode["Element"] = 9] = "Element"; + SectionCode[SectionCode["Code"] = 10] = "Code"; + SectionCode[SectionCode["Data"] = 11] = "Data"; + SectionCode[SectionCode["DataCount"] = 12] = "DataCount"; + SectionCode[SectionCode["Tag"] = 13] = "Tag"; +})(SectionCode = exports.SectionCode || (exports.SectionCode = {})); +var OperatorCode; +(function (OperatorCode) { + OperatorCode[OperatorCode["unreachable"] = 0] = "unreachable"; + OperatorCode[OperatorCode["nop"] = 1] = "nop"; + OperatorCode[OperatorCode["block"] = 2] = "block"; + OperatorCode[OperatorCode["loop"] = 3] = "loop"; + OperatorCode[OperatorCode["if"] = 4] = "if"; + OperatorCode[OperatorCode["else"] = 5] = "else"; + OperatorCode[OperatorCode["try"] = 6] = "try"; + OperatorCode[OperatorCode["catch"] = 7] = "catch"; + OperatorCode[OperatorCode["throw"] = 8] = "throw"; + OperatorCode[OperatorCode["rethrow"] = 9] = "rethrow"; + OperatorCode[OperatorCode["unwind"] = 10] = "unwind"; + OperatorCode[OperatorCode["end"] = 11] = "end"; + OperatorCode[OperatorCode["br"] = 12] = "br"; + OperatorCode[OperatorCode["br_if"] = 13] = "br_if"; + OperatorCode[OperatorCode["br_table"] = 14] = "br_table"; + OperatorCode[OperatorCode["return"] = 15] = "return"; + OperatorCode[OperatorCode["call"] = 16] = "call"; + OperatorCode[OperatorCode["call_indirect"] = 17] = "call_indirect"; + OperatorCode[OperatorCode["return_call"] = 18] = "return_call"; + OperatorCode[OperatorCode["return_call_indirect"] = 19] = "return_call_indirect"; + OperatorCode[OperatorCode["call_ref"] = 20] = "call_ref"; + OperatorCode[OperatorCode["return_call_ref"] = 21] = "return_call_ref"; + OperatorCode[OperatorCode["let"] = 23] = "let"; + OperatorCode[OperatorCode["delegate"] = 24] = "delegate"; + OperatorCode[OperatorCode["catch_all"] = 25] = "catch_all"; + OperatorCode[OperatorCode["drop"] = 26] = "drop"; + OperatorCode[OperatorCode["select"] = 27] = "select"; + OperatorCode[OperatorCode["select_with_type"] = 28] = "select_with_type"; + OperatorCode[OperatorCode["local_get"] = 32] = "local_get"; + OperatorCode[OperatorCode["local_set"] = 33] = "local_set"; + OperatorCode[OperatorCode["local_tee"] = 34] = "local_tee"; + OperatorCode[OperatorCode["global_get"] = 35] = "global_get"; + OperatorCode[OperatorCode["global_set"] = 36] = "global_set"; + OperatorCode[OperatorCode["i32_load"] = 40] = "i32_load"; + OperatorCode[OperatorCode["i64_load"] = 41] = "i64_load"; + OperatorCode[OperatorCode["f32_load"] = 42] = "f32_load"; + OperatorCode[OperatorCode["f64_load"] = 43] = "f64_load"; + OperatorCode[OperatorCode["i32_load8_s"] = 44] = "i32_load8_s"; + OperatorCode[OperatorCode["i32_load8_u"] = 45] = "i32_load8_u"; + OperatorCode[OperatorCode["i32_load16_s"] = 46] = "i32_load16_s"; + OperatorCode[OperatorCode["i32_load16_u"] = 47] = "i32_load16_u"; + OperatorCode[OperatorCode["i64_load8_s"] = 48] = "i64_load8_s"; + OperatorCode[OperatorCode["i64_load8_u"] = 49] = "i64_load8_u"; + OperatorCode[OperatorCode["i64_load16_s"] = 50] = "i64_load16_s"; + OperatorCode[OperatorCode["i64_load16_u"] = 51] = "i64_load16_u"; + OperatorCode[OperatorCode["i64_load32_s"] = 52] = "i64_load32_s"; + OperatorCode[OperatorCode["i64_load32_u"] = 53] = "i64_load32_u"; + OperatorCode[OperatorCode["i32_store"] = 54] = "i32_store"; + OperatorCode[OperatorCode["i64_store"] = 55] = "i64_store"; + OperatorCode[OperatorCode["f32_store"] = 56] = "f32_store"; + OperatorCode[OperatorCode["f64_store"] = 57] = "f64_store"; + OperatorCode[OperatorCode["i32_store8"] = 58] = "i32_store8"; + OperatorCode[OperatorCode["i32_store16"] = 59] = "i32_store16"; + OperatorCode[OperatorCode["i64_store8"] = 60] = "i64_store8"; + OperatorCode[OperatorCode["i64_store16"] = 61] = "i64_store16"; + OperatorCode[OperatorCode["i64_store32"] = 62] = "i64_store32"; + OperatorCode[OperatorCode["memory_size"] = 63] = "memory_size"; + OperatorCode[OperatorCode["memory_grow"] = 64] = "memory_grow"; + OperatorCode[OperatorCode["i32_const"] = 65] = "i32_const"; + OperatorCode[OperatorCode["i64_const"] = 66] = "i64_const"; + OperatorCode[OperatorCode["f32_const"] = 67] = "f32_const"; + OperatorCode[OperatorCode["f64_const"] = 68] = "f64_const"; + OperatorCode[OperatorCode["i32_eqz"] = 69] = "i32_eqz"; + OperatorCode[OperatorCode["i32_eq"] = 70] = "i32_eq"; + OperatorCode[OperatorCode["i32_ne"] = 71] = "i32_ne"; + OperatorCode[OperatorCode["i32_lt_s"] = 72] = "i32_lt_s"; + OperatorCode[OperatorCode["i32_lt_u"] = 73] = "i32_lt_u"; + OperatorCode[OperatorCode["i32_gt_s"] = 74] = "i32_gt_s"; + OperatorCode[OperatorCode["i32_gt_u"] = 75] = "i32_gt_u"; + OperatorCode[OperatorCode["i32_le_s"] = 76] = "i32_le_s"; + OperatorCode[OperatorCode["i32_le_u"] = 77] = "i32_le_u"; + OperatorCode[OperatorCode["i32_ge_s"] = 78] = "i32_ge_s"; + OperatorCode[OperatorCode["i32_ge_u"] = 79] = "i32_ge_u"; + OperatorCode[OperatorCode["i64_eqz"] = 80] = "i64_eqz"; + OperatorCode[OperatorCode["i64_eq"] = 81] = "i64_eq"; + OperatorCode[OperatorCode["i64_ne"] = 82] = "i64_ne"; + OperatorCode[OperatorCode["i64_lt_s"] = 83] = "i64_lt_s"; + OperatorCode[OperatorCode["i64_lt_u"] = 84] = "i64_lt_u"; + OperatorCode[OperatorCode["i64_gt_s"] = 85] = "i64_gt_s"; + OperatorCode[OperatorCode["i64_gt_u"] = 86] = "i64_gt_u"; + OperatorCode[OperatorCode["i64_le_s"] = 87] = "i64_le_s"; + OperatorCode[OperatorCode["i64_le_u"] = 88] = "i64_le_u"; + OperatorCode[OperatorCode["i64_ge_s"] = 89] = "i64_ge_s"; + OperatorCode[OperatorCode["i64_ge_u"] = 90] = "i64_ge_u"; + OperatorCode[OperatorCode["f32_eq"] = 91] = "f32_eq"; + OperatorCode[OperatorCode["f32_ne"] = 92] = "f32_ne"; + OperatorCode[OperatorCode["f32_lt"] = 93] = "f32_lt"; + OperatorCode[OperatorCode["f32_gt"] = 94] = "f32_gt"; + OperatorCode[OperatorCode["f32_le"] = 95] = "f32_le"; + OperatorCode[OperatorCode["f32_ge"] = 96] = "f32_ge"; + OperatorCode[OperatorCode["f64_eq"] = 97] = "f64_eq"; + OperatorCode[OperatorCode["f64_ne"] = 98] = "f64_ne"; + OperatorCode[OperatorCode["f64_lt"] = 99] = "f64_lt"; + OperatorCode[OperatorCode["f64_gt"] = 100] = "f64_gt"; + OperatorCode[OperatorCode["f64_le"] = 101] = "f64_le"; + OperatorCode[OperatorCode["f64_ge"] = 102] = "f64_ge"; + OperatorCode[OperatorCode["i32_clz"] = 103] = "i32_clz"; + OperatorCode[OperatorCode["i32_ctz"] = 104] = "i32_ctz"; + OperatorCode[OperatorCode["i32_popcnt"] = 105] = "i32_popcnt"; + OperatorCode[OperatorCode["i32_add"] = 106] = "i32_add"; + OperatorCode[OperatorCode["i32_sub"] = 107] = "i32_sub"; + OperatorCode[OperatorCode["i32_mul"] = 108] = "i32_mul"; + OperatorCode[OperatorCode["i32_div_s"] = 109] = "i32_div_s"; + OperatorCode[OperatorCode["i32_div_u"] = 110] = "i32_div_u"; + OperatorCode[OperatorCode["i32_rem_s"] = 111] = "i32_rem_s"; + OperatorCode[OperatorCode["i32_rem_u"] = 112] = "i32_rem_u"; + OperatorCode[OperatorCode["i32_and"] = 113] = "i32_and"; + OperatorCode[OperatorCode["i32_or"] = 114] = "i32_or"; + OperatorCode[OperatorCode["i32_xor"] = 115] = "i32_xor"; + OperatorCode[OperatorCode["i32_shl"] = 116] = "i32_shl"; + OperatorCode[OperatorCode["i32_shr_s"] = 117] = "i32_shr_s"; + OperatorCode[OperatorCode["i32_shr_u"] = 118] = "i32_shr_u"; + OperatorCode[OperatorCode["i32_rotl"] = 119] = "i32_rotl"; + OperatorCode[OperatorCode["i32_rotr"] = 120] = "i32_rotr"; + OperatorCode[OperatorCode["i64_clz"] = 121] = "i64_clz"; + OperatorCode[OperatorCode["i64_ctz"] = 122] = "i64_ctz"; + OperatorCode[OperatorCode["i64_popcnt"] = 123] = "i64_popcnt"; + OperatorCode[OperatorCode["i64_add"] = 124] = "i64_add"; + OperatorCode[OperatorCode["i64_sub"] = 125] = "i64_sub"; + OperatorCode[OperatorCode["i64_mul"] = 126] = "i64_mul"; + OperatorCode[OperatorCode["i64_div_s"] = 127] = "i64_div_s"; + OperatorCode[OperatorCode["i64_div_u"] = 128] = "i64_div_u"; + OperatorCode[OperatorCode["i64_rem_s"] = 129] = "i64_rem_s"; + OperatorCode[OperatorCode["i64_rem_u"] = 130] = "i64_rem_u"; + OperatorCode[OperatorCode["i64_and"] = 131] = "i64_and"; + OperatorCode[OperatorCode["i64_or"] = 132] = "i64_or"; + OperatorCode[OperatorCode["i64_xor"] = 133] = "i64_xor"; + OperatorCode[OperatorCode["i64_shl"] = 134] = "i64_shl"; + OperatorCode[OperatorCode["i64_shr_s"] = 135] = "i64_shr_s"; + OperatorCode[OperatorCode["i64_shr_u"] = 136] = "i64_shr_u"; + OperatorCode[OperatorCode["i64_rotl"] = 137] = "i64_rotl"; + OperatorCode[OperatorCode["i64_rotr"] = 138] = "i64_rotr"; + OperatorCode[OperatorCode["f32_abs"] = 139] = "f32_abs"; + OperatorCode[OperatorCode["f32_neg"] = 140] = "f32_neg"; + OperatorCode[OperatorCode["f32_ceil"] = 141] = "f32_ceil"; + OperatorCode[OperatorCode["f32_floor"] = 142] = "f32_floor"; + OperatorCode[OperatorCode["f32_trunc"] = 143] = "f32_trunc"; + OperatorCode[OperatorCode["f32_nearest"] = 144] = "f32_nearest"; + OperatorCode[OperatorCode["f32_sqrt"] = 145] = "f32_sqrt"; + OperatorCode[OperatorCode["f32_add"] = 146] = "f32_add"; + OperatorCode[OperatorCode["f32_sub"] = 147] = "f32_sub"; + OperatorCode[OperatorCode["f32_mul"] = 148] = "f32_mul"; + OperatorCode[OperatorCode["f32_div"] = 149] = "f32_div"; + OperatorCode[OperatorCode["f32_min"] = 150] = "f32_min"; + OperatorCode[OperatorCode["f32_max"] = 151] = "f32_max"; + OperatorCode[OperatorCode["f32_copysign"] = 152] = "f32_copysign"; + OperatorCode[OperatorCode["f64_abs"] = 153] = "f64_abs"; + OperatorCode[OperatorCode["f64_neg"] = 154] = "f64_neg"; + OperatorCode[OperatorCode["f64_ceil"] = 155] = "f64_ceil"; + OperatorCode[OperatorCode["f64_floor"] = 156] = "f64_floor"; + OperatorCode[OperatorCode["f64_trunc"] = 157] = "f64_trunc"; + OperatorCode[OperatorCode["f64_nearest"] = 158] = "f64_nearest"; + OperatorCode[OperatorCode["f64_sqrt"] = 159] = "f64_sqrt"; + OperatorCode[OperatorCode["f64_add"] = 160] = "f64_add"; + OperatorCode[OperatorCode["f64_sub"] = 161] = "f64_sub"; + OperatorCode[OperatorCode["f64_mul"] = 162] = "f64_mul"; + OperatorCode[OperatorCode["f64_div"] = 163] = "f64_div"; + OperatorCode[OperatorCode["f64_min"] = 164] = "f64_min"; + OperatorCode[OperatorCode["f64_max"] = 165] = "f64_max"; + OperatorCode[OperatorCode["f64_copysign"] = 166] = "f64_copysign"; + OperatorCode[OperatorCode["i32_wrap_i64"] = 167] = "i32_wrap_i64"; + OperatorCode[OperatorCode["i32_trunc_f32_s"] = 168] = "i32_trunc_f32_s"; + OperatorCode[OperatorCode["i32_trunc_f32_u"] = 169] = "i32_trunc_f32_u"; + OperatorCode[OperatorCode["i32_trunc_f64_s"] = 170] = "i32_trunc_f64_s"; + OperatorCode[OperatorCode["i32_trunc_f64_u"] = 171] = "i32_trunc_f64_u"; + OperatorCode[OperatorCode["i64_extend_i32_s"] = 172] = "i64_extend_i32_s"; + OperatorCode[OperatorCode["i64_extend_i32_u"] = 173] = "i64_extend_i32_u"; + OperatorCode[OperatorCode["i64_trunc_f32_s"] = 174] = "i64_trunc_f32_s"; + OperatorCode[OperatorCode["i64_trunc_f32_u"] = 175] = "i64_trunc_f32_u"; + OperatorCode[OperatorCode["i64_trunc_f64_s"] = 176] = "i64_trunc_f64_s"; + OperatorCode[OperatorCode["i64_trunc_f64_u"] = 177] = "i64_trunc_f64_u"; + OperatorCode[OperatorCode["f32_convert_i32_s"] = 178] = "f32_convert_i32_s"; + OperatorCode[OperatorCode["f32_convert_i32_u"] = 179] = "f32_convert_i32_u"; + OperatorCode[OperatorCode["f32_convert_i64_s"] = 180] = "f32_convert_i64_s"; + OperatorCode[OperatorCode["f32_convert_i64_u"] = 181] = "f32_convert_i64_u"; + OperatorCode[OperatorCode["f32_demote_f64"] = 182] = "f32_demote_f64"; + OperatorCode[OperatorCode["f64_convert_i32_s"] = 183] = "f64_convert_i32_s"; + OperatorCode[OperatorCode["f64_convert_i32_u"] = 184] = "f64_convert_i32_u"; + OperatorCode[OperatorCode["f64_convert_i64_s"] = 185] = "f64_convert_i64_s"; + OperatorCode[OperatorCode["f64_convert_i64_u"] = 186] = "f64_convert_i64_u"; + OperatorCode[OperatorCode["f64_promote_f32"] = 187] = "f64_promote_f32"; + OperatorCode[OperatorCode["i32_reinterpret_f32"] = 188] = "i32_reinterpret_f32"; + OperatorCode[OperatorCode["i64_reinterpret_f64"] = 189] = "i64_reinterpret_f64"; + OperatorCode[OperatorCode["f32_reinterpret_i32"] = 190] = "f32_reinterpret_i32"; + OperatorCode[OperatorCode["f64_reinterpret_i64"] = 191] = "f64_reinterpret_i64"; + OperatorCode[OperatorCode["i32_extend8_s"] = 192] = "i32_extend8_s"; + OperatorCode[OperatorCode["i32_extend16_s"] = 193] = "i32_extend16_s"; + OperatorCode[OperatorCode["i64_extend8_s"] = 194] = "i64_extend8_s"; + OperatorCode[OperatorCode["i64_extend16_s"] = 195] = "i64_extend16_s"; + OperatorCode[OperatorCode["i64_extend32_s"] = 196] = "i64_extend32_s"; + OperatorCode[OperatorCode["prefix_0xfb"] = 251] = "prefix_0xfb"; + OperatorCode[OperatorCode["prefix_0xfc"] = 252] = "prefix_0xfc"; + OperatorCode[OperatorCode["prefix_0xfd"] = 253] = "prefix_0xfd"; + OperatorCode[OperatorCode["prefix_0xfe"] = 254] = "prefix_0xfe"; + OperatorCode[OperatorCode["i32_trunc_sat_f32_s"] = 64512] = "i32_trunc_sat_f32_s"; + OperatorCode[OperatorCode["i32_trunc_sat_f32_u"] = 64513] = "i32_trunc_sat_f32_u"; + OperatorCode[OperatorCode["i32_trunc_sat_f64_s"] = 64514] = "i32_trunc_sat_f64_s"; + OperatorCode[OperatorCode["i32_trunc_sat_f64_u"] = 64515] = "i32_trunc_sat_f64_u"; + OperatorCode[OperatorCode["i64_trunc_sat_f32_s"] = 64516] = "i64_trunc_sat_f32_s"; + OperatorCode[OperatorCode["i64_trunc_sat_f32_u"] = 64517] = "i64_trunc_sat_f32_u"; + OperatorCode[OperatorCode["i64_trunc_sat_f64_s"] = 64518] = "i64_trunc_sat_f64_s"; + OperatorCode[OperatorCode["i64_trunc_sat_f64_u"] = 64519] = "i64_trunc_sat_f64_u"; + OperatorCode[OperatorCode["memory_init"] = 64520] = "memory_init"; + OperatorCode[OperatorCode["data_drop"] = 64521] = "data_drop"; + OperatorCode[OperatorCode["memory_copy"] = 64522] = "memory_copy"; + OperatorCode[OperatorCode["memory_fill"] = 64523] = "memory_fill"; + OperatorCode[OperatorCode["table_init"] = 64524] = "table_init"; + OperatorCode[OperatorCode["elem_drop"] = 64525] = "elem_drop"; + OperatorCode[OperatorCode["table_copy"] = 64526] = "table_copy"; + OperatorCode[OperatorCode["table_grow"] = 64527] = "table_grow"; + OperatorCode[OperatorCode["table_size"] = 64528] = "table_size"; + OperatorCode[OperatorCode["table_fill"] = 64529] = "table_fill"; + OperatorCode[OperatorCode["table_get"] = 37] = "table_get"; + OperatorCode[OperatorCode["table_set"] = 38] = "table_set"; + OperatorCode[OperatorCode["ref_null"] = 208] = "ref_null"; + OperatorCode[OperatorCode["ref_is_null"] = 209] = "ref_is_null"; + OperatorCode[OperatorCode["ref_func"] = 210] = "ref_func"; + OperatorCode[OperatorCode["ref_as_non_null"] = 211] = "ref_as_non_null"; + OperatorCode[OperatorCode["br_on_null"] = 212] = "br_on_null"; + OperatorCode[OperatorCode["ref_eq"] = 213] = "ref_eq"; + OperatorCode[OperatorCode["br_on_non_null"] = 214] = "br_on_non_null"; + OperatorCode[OperatorCode["memory_atomic_notify"] = 65024] = "memory_atomic_notify"; + OperatorCode[OperatorCode["memory_atomic_wait32"] = 65025] = "memory_atomic_wait32"; + OperatorCode[OperatorCode["memory_atomic_wait64"] = 65026] = "memory_atomic_wait64"; + OperatorCode[OperatorCode["atomic_fence"] = 65027] = "atomic_fence"; + OperatorCode[OperatorCode["i32_atomic_load"] = 65040] = "i32_atomic_load"; + OperatorCode[OperatorCode["i64_atomic_load"] = 65041] = "i64_atomic_load"; + OperatorCode[OperatorCode["i32_atomic_load8_u"] = 65042] = "i32_atomic_load8_u"; + OperatorCode[OperatorCode["i32_atomic_load16_u"] = 65043] = "i32_atomic_load16_u"; + OperatorCode[OperatorCode["i64_atomic_load8_u"] = 65044] = "i64_atomic_load8_u"; + OperatorCode[OperatorCode["i64_atomic_load16_u"] = 65045] = "i64_atomic_load16_u"; + OperatorCode[OperatorCode["i64_atomic_load32_u"] = 65046] = "i64_atomic_load32_u"; + OperatorCode[OperatorCode["i32_atomic_store"] = 65047] = "i32_atomic_store"; + OperatorCode[OperatorCode["i64_atomic_store"] = 65048] = "i64_atomic_store"; + OperatorCode[OperatorCode["i32_atomic_store8"] = 65049] = "i32_atomic_store8"; + OperatorCode[OperatorCode["i32_atomic_store16"] = 65050] = "i32_atomic_store16"; + OperatorCode[OperatorCode["i64_atomic_store8"] = 65051] = "i64_atomic_store8"; + OperatorCode[OperatorCode["i64_atomic_store16"] = 65052] = "i64_atomic_store16"; + OperatorCode[OperatorCode["i64_atomic_store32"] = 65053] = "i64_atomic_store32"; + OperatorCode[OperatorCode["i32_atomic_rmw_add"] = 65054] = "i32_atomic_rmw_add"; + OperatorCode[OperatorCode["i64_atomic_rmw_add"] = 65055] = "i64_atomic_rmw_add"; + OperatorCode[OperatorCode["i32_atomic_rmw8_add_u"] = 65056] = "i32_atomic_rmw8_add_u"; + OperatorCode[OperatorCode["i32_atomic_rmw16_add_u"] = 65057] = "i32_atomic_rmw16_add_u"; + OperatorCode[OperatorCode["i64_atomic_rmw8_add_u"] = 65058] = "i64_atomic_rmw8_add_u"; + OperatorCode[OperatorCode["i64_atomic_rmw16_add_u"] = 65059] = "i64_atomic_rmw16_add_u"; + OperatorCode[OperatorCode["i64_atomic_rmw32_add_u"] = 65060] = "i64_atomic_rmw32_add_u"; + OperatorCode[OperatorCode["i32_atomic_rmw_sub"] = 65061] = "i32_atomic_rmw_sub"; + OperatorCode[OperatorCode["i64_atomic_rmw_sub"] = 65062] = "i64_atomic_rmw_sub"; + OperatorCode[OperatorCode["i32_atomic_rmw8_sub_u"] = 65063] = "i32_atomic_rmw8_sub_u"; + OperatorCode[OperatorCode["i32_atomic_rmw16_sub_u"] = 65064] = "i32_atomic_rmw16_sub_u"; + OperatorCode[OperatorCode["i64_atomic_rmw8_sub_u"] = 65065] = "i64_atomic_rmw8_sub_u"; + OperatorCode[OperatorCode["i64_atomic_rmw16_sub_u"] = 65066] = "i64_atomic_rmw16_sub_u"; + OperatorCode[OperatorCode["i64_atomic_rmw32_sub_u"] = 65067] = "i64_atomic_rmw32_sub_u"; + OperatorCode[OperatorCode["i32_atomic_rmw_and"] = 65068] = "i32_atomic_rmw_and"; + OperatorCode[OperatorCode["i64_atomic_rmw_and"] = 65069] = "i64_atomic_rmw_and"; + OperatorCode[OperatorCode["i32_atomic_rmw8_and_u"] = 65070] = "i32_atomic_rmw8_and_u"; + OperatorCode[OperatorCode["i32_atomic_rmw16_and_u"] = 65071] = "i32_atomic_rmw16_and_u"; + OperatorCode[OperatorCode["i64_atomic_rmw8_and_u"] = 65072] = "i64_atomic_rmw8_and_u"; + OperatorCode[OperatorCode["i64_atomic_rmw16_and_u"] = 65073] = "i64_atomic_rmw16_and_u"; + OperatorCode[OperatorCode["i64_atomic_rmw32_and_u"] = 65074] = "i64_atomic_rmw32_and_u"; + OperatorCode[OperatorCode["i32_atomic_rmw_or"] = 65075] = "i32_atomic_rmw_or"; + OperatorCode[OperatorCode["i64_atomic_rmw_or"] = 65076] = "i64_atomic_rmw_or"; + OperatorCode[OperatorCode["i32_atomic_rmw8_or_u"] = 65077] = "i32_atomic_rmw8_or_u"; + OperatorCode[OperatorCode["i32_atomic_rmw16_or_u"] = 65078] = "i32_atomic_rmw16_or_u"; + OperatorCode[OperatorCode["i64_atomic_rmw8_or_u"] = 65079] = "i64_atomic_rmw8_or_u"; + OperatorCode[OperatorCode["i64_atomic_rmw16_or_u"] = 65080] = "i64_atomic_rmw16_or_u"; + OperatorCode[OperatorCode["i64_atomic_rmw32_or_u"] = 65081] = "i64_atomic_rmw32_or_u"; + OperatorCode[OperatorCode["i32_atomic_rmw_xor"] = 65082] = "i32_atomic_rmw_xor"; + OperatorCode[OperatorCode["i64_atomic_rmw_xor"] = 65083] = "i64_atomic_rmw_xor"; + OperatorCode[OperatorCode["i32_atomic_rmw8_xor_u"] = 65084] = "i32_atomic_rmw8_xor_u"; + OperatorCode[OperatorCode["i32_atomic_rmw16_xor_u"] = 65085] = "i32_atomic_rmw16_xor_u"; + OperatorCode[OperatorCode["i64_atomic_rmw8_xor_u"] = 65086] = "i64_atomic_rmw8_xor_u"; + OperatorCode[OperatorCode["i64_atomic_rmw16_xor_u"] = 65087] = "i64_atomic_rmw16_xor_u"; + OperatorCode[OperatorCode["i64_atomic_rmw32_xor_u"] = 65088] = "i64_atomic_rmw32_xor_u"; + OperatorCode[OperatorCode["i32_atomic_rmw_xchg"] = 65089] = "i32_atomic_rmw_xchg"; + OperatorCode[OperatorCode["i64_atomic_rmw_xchg"] = 65090] = "i64_atomic_rmw_xchg"; + OperatorCode[OperatorCode["i32_atomic_rmw8_xchg_u"] = 65091] = "i32_atomic_rmw8_xchg_u"; + OperatorCode[OperatorCode["i32_atomic_rmw16_xchg_u"] = 65092] = "i32_atomic_rmw16_xchg_u"; + OperatorCode[OperatorCode["i64_atomic_rmw8_xchg_u"] = 65093] = "i64_atomic_rmw8_xchg_u"; + OperatorCode[OperatorCode["i64_atomic_rmw16_xchg_u"] = 65094] = "i64_atomic_rmw16_xchg_u"; + OperatorCode[OperatorCode["i64_atomic_rmw32_xchg_u"] = 65095] = "i64_atomic_rmw32_xchg_u"; + OperatorCode[OperatorCode["i32_atomic_rmw_cmpxchg"] = 65096] = "i32_atomic_rmw_cmpxchg"; + OperatorCode[OperatorCode["i64_atomic_rmw_cmpxchg"] = 65097] = "i64_atomic_rmw_cmpxchg"; + OperatorCode[OperatorCode["i32_atomic_rmw8_cmpxchg_u"] = 65098] = "i32_atomic_rmw8_cmpxchg_u"; + OperatorCode[OperatorCode["i32_atomic_rmw16_cmpxchg_u"] = 65099] = "i32_atomic_rmw16_cmpxchg_u"; + OperatorCode[OperatorCode["i64_atomic_rmw8_cmpxchg_u"] = 65100] = "i64_atomic_rmw8_cmpxchg_u"; + OperatorCode[OperatorCode["i64_atomic_rmw16_cmpxchg_u"] = 65101] = "i64_atomic_rmw16_cmpxchg_u"; + OperatorCode[OperatorCode["i64_atomic_rmw32_cmpxchg_u"] = 65102] = "i64_atomic_rmw32_cmpxchg_u"; + OperatorCode[OperatorCode["v128_load"] = 64768] = "v128_load"; + OperatorCode[OperatorCode["i16x8_load8x8_s"] = 64769] = "i16x8_load8x8_s"; + OperatorCode[OperatorCode["i16x8_load8x8_u"] = 64770] = "i16x8_load8x8_u"; + OperatorCode[OperatorCode["i32x4_load16x4_s"] = 64771] = "i32x4_load16x4_s"; + OperatorCode[OperatorCode["i32x4_load16x4_u"] = 64772] = "i32x4_load16x4_u"; + OperatorCode[OperatorCode["i64x2_load32x2_s"] = 64773] = "i64x2_load32x2_s"; + OperatorCode[OperatorCode["i64x2_load32x2_u"] = 64774] = "i64x2_load32x2_u"; + OperatorCode[OperatorCode["v8x16_load_splat"] = 64775] = "v8x16_load_splat"; + OperatorCode[OperatorCode["v16x8_load_splat"] = 64776] = "v16x8_load_splat"; + OperatorCode[OperatorCode["v32x4_load_splat"] = 64777] = "v32x4_load_splat"; + OperatorCode[OperatorCode["v64x2_load_splat"] = 64778] = "v64x2_load_splat"; + OperatorCode[OperatorCode["v128_store"] = 64779] = "v128_store"; + OperatorCode[OperatorCode["v128_const"] = 64780] = "v128_const"; + OperatorCode[OperatorCode["i8x16_shuffle"] = 64781] = "i8x16_shuffle"; + OperatorCode[OperatorCode["i8x16_swizzle"] = 64782] = "i8x16_swizzle"; + OperatorCode[OperatorCode["i8x16_splat"] = 64783] = "i8x16_splat"; + OperatorCode[OperatorCode["i16x8_splat"] = 64784] = "i16x8_splat"; + OperatorCode[OperatorCode["i32x4_splat"] = 64785] = "i32x4_splat"; + OperatorCode[OperatorCode["i64x2_splat"] = 64786] = "i64x2_splat"; + OperatorCode[OperatorCode["f32x4_splat"] = 64787] = "f32x4_splat"; + OperatorCode[OperatorCode["f64x2_splat"] = 64788] = "f64x2_splat"; + OperatorCode[OperatorCode["i8x16_extract_lane_s"] = 64789] = "i8x16_extract_lane_s"; + OperatorCode[OperatorCode["i8x16_extract_lane_u"] = 64790] = "i8x16_extract_lane_u"; + OperatorCode[OperatorCode["i8x16_replace_lane"] = 64791] = "i8x16_replace_lane"; + OperatorCode[OperatorCode["i16x8_extract_lane_s"] = 64792] = "i16x8_extract_lane_s"; + OperatorCode[OperatorCode["i16x8_extract_lane_u"] = 64793] = "i16x8_extract_lane_u"; + OperatorCode[OperatorCode["i16x8_replace_lane"] = 64794] = "i16x8_replace_lane"; + OperatorCode[OperatorCode["i32x4_extract_lane"] = 64795] = "i32x4_extract_lane"; + OperatorCode[OperatorCode["i32x4_replace_lane"] = 64796] = "i32x4_replace_lane"; + OperatorCode[OperatorCode["i64x2_extract_lane"] = 64797] = "i64x2_extract_lane"; + OperatorCode[OperatorCode["i64x2_replace_lane"] = 64798] = "i64x2_replace_lane"; + OperatorCode[OperatorCode["f32x4_extract_lane"] = 64799] = "f32x4_extract_lane"; + OperatorCode[OperatorCode["f32x4_replace_lane"] = 64800] = "f32x4_replace_lane"; + OperatorCode[OperatorCode["f64x2_extract_lane"] = 64801] = "f64x2_extract_lane"; + OperatorCode[OperatorCode["f64x2_replace_lane"] = 64802] = "f64x2_replace_lane"; + OperatorCode[OperatorCode["i8x16_eq"] = 64803] = "i8x16_eq"; + OperatorCode[OperatorCode["i8x16_ne"] = 64804] = "i8x16_ne"; + OperatorCode[OperatorCode["i8x16_lt_s"] = 64805] = "i8x16_lt_s"; + OperatorCode[OperatorCode["i8x16_lt_u"] = 64806] = "i8x16_lt_u"; + OperatorCode[OperatorCode["i8x16_gt_s"] = 64807] = "i8x16_gt_s"; + OperatorCode[OperatorCode["i8x16_gt_u"] = 64808] = "i8x16_gt_u"; + OperatorCode[OperatorCode["i8x16_le_s"] = 64809] = "i8x16_le_s"; + OperatorCode[OperatorCode["i8x16_le_u"] = 64810] = "i8x16_le_u"; + OperatorCode[OperatorCode["i8x16_ge_s"] = 64811] = "i8x16_ge_s"; + OperatorCode[OperatorCode["i8x16_ge_u"] = 64812] = "i8x16_ge_u"; + OperatorCode[OperatorCode["i16x8_eq"] = 64813] = "i16x8_eq"; + OperatorCode[OperatorCode["i16x8_ne"] = 64814] = "i16x8_ne"; + OperatorCode[OperatorCode["i16x8_lt_s"] = 64815] = "i16x8_lt_s"; + OperatorCode[OperatorCode["i16x8_lt_u"] = 64816] = "i16x8_lt_u"; + OperatorCode[OperatorCode["i16x8_gt_s"] = 64817] = "i16x8_gt_s"; + OperatorCode[OperatorCode["i16x8_gt_u"] = 64818] = "i16x8_gt_u"; + OperatorCode[OperatorCode["i16x8_le_s"] = 64819] = "i16x8_le_s"; + OperatorCode[OperatorCode["i16x8_le_u"] = 64820] = "i16x8_le_u"; + OperatorCode[OperatorCode["i16x8_ge_s"] = 64821] = "i16x8_ge_s"; + OperatorCode[OperatorCode["i16x8_ge_u"] = 64822] = "i16x8_ge_u"; + OperatorCode[OperatorCode["i32x4_eq"] = 64823] = "i32x4_eq"; + OperatorCode[OperatorCode["i32x4_ne"] = 64824] = "i32x4_ne"; + OperatorCode[OperatorCode["i32x4_lt_s"] = 64825] = "i32x4_lt_s"; + OperatorCode[OperatorCode["i32x4_lt_u"] = 64826] = "i32x4_lt_u"; + OperatorCode[OperatorCode["i32x4_gt_s"] = 64827] = "i32x4_gt_s"; + OperatorCode[OperatorCode["i32x4_gt_u"] = 64828] = "i32x4_gt_u"; + OperatorCode[OperatorCode["i32x4_le_s"] = 64829] = "i32x4_le_s"; + OperatorCode[OperatorCode["i32x4_le_u"] = 64830] = "i32x4_le_u"; + OperatorCode[OperatorCode["i32x4_ge_s"] = 64831] = "i32x4_ge_s"; + OperatorCode[OperatorCode["i32x4_ge_u"] = 64832] = "i32x4_ge_u"; + OperatorCode[OperatorCode["f32x4_eq"] = 64833] = "f32x4_eq"; + OperatorCode[OperatorCode["f32x4_ne"] = 64834] = "f32x4_ne"; + OperatorCode[OperatorCode["f32x4_lt"] = 64835] = "f32x4_lt"; + OperatorCode[OperatorCode["f32x4_gt"] = 64836] = "f32x4_gt"; + OperatorCode[OperatorCode["f32x4_le"] = 64837] = "f32x4_le"; + OperatorCode[OperatorCode["f32x4_ge"] = 64838] = "f32x4_ge"; + OperatorCode[OperatorCode["f64x2_eq"] = 64839] = "f64x2_eq"; + OperatorCode[OperatorCode["f64x2_ne"] = 64840] = "f64x2_ne"; + OperatorCode[OperatorCode["f64x2_lt"] = 64841] = "f64x2_lt"; + OperatorCode[OperatorCode["f64x2_gt"] = 64842] = "f64x2_gt"; + OperatorCode[OperatorCode["f64x2_le"] = 64843] = "f64x2_le"; + OperatorCode[OperatorCode["f64x2_ge"] = 64844] = "f64x2_ge"; + OperatorCode[OperatorCode["v128_not"] = 64845] = "v128_not"; + OperatorCode[OperatorCode["v128_and"] = 64846] = "v128_and"; + OperatorCode[OperatorCode["v128_andnot"] = 64847] = "v128_andnot"; + OperatorCode[OperatorCode["v128_or"] = 64848] = "v128_or"; + OperatorCode[OperatorCode["v128_xor"] = 64849] = "v128_xor"; + OperatorCode[OperatorCode["v128_bitselect"] = 64850] = "v128_bitselect"; + OperatorCode[OperatorCode["v128_any_true"] = 64851] = "v128_any_true"; + OperatorCode[OperatorCode["v128_load8_lane"] = 64852] = "v128_load8_lane"; + OperatorCode[OperatorCode["v128_load16_lane"] = 64853] = "v128_load16_lane"; + OperatorCode[OperatorCode["v128_load32_lane"] = 64854] = "v128_load32_lane"; + OperatorCode[OperatorCode["v128_load64_lane"] = 64855] = "v128_load64_lane"; + OperatorCode[OperatorCode["v128_store8_lane"] = 64856] = "v128_store8_lane"; + OperatorCode[OperatorCode["v128_store16_lane"] = 64857] = "v128_store16_lane"; + OperatorCode[OperatorCode["v128_store32_lane"] = 64858] = "v128_store32_lane"; + OperatorCode[OperatorCode["v128_store64_lane"] = 64859] = "v128_store64_lane"; + OperatorCode[OperatorCode["v128_load32_zero"] = 64860] = "v128_load32_zero"; + OperatorCode[OperatorCode["v128_load64_zero"] = 64861] = "v128_load64_zero"; + OperatorCode[OperatorCode["f32x4_demote_f64x2_zero"] = 64862] = "f32x4_demote_f64x2_zero"; + OperatorCode[OperatorCode["f64x2_promote_low_f32x4"] = 64863] = "f64x2_promote_low_f32x4"; + OperatorCode[OperatorCode["i8x16_abs"] = 64864] = "i8x16_abs"; + OperatorCode[OperatorCode["i8x16_neg"] = 64865] = "i8x16_neg"; + OperatorCode[OperatorCode["i8x16_popcnt"] = 64866] = "i8x16_popcnt"; + OperatorCode[OperatorCode["i8x16_all_true"] = 64867] = "i8x16_all_true"; + OperatorCode[OperatorCode["i8x16_bitmask"] = 64868] = "i8x16_bitmask"; + OperatorCode[OperatorCode["i8x16_narrow_i16x8_s"] = 64869] = "i8x16_narrow_i16x8_s"; + OperatorCode[OperatorCode["i8x16_narrow_i16x8_u"] = 64870] = "i8x16_narrow_i16x8_u"; + OperatorCode[OperatorCode["f32x4_ceil"] = 64871] = "f32x4_ceil"; + OperatorCode[OperatorCode["f32x4_floor"] = 64872] = "f32x4_floor"; + OperatorCode[OperatorCode["f32x4_trunc"] = 64873] = "f32x4_trunc"; + OperatorCode[OperatorCode["f32x4_nearest"] = 64874] = "f32x4_nearest"; + OperatorCode[OperatorCode["i8x16_shl"] = 64875] = "i8x16_shl"; + OperatorCode[OperatorCode["i8x16_shr_s"] = 64876] = "i8x16_shr_s"; + OperatorCode[OperatorCode["i8x16_shr_u"] = 64877] = "i8x16_shr_u"; + OperatorCode[OperatorCode["i8x16_add"] = 64878] = "i8x16_add"; + OperatorCode[OperatorCode["i8x16_add_sat_s"] = 64879] = "i8x16_add_sat_s"; + OperatorCode[OperatorCode["i8x16_add_sat_u"] = 64880] = "i8x16_add_sat_u"; + OperatorCode[OperatorCode["i8x16_sub"] = 64881] = "i8x16_sub"; + OperatorCode[OperatorCode["i8x16_sub_sat_s"] = 64882] = "i8x16_sub_sat_s"; + OperatorCode[OperatorCode["i8x16_sub_sat_u"] = 64883] = "i8x16_sub_sat_u"; + OperatorCode[OperatorCode["f64x2_ceil"] = 64884] = "f64x2_ceil"; + OperatorCode[OperatorCode["f64x2_floor"] = 64885] = "f64x2_floor"; + OperatorCode[OperatorCode["i8x16_min_s"] = 64886] = "i8x16_min_s"; + OperatorCode[OperatorCode["i8x16_min_u"] = 64887] = "i8x16_min_u"; + OperatorCode[OperatorCode["i8x16_max_s"] = 64888] = "i8x16_max_s"; + OperatorCode[OperatorCode["i8x16_max_u"] = 64889] = "i8x16_max_u"; + OperatorCode[OperatorCode["f64x2_trunc"] = 64890] = "f64x2_trunc"; + OperatorCode[OperatorCode["i8x16_avgr_u"] = 64891] = "i8x16_avgr_u"; + OperatorCode[OperatorCode["i16x8_extadd_pairwise_i8x16_s"] = 64892] = "i16x8_extadd_pairwise_i8x16_s"; + OperatorCode[OperatorCode["i16x8_extadd_pairwise_i8x16_u"] = 64893] = "i16x8_extadd_pairwise_i8x16_u"; + OperatorCode[OperatorCode["i32x4_extadd_pairwise_i16x8_s"] = 64894] = "i32x4_extadd_pairwise_i16x8_s"; + OperatorCode[OperatorCode["i32x4_extadd_pairwise_i16x8_u"] = 64895] = "i32x4_extadd_pairwise_i16x8_u"; + OperatorCode[OperatorCode["i16x8_abs"] = 64896] = "i16x8_abs"; + OperatorCode[OperatorCode["i16x8_neg"] = 64897] = "i16x8_neg"; + OperatorCode[OperatorCode["i16x8_q15mulr_sat_s"] = 64898] = "i16x8_q15mulr_sat_s"; + OperatorCode[OperatorCode["i16x8_all_true"] = 64899] = "i16x8_all_true"; + OperatorCode[OperatorCode["i16x8_bitmask"] = 64900] = "i16x8_bitmask"; + OperatorCode[OperatorCode["i16x8_narrow_i32x4_s"] = 64901] = "i16x8_narrow_i32x4_s"; + OperatorCode[OperatorCode["i16x8_narrow_i32x4_u"] = 64902] = "i16x8_narrow_i32x4_u"; + OperatorCode[OperatorCode["i16x8_extend_low_i8x16_s"] = 64903] = "i16x8_extend_low_i8x16_s"; + OperatorCode[OperatorCode["i16x8_extend_high_i8x16_s"] = 64904] = "i16x8_extend_high_i8x16_s"; + OperatorCode[OperatorCode["i16x8_extend_low_i8x16_u"] = 64905] = "i16x8_extend_low_i8x16_u"; + OperatorCode[OperatorCode["i16x8_extend_high_i8x16_u"] = 64906] = "i16x8_extend_high_i8x16_u"; + OperatorCode[OperatorCode["i16x8_shl"] = 64907] = "i16x8_shl"; + OperatorCode[OperatorCode["i16x8_shr_s"] = 64908] = "i16x8_shr_s"; + OperatorCode[OperatorCode["i16x8_shr_u"] = 64909] = "i16x8_shr_u"; + OperatorCode[OperatorCode["i16x8_add"] = 64910] = "i16x8_add"; + OperatorCode[OperatorCode["i16x8_add_sat_s"] = 64911] = "i16x8_add_sat_s"; + OperatorCode[OperatorCode["i16x8_add_sat_u"] = 64912] = "i16x8_add_sat_u"; + OperatorCode[OperatorCode["i16x8_sub"] = 64913] = "i16x8_sub"; + OperatorCode[OperatorCode["i16x8_sub_sat_s"] = 64914] = "i16x8_sub_sat_s"; + OperatorCode[OperatorCode["i16x8_sub_sat_u"] = 64915] = "i16x8_sub_sat_u"; + OperatorCode[OperatorCode["f64x2_nearest"] = 64916] = "f64x2_nearest"; + OperatorCode[OperatorCode["i16x8_mul"] = 64917] = "i16x8_mul"; + OperatorCode[OperatorCode["i16x8_min_s"] = 64918] = "i16x8_min_s"; + OperatorCode[OperatorCode["i16x8_min_u"] = 64919] = "i16x8_min_u"; + OperatorCode[OperatorCode["i16x8_max_s"] = 64920] = "i16x8_max_s"; + OperatorCode[OperatorCode["i16x8_max_u"] = 64921] = "i16x8_max_u"; + OperatorCode[OperatorCode["i16x8_avgr_u"] = 64923] = "i16x8_avgr_u"; + OperatorCode[OperatorCode["i16x8_extmul_low_i8x16_s"] = 64924] = "i16x8_extmul_low_i8x16_s"; + OperatorCode[OperatorCode["i16x8_extmul_high_i8x16_s"] = 64925] = "i16x8_extmul_high_i8x16_s"; + OperatorCode[OperatorCode["i16x8_extmul_low_i8x16_u"] = 64926] = "i16x8_extmul_low_i8x16_u"; + OperatorCode[OperatorCode["i16x8_extmul_high_i8x16_u"] = 64927] = "i16x8_extmul_high_i8x16_u"; + OperatorCode[OperatorCode["i32x4_abs"] = 64928] = "i32x4_abs"; + OperatorCode[OperatorCode["i32x4_neg"] = 64929] = "i32x4_neg"; + OperatorCode[OperatorCode["i32x4_all_true"] = 64931] = "i32x4_all_true"; + OperatorCode[OperatorCode["i32x4_bitmask"] = 64932] = "i32x4_bitmask"; + OperatorCode[OperatorCode["i32x4_extend_low_i16x8_s"] = 64935] = "i32x4_extend_low_i16x8_s"; + OperatorCode[OperatorCode["i32x4_extend_high_i16x8_s"] = 64936] = "i32x4_extend_high_i16x8_s"; + OperatorCode[OperatorCode["i32x4_extend_low_i16x8_u"] = 64937] = "i32x4_extend_low_i16x8_u"; + OperatorCode[OperatorCode["i32x4_extend_high_i16x8_u"] = 64938] = "i32x4_extend_high_i16x8_u"; + OperatorCode[OperatorCode["i32x4_shl"] = 64939] = "i32x4_shl"; + OperatorCode[OperatorCode["i32x4_shr_s"] = 64940] = "i32x4_shr_s"; + OperatorCode[OperatorCode["i32x4_shr_u"] = 64941] = "i32x4_shr_u"; + OperatorCode[OperatorCode["i32x4_add"] = 64942] = "i32x4_add"; + OperatorCode[OperatorCode["i32x4_sub"] = 64945] = "i32x4_sub"; + OperatorCode[OperatorCode["i32x4_mul"] = 64949] = "i32x4_mul"; + OperatorCode[OperatorCode["i32x4_min_s"] = 64950] = "i32x4_min_s"; + OperatorCode[OperatorCode["i32x4_min_u"] = 64951] = "i32x4_min_u"; + OperatorCode[OperatorCode["i32x4_max_s"] = 64952] = "i32x4_max_s"; + OperatorCode[OperatorCode["i32x4_max_u"] = 64953] = "i32x4_max_u"; + OperatorCode[OperatorCode["i32x4_dot_i16x8_s"] = 64954] = "i32x4_dot_i16x8_s"; + OperatorCode[OperatorCode["i32x4_extmul_low_i16x8_s"] = 64956] = "i32x4_extmul_low_i16x8_s"; + OperatorCode[OperatorCode["i32x4_extmul_high_i16x8_s"] = 64957] = "i32x4_extmul_high_i16x8_s"; + OperatorCode[OperatorCode["i32x4_extmul_low_i16x8_u"] = 64958] = "i32x4_extmul_low_i16x8_u"; + OperatorCode[OperatorCode["i32x4_extmul_high_i16x8_u"] = 64959] = "i32x4_extmul_high_i16x8_u"; + OperatorCode[OperatorCode["i64x2_abs"] = 64960] = "i64x2_abs"; + OperatorCode[OperatorCode["i64x2_neg"] = 64961] = "i64x2_neg"; + OperatorCode[OperatorCode["i64x2_all_true"] = 64963] = "i64x2_all_true"; + OperatorCode[OperatorCode["i64x2_bitmask"] = 64964] = "i64x2_bitmask"; + OperatorCode[OperatorCode["i64x2_extend_low_i32x4_s"] = 64967] = "i64x2_extend_low_i32x4_s"; + OperatorCode[OperatorCode["i64x2_extend_high_i32x4_s"] = 64968] = "i64x2_extend_high_i32x4_s"; + OperatorCode[OperatorCode["i64x2_extend_low_i32x4_u"] = 64969] = "i64x2_extend_low_i32x4_u"; + OperatorCode[OperatorCode["i64x2_extend_high_i32x4_u"] = 64970] = "i64x2_extend_high_i32x4_u"; + OperatorCode[OperatorCode["i64x2_shl"] = 64971] = "i64x2_shl"; + OperatorCode[OperatorCode["i64x2_shr_s"] = 64972] = "i64x2_shr_s"; + OperatorCode[OperatorCode["i64x2_shr_u"] = 64973] = "i64x2_shr_u"; + OperatorCode[OperatorCode["i64x2_add"] = 64974] = "i64x2_add"; + OperatorCode[OperatorCode["i64x2_sub"] = 64977] = "i64x2_sub"; + OperatorCode[OperatorCode["i64x2_mul"] = 64981] = "i64x2_mul"; + OperatorCode[OperatorCode["i64x2_eq"] = 64982] = "i64x2_eq"; + OperatorCode[OperatorCode["i64x2_ne"] = 64983] = "i64x2_ne"; + OperatorCode[OperatorCode["i64x2_lt_s"] = 64984] = "i64x2_lt_s"; + OperatorCode[OperatorCode["i64x2_gt_s"] = 64985] = "i64x2_gt_s"; + OperatorCode[OperatorCode["i64x2_le_s"] = 64986] = "i64x2_le_s"; + OperatorCode[OperatorCode["i64x2_ge_s"] = 64987] = "i64x2_ge_s"; + OperatorCode[OperatorCode["i64x2_extmul_low_i32x4_s"] = 64988] = "i64x2_extmul_low_i32x4_s"; + OperatorCode[OperatorCode["i64x2_extmul_high_i32x4_s"] = 64989] = "i64x2_extmul_high_i32x4_s"; + OperatorCode[OperatorCode["i64x2_extmul_low_i32x4_u"] = 64990] = "i64x2_extmul_low_i32x4_u"; + OperatorCode[OperatorCode["i64x2_extmul_high_i32x4_u"] = 64991] = "i64x2_extmul_high_i32x4_u"; + OperatorCode[OperatorCode["f32x4_abs"] = 64992] = "f32x4_abs"; + OperatorCode[OperatorCode["f32x4_neg"] = 64993] = "f32x4_neg"; + OperatorCode[OperatorCode["f32x4_sqrt"] = 64995] = "f32x4_sqrt"; + OperatorCode[OperatorCode["f32x4_add"] = 64996] = "f32x4_add"; + OperatorCode[OperatorCode["f32x4_sub"] = 64997] = "f32x4_sub"; + OperatorCode[OperatorCode["f32x4_mul"] = 64998] = "f32x4_mul"; + OperatorCode[OperatorCode["f32x4_div"] = 64999] = "f32x4_div"; + OperatorCode[OperatorCode["f32x4_min"] = 65000] = "f32x4_min"; + OperatorCode[OperatorCode["f32x4_max"] = 65001] = "f32x4_max"; + OperatorCode[OperatorCode["f32x4_pmin"] = 65002] = "f32x4_pmin"; + OperatorCode[OperatorCode["f32x4_pmax"] = 65003] = "f32x4_pmax"; + OperatorCode[OperatorCode["f64x2_abs"] = 65004] = "f64x2_abs"; + OperatorCode[OperatorCode["f64x2_neg"] = 65005] = "f64x2_neg"; + OperatorCode[OperatorCode["f64x2_sqrt"] = 65007] = "f64x2_sqrt"; + OperatorCode[OperatorCode["f64x2_add"] = 65008] = "f64x2_add"; + OperatorCode[OperatorCode["f64x2_sub"] = 65009] = "f64x2_sub"; + OperatorCode[OperatorCode["f64x2_mul"] = 65010] = "f64x2_mul"; + OperatorCode[OperatorCode["f64x2_div"] = 65011] = "f64x2_div"; + OperatorCode[OperatorCode["f64x2_min"] = 65012] = "f64x2_min"; + OperatorCode[OperatorCode["f64x2_max"] = 65013] = "f64x2_max"; + OperatorCode[OperatorCode["f64x2_pmin"] = 65014] = "f64x2_pmin"; + OperatorCode[OperatorCode["f64x2_pmax"] = 65015] = "f64x2_pmax"; + OperatorCode[OperatorCode["i32x4_trunc_sat_f32x4_s"] = 65016] = "i32x4_trunc_sat_f32x4_s"; + OperatorCode[OperatorCode["i32x4_trunc_sat_f32x4_u"] = 65017] = "i32x4_trunc_sat_f32x4_u"; + OperatorCode[OperatorCode["f32x4_convert_i32x4_s"] = 65018] = "f32x4_convert_i32x4_s"; + OperatorCode[OperatorCode["f32x4_convert_i32x4_u"] = 65019] = "f32x4_convert_i32x4_u"; + OperatorCode[OperatorCode["i32x4_trunc_sat_f64x2_s_zero"] = 65020] = "i32x4_trunc_sat_f64x2_s_zero"; + OperatorCode[OperatorCode["i32x4_trunc_sat_f64x2_u_zero"] = 65021] = "i32x4_trunc_sat_f64x2_u_zero"; + OperatorCode[OperatorCode["f64x2_convert_low_i32x4_s"] = 65022] = "f64x2_convert_low_i32x4_s"; + OperatorCode[OperatorCode["f64x2_convert_low_i32x4_u"] = 65023] = "f64x2_convert_low_i32x4_u"; + // GC proposal (milestone 6). + OperatorCode[OperatorCode["struct_new_with_rtt"] = 64257] = "struct_new_with_rtt"; + OperatorCode[OperatorCode["struct_new_default_with_rtt"] = 64258] = "struct_new_default_with_rtt"; + OperatorCode[OperatorCode["struct_get"] = 64259] = "struct_get"; + OperatorCode[OperatorCode["struct_get_s"] = 64260] = "struct_get_s"; + OperatorCode[OperatorCode["struct_get_u"] = 64261] = "struct_get_u"; + OperatorCode[OperatorCode["struct_set"] = 64262] = "struct_set"; + OperatorCode[OperatorCode["struct_new"] = 64263] = "struct_new"; + OperatorCode[OperatorCode["struct_new_default"] = 64264] = "struct_new_default"; + OperatorCode[OperatorCode["array_fill"] = 64271] = "array_fill"; + OperatorCode[OperatorCode["array_new_with_rtt"] = 64273] = "array_new_with_rtt"; + OperatorCode[OperatorCode["array_new_default_with_rtt"] = 64274] = "array_new_default_with_rtt"; + OperatorCode[OperatorCode["array_get"] = 64275] = "array_get"; + OperatorCode[OperatorCode["array_get_s"] = 64276] = "array_get_s"; + OperatorCode[OperatorCode["array_get_u"] = 64277] = "array_get_u"; + OperatorCode[OperatorCode["array_set"] = 64278] = "array_set"; + OperatorCode[OperatorCode["array_len_"] = 64279] = "array_len_"; + OperatorCode[OperatorCode["array_len"] = 64281] = "array_len"; + OperatorCode[OperatorCode["array_copy"] = 64280] = "array_copy"; + OperatorCode[OperatorCode["array_new_fixed"] = 64282] = "array_new_fixed"; + OperatorCode[OperatorCode["array_new"] = 64283] = "array_new"; + OperatorCode[OperatorCode["array_new_default"] = 64284] = "array_new_default"; + OperatorCode[OperatorCode["array_new_data"] = 64285] = "array_new_data"; + OperatorCode[OperatorCode["array_init_from_data"] = 64286] = "array_init_from_data"; + OperatorCode[OperatorCode["array_new_elem"] = 64287] = "array_new_elem"; + OperatorCode[OperatorCode["i31_new"] = 64288] = "i31_new"; + OperatorCode[OperatorCode["i31_get_s"] = 64289] = "i31_get_s"; + OperatorCode[OperatorCode["i31_get_u"] = 64290] = "i31_get_u"; + OperatorCode[OperatorCode["rtt_canon"] = 64304] = "rtt_canon"; + OperatorCode[OperatorCode["rtt_sub"] = 64305] = "rtt_sub"; + OperatorCode[OperatorCode["rtt_fresh_sub"] = 64306] = "rtt_fresh_sub"; + OperatorCode[OperatorCode["ref_test"] = 64320] = "ref_test"; + OperatorCode[OperatorCode["ref_cast"] = 64321] = "ref_cast"; + OperatorCode[OperatorCode["br_on_cast_"] = 64322] = "br_on_cast_"; + OperatorCode[OperatorCode["br_on_cast_fail_"] = 64323] = "br_on_cast_fail_"; + OperatorCode[OperatorCode["ref_test_"] = 64324] = "ref_test_"; + OperatorCode[OperatorCode["ref_cast_"] = 64325] = "ref_cast_"; + OperatorCode[OperatorCode["br_on_cast__"] = 64326] = "br_on_cast__"; + OperatorCode[OperatorCode["br_on_cast_fail__"] = 64327] = "br_on_cast_fail__"; + OperatorCode[OperatorCode["ref_test_null"] = 64328] = "ref_test_null"; + OperatorCode[OperatorCode["ref_cast_null"] = 64329] = "ref_cast_null"; + OperatorCode[OperatorCode["br_on_cast_null_"] = 64330] = "br_on_cast_null_"; + OperatorCode[OperatorCode["br_on_cast_fail_null_"] = 64331] = "br_on_cast_fail_null_"; + OperatorCode[OperatorCode["ref_cast_nop"] = 64332] = "ref_cast_nop"; + OperatorCode[OperatorCode["br_on_cast"] = 64334] = "br_on_cast"; + OperatorCode[OperatorCode["br_on_cast_fail"] = 64335] = "br_on_cast_fail"; + OperatorCode[OperatorCode["ref_is_func_"] = 64336] = "ref_is_func_"; + OperatorCode[OperatorCode["ref_is_data_"] = 64337] = "ref_is_data_"; + OperatorCode[OperatorCode["ref_is_i31_"] = 64338] = "ref_is_i31_"; + OperatorCode[OperatorCode["ref_is_array_"] = 64339] = "ref_is_array_"; + OperatorCode[OperatorCode["array_init_data"] = 64340] = "array_init_data"; + OperatorCode[OperatorCode["array_init_elem"] = 64341] = "array_init_elem"; + OperatorCode[OperatorCode["ref_as_func_"] = 64344] = "ref_as_func_"; + OperatorCode[OperatorCode["ref_as_data_"] = 64345] = "ref_as_data_"; + OperatorCode[OperatorCode["ref_as_i31_"] = 64346] = "ref_as_i31_"; + OperatorCode[OperatorCode["ref_as_array_"] = 64347] = "ref_as_array_"; + OperatorCode[OperatorCode["br_on_func_"] = 64352] = "br_on_func_"; + OperatorCode[OperatorCode["br_on_data_"] = 64353] = "br_on_data_"; + OperatorCode[OperatorCode["br_on_i31_"] = 64354] = "br_on_i31_"; + OperatorCode[OperatorCode["br_on_non_func_"] = 64355] = "br_on_non_func_"; + OperatorCode[OperatorCode["br_on_non_data_"] = 64356] = "br_on_non_data_"; + OperatorCode[OperatorCode["br_on_non_i31_"] = 64357] = "br_on_non_i31_"; + OperatorCode[OperatorCode["br_on_array_"] = 64358] = "br_on_array_"; + OperatorCode[OperatorCode["br_on_non_array_"] = 64359] = "br_on_non_array_"; + OperatorCode[OperatorCode["extern_internalize"] = 64368] = "extern_internalize"; + OperatorCode[OperatorCode["extern_externalize"] = 64369] = "extern_externalize"; +})(OperatorCode = exports.OperatorCode || (exports.OperatorCode = {})); +exports.OperatorCodeNames = [ + "unreachable", + "nop", + "block", + "loop", + "if", + "else", + "try", + "catch", + "throw", + "rethrow", + "unwind", + "end", + "br", + "br_if", + "br_table", + "return", + "call", + "call_indirect", + "return_call", + "return_call_indirect", + "call_ref", + "return_call_ref", + undefined, + "let", + "delegate", + "catch_all", + "drop", + "select", + "select", + undefined, + undefined, + undefined, + "local.get", + "local.set", + "local.tee", + "global.get", + "global.set", + "table.get", + "table.set", + undefined, + "i32.load", + "i64.load", + "f32.load", + "f64.load", + "i32.load8_s", + "i32.load8_u", + "i32.load16_s", + "i32.load16_u", + "i64.load8_s", + "i64.load8_u", + "i64.load16_s", + "i64.load16_u", + "i64.load32_s", + "i64.load32_u", + "i32.store", + "i64.store", + "f32.store", + "f64.store", + "i32.store8", + "i32.store16", + "i64.store8", + "i64.store16", + "i64.store32", + "memory.size", + "memory.grow", + "i32.const", + "i64.const", + "f32.const", + "f64.const", + "i32.eqz", + "i32.eq", + "i32.ne", + "i32.lt_s", + "i32.lt_u", + "i32.gt_s", + "i32.gt_u", + "i32.le_s", + "i32.le_u", + "i32.ge_s", + "i32.ge_u", + "i64.eqz", + "i64.eq", + "i64.ne", + "i64.lt_s", + "i64.lt_u", + "i64.gt_s", + "i64.gt_u", + "i64.le_s", + "i64.le_u", + "i64.ge_s", + "i64.ge_u", + "f32.eq", + "f32.ne", + "f32.lt", + "f32.gt", + "f32.le", + "f32.ge", + "f64.eq", + "f64.ne", + "f64.lt", + "f64.gt", + "f64.le", + "f64.ge", + "i32.clz", + "i32.ctz", + "i32.popcnt", + "i32.add", + "i32.sub", + "i32.mul", + "i32.div_s", + "i32.div_u", + "i32.rem_s", + "i32.rem_u", + "i32.and", + "i32.or", + "i32.xor", + "i32.shl", + "i32.shr_s", + "i32.shr_u", + "i32.rotl", + "i32.rotr", + "i64.clz", + "i64.ctz", + "i64.popcnt", + "i64.add", + "i64.sub", + "i64.mul", + "i64.div_s", + "i64.div_u", + "i64.rem_s", + "i64.rem_u", + "i64.and", + "i64.or", + "i64.xor", + "i64.shl", + "i64.shr_s", + "i64.shr_u", + "i64.rotl", + "i64.rotr", + "f32.abs", + "f32.neg", + "f32.ceil", + "f32.floor", + "f32.trunc", + "f32.nearest", + "f32.sqrt", + "f32.add", + "f32.sub", + "f32.mul", + "f32.div", + "f32.min", + "f32.max", + "f32.copysign", + "f64.abs", + "f64.neg", + "f64.ceil", + "f64.floor", + "f64.trunc", + "f64.nearest", + "f64.sqrt", + "f64.add", + "f64.sub", + "f64.mul", + "f64.div", + "f64.min", + "f64.max", + "f64.copysign", + "i32.wrap_i64", + "i32.trunc_f32_s", + "i32.trunc_f32_u", + "i32.trunc_f64_s", + "i32.trunc_f64_u", + "i64.extend_i32_s", + "i64.extend_i32_u", + "i64.trunc_f32_s", + "i64.trunc_f32_u", + "i64.trunc_f64_s", + "i64.trunc_f64_u", + "f32.convert_i32_s", + "f32.convert_i32_u", + "f32.convert_i64_s", + "f32.convert_i64_u", + "f32.demote_f64", + "f64.convert_i32_s", + "f64.convert_i32_u", + "f64.convert_i64_s", + "f64.convert_i64_u", + "f64.promote_f32", + "i32.reinterpret_f32", + "i64.reinterpret_f64", + "f32.reinterpret_i32", + "f64.reinterpret_i64", + "i32.extend8_s", + "i32.extend16_s", + "i64.extend8_s", + "i64.extend16_s", + "i64.extend32_s", + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + "ref.null", + "ref.is_null", + "ref.func", + "ref.as_non_null", + "br_on_null", + "ref.eq", + "br_on_non_null", + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, +]; +[ + "i32.trunc_sat_f32_s", + "i32.trunc_sat_f32_u", + "i32.trunc_sat_f64_s", + "i32.trunc_sat_f64_u", + "i64.trunc_sat_f32_s", + "i64.trunc_sat_f32_u", + "i64.trunc_sat_f64_s", + "i64.trunc_sat_f64_u", + "memory.init", + "data.drop", + "memory.copy", + "memory.fill", + "table.init", + "elem.drop", + "table.copy", + "table.grow", + "table.size", + "table.fill", +].forEach(function (s, i) { + exports.OperatorCodeNames[0xfc00 | i] = s; +}); +[ + "v128.load", + "i16x8.load8x8_s", + "i16x8.load8x8_u", + "i32x4.load16x4_s", + "i32x4.load16x4_u", + "i64x2.load32x2_s", + "i64x2.load32x2_u", + "v8x16.load_splat", + "v16x8.load_splat", + "v32x4.load_splat", + "v64x2.load_splat", + "v128.store", + "v128.const", + "i8x16.shuffle", + "i8x16.swizzle", + "i8x16.splat", + "i16x8.splat", + "i32x4.splat", + "i64x2.splat", + "f32x4.splat", + "f64x2.splat", + "i8x16.extract_lane_s", + "i8x16.extract_lane_u", + "i8x16.replace_lane", + "i16x8.extract_lane_s", + "i16x8.extract_lane_u", + "i16x8.replace_lane", + "i32x4.extract_lane", + "i32x4.replace_lane", + "i64x2.extract_lane", + "i64x2.replace_lane", + "f32x4.extract_lane", + "f32x4.replace_lane", + "f64x2.extract_lane", + "f64x2.replace_lane", + "i8x16.eq", + "i8x16.ne", + "i8x16.lt_s", + "i8x16.lt_u", + "i8x16.gt_s", + "i8x16.gt_u", + "i8x16.le_s", + "i8x16.le_u", + "i8x16.ge_s", + "i8x16.ge_u", + "i16x8.eq", + "i16x8.ne", + "i16x8.lt_s", + "i16x8.lt_u", + "i16x8.gt_s", + "i16x8.gt_u", + "i16x8.le_s", + "i16x8.le_u", + "i16x8.ge_s", + "i16x8.ge_u", + "i32x4.eq", + "i32x4.ne", + "i32x4.lt_s", + "i32x4.lt_u", + "i32x4.gt_s", + "i32x4.gt_u", + "i32x4.le_s", + "i32x4.le_u", + "i32x4.ge_s", + "i32x4.ge_u", + "f32x4.eq", + "f32x4.ne", + "f32x4.lt", + "f32x4.gt", + "f32x4.le", + "f32x4.ge", + "f64x2.eq", + "f64x2.ne", + "f64x2.lt", + "f64x2.gt", + "f64x2.le", + "f64x2.ge", + "v128.not", + "v128.and", + "v128.andnot", + "v128.or", + "v128.xor", + "v128.bitselect", + "v128.any_true", + "v128.load8_lane", + "v128.load16_lane", + "v128.load32_lane", + "v128.load64_lane", + "v128.store8_lane", + "v128.store16_lane", + "v128.store32_lane", + "v128.store64_lane", + "v128.load32_zero", + "v128.load64_zero", + "f32x4.demote_f64x2_zero", + "f64x2.promote_low_f32x4", + "i8x16.abs", + "i8x16.neg", + "i8x16_popcnt", + "i8x16.all_true", + "i8x16.bitmask", + "i8x16.narrow_i16x8_s", + "i8x16.narrow_i16x8_u", + "f32x4.ceil", + "f32x4.floor", + "f32x4.trunc", + "f32x4.nearest", + "i8x16.shl", + "i8x16.shr_s", + "i8x16.shr_u", + "i8x16.add", + "i8x16.add_sat_s", + "i8x16.add_sat_u", + "i8x16.sub", + "i8x16.sub_sat_s", + "i8x16.sub_sat_u", + "f64x2.ceil", + "f64x2.floor", + "i8x16.min_s", + "i8x16.min_u", + "i8x16.max_s", + "i8x16.max_u", + "f64x2.trunc", + "i8x16.avgr_u", + "i16x8.extadd_pairwise_i8x16_s", + "i16x8.extadd_pairwise_i8x16_u", + "i32x4.extadd_pairwise_i16x8_s", + "i32x4.extadd_pairwise_i16x8_u", + "i16x8.abs", + "i16x8.neg", + "i16x8.q15mulr_sat_s", + "i16x8.all_true", + "i16x8.bitmask", + "i16x8.narrow_i32x4_s", + "i16x8.narrow_i32x4_u", + "i16x8.extend_low_i8x16_s", + "i16x8.extend_high_i8x16_s", + "i16x8.extend_low_i8x16_u", + "i16x8.extend_high_i8x16_u", + "i16x8.shl", + "i16x8.shr_s", + "i16x8.shr_u", + "i16x8.add", + "i16x8.add_sat_s", + "i16x8.add_sat_u", + "i16x8.sub", + "i16x8.sub_sat_s", + "i16x8.sub_sat_u", + "f64x2.nearest", + "i16x8.mul", + "i16x8.min_s", + "i16x8.min_u", + "i16x8.max_s", + "i16x8.max_u", + undefined, + "i16x8.avgr_u", + "i16x8.extmul_low_i8x16_s", + "i16x8.extmul_high_i8x16_s", + "i16x8.extmul_low_i8x16_u", + "i16x8.extmul_high_i8x16_u", + "i32x4.abs", + "i32x4.neg", + undefined, + "i32x4.all_true", + "i32x4.bitmask", + undefined, + undefined, + "i32x4.extend_low_i16x8_s", + "i32x4.extend_high_i16x8_s", + "i32x4.extend_low_i16x8_u", + "i32x4.extend_high_i16x8_u", + "i32x4.shl", + "i32x4.shr_s", + "i32x4.shr_u", + "i32x4.add", + undefined, + undefined, + "i32x4.sub", + undefined, + undefined, + undefined, + "i32x4.mul", + "i32x4.min_s", + "i32x4.min_u", + "i32x4.max_s", + "i32x4.max_u", + "i32x4.dot_i16x8_s", + undefined, + "i32x4.extmul_low_i16x8_s", + "i32x4.extmul_high_i16x8_s", + "i32x4.extmul_low_i16x8_u", + "i32x4.extmul_high_i16x8_u", + "i64x2.abs", + "i64x2.neg", + undefined, + "i64x2.all_true", + "i64x2.bitmask", + undefined, + undefined, + "i64x2.extend_low_i32x4_s", + "i64x2.extend_high_i32x4_s", + "i64x2.extend_low_i32x4_u", + "i64x2.extend_high_i32x4_u", + "i64x2.shl", + "i64x2.shr_s", + "i64x2.shr_u", + "i64x2.add", + undefined, + undefined, + "i64x2.sub", + undefined, + undefined, + undefined, + "i64x2.mul", + "i64x2.eq", + "i64x2.ne", + "i64x2.lt_s", + "i64x2.gt_s", + "i64x2.le_s", + "i64x2.ge_s", + "i64x2.extmul_low_i32x4_s", + "i64x2.extmul_high_i32x4_s", + "i64x2.extmul_low_i32x4_u", + "i64x2.extmul_high_i32x4_u", + "f32x4.abs", + "f32x4.neg", + undefined, + "f32x4.sqrt", + "f32x4.add", + "f32x4.sub", + "f32x4.mul", + "f32x4.div", + "f32x4.min", + "f32x4.max", + "f32x4.pmin", + "f32x4.pmax", + "f64x2.abs", + "f64x2.neg", + undefined, + "f64x2.sqrt", + "f64x2.add", + "f64x2.sub", + "f64x2.mul", + "f64x2.div", + "f64x2.min", + "f64x2.max", + "f64x2.pmin", + "f64x2.pmax", + "i32x4.trunc_sat_f32x4_s", + "i32x4.trunc_sat_f32x4_u", + "f32x4.convert_i32x4_s", + "f32x4.convert_i32x4_u", + "i32x4.trunc_sat_f64x2_s_zero", + "i32x4.trunc_sat_f64x2_u_zero", + "f64x2.convert_low_i32x4_s", + "f64x2.convert_low_i32x4_u", +].forEach(function (s, i) { + exports.OperatorCodeNames[0xfd00 | i] = s; +}); +[ + "memory.atomic.notify", + "memory.atomic.wait32", + "memory.atomic.wait64", + "atomic.fence", + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + "i32.atomic.load", + "i64.atomic.load", + "i32.atomic.load8_u", + "i32.atomic.load16_u", + "i64.atomic.load8_u", + "i64.atomic.load16_u", + "i64.atomic.load32_u", + "i32.atomic.store", + "i64.atomic.store", + "i32.atomic.store8", + "i32.atomic.store16", + "i64.atomic.store8", + "i64.atomic.store16", + "i64.atomic.store32", + "i32.atomic.rmw.add", + "i64.atomic.rmw.add", + "i32.atomic.rmw8.add_u", + "i32.atomic.rmw16.add_u", + "i64.atomic.rmw8.add_u", + "i64.atomic.rmw16.add_u", + "i64.atomic.rmw32.add_u", + "i32.atomic.rmw.sub", + "i64.atomic.rmw.sub", + "i32.atomic.rmw8.sub_u", + "i32.atomic.rmw16.sub_u", + "i64.atomic.rmw8.sub_u", + "i64.atomic.rmw16.sub_u", + "i64.atomic.rmw32.sub_u", + "i32.atomic.rmw.and", + "i64.atomic.rmw.and", + "i32.atomic.rmw8.and_u", + "i32.atomic.rmw16.and_u", + "i64.atomic.rmw8.and_u", + "i64.atomic.rmw16.and_u", + "i64.atomic.rmw32.and_u", + "i32.atomic.rmw.or", + "i64.atomic.rmw.or", + "i32.atomic.rmw8.or_u", + "i32.atomic.rmw16.or_u", + "i64.atomic.rmw8.or_u", + "i64.atomic.rmw16.or_u", + "i64.atomic.rmw32.or_u", + "i32.atomic.rmw.xor", + "i64.atomic.rmw.xor", + "i32.atomic.rmw8.xor_u", + "i32.atomic.rmw16.xor_u", + "i64.atomic.rmw8.xor_u", + "i64.atomic.rmw16.xor_u", + "i64.atomic.rmw32.xor_u", + "i32.atomic.rmw.xchg", + "i64.atomic.rmw.xchg", + "i32.atomic.rmw8.xchg_u", + "i32.atomic.rmw16.xchg_u", + "i64.atomic.rmw8.xchg_u", + "i64.atomic.rmw16.xchg_u", + "i64.atomic.rmw32.xchg_u", + "i32.atomic.rmw.cmpxchg", + "i64.atomic.rmw.cmpxchg", + "i32.atomic.rmw8.cmpxchg_u", + "i32.atomic.rmw16.cmpxchg_u", + "i64.atomic.rmw8.cmpxchg_u", + "i64.atomic.rmw16.cmpxchg_u", + "i64.atomic.rmw32.cmpxchg_u", +].forEach(function (s, i) { + exports.OperatorCodeNames[0xfe00 | i] = s; +}); +exports.OperatorCodeNames[0xfb01] = "struct.new_with_rtt"; +exports.OperatorCodeNames[0xfb02] = "struct.new_default_with_rtt"; +exports.OperatorCodeNames[0xfb03] = "struct.get"; +exports.OperatorCodeNames[0xfb04] = "struct.get_s"; +exports.OperatorCodeNames[0xfb05] = "struct.get_u"; +exports.OperatorCodeNames[0xfb06] = "struct.set"; +exports.OperatorCodeNames[0xfb07] = "struct.new"; +exports.OperatorCodeNames[0xfb08] = "struct.new_default"; +exports.OperatorCodeNames[0xfb0f] = "array.fill"; +exports.OperatorCodeNames[0xfb11] = "array.new_with_rtt"; +exports.OperatorCodeNames[0xfb12] = "array.new_default_with_rtt"; +exports.OperatorCodeNames[0xfb13] = "array.get"; +exports.OperatorCodeNames[0xfb14] = "array.get_s"; +exports.OperatorCodeNames[0xfb15] = "array.get_u"; +exports.OperatorCodeNames[0xfb16] = "array.set"; +exports.OperatorCodeNames[0xfb17] = "array.len"; // TODO remove +exports.OperatorCodeNames[0xfb18] = "array.copy"; +exports.OperatorCodeNames[0xfb19] = "array.len"; +exports.OperatorCodeNames[0xfb1a] = "array.new_fixed"; +exports.OperatorCodeNames[0xfb1b] = "array.new"; +exports.OperatorCodeNames[0xfb1c] = "array.new_default"; +exports.OperatorCodeNames[0xfb1d] = "array.new_data"; +exports.OperatorCodeNames[0xfb1e] = "array.init_from_data"; +exports.OperatorCodeNames[0xfb1f] = "array.new_elem"; +exports.OperatorCodeNames[0xfb20] = "i31.new"; +exports.OperatorCodeNames[0xfb21] = "i31.get_s"; +exports.OperatorCodeNames[0xfb22] = "i31.get_u"; +exports.OperatorCodeNames[0xfb30] = "rtt.canon"; +exports.OperatorCodeNames[0xfb31] = "rtt.sub"; +exports.OperatorCodeNames[0xfb32] = "rtt.fresh_sub"; +exports.OperatorCodeNames[0xfb40] = "ref.test"; +exports.OperatorCodeNames[0xfb41] = "ref.cast"; +exports.OperatorCodeNames[0xfb42] = "br_on_cast"; +exports.OperatorCodeNames[0xfb43] = "br_on_cast_fail"; +exports.OperatorCodeNames[0xfb44] = "ref.test_static"; +exports.OperatorCodeNames[0xfb45] = "ref.cast_static"; +exports.OperatorCodeNames[0xfb46] = "br_on_cast_static"; +exports.OperatorCodeNames[0xfb47] = "br_on_cast_static_fail"; +exports.OperatorCodeNames[0xfb48] = "ref.test_null"; +exports.OperatorCodeNames[0xfb49] = "ref.cast_null"; +exports.OperatorCodeNames[0xfb4a] = "br_on_cast_null"; +exports.OperatorCodeNames[0xfb4b] = "br_on_cast_fail_null"; +exports.OperatorCodeNames[0xfb4c] = "ref.cast_nop"; +exports.OperatorCodeNames[0xfb4e] = "br_on_cast"; +exports.OperatorCodeNames[0xfb4f] = "br_on_cast_fail"; +exports.OperatorCodeNames[0xfb50] = "ref.is_func"; +exports.OperatorCodeNames[0xfb51] = "ref.is_data"; +exports.OperatorCodeNames[0xfb52] = "ref.is_i31"; +exports.OperatorCodeNames[0xfb53] = "ref.is_array"; +exports.OperatorCodeNames[0xfb54] = "array.init_data"; +exports.OperatorCodeNames[0xfb55] = "array.init_elem"; +exports.OperatorCodeNames[0xfb58] = "ref.as_func"; +exports.OperatorCodeNames[0xfb59] = "ref.as_data"; +exports.OperatorCodeNames[0xfb5a] = "ref.as_i31"; +exports.OperatorCodeNames[0xfb5b] = "ref.as_array"; +exports.OperatorCodeNames[0xfb60] = "br_on_func"; +exports.OperatorCodeNames[0xfb61] = "br_on_data"; +exports.OperatorCodeNames[0xfb62] = "br_on_i31"; +exports.OperatorCodeNames[0xfb63] = "br_on_non_func"; +exports.OperatorCodeNames[0xfb64] = "br_on_non_data"; +exports.OperatorCodeNames[0xfb65] = "br_on_non_i31"; +exports.OperatorCodeNames[0xfb66] = "br_on_array"; +exports.OperatorCodeNames[0xfb67] = "br_on_non_array"; +exports.OperatorCodeNames[0xfb70] = "extern.internalize"; +exports.OperatorCodeNames[0xfb71] = "extern.externalize"; +var ExternalKind; +(function (ExternalKind) { + ExternalKind[ExternalKind["Function"] = 0] = "Function"; + ExternalKind[ExternalKind["Table"] = 1] = "Table"; + ExternalKind[ExternalKind["Memory"] = 2] = "Memory"; + ExternalKind[ExternalKind["Global"] = 3] = "Global"; + ExternalKind[ExternalKind["Tag"] = 4] = "Tag"; +})(ExternalKind = exports.ExternalKind || (exports.ExternalKind = {})); +var TypeKind; +(function (TypeKind) { + TypeKind[TypeKind["unspecified"] = 0] = "unspecified"; + TypeKind[TypeKind["i32"] = -1] = "i32"; + TypeKind[TypeKind["i64"] = -2] = "i64"; + TypeKind[TypeKind["f32"] = -3] = "f32"; + TypeKind[TypeKind["f64"] = -4] = "f64"; + TypeKind[TypeKind["v128"] = -5] = "v128"; + TypeKind[TypeKind["i8"] = -6] = "i8"; + TypeKind[TypeKind["i16"] = -7] = "i16"; + TypeKind[TypeKind["funcref"] = -16] = "funcref"; + TypeKind[TypeKind["externref"] = -17] = "externref"; + TypeKind[TypeKind["anyref"] = -18] = "anyref"; + TypeKind[TypeKind["eqref"] = -19] = "eqref"; + TypeKind[TypeKind["ref_null"] = -20] = "ref_null"; + TypeKind[TypeKind["ref"] = -21] = "ref"; + TypeKind[TypeKind["i31ref"] = -22] = "i31ref"; + TypeKind[TypeKind["nullexternref"] = -23] = "nullexternref"; + TypeKind[TypeKind["nullfuncref"] = -24] = "nullfuncref"; + TypeKind[TypeKind["structref"] = -25] = "structref"; + TypeKind[TypeKind["arrayref"] = -26] = "arrayref"; + TypeKind[TypeKind["nullref"] = -27] = "nullref"; + TypeKind[TypeKind["func"] = -32] = "func"; + TypeKind[TypeKind["struct"] = -33] = "struct"; + TypeKind[TypeKind["array"] = -34] = "array"; + TypeKind[TypeKind["subtype"] = -48] = "subtype"; + TypeKind[TypeKind["rec_group"] = -49] = "rec_group"; + TypeKind[TypeKind["subtype_final"] = -50] = "subtype_final"; + TypeKind[TypeKind["empty_block_type"] = -64] = "empty_block_type"; +})(TypeKind = exports.TypeKind || (exports.TypeKind = {})); +var FieldDef = /** @class */ (function () { + function FieldDef() { + } + return FieldDef; +}()); +exports.FieldDef = FieldDef; +var FuncDef = /** @class */ (function () { + function FuncDef() { + } + return FuncDef; +}()); +exports.FuncDef = FuncDef; +var Type = exports.Type = /** @class */ (function () { + function Type(code) { + this.code = code; + } + Object.defineProperty(Type.prototype, "isIndex", { + get: function () { + return this.code >= 0; + }, + enumerable: false, + configurable: true + }); + Object.defineProperty(Type.prototype, "kind", { + get: function () { + return this.code >= 0 ? 0 /* TypeKind.unspecified */ : this.code; + }, + enumerable: false, + configurable: true + }); + Object.defineProperty(Type.prototype, "index", { + get: function () { + return this.code < 0 ? -1 : this.code; + }, + enumerable: false, + configurable: true + }); + // Convenience singletons. + Type.funcref = new Type(-16 /* TypeKind.funcref */); + Type.externref = new Type(-17 /* TypeKind.externref */); + return Type; +}()); +var RefType = /** @class */ (function (_super) { + __extends(RefType, _super); + function RefType(kind, ref_index) { + var _this = this; + if (kind != -21 /* TypeKind.ref */ && kind !== -20 /* TypeKind.ref_null */) { + throw new Error("Unexpected type kind: ".concat(kind, "}")); + } + _this = _super.call(this, kind) || this; + _this.ref_index = ref_index; + return _this; + } + Object.defineProperty(RefType.prototype, "isNullable", { + get: function () { + return this.kind == -20 /* TypeKind.ref_null */; + }, + enumerable: false, + configurable: true + }); + return RefType; +}(Type)); +exports.RefType = RefType; +var RelocType; +(function (RelocType) { + RelocType[RelocType["FunctionIndex_LEB"] = 0] = "FunctionIndex_LEB"; + RelocType[RelocType["TableIndex_SLEB"] = 1] = "TableIndex_SLEB"; + RelocType[RelocType["TableIndex_I32"] = 2] = "TableIndex_I32"; + RelocType[RelocType["GlobalAddr_LEB"] = 3] = "GlobalAddr_LEB"; + RelocType[RelocType["GlobalAddr_SLEB"] = 4] = "GlobalAddr_SLEB"; + RelocType[RelocType["GlobalAddr_I32"] = 5] = "GlobalAddr_I32"; + RelocType[RelocType["TypeIndex_LEB"] = 6] = "TypeIndex_LEB"; + RelocType[RelocType["GlobalIndex_LEB"] = 7] = "GlobalIndex_LEB"; +})(RelocType = exports.RelocType || (exports.RelocType = {})); +var LinkingType; +(function (LinkingType) { + LinkingType[LinkingType["StackPointer"] = 1] = "StackPointer"; +})(LinkingType = exports.LinkingType || (exports.LinkingType = {})); +var NameType; +(function (NameType) { + NameType[NameType["Module"] = 0] = "Module"; + NameType[NameType["Function"] = 1] = "Function"; + NameType[NameType["Local"] = 2] = "Local"; + NameType[NameType["Label"] = 3] = "Label"; + NameType[NameType["Type"] = 4] = "Type"; + NameType[NameType["Table"] = 5] = "Table"; + NameType[NameType["Memory"] = 6] = "Memory"; + NameType[NameType["Global"] = 7] = "Global"; + NameType[NameType["Elem"] = 8] = "Elem"; + NameType[NameType["Data"] = 9] = "Data"; + NameType[NameType["Field"] = 10] = "Field"; + NameType[NameType["Tag"] = 11] = "Tag"; +})(NameType = exports.NameType || (exports.NameType = {})); +var BinaryReaderState; +(function (BinaryReaderState) { + BinaryReaderState[BinaryReaderState["ERROR"] = -1] = "ERROR"; + BinaryReaderState[BinaryReaderState["INITIAL"] = 0] = "INITIAL"; + BinaryReaderState[BinaryReaderState["BEGIN_WASM"] = 1] = "BEGIN_WASM"; + BinaryReaderState[BinaryReaderState["END_WASM"] = 2] = "END_WASM"; + BinaryReaderState[BinaryReaderState["BEGIN_SECTION"] = 3] = "BEGIN_SECTION"; + BinaryReaderState[BinaryReaderState["END_SECTION"] = 4] = "END_SECTION"; + BinaryReaderState[BinaryReaderState["SKIPPING_SECTION"] = 5] = "SKIPPING_SECTION"; + BinaryReaderState[BinaryReaderState["READING_SECTION_RAW_DATA"] = 6] = "READING_SECTION_RAW_DATA"; + BinaryReaderState[BinaryReaderState["SECTION_RAW_DATA"] = 7] = "SECTION_RAW_DATA"; + BinaryReaderState[BinaryReaderState["TYPE_SECTION_ENTRY"] = 11] = "TYPE_SECTION_ENTRY"; + BinaryReaderState[BinaryReaderState["IMPORT_SECTION_ENTRY"] = 12] = "IMPORT_SECTION_ENTRY"; + BinaryReaderState[BinaryReaderState["FUNCTION_SECTION_ENTRY"] = 13] = "FUNCTION_SECTION_ENTRY"; + BinaryReaderState[BinaryReaderState["TABLE_SECTION_ENTRY"] = 14] = "TABLE_SECTION_ENTRY"; + BinaryReaderState[BinaryReaderState["MEMORY_SECTION_ENTRY"] = 15] = "MEMORY_SECTION_ENTRY"; + BinaryReaderState[BinaryReaderState["GLOBAL_SECTION_ENTRY"] = 16] = "GLOBAL_SECTION_ENTRY"; + BinaryReaderState[BinaryReaderState["EXPORT_SECTION_ENTRY"] = 17] = "EXPORT_SECTION_ENTRY"; + BinaryReaderState[BinaryReaderState["DATA_SECTION_ENTRY"] = 18] = "DATA_SECTION_ENTRY"; + BinaryReaderState[BinaryReaderState["NAME_SECTION_ENTRY"] = 19] = "NAME_SECTION_ENTRY"; + BinaryReaderState[BinaryReaderState["ELEMENT_SECTION_ENTRY"] = 20] = "ELEMENT_SECTION_ENTRY"; + BinaryReaderState[BinaryReaderState["LINKING_SECTION_ENTRY"] = 21] = "LINKING_SECTION_ENTRY"; + BinaryReaderState[BinaryReaderState["START_SECTION_ENTRY"] = 22] = "START_SECTION_ENTRY"; + BinaryReaderState[BinaryReaderState["TAG_SECTION_ENTRY"] = 23] = "TAG_SECTION_ENTRY"; + BinaryReaderState[BinaryReaderState["BEGIN_INIT_EXPRESSION_BODY"] = 25] = "BEGIN_INIT_EXPRESSION_BODY"; + BinaryReaderState[BinaryReaderState["INIT_EXPRESSION_OPERATOR"] = 26] = "INIT_EXPRESSION_OPERATOR"; + BinaryReaderState[BinaryReaderState["END_INIT_EXPRESSION_BODY"] = 27] = "END_INIT_EXPRESSION_BODY"; + BinaryReaderState[BinaryReaderState["BEGIN_FUNCTION_BODY"] = 28] = "BEGIN_FUNCTION_BODY"; + BinaryReaderState[BinaryReaderState["READING_FUNCTION_HEADER"] = 29] = "READING_FUNCTION_HEADER"; + BinaryReaderState[BinaryReaderState["CODE_OPERATOR"] = 30] = "CODE_OPERATOR"; + BinaryReaderState[BinaryReaderState["END_FUNCTION_BODY"] = 31] = "END_FUNCTION_BODY"; + BinaryReaderState[BinaryReaderState["SKIPPING_FUNCTION_BODY"] = 32] = "SKIPPING_FUNCTION_BODY"; + BinaryReaderState[BinaryReaderState["BEGIN_ELEMENT_SECTION_ENTRY"] = 33] = "BEGIN_ELEMENT_SECTION_ENTRY"; + BinaryReaderState[BinaryReaderState["ELEMENT_SECTION_ENTRY_BODY"] = 34] = "ELEMENT_SECTION_ENTRY_BODY"; + BinaryReaderState[BinaryReaderState["END_ELEMENT_SECTION_ENTRY"] = 35] = "END_ELEMENT_SECTION_ENTRY"; + BinaryReaderState[BinaryReaderState["BEGIN_DATA_SECTION_ENTRY"] = 36] = "BEGIN_DATA_SECTION_ENTRY"; + BinaryReaderState[BinaryReaderState["DATA_SECTION_ENTRY_BODY"] = 37] = "DATA_SECTION_ENTRY_BODY"; + BinaryReaderState[BinaryReaderState["END_DATA_SECTION_ENTRY"] = 38] = "END_DATA_SECTION_ENTRY"; + BinaryReaderState[BinaryReaderState["BEGIN_GLOBAL_SECTION_ENTRY"] = 39] = "BEGIN_GLOBAL_SECTION_ENTRY"; + BinaryReaderState[BinaryReaderState["END_GLOBAL_SECTION_ENTRY"] = 40] = "END_GLOBAL_SECTION_ENTRY"; + BinaryReaderState[BinaryReaderState["RELOC_SECTION_HEADER"] = 41] = "RELOC_SECTION_HEADER"; + BinaryReaderState[BinaryReaderState["RELOC_SECTION_ENTRY"] = 42] = "RELOC_SECTION_ENTRY"; + BinaryReaderState[BinaryReaderState["SOURCE_MAPPING_URL"] = 43] = "SOURCE_MAPPING_URL"; + BinaryReaderState[BinaryReaderState["BEGIN_OFFSET_EXPRESSION_BODY"] = 44] = "BEGIN_OFFSET_EXPRESSION_BODY"; + BinaryReaderState[BinaryReaderState["OFFSET_EXPRESSION_OPERATOR"] = 45] = "OFFSET_EXPRESSION_OPERATOR"; + BinaryReaderState[BinaryReaderState["END_OFFSET_EXPRESSION_BODY"] = 46] = "END_OFFSET_EXPRESSION_BODY"; + BinaryReaderState[BinaryReaderState["BEGIN_REC_GROUP"] = 47] = "BEGIN_REC_GROUP"; + BinaryReaderState[BinaryReaderState["END_REC_GROUP"] = 48] = "END_REC_GROUP"; + BinaryReaderState[BinaryReaderState["DATA_COUNT_SECTION_ENTRY"] = 49] = "DATA_COUNT_SECTION_ENTRY"; +})(BinaryReaderState = exports.BinaryReaderState || (exports.BinaryReaderState = {})); +var DataSegmentType; +(function (DataSegmentType) { + DataSegmentType[DataSegmentType["Active"] = 0] = "Active"; + DataSegmentType[DataSegmentType["Passive"] = 1] = "Passive"; + DataSegmentType[DataSegmentType["ActiveWithMemoryIndex"] = 2] = "ActiveWithMemoryIndex"; +})(DataSegmentType || (DataSegmentType = {})); +function isActiveDataSegmentType(segmentType) { + switch (segmentType) { + case 0 /* DataSegmentType.Active */: + case 2 /* DataSegmentType.ActiveWithMemoryIndex */: + return true; + default: + return false; + } +} +var DataMode; +(function (DataMode) { + DataMode[DataMode["Active"] = 0] = "Active"; + DataMode[DataMode["Passive"] = 1] = "Passive"; +})(DataMode = exports.DataMode || (exports.DataMode = {})); +var ElementSegmentType; +(function (ElementSegmentType) { + ElementSegmentType[ElementSegmentType["LegacyActiveFuncrefExternval"] = 0] = "LegacyActiveFuncrefExternval"; + ElementSegmentType[ElementSegmentType["PassiveExternval"] = 1] = "PassiveExternval"; + ElementSegmentType[ElementSegmentType["ActiveExternval"] = 2] = "ActiveExternval"; + ElementSegmentType[ElementSegmentType["DeclaredExternval"] = 3] = "DeclaredExternval"; + ElementSegmentType[ElementSegmentType["LegacyActiveFuncrefElemexpr"] = 4] = "LegacyActiveFuncrefElemexpr"; + ElementSegmentType[ElementSegmentType["PassiveElemexpr"] = 5] = "PassiveElemexpr"; + ElementSegmentType[ElementSegmentType["ActiveElemexpr"] = 6] = "ActiveElemexpr"; + ElementSegmentType[ElementSegmentType["DeclaredElemexpr"] = 7] = "DeclaredElemexpr"; +})(ElementSegmentType || (ElementSegmentType = {})); +function isActiveElementSegmentType(segmentType) { + switch (segmentType) { + case 0 /* ElementSegmentType.LegacyActiveFuncrefExternval */: + case 2 /* ElementSegmentType.ActiveExternval */: + case 4 /* ElementSegmentType.LegacyActiveFuncrefElemexpr */: + case 6 /* ElementSegmentType.ActiveElemexpr */: + return true; + default: + return false; + } +} +function isExternvalElementSegmentType(segmentType) { + switch (segmentType) { + case 0 /* ElementSegmentType.LegacyActiveFuncrefExternval */: + case 1 /* ElementSegmentType.PassiveExternval */: + case 2 /* ElementSegmentType.ActiveExternval */: + case 3 /* ElementSegmentType.DeclaredExternval */: + return true; + default: + return false; + } +} +var ElementMode; +(function (ElementMode) { + ElementMode[ElementMode["Active"] = 0] = "Active"; + ElementMode[ElementMode["Passive"] = 1] = "Passive"; + ElementMode[ElementMode["Declarative"] = 2] = "Declarative"; +})(ElementMode = exports.ElementMode || (exports.ElementMode = {})); +var DataRange = /** @class */ (function () { + function DataRange(start, end) { + this.start = start; + this.end = end; + } + DataRange.prototype.offset = function (delta) { + this.start += delta; + this.end += delta; + }; + return DataRange; +}()); +var TagAttribute; +(function (TagAttribute) { + TagAttribute[TagAttribute["Exception"] = 0] = "Exception"; +})(TagAttribute = exports.TagAttribute || (exports.TagAttribute = {})); +var Int64 = /** @class */ (function () { + function Int64(data) { + this._data = data || new Uint8Array(8); + } + Int64.prototype.toInt32 = function () { + return (this._data[0] | + (this._data[1] << 8) | + (this._data[2] << 16) | + (this._data[3] << 24)); + }; + Int64.prototype.toDouble = function () { + var power = 1; + var sum; + if (this._data[7] & 0x80) { + sum = -1; + for (var i = 0; i < 8; i++, power *= 256) + sum -= power * (0xff ^ this._data[i]); + } + else { + sum = 0; + for (var i = 0; i < 8; i++, power *= 256) + sum += power * this._data[i]; + } + return sum; + }; + Int64.prototype.toString = function () { + var low = (this._data[0] | + (this._data[1] << 8) | + (this._data[2] << 16) | + (this._data[3] << 24)) >>> + 0; + var high = (this._data[4] | + (this._data[5] << 8) | + (this._data[6] << 16) | + (this._data[7] << 24)) >>> + 0; + if (low === 0 && high === 0) { + return "0"; + } + var sign = false; + if (high >> 31) { + high = 4294967296 - high; + if (low > 0) { + high--; + low = 4294967296 - low; + } + sign = true; + } + var buf = []; + while (high > 0) { + var t = (high % 10) * 4294967296 + low; + high = Math.floor(high / 10); + buf.unshift((t % 10).toString()); + low = Math.floor(t / 10); + } + while (low > 0) { + buf.unshift((low % 10).toString()); + low = Math.floor(low / 10); + } + if (sign) + buf.unshift("-"); + return buf.join(""); + }; + Object.defineProperty(Int64.prototype, "data", { + get: function () { + return this._data; + }, + enumerable: false, + configurable: true + }); + return Int64; +}()); +exports.Int64 = Int64; +var BinaryReader = /** @class */ (function () { + function BinaryReader() { + this._data = null; + this._pos = 0; + this._length = 0; + this._eof = false; + this.state = 0 /* BinaryReaderState.INITIAL */; + this.result = null; + this.error = null; + this._sectionEntriesLeft = 0; + this._sectionId = -1 /* SectionCode.Unknown */; + this._sectionRange = null; + this._functionRange = null; + this._segmentType = 0; + this._segmentEntriesLeft = 0; + this._recGroupTypesLeft = 0; + } + Object.defineProperty(BinaryReader.prototype, "data", { + get: function () { + return this._data; + }, + enumerable: false, + configurable: true + }); + Object.defineProperty(BinaryReader.prototype, "position", { + get: function () { + return this._pos; + }, + enumerable: false, + configurable: true + }); + Object.defineProperty(BinaryReader.prototype, "length", { + get: function () { + return this._length; + }, + enumerable: false, + configurable: true + }); + BinaryReader.prototype.setData = function (buffer, pos, length, eof) { + var posDelta = pos - this._pos; + this._data = new Uint8Array(buffer); + this._pos = pos; + this._length = length; + this._eof = eof === undefined ? true : eof; + if (this._sectionRange) + this._sectionRange.offset(posDelta); + if (this._functionRange) + this._functionRange.offset(posDelta); + }; + BinaryReader.prototype.hasBytes = function (n) { + return this._pos + n <= this._length; + }; + BinaryReader.prototype.hasMoreBytes = function () { + return this.hasBytes(1); + }; + BinaryReader.prototype.readUint8 = function () { + return this._data[this._pos++]; + }; + BinaryReader.prototype.readInt32 = function () { + var b1 = this._data[this._pos++]; + var b2 = this._data[this._pos++]; + var b3 = this._data[this._pos++]; + var b4 = this._data[this._pos++]; + return b1 | (b2 << 8) | (b3 << 16) | (b4 << 24); + }; + BinaryReader.prototype.readUint32 = function () { + return this.readInt32(); + }; + BinaryReader.prototype.peekInt32 = function () { + var b1 = this._data[this._pos]; + var b2 = this._data[this._pos + 1]; + var b3 = this._data[this._pos + 2]; + var b4 = this._data[this._pos + 3]; + return b1 | (b2 << 8) | (b3 << 16) | (b4 << 24); + }; + BinaryReader.prototype.hasVarIntBytes = function () { + var pos = this._pos; + while (pos < this._length) { + if ((this._data[pos++] & 0x80) == 0) + return true; + } + return false; + }; + BinaryReader.prototype.readVarUint1 = function () { + return this.readUint8(); + }; + BinaryReader.prototype.readVarInt7 = function () { + return (this.readUint8() << 25) >> 25; + }; + BinaryReader.prototype.readVarUint7 = function () { + return this.readUint8(); + }; + BinaryReader.prototype.readVarInt32 = function () { + var result = 0; + var shift = 0; + while (true) { + var byte = this.readUint8(); + result |= (byte & 0x7f) << shift; + shift += 7; + if ((byte & 0x80) === 0) + break; + } + if (shift >= 32) + return result; + var ashift = 32 - shift; + return (result << ashift) >> ashift; + }; + BinaryReader.prototype.readVarUint32 = function () { + var result = 0; + var shift = 0; + while (true) { + var byte = this.readUint8(); + result |= (byte & 0x7f) << shift; + shift += 7; + if ((byte & 0x80) === 0) + break; + } + return result >>> 0; + }; + BinaryReader.prototype.readVarInt64 = function () { + var result = new Uint8Array(8); + var i = 0; + var c = 0; + var shift = 0; + while (true) { + var byte = this.readUint8(); + c |= (byte & 0x7f) << shift; + shift += 7; + if (shift > 8) { + result[i++] = c & 0xff; + c >>= 8; + shift -= 8; + } + if ((byte & 0x80) === 0) + break; + } + var ashift = 32 - shift; + c = (c << ashift) >> ashift; + while (i < 8) { + result[i++] = c & 0xff; + c >>= 8; + } + return new Int64(result); + }; + // Reads any "s33" (signed 33-bit integer) value correctly; no guarantees + // outside that range. + BinaryReader.prototype.readHeapType = function () { + var lsb = this.readUint8(); + if (lsb & 0x80) { + // Has more data than one byte. + var tail = this.readVarInt32(); + return (tail - 1) * 128 + lsb; + } + else { + return (lsb << 25) >> 25; + } + }; + BinaryReader.prototype.readType = function () { + var kind = this.readHeapType(); + if (kind >= 0) { + return new Type(kind); + } + switch (kind) { + case -20 /* TypeKind.ref_null */: + case -21 /* TypeKind.ref */: + var index = this.readHeapType(); + return new RefType(kind, index); + case -1 /* TypeKind.i32 */: + case -2 /* TypeKind.i64 */: + case -3 /* TypeKind.f32 */: + case -4 /* TypeKind.f64 */: + case -5 /* TypeKind.v128 */: + case -6 /* TypeKind.i8 */: + case -7 /* TypeKind.i16 */: + case -16 /* TypeKind.funcref */: + case -17 /* TypeKind.externref */: + case -18 /* TypeKind.anyref */: + case -19 /* TypeKind.eqref */: + case -22 /* TypeKind.i31ref */: + case -23 /* TypeKind.nullexternref */: + case -24 /* TypeKind.nullfuncref */: + case -25 /* TypeKind.structref */: + case -26 /* TypeKind.arrayref */: + case -27 /* TypeKind.nullref */: + case -32 /* TypeKind.func */: + case -33 /* TypeKind.struct */: + case -34 /* TypeKind.array */: + case -48 /* TypeKind.subtype */: + case -49 /* TypeKind.rec_group */: + case -50 /* TypeKind.subtype_final */: + case -64 /* TypeKind.empty_block_type */: + return new Type(kind); + default: + throw new Error("Unknown type kind: ".concat(kind)); + } + }; + BinaryReader.prototype.readStringBytes = function () { + var length = this.readVarUint32(); + return this.readBytes(length); + }; + BinaryReader.prototype.readBytes = function (length) { + var result = this._data.subarray(this._pos, this._pos + length); + this._pos += length; + return new Uint8Array(result); // making a clone of the data + }; + BinaryReader.prototype.skipBytes = function (length) { + this._pos += length; + }; + BinaryReader.prototype.hasStringBytes = function () { + if (!this.hasVarIntBytes()) + return false; + var pos = this._pos; + var length = this.readVarUint32(); + var result = this.hasBytes(length); + this._pos = pos; + return result; + }; + BinaryReader.prototype.hasSectionPayload = function () { + return this.hasBytes(this._sectionRange.end - this._pos); + }; + BinaryReader.prototype.readFuncType = function () { + var paramCount = this.readVarUint32(); + var paramTypes = new Array(paramCount); + for (var i = 0; i < paramCount; i++) + paramTypes[i] = this.readType(); + var returnCount = this.readVarUint32(); + var returnTypes = new Array(returnCount); + for (var i = 0; i < returnCount; i++) + returnTypes[i] = this.readType(); + return { + form: -32 /* TypeKind.func */, + params: paramTypes, + returns: returnTypes, + }; + }; + BinaryReader.prototype.readBaseType = function () { + var form = this.readVarInt7(); + switch (form) { + case -32 /* TypeKind.func */: + return this.readFuncType(); + case -33 /* TypeKind.struct */: + return this.readStructType(); + case -34 /* TypeKind.array */: + return this.readArrayType(); + default: + throw new Error("Unknown type kind: ".concat(form)); + } + }; + BinaryReader.prototype.readSubtype = function (final) { + var supertypesCount = this.readVarUint32(); + var supertypes = new Array(supertypesCount); + for (var i = 0; i < supertypesCount; i++) { + supertypes[i] = this.readHeapType(); + } + var result = this.readBaseType(); + result.supertypes = supertypes; + result.final = final; + return result; + }; + BinaryReader.prototype.readStructType = function () { + var fieldCount = this.readVarUint32(); + var fieldTypes = new Array(fieldCount); + var fieldMutabilities = new Array(fieldCount); + for (var i = 0; i < fieldCount; i++) { + fieldTypes[i] = this.readType(); + fieldMutabilities[i] = !!this.readVarUint1(); + } + return { + form: -33 /* TypeKind.struct */, + fields: fieldTypes, + mutabilities: fieldMutabilities, + }; + }; + BinaryReader.prototype.readArrayType = function () { + var elementType = this.readType(); + var mutability = !!this.readVarUint1(); + return { + form: -34 /* TypeKind.array */, + elementType: elementType, + mutability: mutability, + }; + }; + BinaryReader.prototype.readResizableLimits = function (maxPresent) { + var initial = this.readVarUint32(); + var maximum; + if (maxPresent) { + maximum = this.readVarUint32(); + } + return { initial: initial, maximum: maximum }; + }; + BinaryReader.prototype.readTableType = function () { + var elementType = this.readType(); + var flags = this.readVarUint32(); + var limits = this.readResizableLimits(!!(flags & 0x01)); + return { elementType: elementType, limits: limits }; + }; + BinaryReader.prototype.readMemoryType = function () { + var flags = this.readVarUint32(); + var shared = !!(flags & 0x02); + return { + limits: this.readResizableLimits(!!(flags & 0x01)), + shared: shared, + }; + }; + BinaryReader.prototype.readGlobalType = function () { + if (!this.hasVarIntBytes()) { + return null; + } + var pos = this._pos; + var contentType = this.readType(); + if (!this.hasVarIntBytes()) { + this._pos = pos; + return null; + } + var mutability = this.readVarUint1(); + return { contentType: contentType, mutability: mutability }; + }; + BinaryReader.prototype.readTagType = function () { + var attribute = this.readVarUint32(); + var typeIndex = this.readVarUint32(); + return { + attribute: attribute, + typeIndex: typeIndex, + }; + }; + BinaryReader.prototype.readTypeEntryCommon = function (form) { + switch (form) { + case -32 /* TypeKind.func */: + this.result = this.readFuncType(); + break; + case -48 /* TypeKind.subtype */: + this.result = this.readSubtype(false); + break; + case -50 /* TypeKind.subtype_final */: + this.result = this.readSubtype(true); + break; + case -33 /* TypeKind.struct */: + this.result = this.readStructType(); + break; + case -34 /* TypeKind.array */: + this.result = this.readArrayType(); + break; + case -1 /* TypeKind.i32 */: + case -2 /* TypeKind.i64 */: + case -3 /* TypeKind.f32 */: + case -4 /* TypeKind.f64 */: + case -5 /* TypeKind.v128 */: + case -6 /* TypeKind.i8 */: + case -7 /* TypeKind.i16 */: + case -16 /* TypeKind.funcref */: + case -17 /* TypeKind.externref */: + case -18 /* TypeKind.anyref */: + case -19 /* TypeKind.eqref */: + this.result = { + form: form, + }; + break; + default: + throw new Error("Unknown type kind: ".concat(form)); + } + }; + BinaryReader.prototype.readTypeEntry = function () { + if (this._sectionEntriesLeft === 0) { + this.skipSection(); + return this.read(); + } + var form = this.readVarInt7(); + if (form == -49 /* TypeKind.rec_group */) { + this.state = 47 /* BinaryReaderState.BEGIN_REC_GROUP */; + this.result = null; + this._recGroupTypesLeft = this.readVarUint32(); + } + else { + this.state = 11 /* BinaryReaderState.TYPE_SECTION_ENTRY */; + this.readTypeEntryCommon(form); + this._sectionEntriesLeft--; + } + return true; + }; + BinaryReader.prototype.readRecGroupEntry = function () { + if (this._recGroupTypesLeft === 0) { + this.state = 48 /* BinaryReaderState.END_REC_GROUP */; + this.result = null; + this._sectionEntriesLeft--; + this._recGroupTypesLeft = -1; + return true; + } + this.state = 11 /* BinaryReaderState.TYPE_SECTION_ENTRY */; + var form = this.readVarInt7(); + this.readTypeEntryCommon(form); + this._recGroupTypesLeft--; + return true; + }; + BinaryReader.prototype.readImportEntry = function () { + if (this._sectionEntriesLeft === 0) { + this.skipSection(); + return this.read(); + } + this.state = 12 /* BinaryReaderState.IMPORT_SECTION_ENTRY */; + var module = this.readStringBytes(); + var field = this.readStringBytes(); + var kind = this.readUint8(); + var funcTypeIndex; + var type; + switch (kind) { + case 0 /* ExternalKind.Function */: + funcTypeIndex = this.readVarUint32(); + break; + case 1 /* ExternalKind.Table */: + type = this.readTableType(); + break; + case 2 /* ExternalKind.Memory */: + type = this.readMemoryType(); + break; + case 3 /* ExternalKind.Global */: + type = this.readGlobalType(); + break; + case 4 /* ExternalKind.Tag */: + type = this.readTagType(); + break; + } + this.result = { + module: module, + field: field, + kind: kind, + funcTypeIndex: funcTypeIndex, + type: type, + }; + this._sectionEntriesLeft--; + return true; + }; + BinaryReader.prototype.readExportEntry = function () { + if (this._sectionEntriesLeft === 0) { + this.skipSection(); + return this.read(); + } + var field = this.readStringBytes(); + var kind = this.readUint8(); + var index = this.readVarUint32(); + this.state = 17 /* BinaryReaderState.EXPORT_SECTION_ENTRY */; + this.result = { field: field, kind: kind, index: index }; + this._sectionEntriesLeft--; + return true; + }; + BinaryReader.prototype.readFunctionEntry = function () { + if (this._sectionEntriesLeft === 0) { + this.skipSection(); + return this.read(); + } + var typeIndex = this.readVarUint32(); + this.state = 13 /* BinaryReaderState.FUNCTION_SECTION_ENTRY */; + this.result = { typeIndex: typeIndex }; + this._sectionEntriesLeft--; + return true; + }; + BinaryReader.prototype.readTableEntry = function () { + if (this._sectionEntriesLeft === 0) { + this.skipSection(); + return this.read(); + } + this.state = 14 /* BinaryReaderState.TABLE_SECTION_ENTRY */; + this.result = this.readTableType(); + this._sectionEntriesLeft--; + return true; + }; + BinaryReader.prototype.readMemoryEntry = function () { + if (this._sectionEntriesLeft === 0) { + this.skipSection(); + return this.read(); + } + this.state = 15 /* BinaryReaderState.MEMORY_SECTION_ENTRY */; + this.result = this.readMemoryType(); + this._sectionEntriesLeft--; + return true; + }; + BinaryReader.prototype.readTagEntry = function () { + if (this._sectionEntriesLeft === 0) { + this.skipSection(); + return this.read(); + } + this.state = 23 /* BinaryReaderState.TAG_SECTION_ENTRY */; + this.result = this.readTagType(); + this._sectionEntriesLeft--; + return true; + }; + BinaryReader.prototype.readGlobalEntry = function () { + if (this._sectionEntriesLeft === 0) { + this.skipSection(); + return this.read(); + } + var globalType = this.readGlobalType(); + if (!globalType) { + this.state = 16 /* BinaryReaderState.GLOBAL_SECTION_ENTRY */; + return false; + } + this.state = 39 /* BinaryReaderState.BEGIN_GLOBAL_SECTION_ENTRY */; + this.result = { + type: globalType, + }; + this._sectionEntriesLeft--; + return true; + }; + BinaryReader.prototype.readElementEntry = function () { + if (this._sectionEntriesLeft === 0) { + this.skipSection(); + return this.read(); + } + var pos = this._pos; + if (!this.hasMoreBytes()) { + this.state = 20 /* BinaryReaderState.ELEMENT_SECTION_ENTRY */; + return false; + } + var segmentType = this.readUint8(); + var mode, tableIndex; + switch (segmentType) { + case 0 /* ElementSegmentType.LegacyActiveFuncrefExternval */: + case 4 /* ElementSegmentType.LegacyActiveFuncrefElemexpr */: + mode = 0 /* ElementMode.Active */; + tableIndex = 0; + break; + case 1 /* ElementSegmentType.PassiveExternval */: + case 5 /* ElementSegmentType.PassiveElemexpr */: + mode = 1 /* ElementMode.Passive */; + break; + case 2 /* ElementSegmentType.ActiveExternval */: + case 6 /* ElementSegmentType.ActiveElemexpr */: + mode = 0 /* ElementMode.Active */; + if (!this.hasVarIntBytes()) { + this.state = 20 /* BinaryReaderState.ELEMENT_SECTION_ENTRY */; + this._pos = pos; + return false; + } + tableIndex = this.readVarUint32(); + break; + case 3 /* ElementSegmentType.DeclaredExternval */: + case 7 /* ElementSegmentType.DeclaredElemexpr */: + mode = 2 /* ElementMode.Declarative */; + break; + default: + throw new Error("Unsupported element segment type ".concat(segmentType)); + } + this.state = 33 /* BinaryReaderState.BEGIN_ELEMENT_SECTION_ENTRY */; + this.result = { mode: mode, tableIndex: tableIndex }; + this._sectionEntriesLeft--; + this._segmentType = segmentType; + return true; + }; + BinaryReader.prototype.readElementEntryBody = function () { + var elementType = Type.funcref; + switch (this._segmentType) { + case 1 /* ElementSegmentType.PassiveExternval */: + case 2 /* ElementSegmentType.ActiveExternval */: + case 3 /* ElementSegmentType.DeclaredExternval */: + if (!this.hasMoreBytes()) + return false; + // We just skip the 0x00 byte, the `elemkind` byte + // is reserved for future versions of WebAssembly. + this.skipBytes(1); + break; + case 5 /* ElementSegmentType.PassiveElemexpr */: + case 6 /* ElementSegmentType.ActiveElemexpr */: + case 7 /* ElementSegmentType.DeclaredElemexpr */: + if (!this.hasMoreBytes()) + return false; + elementType = this.readType(); + break; + case 0 /* ElementSegmentType.LegacyActiveFuncrefExternval */: + case 4 /* ElementSegmentType.LegacyActiveFuncrefElemexpr */: + // The element type is implicitly `funcref`. + break; + default: + throw new Error("Unsupported element segment type ".concat(this._segmentType)); + } + this.state = 34 /* BinaryReaderState.ELEMENT_SECTION_ENTRY_BODY */; + this.result = { elementType: elementType }; + return true; + }; + BinaryReader.prototype.readDataEntry = function () { + if (this._sectionEntriesLeft === 0) { + this.skipSection(); + return this.read(); + } + var pos = this._pos; + if (!this.hasVarIntBytes()) { + this.state = 18 /* BinaryReaderState.DATA_SECTION_ENTRY */; + return false; + } + var segmentType = this.readVarUint32(); + var mode, memoryIndex; + switch (segmentType) { + case 0 /* DataSegmentType.Active */: + mode = 0 /* DataMode.Active */; + memoryIndex = 0; + break; + case 1 /* DataSegmentType.Passive */: + mode = 1 /* DataMode.Passive */; + break; + case 2 /* DataSegmentType.ActiveWithMemoryIndex */: + mode = 0 /* DataMode.Active */; + if (!this.hasVarIntBytes()) { + this._pos = pos; + this.state = 18 /* BinaryReaderState.DATA_SECTION_ENTRY */; + return false; + } + memoryIndex = this.readVarUint32(); + break; + default: + throw new Error("Unsupported data segment type ".concat(segmentType)); + } + this.state = 36 /* BinaryReaderState.BEGIN_DATA_SECTION_ENTRY */; + this.result = { mode: mode, memoryIndex: memoryIndex }; + this._sectionEntriesLeft--; + this._segmentType = segmentType; + return true; + }; + BinaryReader.prototype.readDataCountEntry = function () { + if (this._sectionEntriesLeft === 0) { + this.skipSection(); + return this.read(); + } + this.state = 49 /* BinaryReaderState.DATA_COUNT_SECTION_ENTRY */; + this.result = this.readVarUint32(); + this._sectionEntriesLeft--; + return true; + }; + BinaryReader.prototype.readDataEntryBody = function () { + if (!this.hasStringBytes()) { + return false; + } + this.state = 37 /* BinaryReaderState.DATA_SECTION_ENTRY_BODY */; + this.result = { + data: this.readStringBytes(), + }; + return true; + }; + BinaryReader.prototype.readInitExpressionBody = function () { + this.state = 25 /* BinaryReaderState.BEGIN_INIT_EXPRESSION_BODY */; + this.result = null; + return true; + }; + BinaryReader.prototype.readOffsetExpressionBody = function () { + this.state = 44 /* BinaryReaderState.BEGIN_OFFSET_EXPRESSION_BODY */; + this.result = null; + return true; + }; + BinaryReader.prototype.readMemoryImmediate = function () { + var flags = this.readVarUint32(); + var offset = this.readVarUint32(); + return { flags: flags, offset: offset }; + }; + BinaryReader.prototype.readNameMap = function () { + var count = this.readVarUint32(); + var result = []; + for (var i = 0; i < count; i++) { + var index = this.readVarUint32(); + var name = this.readStringBytes(); + result.push({ index: index, name: name }); + } + return result; + }; + BinaryReader.prototype.readNameEntry = function () { + var pos = this._pos; + if (pos >= this._sectionRange.end) { + this.skipSection(); + return this.read(); + } + if (!this.hasVarIntBytes()) + return false; + var type = this.readVarUint7(); + if (!this.hasVarIntBytes()) { + this._pos = pos; + return false; + } + var payloadLength = this.readVarUint32(); + if (!this.hasBytes(payloadLength)) { + this._pos = pos; + return false; + } + var result; + switch (type) { + case 0 /* NameType.Module */: + result = { + type: type, + moduleName: this.readStringBytes(), + }; + break; + case 1 /* NameType.Function */: + case 11 /* NameType.Tag */: + case 4 /* NameType.Type */: + case 5 /* NameType.Table */: + case 6 /* NameType.Memory */: + case 7 /* NameType.Global */: + result = { + type: type, + names: this.readNameMap(), + }; + break; + case 2 /* NameType.Local */: + var funcsLength = this.readVarUint32(); + var funcs = []; + for (var i = 0; i < funcsLength; i++) { + var funcIndex = this.readVarUint32(); + funcs.push({ + index: funcIndex, + locals: this.readNameMap(), + }); + } + result = { + type: type, + funcs: funcs, + }; + break; + case 10 /* NameType.Field */: + var typesLength = this.readVarUint32(); + var types = []; + for (var i = 0; i < typesLength; i++) { + var fieldIndex = this.readVarUint32(); + types.push({ + index: fieldIndex, + fields: this.readNameMap(), + }); + } + result = { + type: type, + types: types, + }; + break; + default: + // Skip this unknown name subsection (as per specification, + // custom section errors shouldn't cause Wasm parsing to fail). + this.skipBytes(payloadLength); + return this.read(); + } + this.state = 19 /* BinaryReaderState.NAME_SECTION_ENTRY */; + this.result = result; + return true; + }; + BinaryReader.prototype.readRelocHeader = function () { + // See https://github.com/WebAssembly/tool-conventions/blob/master/Linking.md + if (!this.hasVarIntBytes()) { + return false; + } + var pos = this._pos; + var sectionId = this.readVarUint7(); + var sectionName; + if (sectionId === 0 /* SectionCode.Custom */) { + if (!this.hasStringBytes()) { + this._pos = pos; + return false; + } + sectionName = this.readStringBytes(); + } + this.state = 41 /* BinaryReaderState.RELOC_SECTION_HEADER */; + this.result = { + id: sectionId, + name: sectionName, + }; + return true; + }; + BinaryReader.prototype.readLinkingEntry = function () { + if (this._sectionEntriesLeft === 0) { + this.skipSection(); + return this.read(); + } + if (!this.hasVarIntBytes()) + return false; + var pos = this._pos; + var type = this.readVarUint32(); + var index; + switch (type) { + case 1 /* LinkingType.StackPointer */: + if (!this.hasVarIntBytes()) { + this._pos = pos; + return false; + } + index = this.readVarUint32(); + break; + default: + this.error = new Error("Bad linking type: ".concat(type)); + this.state = -1 /* BinaryReaderState.ERROR */; + return true; + } + this.state = 21 /* BinaryReaderState.LINKING_SECTION_ENTRY */; + this.result = { type: type, index: index }; + this._sectionEntriesLeft--; + return true; + }; + BinaryReader.prototype.readSourceMappingURL = function () { + if (!this.hasStringBytes()) + return false; + var url = this.readStringBytes(); + this.state = 43 /* BinaryReaderState.SOURCE_MAPPING_URL */; + this.result = { url: url }; + return true; + }; + BinaryReader.prototype.readRelocEntry = function () { + if (this._sectionEntriesLeft === 0) { + this.skipSection(); + return this.read(); + } + if (!this.hasVarIntBytes()) + return false; + var pos = this._pos; + var type = this.readVarUint7(); + if (!this.hasVarIntBytes()) { + this._pos = pos; + return false; + } + var offset = this.readVarUint32(); + if (!this.hasVarIntBytes()) { + this._pos = pos; + return false; + } + var index = this.readVarUint32(); + var addend; + switch (type) { + case 0 /* RelocType.FunctionIndex_LEB */: + case 1 /* RelocType.TableIndex_SLEB */: + case 2 /* RelocType.TableIndex_I32 */: + case 6 /* RelocType.TypeIndex_LEB */: + case 7 /* RelocType.GlobalIndex_LEB */: + break; + case 3 /* RelocType.GlobalAddr_LEB */: + case 4 /* RelocType.GlobalAddr_SLEB */: + case 5 /* RelocType.GlobalAddr_I32 */: + if (!this.hasVarIntBytes()) { + this._pos = pos; + return false; + } + addend = this.readVarUint32(); + break; + default: + this.error = new Error("Bad relocation type: ".concat(type)); + this.state = -1 /* BinaryReaderState.ERROR */; + return true; + } + this.state = 42 /* BinaryReaderState.RELOC_SECTION_ENTRY */; + this.result = { + type: type, + offset: offset, + index: index, + addend: addend, + }; + this._sectionEntriesLeft--; + return true; + }; + BinaryReader.prototype.readCodeOperator_0xfb = function () { + // The longest instructions have: 2 bytes opcode, 5 bytes type index, + // 5 bytes field index. + var MAX_CODE_OPERATOR_0XFB_SIZE = 12; + if (!this._eof && !this.hasBytes(MAX_CODE_OPERATOR_0XFB_SIZE)) { + return false; + } + var code, brDepth, refType, srcType, fieldIndex, segmentIndex, len, literal; + code = this._data[this._pos++] | 0xfb00; + switch (code) { + case 64334 /* OperatorCode.br_on_cast */: + case 64335 /* OperatorCode.br_on_cast_fail */: + literal = this.readUint8(); + brDepth = this.readVarUint32(); + srcType = this.readHeapType(); + refType = this.readHeapType(); + break; + case 64322 /* OperatorCode.br_on_cast_ */: + case 64323 /* OperatorCode.br_on_cast_fail_ */: + brDepth = this.readVarUint32(); + refType = this.readHeapType(); + break; + case 64326 /* OperatorCode.br_on_cast__ */: + case 64327 /* OperatorCode.br_on_cast_fail__ */: + brDepth = this.readVarUint32(); + refType = this.readVarUint32(); + break; + case 64275 /* OperatorCode.array_get */: + case 64276 /* OperatorCode.array_get_s */: + case 64277 /* OperatorCode.array_get_u */: + case 64279 /* OperatorCode.array_len_ */: + case 64278 /* OperatorCode.array_set */: + case 64283 /* OperatorCode.array_new */: + case 64273 /* OperatorCode.array_new_with_rtt */: + case 64284 /* OperatorCode.array_new_default */: + case 64274 /* OperatorCode.array_new_default_with_rtt */: + case 64263 /* OperatorCode.struct_new */: + case 64257 /* OperatorCode.struct_new_with_rtt */: + case 64264 /* OperatorCode.struct_new_default */: + case 64258 /* OperatorCode.struct_new_default_with_rtt */: + case 64304 /* OperatorCode.rtt_canon */: + case 64305 /* OperatorCode.rtt_sub */: + case 64306 /* OperatorCode.rtt_fresh_sub */: + refType = this.readVarUint32(); + break; + case 64282 /* OperatorCode.array_new_fixed */: + refType = this.readVarUint32(); + len = this.readVarUint32(); + break; + case 64280 /* OperatorCode.array_copy */: + refType = this.readVarUint32(); + srcType = this.readVarUint32(); + break; + case 64259 /* OperatorCode.struct_get */: + case 64260 /* OperatorCode.struct_get_s */: + case 64261 /* OperatorCode.struct_get_u */: + case 64262 /* OperatorCode.struct_set */: + refType = this.readVarUint32(); + fieldIndex = this.readVarUint32(); + break; + case 64285 /* OperatorCode.array_new_data */: + case 64287 /* OperatorCode.array_new_elem */: + case 64340 /* OperatorCode.array_init_data */: + case 64341 /* OperatorCode.array_init_elem */: + refType = this.readVarUint32(); + segmentIndex = this.readVarUint32(); + break; + case 64320 /* OperatorCode.ref_test */: + case 64328 /* OperatorCode.ref_test_null */: + case 64321 /* OperatorCode.ref_cast */: + case 64329 /* OperatorCode.ref_cast_null */: + refType = this.readHeapType(); + break; + case 64324 /* OperatorCode.ref_test_ */: + case 64325 /* OperatorCode.ref_cast_ */: + refType = this.readVarUint32(); + break; + case 64281 /* OperatorCode.array_len */: + case 64369 /* OperatorCode.extern_externalize */: + case 64368 /* OperatorCode.extern_internalize */: + case 64288 /* OperatorCode.i31_new */: + case 64289 /* OperatorCode.i31_get_s */: + case 64290 /* OperatorCode.i31_get_u */: + break; + default: + this.error = new Error("Unknown operator: 0x".concat(code.toString(16).padStart(4, "0"))); + this.state = -1 /* BinaryReaderState.ERROR */; + return true; + } + this.result = { + code: code, + blockType: undefined, + refType: refType, + srcType: srcType, + brDepth: brDepth, + brTable: undefined, + tableIndex: undefined, + funcIndex: undefined, + typeIndex: undefined, + localIndex: undefined, + globalIndex: undefined, + fieldIndex: fieldIndex, + memoryAddress: undefined, + literal: literal, + segmentIndex: segmentIndex, + destinationIndex: undefined, + len: len, + lines: undefined, + lineIndex: undefined, + }; + return true; + }; + BinaryReader.prototype.readCodeOperator_0xfc = function () { + if (!this.hasVarIntBytes()) { + return false; + } + var code = this.readVarUint32() | 0xfc00; + var reserved, segmentIndex, destinationIndex, tableIndex; + switch (code) { + case 64512 /* OperatorCode.i32_trunc_sat_f32_s */: + case 64513 /* OperatorCode.i32_trunc_sat_f32_u */: + case 64514 /* OperatorCode.i32_trunc_sat_f64_s */: + case 64515 /* OperatorCode.i32_trunc_sat_f64_u */: + case 64516 /* OperatorCode.i64_trunc_sat_f32_s */: + case 64517 /* OperatorCode.i64_trunc_sat_f32_u */: + case 64518 /* OperatorCode.i64_trunc_sat_f64_s */: + case 64519 /* OperatorCode.i64_trunc_sat_f64_u */: + break; + case 64522 /* OperatorCode.memory_copy */: + // Currently memory index must be zero. + reserved = this.readVarUint1(); + reserved = this.readVarUint1(); + break; + case 64523 /* OperatorCode.memory_fill */: + reserved = this.readVarUint1(); + break; + case 64524 /* OperatorCode.table_init */: + segmentIndex = this.readVarUint32(); + tableIndex = this.readVarUint32(); + break; + case 64526 /* OperatorCode.table_copy */: + tableIndex = this.readVarUint32(); + destinationIndex = this.readVarUint32(); + break; + case 64527 /* OperatorCode.table_grow */: + case 64528 /* OperatorCode.table_size */: + case 64529 /* OperatorCode.table_fill */: + tableIndex = this.readVarUint32(); + break; + case 64520 /* OperatorCode.memory_init */: + segmentIndex = this.readVarUint32(); + reserved = this.readVarUint1(); + break; + case 64521 /* OperatorCode.data_drop */: + case 64525 /* OperatorCode.elem_drop */: + segmentIndex = this.readVarUint32(); + break; + default: + this.error = new Error("Unknown operator: 0x".concat(code.toString(16).padStart(4, "0"))); + this.state = -1 /* BinaryReaderState.ERROR */; + return true; + } + this.result = { + code: code, + blockType: undefined, + selectType: undefined, + refType: undefined, + srcType: undefined, + brDepth: undefined, + brTable: undefined, + funcIndex: undefined, + typeIndex: undefined, + tableIndex: tableIndex, + localIndex: undefined, + globalIndex: undefined, + fieldIndex: undefined, + memoryAddress: undefined, + literal: undefined, + segmentIndex: segmentIndex, + destinationIndex: destinationIndex, + len: undefined, + lines: undefined, + lineIndex: undefined, + }; + return true; + }; + BinaryReader.prototype.readCodeOperator_0xfd = function () { + var MAX_CODE_OPERATOR_0XFD_SIZE = 17; + var pos = this._pos; + if (!this._eof && pos + MAX_CODE_OPERATOR_0XFD_SIZE > this._length) { + return false; + } + if (!this.hasVarIntBytes()) { + return false; + } + var code = this.readVarUint32() | 0xfd00; + var memoryAddress; + var literal; + var lineIndex; + var lines; + switch (code) { + case 64768 /* OperatorCode.v128_load */: + case 64769 /* OperatorCode.i16x8_load8x8_s */: + case 64770 /* OperatorCode.i16x8_load8x8_u */: + case 64771 /* OperatorCode.i32x4_load16x4_s */: + case 64772 /* OperatorCode.i32x4_load16x4_u */: + case 64773 /* OperatorCode.i64x2_load32x2_s */: + case 64774 /* OperatorCode.i64x2_load32x2_u */: + case 64775 /* OperatorCode.v8x16_load_splat */: + case 64776 /* OperatorCode.v16x8_load_splat */: + case 64777 /* OperatorCode.v32x4_load_splat */: + case 64778 /* OperatorCode.v64x2_load_splat */: + case 64779 /* OperatorCode.v128_store */: + case 64860 /* OperatorCode.v128_load32_zero */: + case 64861 /* OperatorCode.v128_load64_zero */: + memoryAddress = this.readMemoryImmediate(); + break; + case 64780 /* OperatorCode.v128_const */: + literal = this.readBytes(16); + break; + case 64781 /* OperatorCode.i8x16_shuffle */: + lines = new Uint8Array(16); + for (var i = 0; i < lines.length; i++) { + lines[i] = this.readUint8(); + } + break; + case 64789 /* OperatorCode.i8x16_extract_lane_s */: + case 64790 /* OperatorCode.i8x16_extract_lane_u */: + case 64791 /* OperatorCode.i8x16_replace_lane */: + case 64792 /* OperatorCode.i16x8_extract_lane_s */: + case 64793 /* OperatorCode.i16x8_extract_lane_u */: + case 64794 /* OperatorCode.i16x8_replace_lane */: + case 64795 /* OperatorCode.i32x4_extract_lane */: + case 64796 /* OperatorCode.i32x4_replace_lane */: + case 64797 /* OperatorCode.i64x2_extract_lane */: + case 64798 /* OperatorCode.i64x2_replace_lane */: + case 64799 /* OperatorCode.f32x4_extract_lane */: + case 64800 /* OperatorCode.f32x4_replace_lane */: + case 64801 /* OperatorCode.f64x2_extract_lane */: + case 64802 /* OperatorCode.f64x2_replace_lane */: + lineIndex = this.readUint8(); + break; + case 64782 /* OperatorCode.i8x16_swizzle */: + case 64783 /* OperatorCode.i8x16_splat */: + case 64784 /* OperatorCode.i16x8_splat */: + case 64785 /* OperatorCode.i32x4_splat */: + case 64786 /* OperatorCode.i64x2_splat */: + case 64787 /* OperatorCode.f32x4_splat */: + case 64788 /* OperatorCode.f64x2_splat */: + case 64803 /* OperatorCode.i8x16_eq */: + case 64804 /* OperatorCode.i8x16_ne */: + case 64805 /* OperatorCode.i8x16_lt_s */: + case 64806 /* OperatorCode.i8x16_lt_u */: + case 64807 /* OperatorCode.i8x16_gt_s */: + case 64808 /* OperatorCode.i8x16_gt_u */: + case 64809 /* OperatorCode.i8x16_le_s */: + case 64810 /* OperatorCode.i8x16_le_u */: + case 64811 /* OperatorCode.i8x16_ge_s */: + case 64812 /* OperatorCode.i8x16_ge_u */: + case 64813 /* OperatorCode.i16x8_eq */: + case 64814 /* OperatorCode.i16x8_ne */: + case 64815 /* OperatorCode.i16x8_lt_s */: + case 64816 /* OperatorCode.i16x8_lt_u */: + case 64817 /* OperatorCode.i16x8_gt_s */: + case 64818 /* OperatorCode.i16x8_gt_u */: + case 64819 /* OperatorCode.i16x8_le_s */: + case 64820 /* OperatorCode.i16x8_le_u */: + case 64821 /* OperatorCode.i16x8_ge_s */: + case 64822 /* OperatorCode.i16x8_ge_u */: + case 64823 /* OperatorCode.i32x4_eq */: + case 64824 /* OperatorCode.i32x4_ne */: + case 64825 /* OperatorCode.i32x4_lt_s */: + case 64826 /* OperatorCode.i32x4_lt_u */: + case 64827 /* OperatorCode.i32x4_gt_s */: + case 64828 /* OperatorCode.i32x4_gt_u */: + case 64829 /* OperatorCode.i32x4_le_s */: + case 64830 /* OperatorCode.i32x4_le_u */: + case 64831 /* OperatorCode.i32x4_ge_s */: + case 64832 /* OperatorCode.i32x4_ge_u */: + case 64833 /* OperatorCode.f32x4_eq */: + case 64834 /* OperatorCode.f32x4_ne */: + case 64835 /* OperatorCode.f32x4_lt */: + case 64836 /* OperatorCode.f32x4_gt */: + case 64837 /* OperatorCode.f32x4_le */: + case 64838 /* OperatorCode.f32x4_ge */: + case 64839 /* OperatorCode.f64x2_eq */: + case 64840 /* OperatorCode.f64x2_ne */: + case 64841 /* OperatorCode.f64x2_lt */: + case 64842 /* OperatorCode.f64x2_gt */: + case 64843 /* OperatorCode.f64x2_le */: + case 64844 /* OperatorCode.f64x2_ge */: + case 64845 /* OperatorCode.v128_not */: + case 64846 /* OperatorCode.v128_and */: + case 64847 /* OperatorCode.v128_andnot */: + case 64848 /* OperatorCode.v128_or */: + case 64849 /* OperatorCode.v128_xor */: + case 64850 /* OperatorCode.v128_bitselect */: + case 64851 /* OperatorCode.v128_any_true */: + case 64862 /* OperatorCode.f32x4_demote_f64x2_zero */: + case 64863 /* OperatorCode.f64x2_promote_low_f32x4 */: + case 64864 /* OperatorCode.i8x16_abs */: + case 64865 /* OperatorCode.i8x16_neg */: + case 64866 /* OperatorCode.i8x16_popcnt */: + case 64867 /* OperatorCode.i8x16_all_true */: + case 64868 /* OperatorCode.i8x16_bitmask */: + case 64869 /* OperatorCode.i8x16_narrow_i16x8_s */: + case 64870 /* OperatorCode.i8x16_narrow_i16x8_u */: + case 64871 /* OperatorCode.f32x4_ceil */: + case 64872 /* OperatorCode.f32x4_floor */: + case 64873 /* OperatorCode.f32x4_trunc */: + case 64874 /* OperatorCode.f32x4_nearest */: + case 64875 /* OperatorCode.i8x16_shl */: + case 64876 /* OperatorCode.i8x16_shr_s */: + case 64877 /* OperatorCode.i8x16_shr_u */: + case 64878 /* OperatorCode.i8x16_add */: + case 64879 /* OperatorCode.i8x16_add_sat_s */: + case 64880 /* OperatorCode.i8x16_add_sat_u */: + case 64881 /* OperatorCode.i8x16_sub */: + case 64882 /* OperatorCode.i8x16_sub_sat_s */: + case 64883 /* OperatorCode.i8x16_sub_sat_u */: + case 64884 /* OperatorCode.f64x2_ceil */: + case 64885 /* OperatorCode.f64x2_floor */: + case 64886 /* OperatorCode.i8x16_min_s */: + case 64887 /* OperatorCode.i8x16_min_u */: + case 64888 /* OperatorCode.i8x16_max_s */: + case 64889 /* OperatorCode.i8x16_max_u */: + case 64890 /* OperatorCode.f64x2_trunc */: + case 64891 /* OperatorCode.i8x16_avgr_u */: + case 64892 /* OperatorCode.i16x8_extadd_pairwise_i8x16_s */: + case 64893 /* OperatorCode.i16x8_extadd_pairwise_i8x16_u */: + case 64894 /* OperatorCode.i32x4_extadd_pairwise_i16x8_s */: + case 64895 /* OperatorCode.i32x4_extadd_pairwise_i16x8_u */: + case 64896 /* OperatorCode.i16x8_abs */: + case 64897 /* OperatorCode.i16x8_neg */: + case 64898 /* OperatorCode.i16x8_q15mulr_sat_s */: + case 64899 /* OperatorCode.i16x8_all_true */: + case 64900 /* OperatorCode.i16x8_bitmask */: + case 64901 /* OperatorCode.i16x8_narrow_i32x4_s */: + case 64902 /* OperatorCode.i16x8_narrow_i32x4_u */: + case 64903 /* OperatorCode.i16x8_extend_low_i8x16_s */: + case 64904 /* OperatorCode.i16x8_extend_high_i8x16_s */: + case 64905 /* OperatorCode.i16x8_extend_low_i8x16_u */: + case 64906 /* OperatorCode.i16x8_extend_high_i8x16_u */: + case 64907 /* OperatorCode.i16x8_shl */: + case 64908 /* OperatorCode.i16x8_shr_s */: + case 64909 /* OperatorCode.i16x8_shr_u */: + case 64910 /* OperatorCode.i16x8_add */: + case 64911 /* OperatorCode.i16x8_add_sat_s */: + case 64912 /* OperatorCode.i16x8_add_sat_u */: + case 64913 /* OperatorCode.i16x8_sub */: + case 64914 /* OperatorCode.i16x8_sub_sat_s */: + case 64915 /* OperatorCode.i16x8_sub_sat_u */: + case 64916 /* OperatorCode.f64x2_nearest */: + case 64917 /* OperatorCode.i16x8_mul */: + case 64918 /* OperatorCode.i16x8_min_s */: + case 64919 /* OperatorCode.i16x8_min_u */: + case 64920 /* OperatorCode.i16x8_max_s */: + case 64921 /* OperatorCode.i16x8_max_u */: + case 64923 /* OperatorCode.i16x8_avgr_u */: + case 64924 /* OperatorCode.i16x8_extmul_low_i8x16_s */: + case 64925 /* OperatorCode.i16x8_extmul_high_i8x16_s */: + case 64926 /* OperatorCode.i16x8_extmul_low_i8x16_u */: + case 64927 /* OperatorCode.i16x8_extmul_high_i8x16_u */: + case 64928 /* OperatorCode.i32x4_abs */: + case 64929 /* OperatorCode.i32x4_neg */: + case 64931 /* OperatorCode.i32x4_all_true */: + case 64932 /* OperatorCode.i32x4_bitmask */: + case 64935 /* OperatorCode.i32x4_extend_low_i16x8_s */: + case 64936 /* OperatorCode.i32x4_extend_high_i16x8_s */: + case 64937 /* OperatorCode.i32x4_extend_low_i16x8_u */: + case 64938 /* OperatorCode.i32x4_extend_high_i16x8_u */: + case 64939 /* OperatorCode.i32x4_shl */: + case 64940 /* OperatorCode.i32x4_shr_s */: + case 64941 /* OperatorCode.i32x4_shr_u */: + case 64942 /* OperatorCode.i32x4_add */: + case 64945 /* OperatorCode.i32x4_sub */: + case 64949 /* OperatorCode.i32x4_mul */: + case 64950 /* OperatorCode.i32x4_min_s */: + case 64951 /* OperatorCode.i32x4_min_u */: + case 64952 /* OperatorCode.i32x4_max_s */: + case 64953 /* OperatorCode.i32x4_max_u */: + case 64954 /* OperatorCode.i32x4_dot_i16x8_s */: + case 64956 /* OperatorCode.i32x4_extmul_low_i16x8_s */: + case 64957 /* OperatorCode.i32x4_extmul_high_i16x8_s */: + case 64958 /* OperatorCode.i32x4_extmul_low_i16x8_u */: + case 64959 /* OperatorCode.i32x4_extmul_high_i16x8_u */: + case 64960 /* OperatorCode.i64x2_abs */: + case 64961 /* OperatorCode.i64x2_neg */: + case 64963 /* OperatorCode.i64x2_all_true */: + case 64964 /* OperatorCode.i64x2_bitmask */: + case 64967 /* OperatorCode.i64x2_extend_low_i32x4_s */: + case 64968 /* OperatorCode.i64x2_extend_high_i32x4_s */: + case 64969 /* OperatorCode.i64x2_extend_low_i32x4_u */: + case 64970 /* OperatorCode.i64x2_extend_high_i32x4_u */: + case 64971 /* OperatorCode.i64x2_shl */: + case 64972 /* OperatorCode.i64x2_shr_s */: + case 64973 /* OperatorCode.i64x2_shr_u */: + case 64974 /* OperatorCode.i64x2_add */: + case 64977 /* OperatorCode.i64x2_sub */: + case 64981 /* OperatorCode.i64x2_mul */: + case 64982 /* OperatorCode.i64x2_eq */: + case 64983 /* OperatorCode.i64x2_ne */: + case 64984 /* OperatorCode.i64x2_lt_s */: + case 64985 /* OperatorCode.i64x2_gt_s */: + case 64986 /* OperatorCode.i64x2_le_s */: + case 64987 /* OperatorCode.i64x2_ge_s */: + case 64988 /* OperatorCode.i64x2_extmul_low_i32x4_s */: + case 64989 /* OperatorCode.i64x2_extmul_high_i32x4_s */: + case 64988 /* OperatorCode.i64x2_extmul_low_i32x4_s */: + case 64989 /* OperatorCode.i64x2_extmul_high_i32x4_s */: + case 64992 /* OperatorCode.f32x4_abs */: + case 64992 /* OperatorCode.f32x4_abs */: + case 64993 /* OperatorCode.f32x4_neg */: + case 64995 /* OperatorCode.f32x4_sqrt */: + case 64996 /* OperatorCode.f32x4_add */: + case 64997 /* OperatorCode.f32x4_sub */: + case 64998 /* OperatorCode.f32x4_mul */: + case 64999 /* OperatorCode.f32x4_div */: + case 65000 /* OperatorCode.f32x4_min */: + case 65001 /* OperatorCode.f32x4_max */: + case 65002 /* OperatorCode.f32x4_pmin */: + case 65003 /* OperatorCode.f32x4_pmax */: + case 65004 /* OperatorCode.f64x2_abs */: + case 65005 /* OperatorCode.f64x2_neg */: + case 65007 /* OperatorCode.f64x2_sqrt */: + case 65008 /* OperatorCode.f64x2_add */: + case 65009 /* OperatorCode.f64x2_sub */: + case 65010 /* OperatorCode.f64x2_mul */: + case 65011 /* OperatorCode.f64x2_div */: + case 65012 /* OperatorCode.f64x2_min */: + case 65013 /* OperatorCode.f64x2_max */: + case 65014 /* OperatorCode.f64x2_pmin */: + case 65015 /* OperatorCode.f64x2_pmax */: + case 65016 /* OperatorCode.i32x4_trunc_sat_f32x4_s */: + case 65017 /* OperatorCode.i32x4_trunc_sat_f32x4_u */: + case 65018 /* OperatorCode.f32x4_convert_i32x4_s */: + case 65019 /* OperatorCode.f32x4_convert_i32x4_u */: + case 65020 /* OperatorCode.i32x4_trunc_sat_f64x2_s_zero */: + case 65021 /* OperatorCode.i32x4_trunc_sat_f64x2_u_zero */: + case 65022 /* OperatorCode.f64x2_convert_low_i32x4_s */: + case 65023 /* OperatorCode.f64x2_convert_low_i32x4_u */: + break; + default: + this.error = new Error("Unknown operator: 0x".concat(code.toString(16).padStart(4, "0"))); + this.state = -1 /* BinaryReaderState.ERROR */; + return true; + } + this.result = { + code: code, + blockType: undefined, + selectType: undefined, + refType: undefined, + srcType: undefined, + brDepth: undefined, + brTable: undefined, + funcIndex: undefined, + typeIndex: undefined, + localIndex: undefined, + globalIndex: undefined, + fieldIndex: undefined, + memoryAddress: memoryAddress, + literal: literal, + segmentIndex: undefined, + destinationIndex: undefined, + len: undefined, + lines: lines, + lineIndex: lineIndex, + }; + return true; + }; + BinaryReader.prototype.readCodeOperator_0xfe = function () { + var MAX_CODE_OPERATOR_0XFE_SIZE = 11; + var pos = this._pos; + if (!this._eof && pos + MAX_CODE_OPERATOR_0XFE_SIZE > this._length) { + return false; + } + if (!this.hasVarIntBytes()) { + return false; + } + var code = this.readVarUint32() | 0xfe00; + var memoryAddress; + switch (code) { + case 65024 /* OperatorCode.memory_atomic_notify */: + case 65025 /* OperatorCode.memory_atomic_wait32 */: + case 65026 /* OperatorCode.memory_atomic_wait64 */: + case 65040 /* OperatorCode.i32_atomic_load */: + case 65041 /* OperatorCode.i64_atomic_load */: + case 65042 /* OperatorCode.i32_atomic_load8_u */: + case 65043 /* OperatorCode.i32_atomic_load16_u */: + case 65044 /* OperatorCode.i64_atomic_load8_u */: + case 65045 /* OperatorCode.i64_atomic_load16_u */: + case 65046 /* OperatorCode.i64_atomic_load32_u */: + case 65047 /* OperatorCode.i32_atomic_store */: + case 65048 /* OperatorCode.i64_atomic_store */: + case 65049 /* OperatorCode.i32_atomic_store8 */: + case 65050 /* OperatorCode.i32_atomic_store16 */: + case 65051 /* OperatorCode.i64_atomic_store8 */: + case 65052 /* OperatorCode.i64_atomic_store16 */: + case 65053 /* OperatorCode.i64_atomic_store32 */: + case 65054 /* OperatorCode.i32_atomic_rmw_add */: + case 65055 /* OperatorCode.i64_atomic_rmw_add */: + case 65056 /* OperatorCode.i32_atomic_rmw8_add_u */: + case 65057 /* OperatorCode.i32_atomic_rmw16_add_u */: + case 65058 /* OperatorCode.i64_atomic_rmw8_add_u */: + case 65059 /* OperatorCode.i64_atomic_rmw16_add_u */: + case 65060 /* OperatorCode.i64_atomic_rmw32_add_u */: + case 65061 /* OperatorCode.i32_atomic_rmw_sub */: + case 65062 /* OperatorCode.i64_atomic_rmw_sub */: + case 65063 /* OperatorCode.i32_atomic_rmw8_sub_u */: + case 65064 /* OperatorCode.i32_atomic_rmw16_sub_u */: + case 65065 /* OperatorCode.i64_atomic_rmw8_sub_u */: + case 65066 /* OperatorCode.i64_atomic_rmw16_sub_u */: + case 65067 /* OperatorCode.i64_atomic_rmw32_sub_u */: + case 65068 /* OperatorCode.i32_atomic_rmw_and */: + case 65069 /* OperatorCode.i64_atomic_rmw_and */: + case 65070 /* OperatorCode.i32_atomic_rmw8_and_u */: + case 65071 /* OperatorCode.i32_atomic_rmw16_and_u */: + case 65072 /* OperatorCode.i64_atomic_rmw8_and_u */: + case 65073 /* OperatorCode.i64_atomic_rmw16_and_u */: + case 65074 /* OperatorCode.i64_atomic_rmw32_and_u */: + case 65075 /* OperatorCode.i32_atomic_rmw_or */: + case 65076 /* OperatorCode.i64_atomic_rmw_or */: + case 65077 /* OperatorCode.i32_atomic_rmw8_or_u */: + case 65078 /* OperatorCode.i32_atomic_rmw16_or_u */: + case 65079 /* OperatorCode.i64_atomic_rmw8_or_u */: + case 65080 /* OperatorCode.i64_atomic_rmw16_or_u */: + case 65081 /* OperatorCode.i64_atomic_rmw32_or_u */: + case 65082 /* OperatorCode.i32_atomic_rmw_xor */: + case 65083 /* OperatorCode.i64_atomic_rmw_xor */: + case 65084 /* OperatorCode.i32_atomic_rmw8_xor_u */: + case 65085 /* OperatorCode.i32_atomic_rmw16_xor_u */: + case 65086 /* OperatorCode.i64_atomic_rmw8_xor_u */: + case 65087 /* OperatorCode.i64_atomic_rmw16_xor_u */: + case 65088 /* OperatorCode.i64_atomic_rmw32_xor_u */: + case 65089 /* OperatorCode.i32_atomic_rmw_xchg */: + case 65090 /* OperatorCode.i64_atomic_rmw_xchg */: + case 65091 /* OperatorCode.i32_atomic_rmw8_xchg_u */: + case 65092 /* OperatorCode.i32_atomic_rmw16_xchg_u */: + case 65093 /* OperatorCode.i64_atomic_rmw8_xchg_u */: + case 65094 /* OperatorCode.i64_atomic_rmw16_xchg_u */: + case 65095 /* OperatorCode.i64_atomic_rmw32_xchg_u */: + case 65096 /* OperatorCode.i32_atomic_rmw_cmpxchg */: + case 65097 /* OperatorCode.i64_atomic_rmw_cmpxchg */: + case 65098 /* OperatorCode.i32_atomic_rmw8_cmpxchg_u */: + case 65099 /* OperatorCode.i32_atomic_rmw16_cmpxchg_u */: + case 65100 /* OperatorCode.i64_atomic_rmw8_cmpxchg_u */: + case 65101 /* OperatorCode.i64_atomic_rmw16_cmpxchg_u */: + case 65102 /* OperatorCode.i64_atomic_rmw32_cmpxchg_u */: + memoryAddress = this.readMemoryImmediate(); + break; + case 65027 /* OperatorCode.atomic_fence */: { + var consistency_model = this.readUint8(); + if (consistency_model != 0) { + this.error = new Error("atomic.fence consistency model must be 0"); + this.state = -1 /* BinaryReaderState.ERROR */; + return true; + } + break; + } + default: + this.error = new Error("Unknown operator: 0x".concat(code.toString(16).padStart(4, "0"))); + this.state = -1 /* BinaryReaderState.ERROR */; + return true; + } + this.result = { + code: code, + blockType: undefined, + selectType: undefined, + refType: undefined, + srcType: undefined, + brDepth: undefined, + brTable: undefined, + funcIndex: undefined, + typeIndex: undefined, + localIndex: undefined, + globalIndex: undefined, + fieldIndex: undefined, + memoryAddress: memoryAddress, + literal: undefined, + segmentIndex: undefined, + destinationIndex: undefined, + len: undefined, + lines: undefined, + lineIndex: undefined, + }; + return true; + }; + BinaryReader.prototype.readCodeOperator = function () { + switch (this.state) { + case 30 /* BinaryReaderState.CODE_OPERATOR */: + if (this._pos >= this._functionRange.end) { + this.skipFunctionBody(); + return this.read(); + } + break; + case 26 /* BinaryReaderState.INIT_EXPRESSION_OPERATOR */: + if (this.result && + this.result.code === 11 /* OperatorCode.end */) { + this.state = 27 /* BinaryReaderState.END_INIT_EXPRESSION_BODY */; + this.result = null; + return true; + } + break; + case 45 /* BinaryReaderState.OFFSET_EXPRESSION_OPERATOR */: + if (this.result && + this.result.code === 11 /* OperatorCode.end */) { + this.state = 46 /* BinaryReaderState.END_OFFSET_EXPRESSION_BODY */; + this.result = null; + return true; + } + break; + } + var code, blockType, selectType, refType, brDepth, brTable, relativeDepth, funcIndex, typeIndex, tableIndex, localIndex, globalIndex, tagIndex, memoryAddress, literal, reserved; + if (this.state === 26 /* BinaryReaderState.INIT_EXPRESSION_OPERATOR */ && + this._sectionId === 9 /* SectionCode.Element */ && + isExternvalElementSegmentType(this._segmentType)) { + // We are reading a `vec(funcidx)` here, which is a dense encoding + // for a sequence of `((ref.func y) end)` instructions. + if (this.result && + this.result.code === 210 /* OperatorCode.ref_func */) { + code = 11 /* OperatorCode.end */; + } + else { + if (!this.hasVarIntBytes()) + return false; + code = 210 /* OperatorCode.ref_func */; + funcIndex = this.readVarUint32(); + } + } + else { + var MAX_CODE_OPERATOR_SIZE = 11; // i64.const or load/store + var pos = this._pos; + if (!this._eof && pos + MAX_CODE_OPERATOR_SIZE > this._length) { + return false; + } + code = this._data[this._pos++]; + switch (code) { + case 2 /* OperatorCode.block */: + case 3 /* OperatorCode.loop */: + case 4 /* OperatorCode.if */: + case 6 /* OperatorCode.try */: + blockType = this.readType(); + break; + case 12 /* OperatorCode.br */: + case 13 /* OperatorCode.br_if */: + case 212 /* OperatorCode.br_on_null */: + case 214 /* OperatorCode.br_on_non_null */: + brDepth = this.readVarUint32(); + break; + case 14 /* OperatorCode.br_table */: + var tableCount = this.readVarUint32(); + if (!this.hasBytes(tableCount + 1)) { + // We need at least (tableCount + 1) bytes + this._pos = pos; + return false; + } + brTable = []; + for (var i = 0; i <= tableCount; i++) { + // including default + if (!this.hasVarIntBytes()) { + this._pos = pos; + return false; + } + brTable.push(this.readVarUint32()); + } + break; + case 9 /* OperatorCode.rethrow */: + case 24 /* OperatorCode.delegate */: + relativeDepth = this.readVarUint32(); + break; + case 7 /* OperatorCode.catch */: + case 8 /* OperatorCode.throw */: + tagIndex = this.readVarInt32(); + break; + case 208 /* OperatorCode.ref_null */: + refType = this.readHeapType(); + break; + case 16 /* OperatorCode.call */: + case 18 /* OperatorCode.return_call */: + case 210 /* OperatorCode.ref_func */: + funcIndex = this.readVarUint32(); + break; + case 17 /* OperatorCode.call_indirect */: + case 19 /* OperatorCode.return_call_indirect */: + typeIndex = this.readVarUint32(); + reserved = this.readVarUint1(); + break; + case 32 /* OperatorCode.local_get */: + case 33 /* OperatorCode.local_set */: + case 34 /* OperatorCode.local_tee */: + localIndex = this.readVarUint32(); + break; + case 35 /* OperatorCode.global_get */: + case 36 /* OperatorCode.global_set */: + globalIndex = this.readVarUint32(); + break; + case 37 /* OperatorCode.table_get */: + case 38 /* OperatorCode.table_set */: + tableIndex = this.readVarUint32(); + break; + case 20 /* OperatorCode.call_ref */: + case 21 /* OperatorCode.return_call_ref */: + typeIndex = this.readHeapType(); + break; + case 40 /* OperatorCode.i32_load */: + case 41 /* OperatorCode.i64_load */: + case 42 /* OperatorCode.f32_load */: + case 43 /* OperatorCode.f64_load */: + case 44 /* OperatorCode.i32_load8_s */: + case 45 /* OperatorCode.i32_load8_u */: + case 46 /* OperatorCode.i32_load16_s */: + case 47 /* OperatorCode.i32_load16_u */: + case 48 /* OperatorCode.i64_load8_s */: + case 49 /* OperatorCode.i64_load8_u */: + case 50 /* OperatorCode.i64_load16_s */: + case 51 /* OperatorCode.i64_load16_u */: + case 52 /* OperatorCode.i64_load32_s */: + case 53 /* OperatorCode.i64_load32_u */: + case 54 /* OperatorCode.i32_store */: + case 55 /* OperatorCode.i64_store */: + case 56 /* OperatorCode.f32_store */: + case 57 /* OperatorCode.f64_store */: + case 58 /* OperatorCode.i32_store8 */: + case 59 /* OperatorCode.i32_store16 */: + case 60 /* OperatorCode.i64_store8 */: + case 61 /* OperatorCode.i64_store16 */: + case 62 /* OperatorCode.i64_store32 */: + memoryAddress = this.readMemoryImmediate(); + break; + case 63 /* OperatorCode.memory_size */: + case 64 /* OperatorCode.memory_grow */: + reserved = this.readVarUint1(); + break; + case 65 /* OperatorCode.i32_const */: + literal = this.readVarInt32(); + break; + case 66 /* OperatorCode.i64_const */: + literal = this.readVarInt64(); + break; + case 67 /* OperatorCode.f32_const */: + literal = new DataView(this._data.buffer, this._data.byteOffset).getFloat32(this._pos, true); + this._pos += 4; + break; + case 68 /* OperatorCode.f64_const */: + literal = new DataView(this._data.buffer, this._data.byteOffset).getFloat64(this._pos, true); + this._pos += 8; + break; + case 28 /* OperatorCode.select_with_type */: + var num_types = this.readVarInt32(); + // Only 1 is a valid value currently. + if (num_types == 1) { + selectType = this.readType(); + } + break; + case 251 /* OperatorCode.prefix_0xfb */: + if (this.readCodeOperator_0xfb()) { + return true; + } + this._pos = pos; + return false; + case 252 /* OperatorCode.prefix_0xfc */: + if (this.readCodeOperator_0xfc()) { + return true; + } + this._pos = pos; + return false; + case 253 /* OperatorCode.prefix_0xfd */: + if (this.readCodeOperator_0xfd()) { + return true; + } + this._pos = pos; + return false; + case 254 /* OperatorCode.prefix_0xfe */: + if (this.readCodeOperator_0xfe()) { + return true; + } + this._pos = pos; + return false; + case 0 /* OperatorCode.unreachable */: + case 1 /* OperatorCode.nop */: + case 5 /* OperatorCode.else */: + case 10 /* OperatorCode.unwind */: + case 11 /* OperatorCode.end */: + case 15 /* OperatorCode.return */: + case 25 /* OperatorCode.catch_all */: + case 26 /* OperatorCode.drop */: + case 27 /* OperatorCode.select */: + case 69 /* OperatorCode.i32_eqz */: + case 70 /* OperatorCode.i32_eq */: + case 71 /* OperatorCode.i32_ne */: + case 72 /* OperatorCode.i32_lt_s */: + case 73 /* OperatorCode.i32_lt_u */: + case 74 /* OperatorCode.i32_gt_s */: + case 75 /* OperatorCode.i32_gt_u */: + case 76 /* OperatorCode.i32_le_s */: + case 77 /* OperatorCode.i32_le_u */: + case 78 /* OperatorCode.i32_ge_s */: + case 79 /* OperatorCode.i32_ge_u */: + case 80 /* OperatorCode.i64_eqz */: + case 81 /* OperatorCode.i64_eq */: + case 82 /* OperatorCode.i64_ne */: + case 83 /* OperatorCode.i64_lt_s */: + case 84 /* OperatorCode.i64_lt_u */: + case 85 /* OperatorCode.i64_gt_s */: + case 86 /* OperatorCode.i64_gt_u */: + case 87 /* OperatorCode.i64_le_s */: + case 88 /* OperatorCode.i64_le_u */: + case 89 /* OperatorCode.i64_ge_s */: + case 90 /* OperatorCode.i64_ge_u */: + case 91 /* OperatorCode.f32_eq */: + case 92 /* OperatorCode.f32_ne */: + case 93 /* OperatorCode.f32_lt */: + case 94 /* OperatorCode.f32_gt */: + case 95 /* OperatorCode.f32_le */: + case 96 /* OperatorCode.f32_ge */: + case 97 /* OperatorCode.f64_eq */: + case 98 /* OperatorCode.f64_ne */: + case 99 /* OperatorCode.f64_lt */: + case 100 /* OperatorCode.f64_gt */: + case 101 /* OperatorCode.f64_le */: + case 102 /* OperatorCode.f64_ge */: + case 103 /* OperatorCode.i32_clz */: + case 104 /* OperatorCode.i32_ctz */: + case 105 /* OperatorCode.i32_popcnt */: + case 106 /* OperatorCode.i32_add */: + case 107 /* OperatorCode.i32_sub */: + case 108 /* OperatorCode.i32_mul */: + case 109 /* OperatorCode.i32_div_s */: + case 110 /* OperatorCode.i32_div_u */: + case 111 /* OperatorCode.i32_rem_s */: + case 112 /* OperatorCode.i32_rem_u */: + case 113 /* OperatorCode.i32_and */: + case 114 /* OperatorCode.i32_or */: + case 115 /* OperatorCode.i32_xor */: + case 116 /* OperatorCode.i32_shl */: + case 117 /* OperatorCode.i32_shr_s */: + case 118 /* OperatorCode.i32_shr_u */: + case 119 /* OperatorCode.i32_rotl */: + case 120 /* OperatorCode.i32_rotr */: + case 121 /* OperatorCode.i64_clz */: + case 122 /* OperatorCode.i64_ctz */: + case 123 /* OperatorCode.i64_popcnt */: + case 124 /* OperatorCode.i64_add */: + case 125 /* OperatorCode.i64_sub */: + case 126 /* OperatorCode.i64_mul */: + case 127 /* OperatorCode.i64_div_s */: + case 128 /* OperatorCode.i64_div_u */: + case 129 /* OperatorCode.i64_rem_s */: + case 130 /* OperatorCode.i64_rem_u */: + case 131 /* OperatorCode.i64_and */: + case 132 /* OperatorCode.i64_or */: + case 133 /* OperatorCode.i64_xor */: + case 134 /* OperatorCode.i64_shl */: + case 135 /* OperatorCode.i64_shr_s */: + case 136 /* OperatorCode.i64_shr_u */: + case 137 /* OperatorCode.i64_rotl */: + case 138 /* OperatorCode.i64_rotr */: + case 139 /* OperatorCode.f32_abs */: + case 140 /* OperatorCode.f32_neg */: + case 141 /* OperatorCode.f32_ceil */: + case 142 /* OperatorCode.f32_floor */: + case 143 /* OperatorCode.f32_trunc */: + case 144 /* OperatorCode.f32_nearest */: + case 145 /* OperatorCode.f32_sqrt */: + case 146 /* OperatorCode.f32_add */: + case 147 /* OperatorCode.f32_sub */: + case 148 /* OperatorCode.f32_mul */: + case 149 /* OperatorCode.f32_div */: + case 150 /* OperatorCode.f32_min */: + case 151 /* OperatorCode.f32_max */: + case 152 /* OperatorCode.f32_copysign */: + case 153 /* OperatorCode.f64_abs */: + case 154 /* OperatorCode.f64_neg */: + case 155 /* OperatorCode.f64_ceil */: + case 156 /* OperatorCode.f64_floor */: + case 157 /* OperatorCode.f64_trunc */: + case 158 /* OperatorCode.f64_nearest */: + case 159 /* OperatorCode.f64_sqrt */: + case 160 /* OperatorCode.f64_add */: + case 161 /* OperatorCode.f64_sub */: + case 162 /* OperatorCode.f64_mul */: + case 163 /* OperatorCode.f64_div */: + case 164 /* OperatorCode.f64_min */: + case 165 /* OperatorCode.f64_max */: + case 166 /* OperatorCode.f64_copysign */: + case 167 /* OperatorCode.i32_wrap_i64 */: + case 168 /* OperatorCode.i32_trunc_f32_s */: + case 169 /* OperatorCode.i32_trunc_f32_u */: + case 170 /* OperatorCode.i32_trunc_f64_s */: + case 171 /* OperatorCode.i32_trunc_f64_u */: + case 172 /* OperatorCode.i64_extend_i32_s */: + case 173 /* OperatorCode.i64_extend_i32_u */: + case 174 /* OperatorCode.i64_trunc_f32_s */: + case 175 /* OperatorCode.i64_trunc_f32_u */: + case 176 /* OperatorCode.i64_trunc_f64_s */: + case 177 /* OperatorCode.i64_trunc_f64_u */: + case 178 /* OperatorCode.f32_convert_i32_s */: + case 179 /* OperatorCode.f32_convert_i32_u */: + case 180 /* OperatorCode.f32_convert_i64_s */: + case 181 /* OperatorCode.f32_convert_i64_u */: + case 182 /* OperatorCode.f32_demote_f64 */: + case 183 /* OperatorCode.f64_convert_i32_s */: + case 184 /* OperatorCode.f64_convert_i32_u */: + case 185 /* OperatorCode.f64_convert_i64_s */: + case 186 /* OperatorCode.f64_convert_i64_u */: + case 187 /* OperatorCode.f64_promote_f32 */: + case 188 /* OperatorCode.i32_reinterpret_f32 */: + case 189 /* OperatorCode.i64_reinterpret_f64 */: + case 190 /* OperatorCode.f32_reinterpret_i32 */: + case 191 /* OperatorCode.f64_reinterpret_i64 */: + case 192 /* OperatorCode.i32_extend8_s */: + case 193 /* OperatorCode.i32_extend16_s */: + case 194 /* OperatorCode.i64_extend8_s */: + case 195 /* OperatorCode.i64_extend16_s */: + case 196 /* OperatorCode.i64_extend32_s */: + case 209 /* OperatorCode.ref_is_null */: + case 211 /* OperatorCode.ref_as_non_null */: + case 213 /* OperatorCode.ref_eq */: + break; + default: + this.error = new Error("Unknown operator: ".concat(code)); + this.state = -1 /* BinaryReaderState.ERROR */; + return true; + } + } + this.result = { + code: code, + blockType: blockType, + selectType: selectType, + refType: refType, + srcType: undefined, + brDepth: brDepth, + brTable: brTable, + relativeDepth: relativeDepth, + tableIndex: tableIndex, + funcIndex: funcIndex, + typeIndex: typeIndex, + localIndex: localIndex, + globalIndex: globalIndex, + fieldIndex: undefined, + tagIndex: tagIndex, + memoryAddress: memoryAddress, + literal: literal, + segmentIndex: undefined, + destinationIndex: undefined, + len: undefined, + lines: undefined, + lineIndex: undefined, + }; + return true; + }; + BinaryReader.prototype.readFunctionBody = function () { + if (this._sectionEntriesLeft === 0) { + this.skipSection(); + return this.read(); + } + if (!this.hasVarIntBytes()) + return false; + var pos = this._pos; + var size = this.readVarUint32(); + var bodyEnd = this._pos + size; + if (!this.hasVarIntBytes()) { + this._pos = pos; + return false; + } + var localCount = this.readVarUint32(); + var locals = []; + for (var i = 0; i < localCount; i++) { + if (!this.hasVarIntBytes()) { + this._pos = pos; + return false; + } + var count = this.readVarUint32(); + if (!this.hasVarIntBytes()) { + this._pos = pos; + return false; + } + var type = this.readType(); + locals.push({ count: count, type: type }); + } + var bodyStart = this._pos; + this.state = 28 /* BinaryReaderState.BEGIN_FUNCTION_BODY */; + this.result = { + locals: locals, + }; + this._functionRange = new DataRange(bodyStart, bodyEnd); + this._sectionEntriesLeft--; + return true; + }; + BinaryReader.prototype.readSectionHeader = function () { + if (this._pos >= this._length && this._eof) { + this._sectionId = -1 /* SectionCode.Unknown */; + this._sectionRange = null; + this.result = null; + this.state = 2 /* BinaryReaderState.END_WASM */; + return true; + } + // TODO: Handle _eof. + if (this._pos < this._length - 4) { + var magicNumber = this.peekInt32(); + if (magicNumber === WASM_MAGIC_NUMBER) { + this._sectionId = -1 /* SectionCode.Unknown */; + this._sectionRange = null; + this.result = null; + this.state = 2 /* BinaryReaderState.END_WASM */; + return true; + } + } + if (!this.hasVarIntBytes()) + return false; + var sectionStart = this._pos; + var id = this.readVarUint7(); + if (!this.hasVarIntBytes()) { + this._pos = sectionStart; + return false; + } + var payloadLength = this.readVarUint32(); + var name = null; + var payloadEnd = this._pos + payloadLength; + if (id == 0) { + if (!this.hasStringBytes()) { + this._pos = sectionStart; + return false; + } + name = this.readStringBytes(); + } + this.result = { id: id, name: name }; + this._sectionId = id; + this._sectionRange = new DataRange(this._pos, payloadEnd); + this.state = 3 /* BinaryReaderState.BEGIN_SECTION */; + return true; + }; + BinaryReader.prototype.readSectionRawData = function () { + var payloadLength = this._sectionRange.end - this._sectionRange.start; + if (!this.hasBytes(payloadLength)) { + return false; + } + this.state = 7 /* BinaryReaderState.SECTION_RAW_DATA */; + this.result = this.readBytes(payloadLength); + return true; + }; + BinaryReader.prototype.readSectionBody = function () { + if (this._pos >= this._sectionRange.end) { + this.result = null; + this.state = 4 /* BinaryReaderState.END_SECTION */; + this._sectionId = -1 /* SectionCode.Unknown */; + this._sectionRange = null; + return true; + } + var currentSection = this.result; + switch (currentSection.id) { + case 1 /* SectionCode.Type */: + if (!this.hasSectionPayload()) + return false; + this._sectionEntriesLeft = this.readVarUint32(); + this._recGroupTypesLeft = -1; + return this.readTypeEntry(); + case 2 /* SectionCode.Import */: + if (!this.hasSectionPayload()) + return false; + this._sectionEntriesLeft = this.readVarUint32(); + return this.readImportEntry(); + case 7 /* SectionCode.Export */: + if (!this.hasSectionPayload()) + return false; + this._sectionEntriesLeft = this.readVarUint32(); + return this.readExportEntry(); + case 3 /* SectionCode.Function */: + if (!this.hasSectionPayload()) + return false; + this._sectionEntriesLeft = this.readVarUint32(); + return this.readFunctionEntry(); + case 4 /* SectionCode.Table */: + if (!this.hasSectionPayload()) + return false; + this._sectionEntriesLeft = this.readVarUint32(); + return this.readTableEntry(); + case 5 /* SectionCode.Memory */: + if (!this.hasSectionPayload()) + return false; + this._sectionEntriesLeft = this.readVarUint32(); + return this.readMemoryEntry(); + case 6 /* SectionCode.Global */: + if (!this.hasVarIntBytes()) + return false; + this._sectionEntriesLeft = this.readVarUint32(); + return this.readGlobalEntry(); + case 8 /* SectionCode.Start */: + if (!this.hasVarIntBytes()) + return false; + this.state = 22 /* BinaryReaderState.START_SECTION_ENTRY */; + this.result = { index: this.readVarUint32() }; + return true; + case 10 /* SectionCode.Code */: + if (!this.hasVarIntBytes()) + return false; + this._sectionEntriesLeft = this.readVarUint32(); + this.state = 29 /* BinaryReaderState.READING_FUNCTION_HEADER */; + return this.readFunctionBody(); + case 9 /* SectionCode.Element */: + if (!this.hasVarIntBytes()) + return false; + this._sectionEntriesLeft = this.readVarUint32(); + return this.readElementEntry(); + case 11 /* SectionCode.Data */: + if (!this.hasVarIntBytes()) + return false; + this._sectionEntriesLeft = this.readVarUint32(); + return this.readDataEntry(); + case 12 /* SectionCode.DataCount */: + if (!this.hasVarIntBytes()) + return false; + this._sectionEntriesLeft = this.readVarUint32(); + return this.readDataCountEntry(); + case 13 /* SectionCode.Tag */: + if (!this.hasVarIntBytes()) + return false; + this._sectionEntriesLeft = this.readVarUint32(); + return this.readTagEntry(); + case 0 /* SectionCode.Custom */: + var customSectionName = (0, exports.bytesToString)(currentSection.name); + if (customSectionName === "name") { + return this.readNameEntry(); + } + if (customSectionName.indexOf("reloc.") === 0) { + return this.readRelocHeader(); + } + if (customSectionName === "linking") { + if (!this.hasVarIntBytes()) + return false; + this._sectionEntriesLeft = this.readVarUint32(); + return this.readLinkingEntry(); + } + if (customSectionName === "sourceMappingURL") { + return this.readSourceMappingURL(); + } + return this.readSectionRawData(); + default: + this.error = new Error("Unsupported section: ".concat(this._sectionId)); + this.state = -1 /* BinaryReaderState.ERROR */; + return true; + } + }; + BinaryReader.prototype.read = function () { + switch (this.state) { + case 0 /* BinaryReaderState.INITIAL */: + if (!this.hasBytes(8)) + return false; + var magicNumber = this.readUint32(); + if (magicNumber != WASM_MAGIC_NUMBER) { + this.error = new Error("Bad magic number"); + this.state = -1 /* BinaryReaderState.ERROR */; + return true; + } + var version = this.readUint32(); + if (version != WASM_SUPPORTED_VERSION && + version != WASM_SUPPORTED_EXPERIMENTAL_VERSION) { + this.error = new Error("Bad version number ".concat(version)); + this.state = -1 /* BinaryReaderState.ERROR */; + return true; + } + this.result = { magicNumber: magicNumber, version: version }; + this.state = 1 /* BinaryReaderState.BEGIN_WASM */; + return true; + case 2 /* BinaryReaderState.END_WASM */: + this.result = null; + this.state = 1 /* BinaryReaderState.BEGIN_WASM */; + if (this.hasMoreBytes()) { + this.state = 0 /* BinaryReaderState.INITIAL */; + return this.read(); + } + return false; + case -1 /* BinaryReaderState.ERROR */: + return true; + case 1 /* BinaryReaderState.BEGIN_WASM */: + case 4 /* BinaryReaderState.END_SECTION */: + return this.readSectionHeader(); + case 3 /* BinaryReaderState.BEGIN_SECTION */: + return this.readSectionBody(); + case 5 /* BinaryReaderState.SKIPPING_SECTION */: + if (!this.hasSectionPayload()) { + return false; + } + this.state = 4 /* BinaryReaderState.END_SECTION */; + this._pos = this._sectionRange.end; + this._sectionId = -1 /* SectionCode.Unknown */; + this._sectionRange = null; + this.result = null; + return true; + case 32 /* BinaryReaderState.SKIPPING_FUNCTION_BODY */: + this.state = 31 /* BinaryReaderState.END_FUNCTION_BODY */; + this._pos = this._functionRange.end; + this._functionRange = null; + this.result = null; + return true; + case 11 /* BinaryReaderState.TYPE_SECTION_ENTRY */: + if (this._recGroupTypesLeft >= 0) { + return this.readRecGroupEntry(); + } + return this.readTypeEntry(); + case 47 /* BinaryReaderState.BEGIN_REC_GROUP */: + return this.readRecGroupEntry(); + case 48 /* BinaryReaderState.END_REC_GROUP */: + return this.readTypeEntry(); + case 12 /* BinaryReaderState.IMPORT_SECTION_ENTRY */: + return this.readImportEntry(); + case 17 /* BinaryReaderState.EXPORT_SECTION_ENTRY */: + return this.readExportEntry(); + case 13 /* BinaryReaderState.FUNCTION_SECTION_ENTRY */: + return this.readFunctionEntry(); + case 14 /* BinaryReaderState.TABLE_SECTION_ENTRY */: + return this.readTableEntry(); + case 15 /* BinaryReaderState.MEMORY_SECTION_ENTRY */: + return this.readMemoryEntry(); + case 23 /* BinaryReaderState.TAG_SECTION_ENTRY */: + return this.readTagEntry(); + case 16 /* BinaryReaderState.GLOBAL_SECTION_ENTRY */: + case 40 /* BinaryReaderState.END_GLOBAL_SECTION_ENTRY */: + return this.readGlobalEntry(); + case 39 /* BinaryReaderState.BEGIN_GLOBAL_SECTION_ENTRY */: + return this.readInitExpressionBody(); + case 20 /* BinaryReaderState.ELEMENT_SECTION_ENTRY */: + case 35 /* BinaryReaderState.END_ELEMENT_SECTION_ENTRY */: + return this.readElementEntry(); + case 33 /* BinaryReaderState.BEGIN_ELEMENT_SECTION_ENTRY */: + if (isActiveElementSegmentType(this._segmentType)) { + return this.readOffsetExpressionBody(); + } + else { + // passive or declared element segment + return this.readElementEntryBody(); + } + case 34 /* BinaryReaderState.ELEMENT_SECTION_ENTRY_BODY */: + if (!this.hasVarIntBytes()) + return false; + this._segmentEntriesLeft = this.readVarUint32(); + if (this._segmentEntriesLeft === 0) { + this.state = 35 /* BinaryReaderState.END_ELEMENT_SECTION_ENTRY */; + this.result = null; + return true; + } + return this.readInitExpressionBody(); + case 49 /* BinaryReaderState.DATA_COUNT_SECTION_ENTRY */: + return this.readDataCountEntry(); + case 18 /* BinaryReaderState.DATA_SECTION_ENTRY */: + case 38 /* BinaryReaderState.END_DATA_SECTION_ENTRY */: + return this.readDataEntry(); + case 36 /* BinaryReaderState.BEGIN_DATA_SECTION_ENTRY */: + if (isActiveDataSegmentType(this._segmentType)) { + return this.readOffsetExpressionBody(); + } + else { + // passive data segment + return this.readDataEntryBody(); + } + case 37 /* BinaryReaderState.DATA_SECTION_ENTRY_BODY */: + this.state = 38 /* BinaryReaderState.END_DATA_SECTION_ENTRY */; + this.result = null; + return true; + case 27 /* BinaryReaderState.END_INIT_EXPRESSION_BODY */: + switch (this._sectionId) { + case 6 /* SectionCode.Global */: + this.state = 40 /* BinaryReaderState.END_GLOBAL_SECTION_ENTRY */; + return true; + case 9 /* SectionCode.Element */: + if (--this._segmentEntriesLeft > 0) { + return this.readInitExpressionBody(); + } + this.state = 35 /* BinaryReaderState.END_ELEMENT_SECTION_ENTRY */; + this.result = null; + return true; + } + this.error = new Error("Unexpected section type: ".concat(this._sectionId)); + this.state = -1 /* BinaryReaderState.ERROR */; + return true; + case 46 /* BinaryReaderState.END_OFFSET_EXPRESSION_BODY */: + if (this._sectionId === 11 /* SectionCode.Data */) { + return this.readDataEntryBody(); + } + else { + return this.readElementEntryBody(); + } + case 19 /* BinaryReaderState.NAME_SECTION_ENTRY */: + return this.readNameEntry(); + case 41 /* BinaryReaderState.RELOC_SECTION_HEADER */: + if (!this.hasVarIntBytes()) + return false; + this._sectionEntriesLeft = this.readVarUint32(); + return this.readRelocEntry(); + case 21 /* BinaryReaderState.LINKING_SECTION_ENTRY */: + return this.readLinkingEntry(); + case 43 /* BinaryReaderState.SOURCE_MAPPING_URL */: + this.state = 4 /* BinaryReaderState.END_SECTION */; + this.result = null; + return true; + case 42 /* BinaryReaderState.RELOC_SECTION_ENTRY */: + return this.readRelocEntry(); + case 29 /* BinaryReaderState.READING_FUNCTION_HEADER */: + case 31 /* BinaryReaderState.END_FUNCTION_BODY */: + return this.readFunctionBody(); + case 28 /* BinaryReaderState.BEGIN_FUNCTION_BODY */: + this.state = 30 /* BinaryReaderState.CODE_OPERATOR */; + return this.readCodeOperator(); + case 25 /* BinaryReaderState.BEGIN_INIT_EXPRESSION_BODY */: + this.state = 26 /* BinaryReaderState.INIT_EXPRESSION_OPERATOR */; + return this.readCodeOperator(); + case 44 /* BinaryReaderState.BEGIN_OFFSET_EXPRESSION_BODY */: + this.state = 45 /* BinaryReaderState.OFFSET_EXPRESSION_OPERATOR */; + return this.readCodeOperator(); + case 30 /* BinaryReaderState.CODE_OPERATOR */: + case 26 /* BinaryReaderState.INIT_EXPRESSION_OPERATOR */: + case 45 /* BinaryReaderState.OFFSET_EXPRESSION_OPERATOR */: + return this.readCodeOperator(); + case 6 /* BinaryReaderState.READING_SECTION_RAW_DATA */: + return this.readSectionRawData(); + case 22 /* BinaryReaderState.START_SECTION_ENTRY */: + case 7 /* BinaryReaderState.SECTION_RAW_DATA */: + this.state = 4 /* BinaryReaderState.END_SECTION */; + this.result = null; + return true; + default: + this.error = new Error("Unsupported state: ".concat(this.state)); + this.state = -1 /* BinaryReaderState.ERROR */; + return true; + } + }; + BinaryReader.prototype.skipSection = function () { + if (this.state === -1 /* BinaryReaderState.ERROR */ || + this.state === 0 /* BinaryReaderState.INITIAL */ || + this.state === 4 /* BinaryReaderState.END_SECTION */ || + this.state === 1 /* BinaryReaderState.BEGIN_WASM */ || + this.state === 2 /* BinaryReaderState.END_WASM */) + return; + this.state = 5 /* BinaryReaderState.SKIPPING_SECTION */; + }; + BinaryReader.prototype.skipFunctionBody = function () { + if (this.state !== 28 /* BinaryReaderState.BEGIN_FUNCTION_BODY */ && + this.state !== 30 /* BinaryReaderState.CODE_OPERATOR */) + return; + this.state = 32 /* BinaryReaderState.SKIPPING_FUNCTION_BODY */; + }; + BinaryReader.prototype.skipInitExpression = function () { + while (this.state === 26 /* BinaryReaderState.INIT_EXPRESSION_OPERATOR */) + this.readCodeOperator(); + }; + BinaryReader.prototype.fetchSectionRawData = function () { + if (this.state !== 3 /* BinaryReaderState.BEGIN_SECTION */) { + this.error = new Error("Unsupported state: ".concat(this.state)); + this.state = -1 /* BinaryReaderState.ERROR */; + return; + } + this.state = 6 /* BinaryReaderState.READING_SECTION_RAW_DATA */; + }; + return BinaryReader; +}()); +exports.BinaryReader = BinaryReader; +if (typeof TextDecoder !== "undefined") { + try { + exports.bytesToString = (function () { + var utf8Decoder = new TextDecoder("utf-8"); + utf8Decoder.decode(new Uint8Array([97, 208, 144])); + return function (b) { return utf8Decoder.decode(b); }; + })(); + } + catch (_) { + /* ignore */ + } +} +if (!exports.bytesToString) { + exports.bytesToString = function (b) { + var str = String.fromCharCode.apply(null, b); + return decodeURIComponent(escape(str)); + }; +} diff --git a/devtools/client/shared/vendor/dagre-d3.js b/devtools/client/shared/vendor/dagre-d3.js new file mode 100644 index 0000000000..482ce827f9 --- /dev/null +++ b/devtools/client/shared/vendor/dagre-d3.js @@ -0,0 +1,4560 @@ +;(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o Math.abs(dx) * h) { + // Intersection is top or bottom of rect. + if (dy < 0) { + h = -h; + } + sx = dy === 0 ? 0 : h * dx / dy; + sy = h; + } else { + // Intersection is left or right of rect. + if (dx < 0) { + w = -w; + } + sx = w; + sy = dx === 0 ? 0 : w * dy / dx; + } + + return {x: x + sx, y: y + sy}; +} + +function isComposite(g, u) { + return 'children' in g && g.children(u).length; +} + +function bind(func, thisArg) { + // For some reason PhantomJS occassionally fails when using the builtin bind, + // so we check if it is available and if not, use a degenerate polyfill. + if (func.bind) { + return func.bind(thisArg); + } + + return function() { + return func.apply(thisArg, arguments); + }; +} + +},{"d3":10,"dagre":11}],4:[function(require,module,exports){ +module.exports = '0.1.5'; + +},{}],5:[function(require,module,exports){ +exports.Set = require('./lib/Set'); +exports.PriorityQueue = require('./lib/PriorityQueue'); +exports.version = require('./lib/version'); + +},{"./lib/PriorityQueue":6,"./lib/Set":7,"./lib/version":9}],6:[function(require,module,exports){ +module.exports = PriorityQueue; + +/** + * A min-priority queue data structure. This algorithm is derived from Cormen, + * et al., "Introduction to Algorithms". The basic idea of a min-priority + * queue is that you can efficiently (in O(1) time) get the smallest key in + * the queue. Adding and removing elements takes O(log n) time. A key can + * have its priority decreased in O(log n) time. + */ +function PriorityQueue() { + this._arr = []; + this._keyIndices = {}; +} + +/** + * Returns the number of elements in the queue. Takes `O(1)` time. + */ +PriorityQueue.prototype.size = function() { + return this._arr.length; +}; + +/** + * Returns the keys that are in the queue. Takes `O(n)` time. + */ +PriorityQueue.prototype.keys = function() { + return this._arr.map(function(x) { return x.key; }); +}; + +/** + * Returns `true` if **key** is in the queue and `false` if not. + */ +PriorityQueue.prototype.has = function(key) { + return key in this._keyIndices; +}; + +/** + * Returns the priority for **key**. If **key** is not present in the queue + * then this function returns `undefined`. Takes `O(1)` time. + * + * @param {Object} key + */ +PriorityQueue.prototype.priority = function(key) { + var index = this._keyIndices[key]; + if (index !== undefined) { + return this._arr[index].priority; + } +}; + +/** + * Returns the key for the minimum element in this queue. If the queue is + * empty this function throws an Error. Takes `O(1)` time. + */ +PriorityQueue.prototype.min = function() { + if (this.size() === 0) { + throw new Error("Queue underflow"); + } + return this._arr[0].key; +}; + +/** + * Inserts a new key into the priority queue. If the key already exists in + * the queue this function returns `false`; otherwise it will return `true`. + * Takes `O(n)` time. + * + * @param {Object} key the key to add + * @param {Number} priority the initial priority for the key + */ +PriorityQueue.prototype.add = function(key, priority) { + var keyIndices = this._keyIndices; + if (!(key in keyIndices)) { + var arr = this._arr; + var index = arr.length; + keyIndices[key] = index; + arr.push({key: key, priority: priority}); + this._decrease(index); + return true; + } + return false; +}; + +/** + * Removes and returns the smallest key in the queue. Takes `O(log n)` time. + */ +PriorityQueue.prototype.removeMin = function() { + this._swap(0, this._arr.length - 1); + var min = this._arr.pop(); + delete this._keyIndices[min.key]; + this._heapify(0); + return min.key; +}; + +/** + * Decreases the priority for **key** to **priority**. If the new priority is + * greater than the previous priority, this function will throw an Error. + * + * @param {Object} key the key for which to raise priority + * @param {Number} priority the new priority for the key + */ +PriorityQueue.prototype.decrease = function(key, priority) { + var index = this._keyIndices[key]; + if (priority > this._arr[index].priority) { + throw new Error("New priority is greater than current priority. " + + "Key: " + key + " Old: " + this._arr[index].priority + " New: " + priority); + } + this._arr[index].priority = priority; + this._decrease(index); +}; + +PriorityQueue.prototype._heapify = function(i) { + var arr = this._arr; + var l = 2 * i, + r = l + 1, + largest = i; + if (l < arr.length) { + largest = arr[l].priority < arr[largest].priority ? l : largest; + if (r < arr.length) { + largest = arr[r].priority < arr[largest].priority ? r : largest; + } + if (largest !== i) { + this._swap(i, largest); + this._heapify(largest); + } + } +}; + +PriorityQueue.prototype._decrease = function(index) { + var arr = this._arr; + var priority = arr[index].priority; + var parent; + while (index !== 0) { + parent = index >> 1; + if (arr[parent].priority < priority) { + break; + } + this._swap(index, parent); + index = parent; + } +}; + +PriorityQueue.prototype._swap = function(i, j) { + var arr = this._arr; + var keyIndices = this._keyIndices; + var origArrI = arr[i]; + var origArrJ = arr[j]; + arr[i] = origArrJ; + arr[j] = origArrI; + keyIndices[origArrJ.key] = i; + keyIndices[origArrI.key] = j; +}; + +},{}],7:[function(require,module,exports){ +var util = require('./util'); + +module.exports = Set; + +/** + * Constructs a new Set with an optional set of `initialKeys`. + * + * It is important to note that keys are coerced to String for most purposes + * with this object, similar to the behavior of JavaScript's Object. For + * example, the following will add only one key: + * + * var s = new Set(); + * s.add(1); + * s.add("1"); + * + * However, the type of the key is preserved internally so that `keys` returns + * the original key set uncoerced. For the above example, `keys` would return + * `[1]`. + */ +function Set(initialKeys) { + this._size = 0; + this._keys = {}; + + if (initialKeys) { + for (var i = 0, il = initialKeys.length; i < il; ++i) { + this.add(initialKeys[i]); + } + } +} + +/** + * Returns a new Set that represents the set intersection of the array of given + * sets. + */ +Set.intersect = function(sets) { + if (sets.length === 0) { + return new Set(); + } + + var result = new Set(!util.isArray(sets[0]) ? sets[0].keys() : sets[0]); + for (var i = 1, il = sets.length; i < il; ++i) { + var resultKeys = result.keys(), + other = !util.isArray(sets[i]) ? sets[i] : new Set(sets[i]); + for (var j = 0, jl = resultKeys.length; j < jl; ++j) { + var key = resultKeys[j]; + if (!other.has(key)) { + result.remove(key); + } + } + } + + return result; +}; + +/** + * Returns a new Set that represents the set union of the array of given sets. + */ +Set.union = function(sets) { + var totalElems = util.reduce(sets, function(lhs, rhs) { + return lhs + (rhs.size ? rhs.size() : rhs.length); + }, 0); + var arr = new Array(totalElems); + + var k = 0; + for (var i = 0, il = sets.length; i < il; ++i) { + var cur = sets[i], + keys = !util.isArray(cur) ? cur.keys() : cur; + for (var j = 0, jl = keys.length; j < jl; ++j) { + arr[k++] = keys[j]; + } + } + + return new Set(arr); +}; + +/** + * Returns the size of this set in `O(1)` time. + */ +Set.prototype.size = function() { + return this._size; +}; + +/** + * Returns the keys in this set. Takes `O(n)` time. + */ +Set.prototype.keys = function() { + return values(this._keys); +}; + +/** + * Tests if a key is present in this Set. Returns `true` if it is and `false` + * if not. Takes `O(1)` time. + */ +Set.prototype.has = function(key) { + return key in this._keys; +}; + +/** + * Adds a new key to this Set if it is not already present. Returns `true` if + * the key was added and `false` if it was already present. Takes `O(1)` time. + */ +Set.prototype.add = function(key) { + if (!(key in this._keys)) { + this._keys[key] = key; + ++this._size; + return true; + } + return false; +}; + +/** + * Removes a key from this Set. If the key was removed this function returns + * `true`. If not, it returns `false`. Takes `O(1)` time. + */ +Set.prototype.remove = function(key) { + if (key in this._keys) { + delete this._keys[key]; + --this._size; + return true; + } + return false; +}; + +/* + * Returns an array of all values for properties of **o**. + */ +function values(o) { + var ks = Object.keys(o), + len = ks.length, + result = new Array(len), + i; + for (i = 0; i < len; ++i) { + result[i] = o[ks[i]]; + } + return result; +} + +},{"./util":8}],8:[function(require,module,exports){ +/* + * This polyfill comes from + * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray + */ +if(!Array.isArray) { + exports.isArray = function (vArg) { + return Object.prototype.toString.call(vArg) === '[object Array]'; + }; +} else { + exports.isArray = Array.isArray; +} + +/* + * Slightly adapted polyfill from + * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce + */ +if ('function' !== typeof Array.prototype.reduce) { + exports.reduce = function(array, callback, opt_initialValue) { + 'use strict'; + if (null === array || 'undefined' === typeof array) { + // At the moment all modern browsers, that support strict mode, have + // native implementation of Array.prototype.reduce. For instance, IE8 + // does not support strict mode, so this check is actually useless. + throw new TypeError( + 'Array.prototype.reduce called on null or undefined'); + } + if ('function' !== typeof callback) { + throw new TypeError(callback + ' is not a function'); + } + var index, value, + length = array.length >>> 0, + isValueSet = false; + if (1 < arguments.length) { + value = opt_initialValue; + isValueSet = true; + } + for (index = 0; length > index; ++index) { + if (array.hasOwnProperty(index)) { + if (isValueSet) { + value = callback(value, array[index], index, array); + } + else { + value = array[index]; + isValueSet = true; + } + } + } + if (!isValueSet) { + throw new TypeError('Reduce of empty array with no initial value'); + } + return value; + }; +} else { + exports.reduce = function(array, callback, opt_initialValue) { + return array.reduce(callback, opt_initialValue); + }; +} + +},{}],9:[function(require,module,exports){ +module.exports = '1.1.3'; + +},{}],10:[function(require,module,exports){ +require("./d3"); +module.exports = d3; +(function () { delete this.d3; })(); // unset global + +},{}],11:[function(require,module,exports){ +/* +Copyright (c) 2012-2013 Chris Pettitt + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ +exports.Digraph = require("graphlib").Digraph; +exports.Graph = require("graphlib").Graph; +exports.layout = require("./lib/layout"); +exports.version = require("./lib/version"); + +},{"./lib/layout":12,"./lib/version":27,"graphlib":28}],12:[function(require,module,exports){ +var util = require('./util'), + rank = require('./rank'), + order = require('./order'), + CGraph = require('graphlib').CGraph, + CDigraph = require('graphlib').CDigraph; + +module.exports = function() { + // External configuration + var config = { + // How much debug information to include? + debugLevel: 0, + // Max number of sweeps to perform in order phase + orderMaxSweeps: order.DEFAULT_MAX_SWEEPS, + // Use network simplex algorithm in ranking + rankSimplex: false, + // Rank direction. Valid values are (TB, LR) + rankDir: 'TB' + }; + + // Phase functions + var position = require('./position')(); + + // This layout object + var self = {}; + + self.orderIters = util.propertyAccessor(self, config, 'orderMaxSweeps'); + + self.rankSimplex = util.propertyAccessor(self, config, 'rankSimplex'); + + self.nodeSep = delegateProperty(position.nodeSep); + self.edgeSep = delegateProperty(position.edgeSep); + self.universalSep = delegateProperty(position.universalSep); + self.rankSep = delegateProperty(position.rankSep); + self.rankDir = util.propertyAccessor(self, config, 'rankDir'); + self.debugAlignment = delegateProperty(position.debugAlignment); + + self.debugLevel = util.propertyAccessor(self, config, 'debugLevel', function(x) { + util.log.level = x; + position.debugLevel(x); + }); + + self.run = util.time('Total layout', run); + + self._normalize = normalize; + + return self; + + /* + * Constructs an adjacency graph using the nodes and edges specified through + * config. For each node and edge we add a property `dagre` that contains an + * object that will hold intermediate and final layout information. Some of + * the contents include: + * + * 1) A generated ID that uniquely identifies the object. + * 2) Dimension information for nodes (copied from the source node). + * 3) Optional dimension information for edges. + * + * After the adjacency graph is constructed the code no longer needs to use + * the original nodes and edges passed in via config. + */ + function initLayoutGraph(inputGraph) { + var g = new CDigraph(); + + inputGraph.eachNode(function(u, value) { + if (value === undefined) value = {}; + g.addNode(u, { + width: value.width, + height: value.height + }); + if (value.hasOwnProperty('rank')) { + g.node(u).prefRank = value.rank; + } + }); + + // Set up subgraphs + if (inputGraph.parent) { + inputGraph.nodes().forEach(function(u) { + g.parent(u, inputGraph.parent(u)); + }); + } + + inputGraph.eachEdge(function(e, u, v, value) { + if (value === undefined) value = {}; + var newValue = { + e: e, + minLen: value.minLen || 1, + width: value.width || 0, + height: value.height || 0, + points: [] + }; + + g.addEdge(null, u, v, newValue); + }); + + // Initial graph attributes + var graphValue = inputGraph.graph() || {}; + g.graph({ + rankDir: graphValue.rankDir || config.rankDir, + orderRestarts: graphValue.orderRestarts + }); + + return g; + } + + function run(inputGraph) { + var rankSep = self.rankSep(); + var g; + try { + // Build internal graph + g = util.time('initLayoutGraph', initLayoutGraph)(inputGraph); + + if (g.order() === 0) { + return g; + } + + // Make space for edge labels + g.eachEdge(function(e, s, t, a) { + a.minLen *= 2; + }); + self.rankSep(rankSep / 2); + + // Determine the rank for each node. Nodes with a lower rank will appear + // above nodes of higher rank. + util.time('rank.run', rank.run)(g, config.rankSimplex); + + // Normalize the graph by ensuring that every edge is proper (each edge has + // a length of 1). We achieve this by adding dummy nodes to long edges, + // thus shortening them. + util.time('normalize', normalize)(g); + + // Order the nodes so that edge crossings are minimized. + util.time('order', order)(g, config.orderMaxSweeps); + + // Find the x and y coordinates for every node in the graph. + util.time('position', position.run)(g); + + // De-normalize the graph by removing dummy nodes and augmenting the + // original long edges with coordinate information. + util.time('undoNormalize', undoNormalize)(g); + + // Reverses points for edges that are in a reversed state. + util.time('fixupEdgePoints', fixupEdgePoints)(g); + + // Restore delete edges and reverse edges that were reversed in the rank + // phase. + util.time('rank.restoreEdges', rank.restoreEdges)(g); + + // Construct final result graph and return it + return util.time('createFinalGraph', createFinalGraph)(g, inputGraph.isDirected()); + } finally { + self.rankSep(rankSep); + } + } + + /* + * This function is responsible for 'normalizing' the graph. The process of + * normalization ensures that no edge in the graph has spans more than one + * rank. To do this it inserts dummy nodes as needed and links them by adding + * dummy edges. This function keeps enough information in the dummy nodes and + * edges to ensure that the original graph can be reconstructed later. + * + * This method assumes that the input graph is cycle free. + */ + function normalize(g) { + var dummyCount = 0; + g.eachEdge(function(e, s, t, a) { + var sourceRank = g.node(s).rank; + var targetRank = g.node(t).rank; + if (sourceRank + 1 < targetRank) { + for (var u = s, rank = sourceRank + 1, i = 0; rank < targetRank; ++rank, ++i) { + var v = '_D' + (++dummyCount); + var node = { + width: a.width, + height: a.height, + edge: { id: e, source: s, target: t, attrs: a }, + rank: rank, + dummy: true + }; + + // If this node represents a bend then we will use it as a control + // point. For edges with 2 segments this will be the center dummy + // node. For edges with more than two segments, this will be the + // first and last dummy node. + if (i === 0) node.index = 0; + else if (rank + 1 === targetRank) node.index = 1; + + g.addNode(v, node); + g.addEdge(null, u, v, {}); + u = v; + } + g.addEdge(null, u, t, {}); + g.delEdge(e); + } + }); + } + + /* + * Reconstructs the graph as it was before normalization. The positions of + * dummy nodes are used to build an array of points for the original 'long' + * edge. Dummy nodes and edges are removed. + */ + function undoNormalize(g) { + g.eachNode(function(u, a) { + if (a.dummy) { + if ('index' in a) { + var edge = a.edge; + if (!g.hasEdge(edge.id)) { + g.addEdge(edge.id, edge.source, edge.target, edge.attrs); + } + var points = g.edge(edge.id).points; + points[a.index] = { x: a.x, y: a.y, ul: a.ul, ur: a.ur, dl: a.dl, dr: a.dr }; + } + g.delNode(u); + } + }); + } + + /* + * For each edge that was reversed during the `acyclic` step, reverse its + * array of points. + */ + function fixupEdgePoints(g) { + g.eachEdge(function(e, s, t, a) { if (a.reversed) a.points.reverse(); }); + } + + function createFinalGraph(g, isDirected) { + var out = isDirected ? new CDigraph() : new CGraph(); + out.graph(g.graph()); + g.eachNode(function(u, value) { out.addNode(u, value); }); + g.eachNode(function(u) { out.parent(u, g.parent(u)); }); + g.eachEdge(function(e, u, v, value) { + out.addEdge(value.e, u, v, value); + }); + + // Attach bounding box information + var maxX = 0, maxY = 0; + g.eachNode(function(u, value) { + if (!g.children(u).length) { + maxX = Math.max(maxX, value.x + value.width / 2); + maxY = Math.max(maxY, value.y + value.height / 2); + } + }); + g.eachEdge(function(e, u, v, value) { + var maxXPoints = Math.max.apply(Math, value.points.map(function(p) { return p.x; })); + var maxYPoints = Math.max.apply(Math, value.points.map(function(p) { return p.y; })); + maxX = Math.max(maxX, maxXPoints + value.width / 2); + maxY = Math.max(maxY, maxYPoints + value.height / 2); + }); + out.graph().width = maxX; + out.graph().height = maxY; + + return out; + } + + /* + * Given a function, a new function is returned that invokes the given + * function. The return value from the function is always the `self` object. + */ + function delegateProperty(f) { + return function() { + if (!arguments.length) return f(); + f.apply(null, arguments); + return self; + }; + } +}; + + +},{"./order":13,"./position":18,"./rank":19,"./util":26,"graphlib":28}],13:[function(require,module,exports){ +var util = require('./util'), + crossCount = require('./order/crossCount'), + initLayerGraphs = require('./order/initLayerGraphs'), + initOrder = require('./order/initOrder'), + sortLayer = require('./order/sortLayer'); + +module.exports = order; + +// The maximum number of sweeps to perform before finishing the order phase. +var DEFAULT_MAX_SWEEPS = 24; +order.DEFAULT_MAX_SWEEPS = DEFAULT_MAX_SWEEPS; + +/* + * Runs the order phase with the specified `graph, `maxSweeps`, and + * `debugLevel`. If `maxSweeps` is not specified we use `DEFAULT_MAX_SWEEPS`. + * If `debugLevel` is not set we assume 0. + */ +function order(g, maxSweeps) { + if (arguments.length < 2) { + maxSweeps = DEFAULT_MAX_SWEEPS; + } + + var restarts = g.graph().orderRestarts || 0; + + var layerGraphs = initLayerGraphs(g); + // TODO: remove this when we add back support for ordering clusters + layerGraphs.forEach(function(lg) { + lg = lg.filterNodes(function(u) { return !g.children(u).length; }); + }); + + var iters = 0, + currentBestCC, + allTimeBestCC = Number.MAX_VALUE, + allTimeBest = {}; + + function saveAllTimeBest() { + g.eachNode(function(u, value) { allTimeBest[u] = value.order; }); + } + + for (var j = 0; j < Number(restarts) + 1 && allTimeBestCC !== 0; ++j) { + currentBestCC = Number.MAX_VALUE; + initOrder(g, restarts > 0); + + util.log(2, 'Order phase start cross count: ' + g.graph().orderInitCC); + + var i, lastBest, cc; + for (i = 0, lastBest = 0; lastBest < 4 && i < maxSweeps && currentBestCC > 0; ++i, ++lastBest, ++iters) { + sweep(g, layerGraphs, i); + cc = crossCount(g); + if (cc < currentBestCC) { + lastBest = 0; + currentBestCC = cc; + if (cc < allTimeBestCC) { + saveAllTimeBest(); + allTimeBestCC = cc; + } + } + util.log(3, 'Order phase start ' + j + ' iter ' + i + ' cross count: ' + cc); + } + } + + Object.keys(allTimeBest).forEach(function(u) { + if (!g.children || !g.children(u).length) { + g.node(u).order = allTimeBest[u]; + } + }); + g.graph().orderCC = allTimeBestCC; + + util.log(2, 'Order iterations: ' + iters); + util.log(2, 'Order phase best cross count: ' + g.graph().orderCC); +} + +function predecessorWeights(g, nodes) { + var weights = {}; + nodes.forEach(function(u) { + weights[u] = g.inEdges(u).map(function(e) { + return g.node(g.source(e)).order; + }); + }); + return weights; +} + +function successorWeights(g, nodes) { + var weights = {}; + nodes.forEach(function(u) { + weights[u] = g.outEdges(u).map(function(e) { + return g.node(g.target(e)).order; + }); + }); + return weights; +} + +function sweep(g, layerGraphs, iter) { + if (iter % 2 === 0) { + sweepDown(g, layerGraphs, iter); + } else { + sweepUp(g, layerGraphs, iter); + } +} + +function sweepDown(g, layerGraphs) { + var cg; + for (i = 1; i < layerGraphs.length; ++i) { + cg = sortLayer(layerGraphs[i], cg, predecessorWeights(g, layerGraphs[i].nodes())); + } +} + +function sweepUp(g, layerGraphs) { + var cg; + for (i = layerGraphs.length - 2; i >= 0; --i) { + sortLayer(layerGraphs[i], cg, successorWeights(g, layerGraphs[i].nodes())); + } +} + +},{"./order/crossCount":14,"./order/initLayerGraphs":15,"./order/initOrder":16,"./order/sortLayer":17,"./util":26}],14:[function(require,module,exports){ +var util = require('../util'); + +module.exports = crossCount; + +/* + * Returns the cross count for the given graph. + */ +function crossCount(g) { + var cc = 0; + var ordering = util.ordering(g); + for (var i = 1; i < ordering.length; ++i) { + cc += twoLayerCrossCount(g, ordering[i-1], ordering[i]); + } + return cc; +} + +/* + * This function searches through a ranked and ordered graph and counts the + * number of edges that cross. This algorithm is derived from: + * + * W. Barth et al., Bilayer Cross Counting, JGAA, 8(2) 179–194 (2004) + */ +function twoLayerCrossCount(g, layer1, layer2) { + var indices = []; + layer1.forEach(function(u) { + var nodeIndices = []; + g.outEdges(u).forEach(function(e) { nodeIndices.push(g.node(g.target(e)).order); }); + nodeIndices.sort(function(x, y) { return x - y; }); + indices = indices.concat(nodeIndices); + }); + + var firstIndex = 1; + while (firstIndex < layer2.length) firstIndex <<= 1; + + var treeSize = 2 * firstIndex - 1; + firstIndex -= 1; + + var tree = []; + for (var i = 0; i < treeSize; ++i) { tree[i] = 0; } + + var cc = 0; + indices.forEach(function(i) { + var treeIndex = i + firstIndex; + ++tree[treeIndex]; + while (treeIndex > 0) { + if (treeIndex % 2) { + cc += tree[treeIndex + 1]; + } + treeIndex = (treeIndex - 1) >> 1; + ++tree[treeIndex]; + } + }); + + return cc; +} + +},{"../util":26}],15:[function(require,module,exports){ +var nodesFromList = require('graphlib').filter.nodesFromList, + /* jshint -W079 */ + Set = require('cp-data').Set; + +module.exports = initLayerGraphs; + +/* + * This function takes a compound layered graph, g, and produces an array of + * layer graphs. Each entry in the array represents a subgraph of nodes + * relevant for performing crossing reduction on that layer. + */ +function initLayerGraphs(g) { + var ranks = []; + + function dfs(u) { + if (u === null) { + g.children(u).forEach(function(v) { dfs(v); }); + return; + } + + var value = g.node(u); + value.minRank = ('rank' in value) ? value.rank : Number.MAX_VALUE; + value.maxRank = ('rank' in value) ? value.rank : Number.MIN_VALUE; + var uRanks = new Set(); + g.children(u).forEach(function(v) { + var rs = dfs(v); + uRanks = Set.union([uRanks, rs]); + value.minRank = Math.min(value.minRank, g.node(v).minRank); + value.maxRank = Math.max(value.maxRank, g.node(v).maxRank); + }); + + if ('rank' in value) uRanks.add(value.rank); + + uRanks.keys().forEach(function(r) { + if (!(r in ranks)) ranks[r] = []; + ranks[r].push(u); + }); + + return uRanks; + } + dfs(null); + + var layerGraphs = []; + ranks.forEach(function(us, rank) { + layerGraphs[rank] = g.filterNodes(nodesFromList(us)); + }); + + return layerGraphs; +} + +},{"cp-data":5,"graphlib":28}],16:[function(require,module,exports){ +var crossCount = require('./crossCount'), + util = require('../util'); + +module.exports = initOrder; + +/* + * Given a graph with a set of layered nodes (i.e. nodes that have a `rank` + * attribute) this function attaches an `order` attribute that uniquely + * arranges each node of each rank. If no constraint graph is provided the + * order of the nodes in each rank is entirely arbitrary. + */ +function initOrder(g, random) { + var layers = []; + + g.eachNode(function(u, value) { + var layer = layers[value.rank]; + if (g.children && g.children(u).length > 0) return; + if (!layer) { + layer = layers[value.rank] = []; + } + layer.push(u); + }); + + layers.forEach(function(layer) { + if (random) { + util.shuffle(layer); + } + layer.forEach(function(u, i) { + g.node(u).order = i; + }); + }); + + var cc = crossCount(g); + g.graph().orderInitCC = cc; + g.graph().orderCC = Number.MAX_VALUE; +} + +},{"../util":26,"./crossCount":14}],17:[function(require,module,exports){ +var util = require('../util'); +/* + Digraph = require('graphlib').Digraph, + topsort = require('graphlib').alg.topsort, + nodesFromList = require('graphlib').filter.nodesFromList; +*/ + +module.exports = sortLayer; + +/* +function sortLayer(g, cg, weights) { + var result = sortLayerSubgraph(g, null, cg, weights); + result.list.forEach(function(u, i) { + g.node(u).order = i; + }); + return result.constraintGraph; +} +*/ + +function sortLayer(g, cg, weights) { + var ordering = []; + var bs = {}; + g.eachNode(function(u, value) { + ordering[value.order] = u; + var ws = weights[u]; + if (ws.length) { + bs[u] = util.sum(ws) / ws.length; + } + }); + + var toSort = g.nodes().filter(function(u) { return bs[u] !== undefined; }); + toSort.sort(function(x, y) { + return bs[x] - bs[y] || g.node(x).order - g.node(y).order; + }); + + for (var i = 0, j = 0, jl = toSort.length; j < jl; ++i) { + if (bs[ordering[i]] !== undefined) { + g.node(toSort[j++]).order = i; + } + } +} + +// TOOD: re-enable constrained sorting once we have a strategy for handling +// undefined barycenters. +/* +function sortLayerSubgraph(g, sg, cg, weights) { + cg = cg ? cg.filterNodes(nodesFromList(g.children(sg))) : new Digraph(); + + var nodeData = {}; + g.children(sg).forEach(function(u) { + if (g.children(u).length) { + nodeData[u] = sortLayerSubgraph(g, u, cg, weights); + nodeData[u].firstSG = u; + nodeData[u].lastSG = u; + } else { + var ws = weights[u]; + nodeData[u] = { + degree: ws.length, + barycenter: ws.length > 0 ? util.sum(ws) / ws.length : 0, + list: [u] + }; + } + }); + + resolveViolatedConstraints(g, cg, nodeData); + + var keys = Object.keys(nodeData); + keys.sort(function(x, y) { + return nodeData[x].barycenter - nodeData[y].barycenter; + }); + + var result = keys.map(function(u) { return nodeData[u]; }) + .reduce(function(lhs, rhs) { return mergeNodeData(g, lhs, rhs); }); + return result; +} + +/* +function mergeNodeData(g, lhs, rhs) { + var cg = mergeDigraphs(lhs.constraintGraph, rhs.constraintGraph); + + if (lhs.lastSG !== undefined && rhs.firstSG !== undefined) { + if (cg === undefined) { + cg = new Digraph(); + } + if (!cg.hasNode(lhs.lastSG)) { cg.addNode(lhs.lastSG); } + cg.addNode(rhs.firstSG); + cg.addEdge(null, lhs.lastSG, rhs.firstSG); + } + + return { + degree: lhs.degree + rhs.degree, + barycenter: (lhs.barycenter * lhs.degree + rhs.barycenter * rhs.degree) / + (lhs.degree + rhs.degree), + list: lhs.list.concat(rhs.list), + firstSG: lhs.firstSG !== undefined ? lhs.firstSG : rhs.firstSG, + lastSG: rhs.lastSG !== undefined ? rhs.lastSG : lhs.lastSG, + constraintGraph: cg + }; +} + +function mergeDigraphs(lhs, rhs) { + if (lhs === undefined) return rhs; + if (rhs === undefined) return lhs; + + lhs = lhs.copy(); + rhs.nodes().forEach(function(u) { lhs.addNode(u); }); + rhs.edges().forEach(function(e, u, v) { lhs.addEdge(null, u, v); }); + return lhs; +} + +function resolveViolatedConstraints(g, cg, nodeData) { + // Removes nodes `u` and `v` from `cg` and makes any edges incident on them + // incident on `w` instead. + function collapseNodes(u, v, w) { + // TODO original paper removes self loops, but it is not obvious when this would happen + cg.inEdges(u).forEach(function(e) { + cg.delEdge(e); + cg.addEdge(null, cg.source(e), w); + }); + + cg.outEdges(v).forEach(function(e) { + cg.delEdge(e); + cg.addEdge(null, w, cg.target(e)); + }); + + cg.delNode(u); + cg.delNode(v); + } + + var violated; + while ((violated = findViolatedConstraint(cg, nodeData)) !== undefined) { + var source = cg.source(violated), + target = cg.target(violated); + + var v; + while ((v = cg.addNode(null)) && g.hasNode(v)) { + cg.delNode(v); + } + + // Collapse barycenter and list + nodeData[v] = mergeNodeData(g, nodeData[source], nodeData[target]); + delete nodeData[source]; + delete nodeData[target]; + + collapseNodes(source, target, v); + if (cg.incidentEdges(v).length === 0) { cg.delNode(v); } + } +} + +function findViolatedConstraint(cg, nodeData) { + var us = topsort(cg); + for (var i = 0; i < us.length; ++i) { + var u = us[i]; + var inEdges = cg.inEdges(u); + for (var j = 0; j < inEdges.length; ++j) { + var e = inEdges[j]; + if (nodeData[cg.source(e)].barycenter >= nodeData[u].barycenter) { + return e; + } + } + } +} +*/ + +},{"../util":26}],18:[function(require,module,exports){ +var util = require('./util'); + +/* + * The algorithms here are based on Brandes and Köpf, "Fast and Simple + * Horizontal Coordinate Assignment". + */ +module.exports = function() { + // External configuration + var config = { + nodeSep: 50, + edgeSep: 10, + universalSep: null, + rankSep: 30 + }; + + var self = {}; + + self.nodeSep = util.propertyAccessor(self, config, 'nodeSep'); + self.edgeSep = util.propertyAccessor(self, config, 'edgeSep'); + // If not null this separation value is used for all nodes and edges + // regardless of their widths. `nodeSep` and `edgeSep` are ignored with this + // option. + self.universalSep = util.propertyAccessor(self, config, 'universalSep'); + self.rankSep = util.propertyAccessor(self, config, 'rankSep'); + self.debugLevel = util.propertyAccessor(self, config, 'debugLevel'); + + self.run = run; + + return self; + + function run(g) { + g = g.filterNodes(util.filterNonSubgraphs(g)); + + var layering = util.ordering(g); + + var conflicts = findConflicts(g, layering); + + var xss = {}; + ['u', 'd'].forEach(function(vertDir) { + if (vertDir === 'd') layering.reverse(); + + ['l', 'r'].forEach(function(horizDir) { + if (horizDir === 'r') reverseInnerOrder(layering); + + var dir = vertDir + horizDir; + var align = verticalAlignment(g, layering, conflicts, vertDir === 'u' ? 'predecessors' : 'successors'); + xss[dir]= horizontalCompaction(g, layering, align.pos, align.root, align.align); + + if (config.debugLevel >= 3) + debugPositioning(vertDir + horizDir, g, layering, xss[dir]); + + if (horizDir === 'r') flipHorizontally(xss[dir]); + + if (horizDir === 'r') reverseInnerOrder(layering); + }); + + if (vertDir === 'd') layering.reverse(); + }); + + balance(g, layering, xss); + + g.eachNode(function(v) { + var xs = []; + for (var alignment in xss) { + var alignmentX = xss[alignment][v]; + posXDebug(alignment, g, v, alignmentX); + xs.push(alignmentX); + } + xs.sort(function(x, y) { return x - y; }); + posX(g, v, (xs[1] + xs[2]) / 2); + }); + + // Align y coordinates with ranks + var y = 0, reverseY = g.graph().rankDir === 'BT' || g.graph().rankDir === 'RL'; + layering.forEach(function(layer) { + var maxHeight = util.max(layer.map(function(u) { return height(g, u); })); + y += maxHeight / 2; + layer.forEach(function(u) { + posY(g, u, reverseY ? -y : y); + }); + y += maxHeight / 2 + config.rankSep; + }); + + // Translate layout so that top left corner of bounding rectangle has + // coordinate (0, 0). + var minX = util.min(g.nodes().map(function(u) { return posX(g, u) - width(g, u) / 2; })); + var minY = util.min(g.nodes().map(function(u) { return posY(g, u) - height(g, u) / 2; })); + g.eachNode(function(u) { + posX(g, u, posX(g, u) - minX); + posY(g, u, posY(g, u) - minY); + }); + } + + /* + * Generate an ID that can be used to represent any undirected edge that is + * incident on `u` and `v`. + */ + function undirEdgeId(u, v) { + return u < v + ? u.toString().length + ':' + u + '-' + v + : v.toString().length + ':' + v + '-' + u; + } + + function findConflicts(g, layering) { + var conflicts = {}, // Set of conflicting edge ids + pos = {}, // Position of node in its layer + prevLayer, + currLayer, + k0, // Position of the last inner segment in the previous layer + l, // Current position in the current layer (for iteration up to `l1`) + k1; // Position of the next inner segment in the previous layer or + // the position of the last element in the previous layer + + if (layering.length <= 2) return conflicts; + + function updateConflicts(v) { + var k = pos[v]; + if (k < k0 || k > k1) { + conflicts[undirEdgeId(currLayer[l], v)] = true; + } + } + + layering[1].forEach(function(u, i) { pos[u] = i; }); + for (var i = 1; i < layering.length - 1; ++i) { + prevLayer = layering[i]; + currLayer = layering[i+1]; + k0 = 0; + l = 0; + + // Scan current layer for next node that is incident to an inner segement + // between layering[i+1] and layering[i]. + for (var l1 = 0; l1 < currLayer.length; ++l1) { + var u = currLayer[l1]; // Next inner segment in the current layer or + // last node in the current layer + pos[u] = l1; + k1 = undefined; + + if (g.node(u).dummy) { + var uPred = g.predecessors(u)[0]; + // Note: In the case of self loops and sideways edges it is possible + // for a dummy not to have a predecessor. + if (uPred !== undefined && g.node(uPred).dummy) + k1 = pos[uPred]; + } + if (k1 === undefined && l1 === currLayer.length - 1) + k1 = prevLayer.length - 1; + + if (k1 !== undefined) { + for (; l <= l1; ++l) { + g.predecessors(currLayer[l]).forEach(updateConflicts); + } + k0 = k1; + } + } + } + + return conflicts; + } + + function verticalAlignment(g, layering, conflicts, relationship) { + var pos = {}, // Position for a node in its layer + root = {}, // Root of the block that the node participates in + align = {}; // Points to the next node in the block or, if the last + // element in the block, points to the first block's root + + layering.forEach(function(layer) { + layer.forEach(function(u, i) { + root[u] = u; + align[u] = u; + pos[u] = i; + }); + }); + + layering.forEach(function(layer) { + var prevIdx = -1; + layer.forEach(function(v) { + var related = g[relationship](v), // Adjacent nodes from the previous layer + mid; // The mid point in the related array + + if (related.length > 0) { + related.sort(function(x, y) { return pos[x] - pos[y]; }); + mid = (related.length - 1) / 2; + related.slice(Math.floor(mid), Math.ceil(mid) + 1).forEach(function(u) { + if (align[v] === v) { + if (!conflicts[undirEdgeId(u, v)] && prevIdx < pos[u]) { + align[u] = v; + align[v] = root[v] = root[u]; + prevIdx = pos[u]; + } + } + }); + } + }); + }); + + return { pos: pos, root: root, align: align }; + } + + // This function deviates from the standard BK algorithm in two ways. First + // it takes into account the size of the nodes. Second it includes a fix to + // the original algorithm that is described in Carstens, "Node and Label + // Placement in a Layered Layout Algorithm". + function horizontalCompaction(g, layering, pos, root, align) { + var sink = {}, // Mapping of node id -> sink node id for class + maybeShift = {}, // Mapping of sink node id -> { class node id, min shift } + shift = {}, // Mapping of sink node id -> shift + pred = {}, // Mapping of node id -> predecessor node (or null) + xs = {}; // Calculated X positions + + layering.forEach(function(layer) { + layer.forEach(function(u, i) { + sink[u] = u; + maybeShift[u] = {}; + if (i > 0) + pred[u] = layer[i - 1]; + }); + }); + + function updateShift(toShift, neighbor, delta) { + if (!(neighbor in maybeShift[toShift])) { + maybeShift[toShift][neighbor] = delta; + } else { + maybeShift[toShift][neighbor] = Math.min(maybeShift[toShift][neighbor], delta); + } + } + + function placeBlock(v) { + if (!(v in xs)) { + xs[v] = 0; + var w = v; + do { + if (pos[w] > 0) { + var u = root[pred[w]]; + placeBlock(u); + if (sink[v] === v) { + sink[v] = sink[u]; + } + var delta = sep(g, pred[w]) + sep(g, w); + if (sink[v] !== sink[u]) { + updateShift(sink[u], sink[v], xs[v] - xs[u] - delta); + } else { + xs[v] = Math.max(xs[v], xs[u] + delta); + } + } + w = align[w]; + } while (w !== v); + } + } + + // Root coordinates relative to sink + util.values(root).forEach(function(v) { + placeBlock(v); + }); + + // Absolute coordinates + // There is an assumption here that we've resolved shifts for any classes + // that begin at an earlier layer. We guarantee this by visiting layers in + // order. + layering.forEach(function(layer) { + layer.forEach(function(v) { + xs[v] = xs[root[v]]; + if (v === root[v] && v === sink[v]) { + var minShift = 0; + if (v in maybeShift && Object.keys(maybeShift[v]).length > 0) { + minShift = util.min(Object.keys(maybeShift[v]) + .map(function(u) { + return maybeShift[v][u] + (u in shift ? shift[u] : 0); + } + )); + } + shift[v] = minShift; + } + }); + }); + + layering.forEach(function(layer) { + layer.forEach(function(v) { + xs[v] += shift[sink[root[v]]] || 0; + }); + }); + + return xs; + } + + function findMinCoord(g, layering, xs) { + return util.min(layering.map(function(layer) { + var u = layer[0]; + return xs[u]; + })); + } + + function findMaxCoord(g, layering, xs) { + return util.max(layering.map(function(layer) { + var u = layer[layer.length - 1]; + return xs[u]; + })); + } + + function balance(g, layering, xss) { + var min = {}, // Min coordinate for the alignment + max = {}, // Max coordinate for the alginment + smallestAlignment, + shift = {}; // Amount to shift a given alignment + + function updateAlignment(v) { + xss[alignment][v] += shift[alignment]; + } + + var smallest = Number.POSITIVE_INFINITY; + for (var alignment in xss) { + var xs = xss[alignment]; + min[alignment] = findMinCoord(g, layering, xs); + max[alignment] = findMaxCoord(g, layering, xs); + var w = max[alignment] - min[alignment]; + if (w < smallest) { + smallest = w; + smallestAlignment = alignment; + } + } + + // Determine how much to adjust positioning for each alignment + ['u', 'd'].forEach(function(vertDir) { + ['l', 'r'].forEach(function(horizDir) { + var alignment = vertDir + horizDir; + shift[alignment] = horizDir === 'l' + ? min[smallestAlignment] - min[alignment] + : max[smallestAlignment] - max[alignment]; + }); + }); + + // Find average of medians for xss array + for (alignment in xss) { + g.eachNode(updateAlignment); + } + } + + function flipHorizontally(xs) { + for (var u in xs) { + xs[u] = -xs[u]; + } + } + + function reverseInnerOrder(layering) { + layering.forEach(function(layer) { + layer.reverse(); + }); + } + + function width(g, u) { + switch (g.graph().rankDir) { + case 'LR': return g.node(u).height; + case 'RL': return g.node(u).height; + default: return g.node(u).width; + } + } + + function height(g, u) { + switch(g.graph().rankDir) { + case 'LR': return g.node(u).width; + case 'RL': return g.node(u).width; + default: return g.node(u).height; + } + } + + function sep(g, u) { + if (config.universalSep !== null) { + return config.universalSep; + } + var w = width(g, u); + var s = g.node(u).dummy ? config.edgeSep : config.nodeSep; + return (w + s) / 2; + } + + function posX(g, u, x) { + if (g.graph().rankDir === 'LR' || g.graph().rankDir === 'RL') { + if (arguments.length < 3) { + return g.node(u).y; + } else { + g.node(u).y = x; + } + } else { + if (arguments.length < 3) { + return g.node(u).x; + } else { + g.node(u).x = x; + } + } + } + + function posXDebug(name, g, u, x) { + if (g.graph().rankDir === 'LR' || g.graph().rankDir === 'RL') { + if (arguments.length < 3) { + return g.node(u)[name]; + } else { + g.node(u)[name] = x; + } + } else { + if (arguments.length < 3) { + return g.node(u)[name]; + } else { + g.node(u)[name] = x; + } + } + } + + function posY(g, u, y) { + if (g.graph().rankDir === 'LR' || g.graph().rankDir === 'RL') { + if (arguments.length < 3) { + return g.node(u).x; + } else { + g.node(u).x = y; + } + } else { + if (arguments.length < 3) { + return g.node(u).y; + } else { + g.node(u).y = y; + } + } + } + + function debugPositioning(align, g, layering, xs) { + layering.forEach(function(l, li) { + var u, xU; + l.forEach(function(v) { + var xV = xs[v]; + if (u) { + var s = sep(g, u) + sep(g, v); + if (xV - xU < s) + console.log('Position phase: sep violation. Align: ' + align + '. Layer: ' + li + '. ' + + 'U: ' + u + ' V: ' + v + '. Actual sep: ' + (xV - xU) + ' Expected sep: ' + s); + } + u = v; + xU = xV; + }); + }); + } +}; + +},{"./util":26}],19:[function(require,module,exports){ +var util = require('./util'), + acyclic = require('./rank/acyclic'), + initRank = require('./rank/initRank'), + feasibleTree = require('./rank/feasibleTree'), + constraints = require('./rank/constraints'), + simplex = require('./rank/simplex'), + components = require('graphlib').alg.components, + filter = require('graphlib').filter; + +exports.run = run; +exports.restoreEdges = restoreEdges; + +/* + * Heuristic function that assigns a rank to each node of the input graph with + * the intent of minimizing edge lengths, while respecting the `minLen` + * attribute of incident edges. + * + * Prerequisites: + * + * * Each edge in the input graph must have an assigned 'minLen' attribute + */ +function run(g, useSimplex) { + expandSelfLoops(g); + + // If there are rank constraints on nodes, then build a new graph that + // encodes the constraints. + util.time('constraints.apply', constraints.apply)(g); + + expandSidewaysEdges(g); + + // Reverse edges to get an acyclic graph, we keep the graph in an acyclic + // state until the very end. + util.time('acyclic', acyclic)(g); + + // Convert the graph into a flat graph for ranking + var flatGraph = g.filterNodes(util.filterNonSubgraphs(g)); + + // Assign an initial ranking using DFS. + initRank(flatGraph); + + // For each component improve the assigned ranks. + components(flatGraph).forEach(function(cmpt) { + var subgraph = flatGraph.filterNodes(filter.nodesFromList(cmpt)); + rankComponent(subgraph, useSimplex); + }); + + // Relax original constraints + util.time('constraints.relax', constraints.relax(g)); + + // When handling nodes with constrained ranks it is possible to end up with + // edges that point to previous ranks. Most of the subsequent algorithms assume + // that edges are pointing to successive ranks only. Here we reverse any "back + // edges" and mark them as such. The acyclic algorithm will reverse them as a + // post processing step. + util.time('reorientEdges', reorientEdges)(g); +} + +function restoreEdges(g) { + acyclic.undo(g); +} + +/* + * Expand self loops into three dummy nodes. One will sit above the incident + * node, one will be at the same level, and one below. The result looks like: + * + * /--<--x--->--\ + * node y + * \--<--z--->--/ + * + * Dummy nodes x, y, z give us the shape of a loop and node y is where we place + * the label. + * + * TODO: consolidate knowledge of dummy node construction. + * TODO: support minLen = 2 + */ +function expandSelfLoops(g) { + g.eachEdge(function(e, u, v, a) { + if (u === v) { + var x = addDummyNode(g, e, u, v, a, 0, false), + y = addDummyNode(g, e, u, v, a, 1, true), + z = addDummyNode(g, e, u, v, a, 2, false); + g.addEdge(null, x, u, {minLen: 1, selfLoop: true}); + g.addEdge(null, x, y, {minLen: 1, selfLoop: true}); + g.addEdge(null, u, z, {minLen: 1, selfLoop: true}); + g.addEdge(null, y, z, {minLen: 1, selfLoop: true}); + g.delEdge(e); + } + }); +} + +function expandSidewaysEdges(g) { + g.eachEdge(function(e, u, v, a) { + if (u === v) { + var origEdge = a.originalEdge, + dummy = addDummyNode(g, origEdge.e, origEdge.u, origEdge.v, origEdge.value, 0, true); + g.addEdge(null, u, dummy, {minLen: 1}); + g.addEdge(null, dummy, v, {minLen: 1}); + g.delEdge(e); + } + }); +} + +function addDummyNode(g, e, u, v, a, index, isLabel) { + return g.addNode(null, { + width: isLabel ? a.width : 0, + height: isLabel ? a.height : 0, + edge: { id: e, source: u, target: v, attrs: a }, + dummy: true, + index: index + }); +} + +function reorientEdges(g) { + g.eachEdge(function(e, u, v, value) { + if (g.node(u).rank > g.node(v).rank) { + g.delEdge(e); + value.reversed = true; + g.addEdge(e, v, u, value); + } + }); +} + +function rankComponent(subgraph, useSimplex) { + var spanningTree = feasibleTree(subgraph); + + if (useSimplex) { + util.log(1, 'Using network simplex for ranking'); + simplex(subgraph, spanningTree); + } + normalize(subgraph); +} + +function normalize(g) { + var m = util.min(g.nodes().map(function(u) { return g.node(u).rank; })); + g.eachNode(function(u, node) { node.rank -= m; }); +} + +},{"./rank/acyclic":20,"./rank/constraints":21,"./rank/feasibleTree":22,"./rank/initRank":23,"./rank/simplex":25,"./util":26,"graphlib":28}],20:[function(require,module,exports){ +var util = require('../util'); + +module.exports = acyclic; +module.exports.undo = undo; + +/* + * This function takes a directed graph that may have cycles and reverses edges + * as appropriate to break these cycles. Each reversed edge is assigned a + * `reversed` attribute with the value `true`. + * + * There should be no self loops in the graph. + */ +function acyclic(g) { + var onStack = {}, + visited = {}, + reverseCount = 0; + + function dfs(u) { + if (u in visited) return; + visited[u] = onStack[u] = true; + g.outEdges(u).forEach(function(e) { + var t = g.target(e), + value; + + if (u === t) { + console.error('Warning: found self loop "' + e + '" for node "' + u + '"'); + } else if (t in onStack) { + value = g.edge(e); + g.delEdge(e); + value.reversed = true; + ++reverseCount; + g.addEdge(e, t, u, value); + } else { + dfs(t); + } + }); + + delete onStack[u]; + } + + g.eachNode(function(u) { dfs(u); }); + + util.log(2, 'Acyclic Phase: reversed ' + reverseCount + ' edge(s)'); + + return reverseCount; +} + +/* + * Given a graph that has had the acyclic operation applied, this function + * undoes that operation. More specifically, any edge with the `reversed` + * attribute is again reversed to restore the original direction of the edge. + */ +function undo(g) { + g.eachEdge(function(e, s, t, a) { + if (a.reversed) { + delete a.reversed; + g.delEdge(e); + g.addEdge(e, t, s, a); + } + }); +} + +},{"../util":26}],21:[function(require,module,exports){ +exports.apply = function(g) { + function dfs(sg) { + var rankSets = {}; + g.children(sg).forEach(function(u) { + if (g.children(u).length) { + dfs(u); + return; + } + + var value = g.node(u), + prefRank = value.prefRank; + if (prefRank !== undefined) { + if (!checkSupportedPrefRank(prefRank)) { return; } + + if (!(prefRank in rankSets)) { + rankSets.prefRank = [u]; + } else { + rankSets.prefRank.push(u); + } + + var newU = rankSets[prefRank]; + if (newU === undefined) { + newU = rankSets[prefRank] = g.addNode(null, { originalNodes: [] }); + g.parent(newU, sg); + } + + redirectInEdges(g, u, newU, prefRank === 'min'); + redirectOutEdges(g, u, newU, prefRank === 'max'); + + // Save original node and remove it from reduced graph + g.node(newU).originalNodes.push({ u: u, value: value, parent: sg }); + g.delNode(u); + } + }); + + addLightEdgesFromMinNode(g, sg, rankSets.min); + addLightEdgesToMaxNode(g, sg, rankSets.max); + } + + dfs(null); +}; + +function checkSupportedPrefRank(prefRank) { + if (prefRank !== 'min' && prefRank !== 'max' && prefRank.indexOf('same_') !== 0) { + console.error('Unsupported rank type: ' + prefRank); + return false; + } + return true; +} + +function redirectInEdges(g, u, newU, reverse) { + g.inEdges(u).forEach(function(e) { + var origValue = g.edge(e), + value; + if (origValue.originalEdge) { + value = origValue; + } else { + value = { + originalEdge: { e: e, u: g.source(e), v: g.target(e), value: origValue }, + minLen: g.edge(e).minLen + }; + } + + // Do not reverse edges for self-loops. + if (origValue.selfLoop) { + reverse = false; + } + + if (reverse) { + // Ensure that all edges to min are reversed + g.addEdge(null, newU, g.source(e), value); + value.reversed = true; + } else { + g.addEdge(null, g.source(e), newU, value); + } + }); +} + +function redirectOutEdges(g, u, newU, reverse) { + g.outEdges(u).forEach(function(e) { + var origValue = g.edge(e), + value; + if (origValue.originalEdge) { + value = origValue; + } else { + value = { + originalEdge: { e: e, u: g.source(e), v: g.target(e), value: origValue }, + minLen: g.edge(e).minLen + }; + } + + // Do not reverse edges for self-loops. + if (origValue.selfLoop) { + reverse = false; + } + + if (reverse) { + // Ensure that all edges from max are reversed + g.addEdge(null, g.target(e), newU, value); + value.reversed = true; + } else { + g.addEdge(null, newU, g.target(e), value); + } + }); +} + +function addLightEdgesFromMinNode(g, sg, minNode) { + if (minNode !== undefined) { + g.children(sg).forEach(function(u) { + // The dummy check ensures we don't add an edge if the node is involved + // in a self loop or sideways edge. + if (u !== minNode && !g.outEdges(minNode, u).length && !g.node(u).dummy) { + g.addEdge(null, minNode, u, { minLen: 0 }); + } + }); + } +} + +function addLightEdgesToMaxNode(g, sg, maxNode) { + if (maxNode !== undefined) { + g.children(sg).forEach(function(u) { + // The dummy check ensures we don't add an edge if the node is involved + // in a self loop or sideways edge. + if (u !== maxNode && !g.outEdges(u, maxNode).length && !g.node(u).dummy) { + g.addEdge(null, u, maxNode, { minLen: 0 }); + } + }); + } +} + +/* + * This function "relaxes" the constraints applied previously by the "apply" + * function. It expands any nodes that were collapsed and assigns the rank of + * the collapsed node to each of the expanded nodes. It also restores the + * original edges and removes any dummy edges pointing at the collapsed nodes. + * + * Note that the process of removing collapsed nodes also removes dummy edges + * automatically. + */ +exports.relax = function(g) { + // Save original edges + var originalEdges = []; + g.eachEdge(function(e, u, v, value) { + var originalEdge = value.originalEdge; + if (originalEdge) { + originalEdges.push(originalEdge); + } + }); + + // Expand collapsed nodes + g.eachNode(function(u, value) { + var originalNodes = value.originalNodes; + if (originalNodes) { + originalNodes.forEach(function(originalNode) { + originalNode.value.rank = value.rank; + g.addNode(originalNode.u, originalNode.value); + g.parent(originalNode.u, originalNode.parent); + }); + g.delNode(u); + } + }); + + // Restore original edges + originalEdges.forEach(function(edge) { + g.addEdge(edge.e, edge.u, edge.v, edge.value); + }); +}; + +},{}],22:[function(require,module,exports){ +/* jshint -W079 */ +var Set = require('cp-data').Set, +/* jshint +W079 */ + Digraph = require('graphlib').Digraph, + util = require('../util'); + +module.exports = feasibleTree; + +/* + * Given an acyclic graph with each node assigned a `rank` attribute, this + * function constructs and returns a spanning tree. This function may reduce + * the length of some edges from the initial rank assignment while maintaining + * the `minLen` specified by each edge. + * + * Prerequisites: + * + * * The input graph is acyclic + * * Each node in the input graph has an assigned `rank` attribute + * * Each edge in the input graph has an assigned `minLen` attribute + * + * Outputs: + * + * A feasible spanning tree for the input graph (i.e. a spanning tree that + * respects each graph edge's `minLen` attribute) represented as a Digraph with + * a `root` attribute on graph. + * + * Nodes have the same id and value as that in the input graph. + * + * Edges in the tree have arbitrarily assigned ids. The attributes for edges + * include `reversed`. `reversed` indicates that the edge is a + * back edge in the input graph. + */ +function feasibleTree(g) { + var remaining = new Set(g.nodes()), + tree = new Digraph(); + + if (remaining.size() === 1) { + var root = g.nodes()[0]; + tree.addNode(root, {}); + tree.graph({ root: root }); + return tree; + } + + function addTightEdges(v) { + var continueToScan = true; + g.predecessors(v).forEach(function(u) { + if (remaining.has(u) && !slack(g, u, v)) { + if (remaining.has(v)) { + tree.addNode(v, {}); + remaining.remove(v); + tree.graph({ root: v }); + } + + tree.addNode(u, {}); + tree.addEdge(null, u, v, { reversed: true }); + remaining.remove(u); + addTightEdges(u); + continueToScan = false; + } + }); + + g.successors(v).forEach(function(w) { + if (remaining.has(w) && !slack(g, v, w)) { + if (remaining.has(v)) { + tree.addNode(v, {}); + remaining.remove(v); + tree.graph({ root: v }); + } + + tree.addNode(w, {}); + tree.addEdge(null, v, w, {}); + remaining.remove(w); + addTightEdges(w); + continueToScan = false; + } + }); + return continueToScan; + } + + function createTightEdge() { + var minSlack = Number.MAX_VALUE; + remaining.keys().forEach(function(v) { + g.predecessors(v).forEach(function(u) { + if (!remaining.has(u)) { + var edgeSlack = slack(g, u, v); + if (Math.abs(edgeSlack) < Math.abs(minSlack)) { + minSlack = -edgeSlack; + } + } + }); + + g.successors(v).forEach(function(w) { + if (!remaining.has(w)) { + var edgeSlack = slack(g, v, w); + if (Math.abs(edgeSlack) < Math.abs(minSlack)) { + minSlack = edgeSlack; + } + } + }); + }); + + tree.eachNode(function(u) { g.node(u).rank -= minSlack; }); + } + + while (remaining.size()) { + var nodesToSearch = !tree.order() ? remaining.keys() : tree.nodes(); + for (var i = 0, il = nodesToSearch.length; + i < il && addTightEdges(nodesToSearch[i]); + ++i); + if (remaining.size()) { + createTightEdge(); + } + } + + return tree; +} + +function slack(g, u, v) { + var rankDiff = g.node(v).rank - g.node(u).rank; + var maxMinLen = util.max(g.outEdges(u, v) + .map(function(e) { return g.edge(e).minLen; })); + return rankDiff - maxMinLen; +} + +},{"../util":26,"cp-data":5,"graphlib":28}],23:[function(require,module,exports){ +var util = require('../util'), + topsort = require('graphlib').alg.topsort; + +module.exports = initRank; + +/* + * Assigns a `rank` attribute to each node in the input graph and ensures that + * this rank respects the `minLen` attribute of incident edges. + * + * Prerequisites: + * + * * The input graph must be acyclic + * * Each edge in the input graph must have an assigned 'minLen' attribute + */ +function initRank(g) { + var sorted = topsort(g); + + sorted.forEach(function(u) { + var inEdges = g.inEdges(u); + if (inEdges.length === 0) { + g.node(u).rank = 0; + return; + } + + var minLens = inEdges.map(function(e) { + return g.node(g.source(e)).rank + g.edge(e).minLen; + }); + g.node(u).rank = util.max(minLens); + }); +} + +},{"../util":26,"graphlib":28}],24:[function(require,module,exports){ +module.exports = { + slack: slack +}; + +/* + * A helper to calculate the slack between two nodes (`u` and `v`) given a + * `minLen` constraint. The slack represents how much the distance between `u` + * and `v` could shrink while maintaining the `minLen` constraint. If the value + * is negative then the constraint is currently violated. + * + This function requires that `u` and `v` are in `graph` and they both have a + `rank` attribute. + */ +function slack(graph, u, v, minLen) { + return Math.abs(graph.node(u).rank - graph.node(v).rank) - minLen; +} + +},{}],25:[function(require,module,exports){ +var util = require('../util'), + rankUtil = require('./rankUtil'); + +module.exports = simplex; + +function simplex(graph, spanningTree) { + // The network simplex algorithm repeatedly replaces edges of + // the spanning tree with negative cut values until no such + // edge exists. + initCutValues(graph, spanningTree); + while (true) { + var e = leaveEdge(spanningTree); + if (e === null) break; + var f = enterEdge(graph, spanningTree, e); + exchange(graph, spanningTree, e, f); + } +} + +/* + * Set the cut values of edges in the spanning tree by a depth-first + * postorder traversal. The cut value corresponds to the cost, in + * terms of a ranking's edge length sum, of lengthening an edge. + * Negative cut values typically indicate edges that would yield a + * smaller edge length sum if they were lengthened. + */ +function initCutValues(graph, spanningTree) { + computeLowLim(spanningTree); + + spanningTree.eachEdge(function(id, u, v, treeValue) { + treeValue.cutValue = 0; + }); + + // Propagate cut values up the tree. + function dfs(n) { + var children = spanningTree.successors(n); + for (var c in children) { + var child = children[c]; + dfs(child); + } + if (n !== spanningTree.graph().root) { + setCutValue(graph, spanningTree, n); + } + } + dfs(spanningTree.graph().root); +} + +/* + * Perform a DFS postorder traversal, labeling each node v with + * its traversal order 'lim(v)' and the minimum traversal number + * of any of its descendants 'low(v)'. This provides an efficient + * way to test whether u is an ancestor of v since + * low(u) <= lim(v) <= lim(u) if and only if u is an ancestor. + */ +function computeLowLim(tree) { + var postOrderNum = 0; + + function dfs(n) { + var children = tree.successors(n); + var low = postOrderNum; + for (var c in children) { + var child = children[c]; + dfs(child); + low = Math.min(low, tree.node(child).low); + } + tree.node(n).low = low; + tree.node(n).lim = postOrderNum++; + } + + dfs(tree.graph().root); +} + +/* + * To compute the cut value of the edge parent -> child, we consider + * it and any other graph edges to or from the child. + * parent + * | + * child + * / \ + * u v + */ +function setCutValue(graph, tree, child) { + var parentEdge = tree.inEdges(child)[0]; + + // List of child's children in the spanning tree. + var grandchildren = []; + var grandchildEdges = tree.outEdges(child); + for (var gce in grandchildEdges) { + grandchildren.push(tree.target(grandchildEdges[gce])); + } + + var cutValue = 0; + + // TODO: Replace unit increment/decrement with edge weights. + var E = 0; // Edges from child to grandchild's subtree. + var F = 0; // Edges to child from grandchild's subtree. + var G = 0; // Edges from child to nodes outside of child's subtree. + var H = 0; // Edges from nodes outside of child's subtree to child. + + // Consider all graph edges from child. + var outEdges = graph.outEdges(child); + var gc; + for (var oe in outEdges) { + var succ = graph.target(outEdges[oe]); + for (gc in grandchildren) { + if (inSubtree(tree, succ, grandchildren[gc])) { + E++; + } + } + if (!inSubtree(tree, succ, child)) { + G++; + } + } + + // Consider all graph edges to child. + var inEdges = graph.inEdges(child); + for (var ie in inEdges) { + var pred = graph.source(inEdges[ie]); + for (gc in grandchildren) { + if (inSubtree(tree, pred, grandchildren[gc])) { + F++; + } + } + if (!inSubtree(tree, pred, child)) { + H++; + } + } + + // Contributions depend on the alignment of the parent -> child edge + // and the child -> u or v edges. + var grandchildCutSum = 0; + for (gc in grandchildren) { + var cv = tree.edge(grandchildEdges[gc]).cutValue; + if (!tree.edge(grandchildEdges[gc]).reversed) { + grandchildCutSum += cv; + } else { + grandchildCutSum -= cv; + } + } + + if (!tree.edge(parentEdge).reversed) { + cutValue += grandchildCutSum - E + F - G + H; + } else { + cutValue -= grandchildCutSum - E + F - G + H; + } + + tree.edge(parentEdge).cutValue = cutValue; +} + +/* + * Return whether n is a node in the subtree with the given + * root. + */ +function inSubtree(tree, n, root) { + return (tree.node(root).low <= tree.node(n).lim && + tree.node(n).lim <= tree.node(root).lim); +} + +/* + * Return an edge from the tree with a negative cut value, or null if there + * is none. + */ +function leaveEdge(tree) { + var edges = tree.edges(); + for (var n in edges) { + var e = edges[n]; + var treeValue = tree.edge(e); + if (treeValue.cutValue < 0) { + return e; + } + } + return null; +} + +/* + * The edge e should be an edge in the tree, with an underlying edge + * in the graph, with a negative cut value. Of the two nodes incident + * on the edge, take the lower one. enterEdge returns an edge with + * minimum slack going from outside of that node's subtree to inside + * of that node's subtree. + */ +function enterEdge(graph, tree, e) { + var source = tree.source(e); + var target = tree.target(e); + var lower = tree.node(target).lim < tree.node(source).lim ? target : source; + + // Is the tree edge aligned with the graph edge? + var aligned = !tree.edge(e).reversed; + + var minSlack = Number.POSITIVE_INFINITY; + var minSlackEdge; + if (aligned) { + graph.eachEdge(function(id, u, v, value) { + if (id !== e && inSubtree(tree, u, lower) && !inSubtree(tree, v, lower)) { + var slack = rankUtil.slack(graph, u, v, value.minLen); + if (slack < minSlack) { + minSlack = slack; + minSlackEdge = id; + } + } + }); + } else { + graph.eachEdge(function(id, u, v, value) { + if (id !== e && !inSubtree(tree, u, lower) && inSubtree(tree, v, lower)) { + var slack = rankUtil.slack(graph, u, v, value.minLen); + if (slack < minSlack) { + minSlack = slack; + minSlackEdge = id; + } + } + }); + } + + if (minSlackEdge === undefined) { + var outside = []; + var inside = []; + graph.eachNode(function(id) { + if (!inSubtree(tree, id, lower)) { + outside.push(id); + } else { + inside.push(id); + } + }); + throw new Error('No edge found from outside of tree to inside'); + } + + return minSlackEdge; +} + +/* + * Replace edge e with edge f in the tree, recalculating the tree root, + * the nodes' low and lim properties and the edges' cut values. + */ +function exchange(graph, tree, e, f) { + tree.delEdge(e); + var source = graph.source(f); + var target = graph.target(f); + + // Redirect edges so that target is the root of its subtree. + function redirect(v) { + var edges = tree.inEdges(v); + for (var i in edges) { + var e = edges[i]; + var u = tree.source(e); + var value = tree.edge(e); + redirect(u); + tree.delEdge(e); + value.reversed = !value.reversed; + tree.addEdge(e, v, u, value); + } + } + + redirect(target); + + var root = source; + var edges = tree.inEdges(root); + while (edges.length > 0) { + root = tree.source(edges[0]); + edges = tree.inEdges(root); + } + + tree.graph().root = root; + + tree.addEdge(null, source, target, {cutValue: 0}); + + initCutValues(graph, tree); + + adjustRanks(graph, tree); +} + +/* + * Reset the ranks of all nodes based on the current spanning tree. + * The rank of the tree's root remains unchanged, while all other + * nodes are set to the sum of minimum length constraints along + * the path from the root. + */ +function adjustRanks(graph, tree) { + function dfs(p) { + var children = tree.successors(p); + children.forEach(function(c) { + var minLen = minimumLength(graph, p, c); + graph.node(c).rank = graph.node(p).rank + minLen; + dfs(c); + }); + } + + dfs(tree.graph().root); +} + +/* + * If u and v are connected by some edges in the graph, return the + * minimum length of those edges, as a positive number if v succeeds + * u and as a negative number if v precedes u. + */ +function minimumLength(graph, u, v) { + var outEdges = graph.outEdges(u, v); + if (outEdges.length > 0) { + return util.max(outEdges.map(function(e) { + return graph.edge(e).minLen; + })); + } + + var inEdges = graph.inEdges(u, v); + if (inEdges.length > 0) { + return -util.max(inEdges.map(function(e) { + return graph.edge(e).minLen; + })); + } +} + +},{"../util":26,"./rankUtil":24}],26:[function(require,module,exports){ +/* + * Returns the smallest value in the array. + */ +exports.min = function(values) { + return Math.min.apply(Math, values); +}; + +/* + * Returns the largest value in the array. + */ +exports.max = function(values) { + return Math.max.apply(Math, values); +}; + +/* + * Returns `true` only if `f(x)` is `true` for all `x` in `xs`. Otherwise + * returns `false`. This function will return immediately if it finds a + * case where `f(x)` does not hold. + */ +exports.all = function(xs, f) { + for (var i = 0; i < xs.length; ++i) { + if (!f(xs[i])) { + return false; + } + } + return true; +}; + +/* + * Accumulates the sum of elements in the given array using the `+` operator. + */ +exports.sum = function(values) { + return values.reduce(function(acc, x) { return acc + x; }, 0); +}; + +/* + * Returns an array of all values in the given object. + */ +exports.values = function(obj) { + return Object.keys(obj).map(function(k) { return obj[k]; }); +}; + +exports.shuffle = function(array) { + for (i = array.length - 1; i > 0; --i) { + var j = Math.floor(Math.random() * (i + 1)); + var aj = array[j]; + array[j] = array[i]; + array[i] = aj; + } +}; + +exports.propertyAccessor = function(self, config, field, setHook) { + return function(x) { + if (!arguments.length) return config[field]; + config[field] = x; + if (setHook) setHook(x); + return self; + }; +}; + +/* + * Given a layered, directed graph with `rank` and `order` node attributes, + * this function returns an array of ordered ranks. Each rank contains an array + * of the ids of the nodes in that rank in the order specified by the `order` + * attribute. + */ +exports.ordering = function(g) { + var ordering = []; + g.eachNode(function(u, value) { + var rank = ordering[value.rank] || (ordering[value.rank] = []); + rank[value.order] = u; + }); + return ordering; +}; + +/* + * A filter that can be used with `filterNodes` to get a graph that only + * includes nodes that do not contain others nodes. + */ +exports.filterNonSubgraphs = function(g) { + return function(u) { + return g.children(u).length === 0; + }; +}; + +/* + * Returns a new function that wraps `func` with a timer. The wrapper logs the + * time it takes to execute the function. + * + * The timer will be enabled provided `log.level >= 1`. + */ +function time(name, func) { + return function() { + var start = new Date().getTime(); + try { + return func.apply(null, arguments); + } finally { + log(1, name + ' time: ' + (new Date().getTime() - start) + 'ms'); + } + }; +} +time.enabled = false; + +exports.time = time; + +/* + * A global logger with the specification `log(level, message, ...)` that + * will log a message to the console if `log.level >= level`. + */ +function log(level) { + if (log.level >= level) { + console.log.apply(console, Array.prototype.slice.call(arguments, 1)); + } +} +log.level = 0; + +exports.log = log; + +},{}],27:[function(require,module,exports){ +module.exports = '0.4.5'; + +},{}],28:[function(require,module,exports){ +exports.Graph = require("./lib/Graph"); +exports.Digraph = require("./lib/Digraph"); +exports.CGraph = require("./lib/CGraph"); +exports.CDigraph = require("./lib/CDigraph"); +require("./lib/graph-converters"); + +exports.alg = { + isAcyclic: require("./lib/alg/isAcyclic"), + components: require("./lib/alg/components"), + dijkstra: require("./lib/alg/dijkstra"), + dijkstraAll: require("./lib/alg/dijkstraAll"), + findCycles: require("./lib/alg/findCycles"), + floydWarshall: require("./lib/alg/floydWarshall"), + postorder: require("./lib/alg/postorder"), + preorder: require("./lib/alg/preorder"), + prim: require("./lib/alg/prim"), + tarjan: require("./lib/alg/tarjan"), + topsort: require("./lib/alg/topsort") +}; + +exports.converter = { + json: require("./lib/converter/json.js") +}; + +var filter = require("./lib/filter"); +exports.filter = { + all: filter.all, + nodesFromList: filter.nodesFromList +}; + +exports.version = require("./lib/version"); + +},{"./lib/CDigraph":30,"./lib/CGraph":31,"./lib/Digraph":32,"./lib/Graph":33,"./lib/alg/components":34,"./lib/alg/dijkstra":35,"./lib/alg/dijkstraAll":36,"./lib/alg/findCycles":37,"./lib/alg/floydWarshall":38,"./lib/alg/isAcyclic":39,"./lib/alg/postorder":40,"./lib/alg/preorder":41,"./lib/alg/prim":42,"./lib/alg/tarjan":43,"./lib/alg/topsort":44,"./lib/converter/json.js":46,"./lib/filter":47,"./lib/graph-converters":48,"./lib/version":50}],29:[function(require,module,exports){ +/* jshint -W079 */ +var Set = require("cp-data").Set; +/* jshint +W079 */ + +module.exports = BaseGraph; + +function BaseGraph() { + // The value assigned to the graph itself. + this._value = undefined; + + // Map of node id -> { id, value } + this._nodes = {}; + + // Map of edge id -> { id, u, v, value } + this._edges = {}; + + // Used to generate a unique id in the graph + this._nextId = 0; +} + +// Number of nodes +BaseGraph.prototype.order = function() { + return Object.keys(this._nodes).length; +}; + +// Number of edges +BaseGraph.prototype.size = function() { + return Object.keys(this._edges).length; +}; + +// Accessor for graph level value +BaseGraph.prototype.graph = function(value) { + if (arguments.length === 0) { + return this._value; + } + this._value = value; +}; + +BaseGraph.prototype.hasNode = function(u) { + return u in this._nodes; +}; + +BaseGraph.prototype.node = function(u, value) { + var node = this._strictGetNode(u); + if (arguments.length === 1) { + return node.value; + } + node.value = value; +}; + +BaseGraph.prototype.nodes = function() { + var nodes = []; + this.eachNode(function(id) { nodes.push(id); }); + return nodes; +}; + +BaseGraph.prototype.eachNode = function(func) { + for (var k in this._nodes) { + var node = this._nodes[k]; + func(node.id, node.value); + } +}; + +BaseGraph.prototype.hasEdge = function(e) { + return e in this._edges; +}; + +BaseGraph.prototype.edge = function(e, value) { + var edge = this._strictGetEdge(e); + if (arguments.length === 1) { + return edge.value; + } + edge.value = value; +}; + +BaseGraph.prototype.edges = function() { + var es = []; + this.eachEdge(function(id) { es.push(id); }); + return es; +}; + +BaseGraph.prototype.eachEdge = function(func) { + for (var k in this._edges) { + var edge = this._edges[k]; + func(edge.id, edge.u, edge.v, edge.value); + } +}; + +BaseGraph.prototype.incidentNodes = function(e) { + var edge = this._strictGetEdge(e); + return [edge.u, edge.v]; +}; + +BaseGraph.prototype.addNode = function(u, value) { + if (u === undefined || u === null) { + do { + u = "_" + (++this._nextId); + } while (this.hasNode(u)); + } else if (this.hasNode(u)) { + throw new Error("Graph already has node '" + u + "'"); + } + this._nodes[u] = { id: u, value: value }; + return u; +}; + +BaseGraph.prototype.delNode = function(u) { + this._strictGetNode(u); + this.incidentEdges(u).forEach(function(e) { this.delEdge(e); }, this); + delete this._nodes[u]; +}; + +// inMap and outMap are opposite sides of an incidence map. For example, for +// Graph these would both come from the _incidentEdges map, while for Digraph +// they would come from _inEdges and _outEdges. +BaseGraph.prototype._addEdge = function(e, u, v, value, inMap, outMap) { + this._strictGetNode(u); + this._strictGetNode(v); + + if (e === undefined || e === null) { + do { + e = "_" + (++this._nextId); + } while (this.hasEdge(e)); + } + else if (this.hasEdge(e)) { + throw new Error("Graph already has edge '" + e + "'"); + } + + this._edges[e] = { id: e, u: u, v: v, value: value }; + addEdgeToMap(inMap[v], u, e); + addEdgeToMap(outMap[u], v, e); + + return e; +}; + +// See note for _addEdge regarding inMap and outMap. +BaseGraph.prototype._delEdge = function(e, inMap, outMap) { + var edge = this._strictGetEdge(e); + delEdgeFromMap(inMap[edge.v], edge.u, e); + delEdgeFromMap(outMap[edge.u], edge.v, e); + delete this._edges[e]; +}; + +BaseGraph.prototype.copy = function() { + var copy = new this.constructor(); + copy.graph(this.graph()); + this.eachNode(function(u, value) { copy.addNode(u, value); }); + this.eachEdge(function(e, u, v, value) { copy.addEdge(e, u, v, value); }); + copy._nextId = this._nextId; + return copy; +}; + +BaseGraph.prototype.filterNodes = function(filter) { + var copy = new this.constructor(); + copy.graph(this.graph()); + this.eachNode(function(u, value) { + if (filter(u)) { + copy.addNode(u, value); + } + }); + this.eachEdge(function(e, u, v, value) { + if (copy.hasNode(u) && copy.hasNode(v)) { + copy.addEdge(e, u, v, value); + } + }); + return copy; +}; + +BaseGraph.prototype._strictGetNode = function(u) { + var node = this._nodes[u]; + if (node === undefined) { + throw new Error("Node '" + u + "' is not in graph"); + } + return node; +}; + +BaseGraph.prototype._strictGetEdge = function(e) { + var edge = this._edges[e]; + if (edge === undefined) { + throw new Error("Edge '" + e + "' is not in graph"); + } + return edge; +}; + +function addEdgeToMap(map, v, e) { + (map[v] || (map[v] = new Set())).add(e); +} + +function delEdgeFromMap(map, v, e) { + var vEntry = map[v]; + vEntry.remove(e); + if (vEntry.size() === 0) { + delete map[v]; + } +} + + +},{"cp-data":5}],30:[function(require,module,exports){ +var Digraph = require("./Digraph"), + compoundify = require("./compoundify"); + +var CDigraph = compoundify(Digraph); + +module.exports = CDigraph; + +CDigraph.fromDigraph = function(src) { + var g = new CDigraph(), + graphValue = src.graph(); + + if (graphValue !== undefined) { + g.graph(graphValue); + } + + src.eachNode(function(u, value) { + if (value === undefined) { + g.addNode(u); + } else { + g.addNode(u, value); + } + }); + src.eachEdge(function(e, u, v, value) { + if (value === undefined) { + g.addEdge(null, u, v); + } else { + g.addEdge(null, u, v, value); + } + }); + return g; +}; + +CDigraph.prototype.toString = function() { + return "CDigraph " + JSON.stringify(this, null, 2); +}; + +},{"./Digraph":32,"./compoundify":45}],31:[function(require,module,exports){ +var Graph = require("./Graph"), + compoundify = require("./compoundify"); + +var CGraph = compoundify(Graph); + +module.exports = CGraph; + +CGraph.fromGraph = function(src) { + var g = new CGraph(), + graphValue = src.graph(); + + if (graphValue !== undefined) { + g.graph(graphValue); + } + + src.eachNode(function(u, value) { + if (value === undefined) { + g.addNode(u); + } else { + g.addNode(u, value); + } + }); + src.eachEdge(function(e, u, v, value) { + if (value === undefined) { + g.addEdge(null, u, v); + } else { + g.addEdge(null, u, v, value); + } + }); + return g; +}; + +CGraph.prototype.toString = function() { + return "CGraph " + JSON.stringify(this, null, 2); +}; + +},{"./Graph":33,"./compoundify":45}],32:[function(require,module,exports){ +/* + * This file is organized with in the following order: + * + * Exports + * Graph constructors + * Graph queries (e.g. nodes(), edges() + * Graph mutators + * Helper functions + */ + +var util = require("./util"), + BaseGraph = require("./BaseGraph"), +/* jshint -W079 */ + Set = require("cp-data").Set; +/* jshint +W079 */ + +module.exports = Digraph; + +/* + * Constructor to create a new directed multi-graph. + */ +function Digraph() { + BaseGraph.call(this); + + /*! Map of sourceId -> {targetId -> Set of edge ids} */ + this._inEdges = {}; + + /*! Map of targetId -> {sourceId -> Set of edge ids} */ + this._outEdges = {}; +} + +Digraph.prototype = new BaseGraph(); +Digraph.prototype.constructor = Digraph; + +/* + * Always returns `true`. + */ +Digraph.prototype.isDirected = function() { + return true; +}; + +/* + * Returns all successors of the node with the id `u`. That is, all nodes + * that have the node `u` as their source are returned. + * + * If no node `u` exists in the graph this function throws an Error. + * + * @param {String} u a node id + */ +Digraph.prototype.successors = function(u) { + this._strictGetNode(u); + return Object.keys(this._outEdges[u]) + .map(function(v) { return this._nodes[v].id; }, this); +}; + +/* + * Returns all predecessors of the node with the id `u`. That is, all nodes + * that have the node `u` as their target are returned. + * + * If no node `u` exists in the graph this function throws an Error. + * + * @param {String} u a node id + */ +Digraph.prototype.predecessors = function(u) { + this._strictGetNode(u); + return Object.keys(this._inEdges[u]) + .map(function(v) { return this._nodes[v].id; }, this); +}; + +/* + * Returns all nodes that are adjacent to the node with the id `u`. In other + * words, this function returns the set of all successors and predecessors of + * node `u`. + * + * @param {String} u a node id + */ +Digraph.prototype.neighbors = function(u) { + return Set.union([this.successors(u), this.predecessors(u)]).keys(); +}; + +/* + * Returns all nodes in the graph that have no in-edges. + */ +Digraph.prototype.sources = function() { + var self = this; + return this._filterNodes(function(u) { + // This could have better space characteristics if we had an inDegree function. + return self.inEdges(u).length === 0; + }); +}; + +/* + * Returns all nodes in the graph that have no out-edges. + */ +Digraph.prototype.sinks = function() { + var self = this; + return this._filterNodes(function(u) { + // This could have better space characteristics if we have an outDegree function. + return self.outEdges(u).length === 0; + }); +}; + +/* + * Returns the source node incident on the edge identified by the id `e`. If no + * such edge exists in the graph this function throws an Error. + * + * @param {String} e an edge id + */ +Digraph.prototype.source = function(e) { + return this._strictGetEdge(e).u; +}; + +/* + * Returns the target node incident on the edge identified by the id `e`. If no + * such edge exists in the graph this function throws an Error. + * + * @param {String} e an edge id + */ +Digraph.prototype.target = function(e) { + return this._strictGetEdge(e).v; +}; + +/* + * Returns an array of ids for all edges in the graph that have the node + * `target` as their target. If the node `target` is not in the graph this + * function raises an Error. + * + * Optionally a `source` node can also be specified. This causes the results + * to be filtered such that only edges from `source` to `target` are included. + * If the node `source` is specified but is not in the graph then this function + * raises an Error. + * + * @param {String} target the target node id + * @param {String} [source] an optional source node id + */ +Digraph.prototype.inEdges = function(target, source) { + this._strictGetNode(target); + var results = Set.union(util.values(this._inEdges[target])).keys(); + if (arguments.length > 1) { + this._strictGetNode(source); + results = results.filter(function(e) { return this.source(e) === source; }, this); + } + return results; +}; + +/* + * Returns an array of ids for all edges in the graph that have the node + * `source` as their source. If the node `source` is not in the graph this + * function raises an Error. + * + * Optionally a `target` node may also be specified. This causes the results + * to be filtered such that only edges from `source` to `target` are included. + * If the node `target` is specified but is not in the graph then this function + * raises an Error. + * + * @param {String} source the source node id + * @param {String} [target] an optional target node id + */ +Digraph.prototype.outEdges = function(source, target) { + this._strictGetNode(source); + var results = Set.union(util.values(this._outEdges[source])).keys(); + if (arguments.length > 1) { + this._strictGetNode(target); + results = results.filter(function(e) { return this.target(e) === target; }, this); + } + return results; +}; + +/* + * Returns an array of ids for all edges in the graph that have the `u` as + * their source or their target. If the node `u` is not in the graph this + * function raises an Error. + * + * Optionally a `v` node may also be specified. This causes the results to be + * filtered such that only edges between `u` and `v` - in either direction - + * are included. IF the node `v` is specified but not in the graph then this + * function raises an Error. + * + * @param {String} u the node for which to find incident edges + * @param {String} [v] option node that must be adjacent to `u` + */ +Digraph.prototype.incidentEdges = function(u, v) { + if (arguments.length > 1) { + return Set.union([this.outEdges(u, v), this.outEdges(v, u)]).keys(); + } else { + return Set.union([this.inEdges(u), this.outEdges(u)]).keys(); + } +}; + +/* + * Returns a string representation of this graph. + */ +Digraph.prototype.toString = function() { + return "Digraph " + JSON.stringify(this, null, 2); +}; + +/* + * Adds a new node with the id `u` to the graph and assigns it the value + * `value`. If a node with the id is already a part of the graph this function + * throws an Error. + * + * @param {String} u a node id + * @param {Object} [value] an optional value to attach to the node + */ +Digraph.prototype.addNode = function(u, value) { + u = BaseGraph.prototype.addNode.call(this, u, value); + this._inEdges[u] = {}; + this._outEdges[u] = {}; + return u; +}; + +/* + * Removes a node from the graph that has the id `u`. Any edges incident on the + * node are also removed. If the graph does not contain a node with the id this + * function will throw an Error. + * + * @param {String} u a node id + */ +Digraph.prototype.delNode = function(u) { + BaseGraph.prototype.delNode.call(this, u); + delete this._inEdges[u]; + delete this._outEdges[u]; +}; + +/* + * Adds a new edge to the graph with the id `e` from a node with the id `source` + * to a node with an id `target` and assigns it the value `value`. This graph + * allows more than one edge from `source` to `target` as long as the id `e` + * is unique in the set of edges. If `e` is `null` the graph will assign a + * unique identifier to the edge. + * + * If `source` or `target` are not present in the graph this function will + * throw an Error. + * + * @param {String} [e] an edge id + * @param {String} source the source node id + * @param {String} target the target node id + * @param {Object} [value] an optional value to attach to the edge + */ +Digraph.prototype.addEdge = function(e, source, target, value) { + return BaseGraph.prototype._addEdge.call(this, e, source, target, value, + this._inEdges, this._outEdges); +}; + +/* + * Removes an edge in the graph with the id `e`. If no edge in the graph has + * the id `e` this function will throw an Error. + * + * @param {String} e an edge id + */ +Digraph.prototype.delEdge = function(e) { + BaseGraph.prototype._delEdge.call(this, e, this._inEdges, this._outEdges); +}; + +// Unlike BaseGraph.filterNodes, this helper just returns nodes that +// satisfy a predicate. +Digraph.prototype._filterNodes = function(pred) { + var filtered = []; + this.eachNode(function(u) { + if (pred(u)) { + filtered.push(u); + } + }); + return filtered; +}; + + +},{"./BaseGraph":29,"./util":49,"cp-data":5}],33:[function(require,module,exports){ +/* + * This file is organized with in the following order: + * + * Exports + * Graph constructors + * Graph queries (e.g. nodes(), edges() + * Graph mutators + * Helper functions + */ + +var util = require("./util"), + BaseGraph = require("./BaseGraph"), +/* jshint -W079 */ + Set = require("cp-data").Set; +/* jshint +W079 */ + +module.exports = Graph; + +/* + * Constructor to create a new undirected multi-graph. + */ +function Graph() { + BaseGraph.call(this); + + /*! Map of nodeId -> { otherNodeId -> Set of edge ids } */ + this._incidentEdges = {}; +} + +Graph.prototype = new BaseGraph(); +Graph.prototype.constructor = Graph; + +/* + * Always returns `false`. + */ +Graph.prototype.isDirected = function() { + return false; +}; + +/* + * Returns all nodes that are adjacent to the node with the id `u`. + * + * @param {String} u a node id + */ +Graph.prototype.neighbors = function(u) { + this._strictGetNode(u); + return Object.keys(this._incidentEdges[u]) + .map(function(v) { return this._nodes[v].id; }, this); +}; + +/* + * Returns an array of ids for all edges in the graph that are incident on `u`. + * If the node `u` is not in the graph this function raises an Error. + * + * Optionally a `v` node may also be specified. This causes the results to be + * filtered such that only edges between `u` and `v` are included. If the node + * `v` is specified but not in the graph then this function raises an Error. + * + * @param {String} u the node for which to find incident edges + * @param {String} [v] option node that must be adjacent to `u` + */ +Graph.prototype.incidentEdges = function(u, v) { + this._strictGetNode(u); + if (arguments.length > 1) { + this._strictGetNode(v); + return v in this._incidentEdges[u] ? this._incidentEdges[u][v].keys() : []; + } else { + return Set.union(util.values(this._incidentEdges[u])).keys(); + } +}; + +/* + * Returns a string representation of this graph. + */ +Graph.prototype.toString = function() { + return "Graph " + JSON.stringify(this, null, 2); +}; + +/* + * Adds a new node with the id `u` to the graph and assigns it the value + * `value`. If a node with the id is already a part of the graph this function + * throws an Error. + * + * @param {String} u a node id + * @param {Object} [value] an optional value to attach to the node + */ +Graph.prototype.addNode = function(u, value) { + u = BaseGraph.prototype.addNode.call(this, u, value); + this._incidentEdges[u] = {}; + return u; +}; + +/* + * Removes a node from the graph that has the id `u`. Any edges incident on the + * node are also removed. If the graph does not contain a node with the id this + * function will throw an Error. + * + * @param {String} u a node id + */ +Graph.prototype.delNode = function(u) { + BaseGraph.prototype.delNode.call(this, u); + delete this._incidentEdges[u]; +}; + +/* + * Adds a new edge to the graph with the id `e` between a node with the id `u` + * and a node with an id `v` and assigns it the value `value`. This graph + * allows more than one edge between `u` and `v` as long as the id `e` + * is unique in the set of edges. If `e` is `null` the graph will assign a + * unique identifier to the edge. + * + * If `u` or `v` are not present in the graph this function will throw an + * Error. + * + * @param {String} [e] an edge id + * @param {String} u the node id of one of the adjacent nodes + * @param {String} v the node id of the other adjacent node + * @param {Object} [value] an optional value to attach to the edge + */ +Graph.prototype.addEdge = function(e, u, v, value) { + return BaseGraph.prototype._addEdge.call(this, e, u, v, value, + this._incidentEdges, this._incidentEdges); +}; + +/* + * Removes an edge in the graph with the id `e`. If no edge in the graph has + * the id `e` this function will throw an Error. + * + * @param {String} e an edge id + */ +Graph.prototype.delEdge = function(e) { + BaseGraph.prototype._delEdge.call(this, e, this._incidentEdges, this._incidentEdges); +}; + + +},{"./BaseGraph":29,"./util":49,"cp-data":5}],34:[function(require,module,exports){ +/* jshint -W079 */ +var Set = require("cp-data").Set; +/* jshint +W079 */ + +module.exports = components; + +/** + * Finds all [connected components][] in a graph and returns an array of these + * components. Each component is itself an array that contains the ids of nodes + * in the component. + * + * This function only works with undirected Graphs. + * + * [connected components]: http://en.wikipedia.org/wiki/Connected_component_(graph_theory) + * + * @param {Graph} g the graph to search for components + */ +function components(g) { + var results = []; + var visited = new Set(); + + function dfs(v, component) { + if (!visited.has(v)) { + visited.add(v); + component.push(v); + g.neighbors(v).forEach(function(w) { + dfs(w, component); + }); + } + } + + g.nodes().forEach(function(v) { + var component = []; + dfs(v, component); + if (component.length > 0) { + results.push(component); + } + }); + + return results; +} + +},{"cp-data":5}],35:[function(require,module,exports){ +var PriorityQueue = require("cp-data").PriorityQueue; + +module.exports = dijkstra; + +/** + * This function is an implementation of [Dijkstra's algorithm][] which finds + * the shortest path from **source** to all other nodes in **g**. This + * function returns a map of `u -> { distance, predecessor }`. The distance + * property holds the sum of the weights from **source** to `u` along the + * shortest path or `Number.POSITIVE_INFINITY` if there is no path from + * **source**. The predecessor property can be used to walk the individual + * elements of the path from **source** to **u** in reverse order. + * + * This function takes an optional `weightFunc(e)` which returns the + * weight of the edge `e`. If no weightFunc is supplied then each edge is + * assumed to have a weight of 1. This function throws an Error if any of + * the traversed edges have a negative edge weight. + * + * This function takes an optional `incidentFunc(u)` which returns the ids of + * all edges incident to the node `u` for the purposes of shortest path + * traversal. By default this function uses the `g.outEdges` for Digraphs and + * `g.incidentEdges` for Graphs. + * + * This function takes `O((|E| + |V|) * log |V|)` time. + * + * [Dijkstra's algorithm]: http://en.wikipedia.org/wiki/Dijkstra%27s_algorithm + * + * @param {Graph} g the graph to search for shortest paths from **source** + * @param {Object} source the source from which to start the search + * @param {Function} [weightFunc] optional weight function + * @param {Function} [incidentFunc] optional incident function + */ +function dijkstra(g, source, weightFunc, incidentFunc) { + var results = {}, + pq = new PriorityQueue(); + + function updateNeighbors(e) { + var incidentNodes = g.incidentNodes(e), + v = incidentNodes[0] !== u ? incidentNodes[0] : incidentNodes[1], + vEntry = results[v], + weight = weightFunc(e), + distance = uEntry.distance + weight; + + if (weight < 0) { + throw new Error("dijkstra does not allow negative edge weights. Bad edge: " + e + " Weight: " + weight); + } + + if (distance < vEntry.distance) { + vEntry.distance = distance; + vEntry.predecessor = u; + pq.decrease(v, distance); + } + } + + weightFunc = weightFunc || function() { return 1; }; + incidentFunc = incidentFunc || (g.isDirected() + ? function(u) { return g.outEdges(u); } + : function(u) { return g.incidentEdges(u); }); + + g.eachNode(function(u) { + var distance = u === source ? 0 : Number.POSITIVE_INFINITY; + results[u] = { distance: distance }; + pq.add(u, distance); + }); + + var u, uEntry; + while (pq.size() > 0) { + u = pq.removeMin(); + uEntry = results[u]; + if (uEntry.distance === Number.POSITIVE_INFINITY) { + break; + } + + incidentFunc(u).forEach(updateNeighbors); + } + + return results; +} + +},{"cp-data":5}],36:[function(require,module,exports){ +var dijkstra = require("./dijkstra"); + +module.exports = dijkstraAll; + +/** + * This function finds the shortest path from each node to every other + * reachable node in the graph. It is similar to [alg.dijkstra][], but + * instead of returning a single-source array, it returns a mapping of + * of `source -> alg.dijksta(g, source, weightFunc, incidentFunc)`. + * + * This function takes an optional `weightFunc(e)` which returns the + * weight of the edge `e`. If no weightFunc is supplied then each edge is + * assumed to have a weight of 1. This function throws an Error if any of + * the traversed edges have a negative edge weight. + * + * This function takes an optional `incidentFunc(u)` which returns the ids of + * all edges incident to the node `u` for the purposes of shortest path + * traversal. By default this function uses the `outEdges` function on the + * supplied graph. + * + * This function takes `O(|V| * (|E| + |V|) * log |V|)` time. + * + * [alg.dijkstra]: dijkstra.js.html#dijkstra + * + * @param {Graph} g the graph to search for shortest paths from **source** + * @param {Function} [weightFunc] optional weight function + * @param {Function} [incidentFunc] optional incident function + */ +function dijkstraAll(g, weightFunc, incidentFunc) { + var results = {}; + g.eachNode(function(u) { + results[u] = dijkstra(g, u, weightFunc, incidentFunc); + }); + return results; +} + +},{"./dijkstra":35}],37:[function(require,module,exports){ +var tarjan = require("./tarjan"); + +module.exports = findCycles; + +/* + * Given a Digraph **g** this function returns all nodes that are part of a + * cycle. Since there may be more than one cycle in a graph this function + * returns an array of these cycles, where each cycle is itself represented + * by an array of ids for each node involved in that cycle. + * + * [alg.isAcyclic][] is more efficient if you only need to determine whether + * a graph has a cycle or not. + * + * [alg.isAcyclic]: isAcyclic.js.html#isAcyclic + * + * @param {Digraph} g the graph to search for cycles. + */ +function findCycles(g) { + return tarjan(g).filter(function(cmpt) { return cmpt.length > 1; }); +} + +},{"./tarjan":43}],38:[function(require,module,exports){ +module.exports = floydWarshall; + +/** + * This function is an implementation of the [Floyd-Warshall algorithm][], + * which finds the shortest path from each node to every other reachable node + * in the graph. It is similar to [alg.dijkstraAll][], but it handles negative + * edge weights and is more efficient for some types of graphs. This function + * returns a map of `source -> { target -> { distance, predecessor }`. The + * distance property holds the sum of the weights from `source` to `target` + * along the shortest path of `Number.POSITIVE_INFINITY` if there is no path + * from `source`. The predecessor property can be used to walk the individual + * elements of the path from `source` to `target` in reverse order. + * + * This function takes an optional `weightFunc(e)` which returns the + * weight of the edge `e`. If no weightFunc is supplied then each edge is + * assumed to have a weight of 1. + * + * This function takes an optional `incidentFunc(u)` which returns the ids of + * all edges incident to the node `u` for the purposes of shortest path + * traversal. By default this function uses the `outEdges` function on the + * supplied graph. + * + * This algorithm takes O(|V|^3) time. + * + * [Floyd-Warshall algorithm]: https://en.wikipedia.org/wiki/Floyd-Warshall_algorithm + * [alg.dijkstraAll]: dijkstraAll.js.html#dijkstraAll + * + * @param {Graph} g the graph to search for shortest paths from **source** + * @param {Function} [weightFunc] optional weight function + * @param {Function} [incidentFunc] optional incident function + */ +function floydWarshall(g, weightFunc, incidentFunc) { + var results = {}, + nodes = g.nodes(); + + weightFunc = weightFunc || function() { return 1; }; + incidentFunc = incidentFunc || (g.isDirected() + ? function(u) { return g.outEdges(u); } + : function(u) { return g.incidentEdges(u); }); + + nodes.forEach(function(u) { + results[u] = {}; + results[u][u] = { distance: 0 }; + nodes.forEach(function(v) { + if (u !== v) { + results[u][v] = { distance: Number.POSITIVE_INFINITY }; + } + }); + incidentFunc(u).forEach(function(e) { + var incidentNodes = g.incidentNodes(e), + v = incidentNodes[0] !== u ? incidentNodes[0] : incidentNodes[1], + d = weightFunc(e); + if (d < results[u][v].distance) { + results[u][v] = { distance: d, predecessor: u }; + } + }); + }); + + nodes.forEach(function(k) { + var rowK = results[k]; + nodes.forEach(function(i) { + var rowI = results[i]; + nodes.forEach(function(j) { + var ik = rowI[k]; + var kj = rowK[j]; + var ij = rowI[j]; + var altDistance = ik.distance + kj.distance; + if (altDistance < ij.distance) { + ij.distance = altDistance; + ij.predecessor = kj.predecessor; + } + }); + }); + }); + + return results; +} + +},{}],39:[function(require,module,exports){ +var topsort = require("./topsort"); + +module.exports = isAcyclic; + +/* + * Given a Digraph **g** this function returns `true` if the graph has no + * cycles and returns `false` if it does. This algorithm returns as soon as it + * detects the first cycle. + * + * Use [alg.findCycles][] if you need the actual list of cycles in a graph. + * + * [alg.findCycles]: findCycles.js.html#findCycles + * + * @param {Digraph} g the graph to test for cycles + */ +function isAcyclic(g) { + try { + topsort(g); + } catch (e) { + if (e instanceof topsort.CycleException) return false; + throw e; + } + return true; +} + +},{"./topsort":44}],40:[function(require,module,exports){ +/* jshint -W079 */ +var Set = require("cp-data").Set; +/* jshint +W079 */ + +module.exports = postorder; + +// Postorder traversal of g, calling f for each visited node. Assumes the graph +// is a tree. +function postorder(g, root, f) { + var visited = new Set(); + if (g.isDirected()) { + throw new Error("This function only works for undirected graphs"); + } + function dfs(u, prev) { + if (visited.has(u)) { + throw new Error("The input graph is not a tree: " + g); + } + visited.add(u); + g.neighbors(u).forEach(function(v) { + if (v !== prev) dfs(v, u); + }); + f(u); + } + dfs(root); +} + +},{"cp-data":5}],41:[function(require,module,exports){ +/* jshint -W079 */ +var Set = require("cp-data").Set; +/* jshint +W079 */ + +module.exports = preorder; + +// Preorder traversal of g, calling f for each visited node. Assumes the graph +// is a tree. +function preorder(g, root, f) { + var visited = new Set(); + if (g.isDirected()) { + throw new Error("This function only works for undirected graphs"); + } + function dfs(u, prev) { + if (visited.has(u)) { + throw new Error("The input graph is not a tree: " + g); + } + visited.add(u); + f(u); + g.neighbors(u).forEach(function(v) { + if (v !== prev) dfs(v, u); + }); + } + dfs(root); +} + +},{"cp-data":5}],42:[function(require,module,exports){ +var Graph = require("../Graph"), + PriorityQueue = require("cp-data").PriorityQueue; + +module.exports = prim; + +/** + * [Prim's algorithm][] takes a connected undirected graph and generates a + * [minimum spanning tree][]. This function returns the minimum spanning + * tree as an undirected graph. This algorithm is derived from the description + * in "Introduction to Algorithms", Third Edition, Cormen, et al., Pg 634. + * + * This function takes a `weightFunc(e)` which returns the weight of the edge + * `e`. It throws an Error if the graph is not connected. + * + * This function takes `O(|E| log |V|)` time. + * + * [Prim's algorithm]: https://en.wikipedia.org/wiki/Prim's_algorithm + * [minimum spanning tree]: https://en.wikipedia.org/wiki/Minimum_spanning_tree + * + * @param {Graph} g the graph used to generate the minimum spanning tree + * @param {Function} weightFunc the weight function to use + */ +function prim(g, weightFunc) { + var result = new Graph(), + parents = {}, + pq = new PriorityQueue(), + u; + + function updateNeighbors(e) { + var incidentNodes = g.incidentNodes(e), + v = incidentNodes[0] !== u ? incidentNodes[0] : incidentNodes[1], + pri = pq.priority(v); + if (pri !== undefined) { + var edgeWeight = weightFunc(e); + if (edgeWeight < pri) { + parents[v] = u; + pq.decrease(v, edgeWeight); + } + } + } + + if (g.order() === 0) { + return result; + } + + g.eachNode(function(u) { + pq.add(u, Number.POSITIVE_INFINITY); + result.addNode(u); + }); + + // Start from an arbitrary node + pq.decrease(g.nodes()[0], 0); + + var init = false; + while (pq.size() > 0) { + u = pq.removeMin(); + if (u in parents) { + result.addEdge(null, u, parents[u]); + } else if (init) { + throw new Error("Input graph is not connected: " + g); + } else { + init = true; + } + + g.incidentEdges(u).forEach(updateNeighbors); + } + + return result; +} + +},{"../Graph":33,"cp-data":5}],43:[function(require,module,exports){ +module.exports = tarjan; + +/** + * This function is an implementation of [Tarjan's algorithm][] which finds + * all [strongly connected components][] in the directed graph **g**. Each + * strongly connected component is composed of nodes that can reach all other + * nodes in the component via directed edges. A strongly connected component + * can consist of a single node if that node cannot both reach and be reached + * by any other specific node in the graph. Components of more than one node + * are guaranteed to have at least one cycle. + * + * This function returns an array of components. Each component is itself an + * array that contains the ids of all nodes in the component. + * + * [Tarjan's algorithm]: http://en.wikipedia.org/wiki/Tarjan's_strongly_connected_components_algorithm + * [strongly connected components]: http://en.wikipedia.org/wiki/Strongly_connected_component + * + * @param {Digraph} g the graph to search for strongly connected components + */ +function tarjan(g) { + if (!g.isDirected()) { + throw new Error("tarjan can only be applied to a directed graph. Bad input: " + g); + } + + var index = 0, + stack = [], + visited = {}, // node id -> { onStack, lowlink, index } + results = []; + + function dfs(u) { + var entry = visited[u] = { + onStack: true, + lowlink: index, + index: index++ + }; + stack.push(u); + + g.successors(u).forEach(function(v) { + if (!(v in visited)) { + dfs(v); + entry.lowlink = Math.min(entry.lowlink, visited[v].lowlink); + } else if (visited[v].onStack) { + entry.lowlink = Math.min(entry.lowlink, visited[v].index); + } + }); + + if (entry.lowlink === entry.index) { + var cmpt = [], + v; + do { + v = stack.pop(); + visited[v].onStack = false; + cmpt.push(v); + } while (u !== v); + results.push(cmpt); + } + } + + g.nodes().forEach(function(u) { + if (!(u in visited)) { + dfs(u); + } + }); + + return results; +} + +},{}],44:[function(require,module,exports){ +module.exports = topsort; +topsort.CycleException = CycleException; + +/* + * Given a graph **g**, this function returns an ordered list of nodes such + * that for each edge `u -> v`, `u` appears before `v` in the list. If the + * graph has a cycle it is impossible to generate such a list and + * **CycleException** is thrown. + * + * See [topological sorting](https://en.wikipedia.org/wiki/Topological_sorting) + * for more details about how this algorithm works. + * + * @param {Digraph} g the graph to sort + */ +function topsort(g) { + if (!g.isDirected()) { + throw new Error("topsort can only be applied to a directed graph. Bad input: " + g); + } + + var visited = {}; + var stack = {}; + var results = []; + + function visit(node) { + if (node in stack) { + throw new CycleException(); + } + + if (!(node in visited)) { + stack[node] = true; + visited[node] = true; + g.predecessors(node).forEach(function(pred) { + visit(pred); + }); + delete stack[node]; + results.push(node); + } + } + + var sinks = g.sinks(); + if (g.order() !== 0 && sinks.length === 0) { + throw new CycleException(); + } + + g.sinks().forEach(function(sink) { + visit(sink); + }); + + return results; +} + +function CycleException() {} + +CycleException.prototype.toString = function() { + return "Graph has at least one cycle"; +}; + +},{}],45:[function(require,module,exports){ +// This file provides a helper function that mixes-in Dot behavior to an +// existing graph prototype. + +/* jshint -W079 */ +var Set = require("cp-data").Set; +/* jshint +W079 */ + +module.exports = compoundify; + +// Extends the given SuperConstructor with the ability for nodes to contain +// other nodes. A special node id `null` is used to indicate the root graph. +function compoundify(SuperConstructor) { + function Constructor() { + SuperConstructor.call(this); + + // Map of object id -> parent id (or null for root graph) + this._parents = {}; + + // Map of id (or null) -> children set + this._children = {}; + this._children[null] = new Set(); + } + + Constructor.prototype = new SuperConstructor(); + Constructor.prototype.constructor = Constructor; + + Constructor.prototype.parent = function(u, parent) { + this._strictGetNode(u); + + if (arguments.length < 2) { + return this._parents[u]; + } + + if (u === parent) { + throw new Error("Cannot make " + u + " a parent of itself"); + } + if (parent !== null) { + this._strictGetNode(parent); + } + + this._children[this._parents[u]].remove(u); + this._parents[u] = parent; + this._children[parent].add(u); + }; + + Constructor.prototype.children = function(u) { + if (u !== null) { + this._strictGetNode(u); + } + return this._children[u].keys(); + }; + + Constructor.prototype.addNode = function(u, value) { + u = SuperConstructor.prototype.addNode.call(this, u, value); + this._parents[u] = null; + this._children[u] = new Set(); + this._children[null].add(u); + return u; + }; + + Constructor.prototype.delNode = function(u) { + // Promote all children to the parent of the subgraph + var parent = this.parent(u); + this._children[u].keys().forEach(function(child) { + this.parent(child, parent); + }, this); + + this._children[parent].remove(u); + delete this._parents[u]; + delete this._children[u]; + + return SuperConstructor.prototype.delNode.call(this, u); + }; + + Constructor.prototype.copy = function() { + var copy = SuperConstructor.prototype.copy.call(this); + this.nodes().forEach(function(u) { + copy.parent(u, this.parent(u)); + }, this); + return copy; + }; + + Constructor.prototype.filterNodes = function(filter) { + var self = this, + copy = SuperConstructor.prototype.filterNodes.call(this, filter); + + var parents = {}; + function findParent(u) { + var parent = self.parent(u); + if (parent === null || copy.hasNode(parent)) { + parents[u] = parent; + return parent; + } else if (parent in parents) { + return parents[parent]; + } else { + return findParent(parent); + } + } + + copy.eachNode(function(u) { copy.parent(u, findParent(u)); }); + + return copy; + }; + + return Constructor; +} + +},{"cp-data":5}],46:[function(require,module,exports){ +var Graph = require("../Graph"), + Digraph = require("../Digraph"), + CGraph = require("../CGraph"), + CDigraph = require("../CDigraph"); + +exports.decode = function(nodes, edges, Ctor) { + Ctor = Ctor || Digraph; + + if (typeOf(nodes) !== "Array") { + throw new Error("nodes is not an Array"); + } + + if (typeOf(edges) !== "Array") { + throw new Error("edges is not an Array"); + } + + if (typeof Ctor === "string") { + switch(Ctor) { + case "graph": Ctor = Graph; break; + case "digraph": Ctor = Digraph; break; + case "cgraph": Ctor = CGraph; break; + case "cdigraph": Ctor = CDigraph; break; + default: throw new Error("Unrecognized graph type: " + Ctor); + } + } + + var graph = new Ctor(); + + nodes.forEach(function(u) { + graph.addNode(u.id, u.value); + }); + + // If the graph is compound, set up children... + if (graph.parent) { + nodes.forEach(function(u) { + if (u.children) { + u.children.forEach(function(v) { + graph.parent(v, u.id); + }); + } + }); + } + + edges.forEach(function(e) { + graph.addEdge(e.id, e.u, e.v, e.value); + }); + + return graph; +}; + +exports.encode = function(graph) { + var nodes = []; + var edges = []; + + graph.eachNode(function(u, value) { + var node = {id: u, value: value}; + if (graph.children) { + var children = graph.children(u); + if (children.length) { + node.children = children; + } + } + nodes.push(node); + }); + + graph.eachEdge(function(e, u, v, value) { + edges.push({id: e, u: u, v: v, value: value}); + }); + + var type; + if (graph instanceof CDigraph) { + type = "cdigraph"; + } else if (graph instanceof CGraph) { + type = "cgraph"; + } else if (graph instanceof Digraph) { + type = "digraph"; + } else if (graph instanceof Graph) { + type = "graph"; + } else { + throw new Error("Couldn't determine type of graph: " + graph); + } + + return { nodes: nodes, edges: edges, type: type }; +}; + +function typeOf(obj) { + return Object.prototype.toString.call(obj).slice(8, -1); +} + +},{"../CDigraph":30,"../CGraph":31,"../Digraph":32,"../Graph":33}],47:[function(require,module,exports){ +/* jshint -W079 */ +var Set = require("cp-data").Set; +/* jshint +W079 */ + +exports.all = function() { + return function() { return true; }; +}; + +exports.nodesFromList = function(nodes) { + var set = new Set(nodes); + return function(u) { + return set.has(u); + }; +}; + +},{"cp-data":5}],48:[function(require,module,exports){ +var Graph = require("./Graph"), + Digraph = require("./Digraph"); + +// Side-effect based changes are lousy, but node doesn't seem to resolve the +// requires cycle. + +/** + * Returns a new directed graph using the nodes and edges from this graph. The + * new graph will have the same nodes, but will have twice the number of edges: + * each edge is split into two edges with opposite directions. Edge ids, + * consequently, are not preserved by this transformation. + */ +Graph.prototype.toDigraph = +Graph.prototype.asDirected = function() { + var g = new Digraph(); + this.eachNode(function(u, value) { g.addNode(u, value); }); + this.eachEdge(function(e, u, v, value) { + g.addEdge(null, u, v, value); + g.addEdge(null, v, u, value); + }); + return g; +}; + +/** + * Returns a new undirected graph using the nodes and edges from this graph. + * The new graph will have the same nodes, but the edges will be made + * undirected. Edge ids are preserved in this transformation. + */ +Digraph.prototype.toGraph = +Digraph.prototype.asUndirected = function() { + var g = new Graph(); + this.eachNode(function(u, value) { g.addNode(u, value); }); + this.eachEdge(function(e, u, v, value) { + g.addEdge(e, u, v, value); + }); + return g; +}; + +},{"./Digraph":32,"./Graph":33}],49:[function(require,module,exports){ +// Returns an array of all values for properties of **o**. +exports.values = function(o) { + var ks = Object.keys(o), + len = ks.length, + result = new Array(len), + i; + for (i = 0; i < len; ++i) { + result[i] = o[ks[i]]; + } + return result; +}; + +},{}],50:[function(require,module,exports){ +module.exports = '0.7.4'; + +},{}]},{},[1]) +; \ No newline at end of file diff --git a/devtools/client/shared/vendor/fluent-react.js b/devtools/client/shared/vendor/fluent-react.js new file mode 100644 index 0000000000..472c1247a4 --- /dev/null +++ b/devtools/client/shared/vendor/fluent-react.js @@ -0,0 +1,686 @@ +/* Copyright 2019 Mozilla Foundation and others + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +'use strict'; + +/* fluent-react@0.10.0 */ + +Object.defineProperty(exports, '__esModule', { value: true }); + +function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } + +const react = require("resource://devtools/client/shared/vendor/react.js"); +const PropTypes = _interopDefault(require("resource://devtools/client/shared/vendor/react-prop-types.js")); + +/* + * Synchronously map an identifier or an array of identifiers to the best + * `FluentBundle` instance(s). + * + * @param {Iterable} iterable + * @param {string|Array} ids + * @returns {FluentBundle|Array} + */ +function mapBundleSync(iterable, ids) { + if (!Array.isArray(ids)) { + return getBundleForId(iterable, ids); + } + + return ids.map( + id => getBundleForId(iterable, id) + ); +} + +/* + * Find the best `FluentBundle` with the translation for `id`. + */ +function getBundleForId(iterable, id) { + for (const bundle of iterable) { + if (bundle.hasMessage(id)) { + return bundle; + } + } + + return null; +} + +/* + * Asynchronously map an identifier or an array of identifiers to the best + * `FluentBundle` instance(s). + * + * @param {AsyncIterable} iterable + * @param {string|Array} ids + * @returns {Promise>} + */ + +/* + * @module fluent-sequence + * @overview Manage ordered sequences of FluentBundles. + */ + +/* + * Base CachedIterable class. + */ +class CachedIterable extends Array { + /** + * Create a `CachedIterable` instance from an iterable or, if another + * instance of `CachedIterable` is passed, return it without any + * modifications. + * + * @param {Iterable} iterable + * @returns {CachedIterable} + */ + static from(iterable) { + if (iterable instanceof this) { + return iterable; + } + + return new this(iterable); + } +} + +/* + * CachedSyncIterable caches the elements yielded by an iterable. + * + * It can be used to iterate over an iterable many times without depleting the + * iterable. + */ +class CachedSyncIterable extends CachedIterable { + /** + * Create an `CachedSyncIterable` instance. + * + * @param {Iterable} iterable + * @returns {CachedSyncIterable} + */ + constructor(iterable) { + super(); + + if (Symbol.iterator in Object(iterable)) { + this.iterator = iterable[Symbol.iterator](); + } else { + throw new TypeError("Argument must implement the iteration protocol."); + } + } + + [Symbol.iterator]() { + const cached = this; + let cur = 0; + + return { + next() { + if (cached.length <= cur) { + cached.push(cached.iterator.next()); + } + return cached[cur++]; + } + }; + } + + /** + * This method allows user to consume the next element from the iterator + * into the cache. + * + * @param {number} count - number of elements to consume + */ + touchNext(count = 1) { + let idx = 0; + while (idx++ < count) { + const last = this[this.length - 1]; + if (last && last.done) { + break; + } + this.push(this.iterator.next()); + } + // Return the last cached {value, done} object to allow the calling + // code to decide if it needs to call touchNext again. + return this[this.length - 1]; + } +} + +/* + * `ReactLocalization` handles translation formatting and fallback. + * + * The current negotiated fallback chain of languages is stored in the + * `ReactLocalization` instance in form of an iterable of `FluentBundle` + * instances. This iterable is used to find the best existing translation for + * a given identifier. + * + * `Localized` components must subscribe to the changes of the + * `ReactLocalization`'s fallback chain. When the fallback chain changes (the + * `bundles` iterable is set anew), all subscribed compontent must relocalize. + * + * The `ReactLocalization` class instances are exposed to `Localized` elements + * via the `LocalizationProvider` component. + */ +class ReactLocalization { + constructor(bundles) { + this.bundles = CachedSyncIterable.from(bundles); + this.subs = new Set(); + } + + /* + * Subscribe a `Localized` component to changes of `bundles`. + */ + subscribe(comp) { + this.subs.add(comp); + } + + /* + * Unsubscribe a `Localized` component from `bundles` changes. + */ + unsubscribe(comp) { + this.subs.delete(comp); + } + + /* + * Set a new `bundles` iterable and trigger the retranslation. + */ + setBundles(bundles) { + this.bundles = CachedSyncIterable.from(bundles); + + // Update all subscribed Localized components. + this.subs.forEach(comp => comp.relocalize()); + } + + getBundle(id) { + return mapBundleSync(this.bundles, id); + } + + /* + * Find a translation by `id` and format it to a string using `args`. + */ + getString(id, args, fallback) { + const bundle = this.getBundle(id); + if (bundle) { + const msg = bundle.getMessage(id); + if (msg && msg.value) { + let errors = []; + let value = bundle.formatPattern(msg.value, args, errors); + for (let error of errors) { + this.reportError(error); + } + return value; + } + } + + return fallback || id; + } + + // XXX Control this via a prop passed to the LocalizationProvider. + // See https://github.com/projectfluent/fluent.js/issues/411. + reportError(error) { + /* global console */ + // eslint-disable-next-line no-console + console.warn(`[@fluent/react] ${error.name}: ${error.message}`); + } +} + +function isReactLocalization(props, propName) { + const prop = props[propName]; + + if (prop instanceof ReactLocalization) { + return null; + } + + return new Error( + `The ${propName} context field must be an instance of ReactLocalization.` + ); +} + +/* eslint-env browser */ + +let cachedParseMarkup; + +// We use a function creator to make the reference to `document` lazy. At the +// same time, it's eager enough to throw in as soon as +// it's first mounted which reduces the risk of this error making it to the +// runtime without developers noticing it in development. +function createParseMarkup() { + if (typeof(document) === "undefined") { + // We can't use