Skip to content

Commit 12739e6

Browse files
Add JSTypedArray(bufffer: UnsafeBufferPointer<UInt8>)
1 parent d361080 commit 12739e6

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Sources/JavaScriptKit/BasicObjects/JSTypedArray.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ public class JSTypedArray<Element>: JSBridgedClass, ExpressibleByArrayLiteral wh
5252
self.init(unsafelyWrapping: JSObject(id: jsArrayRef))
5353
}
5454

55+
/// Initialize a new instance of TypedArray in JavaScript environment with given buffer elements.
56+
///
57+
/// - Parameter buffer: The buffer that will be copied to create a new instance of TypedArray
58+
public convenience init(buffer: UnsafeBufferPointer<Element>) {
59+
let jsArrayRef = _create_typed_array(Self.constructor!.id, buffer.baseAddress!, Int32(buffer.count))
60+
self.init(unsafelyWrapping: JSObject(id: jsArrayRef))
61+
}
62+
5563
/// Convenience initializer for `Sequence`.
5664
public convenience init<S: Sequence>(_ sequence: S) where S.Element == Element {
5765
self.init(Array(sequence))

0 commit comments

Comments
 (0)