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
8 changes: 6 additions & 2 deletions crates/perry-hir/src/eval_classifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -813,8 +813,12 @@ mod tests {
// Unique location so this test's recorded site is identifiable even if
// sibling tests push to the process-global sink concurrently.
let loc = "/app/unimpl_defers_fixture.ts:42";
let decision =
check_unimplemented_api("`process.binding` is not implemented (#463)", "process.binding", loc, 0);
let decision = check_unimplemented_api(
"`process.binding` is not implemented (#463)",
"process.binding",
loc,
0,
);
match decision {
UnimplementedDecision::DeferToRuntimeError(msg) => {
assert!(msg.contains("process.binding"), "msg: {msg}");
Expand Down
19 changes: 13 additions & 6 deletions crates/perry-hir/src/lower/expr_call/module_class_static.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,23 @@ pub(super) fn try_module_class_static(
&ctx.source_file_path,
outer_member.span.lo.0,
);
match crate::check_unimplemented_api(&msg, &api, &location, outer_member.span.lo.0) {
match crate::check_unimplemented_api(
&msg,
&api,
&location,
outer_member.span.lo.0,
) {
crate::UnimplementedDecision::Refuse => {
crate::lower_bail!(outer_member.span, "{}", msg);
}
crate::UnimplementedDecision::DeferToRuntimeError(runtime_msg) => {
return Ok(Ok(super::super::const_fold_fn::synth_deferred_throw_value(
ctx,
&runtime_msg,
outer_member.span,
)?));
return Ok(Ok(
super::super::const_fold_fn::synth_deferred_throw_value(
ctx,
&runtime_msg,
outer_member.span,
)?,
));
}
}
}
Expand Down
38 changes: 26 additions & 12 deletions crates/perry-hir/src/lower/expr_call/native_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,16 +459,23 @@ pub(super) fn try_native_module_methods(
&ctx.source_file_path,
member.span.lo.0,
);
match crate::check_unimplemented_api(&msg, &api, &location, member.span.lo.0) {
match crate::check_unimplemented_api(
&msg,
&api,
&location,
member.span.lo.0,
) {
crate::UnimplementedDecision::Refuse => {
crate::lower_bail!(member.span, "{}", msg);
}
crate::UnimplementedDecision::DeferToRuntimeError(runtime_msg) => {
return Ok(Ok(super::super::const_fold_fn::synth_deferred_throw_value(
ctx,
&runtime_msg,
member.span,
)?));
return Ok(Ok(
super::super::const_fold_fn::synth_deferred_throw_value(
ctx,
&runtime_msg,
member.span,
)?,
));
}
}
}
Expand Down Expand Up @@ -1546,16 +1553,23 @@ pub(super) fn try_native_module_methods(
&ctx.source_file_path,
member.span.lo.0,
);
match crate::check_unimplemented_api(&msg, &api, &location, member.span.lo.0) {
match crate::check_unimplemented_api(
&msg,
&api,
&location,
member.span.lo.0,
) {
crate::UnimplementedDecision::Refuse => {
crate::lower_bail!(member.span, "{}", msg);
}
crate::UnimplementedDecision::DeferToRuntimeError(runtime_msg) => {
return Ok(Ok(super::super::const_fold_fn::synth_deferred_throw_value(
ctx,
&runtime_msg,
member.span,
)?));
return Ok(Ok(
super::super::const_fold_fn::synth_deferred_throw_value(
ctx,
&runtime_msg,
member.span,
)?,
));
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion crates/perry-hir/src/lower/expr_call/nested_namespace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,9 @@ pub(super) fn try_util_types_namespace(
crate::UnimplementedDecision::Refuse => {
crate::lower_bail!(outer_member.span, "{}", msg);
}
crate::UnimplementedDecision::DeferToRuntimeError(runtime_msg) => {
crate::UnimplementedDecision::DeferToRuntimeError(
runtime_msg,
) => {
return Ok(Ok(
super::super::const_fold_fn::synth_deferred_throw_value(
ctx,
Expand Down
3 changes: 2 additions & 1 deletion crates/perry-hir/src/lower/expr_member.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2331,7 +2331,8 @@ fn lower_member_inner(ctx: &mut LoweringContext, member: &ast::MemberExpr) -> Re
// for the end-of-compile notice); strict-unimplemented mode restores
// the hard #463 refusal. #2309 tree-shake deferral is handled inside.
let api = format!("{module}.{prop}");
let location = crate::eval_classifier::location_string(&ctx.source_file_path, member.span.lo.0);
let location =
crate::eval_classifier::location_string(&ctx.source_file_path, member.span.lo.0);
match crate::check_unimplemented_api(&msg, &api, &location, member.span.lo.0) {
crate::UnimplementedDecision::Refuse => {
crate::lower_bail!(member.span, "{}", msg);
Expand Down
10 changes: 4 additions & 6 deletions crates/perry-hir/tests/export_var_uninitialized_lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ fn uninitialized_export_var_registers_exported_binding() {
// A backing `Stmt::Let` (declared `undefined`) must precede the IIFE
// assignment in module init — without it codegen never emits the global
// that backs the value-getter.
let let_idx = module.init.iter().position(|s| {
matches!(s, Stmt::Let { name, init, .. } if name == "Color" && init.is_none())
});
let let_idx = module.init.iter().position(
|s| matches!(s, Stmt::Let { name, init, .. } if name == "Color" && init.is_none()),
);
assert!(
let_idx.is_some(),
"expected a hoisted `Stmt::Let {{ name: \"Color\", init: None }}` in module init: {:?}",
Expand Down Expand Up @@ -102,7 +102,5 @@ fn initialized_export_var_still_exports() {
// `Some(init)` branch, not the new `else`).
let module = lower_result("export var initialized = 1;");
assert!(is_named_export(&module, "initialized"));
assert!(module
.exported_objects
.contains(&"initialized".to_string()));
assert!(module.exported_objects.contains(&"initialized".to_string()));
}
3 changes: 1 addition & 2 deletions crates/perry-hir/tests/unimplemented_api_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ fn lower_result_mode(src: &str, strict_unimplemented: bool) -> Result<perry_hir:
let mut cache = SourceCache::new();
let parsed = parse_typescript_with_cache(&src, "test.ts", &mut cache)
.expect("parse should succeed");
let result =
lower_module(&parsed.module, "test", "test.ts").map_err(|e| e.to_string());
let result = lower_module(&parsed.module, "test", "test.ts").map_err(|e| e.to_string());
// Drain any notice sites this lower recorded so they don't leak
// into the process-global sink another test might inspect.
let _ = perry_hir::take_deferred_eval_sites();
Expand Down
3 changes: 1 addition & 2 deletions crates/perry-runtime/src/buffer/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -559,8 +559,7 @@ pub fn buffer_alloc(capacity: u32) -> *mut BufferHeader {
// runtime's `*(ptr - GC_HEADER_SIZE)` obj_type probes read a mapped `0`
// (matching no `GC_TYPE_*`) instead of faulting at a region boundary.
let inner = buffer_layout(capacity as usize);
let layout =
Layout::from_size_align(crate::gc::GC_HEADER_SIZE + inner.size(), 8).unwrap();
let layout = Layout::from_size_align(crate::gc::GC_HEADER_SIZE + inner.size(), 8).unwrap();
unsafe {
let raw = alloc(layout);
if raw.is_null() {
Expand Down
7 changes: 2 additions & 5 deletions crates/perry-stdlib/src/readline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -751,9 +751,7 @@ fn ensure_reader_started() {
// flowing mode this is the last 'data' chunk for input like
// `printf "abc"` (no final newline); otherwise it's a final 'line'.
if !line_buf.is_empty() && !STDIN_DESTROYED.load(Ordering::Acquire) {
if STDIN_DATA_FLOWING.load(Ordering::Acquire)
&& !RAW_MODE.load(Ordering::Acquire)
{
if STDIN_DATA_FLOWING.load(Ordering::Acquire) && !RAW_MODE.load(Ordering::Acquire) {
if let Ok(mut q) = PENDING_DATA.lock() {
q.push(std::mem::take(&mut line_buf));
}
Expand Down Expand Up @@ -1503,8 +1501,7 @@ pub extern "C" fn js_readline_has_active() -> i32 {
&& !destroyed
&& refed
&& !paused
&& (((RAW_MODE.load(Ordering::Acquire)
|| STDIN_DATA_FLOWING.load(Ordering::Acquire))
&& (((RAW_MODE.load(Ordering::Acquire) || STDIN_DATA_FLOWING.load(Ordering::Acquire))
&& has_stdin_callbacks)
|| has_line_callbacks
|| has_close_cb);
Expand Down
Loading
Loading