summary refs log tree commit diff stats
path: root/lib/std
diff options
context:
space:
mode:
authorflywind <43030857+xflywind@users.noreply.github.com>2021-01-19 07:57:16 -0600
committerGitHub <noreply@github.com>2021-01-19 14:57:16 +0100
commita0fddfecd438d29ee7acc76333d966911adcedbb (patch)
treeb3c76f21a09348465d3d6131549a2317b69b0d14 /lib/std
parent0300203e811e7ecff4a7ec9bbb087ec946bbf1f2 (diff)
downloadNim-a0fddfecd438d29ee7acc76333d966911adcedbb.tar.gz
perpare for more compact bit operations in JS (#16728)
Diffstat (limited to 'lib/std')
-rw-r--r--lib/std/private/jsutils.nim12
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/std/private/jsutils.nim b/lib/std/private/jsutils.nim
new file mode 100644
index 000000000..cc463ac74
--- /dev/null
+++ b/lib/std/private/jsutils.nim
@@ -0,0 +1,12 @@
+when defined(js):
+  type
+    ArrayBuffer* = ref object of JsRoot
+    Float64Array* = ref object of JsRoot
+    Uint32Array* = 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 `[]`*(arr: Uint32Array, i: int): uint32 {.importjs: "#[#]".}
+  func `[]=`*(arr: Float64Array, i: int, v: float) {.importjs: "#[#] = #".}