Alias global as self and window

Signed-off-by: Francis Bouvier <francis.bouvier@gmail.com>
This commit is contained in:
Francis Bouvier
2023-10-10 14:49:57 +02:00
parent 65b1a76f00
commit 28b1bee241
4 changed files with 13 additions and 1 deletions

View File

@@ -20,6 +20,10 @@ fn execJS(
js_env.start(apis);
defer js_env.stop();
// alias global as self and window
try js_env.attachObject(try js_env.getGlobal(), "self", null);
try js_env.attachObject(try js_env.getGlobal(), "window", null);
// add document object
try js_env.addObject(apis, doc, "document");

View File

@@ -19,6 +19,10 @@ fn execJS(
js_env.start(apis);
defer js_env.stop();
// alias global as self and window
try js_env.attachObject(try js_env.getGlobal(), "self", null);
try js_env.attachObject(try js_env.getGlobal(), "window", null);
// add document object
try js_env.addObject(apis, doc, "document");

View File

@@ -23,6 +23,10 @@ fn testExecFn(
js_env.start(apis);
defer js_env.stop();
// alias global as self and window
try js_env.attachObject(try js_env.getGlobal(), "self", null);
try js_env.attachObject(try js_env.getGlobal(), "window", null);
// document
doc = try parser.documentHTMLParseFromFileAlloc(std.testing.allocator, "test.html");
defer parser.documentHTMLClose(doc);