diff --git a/crates/engine/src/script/dom.rs b/crates/engine/src/script/dom.rs index 46ca2824d4..cd2307d642 100644 --- a/crates/engine/src/script/dom.rs +++ b/crates/engine/src/script/dom.rs @@ -28,7 +28,8 @@ //! false then. Assigning to such a name throws the same error. //! - Assigning `activeDocument` or `selection` without `app.` assigns `app.activeDocument` or the //! active document's selection. A top-level `var selection = ...` does the same and does -//! not make a variable of the script. Assigning `documents` keeps its value. +//! not make a variable of the script. An assignment to `documents` is ignored outside strict +//! mode and throws a `TypeError` in strict mode code or with `#strict on`. //! - Collections list documents in tab order. The objectReferences page says `documents[0]` is //! always the active document; VectorCraft does not follow that yet. //! - `pageItems` lists every object, with the objects inside groups and compound paths after the diff --git a/crates/engine/src/tests/script_dom.rs b/crates/engine/src/tests/script_dom.rs index c1aa77e6a6..2f7bf70a1d 100644 --- a/crates/engine/src/tests/script_dom.rs +++ b/crates/engine/src/tests/script_dom.rs @@ -1841,7 +1841,8 @@ fn objects_of_the_object_model_print_their_class_and_name() { } /// `activeDocument`, `documents` and `selection` without `app.` read the application's members, and -/// assigning one assigns the member: `selection` selects, `documents` keeps its value. +/// assigning one assigns the member: `selection` selects, and `documents` keeps its value outside +/// strict mode and throws a `TypeError` in strict mode code or with `#strict on`. #[test] fn the_application_members_can_be_named_without_app() { let (mut s, a, b) = doc(); @@ -1868,6 +1869,8 @@ fn the_application_members_can_be_named_without_app() { assert!(failure(&mut s, "activeDocument = 5;").contains("not a Document")); let e = failure(&mut s, "'use strict'; documents = 5;"); assert!(e.contains("TypeError") && e.contains("cannot assign to property 'documents': it has only a getter"), "{e}"); + let e = failure(&mut s, "#strict on\ndocuments = 5;"); + assert!(e.contains("TypeError") && e.contains("cannot assign to property 'documents': it has only a getter"), "{e}"); // With no document open, reading `activeDocument` throws as `app.activeDocument` does. let mut s = Session::new(); assert!(failure(&mut s, "activeDocument;").contains("No active document")); diff --git a/docs/mcp.md b/docs/mcp.md index 1bbe49574d..e99add4aa5 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -2777,8 +2777,9 @@ other files through `$`: [Accessing and referencing objects](https://ai-scripting.docsforadobe.dev/scriptingJavascript/objectReferences/) describes; in VectorCraft that holds for `activeDocument`, `documents` and `selection`. VectorCraft's own rules: assigning `activeDocument` or `selection` without `app.` assigns the application's member. A top-level - `var selection = ...` does the same and does not make a variable of the script. Assigning `documents` keeps its - value. `app.documents` + `var selection = ...` does the same and does not make a variable of the script. An assignment to `documents` + leaves its value unchanged. Outside strict mode the assignment is ignored, and in strict mode code + (`'use strict'`) or with `#strict on` it throws a `TypeError`. `app.documents` (https://ai-scripting.docsforadobe.dev/jsobjref/Documents/) has `length`, `[i]`, `index(key)`, `getByName(name)` and `add(colorSpace?, width?, height?, numArtBoards?, artboardLayout?, artboardSpacing?, artboardRowsOrCols?)`, which runs `file.new` (`artboardRowsOrCols` is the number of rows for `GridByCol` and `RLGridByCol`, and of