Merge pull request #9470 from dotCooCoo/fix/symbol-registry-budget

Charge Symbol registry hashing and correct key buffer reservations
This commit is contained in:
.CooCoo authored and GitHub committed 2026-11-28 02:20:44 -08:00
commit ba978a77a4
5 files changed
+39 -4

No files matched your search

+4 -3
View File
@@ -5,7 +5,7 @@
//! (section 20.4.4.45). Installed in a realm with [`crate::Options::es2015`] only.
use super::{arg, constructor, create_at, data, method, native, new_array};
use crate::heap::{CONFIGURABLE, Class, NativeFn, NativeKind, ObjId, Object, Prop, SYMBOL_BYTES, string_bytes};
use crate::heap::{CONFIGURABLE, Class, NativeFn, NativeKind, ObjId, Object, Prop, SYMBOL_BYTES};
use crate::interp::{Hint, Interp, JsResult};
use crate::symbol::{Es2015Objects, REGISTRY_ENTRY_BYTES, Sym, WellKnown};
use crate::value::{Str, Value};
@@ -90,11 +90,12 @@ fn symbol_ctor(interp: &mut Interp, _: Value, args: &[Value], construct: bool) -
fn symbol_for(interp: &mut Interp, _: Value, args: &[Value], _: bool) -> JsResult<Value> {
let key = interp.to_str(&arg(args, 0))?;
let units = crate::string_builtins::flat_charged(interp, &key)?;
crate::string_builtins::charge_units(interp, units.len())?;
if let Some(v) = interp.symbols.registry.get(&*units) {
return Ok(v.clone());
}
let extra = REGISTRY_ENTRY_BYTES.saturating_add(string_bytes(units.len()));
let sym = new_symbol(interp, Some(Str::from_rc(units.clone())), true, extra)?;
crate::string_builtins::charge_units(interp, units.len())?;
let sym = new_symbol(interp, Some(Str::from_rc(units.clone())), true, REGISTRY_ENTRY_BYTES)?;
interp.symbols.registry.insert(units, Value::Symbol(sym.clone()));
Ok(Value::Symbol(sym))
}
+2 -1
View File
@@ -86,7 +86,8 @@
//! Number hint. A Symbol converted to a string or a number without `String(symbol)` or `toString` throws a
//! `TypeError`. A string converts to a number in the `0b` and `0o` forms as well. Every iterator
//! step and every prototype a Symbol-keyed lookup passes takes fuel, and every Symbol and registry
//! entry counts against the heap limit.
//! entry counts against the heap limit. Registry lookups and insertions take fuel for the key's
//! code units, and a registered description shares the key's existing buffer.
//!
//! With [`Options::es2015`], the realm also provides `Promise` (ECMA-262 11th edition, section
//! 25.6, <https://262.ecma-international.org/11.0/#sec-promise-objects>): the constructor, `then`,
+28
View File
@@ -57,6 +57,34 @@ fn symbol_for_and_key_for_use_the_registry() {
throws("Symbol.for(Symbol())", "TypeError");
}
#[test]
fn symbol_registry_hashing_charges_flat_keys_on_hits_and_misses() {
for hit in [false, true] {
let mut realm = es2015(Limits::default());
let key = "x".repeat(32_768);
assert_eq!(realm.run(&format!("var registryKey = '{key}';")), Ok(JsValue::Undefined));
if hit {
assert_eq!(realm.run("typeof Symbol.for(registryKey)"), Ok(JsValue::String("symbol".into())));
}
realm.set_limits(Limits { fuel: 500, ..Limits::default() });
assert!(matches!(realm.run("Symbol.for(registryKey)"), Err(RunError { kind: RunErrorKind::Limit(LimitKind::Fuel), .. })), "hit={hit}");
realm.set_limits(Limits { fuel: 10_000, ..Limits::default() });
assert_eq!(realm.run("Symbol.for(registryKey) === Symbol.for(registryKey)"), Ok(JsValue::Bool(true)));
}
}
#[test]
fn symbol_registry_keeps_a_flat_key_buffer_only_once() {
let mut realm = es2015(Limits::default());
let key = "x".repeat(32_768);
assert_eq!(realm.run(&format!("var sharedKey = '{key}';")), Ok(JsValue::Undefined));
let used = realm.collect_garbage();
let room = crate::heap::SYMBOL_BYTES + crate::symbol::REGISTRY_ENTRY_BYTES + 4_096;
realm.set_limits(Limits { heap_bytes: used + room, ..Limits::default() });
assert_eq!(realm.run("var registered = Symbol.for(sharedKey); Symbol.keyFor(registered) === sharedKey"), Ok(JsValue::Bool(true)));
assert!(realm.collect_garbage() <= used + room);
}
#[test]
fn implicit_conversion_of_a_symbol_throws_a_type_error() {
throws("Symbol() + ''", "TypeError");
+3
View File
@@ -2701,6 +2701,9 @@ vectorcraft-cli run --cmd script.check --params '{"path": "Tidy Layers.jsx"}'
```
`script.run {path? | source?, name?, args?, answers?, maxFuel?}` runs a JavaScript file against the open documents.
In an ES2015 realm, `Symbol.for` lookups and insertions take fuel for the key's code units. A registered description
shares the key's existing string buffer.
File › Scripts › Other Script… (Cmd+F12) picks a `.js` or `.jsx` file and runs it the same way; the help page
https://helpx.adobe.com/illustrator/desktop/automate-visualize-data/automate-actions/install-and-run-scripts.html
describes that menu item. Pass exactly one of `path` and `source`. A `path` must end in `.js` or `.jsx`, in any
+2
View File
@@ -47,6 +47,8 @@ XMP array insertion with `XMPConst.ARRAY_LAST_ITEM` precedes the last existing i
XMP parsing rejects invalid qualified names, text other than XML whitespace beside descriptions or properties, and conflicting explicit `rdf:about` values, including empty values. Packet scanning skips other processing instructions inside a packet. Packet padding requires a real wrapper trailer and allows leading XML declarations, comments, and processing instructions. Array appends charge their added bytes without scanning existing items, and indexed property reads copy only the selected value. Pending packets count once toward the heap limit. ES5 and ES2015 library installation checks every published member against that limit. Failed serialization and packet-info scans consume fuel. Sidecar writes allow packets up to VectorCraft's 8 MiB packet limit through the host binding.
`Symbol.for` lookups and insertions take fuel for the key's code units, including registry hits on flat strings. A registered description shares the key's existing buffer. Regressions in `crates/js/src/symbol_tests.rs` cover hits, misses, and registering a rooted flat key when the heap has room for metadata but not another key buffer.
- Fold Preview orders overlapping coplanar panels by their fold tree, draws distinct planes and crossing panels by depth, and calculates poses relative to the blank's center. Each plane uses one comparison depth, and every member of a plane group must match every other member. A hinge uses its longest line across all split pieces. Tests cover flat, near-flat, nested and offset folds in `crates/three-d/src/fold/tests.rs` and `crates/three-d/src/fold/raster/tests.rs`.
- `addon.packaging.setFoldAngle` stores or resets individual fold angles for editable Crease, Partial Cut, and Perforation lines. The fold commands read those angles, and role queries report their shared value and stored-angle counts. Engine tests cover validation, locked compound members, one-step undo, native save, and SVG exports.
`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.