diff --git a/changelog.d/8791-web-stream-global-constructors.md b/changelog.d/8791-web-stream-global-constructors.md new file mode 100644 index 00000000000..a557c9d7568 --- /dev/null +++ b/changelog.d/8791-web-stream-global-constructors.md @@ -0,0 +1 @@ +- Fix global `ReadableStreamBYOBReader`, `ByteLengthQueuingStrategy`, and `CountQueuingStrategy` construction after unresolved-identifier validation was tightened. diff --git a/crates/perry-hir/src/lower/expr_new_builtins.rs b/crates/perry-hir/src/lower/expr_new_builtins.rs index 90fc0868888..97a985fe0f5 100644 --- a/crates/perry-hir/src/lower/expr_new_builtins.rs +++ b/crates/perry-hir/src/lower/expr_new_builtins.rs @@ -102,8 +102,11 @@ pub(super) fn is_reified_global_builtin_constructor(name: &str) -> bool { | "CompressionStream" | "DecompressionStream" | "ReadableStream" + | "ReadableStreamBYOBReader" | "WritableStream" | "TransformStream" + | "ByteLengthQueuingStrategy" + | "CountQueuingStrategy" | "AbortController" | "AbortSignal" | "EventTarget" diff --git a/crates/perry-hir/tests/aliased_native_new_resolution.rs b/crates/perry-hir/tests/aliased_native_new_resolution.rs index 9795ddbf215..1705e79353c 100644 --- a/crates/perry-hir/tests/aliased_native_new_resolution.rs +++ b/crates/perry-hir/tests/aliased_native_new_resolution.rs @@ -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}" + ); + } +} diff --git a/crates/perry-hir/tests/c262_parity.rs b/crates/perry-hir/tests/c262_parity.rs index 9090110ba68..8957da8ebae 100644 --- a/crates/perry-hir/tests/c262_parity.rs +++ b/crates/perry-hir/tests/c262_parity.rs @@ -59,6 +59,22 @@ fn closure_display_names(module: &perry_hir::Module) -> Vec { names } +fn class_display_names(module: &perry_hir::Module) -> Vec { + let mut names: Vec = 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, @@ -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]