add system random to stdlib: std/sysrand (#16459)

This commit is contained in:
flywind 2021-02-11 18:00:01 -06:00 • committed by GitHub
commit 18c24eb4d0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 333 additions and 0 deletions

View file

@ -5,14 +5,20 @@ when defined(js):
ArrayBuffer* = ref object of JsRoot
Float64Array* = ref object of JsRoot
Uint32Array* = ref object of JsRoot
Uint8Array* = ref object of JsRoot
BigUint64Array* = ref object of JsRoot
func newArrayBuffer*(n: int): ArrayBuffer {.importjs: "new ArrayBuffer(#)".}
func newFloat64Array*(buffer: ArrayBuffer): Float64Array {.importjs: "new Float64Array(#)".}
func newUint32Array*(buffer: ArrayBuffer): Uint32Array {.importjs: "new Uint32Array(#)".}
func newBigUint64Array*(buffer: ArrayBuffer): BigUint64Array {.importjs: "new BigUint64Array(#)".}
func newUint8Array*(n: int): Uint8Array {.importjs: "new Uint8Array(#)".}
func `[]`*(arr: Uint32Array, i: int): uint32 {.importjs: "#[#]".}
func `[]`*(arr: Uint8Array, i: int): uint8 {.importjs: "#[#]".}
func `[]`*(arr: BigUint64Array, i: int): JsBigInt {.importjs: "#[#]".}
func `[]=`*(arr: Float64Array, i: int, v: float) {.importjs: "#[#] = #".}