mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 15:13:28 +00:00
wpt: refacto js eval
This commit is contained in:
@@ -178,7 +178,8 @@ fn runWPT(arena: *std.heap.ArenaAllocator, f: []const u8, loader: *FileLoader) !
|
|||||||
try js_env.attachObject(try js_env.getGlobal(), "self", null);
|
try js_env.attachObject(try js_env.getGlobal(), "self", null);
|
||||||
try js_env.attachObject(try js_env.getGlobal(), "window", null);
|
try js_env.attachObject(try js_env.getGlobal(), "window", null);
|
||||||
|
|
||||||
var res = jsruntime.JSResult{};
|
// thanks to the arena, we don't need to deinit res.
|
||||||
|
var res: jsruntime.JSResult = undefined;
|
||||||
|
|
||||||
const init =
|
const init =
|
||||||
\\window.listeners = [];
|
\\window.listeners = [];
|
||||||
@@ -198,17 +199,17 @@ fn runWPT(arena: *std.heap.ArenaAllocator, f: []const u8, loader: *FileLoader) !
|
|||||||
\\};
|
\\};
|
||||||
\\window.removeEventListener = function () {};
|
\\window.removeEventListener = function () {};
|
||||||
;
|
;
|
||||||
try js_env.run(alloc, init, "init", &res, null);
|
res = try evalJS(js_env, alloc, init, "init");
|
||||||
if (!res.success) {
|
if (!res.success) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO load <script src> attributes instead of the static list.
|
// TODO load <script src> attributes instead of the static list.
|
||||||
try js_env.run(alloc, try loader.get("/resources/testharness.js"), "testharness.js", &res, null);
|
res = try evalJS(js_env, alloc, try loader.get("/resources/testharness.js"), "testharness.js");
|
||||||
if (!res.success) {
|
if (!res.success) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
try js_env.run(alloc, try loader.get("/resources/testharnessreport.js"), "testharnessreport.js", &res, null);
|
res = try evalJS(js_env, alloc, try loader.get("/resources/testharnessreport.js"), "testharnessreport.js");
|
||||||
if (!res.success) {
|
if (!res.success) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@@ -220,7 +221,7 @@ fn runWPT(arena: *std.heap.ArenaAllocator, f: []const u8, loader: *FileLoader) !
|
|||||||
const s = parser.nodeListItem(scripts, @intCast(i)).?;
|
const s = parser.nodeListItem(scripts, @intCast(i)).?;
|
||||||
|
|
||||||
const src = parser.nodeTextContent(s).?;
|
const src = parser.nodeTextContent(s).?;
|
||||||
try js_env.run(alloc, src, "", &res, null);
|
res = try evalJS(js_env, alloc, src, "");
|
||||||
|
|
||||||
// return the first failure.
|
// return the first failure.
|
||||||
if (!res.success) {
|
if (!res.success) {
|
||||||
@@ -229,26 +230,32 @@ fn runWPT(arena: *std.heap.ArenaAllocator, f: []const u8, loader: *FileLoader) !
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Mark tests as ready to run.
|
// Mark tests as ready to run.
|
||||||
try js_env.run(alloc, "window.dispatchEvent({target: 'load'});", "ready", &res, null);
|
res = try evalJS(js_env, alloc, "window.dispatchEvent({target: 'load'});", "ready");
|
||||||
if (!res.success) {
|
if (!res.success) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check the final test status.
|
// Check the final test status.
|
||||||
try js_env.run(alloc, "report.status;", "teststatus", &res, null);
|
res = try evalJS(js_env, alloc, "report.status;", "teststatus");
|
||||||
if (!res.success) {
|
if (!res.success) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the test failed, return detailed logs intead of the simple status.
|
// If the test failed, return detailed logs intead of the simple status.
|
||||||
if (!std.mem.eql(u8, res.result, "Pass")) {
|
if (!std.mem.eql(u8, res.result, "Pass")) {
|
||||||
try js_env.run(alloc, "report.log", "teststatus", &res, null);
|
return try evalJS(js_env, alloc, "report.log", "teststatus");
|
||||||
}
|
}
|
||||||
|
|
||||||
// return the final result.
|
// return the final result.
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn evalJS(env: jsruntime.Env, alloc: std.mem.Allocator, script: []const u8, name: ?[]const u8) !jsruntime.JSResult {
|
||||||
|
var res = jsruntime.JSResult{};
|
||||||
|
try env.run(alloc, script, name, &res, null);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
// browse the path to find the tests list.
|
// browse the path to find the tests list.
|
||||||
fn findWPTTests(allocator: std.mem.Allocator, path: []const u8, list: *std.ArrayList([]const u8)) !void {
|
fn findWPTTests(allocator: std.mem.Allocator, path: []const u8, list: *std.ArrayList([]const u8)) !void {
|
||||||
var dir = try std.fs.cwd().openIterableDir(path, .{ .no_follow = true });
|
var dir = try std.fs.cwd().openIterableDir(path, .{ .no_follow = true });
|
||||||
|
|||||||
Reference in New Issue
Block a user