WebAssembly.compile()함수는 WebAssembly 바이너리 코드에서 WebAssembly.Module을 컴파일합니다. 이 함수는 모듈을 인스턴스화하기 전에 컴파일해야하는 경우에 유용합니다. 그렇지 않으면 WebAssembly.instantiate () 함수를 사용해야합니다.
Syntax
Promise<WebAssembly.Module> WebAssembly.compile(bufferSource);
Parameters
- bufferSource
- 컴파일 할 .wasm 모듈의 이진 코드가 들어있는 typed array 또는 ArrayBuffer입니다.
Return value
Promise는 컴파일 된 모듈로 표현된 WebAssembly.Module 객체로 반환됩니다.
Exceptions
bufferSource가 typed array가 아니면TypeError가 발생합니다.- 컴파일에 실패하면 promise는
WebAssembly.CompileError와 함께 reject가 반환됩니다.
Examples
다음은 compile() 함수를 사용하여 simple.wasm 바이트 코드를 컴파일 하고 postMessage()를 사용하여 worker에 보내는 예제입니다.
var worker = new Worker("wasm_worker.js");
fetch('simple.wasm').then(response =>
response.arrayBuffer()
).then(bytes =>
WebAssembly.compile(bytes)
).then(mod =>
worker.postMessage(mod)
);
Note: 대부분의 경우에 WebAssembly.compileStreaming()를 사용하는 것이 좋습니다. 이는 compile()보다 효율적이기 때문입니다.
Specifications
| Specification | Status | Comment |
|---|---|---|
| WebAssembly JavaScript Interface The definition of 'compile()' in that specification. |
Working Draft | Initial draft definition. |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
| Desktop | Mobile | Server | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
compile | Chrome Full support 57 | Edge Full support 16 | Firefox
Full support
52
| IE No support No | Opera Full support 44 | Safari Full support 11 | WebView Android Full support 57 | Chrome Android Full support 57 | Edge Mobile
Full support
Yes
| Firefox Android
Full support
52
| Opera Android Full support 43 | Safari iOS Full support 11 | Samsung Internet Android Full support 7.0 | nodejs Full support 8.0.0 |
Legend
- Full support
- Full support
- No support
- No support
- See implementation notes.
- See implementation notes.
- User must explicitly enable this feature.
- User must explicitly enable this feature.