about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--src/html/env.nim2
-rw-r--r--src/html/event.nim2
-rw-r--r--src/js/arraybuffer.nim18
-rw-r--r--src/js/base64.nim2
-rw-r--r--src/js/dict.nim5
-rw-r--r--src/js/encoding.nim3
-rw-r--r--src/js/fromjs.nim12
-rw-r--r--src/js/intl.nim2
-rw-r--r--src/js/jstypes.nim32
-rw-r--r--src/js/strings.nim3
-rw-r--r--src/js/tojs.nim12
-rw-r--r--src/loader/request.nim2
-rw-r--r--src/local/client.nim2
-rw-r--r--src/local/container.nim2
-rw-r--r--src/local/pager.nim2
-rw-r--r--src/types/blob.nim2
16 files changed, 52 insertions, 51 deletions
diff --git a/src/html/env.nim b/src/html/env.nim
index 43a40508..f462c347 100644
--- a/src/html/env.nim
+++ b/src/html/env.nim
@@ -15,7 +15,7 @@ import js/encoding
 import js/error
 import js/intl
 import js/javascript
-import js/strings
+import js/jstypes
 import js/timeout
 import loader/headers
 import loader/loader
diff --git a/src/html/event.nim b/src/html/event.nim
index 8a5c6edc..4eb389f9 100644
--- a/src/html/event.nim
+++ b/src/html/event.nim
@@ -2,10 +2,10 @@ import std/math
 import std/times
 
 import bindings/quickjs
-import js/dict
 import js/error
 import js/fromjs
 import js/javascript
+import js/jstypes
 import js/tojs
 import types/opt
 
diff --git a/src/js/arraybuffer.nim b/src/js/arraybuffer.nim
deleted file mode 100644
index ff9fa24d..00000000
--- a/src/js/arraybuffer.nim
+++ /dev/null
@@ -1,18 +0,0 @@
-import bindings/quickjs
-
-type
-  JSArrayBuffer* = object
-    p*: ptr UncheckedArray[uint8]
-    len*: csize_t
-    dealloc*: JSFreeArrayBufferDataFunc
-
-  JSArrayBufferView* = object
-    abuf*: JSArrayBuffer
-    offset*: csize_t # offset into the buffer
-    nmemb*: csize_t # number of members
-    nsize*: csize_t # member size
-
-  JSUint8Array* = object
-    abuf*: JSArrayBuffer
-    offset*: csize_t # offset into the buffer
-    nmemb*: csize_t # number of members
diff --git a/src/js/base64.nim b/src/js/base64.nim
index 912843b4..f72131c3 100644
--- a/src/js/base64.nim
+++ b/src/js/base64.nim
@@ -3,7 +3,7 @@ import std/base64
 import bindings/quickjs
 import js/domexception
 import js/javascript
-import js/strings
+import js/jstypes
 import types/opt
 
 # atob and btoa convert Latin-1 to base64 and vice versa. (And throw on
diff --git a/src/js/dict.nim b/src/js/dict.nim
deleted file mode 100644
index 5003b92c..00000000
--- a/src/js/dict.nim
+++ /dev/null
@@ -1,5 +0,0 @@
-# This is the WebIDL dictionary type.
-# We only use it for type inference in generics.
-#TODO required members
-
-type JSDict* = object of RootObj
diff --git a/src/js/encoding.nim b/src/js/encoding.nim
index 31f6f575..0e6643fb 100644
--- a/src/js/encoding.nim
+++ b/src/js/encoding.nim
@@ -1,9 +1,8 @@
 import std/streams
 
-import js/arraybuffer
-import js/dict
 import js/error
 import js/javascript
+import js/jstypes
 
 import chakasu/charset
 import chakasu/decoderstream
diff --git a/src/js/fromjs.nim b/src/js/fromjs.nim
index cf3abc6d..d7f34905 100644
--- a/src/js/fromjs.nim
+++ b/src/js/fromjs.nim
@@ -6,9 +6,8 @@ import std/unicode
 
 import bindings/quickjs
 import io/promise
-import js/arraybuffer
-import js/dict
 import js/error
+import js/jstypes
 import js/opaque
 import js/tojs
 import types/opt
@@ -115,12 +114,11 @@ func fromJSInt[T: SomeInteger](ctx: JSContext, val: JSValue):
       return err()
     return ok(cast[uint64](ret))
 
-proc fromJSFloat[T: SomeFloat](ctx: JSContext, val: JSValue):
-    JSResult[T] =
+proc fromJSFloat64(ctx: JSContext, val: JSValue): JSResult[float64] =
   var f64: float64
   if JS_ToFloat64(ctx, addr f64, val) < 0:
     return err()
-  return ok(cast[T](f64))
+  return ok(f64)
 
 macro fromJSTupleBody(a: tuple) =
   let len = a.getType().len - 1
@@ -499,8 +497,8 @@ proc fromJS*[T](ctx: JSContext, val: JSValue): JSResult[T] =
       typeof(result.get.values)](ctx, val)
   elif T is SomeInteger:
     return fromJSInt[T](ctx, val)
-  elif T is SomeFloat:
-    return fromJSFloat[T](ctx, val)
+  elif T is float64:
+    return fromJSFloat64(ctx, val)
   elif T is enum:
     return fromJSEnum[T](ctx, val)
   elif T is JSValue:
diff --git a/src/js/intl.nim b/src/js/intl.nim
index 285a2b4e..9e17edf3 100644
--- a/src/js/intl.nim
+++ b/src/js/intl.nim
@@ -1,8 +1,8 @@
 # Very minimal Intl module... TODO make it more complete
 
 import bindings/quickjs
-import js/dict
 import js/javascript
+import js/jstypes
 import js/tojs
 
 type
diff --git a/src/js/jstypes.nim b/src/js/jstypes.nim
new file mode 100644
index 00000000..b8ef6c55
--- /dev/null
+++ b/src/js/jstypes.nim
@@ -0,0 +1,32 @@
+import bindings/quickjs
+
+# This is the WebIDL dictionary type.
+# We only use it for type inference in generics.
+#TODO required members
+type JSDict* = object of RootObj
+
+# Containers compatible with the internal representation of strings in QuickJS.
+# To convert these, a copy is still needed; however, they remove the UTF-8
+# transcoding step.
+type
+  NarrowString* = distinct string
+  WideString* = distinct seq[uint16]
+
+# Various containers for array buffer types.
+# Converting these only requires copying the metadata; buffers are never copied.
+type
+  JSArrayBuffer* = object
+    p*: ptr UncheckedArray[uint8]
+    len*: csize_t
+    dealloc*: JSFreeArrayBufferDataFunc
+
+  JSArrayBufferView* = object
+    abuf*: JSArrayBuffer
+    offset*: csize_t # offset into the buffer
+    nmemb*: csize_t # number of members
+    nsize*: csize_t # member size
+
+  JSUint8Array* = object
+    abuf*: JSArrayBuffer
+    offset*: csize_t # offset into the buffer
+    nmemb*: csize_t # number of members
diff --git a/src/js/strings.nim b/src/js/strings.nim
deleted file mode 100644
index ab0dd753..00000000
--- a/src/js/strings.nim
+++ /dev/null
@@ -1,3 +0,0 @@
-type
-  NarrowString* = distinct string
-  WideString* = distinct seq[uint16]
diff --git a/src/js/tojs.nim b/src/js/tojs.nim
index 91b1128e..2936ba28 100644
--- a/src/js/tojs.nim
+++ b/src/js/tojs.nim
@@ -13,7 +13,7 @@
 # * JSArrayBuffer, JSUint8Array are converted to a JS object without copying
 #   their contents.
 # * NarrowString is converted to a JS narrow string (with copying). For more
-#   information on JS string handling, see js/strings.nim.
+#   information on JS string handling, see js/jstypes.nim.
 # * Finally, ref object is converted to a JS object whose opaque is the ref
 #   object. (See below.)
 #
@@ -42,11 +42,9 @@ import std/unicode
 
 import bindings/quickjs
 import io/promise
-import js/arraybuffer
-import js/dict
 import js/error
+import js/jstypes
 import js/opaque
-import js/strings
 import js/typeptr
 import types/opt
 
@@ -60,7 +58,7 @@ proc toJS*(ctx: JSContext, n: int): JSValue
 proc toJS*(ctx: JSContext, n: uint16): JSValue
 proc toJS*(ctx: JSContext, n: uint32): JSValue
 proc toJS*(ctx: JSContext, n: uint64): JSValue
-proc toJS*(ctx: JSContext, n: SomeFloat): JSValue
+proc toJS*(ctx: JSContext, n: float64): JSValue
 proc toJS*(ctx: JSContext, b: bool): JSValue
 proc toJS*[U, V](ctx: JSContext, t: Table[U, V]): JSValue
 proc toJS*(ctx: JSContext, opt: Option): JSValue
@@ -158,8 +156,8 @@ proc toJS*(ctx: JSContext, n: uint64): JSValue =
   #TODO this is incorrect
   return JS_NewFloat64(ctx, float64(n))
 
-proc toJS*(ctx: JSContext, n: SomeFloat): JSValue =
-  return JS_NewFloat64(ctx, float64(n))
+proc toJS*(ctx: JSContext, n: float64): JSValue =
+  return JS_NewFloat64(ctx, n)
 
 proc toJS*(ctx: JSContext, b: bool): JSValue =
   return JS_NewBool(ctx, b)
diff --git a/src/loader/request.nim b/src/loader/request.nim
index 1182ca1b..a91731bb 100644
--- a/src/loader/request.nim
+++ b/src/loader/request.nim
@@ -4,10 +4,10 @@ import std/strutils
 import std/tables
 
 import bindings/quickjs
-import js/dict
 import js/error
 import js/fromjs
 import js/javascript
+import js/jstypes
 import loader/headers
 import types/blob
 import types/formdata
diff --git a/src/local/client.nim b/src/local/client.nim
index b2784e1a..ea3ef72a 100644
--- a/src/local/client.nim
+++ b/src/local/client.nim
@@ -34,8 +34,8 @@ import js/error
 import js/fromjs
 import js/intl
 import js/javascript
+import js/jstypes
 import js/module
-import js/strings
 import js/timeout
 import js/tojs
 import loader/headers
diff --git a/src/local/container.nim b/src/local/container.nim
index f010b988..83ba16f0 100644
--- a/src/local/container.nim
+++ b/src/local/container.nim
@@ -11,8 +11,8 @@ import display/winattrs
 import extern/stdio
 import io/promise
 import io/serialize
-import js/dict
 import js/javascript
+import js/jstypes
 import js/regex
 import loader/connecterror
 import loader/request
diff --git a/src/local/pager.nim b/src/local/pager.nim
index 31439443..254c074e 100644
--- a/src/local/pager.nim
+++ b/src/local/pager.nim
@@ -22,8 +22,8 @@ import extern/runproc
 import extern/tempfile
 import io/promise
 import io/socketstream
-import js/dict
 import js/javascript
+import js/jstypes
 import js/regex
 import js/tojs
 import loader/loader
diff --git a/src/types/blob.nim b/src/types/blob.nim
index 5da7317d..63fb5b84 100644
--- a/src/types/blob.nim
+++ b/src/types/blob.nim
@@ -2,9 +2,9 @@ import std/options
 import std/os
 import std/strutils
 
-import js/dict
 import js/fromjs
 import js/javascript
+import js/jstypes
 import utils/mimeguess
 import utils/twtstr