aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js/test
diff options
context:
space:
mode:
authorGravatar Alex Lam S.L <alexlamsl@gmail.com> 2023-01-05 23:17:15 +0200
committerGravatar GitHub <noreply@github.com> 2023-01-05 13:17:15 -0800
commitd22e3ebf9ab6fe2bdecd90fc4d65aa28bce6aae4 (patch)
tree1df4617794ca84e510fe095106f0da54b0a445da /src/bun.js/test
parent0873a15a637339506207fe9bd628e2839d78dbbc (diff)
downloadbun-d22e3ebf9ab6fe2bdecd90fc4d65aa28bce6aae4.tar.gz
bun-d22e3ebf9ab6fe2bdecd90fc4d65aa28bce6aae4.tar.zst
bun-d22e3ebf9ab6fe2bdecd90fc4d65aa28bce6aae4.zip
[socket] fix double-free in `finalize()` (#1731)
- tidy up `.isEmptyOrUndefinedOrNull()` usage
Diffstat (limited to 'src/bun.js/test')
-rw-r--r--src/bun.js/test/jest.zig69
1 files changed, 33 insertions, 36 deletions
diff --git a/src/bun.js/test/jest.zig b/src/bun.js/test/jest.zig
index 07f802c13..590d5ec2b 100644
--- a/src/bun.js/test/jest.zig
+++ b/src/bun.js/test/jest.zig
@@ -1401,45 +1401,42 @@ pub const TestScope = struct {
initial_value = js.JSObjectCallAsFunctionReturnValue(vm.global, callback, null, 0, null);
}
- if (!initial_value.isEmptyOrUndefinedOrNull()) {
- if (initial_value.isAnyError(vm.global)) {
- vm.runErrorHandler(initial_value, null);
- return .{ .fail = active_test_expectation_counter.actual };
- }
-
- if (initial_value.asAnyPromise()) |promise| {
- if (this.promise != null) {
- return .{ .pending = {} };
- }
- this.task = task;
+ if (initial_value.isAnyError(vm.global)) {
+ vm.runErrorHandler(initial_value, null);
+ return .{ .fail = active_test_expectation_counter.actual };
+ }
- // TODO: not easy to coerce JSInternalPromise as JSValue,
- // so simply wait for completion for now.
- switch (promise) {
- .Internal => vm.waitForPromise(promise),
- else => {},
- }
+ if (initial_value.asAnyPromise()) |promise| {
+ if (this.promise != null) {
+ return .{ .pending = {} };
+ }
+ this.task = task;
- switch (promise.status(vm.global.vm())) {
- .Rejected => {
- vm.runErrorHandler(promise.result(vm.global.vm()), null);
- return .{ .fail = active_test_expectation_counter.actual };
- },
- .Pending => {
- task.promise_state = .pending;
- switch (promise) {
- .Normal => |p| {
- _ = p.asValue(vm.global).then(vm.global, task, onResolve, onReject);
- return .{ .pending = {} };
- },
- else => unreachable,
- }
- },
+ // TODO: not easy to coerce JSInternalPromise as JSValue,
+ // so simply wait for completion for now.
+ switch (promise) {
+ .Internal => vm.waitForPromise(promise),
+ else => {},
+ }
- else => {
- _ = promise.result(vm.global.vm());
- },
- }
+ switch (promise.status(vm.global.vm())) {
+ .Rejected => {
+ vm.runErrorHandler(promise.result(vm.global.vm()), null);
+ return .{ .fail = active_test_expectation_counter.actual };
+ },
+ .Pending => {
+ task.promise_state = .pending;
+ switch (promise) {
+ .Normal => |p| {
+ _ = p.asValue(vm.global).then(vm.global, task, onResolve, onReject);
+ return .{ .pending = {} };
+ },
+ else => unreachable,
+ }
+ },
+ else => {
+ _ = promise.result(vm.global.vm());
+ },
}
}