This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

WebAssembly.compileStreaming()

Baseline Widely available *

This feature is well established and works across many devices and browser versions. Itโ€™s been available across browsers since โจ2021๋…„ 9์›”โฉ.

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

**WebAssembly.compileStreaming()**ํ•จ์ˆ˜๋Š” ์ŠคํŠธ๋ฆผ ๋œ ์›๋ณธ ์†Œ์Šค์—์„œ ์ง์ ‘ WebAssembly.Module์„ ์ปดํŒŒ์ผํ•ฉ๋‹ˆ๋‹ค. ์ด ํ•จ์ˆ˜๋Š” ๋ชจ๋“ˆ์„ ์ธ์Šคํ„ด์Šคํ™”ํ•˜๊ธฐ ์ „์— ์ปดํŒŒ์ผํ•ด์•ผํ•˜๋Š” ๊ฒฝ์šฐ ์œ ์šฉํ•ฉ๋‹ˆ๋‹ค (๊ทธ๋ ‡์ง€ ์•Š์œผ๋ฉด WebAssembly.instantiateStreaming () ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค).

Syntax

js
WebAssembly.compileStreaming(source);

Parameters

source

์ŠคํŠธ๋ฆฌ๋ฐ ๋ฐ ์ปดํŒŒ์ผํ•˜๋ ค๋Š” .wasm ๋ชจ๋“ˆ์˜ ๊ธฐ๋ณธ ์†Œ์Šค๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” Response ๊ฐ์ฒด ๋˜๋Š” ์•ฝ์†์„ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค.

Return value

Promise๋Š” ์ปดํŒŒ์ผ ๋œ ๋ชจ๋“ˆ๋กœ ํ‘œํ˜„๋œ WebAssembly.Module ๊ฐ์ฒด๋กœ ๋ฐ˜ํ™˜๋ฉ๋‹ˆ๋‹ค.

Exceptions

  • bufferSource๊ฐ€ typed array๊ฐ€ ์•„๋‹ˆ๋ฉด TypeError๊ฐ€ ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค.
  • ์ปดํŒŒ์ผ์— ์‹คํŒจํ•˜๋ฉด promise๋Š” WebAssembly.CompileError์™€ ํ•จ๊ป˜ reject๊ฐ€ ๋ฐ˜ํ™˜๋ฉ๋‹ˆ๋‹ค.

Examples

๋‹ค์Œ ์˜ˆ์ œ (GitHub์˜ compile-streaming.html ๋ฐ๋ชจ ๋ฐ ๋ผ์ด๋ธŒ๋ณด๊ธฐ)์—์„œ ๊ธฐ๋ณธ ์†Œ์Šค์˜ .wasm ๋ชจ๋“ˆ์„ ์ง์ ‘ ์ŠคํŠธ๋ฆฌ๋ฐ ํ•œ ๋‹ค์Œ WebAssembly.Module ๊ฐ์ฒด๋กœ ์ปดํŒŒ์ผํ•ฉ๋‹ˆ๋‹ค. compileStreaming() ํ•จ์ˆ˜๋Š” Response ๊ฐ์ฒด์— ๋Œ€ํ•œ promise๋ฅผ ๋ฐ›์œผ๋ฏ€๋กœ ์ง์ ‘ fetch() ํ˜ธ์ถœ์„ ์ „๋‹ฌํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

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

WebAssembly.compileStreaming(fetch("simple.wasm"))
  .then((module) => WebAssembly.instantiate(module, importObject))
  .then((instance) => instance.exports.exported_func());

๊ฒฐ๊ณผ ๋ชจ๋“ˆ ์ธ์Šคํ„ด์Šค๋Š” WebAssembly.instantiate ()๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ธ์Šคํ„ด์Šคํ™”๋˜๊ณ  ๋‚ด ๋ณด๋‚ธ ํ•จ์ˆ˜๊ฐ€ ํ˜ธ์ถœ๋ฉ๋‹ˆ๋‹ค.

๋ช…์„ธ์„œ

Specification
WebAssembly Web API
# dom-webassembly-compilestreaming

๋ธŒ๋ผ์šฐ์ € ํ˜ธํ™˜์„ฑ

See also