JavaScript: accept host constructors in Promise statics

This commit is contained in:
dotCooCoo committed 2026-11-26 06:50:40 -08:00
1 parent 5d7e2af8a0
commit 4df7b1179d
4 files changed
+38 -1

No files matched your search

+3 -1
View File
@@ -31,6 +31,7 @@ use super::{arg, constructor, create_at, method, native, new_array};
use crate::LimitKind;
use crate::bytecode::Code;
use crate::heap::{BOUND_ARG_BYTES, Class, Func, NativeFn, NativeKind, OBJECT_BYTES, OPEN, ObjId, Object, PROP_BYTES, Prop, Roots, key};
use crate::host::ArgRead;
use crate::interp::{Abrupt, ErrorType, Interp, JsResult};
use crate::string_builtins::flat_charged;
use crate::value::Value;
@@ -912,7 +913,7 @@ fn thrower(interp: &mut Interp, _: Value, args: &[Value], _: bool) -> JsResult<V
}
/// `v` is a constructor: a function written in JavaScript other than an arrow function or a
/// method, a built-in constructor, or a bound function whose target is one.
/// method, a built-in or registered host constructor, or a bound function whose target is one.
fn is_constructor(interp: &mut Interp, v: &Value) -> JsResult<bool> {
let mut v = v.clone();
loop {
@@ -923,6 +924,7 @@ fn is_constructor(interp: &mut Interp, v: &Value) -> JsResult<bool> {
match func {
Func::Closure { code, .. } => return Ok(!code.arrow && !code.method),
Func::Native { constructor, .. } => return Ok(constructor),
Func::Data { read: ArgRead::Hosted, .. } => return Ok(v.as_object().is_some_and(|o| interp.is_host_constructor(o))),
Func::Bound { target, .. } => {
interp.use_fuel()?;
v = Value::Object(target);
+31
View File
@@ -57,6 +57,37 @@ fn promise_prototype_cannot_be_replaced() {
assert_eq!(string(src), "true,true,true");
}
#[test]
fn promise_statics_accept_registered_host_constructors_and_bound_targets() {
let mut r = realm();
let make: HostFunction = std::rc::Rc::new(|_| Ok(Data::Object(Vec::new())));
r.define_host_classes(
vec![HostClass { name: "Thing".into(), parent: None, members: Vec::new(), index: None, construct: Some(make) }],
Vec::new(),
)
.unwrap();
r.define_host_function("ordinary", Vec::new(), std::rc::Rc::new(|_| Ok(Data::Undefined))).unwrap();
let result = r
.run(
"var constructors = [Thing, Thing.bind(null), Thing.bind(null).bind(null)]; \
var methods = ['resolve', 'reject', 'all', 'allSettled', 'race']; var log = []; \
for (var i = 0; i < constructors.length; i++) { \
var C = constructors[i]; C.resolve = Promise.resolve; \
log.push(new C() instanceof Thing); \
for (var j = 0; j < methods.length; j++) { \
var p = Promise[methods[j]].call(C, []); \
log.push(p instanceof Promise); p.catch(function () {}); \
} \
} \
for (var j = 0; j < methods.length; j++) { \
try { Promise[methods[j]].call(ordinary, []); log.push(false); } \
catch (e) { log.push(e instanceof TypeError); } \
} log.join()",
)
.unwrap();
assert_eq!(result, JsValue::String(vec!["true"; 23].join(",")));
}
#[test]
fn then_callbacks_run_after_the_scripts_code_in_order() {
let src = "Promise.resolve(1).then(function (v) { log.push('a' + v); });\n\
+2
View File
@@ -2890,6 +2890,8 @@ own rules:
- `all`, `allSettled` and `race` take an array, another object whose `length` is a whole number, or a string (one
item per character); any other value rejects the promise they return with a `TypeError`. The promises `then` and the
statics make are always plain `Promise` objects; `Symbol.species` and subclasses are not read.
The statics accept registered host class constructors and bound constructors as `this`; ordinary host functions
still give a `TypeError`.
- A promise rejected with no rejection handler that still has none when the run ends successfully is reported: the
report's `unhandledRejections` lists the first 20 as `{message, messageOrigin, line, column, file?}`, where it was
rejected (the `throw`, or the call of its reject function or of `Promise.reject`), `unhandledRejectionCount` counts
+2
View File
@@ -32,6 +32,8 @@
## Feature submission evidence
Scripts: Promise statics accept registered host class constructors and their bound functions as `this`, while ordinary host functions give a `TypeError`. The statics still return built-in Promise objects. Test: `promise_statics_accept_registered_host_constructors_and_bound_targets` in `crates/js/src/promise_tests.rs`.
Variables panel row context menus (2026-11-20, G12): Right-click highlights the clicked variable without changing the canvas selection and offers Select Bound Object, Variable Options…, Unbind Variable, the four Make Dynamic actions, and Delete Variable. Shift+F10 opens the same menu for the focused row; Escape dismisses it. Row actions target that variable; dynamic actions use the canvas selection. Lock and selection checks disable unavailable actions. Headless pointer/accessibility tests cover opening the menu, highlighting, bound-object selection, deletion in one undo step and restoration, and disabled actions. Scores and estimates unchanged.
Actions panel item context menus (2026-11-20): Right-clicking an Action Set row selects it and presents a context menu with New Action…, New Set…, Duplicate Set, Delete Set, and Set Options…. Right-clicking an Action row selects it and presents a context menu with Play, Record, Duplicate, Delete, Action Options…, and Batch…. Duplicate on an action duplicates that action and selects the duplicate; Delete removes it. Headless tests in `crates/ui-egui/src/panels/actions.rs`: `right_clicking_an_action_set_selects_it_and_presents_set_context_options`, `right_clicking_an_action_selects_it_and_presents_action_options`, and `clicking_duplicate_on_an_action_duplicates_that_action_in_the_set`. Scores and estimates unchanged.