Skip to content

Commit

Permalink
Added BigInt parameters test
Browse files Browse the repository at this point in the history
  • Loading branch information
syrusakbary committed Oct 11, 2019
1 parent c67b189 commit 28aaa40
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ A small library to detect which features of WebAssembly are supported.
- ✅ Runs in Node
- ✅ Provided as an ES6 module, CommonJS and UMD module.
- ✅ CSP compatible
- ✅ Only ~501B gzipped
- ✅ Only ~586B gzipped

## Installation

Expand Down Expand Up @@ -45,6 +45,7 @@ All detectors return a `Promise<bool>`.

| Function | Proposal |
| ----------------------- | ------------------------------------------------------------------------------------------------------------ |
| `bigintParameters()` | [BigInt integration](https://github.com/WebAssembly/JS-BigInt-integration) |
| `bulkMemory()` | [Bulk memory operations](https://github.com/webassembly/bulk-memory-operations) |
| `exceptions()` | [Exception handling](https://github.com/WebAssembly/exception-handling) |
| `multiValue()` | [Multi-value](https://github.com/WebAssembly/multi-value) |
Expand Down
22 changes: 22 additions & 0 deletions src/detectors/bigint-parameters/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Copyright 2019 Google Inc. All Rights Reserved.
* 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.
*/

export default async function(bytes) {
try {
const n = BigInt(0);
const instance = await WebAssembly.instantiate(bytes);
return instance.instance.exports.b(n) === n;
} catch {
return false;
}
}
8 changes: 8 additions & 0 deletions src/detectors/bigint-parameters/module.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
;; Name: BigInt integration
;; Proposal: https://github.com/WebAssembly/JS-BigInt-integration

(module
(func (export "b") (param i64) (result i64)
local.get 0
)
)
1 change: 1 addition & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ checkFeature("signExtensions");
checkFeature("simd");
checkFeature("tailCall");
checkFeature("threads");
checkFeature("bigintParameters");

0 comments on commit 28aaa40

Please sign in to comment.