Commit Graph
196 Commits
Author SHA1 Message Date
BFlat 11a26acb0b Merge pull request #9109 from dotCooCoo/feat/js-es2020-optional-chaining-nullish
Scripts: .js scripts read optional chains and the ?? operator
2026-11-24 16:09:45 +07:00
BFlat cf2c4ae3f7 Merge pull request #9187 from dotCooCoo/fix/js-dollar-stack-script-frame
Scripts: $.stack starts with a line that names the running script
2026-11-24 16:08:08 +07:00
BFlat 7696b503e6 Merge pull request #9079 from dotCooCoo/feat/js-es2015-block-arrow-template
Scripts: .js scripts run let, const, arrows, templates, default and rest parameters and spread
2026-11-24 16:06:07 +07:00
dotCooCoo 05d45599dd JavaScript: heap stops leave no global name, and own elements hide prototype getters
- A script's global let and const names are added only after the room
  for them and the declarations is checked, so a run that stops at the
  heap limit leaves no uninitialized name behind and the same script
  runs once the limit is raised.
- Spread of an array with a length too long for an array literal throws
  RangeError at once when every prototype getter with an index name is
  hidden by an own property of the same name earlier in the chain. The
  scan takes one unit of fuel for each earlier object it looks in, and
  stops where the fuel runs out.
- A spread test now checks the heap total right after the limit stops
  the spread, before a later step could collect, and a larger limit
  lets the same spread complete.
2026-11-24 00:13:24 -08:00
dotCooCoo f205705617 Scripts: $.stack starts with a line that names the running script
$.stack is the current stack trace
(https://extendscript.docsforadobe.dev/extendscript-tools-features/dollar-object/).
It now starts with a line holding the run's name in square brackets, such
as `[main.jsx]`, the name the console shows for the run: the `name` given
to `script.run`, else the `#script` name, else the file's name, else
`script`. The frames follow as before. Scripts that look for a bracketed
line in the trace to find their own name, for example to name a
preferences file, now find it.

The name line comes before the `…` line that stands for frames past 64.
A realm without a name (`Realm::set_script_name(None)`) writes no such
line.

Docs: docs/mcp.md ($ object table), docs/target-app-parity.md.
2026-11-23 11:17:06 -08:00
dotCooCoo 54b9504cb5 JavaScript: a function body reserves room for its arguments object
The call reserves room for the declarations and the arguments object
before the body's let and const environment takes some of it. The body
then reserved room for its declarations again, but not for the
arguments object, so making the object could take the heap estimate
past the limit until the next check. The body now reserves both, with
the arguments size from one helper that the call also uses.
2026-11-22 17:52:55 -08:00
dotCooCoo 723e52c5ec Merge #9079 into feat/js-es2020-optional-chaining-nullish 2026-11-22 17:15:41 -08:00
dotCooCoo d61d494bea JavaScript: declarations and spread checks stay within the heap and fuel limits
- A function body, after default parameters or plain ones, and eval code
  check the heap for their function declarations and variables after
  their `let` and `const` environment is made, so the estimate stays
  within the limit while the declarations are bound.
- Looking for an index getter before spreading a long array takes a unit
  of fuel for each property it inspects, as well as for each object.
- An index accessor with only a setter no longer delays the check of an
  array of length 4294967295 when spread begins, since reading the
  elements does not run it.
- The eval test with `with` now gives the `with` object an `x`, and the
  function case declares its own `var x`, so a function closing over
  the wrong environment fails it.
2026-11-22 16:09:51 -08:00
dotCooCoo 6b8c10999d JavaScript: spread and default parameters stay within the heap limit
- Spreading an array checks the room in the result as each element is
  read, so a getter that shrinks an array of length 4294967295 gives the
  elements it reads. An array no getter reads, and any other object, is
  still checked against its length when spread begins.
- Spread counts each element's index name, and each character of a
  string, against the heap as it reads them.
- A function with default or rest parameters checks the heap again before
  its body's environment and declarations are made, since the parameters'
  values may have used the room the call reserved.
- Without the ES2015 option, a function that eval code declares on the
  global object closes over the global scope, so it sees the scripts'
  `let` and `const` names, as functions of global code do.
- With the ES2015 option, a global `var` whose name the global object
  only inherits gets its own property.
- The test262 ES2015 subset runs a test whose source does not tokenize,
  so the error counts as a failure instead of a skip.
2026-11-22 11:00:34 -08:00
dotCooCoo 1596380f23 Merge #9079 into feat/js-es2020-optional-chaining-nullish 2026-11-22 10:48:32 -08:00
dotCooCoo 15fefc9930 JavaScript: block functions, spread and global declarations follow ECMAScript 2015
- A block function whose name a function of an enclosing block declares is
  not assigned to the variable of that name.
- A labelled function in a block is made when the block is entered, and the
  parser checks it against the `let` and `const` names of its statement list.
- A function standing alone as an `if` branch gets a block of its own.
- Spread reads a `String` object by code point, and reads an array's length
  again before each element.
- A `var` or function declared on the global object stops a later `let` or
  `const` of its name until its property is deleted, and a `var` the global
  object cannot take is a `TypeError` before anything is declared.
- A call keeps its callee, receiver and arguments reachable until its frame
  holds them, and global and eval code keep their environment and their heap
  charge until their frame is pushed.
- Template objects are released when no code that can run holds their sites,
  even when one code has several sites.
- `Realm::set_es2015` during a run applies once the run ends.
- A template piece that spans lines does not let a preprocessor line start
  after it on its last line.
2026-11-22 08:21:30 -08:00
dotCooCoo 001e9ec83e JavaScript: the ?? precedence test tells the two groupings apart
`(null ?? 1 | 2)` and `(null ?? 0 ? 'a' : 'b')` give the same result under
either grouping. `(1 ?? 2 | 4)` gives 5 and `(1 ?? 0 ? 'a' : 'b')` gives 1
when `??` binds the wrong way, so the test now fails on a wrong precedence.
2026-11-22 07:59:50 -08:00
dotCooCoo 74d481ef68 JavaScript: strict eval code keeps its own environment through collections
Strict eval code runs in a new declarative environment that no frame holds
until its declarations are made. Making the scope of its let and const names
reserves heap, and a collection there freed that environment, so the new
scope's outer link pointed at a reused slot. The environment is now a root
while the declarations are made, for direct and indirect eval.
2026-11-22 07:08:44 -08:00
dotCooCoo faa5e3062c Scripts: .js scripts read optional chains and the ?? operator
With Options::es2015, vectorcraft-js reads and runs two ECMAScript 2020
forms: optional chains (a?.b, a?.[key], f?.(args) and the accesses and
calls after them) and ??.

- An optional step that finds undefined or null ends the whole chain
  with undefined, without evaluating its other keys and arguments.
  Parentheses end a chain. a?.b() and a.b?.() call with a as this,
  (a?.b)() does too, eval?.(code) is an indirect eval, and delete a?.b
  is true when a is undefined or null.
- ?? keeps any left side other than undefined and null.
- ?. before a digit still reads as ? and a number (a?.5:1).
- Mixing ?? with && or || without parentheses, assigning to or updating
  an optional chain, a tagged template after one and new a?.b() are
  syntax errors.

Two new jump instructions test for undefined and null, and the verifier
checks both of their paths. A chain of any length compiles with a loop.
.jsx files and source strings stay ES5.1, where ?. and ?? are syntax
errors.

The test262 ES2015 subset now also reads expressions/optional-chaining
and expressions/coalesce: 426 of 426 negative parse runs and 591 of 615
other runs pass with the option. The 24 failing runs are the same as
before this change.
2026-11-22 06:45:48 -08:00
dotCooCoo 33bcf63381 JavaScript: a global function declaration reads the global object's own property
With ES2015 scripts, a function declaration was judged by a property the
global object inherits, so a fixed property on Object.prototype stopped
`function name() {}`. The check now reads the global object's own
property, as ECMA-262 2015 section 8.1.1.4.16 does, and declares nothing
when the global object is not extensible and has no property of that
name. Indirect eval code makes the same check for all of its functions
before it declares any of them, and a function declaration never adds a
property to a global object that is not extensible.
2026-11-22 01:13:14 -08:00
dotCooCoo 4447e02955 JavaScript: a rest parameter checks the heap before its array is made
A call to a function with a rest parameter built the array of its extra
arguments without reserving room for it, so `f.apply(null, big)` could
push the heap estimate past the limit. The call now counts the rest
array, its binding and one property per extra argument in the room it
reserves before the function's environment is made.
2026-11-22 00:52:01 -08:00
dotCooCoo e5a1f339c3 JavaScript: spreading a string counts its flattened copy against the heap
Spreading a concatenated string (`[...s]`, `f(...s)`) flattened it before
any limit was checked, so a script could make the host build the whole
copy before the per-element fuel and heap accounting ran. The spread now
flattens through the same counted helper the string built-ins use, which
ends the run with the heap limit before the copy is made.
2026-11-22 00:44:02 -08:00
dotCooCoo e1e99023c2 Scripts: a failed UnitValue install leaves no constructor or operators behind
When defining the UnitValue members fails part way, the realm turns the
unit operators off again and restores the global UnitValue to what it was
before the call, so a second add_unit_values() installs everything.
2026-11-22 00:30:42 -08:00
dotCooCoo af91c28c64 Merge main into feat/scripts-unitvalue 2026-11-22 00:30:37 -08:00
dotCooCoo e717698e02 Scripts: Annex B block functions are judged one declaration at a time
A function declared in a block sets the enclosing variable of its name
only when that declaration itself is eligible, so a declaration inside
a let of the same name no longer assigns the variable because another
declaration of that name elsewhere in the body is eligible.
2026-11-21 23:37:47 -08:00
dotCooCoo 2ba5dd3735 Scripts: spread reads lengths with ToLength and function scopes stay rooted
Spread of an object with a length property reads the length with
ToLength, so a negative or NaN length adds no elements instead of
wrapping to a count near 2^32. A function body's environments stay on
the collector's roots while its scope, functions and arguments object
are made.
2026-11-21 23:31:38 -08:00
dotCooCoo 21ce815b34 Scripts: global let and const reach functions from every run
Global code runs in the realm's lexical scope in either language, so a
function an earlier ES5.1 run, an indirect eval or the Function
constructor made can read a let or const a later .js run declares. With
the ES2015 option, a script whose function cannot replace a property of
the global object throws a TypeError before any of its let or const
names is declared, so a failed run leaves no name uninitialized.
2026-11-21 23:24:52 -08:00
dotCooCoo 8d0001308f Merge main into feat/js-es2015-block-arrow-template 2026-11-21 22:52:36 -08:00
dotCooCoo 47840d28e3 Scripts: the large km to mi test checks the converted value
The expected value multiplied 1e307 by 1000 before dividing, which
overflows to infinity, so the closeness check accepted any finite
result. The expected value now divides the factors first.
2026-11-21 21:04:03 -08:00
dotCooCoo 7d3094afe6 Scripts: .js scripts run let, const, arrows, templates, default and rest parameters and spread
vectorcraft-js gains Options::es2015, which reads and runs these
ECMAScript 2015 forms: let and const with block scope and their
temporal dead zone, a new let binding for each loop iteration,
function declarations scoped to their block (with the Annex B.3.3
variable outside strict mode code), arrow functions, template
literals and tagged templates, default and rest parameters, and
spread in array literals, calls and new. Spread reads arrays,
strings by code point and objects with a length, by index, and
throws a TypeError for anything else until iterators are added.

Eval code outside strict mode code cannot declare a var that clashes
with a let or const around it, or with a parameter inside a default
value. Spread, template objects and the new scopes take fuel and
count against the heap limit, and nested arrows and templates count
against the depth limit.

script.run sets the option for a .js file; eval, Function, #include
files, $.evalFile and a kept #targetengine read code the way the
running script does. A .jsx file and a source string stay ES5.1.

The test262 runner gains an ES2015 subset run, read without and with
the option. docs/mcp.md and docs/target-app-parity.md describe the
new forms.
2026-11-21 20:43:20 -08:00
dotCooCoo 7e5b421db2 Scripts: UnitValue pixels and percentages use the left object's base
With two UnitValues and a left one in px or %, the right one is now
converted with the left one's baseUnit, so a 1 px value with a 2 pt base
plus 1 in gives 37 px. Conversions keep their intermediate values in
range, so a result that is a finite number no longer fails because a
step on the way overflows or reaches 0.
2026-11-21 20:25:38 -08:00
dotCooCoo 1ab09c8978 Scripts: UnitValue measurements convert and calculate with their units
Scripts get the global UnitValue constructor: a number with one of the
length units (inches, feet, yards, miles, millimeters, centimeters,
meters, kilometers, points, picas, traditional points and picas,
ciceros), pixels or percent. as() and convert() give or change the
unit, baseUnit sets what one pixel and 100% measure, and the arithmetic,
comparison and unary operators calculate with the object's number. With
two objects the right one is converted to the left one's unit.

Conversions go through exact ratios to the inch, so 1 in is exactly
72 pt. An unknown unit or text makes an invalid object; converting it or
using it with an operator, a result that is not finite and a comparison
with a number that is not finite throw a RangeError.

A realm without UnitValue keeps the standard operators. docs/mcp.md
describes the class.
2026-11-21 19:56:57 -08:00
BFlat 7ad52eacb8 Merge pull request #9017 from dotCooCoo/fix/test262-runner-coverage
Tests: the test262 runner parses and runs the Annex B tests
2026-11-22 10:53:45 +07:00
BFlat 6767fefb11 Merge pull request #8968 from dotCooCoo/feat/script-file-hidden-create-alias
Scripts: File.hidden can be set and File.createAlias makes a link within the grants
2026-11-22 10:50:17 +07:00
dotCooCoo 4ed3826e3b Tests: an Annex B tree without its language folder fails
A suite with test/annexB but no test/annexB/language skipped the Annex B
parse test and the language group of annex_b_runs. Both now skip only
when test/annexB is absent, and fail when it is present without its
language folder. The Annex B built-ins folders still skip one by one.
2026-11-21 05:21:17 -08:00
dotCooCoo bd752e95ad Tests: an Annex B folder whose tests are all skipped fails
annex_b_runs counted skipped tests toward its check that a folder has
tests to run, so a folder where every test needs a missing built-in or
is asynchronous passed without running anything. It now requires at
least one test to run, as the ES5 groups do.
2026-11-21 05:17:25 -08:00
dotCooCoo 3f243e90f8 Tests: an unreadable Annex B folder fails the test262 runner
The Annex B runners checked their folders with Path::exists, which returns
false when the metadata cannot be read, so a folder that could not be
searched skipped the tests as if it were absent. They now use try_exists:
only an absent folder skips, and a metadata error fails the test.

The parity doc now says that an interpreter panic fails annex_b_runs and
makes cargo xtask test262 exit non-zero, while conformance failures do not.
2026-11-21 05:13:35 -08:00
dotCooCoo 248936eec3 Tests: the test262 runner parses and runs the Annex B tests
The test262 runner read only test/language and a few built-ins folders,
so the Annex B tests were never counted, among them the for-in variable
with an initializer that must parse in sloppy code and give a
SyntaxError in strict code.

- annex_b_parse_subset parses every test under test/annexB/language
  without a feature tag, of any edition, in the modes its flags give,
  and writes annexb-parse-failures.txt.
- annex_b_runs runs those tests and the test/annexB/built-ins tests for
  String, Date, RegExp and Function through the interpreter and writes
  annexb-language-failures.txt and annexb-builtins-failures.txt. The
  escape and unescape folders still run once, with the ES5 built-ins.
- A suite without test/annexB skips both; a folder there with nothing
  to parse or run fails them. Conformance failures stay in the reports.
- The runner reads only regular files inside the suite: it does not
  follow symbolic links, refuses an includes: name that leaves harness/,
  refuses a file over 8 MiB before reading it, and fails on a folder it
  cannot read instead of skipping it.

Docs: docs/target-app-parity.md, the xtask test262 module comment.
2026-11-21 04:43:42 -08:00
dotCooCoo 999521e391 Scripts: File.hidden can be set and File.createAlias makes a link within the grants
On macOS and Linux, setting `hidden` renames the file or link in its folder with
one leading dot added, or its leading dots taken off. Both the old and the new
name must be places the script may write, and a name of dots alone, a name in
use and a folder are refused. A file the object has open stays open at the new
path.

`createAlias(target)` makes a symbolic link at the object's path to the real
path of a file the script may read. The link's place must be one the script may
write where nothing is, a link that leads nowhere included; the settings folder
is refused for both. When a folder above the link's place is replaced by a link
while the alias is made, the new link is removed and the call fails. `hidden`
reads a link's own name, and setting `hidden`, `rename` and `remove` act on the
link itself.

On Windows both still set `error` and change nothing. `execute` stays
unavailable.

Behavior: https://extendscript.docsforadobe.dev/file-system-access/file-object/
and https://extendscript.docsforadobe.dev/file-system-access/using-file-and-folder-objects/
2026-11-20 21:38:37 -08:00
dotCooCoo 417ed94431 Script checker: setting a File's length, hidden or readonly counts as a file write
Setting a File object's length truncates or pads the file, and setting
readonly or hidden changes it, but script.check reported no outside
category for those assignments. It now reports file.write and
filesWritten for them: plain and compound assignment, ++ and -- before
or after, and the property name as a string literal in brackets.

A new integration test lists every global and member the script host
adds to the JavaScript engine (the own properties of the global object,
of each object or function it holds and of each function's prototype,
compared with a plain engine) and fails when one has no row. Each name
that reaches outside the document has a probe script, and the test
checks that script.check gives it the expected outside id. vc is listed
as not checked: script.check reads scripts written for the reference
app's scripting, and what vc.run does depends on the command. The test
also checks that the checker lists every preprocessor directive the
host reads, through the new DirectiveName::ALL.

File object properties:
https://extendscript.docsforadobe.dev/file-system-access/file-object/
2026-11-20 18:36:13 -08:00
BFlat 48c8ae52a9 Merge pull request #7802 from dotCooCoo/fix/text-a-script-throws-itself-is-not-translated
Scripts: the status bar shows text a script throws as it is
2026-11-19 00:39:21 +07:00
dotCooCoo aa1653690e Merge main into feat/script-file-folder-write 2026-11-15 20:02:53 -08:00
dotCooCoo b1a10c1349 Merge main into fix/text-a-script-throws-itself-is-not-translated 2026-11-15 18:40:02 -08:00
dotCooCoo 16d1ed57ac Scripts: the status bar shows text a script throws as it is
A failed run's status translated a script's own thrown text whenever it
matched one of the app's messages, so `throw new Error('invalid array
length')` read as the app's translated error. Run errors now say whether
their message is the script's own text: errors the interpreter or a host
function throws are marked when they are made, stay the app's own when a
script catches and rethrows them unchanged, and become the script's text
when it changes their name or message. The status bar translates the
words around such a message and shows the script's text unchanged.

- `script.run`'s failed report adds `messageOrigin` (`script` or
  `built-in`); `message`, `kind` and the console line are unchanged.
- The advice about other applications' objects follows only the app's
  own reference errors, not the same text thrown by a script.
2026-11-14 20:42:01 -08:00
dotCooCoo 8a007b03ad Merge main into feat/script-file-folder-write 2026-11-14 19:35:28 -08:00
dotCooCoo cff8f2a30d Merge main into fix/js-interp-errors-translated 2026-11-14 16:00:59 -08:00
dotCooCoo a750c997be Scripts: a property name converted from an object stays counted while its getter or setter runs
A computed name such as o[key], where key's toString returns a rope,
is flattened into a copy that only native code held. A getter or
setter that started a collection dropped that copy from the heap
estimate, so the live heap could pass the limit by one name per
nested access. Indexed reads, ++ and -- on an indexed property, and
Object.defineProperty now keep the converted name reachable while the
accessor runs.
2026-11-14 13:51:09 -08:00
dotCooCoo e4a7d419cc i18n: script identifiers in error messages stay as written
The not-defined and function-declaration errors name the identifier
with an {ident} placeholder, whose value is never translated, so a
script name that matches another message (such as damaged) is shown
unchanged.
2026-11-14 07:51:01 -08:00
dotCooCoo 429f37a221 i18n: script interpreter core errors are translated in every complete-message catalog
A script run that fails on an error the interpreter's core throws (an
unknown name, a property of null or undefined, a property that cannot
be defined, assigned or deleted, a value that is not a function or a
constructor) showed that error in English in the status bar. Seven of
these messages were built in a variable, so the untranslated-strings
report did not list them. Of the 23 complete-message catalogs, 17 had
no rows for the interpreter's messages, and the other six (de, it, pl,
pt-br, uk, zh-hans) had none for "invalid assignment target", the
reasons or the error types.

- Every complete-message catalog has rows for these errors, for the
  reasons a property cannot be defined or assigned, for "invalid
  assignment target", and for the error types (TypeError: {e} and the
  others), so the failed-run line translates the message after the
  type. Names, property names, null, undefined, 'in', 'instanceof' and
  the type are kept, and e.message stays English for scripts. French
  rows keep the no-break space before the colon.
- A value a message quotes in '...' is shown as written, like one in
  "...", so a property named like a translated message keeps its name.
- An error about a property of null or undefined reached through a
  computed key or a member assignment named an empty property
  ("cannot read property '' of null"). It now names a key that is not
  an object and is at most 256 units long, and otherwise says "cannot
  read a property of null" or "cannot set a property of undefined". An
  increment (u['k']++) and a delete (delete null[true]) give the
  "cannot read" form.
- The message scan reads the interpreter's .reject and .reject_bool
  reasons.

Tests: i18n::tests::script_interpreter_core_errors_are_translated,
message_scan_reads_script_interpreter_errors,
interp_tests::errors_about_null_and_undefined_name_the_property.
2026-11-13 21:21:38 -08:00
dotCooCoo 64662b435b Scripts: a file opened under a withdrawn grant is not read
When a run evaluated code that withdrew a kept grant, a File opened under that grant still gave the bytes it held to read, readln and readch, and seek to the end showed its length. Those calls now give Script file access denied and set error, and eof is true. docs/mcp.md says so.
2026-11-13 20:34:27 -08:00
dotCooCoo 0300f70950 Scripts: file and folder dialogs are native functions that pause the script
File.openDialog, File.saveDialog, Folder.selectDialog and the openDlg, saveDlg and selectDlg methods are now built-ins written in Rust instead of JavaScript source compiled when File and Folder are installed. The interpreter gains a native function form that asks the host for a value: it gives the host call to make and a function that takes the answer. When the host waits, the run pauses at the call, and the answer goes to that function before the next instruction, so a filter function or an exception it throws runs at the dialog's call. Arguments, filters, multiSelect, the start folder and the null and error answers work as before.
2026-11-13 14:45:05 -08:00
dotCooCoo 6644dc4686 Merge main into feat/script-file-folder-write 2026-11-13 11:00:25 -08:00
dotCooCoo b153a3d7a6 Scripts: a file whose close could not write it stays open, so a later close tries again 2026-11-13 10:31:59 -08:00
dotCooCoo dbfffc8ecb Scripts: commands read through the gate in runs the person starts, and the grants file is not written over when it cannot be read
- A command a script runs reads only where the script may, also in a run the person started; only
  reads of the app's own folders inside the command are exempt.
- Always and script.grants.revoke leave a grants file they cannot read as it is, and fail.
- script.grants names a path outside the automation read roots by its file name alone.
- copy reads the source once, within the 8 MiB limit, writes those bytes, and gives the copy the
  source's permissions.
- write joins its values as UTF-16 before making them text, so a surrogate pair split between two
  values is one character.
2026-11-13 10:09:27 -08:00
BFlat c7adea5518 Merge pull request #7144 from dotCooCoo/fix/script-line-numbers
Scripts: $.line and $.stack give the line of the file the code is in
2026-11-14 00:51:19 +07:00