mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 23:23:28 +00:00
wpt: load script soruce file dynamically
This commit is contained in:
@@ -82,7 +82,7 @@ pub fn main() !void {
|
|||||||
defer vm.deinit();
|
defer vm.deinit();
|
||||||
|
|
||||||
// prepare libraries to load on each test case.
|
// prepare libraries to load on each test case.
|
||||||
var loader = FileLoader.init(alloc, "tests/wpt");
|
var loader = FileLoader.init(alloc, wpt_dir);
|
||||||
defer loader.deinit();
|
defer loader.deinit();
|
||||||
|
|
||||||
// browse the dir to get the tests dynamically.
|
// browse the dir to get the tests dynamically.
|
||||||
@@ -160,6 +160,8 @@ fn runWPT(arena: *std.heap.ArenaAllocator, comptime apis: []jsruntime.API, f: []
|
|||||||
const html_doc = try parser.documentHTMLParseFromFileAlloc(alloc, f);
|
const html_doc = try parser.documentHTMLParseFromFileAlloc(alloc, f);
|
||||||
const doc = parser.documentHTMLToDocument(html_doc);
|
const doc = parser.documentHTMLToDocument(html_doc);
|
||||||
|
|
||||||
|
const dirname = std.fs.path.dirname(f[wpt_dir.len..]) orelse unreachable;
|
||||||
|
|
||||||
// create JS env
|
// create JS env
|
||||||
var loop = try Loop.init(alloc);
|
var loop = try Loop.init(alloc);
|
||||||
defer loop.deinit();
|
defer loop.deinit();
|
||||||
@@ -207,23 +209,28 @@ fn runWPT(arena: *std.heap.ArenaAllocator, comptime apis: []jsruntime.API, f: []
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO load <script src> attributes instead of the static list.
|
|
||||||
res = try evalJS(js_env, alloc, try loader.get("/resources/testharness.js"), "testharness.js");
|
|
||||||
if (!res.success) {
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
res = try evalJS(js_env, alloc, try loader.get("/resources/testharnessreport.js"), "testharnessreport.js");
|
|
||||||
if (!res.success) {
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
// loop hover the scripts.
|
// loop hover the scripts.
|
||||||
const scripts = parser.documentGetElementsByTagName(doc, "script");
|
const scripts = parser.documentGetElementsByTagName(doc, "script");
|
||||||
const slen = parser.nodeListLength(scripts);
|
const slen = parser.nodeListLength(scripts);
|
||||||
for (0..slen) |i| {
|
for (0..slen) |i| {
|
||||||
const s = parser.nodeListItem(scripts, @intCast(i)).?;
|
const s = parser.nodeListItem(scripts, @intCast(i)).?;
|
||||||
|
|
||||||
const src = parser.nodeTextContent(s).?;
|
// If the script contains an src attribute, load it.
|
||||||
|
if (parser.elementGetAttribute(@as(*parser.Element, @ptrCast(s)), "src")) |src| {
|
||||||
|
var path = src;
|
||||||
|
if (!std.mem.startsWith(u8, src, "/")) {
|
||||||
|
// no need to free path, thanks to the arena.
|
||||||
|
path = try std.fs.path.join(alloc, &.{ "/", dirname, path });
|
||||||
|
}
|
||||||
|
|
||||||
|
res = try evalJS(js_env, alloc, try loader.get(path), src);
|
||||||
|
if (!res.success) {
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the script as a source text, execute it.
|
||||||
|
const src = parser.nodeTextContent(s) orelse continue;
|
||||||
res = try evalJS(js_env, alloc, src, "");
|
res = try evalJS(js_env, alloc, src, "");
|
||||||
|
|
||||||
// return the first failure.
|
// return the first failure.
|
||||||
|
|||||||
Reference in New Issue
Block a user