From 8b05d98951b2cb3432c9ad9dd9216af5638be29f Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 25 Nov 2026 04:23:32 -0800 Subject: [PATCH] Scripts: every script reads E4X and has the XML objects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The script host ran its realm with E4X off, so XML literals were syntax errors and XML, XMLList, Namespace, QName, isXMLName and setDefaultXMLNamespace were missing from every script, although vectorcraft-js has them. script.run and File › Scripts now turn E4X on for .js and .jsx files, script text, #include files, $.evalFile, eval and Function, and for a #targetengine engine. script.check lists the e4x and xml features under the language need instead of hostOnly, since VectorCraft runs them. --- crates/engine/src/script/include.rs | 2 +- crates/engine/src/script/mod.rs | 2 +- crates/engine/src/tests/script_run.rs | 34 +++++++++++++++++++ .../tests/it/script_host_vs_scriptcheck.rs | 10 +++--- crates/scriptcheck/src/catalog.rs | 4 +-- crates/scriptcheck/src/lib.rs | 5 +-- crates/scriptcheck/src/tests.rs | 7 ++++ docs/mcp.md | 17 ++++++---- docs/target-app-parity.md | 1 + 9 files changed, 65 insertions(+), 17 deletions(-) diff --git a/crates/engine/src/script/include.rs b/crates/engine/src/script/include.rs index a024949a35..ae6b41b1a1 100644 --- a/crates/engine/src/script/include.rs +++ b/crates/engine/src/script/include.rs @@ -326,7 +326,7 @@ impl Files { /// The options a file of this run is parsed with, preprocessor lines aside. pub(crate) fn options(&self) -> Options { - Options { max_source_units: MAX_TOTAL_BYTES, es2015: self.es2015, ..Options::default() } + Options { max_source_units: MAX_TOTAL_BYTES, es2015: self.es2015, e4x: true, ..Options::default() } } /// The `JSINCLUDE` folders of this process: absolute folders separated by `;`. diff --git a/crates/engine/src/script/mod.rs b/crates/engine/src/script/mod.rs index 00d0a3a371..fdec594f69 100644 --- a/crates/engine/src/script/mod.rs +++ b/crates/engine/src/script/mod.rs @@ -2009,7 +2009,7 @@ impl Session { // A `.js` script reads ECMAScript 2015; `eval`, `Function`, includes and `$.evalFile` read // code the way the script does. let es2015 = include::es2015_script(request.file.as_deref()); - let options = Options { max_source_units: include::MAX_TOTAL_BYTES.saturating_mul(2), es2015, ..Options::default() }; + let options = Options { max_source_units: include::MAX_TOTAL_BYTES.saturating_mul(2), es2015, e4x: true, ..Options::default() }; let strict = options.strict; // A kept engine reads each run's code the way that run's script does. let mut realm = match realm { diff --git a/crates/engine/src/tests/script_run.rs b/crates/engine/src/tests/script_run.rs index 3cb7dc96af..7c415160be 100644 --- a/crates/engine/src/tests/script_run.rs +++ b/crates/engine/src/tests/script_run.rs @@ -354,6 +354,40 @@ fn a_js_script_reads_optional_chains_and_coalescing_and_a_jsx_script_does_not() let _ = std::fs::remove_dir_all(&dir); } +#[test] +fn every_script_reads_e4x_and_has_the_xml_objects() { + let dir = fresh_folder("e4x"); + let write = |name: &str, text: &str| { + let p = dir.join(name); + std::fs::write(&p, text).unwrap(); + p.to_string_lossy().into_owned() + }; + let mut s = two_docs(); + let path = |p: &str| json!({"path": p}); + // Script text: literals, selectors, for each and the four constructors. + let text = "var x = 12;\n\ + vc.log(x.item.length() + ' ' + x.item.(@id == 'b').toString() + ' ' + x..item[0].@id);\n\ + var sum = 0; for each (var i in x.item) sum += Number(i); vc.log(sum);\n\ + vc.log(new XML('').b.length() + new XMLList('').length());\n\ + vc.log(new Namespace('p', 'urn:p').prefix + ' ' + new QName('urn:q', 'n').localName + ' ' + isXMLName('ok'));\n\ + vc.log(typeof setDefaultXMLNamespace + ' ' + (1 < 2));\n"; + let r = run(&mut s, text).unwrap(); + assert_eq!(r["log"], json!(["2 2 a", 3, 3, "p n true", "function true"]), "{r}"); + // A .js file, a file it includes, eval, Function and $.evalFile read XML as well. + write("lib.jsxinc", "var fromLib = .@n.toString();\n"); + write("more.jsx", "{fromLib}.toString();\n"); + let modern = "#include \"lib.jsxinc\"\nlet tag = {fromLib};\nvc.log(tag.toString());\n\ + vc.log(eval('5').toString());\nvc.log(new Function('return 6.toString()')());\n\ + vc.log($.evalFile(File($.fileName).parent + '/more.jsx'));\n"; + let r = s.execute("script.run", &path(&write("modern.js", modern))).unwrap(); + assert_eq!(r["log"], json!(["7", "5", "6", "7"]), "{r}"); + // A named engine first made by a .js run gives a later .jsx run the XML objects too. + s.execute("script.run", &path(&write("first.js", "#targetengine xmlkept\nlet k = 1;"))).unwrap(); + let later = s.execute("script.run", &path(&write("second.jsx", "#targetengine xmlkept\nvc.log(XML('2').toString());"))).unwrap(); + assert_eq!(later["log"], json!(["2"]), "{later}"); + let _ = std::fs::remove_dir_all(&dir); +} + /// A new empty folder for test `name`. fn fresh_folder(name: &str) -> std::path::PathBuf { let dir = std::env::temp_dir().join(format!("vc-script-run-{name}-{}", std::process::id())); diff --git a/crates/engine/tests/it/script_host_vs_scriptcheck.rs b/crates/engine/tests/it/script_host_vs_scriptcheck.rs index 60239864d7..2ec927bd48 100644 --- a/crates/engine/tests/it/script_host_vs_scriptcheck.rs +++ b/crates/engine/tests/it/script_host_vs_scriptcheck.rs @@ -2,8 +2,8 @@ //! the tables below, and each name that reaches outside the document has the `outside` id //! `script.check` (`vectorcraft-scriptcheck`) gives it. The names are read from a run: the own //! properties of the global object, of each object or function it holds and of each function's -//! `prototype`, with a setter listed again as `name=`. The names a plain `vectorcraft_js::Realm` also -//! has are the language's, which reach files and other apps only through the host; `eval` and +//! `prototype`, with a setter listed again as `name=`. The names a plain `vectorcraft_js::Realm` with +//! E4X also has are the language's, which reach files and other apps only through the host; `eval` and //! `Function` still have rows, since they run code the checker can't read. A name the host adds //! without a row fails the test. @@ -11,7 +11,7 @@ use std::collections::BTreeSet; use serde_json::json; use vectorcraft_engine::Session; -use vectorcraft_js::{DirectiveName, JsValue, Realm}; +use vectorcraft_js::{DirectiveName, JsValue, Options, Realm}; use vectorcraft_scriptcheck::{Limits, check}; /// The names that reach outside the document: each with a script that uses it and the `outside` id @@ -110,9 +110,9 @@ fn host_names() -> BTreeSet { text.lines().map(str::to_string).collect() } -/// The names a plain JavaScript engine has. +/// The names a plain JavaScript engine with E4X has. fn language_names() -> BTreeSet { - match Realm::new().run(LIST) { + match Realm::with_options(Options { e4x: true, ..Options::default() }, vectorcraft_js::Limits::default()).run(LIST) { Ok(JsValue::String(text)) => text.lines().map(str::to_string).collect(), other => panic!("no list: {other:?}"), } diff --git a/crates/scriptcheck/src/catalog.rs b/crates/scriptcheck/src/catalog.rs index 82fd61084b..dc4249b6a6 100644 --- a/crates/scriptcheck/src/catalog.rs +++ b/crates/scriptcheck/src/catalog.rs @@ -164,7 +164,7 @@ features! { DollarEnv "dollar.env" Files, DollarEvalFile "dollar.evalFile" Files, DynamicCode "dynamicCode" Language, - E4x "e4x" HostOnly, + E4x "e4x" Language, ExternalObject "externalObject" HostOnly, FileDialog "file.dialog" Files, FileExecute "file.execute" Files, @@ -186,6 +186,6 @@ features! { SelectTool "selectTool" HostOnly, Socket "socket" HostOnly, UnitValue "unitValue" Language, - Xml "xml" HostOnly, + Xml "xml" Language, Xmp "xmp" HostOnly, } diff --git a/crates/scriptcheck/src/lib.rs b/crates/scriptcheck/src/lib.rs index 2bd8c60fba..e74d299aaa 100644 --- a/crates/scriptcheck/src/lib.rs +++ b/crates/scriptcheck/src/lib.rs @@ -109,7 +109,8 @@ impl Kind { /// A kind of help a script needs from the app that runs it. #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub enum Need { - /// The script language's own objects and directives (`$`, `alert`, `UnitValue`, `#target`). + /// The script language's own objects, syntax and directives (`$`, `alert`, `UnitValue`, E4X + /// with the `XML` object, `#target`). Language, /// The reference app's document model (`app.activeDocument…`). Dom, @@ -120,7 +121,7 @@ pub enum Need { /// Dialogs and windows of its own. Dialogs, /// Features only the reference app has (palettes, messages to other apps, network - /// connections, native code, E4X, actions). + /// connections, native code, actions). HostOnly, } diff --git a/crates/scriptcheck/src/tests.rs b/crates/scriptcheck/src/tests.rs index fec22ed62d..45f5d02d02 100644 --- a/crates/scriptcheck/src/tests.rs +++ b/crates/scriptcheck/src/tests.rs @@ -1550,6 +1550,13 @@ fn application_methods_are_features_not_members() { assert_eq!(r.needs, [Need::MenuCommands, Need::HostOnly]); } +#[test] +fn e4x_and_the_xml_object_need_only_the_language() { + let r = report("var x = ;\nvar y = new XML(s);\nfor each (var v in x.b) {}\n"); + assert!(feature(&r, "e4x").is_some() && feature(&r, "xml").is_some()); + assert_eq!(r.needs, [Need::Language]); +} + #[test] fn type_names_compared_or_created_are_listed() { let r = report(concat!( diff --git a/docs/mcp.md b/docs/mcp.md index 68355c78f6..c6b49db93d 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -2561,11 +2561,11 @@ script, and it does not change the document or the preferences. The reply's `kin top-level `import` or `export`, such as a React `.jsx` file), `notText` (a NUL byte, or more than one byte in ten a control character, in the first 8 KiB) or `tooLarge` (over 8 MiB). For a script, the reply holds these lists: -- `needs` lists what the script needs from the app that runs it: `language` (the script language's own objects - and directives, such as `$`, `alert`, `UnitValue`, `#target` and `#targetengine`), `dom` (the reference app's - document model), `files`, `menuCommands`, `dialogs`, and `hostOnly` (features only the reference app has: - palettes, BridgeTalk, sockets, native code, XMP, the XML object and E4X, operator overloading, reflection, actions - and `selectTool`). +- `needs` lists what the script needs from the app that runs it: `language` (the script language's own objects, + syntax and directives, such as `$`, `alert`, `UnitValue`, the XML object and E4X, `#target` and `#targetengine`), + `dom` (the reference app's document model), `files`, `menuCommands`, `dialogs`, and `hostOnly` (features only the + reference app has: palettes, BridgeTalk, sockets, native code, XMP, operator overloading, reflection, actions and + `selectTool`). - `directives` lists the `#include`, `#includepath`, `#script`, `#strict`, `#target` and `#targetengine` lines, and `targets` splits each `#target` line's application specifier into `app`, `instance`, `version` and `locale`. A directive is read where it starts a line, written `#name` or `//@name`. @@ -2656,7 +2656,12 @@ also reads two ECMAScript 2020 forms (https://262.ecma-international.org/11.0/): `f?.(args)`), which give `undefined` and skip the rest of the chain when the value before `?.` is `undefined` or `null`, and `??`, which evaluates its right side only when its left side is `undefined` or `null`. Mixing `??` with `&&` or `||` without parentheses, and assigning to an optional chain, are syntax errors. In a `.jsx` file and a `source` -string, `?.` and `??` are syntax errors. Which files read these forms is VectorCraft's own rule. The script reaches the +string, `?.` and `??` are syntax errors. Which files read these forms is VectorCraft's own rule. Every script, `.js`, +`.jsx` or `source`, also reads ECMAScript for XML (E4X, ECMA-357, 2nd edition, +https://ecma-international.org/publications-and-standards/standards/ecma-357/): XML and XMLList literals, the `..`, +`.@`, `.*`, `.()` and `::` selectors, `for each`, `default xml namespace`, and the global `XML`, `XMLList`, +`Namespace`, `QName`, `isXMLName` and `setDefaultXMLNamespace`, as the XML object pages describe them +(https://extendscript.docsforadobe.dev/integrating-xml/the-xml-object/). The script reaches the app through the global object `vc`, and writes to the Script Console and runs other files through `$`: - `vc.run(id, params)` runs a command and returns its result. A command that fails throws an error the script can diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index d40a4216cd..7913b5bf43 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1098,6 +1098,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur - `vectorcraft-js` runs ECMAScript for XML (ECMA-357, 2nd edition, https://ecma-international.org/publications-and-standards/standards/ecma-357/) when `Options::e4x` is set, which it is not by default: XML and XMLList literals with embedded `{}` expressions, the `..`, `.@`, `.*`, `.()` and `::` selectors, assignment and `delete` on selected nodes, `for each`, `default xml namespace`, and the `XML`, `XMLList`, `Namespace` and `QName` objects with their methods and settings. `xml.xpath(expression[, variables])` evaluates an XPath 1.0 expression (https://www.w3.org/TR/1999/REC-xpath-19991116/) with all 13 axes and the 27 core functions, and returns the selected nodes as an XMLList in document order without repeats. Each property of `variables` binds the variable of its name, an XMLList runs the expression on each of its elements in turn, and a prefix in a name test resolves through the context element's in-scope namespaces. An expression that breaks the grammar gives a `SyntaxError`; an unknown function, a wrong argument count, an unbound prefix or variable, and a result that is not a node-set or that holds the root or a namespace node give a `TypeError`. `id()` selects nothing, and evaluation uses no native stack, takes fuel and counts against the heap limit. `` in an XML string gives a `SyntaxError`. An XML declaration at the start of an XML string, after optional white space, is checked against XML 1.0's grammar (https://www.w3.org/TR/xml/#NT-XMLDecl): a version of `1.` and digits, then an optional encoding name and an optional standalone `yes` or `no`, in that order; any other declaration, or one with a character XML does not allow, gives a `SyntaxError`. The parser takes fuel for the length of every name, white space run and declaration it scans, and for the text it searched when a quote, CDATA section, comment or processing instruction is not closed. Parsing, serializing, comparing and copying trees use no native stack, and each takes fuel and counts against the heap limit. Inserting a node into itself or its descendants throws a `TypeError` before the tree changes, a literal or XML string nested past `Options::max_depth` gives a `SyntaxError`, and a tree built past that depth stops at the heap limit. Tests: `crates/js/src/xml_tests.rs`. - Scripts: `inScopeNamespaces()`, `namespace()`, `namespaceDeclarations()`, the XPath `namespace` axis, prefixes in an XPath expression and the qualified names `name()` gives count the namespaces they collect from a node and its ancestors against the heap limit, so a node with many namespaces in scope stops the script at the heap limit instead of growing past it. `addNamespace()`, `setNamespace()`, `setName()` and `removeNamespace()` read an element's attributes in place instead of copying them, and `removeNamespace()` counts its walk of the tree; `child()` by index, `comments()`, `text()`, `elements()`, `processingInstructions()` and `normalize()` on an XMLList count their copy of its items; `replace()` counts its copy of the children it matched; and `name()` counts the prefixed name it builds. The `XML`, `XMLList`, `Namespace` and `QName` constructors, `isXMLName()`, `attribute()`, `namespace()`, `propertyIsEnumerable()`, `setName()`, `setLocalName()`, `addNamespace()`, `removeNamespace()` and `setNamespace()` count the copy they make when they flatten a long string argument, and `QName.prototype.toString()` counts its result before it builds it. Tests: `crates/js/src/xml_tests.rs`. - Scripts: assigning to a named child of an XML element (`x.b = v`) counts its list of the matching children against the heap limit, and assigning through an empty XMLList counts the chain of targets it climbs, so an assignment that would not fit stops before the tree changes. `copy()`, `toXMLString()`, `normalize()`, the `..` selector and inserting a node count the stack they keep for each open level of the tree, `copy()` and `toXMLString()` read an element's attributes in place instead of copying the list, `toXMLString()` also reads its namespace declarations in place, and `copy()` counts the declarations it copies before it copies them. `toXMLString()` counts the flat copy it makes of text or an attribute value built by joining strings. Deleting children or attributes by name, and assigning an attribute, remove the nodes in place instead of building a second list. `toXMLString()` counts the set of prefixes it passes looking up a namespace, and picks a new `ns` prefix in one pass over the declarations in scope. Inserting an XMLList, and assigning one to an item of an XMLList, count their copy of the list's items. Parsing counts the open elements, the text it gathers, each tag's attributes and the sets that check them, and the namespace declarations it makes. Comparing XML values, converting them to strings, and reading a name, a namespace or embedded text from a string built by joining strings count the flat copy they make; an attribute name read from a string counts its copy. Tests: `crates/js/src/xml_tests.rs`. + - Scripts: `script.run` and File › Scripts run every script with E4X on, `.js` and `.jsx` files, `#include` files, `$.evalFile`, `eval` and `Function` alike, so XML literals and the global `XML`, `XMLList`, `Namespace`, `QName`, `isXMLName` and `setDefaultXMLNamespace` work as the XML object pages describe them (https://extendscript.docsforadobe.dev/integrating-xml/the-xml-object/). `script.check` lists the `e4x` and `xml` features under the `language` need instead of `hostOnly`. Tests: `crates/engine/src/tests/script_run.rs`, `crates/scriptcheck/src/tests.rs`. - **UI:** Illustrator 2026 layout restyled to measured values: - Medium Dark theme, categorized and Advanced toolbars (a tool group's flyout opens on a right press, a long press or a press on its corner triangle), 35 pt document tabs, 33 pt panel tabs. - Hint bar, contextual task bar, 19 dock panels with ≡ menus.