diff options
author | bptato <nincsnevem662@gmail.com> | 2022-12-18 20:46:30 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2022-12-18 20:46:30 +0100 |
commit | bfaf210d87e90016f8f2521657bd04686170aa43 (patch) | |
tree | e9711cb2f72174058d88ce2d52a76239e3c54c62 /src/types | |
parent | 1fbe17eeddefb87bf8e819be7792ae7a6482d8f8 (diff) | |
download | chawan-bfaf210d87e90016f8f2521657bd04686170aa43.tar.gz |
Add JS support to documents
Diffstat (limited to 'src/types')
-rw-r--r-- | src/types/mime.nim | 23 | ||||
-rw-r--r-- | src/types/url.nim | 8 |
2 files changed, 27 insertions, 4 deletions
diff --git a/src/types/mime.nim b/src/types/mime.nim index fb3f4b2c..2db567ad 100644 --- a/src/types/mime.nim +++ b/src/types/mime.nim @@ -1,3 +1,4 @@ +import algorithm import tables const DefaultGuess = [ @@ -26,3 +27,25 @@ proc guessContentType*(path: string): string = if ext in DefaultGuess: return DefaultGuess[ext] return DefaultGuess[""] + +const JavaScriptTypes = [ + "application/ecmascript", + "application/javascript", + "application/x-ecmascript", + "application/x-javascript", + "text/ecmascript", + "text/javascript", + "text/javascript1.0", + "text/javascript1.1", + "text/javascript1.2", + "text/javascript1.3", + "text/javascript1.4", + "text/javascript1.5", + "text/jscript", + "text/livescript", + "text/x-ecmascript", + "text/x-javascript" +] + +proc isJavaScriptType*(s: string): bool = + return binarySearch(JavaScriptTypes, s) != -1 diff --git a/src/types/url.nim b/src/types/url.nim index f0251fa8..4dbe24c7 100644 --- a/src/types/url.nim +++ b/src/types/url.nim @@ -967,14 +967,14 @@ proc newURL*(s: string, base: Option[string] = none(string)): URL {.jserr, jscto if base.issome: let baseUrl = parseUrl(base.get) if baseUrl.isnone: - JS_THROW JS_TypeError, base.get & " is not a valid URL" + JS_ERR JS_TypeError, base.get & " is not a valid URL" let url = parseUrl(s, baseUrl) if url.isnone: - JS_THROW JS_TypeError, s & " is not a valid URL" + JS_ERR JS_TypeError, s & " is not a valid URL" return url.get let url = parseUrl(s) if url.isnone: - JS_THROW JS_TypeError, s & " is not a valid URL" + JS_ERR JS_TypeError, s & " is not a valid URL" url.get.searchParams = newURLSearchParams() url.get.searchParams.url = url url.get.searchParams.initURLSearchParams(url.get.query.get("")) @@ -1093,6 +1093,6 @@ proc hash*(url: URL, s: string) {.jsfset.} = url.fragment = some("") discard basicParseUrl(s, url = url, stateOverride = some(FRAGMENT_STATE)) -proc addUrlModule*(ctx: JSContext) = +proc addURLModule*(ctx: JSContext) = ctx.registerType(URL) ctx.registerType(URLSearchParams) |