├── .gitignore ├── examples ├── test.ts └── test.js ├── tsconfig.json ├── LICENSE ├── package.json ├── dist ├── wasm-check.min.js └── wasm-check.min.js.map ├── lib ├── index.d.ts ├── index.js.map └── index.js ├── README.md ├── yarn.lock └── index.ts /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | web/ 3 | lib/tsconfig.tsbuildinfo 4 | **/.DS_Store 5 | .idea 6 | yarn-error.log 7 | -------------------------------------------------------------------------------- /examples/test.ts: -------------------------------------------------------------------------------- 1 | import * as check from '../lib/index'; 2 | 3 | const features = { ...check.feature }; 4 | console.log(features); 5 | -------------------------------------------------------------------------------- /examples/test.js: -------------------------------------------------------------------------------- 1 | const assert = require('assert'); 2 | const check = require('../lib/index'); 3 | 4 | assert.strictEqual(check.support(), true); 5 | assert.notStrictEqual(check.support(2), true); 6 | 7 | console.log(check.feature.bulk); 8 | console.log(check.feature.simd); 9 | console.log(check.feature.mutableGlobal); 10 | console.log(check.feature.multiValue); 11 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es2018", 4 | "module": "commonjs", 5 | "moduleResolution": "node", 6 | "esModuleInterop": true, 7 | "resolveJsonModule": true, 8 | "skipLibCheck": true, 9 | "sourceMap": true, 10 | "alwaysStrict": true, 11 | "strictPropertyInitialization": true, 12 | "strictFunctionTypes": true, 13 | "strictNullChecks": true, 14 | "noImplicitAny": true, 15 | "noImplicitThis": true, 16 | "noImplicitReturns": true, 17 | "experimentalDecorators": true, 18 | "forceConsistentCasingInFileNames": true, 19 | "declaration": true, 20 | "baseUrl": "./", 21 | "lib": [ 22 | "dom", 23 | "esnext", 24 | "esnext.bigint" 25 | ], 26 | "outDir": "lib" 27 | }, 28 | "include": [ 29 | "index.ts" 30 | ] 31 | } 32 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 MaxGraey 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "wasm-check", 3 | "version": "2.1.2", 4 | "author": "MaxGraey @ 2021", 5 | "license": "MIT", 6 | "description": "TypeScript / JavaScript library for detect WebAssembly features in node.js & browser", 7 | "keywords": [ 8 | "wasm", 9 | "webassembly", 10 | "feature", 11 | "validate", 12 | "check", 13 | "support", 14 | "test", 15 | "detect" 16 | ], 17 | "sideEffects": false, 18 | "main": "lib/index.js", 19 | "typings": "lib/index.d.ts", 20 | "jsdelivr": "dist/wasm-check.min.js", 21 | "browser": "dist/wasm-check.min.js", 22 | "unpkg": "dist/wasm-check.min.js", 23 | "files": [ 24 | "lib/**/*", 25 | "dist/**/*", 26 | "package.json" 27 | ], 28 | "bugs": "https://github.com/MaxGraey/wasm-check/issues", 29 | "repository": { 30 | "type": "git", 31 | "url": "git+https://github.com/MaxGraey/wasm-check.git" 32 | }, 33 | "engineStrict": true, 34 | "engines": { 35 | "node": ">= 8" 36 | }, 37 | "devDependencies": { 38 | "terser": "^5.3.1", 39 | "typescript": "^4.7.4" 40 | }, 41 | "scripts": { 42 | "build": "tsc && terser lib/index.js -c -m --toplevel --ecma 2018 -o dist/wasm-check.min.js --source-map \"content='./lib/index.js.map'\"", 43 | "watch": "tsc -w", 44 | "prepublishOnly": "yarn build" 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /dist/wasm-check.min.js: -------------------------------------------------------------------------------- 1 | "use strict";function e(e,n){if(!r)return!1;const u=e.buffer;let i=l.get(u);if(null==i){if((i=t.validate(u))&&n)try{new t.Instance(new t.Module(u)).exports[0]()}catch(e){i=!1}l.set(u,i)}return i}const t=this.WebAssembly||globalThis.WebAssembly,r="object"==typeof t,n=e=>void 0!==e,u=(...e)=>Uint8Array.of(0,97,115,109,1,0,0,0,...e),i=(...e)=>Uint32Array.of(1836278016,1,...e),s=(...e)=>i(1610679297,33751040,...e,40239360,259),o=(...e)=>u(1,4,1,96,0,0,3,2,1,0,...e,11,0,10,4,110,97,109,101,2,3,1,0,0),a=(...e)=>Uint16Array.of(24832,28019,1,0,1025,24577,0,515,1,...e),g=(...e)=>a(...e,2842,4096,28164,28001,357,260,256,560,259,0),l=new WeakMap,f=i(1610679553,58589440,117440770,805372165,101318656,1107297281,268438272,1835101700,17039717,36700416,259),c=u(5,3,1,4,1,0,8,4,110,97,109,101,2,1,0),y=a(773,1,2561,269,11,65,65,65,3068,2816,2560,28164,28001,613,259,0),b=i(1610679297,33751040,134873089,100664833,185276736),m=u(2,8,1,1,97,1,98,3,127,1,6,6,1,127,1,65,0,11,7,5,1,1,97,3,1,0,8,4,110,97,109,101,2,1,0),p=Uint16Array.of(24832,28019,1,0,1537,24577,512,32639,515,1,2058,1537,16640,16640,2816,2560,28164,28001,613,259,0),A=g(3082,2561,17152,0,0,252),d=g(2058,1537,16640,49152),U=s(101318657,301990913,268438272,1835101700,17039717),h=o(5,4,1,3,1,1,10,7,1,5,0,254,3,0),x=s(84344833,6357249,17369600,4259847,186257917,1845758464),v=o(10,7,1,5,0,208,112,26);module.exports={support:(t=1)=>r&&e(Uint32Array.of(1836278016,t)),get supportStreaming(){return r&&n(t.instantiateStreaming)},feature:{get bigInt(){return e(f,!0)},get bulk(){return e(y)},get exceptions(){return e(b)},get memory64(){return e(c)},get mutableGlobal(){return e(m)},get multiValue(){return e(p)},get saturateConversions(){return e(A)},get signExtensions(){return e(d)},get tailCall(){return e(U)},get threads(){return e(h)},get simd(){return e(x)},get references(){return e(v)},get typeReflection(){return r&&n(t.Memory.type)},get funcReferences(){return r&&n(t.Function)}}}; -------------------------------------------------------------------------------- /lib/index.d.ts: -------------------------------------------------------------------------------- 1 | declare const _default: { 2 | /** Check support WebAssembly version */ 3 | support(version?: number): boolean; 4 | /** Check support streaming compilation and instantiation */ 5 | readonly supportStreaming: boolean; 6 | feature: { 7 | /** Check support JavaScript BigInt to WebAssembly i64 integration (--experimental-wasm-bigint) */ 8 | readonly bigInt: boolean; 9 | /** Check support bulk memory operations (--experimental-wasm-bulk-memory) */ 10 | readonly bulk: boolean; 11 | /** Check support exception handling (--experimental-wasm-eh) */ 12 | readonly exceptions: boolean; 13 | /** Check support 64-bit memory (--experimental-wasm-memory64) */ 14 | readonly memory64: boolean; 15 | /** Check support import & export of mutable global (--experimental-wasm-mut-global) */ 16 | readonly mutableGlobal: boolean; 17 | /** Check support multi values (--experimental-wasm-mv) */ 18 | readonly multiValue: boolean; 19 | /** Check support non-trapping float-to-int conversions (--experimental-wasm-sat-f2i-conversions) */ 20 | readonly saturateConversions: boolean; 21 | /** Check support zero and sign extensions (--experimental-wasm-se) */ 22 | readonly signExtensions: boolean; 23 | /** Check support tail call optiminations (--experimental-wasm-return-call) */ 24 | readonly tailCall: boolean; 25 | /** Check support threads and atomics (--experimental-wasm-threads) */ 26 | readonly threads: boolean; 27 | /** Check support SIMD (--experimental-wasm-simd) */ 28 | readonly simd: boolean; 29 | /** Check support basic reference types "externref" (--experimental-wasm-reftypes) */ 30 | readonly references: boolean; 31 | /** Check support Type Reflection (--experimental-wasm-type-reflection) */ 32 | readonly typeReflection: boolean; 33 | /** Check support typed function references and closures (pre-proposal) */ 34 | readonly funcReferences: boolean; 35 | }; 36 | }; 37 | export = _default; 38 | -------------------------------------------------------------------------------- /dist/wasm-check.min.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"names":["check","wasm","exec","exists","buffer","ok","cache","get","WA","validate","Instance","Module","exports","_a","set","this","WebAssembly","globalThis","has","entity","u8","bytes","Uint8Array","of","u32","Uint32Array","u32a","u8a","u16a","Uint16Array","u16b","WeakMap","bigIntWasm","memory64Wasm","bulkWasm","exceptionsWasm","mutableGlobalWasm","multiValueWasm","saturateConversionsWasm","signExtensionsWasm","tailCallWasm","threadsWasm","simdWasm","referencesWasm","module","support","version","supportStreaming","instantiateStreaming","feature","bigInt","bulk","exceptions","memory64","mutableGlobal","multiValue","saturateConversions","signExtensions","tailCall","threads","simd","references","typeReflection","Memory","type","funcReferences","Function"],"sources":["../index.ts"],"mappings":"aA6CA,SAASA,EACPC,EACAC,GAEA,IAAKC,EAAQ,OAAO,EACpB,MAAMC,EAASH,EAAKG,OACpB,IAAIC,EAAKC,EAAMC,IAAIH,GACnB,GAAU,MAANC,EAAY,CACd,IAAKA,EAAKG,EAAGC,SAASL,KAAYF,EAChC,IACG,IAAIM,EAAGE,SACN,IAAIF,EAAGG,OAAOP,IACdQ,QAAQ,I,CACV,MAAAC,GAAQR,GAAK,C,CAEjBC,EAAMQ,IAAIV,EAAQC,E,CAEpB,OAAOA,CACT,CAEA,MAAMG,EAAWO,KAAMC,aAAeC,WAAWD,YAC3Cb,EAAuB,iBAAPK,EAChBU,EAAOC,QAAsC,IAAXA,EAElCC,EAAO,IAAIC,IAAoBC,WAAWC,GAAG,EAAG,GAAI,IAAK,IAAK,EAAG,EAAG,EAAG,KAAMF,GAE7EG,EAAO,IAAIH,IAAoBI,YAAYF,GAAG,WAAY,KAAMF,GAChEK,EAAO,IAAIL,I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EACzB,KAAM,KAAM,MAAO,OAGfU,EAAed,EACnB,UAAW,UAAW,UAAW,WAAY,UAGzCe,EAAcd,EAClB,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,GAAI,EAAG,EAAG,EAAG,EAAG,IAAK,EAAG,GAGtCe,EAAWhB,EACf,SAAU,QAAS,SAAU,QAAS,UAAW,YAG7CiB,EAAiBhB,EACrB,GAAI,EAAG,EAAG,EAAG,EAAG,IAAK,IAAK,IAhI5BiB,OAAAhC,QAAS,CAEPiC,QAAO,CAACC,EAAU,IACT3C,GAAUH,EAAMyB,YAAYF,GAAG,WAAYuB,IAIhDC,uBAAqB,OAAO5C,GAAUe,EAAIV,EAAGwC,qBAAsB,EAEvEC,QAAS,CAEHC,aAAW,OAAOlD,EAAMgC,GAAY,EAAM,EAE1CmB,WAAS,OAAOnD,EAAMkC,EAAU,EAEhCkB,iBAAe,OAAOpD,EAAMmC,EAAgB,EAE5CkB,eAAa,OAAOrD,EAAMiC,EAAc,EAExCqB,oBAAkB,OAAOtD,EAAMoC,EAAmB,EAElDmB,iBAAe,OAAOvD,EAAMqC,EAAgB,EAE5CmB,0BAAwB,OAAOxD,EAAMsC,EAAyB,EAE9DmB,qBAAmB,OAAOzD,EAAMuC,EAAoB,EAEpDmB,eAAa,OAAO1D,EAAMwC,EAAc,EAExCmB,cAAY,OAAO3D,EAAMyC,EAAa,EAEtCmB,WAAS,OAAO5D,EAAM0C,EAAU,EAEhCmB,iBAAe,OAAO7D,EAAM2C,EAAgB,EAE5CmB,qBAAmB,OAAO3D,GAAUe,EAAUV,EAAGuD,OAAQC,KAAM,EAE/DC,qBAAmB,OAAO9D,GAAUe,EAAUV,EAAI0D,SAAU"} -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![NPM registry](https://img.shields.io/npm/v/wasm-check.svg?style=for-the-badge)](https://www.npmjs.com/package/wasm-check)[![NPM license](https://img.shields.io/badge/license-mit-green.svg?style=for-the-badge)](LICENSE.md) 2 | 3 | Library for detect WebAssembly post-MVP features in NodeJS & Browser. Small and with zero dependencies. 4 | --- 5 | 6 | ## About post-MVP WebAssembly features 7 | 8 | https://github.com/WebAssembly/design/blob/master/FutureFeatures.md#tracking-issues 9 | 10 | _Tests on Canary with flags:_ 11 | 12 | Enable some experimental features for Chrome Canary (Mac): 13 | ``` 14 | /Applications/Google\ Chrome\ Canary.app/Contents/MacOS/Google\ Chrome\ Canary --js-flags="--experimental-wasm-eh" 15 | ``` 16 | 17 | ## Support feature detections 18 | 19 | - [x] [Reference types](https://github.com/WebAssembly/reference-types) _(standardized)_ 20 | - [x] [BigInt between js and wasm](https://github.com/WebAssembly/JS-BigInt-integration) _(standardized)_ 21 | - [x] [Bulk memory operations](https://github.com/webassembly/bulk-memory-operations) _(standardized)_ 22 | - [x] [Memory 64-bit](https://github.com/WebAssembly/memory64) _(--experimental-wasm-memory64)_ 23 | - [x] [Exceptions](https://github.com/WebAssembly/exception-handling) _(--experimental-wasm-eh)_ 24 | - [x] [Multi values](https://github.com/WebAssembly/multi-value) _(standardized)_ 25 | - [x] [Tail recursion calls](https://github.com/webassembly/tail-call) _(--experimental-wasm-return-call)_ 26 | - [x] [Saturated (non-trapping) conversions from float to int](https://github.com/WebAssembly/nontrapping-float-to-int-conversions) _(standardized)_ 27 | - [x] [Sign extensions](https://github.com/WebAssembly/sign-extension-ops) _(standardized)_ 28 | - [x] [SIMD](https://github.com/webassembly/simd) _(standardized)_ 29 | - [x] [Threads](https://github.com/webassembly/threads) _(standardized)_ 30 | - [x] [Type reflection](https://github.com/WebAssembly/js-types) _(--experimental-wasm-type-reflection)_ 31 | 32 | ## Install 33 | 34 | ``` 35 | yarn add wasm-check 36 | ``` 37 | 38 | or 39 | 40 | ``` 41 | npm i wasm-check 42 | ``` 43 | 44 | ## Usage 45 | 46 | #### Check supported WebAssembly version 47 | 48 | ```ts 49 | import * as check from 'wasm-check'; 50 | // or 51 | // const check = require('wasm-check'); 52 | 53 | console.log(check.support()); // WebAssembly 1.0 (MVP) 54 | console.log(check.support(1)); // ^^^ 55 | console.log(check.support(2)); // WebAssembly 2.0 56 | ``` 57 | 58 | #### Check supporting streaming compilation 59 | 60 | ```ts 61 | import * as check from 'wasm-check'; 62 | 63 | console.log(check.supportStreaming); 64 | ``` 65 | 66 | #### Get all post-MVP WebAssembly features 67 | 68 | ```ts 69 | import * as check from 'wasm-check'; 70 | 71 | const features = { ...check.feature }; 72 | console.log(features); 73 | ``` 74 | 75 | Output: 76 | 77 | ```js 78 | { 79 | bigInt: true, 80 | bulk: true, 81 | exceptions: false, 82 | memory64: false, 83 | mutableGlobal: true, 84 | multiValue: true, 85 | saturateConversions: true, 86 | signExtensions: true, 87 | tailCall: false, 88 | threads: false, 89 | simd: false, 90 | references: false, 91 | typeReflection: false, 92 | funcReferences: false 93 | } 94 | ``` 95 | 96 | #### Or check concrete feature 97 | 98 | ```ts 99 | import * as check from 'wasm-check'; 100 | 101 | console.log(check.feature.simd); // has SIMD support? 102 | console.log(check.feature.tailCalls); // has tail call optimization support? 103 | ``` 104 | 105 | #### TODO 106 | 107 | - [ ] GC integration feature check 108 | -------------------------------------------------------------------------------- /yarn.lock: -------------------------------------------------------------------------------- 1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. 2 | # yarn lockfile v1 3 | 4 | 5 | "@jridgewell/gen-mapping@^0.3.0": 6 | version "0.3.2" 7 | resolved "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.2.tgz" 8 | integrity sha512-mh65xKQAzI6iBcFzwv28KVWSmCkdRBWoOh+bYQGW3+6OZvbbN3TqMGo5hqYxQniRcH9F2VZIoJCm4pa3BPDK/A== 9 | dependencies: 10 | "@jridgewell/set-array" "^1.0.1" 11 | "@jridgewell/sourcemap-codec" "^1.4.10" 12 | "@jridgewell/trace-mapping" "^0.3.9" 13 | 14 | "@jridgewell/resolve-uri@^3.0.3": 15 | version "3.1.0" 16 | resolved "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.0.tgz" 17 | integrity sha512-F2msla3tad+Mfht5cJq7LSXcdudKTWCVYUgw6pLFOOHSTtZlj6SWNYAp+AhuqLmWdBO2X5hPrLcu8cVP8fy28w== 18 | 19 | "@jridgewell/set-array@^1.0.1": 20 | version "1.1.2" 21 | resolved "https://registry.npmjs.org/@jridgewell/set-array/-/set-array-1.1.2.tgz" 22 | integrity sha512-xnkseuNADM0gt2bs+BvhO0p78Mk762YnZdsuzFV018NoG1Sj1SCQvpSqa7XUaTam5vAGasABV9qXASMKnFMwMw== 23 | 24 | "@jridgewell/source-map@^0.3.2": 25 | version "0.3.2" 26 | resolved "https://registry.npmjs.org/@jridgewell/source-map/-/source-map-0.3.2.tgz" 27 | integrity sha512-m7O9o2uR8k2ObDysZYzdfhb08VuEml5oWGiosa1VdaPZ/A6QyPkAJuwN0Q1lhULOf6B7MtQmHENS743hWtCrgw== 28 | dependencies: 29 | "@jridgewell/gen-mapping" "^0.3.0" 30 | "@jridgewell/trace-mapping" "^0.3.9" 31 | 32 | "@jridgewell/sourcemap-codec@^1.4.10": 33 | version "1.4.14" 34 | resolved "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.14.tgz" 35 | integrity sha512-XPSJHWmi394fuUuzDnGz1wiKqWfo1yXecHQMRf2l6hztTO+nPru658AyDngaBe7isIxEkRsPR3FZh+s7iVa4Uw== 36 | 37 | "@jridgewell/trace-mapping@^0.3.9": 38 | version "0.3.14" 39 | resolved "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.14.tgz" 40 | integrity sha512-bJWEfQ9lPTvm3SneWwRFVLzrh6nhjwqw7TUFFBEMzwvg7t7PCDenf2lDwqo4NQXzdpgBXyFgDWnQA+2vkruksQ== 41 | dependencies: 42 | "@jridgewell/resolve-uri" "^3.0.3" 43 | "@jridgewell/sourcemap-codec" "^1.4.10" 44 | 45 | acorn@^8.5.0: 46 | version "8.7.1" 47 | resolved "https://registry.npmjs.org/acorn/-/acorn-8.7.1.tgz" 48 | integrity sha512-Xx54uLJQZ19lKygFXOWsscKUbsBZW0CPykPhVQdhIeIwrbPmJzqeASDInc8nKBnp/JT6igTs82qPXz069H8I/A== 49 | 50 | buffer-from@^1.0.0: 51 | version "1.1.2" 52 | resolved "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz" 53 | integrity sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ== 54 | 55 | commander@^2.20.0: 56 | version "2.20.1" 57 | resolved "https://registry.npmjs.org/commander/-/commander-2.20.1.tgz" 58 | integrity sha512-cCuLsMhJeWQ/ZpsFTbE765kvVfoeSddc4nU3up4fV+fDBcfUXnbITJ+JzhkdjzOqhURjZgujxaioam4RM9yGUg== 59 | 60 | source-map-support@~0.5.20: 61 | version "0.5.21" 62 | resolved "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.21.tgz" 63 | integrity sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w== 64 | dependencies: 65 | buffer-from "^1.0.0" 66 | source-map "^0.6.0" 67 | 68 | source-map@^0.6.0: 69 | version "0.6.1" 70 | resolved "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz" 71 | integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g== 72 | 73 | terser@^5.3.1: 74 | version "5.14.2" 75 | resolved "https://registry.npmjs.org/terser/-/terser-5.14.2.tgz" 76 | integrity sha512-oL0rGeM/WFQCUd0y2QrWxYnq7tfSuKBiqTjRPWrRgB46WD/kiwHwF8T23z78H6Q6kGCuuHcPB+KULHRdxvVGQA== 77 | dependencies: 78 | "@jridgewell/source-map" "^0.3.2" 79 | acorn "^8.5.0" 80 | commander "^2.20.0" 81 | source-map-support "~0.5.20" 82 | 83 | typescript@^4.7.4: 84 | version "4.7.4" 85 | resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.7.4.tgz#1a88596d1cf47d59507a1bcdfb5b9dfe4d488235" 86 | integrity sha512-C0WQT0gezHuw6AdY1M2jxUO83Rjf0HP7Sk1DtXj6j1EwkQNZrHAg2XPWlq62oqEhYvONq5pkC2Y9oPljWToLmQ== 87 | -------------------------------------------------------------------------------- /lib/index.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";AA6CA,SAAS,KAAK,CACZ,IAAqB,EACrB,IAAc;IAEd,IAAI,CAAC,MAAM;QAAE,OAAO,KAAK,CAAA;IACzB,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAA;IAC1B,IAAI,EAAE,GAAG,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;IAC1B,IAAI,EAAE,IAAI,IAAI,EAAE;QACd,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,IAAI,IAAI,EAAE;YACtC,IAAI;gBACD,IAAI,EAAE,CAAC,QAAQ,CACd,IAAI,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CACtB,CAAC,OAAO,CAAC,GAAG,CAAc,EAAE,CAAA;aAC9B;YAAC,WAAM;gBAAE,EAAE,GAAG,KAAK,CAAA;aAAE;SACvB;QACD,KAAK,CAAC,GAAG,CAAC,MAAM,EAAE,EAAG,CAAC,CAAA;KACvB;IACD,OAAO,EAAG,CAAA;AACZ,CAAC;AAED,MAAM,EAAE,GAAS,IAAK,CAAC,WAAW,IAAI,UAAU,CAAC,WAAW,CAAA;AAC5D,MAAM,MAAM,GAAG,OAAO,EAAE,KAAK,QAAQ,CAAA;AACrC,MAAM,GAAG,GAAG,CAAC,MAAe,EAAE,EAAE,CAAC,O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KAAK,CAAC,QAAQ,CAAC,CAAA,CAAC,CAAC;QACrC,qFAAqF;QACrF,IAAI,UAAU,KAAK,OAAO,KAAK,CAAC,cAAc,CAAC,CAAA,CAAC,CAAC;QACjD,0EAA0E;QAC1E,IAAI,cAAc,KAAK,OAAO,MAAM,IAAI,GAAG,CAAO,EAAE,CAAC,MAAO,CAAC,IAAI,CAAC,CAAA,CAAC,CAAC;QACpE,0EAA0E;QAC1E,IAAI,cAAc,KAAK,OAAO,MAAM,IAAI,GAAG,CAAO,EAAG,CAAC,QAAQ,CAAC,CAAA,CAAC,CAAC;QACjE;;;WAGG;KACJ;CACF,CAAA"} -------------------------------------------------------------------------------- /lib/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | function check(wasm, exec) { 3 | if (!exists) 4 | return false; 5 | const buffer = wasm.buffer; 6 | let ok = cache.get(buffer); 7 | if (ok == null) { 8 | if ((ok = WA.validate(buffer)) && exec) { 9 | try { 10 | new WA.Instance(new WA.Module(buffer)).exports['0'](); 11 | } 12 | catch (_a) { 13 | ok = false; 14 | } 15 | } 16 | cache.set(buffer, ok); 17 | } 18 | return ok; 19 | } 20 | const WA = this.WebAssembly || globalThis.WebAssembly; 21 | const exists = typeof WA === 'object'; 22 | const has = (entity) => typeof entity !== 'undefined'; 23 | const u8 = (...bytes) => Uint8Array.of(0, 97, 115, 109, 1, 0, 0, 0, ...bytes); 24 | // const u16 = (...bytes: number[]) => Uint16Array.of(24832, 28019, 1, 0, ...bytes) 25 | const u32 = (...bytes) => Uint32Array.of(0x6D736100, 1, ...bytes); 26 | const u32a = (...bytes) => u32(1610679297, 33751040, ...bytes, 40239360, 259); 27 | const u8a = (...bytes) => u8(1, 4, 1, 96, 0, 0, 3, 2, 1, 0, ...bytes, 11, 0, 10, 4, 110, 97, 109, 101, 2, 3, 1, 0, 0); 28 | const u16a = (...bytes) => Uint16Array.of(24832, 28019, 1, 0, 1025, 24577, 0, 515, 1, ...bytes); 29 | const u16b = (...bytes) => u16a(...bytes, 2842, 4096, 28164, 28001, 357, 260, 256, 560, 259, 0); 30 | const cache = new WeakMap(); 31 | const bigIntWasm = u32(1610679553, 58589440, 117440770, 805372165, 101318656, 1107297281, 268438272, 1835101700, 17039717, 36700416, 259); 32 | const memory64Wasm = u8(5, 3, 1, 4, 1, 0, 8, 4, 110, 97, 109, 101, 2, 1, 0); 33 | const bulkWasm = u16a(773, 1, 2561, 269, 11, 65, 65, 65, 3068, 2816, 2560, 28164, 28001, 613, 259, 0); 34 | const exceptionsWasm = u32(1610679297, 33751040, 134873089, 100664833, 185276736); 35 | const mutableGlobalWasm = u8(2, 8, 1, 1, 97, 1, 98, 3, 127, 1, 6, 6, 1, 127, 1, 65, 0, 11, 7, 5, 1, 1, 97, 3, 1, 0, 8, 4, 110, 97, 109, 101, 2, 1, 0); 36 | const multiValueWasm = Uint16Array.of(24832, 28019, 1, 0, 1537, 24577, 512, 32639, 515, 1, 2058, 1537, 16640, 16640, 2816, 2560, 28164, 28001, 613, 259, 0); 37 | const saturateConversionsWasm = u16b(3082, 2561, 17152, 0, 0, 252); 38 | const signExtensionsWasm = u16b(2058, 1537, 16640, 49152); 39 | const tailCallWasm = u32a(101318657, 301990913, 268438272, 1835101700, 17039717); 40 | const threadsWasm = u8a(5, 4, 1, 3, 1, 1, 10, 7, 1, 5, 0, 254, 3, 0); 41 | const simdWasm = u32a(84344833, 6357249, 17369600, 4259847, 186257917, 1845758464); 42 | const referencesWasm = u8a(10, 7, 1, 5, 0, 208, 112, 26); 43 | module.exports = { 44 | /** Check support WebAssembly version */ 45 | support(version = 1) { 46 | return exists && check(Uint32Array.of(0x6D736100, version)); 47 | }, 48 | /** Check support streaming compilation and instantiation */ 49 | get supportStreaming() { return exists && has(WA.instantiateStreaming); }, 50 | feature: { 51 | /** Check support JavaScript BigInt to WebAssembly i64 integration (--experimental-wasm-bigint) */ 52 | get bigInt() { return check(bigIntWasm, true); }, 53 | /** Check support bulk memory operations (--experimental-wasm-bulk-memory) */ 54 | get bulk() { return check(bulkWasm); }, 55 | /** Check support exception handling (--experimental-wasm-eh) */ 56 | get exceptions() { return check(exceptionsWasm); }, 57 | /** Check support 64-bit memory (--experimental-wasm-memory64) */ 58 | get memory64() { return check(memory64Wasm); }, 59 | /** Check support import & export of mutable global (--experimental-wasm-mut-global) */ 60 | get mutableGlobal() { return check(mutableGlobalWasm); }, 61 | /** Check support multi values (--experimental-wasm-mv) */ 62 | get multiValue() { return check(multiValueWasm); }, 63 | /** Check support non-trapping float-to-int conversions (--experimental-wasm-sat-f2i-conversions) */ 64 | get saturateConversions() { return check(saturateConversionsWasm); }, 65 | /** Check support zero and sign extensions (--experimental-wasm-se) */ 66 | get signExtensions() { return check(signExtensionsWasm); }, 67 | /** Check support tail call optiminations (--experimental-wasm-return-call) */ 68 | get tailCall() { return check(tailCallWasm); }, 69 | /** Check support threads and atomics (--experimental-wasm-threads) */ 70 | get threads() { return check(threadsWasm); }, 71 | /** Check support SIMD (--experimental-wasm-simd) */ 72 | get simd() { return check(simdWasm); }, 73 | /** Check support basic reference types "externref" (--experimental-wasm-reftypes) */ 74 | get references() { return check(referencesWasm); }, 75 | /** Check support Type Reflection (--experimental-wasm-type-reflection) */ 76 | get typeReflection() { return exists && has(WA.Memory.type); }, 77 | /** Check support typed function references and closures (pre-proposal) */ 78 | get funcReferences() { return exists && has(WA.Function); }, 79 | /* TODO 80 | * - GC 81 | * - Web IDL Bindings (Host binding) ? 82 | */ 83 | } 84 | }; 85 | //# sourceMappingURL=index.js.map -------------------------------------------------------------------------------- /index.ts: -------------------------------------------------------------------------------- 1 | export = { 2 | /** Check support WebAssembly version */ 3 | support(version = 1) { 4 | return exists && check(Uint32Array.of(0x6D736100, version)) 5 | }, 6 | 7 | /** Check support streaming compilation and instantiation */ 8 | get supportStreaming() { return exists && has(WA.instantiateStreaming) }, 9 | 10 | feature: { 11 | /** Check support JavaScript BigInt to WebAssembly i64 integration (--experimental-wasm-bigint) */ 12 | get bigInt() { return check(bigIntWasm, true) }, 13 | /** Check support bulk memory operations (--experimental-wasm-bulk-memory) */ 14 | get bulk() { return check(bulkWasm) }, 15 | /** Check support exception handling (--experimental-wasm-eh) */ 16 | get exceptions() { return check(exceptionsWasm) }, 17 | /** Check support 64-bit memory (--experimental-wasm-memory64) */ 18 | get memory64() { return check(memory64Wasm) }, 19 | /** Check support import & export of mutable global (--experimental-wasm-mut-global) */ 20 | get mutableGlobal() { return check(mutableGlobalWasm) }, 21 | /** Check support multi values (--experimental-wasm-mv) */ 22 | get multiValue() { return check(multiValueWasm) }, 23 | /** Check support non-trapping float-to-int conversions (--experimental-wasm-sat-f2i-conversions) */ 24 | get saturateConversions() { return check(saturateConversionsWasm) }, 25 | /** Check support zero and sign extensions (--experimental-wasm-se) */ 26 | get signExtensions() { return check(signExtensionsWasm) }, 27 | /** Check support tail call optiminations (--experimental-wasm-return-call) */ 28 | get tailCall() { return check(tailCallWasm) }, 29 | /** Check support threads and atomics (--experimental-wasm-threads) */ 30 | get threads() { return check(threadsWasm) }, 31 | /** Check support SIMD (--experimental-wasm-simd) */ 32 | get simd() { return check(simdWasm) }, 33 | /** Check support basic reference types "externref" (--experimental-wasm-reftypes) */ 34 | get references() { return check(referencesWasm) }, 35 | /** Check support Type Reflection (--experimental-wasm-type-reflection) */ 36 | get typeReflection() { return exists && has((WA.Memory).type) }, 37 | /** Check support typed function references and closures (pre-proposal) */ 38 | get funcReferences() { return exists && has((WA).Function) }, 39 | /* TODO 40 | * - GC 41 | * - Web IDL Bindings (Host binding) ? 42 | */ 43 | } 44 | } 45 | 46 | function check( 47 | wasm: ArrayBufferView, 48 | exec?: boolean 49 | ) { 50 | if (!exists) return false 51 | const buffer = wasm.buffer 52 | let ok = cache.get(buffer) 53 | if (ok == null) { 54 | if ((ok = WA.validate(buffer)) && exec) { 55 | try { 56 | (new WA.Instance( 57 | new WA.Module(buffer) 58 | ).exports['0'] as Function)() 59 | } catch { ok = false } 60 | } 61 | cache.set(buffer, ok!) 62 | } 63 | return ok! 64 | } 65 | 66 | const WA = (this).WebAssembly || globalThis.WebAssembly 67 | const exists = typeof WA === 'object' 68 | const has = (entity: unknown) => typeof entity !== 'undefined' 69 | 70 | const u8 = (...bytes: number[]) => Uint8Array.of(0, 97, 115, 109, 1, 0, 0, 0, ...bytes) 71 | // const u16 = (...bytes: number[]) => Uint16Array.of(24832, 28019, 1, 0, ...bytes) 72 | const u32 = (...bytes: number[]) => Uint32Array.of(0x6D736100, 1, ...bytes) 73 | const u32a = (...bytes: number[]) => u32(1610679297, 33751040, ...bytes, 40239360, 259) 74 | 75 | const u8a = (...bytes: number[]) => u8(1, 4, 1, 96, 0, 0, 3, 2, 1, 0, ...bytes, 11, 0, 10, 4, 110, 97, 109, 101, 2, 3, 1, 0, 0) 76 | const u16a = (...bytes: number[]) => Uint16Array.of(24832, 28019, 1, 0, 1025, 24577, 0, 515, 1, ...bytes) 77 | const u16b = (...bytes: number[]) => u16a(...bytes, 2842, 4096, 28164, 28001, 357, 260, 256, 560, 259, 0) 78 | 79 | const cache = new WeakMap() 80 | 81 | const bigIntWasm = u32( 82 | 1610679553, 58589440, 117440770, 805372165, 101318656, 1107297281, 268438272, 83 | 1835101700, 17039717, 36700416, 259 84 | ) 85 | 86 | const memory64Wasm = u8( 87 | 5, 3, 1, 4, 1, 0, 8, 4, 110, 97, 109, 101, 2, 1, 0 88 | ) 89 | 90 | const bulkWasm = u16a( 91 | 773, 1, 2561, 269, 11, 65, 65, 65, 3068, 2816, 2560, 28164, 28001, 613, 259, 0 92 | ) 93 | 94 | const exceptionsWasm = u32( 95 | 1610679297, 33751040, 134873089, 100664833, 185276736 96 | ) 97 | 98 | const mutableGlobalWasm = u8( 99 | 2, 8, 1, 1, 97, 1, 98, 3, 127, 1, 6, 6, 1, 127, 1, 65, 0, 11, 7, 5, 1, 1, 97, 100 | 3, 1, 0, 8, 4, 110, 97, 109, 101, 2, 1, 0 101 | ) 102 | 103 | const multiValueWasm = Uint16Array.of( 104 | 24832, 28019, 1, 0, 1537, 24577, 512, 32639, 515, 1, 2058, 105 | 1537, 16640, 16640, 2816, 2560, 28164, 28001, 613, 259, 0 106 | ) 107 | 108 | const saturateConversionsWasm = u16b( 109 | 3082, 2561, 17152, 0, 0, 252 110 | ) 111 | 112 | const signExtensionsWasm = u16b( 113 | 2058, 1537, 16640, 49152 114 | ) 115 | 116 | const tailCallWasm = u32a( 117 | 101318657, 301990913, 268438272, 1835101700, 17039717 118 | ) 119 | 120 | const threadsWasm = u8a( 121 | 5, 4, 1, 3, 1, 1, 10, 7, 1, 5, 0, 254, 3, 0 122 | ) 123 | 124 | const simdWasm = u32a( 125 | 84344833, 6357249, 17369600, 4259847, 186257917, 1845758464 126 | ) 127 | 128 | const referencesWasm = u8a( 129 | 10, 7, 1, 5, 0, 208, 112, 26 130 | ) 131 | --------------------------------------------------------------------------------