Skip to content

Commit

Permalink
test(allocator): Merge test (#9267)
Browse files Browse the repository at this point in the history
  • Loading branch information
kdy1 authored Jul 17, 2024
1 parent a92ce51 commit efc3963
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use criterion::black_box;
use swc_allocator::Allocator;
use swc_allocator::{boxed::Box, Allocator, FastAlloc};

#[test]
fn direct_alloc_std() {
Expand Down Expand Up @@ -33,3 +33,31 @@ fn direct_alloc_in_scope() {
vec.push(item);
}
}

#[test]
fn escape() {
let allocator = Allocator::default();

let obj = {
let _guard = unsafe { allocator.guard() };
Box::new(1234)
};

assert_eq!(*obj, 1234);
// It should not segfault, because the allocator is still alive.
drop(obj);
}

#[test]
fn global_allocator_escape() {
let allocator = Allocator::default();
let obj = {
let _guard = unsafe { allocator.guard() };
Box::new_in(1234, FastAlloc::global())
};

assert_eq!(*obj, 1234);
drop(allocator);
// Object created with global allocator should outlive the allocator.
drop(obj);
}
29 changes: 0 additions & 29 deletions crates/swc_allocator/tests/escape.rs

This file was deleted.

0 comments on commit efc3963

Please sign in to comment.