diff --git a/crates/js/src/builtins/promise.rs b/crates/js/src/builtins/promise.rs index 6667de7a8f..9122362928 100644 --- a/crates/js/src/builtins/promise.rs +++ b/crates/js/src/builtins/promise.rs @@ -30,7 +30,9 @@ use std::rc::Rc; 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::heap::{ + BOUND_ARG_BYTES, CONFIGURABLE, Class, Func, NativeFn, NativeKind, OBJECT_BYTES, OPEN, ObjId, Object, PROP_BYTES, Prop, Roots, key, +}; use crate::interp::{Abrupt, ErrorType, Interp, JsResult}; use crate::value::Value; @@ -261,6 +263,9 @@ pub(crate) fn install(interp: &mut Interp) -> JsResult<()> { let object_proto = interp.intrinsics.object_proto; let proto = interp.heap.alloc_object(Object::new(Class::Ordinary, Some(object_proto))); interp.promises.proto = Some(proto); + if let Some(tag) = interp.well_known(|w| &w.to_string_tag) { + interp.define_sym(proto, tag, Prop::Data { value: Value::str("Promise"), flags: CONFIGURABLE })?; + } let ctor = native(interp, "Promise", promise_ctor, 1, NativeKind::Plain, true)?; interp.promises.ctor = Some(ctor); constructor(interp, "Promise", ctor, proto)?; diff --git a/crates/js/src/promise_tests.rs b/crates/js/src/promise_tests.rs index 25de072b85..01abc2c92e 100644 --- a/crates/js/src/promise_tests.rs +++ b/crates/js/src/promise_tests.rs @@ -57,6 +57,22 @@ fn promise_prototype_cannot_be_replaced() { assert_eq!(string(src), "true,true,true"); } +#[test] +fn promise_prototype_has_a_configurable_string_tag() { + assert_eq!( + string( + "var d = Object.getOwnPropertyDescriptor(Promise.prototype, Symbol.toStringTag); \ + [Object.prototype.toString.call(Promise.prototype), \ + Object.prototype.toString.call(Promise.resolve()), \ + d.value, d.writable, d.enumerable, d.configurable].join()" + ), + "[object Promise],[object Promise],Promise,false,false,true" + ); + let mut r = Realm::new(); + r.add_es2015(); + assert_eq!(r.run("Object.prototype.toString.call(Promise.resolve())").unwrap(), JsValue::String("[object Promise]".into())); +} + #[test] fn then_callbacks_run_after_the_scripts_code_in_order() { let src = "Promise.resolve(1).then(function (v) { log.push('a' + v); });\n\ diff --git a/docs/mcp.md b/docs/mcp.md index 855d1b8b90..0b957260ab 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -2914,6 +2914,8 @@ In a `.js` script, `Promise` follows ECMA-262 11th edition section 25.6 `Promise.resolve`, `reject`, `all`, `allSettled` and `race`. `Promise.any` is not provided. These are VectorCraft's own rules: +- `Promise.prototype[Symbol.toStringTag]` is `"Promise"` when Symbols are available. The property is configurable, + non-enumerable and non-writable. Promise instances also report `[object Promise]` in engines without Symbols. - The callbacks `then`, `catch` and `finally` register run as jobs, one at a time, in the order they were queued, after the script's own code ends and before the run ends; a job a callback queues runs after the jobs already waiting. A promise still pending when no job is left stays pending, and the run ends. diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 74a9bef455..b319aae3e0 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -36,6 +36,8 @@ When startup scripts precede a chosen script, its source must compile before sta `vectorcraft-js` ends a paused or waiting run before `Realm::run` or `Realm::start` compiles new source. Its globals remain available. The earlier run's remaining code and queued jobs do not run. Regressions in `crates/js/src/host_tests.rs` cover paused scripts, Promise reactions, waiting host calls, invalid replacement source, and deferred language settings. +Scripts: `Promise.prototype[Symbol.toStringTag]` is `"Promise"` when Symbols are available, with a configurable, non-enumerable, non-writable descriptor. Promise instances report `[object Promise]` in engines without Symbols. Test: `promise_prototype_has_a_configurable_string_tag` in `crates/js/src/promise_tests.rs`. + History panel row context menus (2026-11-20, G12): Right-clicking any state offers New Document from State, Step to This State, and Clear History. Creating a document uses the clicked snapshot without stepping the source document; Step to This State uses undo/redo and is disabled on the current row; Clear History removes undo and redo steps without changing artwork and is disabled when history is empty. Headless tests in `crates/ui-egui/src/panels/history.rs` cover opening an earlier row menu, snapshot creation, backward/forward jumps, and clearing history. The snapshot chosen when the menu opens is retained while it stays open; pending tool edits are settled before resolving that snapshot to its new row; a discarded snapshot reports that it is unavailable instead of acting on a neighboring row. Jumps settle pending typing before counting undo/redo steps. Shift+F10 opens the focused row menu; Escape dismisses it and restores row focus. Switching documents dismisses the menu before it can act on another document. Headless tests cover these keyboard and document-switch paths. The list and menu use shared Craft UI controls. Scores and estimates unchanged. Character-style edits keep manual leading overrides when Dynamic Text's Block cannot fit the frame. When Block can fit the frame, its generated leading follows the edited style. A regression in `crates/engine/src/cmd/typecmd/block_tests.rs` covers a frame whose inset leaves no room.