Scripts: assigning documents throws in strict mode and is ignored otherwise

The global `documents` has only a getter. The docs and the module and
test comments said only that assigning it keeps its value. They now say
that the assignment is ignored outside strict mode and throws a
TypeError in strict mode code or with `#strict on`, and the test also
checks the `#strict on` case.
This commit is contained in:
dotCooCoo committed 2026-11-27 18:46:40 -08:00
1 parent 5d70217e0c
commit efb7911139
3 files changed
+9 -4

No files matched your search

+2 -1
View File
@@ -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
+4 -1
View File
@@ -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"));
+3 -2
View File
@@ -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