Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions rust/crates/psychoscript/src/reach.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ pub fn roots_but(vm: &Vm, measuring: bool, visit: &mut impl FnMut(Ref)) {
std.headers,
std.array_buffer,
std.data_view,
std.bigint,
std.crypto,
]
.into_iter()
.chain(std.typed)
Expand Down
3 changes: 2 additions & 1 deletion rust/crates/psychoscript/src/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ impl Enc<'_> {
"lazyBuiltins": vm.lazy_builtins,
"std": [std.regexp, std.date, std.uint8, std.buffer, std.text_encoder, std.text_decoder,
std.weak_map, std.weak_set, std.iterator_helper, std.uri_error, std.url, std.params,
std.headers, std.loaded, std.array_buffer, std.typed, std.bigint, std.data_view],
std.headers, std.loaded, std.array_buffer, std.typed, std.bigint, std.data_view, std.crypto],
"host": host,
}))
}
Expand Down Expand Up @@ -2815,6 +2815,7 @@ pub fn restore(vm: &mut Vm, snapshot: &Snapshot, program_hash: &str) -> R<()> {
}
realm.bigint = id(16)?;
realm.data_view = id(17)?;
realm.crypto = id(18)?;
if !vm.intern_restored(base.heap) {
return Err(invalid("a BigInt is saved twice."));
}
Expand Down
24 changes: 24 additions & 0 deletions rust/crates/psychoscript/tests/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,30 @@ fn a_suspended_run_keeps_its_typed_arrays_and_the_buffers_their_views_share() {
);
}

#[test]
fn a_suspended_run_keeps_the_crypto_group_it_loaded() {
// `require` loads the group during the run: its `crypto` tags only what inherits from it after the resume too.
let code = format!(
r#"const c = require('crypto')
await step(1)
{BUSY}
return [Object.prototype.toString.call({{}}), Object.prototype.toString.call(c), c.randomUUID().length]"#
);
let gate = Gate::default();
let state = suspend_mid_loop(&stepping(&gate), &gate, &code);
let o = done(
fresh()
.resume_bytes(&psychoscript::to_bytes(&state))
.unwrap()
.run_resumable()
.unwrap(),
);
assert_eq!(
o.result.unwrap(),
json!(["[object Object]", "[object Crypto]", 36])
);
}

#[test]
fn a_resumed_run_keeps_its_heap_limit() {
// Mid-loop, with 1000 small objects kept: under the limit. After the resume, a run that keeps growing goes over it.
Expand Down