Add missing exception checks

This commit is contained in:
Jarred Sumner
2024-10-04 02:40:58 -07:00
parent b4e81a4e53
commit 97a75b53f5

View File

@@ -702,6 +702,10 @@ pub const Expect = struct {
break;
}
}
if (globalThis.hasException()) {
return .zero;
}
} else if (list_value.isIterable(globalThis)) {
var expected_entry = ExpectedEntry{
.globalThis = globalThis,
@@ -728,6 +732,10 @@ pub const Expect = struct {
return .zero;
}
if (globalThis.hasException()) {
return .zero;
}
if (not) pass = !pass;
if (pass) return .undefined;
@@ -1496,6 +1504,10 @@ pub const Expect = struct {
const truthy = value.toBooleanSlow(globalThis);
if (truthy) pass = true;
if (globalThis.hasException()) {
return .zero;
}
if (not) pass = !pass;
if (pass) return .undefined;
@@ -1690,6 +1702,9 @@ pub const Expect = struct {
const not = this.flags.not;
var pass = value.jestDeepEquals(expected, globalThis);
if (globalThis.hasException()) {
return .zero;
}
if (not) pass = !pass;
if (pass) return .undefined;
@@ -1732,6 +1747,9 @@ pub const Expect = struct {
const not = this.flags.not;
var pass = value.jestStrictDeepEquals(expected, globalThis);
if (globalThis.hasException()) {
return .zero;
}
if (not) pass = !pass;
if (pass) return .undefined;
@@ -1785,11 +1803,17 @@ pub const Expect = struct {
if (pass) {
received_property = value.getIfPropertyExistsFromPath(globalThis, expected_property_path);
if (globalThis.hasException()) {
return .zero;
}
pass = !received_property.isEmpty();
}
if (pass and expected_property != null) {
pass = received_property.jestDeepEquals(expected_property.?, globalThis);
if (globalThis.hasException()) {
return .zero;
}
}
if (not) pass = !pass;
@@ -2724,6 +2748,9 @@ pub const Expect = struct {
const prop_matchers = _prop_matchers;
if (!value.jestDeepMatch(prop_matchers, globalThis, true)) {
if (globalThis.hasException()) {
return .zero;
}
// TODO: print diff with properties from propertyMatchers
const signature = comptime getSignature("toMatchSnapshot", "<green>propertyMatchers<r>", false);
const fmt = signature ++ "\n\nExpected <green>propertyMatchers<r> to match properties from received object" ++
@@ -2733,6 +2760,9 @@ pub const Expect = struct {
globalThis.throwPretty(fmt, .{value.toFmt(&formatter)});
return .zero;
}
if (globalThis.hasException()) {
return .zero;
}
}
const result = Jest.runner.?.snapshots.getOrPut(this, value, hint.slice(), globalThis) catch |err| {
@@ -4169,6 +4199,9 @@ pub const Expect = struct {
const property_matchers = args[0];
var pass = received_object.jestDeepMatch(property_matchers, globalThis, true);
if (globalThis.hasException()) {
return .zero;
}
if (not) pass = !pass;
if (pass) return .undefined;
@@ -4229,6 +4262,8 @@ pub const Expect = struct {
if (!callArg.jestDeepEquals(arguments[callItr.i - 1], globalThis)) {
match = false;
break;
} else if (globalThis.hasException()) {
return .zero;
}
}
@@ -4239,6 +4274,10 @@ pub const Expect = struct {
}
}
if (globalThis.hasException()) {
return .zero;
}
const not = this.flags.not;
if (not) pass = !pass;
if (pass) return .undefined;
@@ -4298,6 +4337,10 @@ pub const Expect = struct {
}
}
if (globalThis.hasException()) {
return .zero;
}
const not = this.flags.not;
if (not) pass = !pass;
if (pass) return .undefined;
@@ -4366,6 +4409,10 @@ pub const Expect = struct {
}
}
if (globalThis.hasException()) {
return .zero;
}
const not = this.flags.not;
if (not) pass = !pass;
if (pass) return .undefined;