Element
JSTypedArray.swift:17typealias Element = Traits.Element
typealias Element = Traits.Element
import JavaScriptKit
Swift framework to interact with JavaScript through WebAssembly.
final class JSTypedArray<Traits> where Traits : TypedArrayElement
A wrapper around all JavaScript TypedArray
classes that exposes their properties in a type-safe way.
associatedtype Element : ConstructibleFromJSValue, ConvertibleToJSValue = Self
convenience init(_ array: [Element])
Initialize a new instance of TypedArray in JavaScript environment with given elements.
convenience init<S>(_ sequence: S) where S : Sequence, Traits.Element == S.Element
Convenience initializer for Sequence
.
required convenience init(arrayLiteral elements: Element...)
convenience init(buffer: UnsafeBufferPointer<Element>)
Initialize a new instance of TypedArray in JavaScript environment with given buffer contents.
init(length: Int)
Initialize a new instance of TypedArray in JavaScript environment with given length. All the elements will be initialized to zero.
required init(unsafelyWrapping jsObject: JSObject)
class var constructor: JSFunction? { get }
var jsObject: JSObject
var length: Int { get }
Length (in elements) of the typed array.
var lengthInBytes: Int { get }
Length (in bytes) of the typed array. The value is established when a TypedArray is constructed and cannot be changed. If the TypedArray is not specifying a byteOffset
or a length
, the length
of the referenced ArrayBuffer
will be returned.
subscript(index: Int) -> Element { get set }
func copyMemory(to buffer: UnsafeMutableBufferPointer<Element>)
Copies the contents of the array to the given buffer.
func withUnsafeBytes<R>(_ body: (UnsafeBufferPointer<Element>) throws -> R) rethrows -> R
Calls the given closure with a pointer to a copy of the underlying bytes of the array’s storage.
func withUnsafeBytesAsync<R>(_ body: (UnsafeBufferPointer<Element>) async throws -> R) async rethrows -> R
Calls the given async closure with a pointer to a copy of the underlying bytes of the array’s storage.