Skip to content
Closed
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
1 change: 1 addition & 0 deletions changelog.d/8791-web-stream-global-constructors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fix global `ReadableStreamBYOBReader`, `ByteLengthQueuingStrategy`, and `CountQueuingStrategy` construction after unresolved-identifier validation was tightened.
3 changes: 3 additions & 0 deletions crates/perry-hir/src/lower/expr_new_builtins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,11 @@ pub(super) fn is_reified_global_builtin_constructor(name: &str) -> bool {
| "CompressionStream"
| "DecompressionStream"
| "ReadableStream"
| "ReadableStreamBYOBReader"
| "WritableStream"
| "TransformStream"
| "ByteLengthQueuingStrategy"
| "CountQueuingStrategy"
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
| "AbortController"
| "AbortSignal"
| "EventTarget"
Expand Down
28 changes: 28 additions & 0 deletions crates/perry-hir/tests/aliased_native_new_resolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,31 @@ fn genuinely_unresolved_new_still_throws() {
ReferenceError throw:\n{debug}"
);
}

#[test]
fn global_web_stream_constructors_do_not_lower_to_unresolved_throw() {
// These constructors are handled by codegen's built-in `new` dispatch,
// just like ReadableStream itself. The unresolved-constructor guard must
// therefore recognize both the bare globals and their globalThis forms.
for name in [
"ReadableStreamBYOBReader",
"ByteLengthQueuingStrategy",
"CountQueuingStrategy",
] {
let bare = lower_debug(&format!(
"const value = new {name}({{ highWaterMark: 1 }});"
));
assert!(
!bare.contains(THROW_HELPER),
"global Web Streams constructor `{name}` must reach built-in lowering:\n{bare}"
);

let qualified = lower_debug(&format!(
"const value = new globalThis.{name}({{ highWaterMark: 1 }});"
));
assert!(
!qualified.contains(THROW_HELPER),
"globalThis Web Streams constructor `{name}` must reach built-in lowering:\n{qualified}"
);
}
}
39 changes: 30 additions & 9 deletions crates/perry-hir/tests/c262_parity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,22 @@ fn closure_display_names(module: &perry_hir::Module) -> Vec<String> {
names
}

fn class_display_names(module: &perry_hir::Module) -> Vec<String> {
let mut names: Vec<String> = module
.classes
.iter()
.map(|class| {
module
.class_display_names
.get(&class.id)
.cloned()
.unwrap_or_else(|| class.name.clone())
})
.collect();
names.sort();
names
}

fn is_number_literal(expr: &Expr, expected: f64) -> bool {
match expr {
Expr::Number(actual) => *actual == expected,
Expand Down Expand Up @@ -127,15 +143,20 @@ fn assignment_named_evaluation_names_anonymous_class_identifier_rhs_only() {
"#,
);

let class_names: Vec<&str> = module
.classes
.iter()
.map(|class| class.name.as_str())
.collect();
assert!(class_names.contains(&"x"), "{class_names:?}");
assert!(class_names.contains(&"cls"), "{class_names:?}");
assert!(!class_names.contains(&"xCls"), "{class_names:?}");
assert!(!class_names.contains(&"xCls2"), "{class_names:?}");
// Class-expression templates may use unique internal registry keys for
// per-evaluation identity. NamedEvaluation is observable through `.name`,
// so assert against the display-name metadata consumed by codegen.
let class_names = class_display_names(&module);
assert!(class_names.contains(&"x".to_string()), "{class_names:?}");
assert!(class_names.contains(&"cls".to_string()), "{class_names:?}");
assert!(
!class_names.contains(&"xCls".to_string()),
"{class_names:?}"
);
assert!(
!class_names.contains(&"xCls2".to_string()),
"{class_names:?}"
);
}

#[test]
Expand Down
Loading