From 83a5c9f3da91b677fd6c9f1bc06b69f292997bd6 Mon Sep 17 00:00:00 2001 From: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Date: Sun, 8 Jan 2023 07:36:42 -0800 Subject: [internal] Fix checking for Error object --- src/bun.js/test/jest.zig | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src/bun.js/test/jest.zig') diff --git a/src/bun.js/test/jest.zig b/src/bun.js/test/jest.zig index 590d5ec2b..68469c7e8 100644 --- a/src/bun.js/test/jest.zig +++ b/src/bun.js/test/jest.zig @@ -1098,7 +1098,7 @@ pub const Expect = struct { const value = arguments[0]; if (value.isEmptyOrUndefinedOrNull() or !value.isObject() and !value.isString()) { var fmt = JSC.ZigConsoleClient.Formatter{ .globalThis = globalObject }; - globalObject.throw("Expected value must be string or Error: {any}", .{ value.toFmt(globalObject, &fmt) }); + globalObject.throw("Expected value must be string or Error: {any}", .{value.toFmt(globalObject, &fmt)}); return .zero; } break :brk value; @@ -1117,19 +1117,19 @@ pub const Expect = struct { } const not = this.op.contains(.not); - const result = value.call(globalObject, &.{}).toError(globalObject); - if (result.isUndefined()) { + const result = value.call(globalObject, &.{}).toError_(); + if (result == .zero) { if (not) return thisValue; globalObject.throw("Expected function to throw", .{}); return .zero; - } else if(not) { + } else if (not) { globalObject.throw("Expected function not to throw", .{}); return .zero; } - if (expected_value == .zero) return thisValue; + if (expected_value == .zero or !expected_value.isCell()) return thisValue; - const expected_error = expected_value.toError(globalObject); + const expected_error = expected_value.toError() orelse expected_value; if (expected_value.isString() or !expected_error.isUndefined()) { const expected = brk: { @@ -1401,7 +1401,7 @@ pub const TestScope = struct { initial_value = js.JSObjectCallAsFunctionReturnValue(vm.global, callback, null, 0, null); } - if (initial_value.isAnyError(vm.global)) { + if (initial_value.isAnyError()) { vm.runErrorHandler(initial_value, null); return .{ .fail = active_test_expectation_counter.actual }; } @@ -1640,7 +1640,7 @@ pub const DescribeScope = struct { } Jest.runner.?.pending_test = pending_test; - if (result.isAnyError(ctx)) return result; + if (result.isAnyError()) return result; if (comptime hook == .beforeAll or hook == .afterAll) { hooks[i] = JSC.JSValue.zero; @@ -1725,8 +1725,8 @@ pub const DescribeScope = struct { return null; }, } - } else if (result.isAnyError(ctx)) { - exception.* = result.asObjectRef(); + } else if (result.toError()) |err| { + exception.* = err.asObjectRef(); return null; } } -- cgit v1.2.3