mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 23:23:28 +00:00
Improves correctness of NodeIterator
Minor improvement to correctness of TreeWalker. Fun fact, this is the first time, that I've run into, where we have to default null and undefined to different values. Also, tweaked the WPT test runner. WPT test results use | as a field delimiter. But a WPT test (and, I assume a message) can contain a |. So we had at least a few tests that were being reported as failed, only because the result line was weird / unexpected. No great robust way to parse this, but I changed it to look explicitly for |Pass or |Fail and use those positions as anchor points.
This commit is contained in:
@@ -941,6 +941,27 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
|
||||
fn jsValueToZig(self: *JsContext, comptime named_function: NamedFunction, comptime T: type, js_value: v8.Value) !T {
|
||||
switch (@typeInfo(T)) {
|
||||
.optional => |o| {
|
||||
if (comptime isJsObject(o.child)) {
|
||||
// If type type is a ?JsObject, then we want to pass
|
||||
// a JsObject, not null. Consider a function,
|
||||
// _doSomething(arg: ?Env.JsObjet) void { ... }
|
||||
//
|
||||
// And then these three calls:
|
||||
// doSomething();
|
||||
// doSomething(null);
|
||||
//
|
||||
// In the first case, we'll pass `null`. But in the
|
||||
// second, we'll pass a JsObject which represents
|
||||
// null.
|
||||
// If we don't have this code, both cases will
|
||||
// pass in `null` and the the doSomething won't
|
||||
// be able to tell if `null` was explicitly passed
|
||||
// or whether no parameter was passed.
|
||||
return JsObject{
|
||||
.js_obj = js_value.castTo(v8.Object),
|
||||
.js_context = self,
|
||||
};
|
||||
}
|
||||
if (js_value.isNullOrUndefined()) {
|
||||
return null;
|
||||
}
|
||||
@@ -1938,6 +1959,24 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
|
||||
return try js_context.createFunction(js_value);
|
||||
}
|
||||
|
||||
pub fn isNull(self: JsObject) bool {
|
||||
return self.js_obj.toValue().isNull();
|
||||
}
|
||||
|
||||
pub fn isUndefined(self: JsObject) bool {
|
||||
return self.js_obj.toValue().isUndefined();
|
||||
}
|
||||
|
||||
pub fn triState(self: JsObject, comptime Struct: type, comptime name: []const u8, comptime T: type) !TriState(T) {
|
||||
if (self.isNull()) {
|
||||
return .{ .null = {} };
|
||||
}
|
||||
if (self.isUndefined()) {
|
||||
return .{ .undefined = {} };
|
||||
}
|
||||
return .{ .value = try self.toZig(Struct, name, T) };
|
||||
}
|
||||
|
||||
pub fn isNullOrUndefined(self: JsObject) bool {
|
||||
return self.js_obj.toValue().isNullOrUndefined();
|
||||
}
|
||||
@@ -1965,6 +2004,14 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
|
||||
const named_function = comptime NamedFunction.init(Struct, name);
|
||||
return self.js_context.jsValueToZig(named_function, T, self.js_obj.toValue());
|
||||
}
|
||||
|
||||
pub fn TriState(comptime T: type) type {
|
||||
return union(enum) {
|
||||
null: void,
|
||||
undefined: void,
|
||||
value: T,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
// This only exists so that we know whether a function wants the opaque
|
||||
|
||||
Reference in New Issue
Block a user