about summary refs log tree commit diff stats
path: root/src/html
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-08-20 16:01:06 +0200
committerbptato <nincsnevem662@gmail.com>2023-08-20 16:50:46 +0200
commit230ad7876ed5f8f26dce02db0e3528a5539150f4 (patch)
treea6051dfaeb43ad45e6f92e171328fcf1d5580922 /src/html
parent65ad7f9fc8b69140c050006fbe9ea1644bc283d8 (diff)
downloadchawan-230ad7876ed5f8f26dce02db0e3528a5539150f4.tar.gz
javascript: finish LegacyUnforgeable + misc fixes
Add jsuffget, jsuffunc for setting LegacyUnforgeable on functions.

Misc fixes:
* define LegacyUnforgeable properties for native object shims
* replace some macros with templates
Diffstat (limited to 'src/html')
-rw-r--r--src/html/dom.nim26
-rw-r--r--src/html/env.nim4
2 files changed, 16 insertions, 14 deletions
diff --git a/src/html/dom.nim b/src/html/dom.nim
index 89fd7748..b33cbd19 100644
--- a/src/html/dom.nim
+++ b/src/html/dom.nim
@@ -92,7 +92,7 @@ type
     location* {.jsget.}: Location
     jsrt*: JSRuntime
     jsctx*: JSContext
-    document* {.jsget.}: Document
+    document* {.jsufget.}: Document
     timeouts*: TimeoutState[int]
     navigate*: proc(url: URL)
 
@@ -1179,7 +1179,7 @@ proc setLocation*(document: Document, s: string): Err[DOMException]
 
 # Note: we do not implement security checks (as documents are in separate
 # windows anyway).
-func href(location: Location): string {.jsfget.} =
+func href(location: Location): string {.jsuffget.} =
   return location.url.serialize()
 
 proc setHref(location: Location, s: string): Err[DOMException]
@@ -1188,21 +1188,21 @@ proc setHref(location: Location, s: string): Err[DOMException]
     return ok()
   return location.document.setLocation(s)
 
-proc assign(location: Location, s: string): Err[DOMException] {.jsfunc.} =
+proc assign(location: Location, s: string): Err[DOMException] {.jsuffunc.} =
   location.setHref(s)
 
-proc replace(location: Location, s: string): Err[DOMException] {.jsfunc.} =
+proc replace(location: Location, s: string): Err[DOMException] {.jsuffunc.} =
   location.setHref(s)
 
-proc reload(location: Location) {.jsfunc.} =
+proc reload(location: Location) {.jsuffunc.} =
   if location.document == nil:
     return
   location.document.window.navigate(location.url)
 
-func origin(location: Location): string {.jsfget.} =
+func origin(location: Location): string {.jsuffget.} =
   return location.url.origin
 
-func protocol(location: Location): string {.jsfget.} =
+func protocol(location: Location): string {.jsuffget.} =
   return location.url.protocol
 
 proc protocol(location: Location, s: string): Err[DOMException] {.jsfset.} =
@@ -1216,7 +1216,7 @@ proc protocol(location: Location, s: string): Err[DOMException] {.jsfset.} =
   document.window.navigate(copyURL)
   return ok()
 
-func host(location: Location): string {.jsfget.} =
+func host(location: Location): string {.jsuffget.} =
   return location.url.host
 
 proc setHost(location: Location, s: string) {.jsfset: "host".} =
@@ -1227,7 +1227,7 @@ proc setHost(location: Location, s: string) {.jsfset: "host".} =
   copyURL.setHost(s)
   document.window.navigate(copyURL)
 
-proc hostname(location: Location): string {.jsfget.} =
+proc hostname(location: Location): string {.jsuffget.} =
   return location.url.hostname
 
 proc setHostname(location: Location, s: string) {.jsfset: "hostname".} =
@@ -1238,7 +1238,7 @@ proc setHostname(location: Location, s: string) {.jsfset: "hostname".} =
   copyURL.setHostname(s)
   document.window.navigate(copyURL)
 
-proc port(location: Location): string {.jsfget.} =
+proc port(location: Location): string {.jsuffget.} =
   return location.url.port
 
 proc setPort(location: Location, s: string) {.jsfset: "port".} =
@@ -1249,7 +1249,7 @@ proc setPort(location: Location, s: string) {.jsfset: "port".} =
   copyURL.setPort(s)
   document.window.navigate(copyURL)
 
-proc pathname(location: Location): string {.jsfget.} =
+proc pathname(location: Location): string {.jsuffget.} =
   return location.url.pathname
 
 proc setPathname(location: Location, s: string) {.jsfset: "pathname".} =
@@ -1260,7 +1260,7 @@ proc setPathname(location: Location, s: string) {.jsfset: "pathname".} =
   copyURL.setPathname(s)
   document.window.navigate(copyURL)
 
-proc search(location: Location): string {.jsfget.} =
+proc search(location: Location): string {.jsuffget.} =
   return location.url.search
 
 proc setSearch(location: Location, s: string) {.jsfset: "search".} =
@@ -1271,7 +1271,7 @@ proc setSearch(location: Location, s: string) {.jsfset: "search".} =
   copyURL.setSearch(s)
   document.window.navigate(copyURL)
 
-proc hash(location: Location): string {.jsfget.} =
+proc hash(location: Location): string {.jsuffget.} =
   return location.url.hash
 
 proc setHash(location: Location, s: string) {.jsfset: "hash".} =
diff --git a/src/html/env.nim b/src/html/env.nim
index 97f202f9..c38852d5 100644
--- a/src/html/env.nim
+++ b/src/html/env.nim
@@ -93,6 +93,9 @@ proc setLocation(window: Window, s: string): Err[DOMException]
     {.jsfset: "location".} =
   window.document.setLocation(s)
 
+proc getWindow(window: Window): Window {.jsuffget: "window".} =
+  return window
+
 proc addScripting*(window: Window, selector: Selector[int]) =
   let rt = newJSRuntime()
   let ctx = rt.newJSContext()
@@ -115,7 +118,6 @@ proc addScripting*(window: Window, selector: Selector[int]) =
   var global = JS_GetGlobalObject(ctx)
   ctx.registerType(Window, asglobal = true)
   ctx.setGlobal(global, window)
-  ctx.defineProperty(global, "window", global)
   JS_FreeValue(ctx, global)
   ctx.addDOMExceptionModule()
   ctx.addconsoleModule()
is code is slow and should not be used except in debugging * circumstances (don't define LY_FIND_LEAKS). * If you are using LY_FIND_LEAKS and don't want the LYLeak* * memory functions to be used in a certain file, * define NO_MEMORY_TRACKING before including this file. * The only safe way to call the LYLeak* functions is to use * the below macros because they depend on the static * string created by __FILE__ to not be dynamic in * nature (don't free it and assume will exist at all * times during execution). * Revision History: * 05-26-94 created for Lynx 2-3-1, Garrett Arch Blythe */ /* * Required includes */ #include <stdlib.h> #include "HTUtils.h" /* * Constant defines */ #define MAX_CONTENT_LENGTH 50 #ifdef VMS #define LEAKAGE_SINK "sys$login:Lynx.leaks" #else #define LEAKAGE_SINK "Lynx.leaks" #endif /* VMS */ /* * Data structures */ typedef struct SourceLocation_tag { /* * The file name and line number of where an event took place. */ CONST char *cp_FileName; short ssi_LineNumber; } SourceLocation; typedef struct AllocationList_tag { /* * A singly linked list. */ struct AllocationList_tag *ALp_Next; /* * The memory pointer allocated. * If set to NULL, then an invalid request was made. * The invalid pointer also. */ void *vp_Alloced; void *vp_BadRequest; /* * The size in bytes of the allocated memory. */ size_t st_Bytes; /* * The source location of specific event (calloc, malloc, free). * realloc kept separate since will track last realloc on pointer. */ SourceLocation SL_memory; SourceLocation SL_realloc; } AllocationList; /* * Global variable declarations */ /* * Macros */ #if defined(LY_FIND_LEAKS) && !defined(NO_MEMORY_TRACKING) /* * Only use these macros if we are to track memory allocations. * The reason for using a macro instead of a define is that we want * to track where the initial allocation took place or where * the last reallocation took place. * Track where the allocation took place by the __FILE__ and __LINE__ * defines which are automatic to the compiler. */ #ifdef malloc #undef malloc #endif /* malloc */ #define malloc(st_bytes) LYLeakMalloc(st_bytes, __FILE__, __LINE__) #ifdef calloc #undef calloc #endif /* calloc */ #define calloc(st_number, st_bytes) LYLeakCalloc(st_number, st_bytes, \ __FILE__, __LINE__) #ifdef realloc #undef realloc #endif /* realloc */ #define realloc(vp_alloced, st_newbytes) LYLeakRealloc(vp_alloced, \ st_newbytes, __FILE__, __LINE__) #ifdef free #undef free #endif /* free */ #define free(vp_alloced) LYLeakFree(vp_alloced, __FILE__, __LINE__) #endif /* LY_FIND_LEAKS && !NO_MEMORY_TRACKING */ /* * Function declarations * See the appropriate source file for usage. */ PUBLIC void LYLeaks NOPARAMS; PUBLIC void *LYLeakMalloc PARAMS((size_t st_bytes, CONST char *cp_File, CONST short ssi_Line)); PUBLIC void *LYLeakCalloc PARAMS((size_t st_number, size_t st_bytes, CONST char *cp_File, CONST short ssi_Line)); PUBLIC void *LYLeakRealloc PARAMS((void *vp_alloced, size_t st_newbytes, CONST char *cp_File, CONST short ssi_Line)); PUBLIC void LYLeakFree PARAMS((void *vp_alloced, CONST char *cp_File, CONST short ssi_Line)); #endif /* __LYLEAKS_H */