Import with #import "std/web".

WebValue :: struct { tag: s32; aux: s32; number: float64; }

A value crossing the boundary: a tag, a length or handle, and a number.

WebUndefinedTag :: 0
WebNullTag :: 1
WebBoolTag :: 2
WebNumberTag :: 3
WebTextTag :: 4
WebObjectTag :: 5
WebStringTag :: 6
WebGlobal :: 1
WebModule :: 2
WebBytesUint8 :: 0

The kinds of typed array WebBytes builds.

WebBytesUint8Clamped :: 1
WebBytesInt16 :: 2
WebBytesInt32 :: 3
WebBytesFloat32 :: 4
WebTypeUndefined :: 0

What WebTypeOf reports.

WebTypeNull :: 1
WebTypeBool :: 2
WebTypeNumber :: 3
WebTypeString :: 4
WebTypeObject :: 5
WebTypeFunction :: 6

Receives a JS function's first three arguments as handles that are valid

WebCallback :: #type (context: s32, first: s32, second: s32, third: s32)
web_failed: bool
WebName :: (text: string) -> s32

Interns a name for property and method access. Do this once per name.

WebUndefined :: () -> WebValue
WebNull :: () -> WebValue
WebBool :: (value: bool) -> WebValue
WebNumber :: (value: float64) -> WebValue
WebText :: (text: string) -> WebValue

The text is read while the call it is passed to runs, so it must stay alive until then.

WebObject :: (handle: s32) -> WebValue
WebAsNumber :: (value: WebValue) -> float64
WebAsBool :: (value: WebValue) -> bool
WebAsObject :: (value: WebValue) -> s32

The handle of an object or string result, or 0.

WebIsUndefined :: (value: WebValue) -> bool
WebFailed :: () -> bool

Whether the last property access, call, or construction threw. The exception is WebLastError.

WebLastError :: () -> s32
WebGet :: (object: s32, name: s32) -> WebValue
WebGetNumber :: (object: s32, name: s32) -> float64
WebGetObject :: (object: s32, name: s32) -> s32
WebSet :: (object: s32, name: s32, value: WebValue)
WebAt :: (object: s32, index: s32) -> WebValue
WebSetAt :: (object: s32, index: s32, value: WebValue)
WebCall :: (object: s32, name: s32, args: *WebValue, count: s32) -> WebValue
WebCall0 :: (object: s32, name: s32) -> WebValue
WebCall1 :: (object: s32, name: s32, a: WebValue) -> WebValue
WebCall2 :: (object: s32, name: s32, a: WebValue, b: WebValue) -> WebValue
WebCall3 :: (object: s32, name: s32, a: WebValue, b: WebValue, c: WebValue) -> WebValue
WebCall4 :: (object: s32, name: s32, a: WebValue, b: WebValue, c: WebValue, d: WebValue) -> WebValue
WebCall5 :: (object: s32, name: s32, a: WebValue, b: WebValue, c: WebValue, d: WebValue, e: WebValue) -> WebValue
WebCall6 :: (object: s32, name: s32, a: WebValue, b: WebValue, c: WebValue, d: WebValue, e: WebValue, f: WebValue) -> WebValue
WebCall8 :: (object: s32, name: s32, a: WebValue, b: WebValue, c: WebValue, d: WebValue, e: WebValue, f: WebValue, g: WebValue, h: WebValue) -> WebValue
WebNew :: (constructor: s32, args: *WebValue, count: s32) -> s32

Constructs `new constructor(args...)`; returns the new object's handle.

WebNew0 :: (constructor: s32) -> s32
WebNew1 :: (constructor: s32, a: WebValue) -> s32
WebNew2 :: (constructor: s32, a: WebValue, b: WebValue) -> s32
WebNew3 :: (constructor: s32, a: WebValue, b: WebValue, c: WebValue) -> s32
WebValueOf :: (handle: s32) -> WebValue

The value a handle holds, such as the number a callback argument carries.

WebNewObject :: () -> s32
WebNewArray :: () -> s32
WebRelease :: (handle: s32)

Frees a handle made by WebKeep or WebFunction. Temporary handles need no release.

WebScope :: () -> s32

Starts a scope; WebEnd(mark) frees every temporary handle made since.

WebEnd :: (mark: s32)
WebKeep :: (handle: s32) -> s32

A handle to the same object that lasts until WebRelease, unlike the temporary one it came from.

WebLiveHandles :: () -> s32

How many handles are live, for checking a program does not leak them.

WebTypeOf :: (handle: s32) -> s32
WebInstanceOf :: (handle: s32, constructor: s32) -> bool
WebFunction :: (callback: WebCallback, context: s32) -> s32

A JS function that runs `callback` with `context` and up to three argument handles, kept until released.

WebStringLength :: (handle: s32) -> s32

The length in bytes of a string handle's text.

WebCopyString :: (handle: s32, buffer: []u8) -> s32

Copies a string handle's text into `buffer`, NUL-terminated, and returns its length in bytes.

WebBytes :: (kind: s32, data: *void, count: s32) -> s32

A typed array holding a copy of `count` elements from `data`.

WebBlobBytes :: (data: *void, count: s32) -> s32

A Blob snapshot of `count` bytes from `data`, or 0 for an invalid range. The browser snapshots the Wasm view within this one host call: callers may change/free the source or grow memory as soon as this returns. This avoids the extra encoded-byte copy of WebBytes followed by a Blob constructor. Useful for files, downloads, media and request bodies; MIME may be supplied later with the ordinary Blob.slice API. WebBytes keeps its copy semantics.

WebCopyOut :: (handle: s32, data: *void, capacity: s32) -> s32

Copies a typed array's bytes into `data`, at most `capacity`; returns the number copied.

WebCopyIn :: (handle: s32, data: *void, length: s32) -> s32

Copies `length` bytes from `data` over the start of a typed array.

WebAwait :: (promise: s32, result: *WebValue) -> bool

Suspends until the promise settles. Returns whether it resolved, with its value in `result`.

WebSleep :: (milliseconds: s32)
WebNextFrame :: (minimum_delay: float64)

Suspends until the browser draws its next frame, and at least `minimum_delay` milliseconds have passed.

Source ↗ · All modules