WebAssembly.validate()

Baseline Widely available *

This feature is well established and works across many devices and browser versions. It’s been available across browsers since October 2017.

* Some parts of this feature may have varying levels of support.

WebAssembly.validate() 関数は WebAssembly バイナリーコードの型付き配列を検証し、そのバイト列が有効な wasm モジュールか (true)、そうでないか (false) を返します。

構文

js
WebAssembly.validate(bufferSource);

引数

bufferSource

検証する WebAssembly バイナリーコードを含む型付き配列または ArrayBuffer

返値

有効な wasm モジュールであるか (true)、そうでないか (false) を示す論理値です。

例外

bufferSource型付き配列または ArrayBuffer でない場合、TypeError が発生します。

validate の使用

以下の例 (validate.htmlソースコード動作例 をご確認ください) は .wasm モジュールを読み取って型付き配列に変換します。次に、 validate() メソッドを使用してモジュールが有効かどうかをチェックします。

js
fetch("simple.wasm")
  .then((response) => response.arrayBuffer())
  .then(function (bytes) {
    var valid = WebAssembly.validate(bytes);
    console.log(
      "The given bytes are " + (valid ? "" : "not ") + "a valid wasm module",
    );
  });

仕様書

Specification
WebAssembly JavaScript Interface
# dom-webassembly-validate

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
validate() static method
compileOptions parameter

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support

関連情報