[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ko/docs/WebAssembly/Reference/JavaScript_interface/Global [Back]  [Original]

WebAssembly.Global - | MDN

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.Global

Baseline Widely available

This feature is well established and works across many devices and browser versions. Its been available across browsers since 2020 3.

WebAssembly.Global JavaScript WebAssembly.Module . .

In this article

WebAssembly.Global()

Global .

Global Global() . Global .

Global.prototype.constructor

. WebAssembly.Global() .

Global.prototype[@@toStringTag]

@@toStringTag "WebAssembly.Global" .

Global.prototype.value

- .

Global.prototype.valueOf()

.

Examples

WebAssembly.Global() . 0 i32 .

Global.value '42' , global.wasm incGlobal() 43 . ( 1 ).

js
const output = document.getElementById("output");

function assertEq(msg, got, expected) {
  output.innerHTML += `Testing ${msg}: `;
  if (got !== expected)
    output.innerHTML += `FAIL!<br>Got: ${got}<br>Expected: ${expected}<br>`;
  else output.innerHTML += `SUCCESS! Got: ${got}<br>`;
}

assertEq("WebAssembly.Global exists", typeof WebAssembly.Global, "function");

const global = new WebAssembly.Global({ value: "i32", mutable: true }, 0);

WebAssembly.instantiateStreaming(fetch("global.wasm"), { js: { global } }).then(
  ({ instance }) => {
    assertEq(
      "getting initial value from wasm",
      instance.exports.getGlobal(),
      0,
    );
    global.value = 42;
    assertEq(
      "getting JS-updated value from wasm",
      instance.exports.getGlobal(),
      42,
    );
    instance.exports.incGlobal();
    assertEq("getting wasm-updated value from JS", global.value, 43);
  },
);

Specification
WebAssembly JavaScript Interface
# globals

See also


Web Proxy Viewer  |  New URL  |  Original Page