aboutsummaryrefslogtreecommitdiffstats
path: root/src/html
diff options
context:
space:
mode:
Diffstat (limited to 'src/html')
-rw-r--r--src/html/dom.nim1
-rw-r--r--src/html/env.nim6
-rw-r--r--src/html/formdata.nim19
3 files changed, 13 insertions, 13 deletions
diff --git a/src/html/dom.nim b/src/html/dom.nim
index 274d401f..37c9f951 100644
--- a/src/html/dom.nim
+++ b/src/html/dom.nim
@@ -105,6 +105,7 @@ type
imageId: int
# list of streams that must be closed for canvas rendering on load
pendingCanvasCtls*: seq[CanvasRenderingContext2D]
+ urandom*: PosixStream
# Navigator stuff
Navigator* = object
diff --git a/src/html/env.nim b/src/html/env.nim
index d0c77b46..f3292504 100644
--- a/src/html/env.nim
+++ b/src/html/env.nim
@@ -331,7 +331,8 @@ proc runJSJobs*(window: Window) =
ctx.writeException(window.console.err)
proc newWindow*(scripting, images, styling: bool; attrs: WindowAttributes;
- factory: CAtomFactory; loader: FileLoader; url: URL): Window =
+ factory: CAtomFactory; loader: FileLoader; url: URL; urandom: PosixStream):
+ Window =
let err = newDynFileStream(stderr)
let window = Window(
attrs: attrs,
@@ -344,7 +345,8 @@ proc newWindow*(scripting, images, styling: bool; attrs: WindowAttributes;
scripting: scripting,
origin: url.origin
),
- factory: factory
+ factory: factory,
+ urandom: urandom
)
window.location = window.newLocation()
if scripting:
diff --git a/src/html/formdata.nim b/src/html/formdata.nim
index f6a7451b..808609d4 100644
--- a/src/html/formdata.nim
+++ b/src/html/formdata.nim
@@ -15,23 +15,20 @@ import utils/twtstr
proc constructEntryList*(form: HTMLFormElement; submitter: Element = nil;
encoding = "UTF-8"): seq[FormDataEntry]
-var urandom* {.global.}: PosixStream
-
-proc generateBoundary(): string =
+proc generateBoundary(urandom: PosixStream): string =
var s: array[33, uint8]
urandom.recvDataLoop(s)
# 33 * 4 / 3 = 44 + prefix string is 22 bytes = 66 bytes
return "----WebKitFormBoundary" & btoa(s)
-proc newFormData0*(): FormData =
- return FormData(boundary: generateBoundary())
-
-proc newFormData0*(entries: seq[FormDataEntry]): FormData =
- return FormData(boundary: generateBoundary(), entries: entries)
+proc newFormData0*(entries: seq[FormDataEntry]; urandom: PosixStream):
+ FormData =
+ return FormData(boundary: urandom.generateBoundary(), entries: entries)
-proc newFormData(form: HTMLFormElement = nil; submitter: HTMLElement = nil):
- DOMResult[FormData] {.jsctor.} =
- let this = newFormData0()
+proc newFormData(ctx: JSContext; form: HTMLFormElement = nil;
+ submitter: HTMLElement = nil): DOMResult[FormData] {.jsctor.} =
+ let urandom = ctx.getGlobal().urandom
+ let this = FormData(boundary: urandom.generateBoundary())
if form != nil:
if submitter != nil:
if not submitter.isSubmitButton():