about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-11-22 20:18:53 +0100
committerbptato <nincsnevem662@gmail.com>2024-11-22 20:24:54 +0100
commit6e7cae47b2037860f53d4ae90d37a91d8b29906b (patch)
treedb8966bced3b74e25dd4c2bf824d130fee41be7c
parent7d549f10ba356486201645ae11fc4796ef5a4441 (diff)
downloadchawan-6e7cae47b2037860f53d4ae90d37a91d8b29906b.tar.gz
dom: implement HTMLDocument, make Image C/W
* add HTMLDocument as alias to Document
* set Image as configurable/writable

So looking closer, HTMLDocument *is* specified, just major browsers
don't follow the spec.

I doubt this incompatibility causes issues, anyway.
-rw-r--r--src/html/dom.nim4
-rw-r--r--test/js/document.html9
-rw-r--r--test/js/window.html4
3 files changed, 12 insertions, 5 deletions
diff --git a/src/html/dom.nim b/src/html/dom.nim
index b7ecffe0..70a9277c 100644
--- a/src/html/dom.nim
+++ b/src/html/dom.nim
@@ -4995,7 +4995,9 @@ return x;
 """)
   doAssert JS_SetConstructorBit(ctx, imageFun, true)
   let jsWindow = JS_GetGlobalObject(ctx)
-  ctx.defineProperty(jsWindow, "Image", imageFun)
+  ctx.definePropertyCW(jsWindow, "Image", imageFun)
+  ctx.definePropertyCW(jsWindow, "HTMLDocument",
+    JS_GetPropertyStr(ctx, jsWindow, "Document"))
   JS_FreeValue(ctx, jsWindow)
 
 # Forward declaration hack
diff --git a/test/js/document.html b/test/js/document.html
index 1020283c..10ecf17d 100644
--- a/test/js/document.html
+++ b/test/js/document.html
@@ -12,10 +12,11 @@ assertEquals(document.toString, document.getElementById("toString"));
 document.toString.remove();
 document.testtest = "hi";
 assertEquals(Object.getOwnPropertyNames(document).toString(), "testtest,location,img2,img3,asdf");
-// the spec doesn't have HTMLDocument, but browsers do.
-//TODO: we'll probably have to implement HTMLDocument ourselves too
-// nonetheless.
-if (!window.HTMLDocument)
+/*
+ * Note: the spec says Document == HTMLDocument, but in other browsers
+ * this is not true.
+ */
+if (HTMLDocument == Document)
 	assertEquals(document.toString(), "[object Document]");
 assertEquals(document, window.document);
 assertEquals(document.implementation, document.implementation);
diff --git a/test/js/window.html b/test/js/window.html
index 81485cad..06729e0e 100644
--- a/test/js/window.html
+++ b/test/js/window.html
@@ -15,5 +15,9 @@ delete window.localStorage.b;
 assertEquals(window.localStorage["b"], undefined);
 window.localStorage["b"] = "y";
 assert(window.sessionStorage instanceof Storage);
+Image = "test";
+HTMLDocument = "test";
+assertEquals(Image, "test");
+assertEquals(HTMLDocument, "test");
 document.getElementById("x").textContent = "Success";
 </script>