WebAssembly

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 JavaScript 객체는 모든 WebAssembly에 관계된 기능의 네임스페이스로서 역할합니다.

대부분의 전역객체와 다르게, WebAssembly는 생성자가 아닙니다 (함수 객체가 아닙니다). 비슷한 예로 수학적인 상수나 함수들을 담고있는 Math 객체나, 국제화 관련 생성자나 언어에 민감한 다른 함수들을 담고있는 Intl 등이 있습니다.

설명

WebAssembly 객체의 기본적인 사용례는 다음과 같습니다:

메서드

WebAssembly.instantiate()

WebAssembly 코드를 컴파일하고 인스턴스화하여 Module과 첫 번째 Instance를 반환하는 기본 API입니다.

WebAssembly.instantiateStreaming()

스트리밍 된 원본 소스에서 직접 WebAssembly 모듈을 컴파일하고 인스턴스화하여 Module과 첫 번째 Instance를 반환합니다.

WebAssembly.compile()

WebAssembly 바이너리 코드에서 WebAssembly.Module을 컴파일하여 인스턴스화를 별도의 단계로 남겨 둡니다.

WebAssembly.compileStreaming()

WebAssembly.Module을 스트림 된 원본 소스에서 직접 컴파일하여 인스턴스화를 별도의 단계로 남겨 둡니다.

WebAssembly.validate()

바이트가 유효한 WebAssembly 코드 (true)인지 아닌지 (false)를 반환하여 WebAssembly 바이너리 코드의 지정된 입력 된 배열을 확인합니다.

생성자

WebAssembly.Global()

Creates a new WebAssembly Global object.

WebAssembly.Module()

Creates a new WebAssembly Module object.

WebAssembly.Instance()

Creates a new WebAssembly Instance object.

WebAssembly.Memory()

Creates a new WebAssembly Memory object.

WebAssembly.Table()

Creates a new WebAssembly Table object.

WebAssembly.CompileError()

Creates a new WebAssembly CompileError object.

WebAssembly.LinkError()

Creates a new WebAssembly LinkError object.

WebAssembly.RuntimeError()

Creates a new WebAssembly RuntimeError object.

예제

다음 예제 (GitHub의 instantiate-streaming.html 데모보기 및 라이브보기)에서는 기본 소스에서 .wasm 모듈을 직접 스트리밍 한 다음 컴파일하고 인스턴스화합니다. 프로미스는 ResultObject로 충족됩니다. instantiateStreaming() 함수는 Response 객체에 대한 promise를 받아들이므로 직접 fetch() 호출에 전달할 수 있습니다.

js
var importObject = { imports: { imported_func: (arg) => console.log(arg) } };

WebAssembly.instantiateStreaming(fetch("simple.wasm"), importObject).then(
  (obj) => obj.instance.exports.exported_func(),
);

그런 다음 ResultObject의 인스턴스 구성에 액세스하고 그 안에 있는 exported_func을 호출합니다.

명세서

Specification
WebAssembly JavaScript Interface
# webassembly-namespace

브라우저 호환성

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
api
CompileError
CompileError() constructor
Exception
Exception() constructor
options.traceStack parameter
Non-standard
Exception.getArg
Exception.is
Stack trace
Non-standard
Global
Global() constructor
Global.value
Global.valueOf
Instance
Instance() constructor
Instance.exports
LinkError
LinkError() constructor
Memory
Memory() constructor
shared flag
Memory.buffer
Memory.grow
Module
Module() constructor
compileOptions parameter
customSections() static method
exports() static method
imports() static method
RuntimeError
RuntimeError() constructor
Table
Table() constructor
Table.get
Table.grow
Table.length
Table.set
Tag
Tag() constructor
Tag.type
compileStreaming() static method
compileOptions parameter
compile() static method
compileOptions parameter
instantiateStreaming() static method
compileOptions parameter
instantiate() static method
compileOptions parameter
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
Non-standard. Check cross-browser support before using.
See implementation notes.
User must explicitly enable this feature.

바깥 고리