Commit Graph
13 Commits
Author SHA1 Message Date
dotCooCoo 5c165ef7ff Scripts: spread, global lets and rest parameters follow the limits and scopes
- Spread keeps its list of elements counted against the heap limit until
  the elements are the array's properties, so a list and an array that
  only fit one at a time end the run with the heap limit.
- A script stopped at the fuel or heap limit while its functions and
  variables are declared removes its `let` and `const` names from the
  global scope, so running it again in the same realm does not throw a
  redeclaration error. A script that throws once it runs keeps them.
- A function whose only non-simple parameter is a rest parameter keeps
  its parameters and body in one environment (ECMA-262 2015 section
  9.2.12), so `var r` in the body or in direct eval is the parameter.
  Its `arguments` object still does not follow the parameters.
2026-11-22 07:33:26 -08:00
dotCooCoo 029482d0d7 Scripts: class code, eval and block functions follow the ES2015 rules
- Direct eval in a derived constructor, or in an arrow function inside
  one, reads the constructor's this binding when it runs, so
  eval('this') before super() throws a ReferenceError, and an arrow
  function made by the eval code sees this once super() returns.
- A class's heritage and computed keys run as strict mode code inside
  sloppy code; the code after the class, and a handler of what they
  throw, stay sloppy.
- A super property write that cannot be made throws with
  Realm::set_strict_writes, as other property writes do.
- A labeled function in a block is made when the block is entered and
  declares its name in the block, so { let f; L: function f() {} } is
  a SyntaxError. A block function whose name a function of an
  enclosing block also declares no longer assigns the outer variable.
- Methods reject duplicate parameter names outside strict mode code.
- With a global object that is not extensible, a var that would add a
  property throws a TypeError before the script or the eval code
  declares anything.
- The receiver, arguments and new.target of a call, a strict eval's
  own environment and spread's elements stay reachable while their
  scopes and properties are made, and spread counts the array's new
  properties against the heap limit before it adds them.
- Tagged template strings objects are dropped once nothing but the
  cache holds their code, also for code with several sites.
- A //@ or # directive after a template with a substitution that
  spans lines is read only at the start of a line.
- The code size estimate counts a block scope's entries by their size.
2026-11-22 06:41:35 -08:00
dotCooCoo 95d1f70041 Scripts: .js scripts define classes with extends, super and new.target
With Options::es2015, vectorcraft-js reads and runs ECMAScript 2015
classes: declarations, scoped to their block like let, and
expressions, with extends, static members, getters and setters and
computed method names. Class code is strict mode code, methods are
not enumerable and cannot be constructed, and calling a class without
new throws a TypeError.

A derived constructor's this throws a ReferenceError until super(...)
returns, and its default constructor passes its arguments on.
super.name and super[key] read, call and write through the prototype
of the method's home object, in class methods and in object literal
methods, which ES2015 allows in a .js script. new.target names the
constructor new was applied to, in functions and their arrow
functions. A class can extend null, a function, a class, or the
built-in constructors Object, Function, Array, String, Number,
Boolean, RegExp, Date and the error types; extending any other
built-in throws a TypeError. Each class and method takes fuel and
counts against the heap limit, and deep constructor chains stop at
the frame limit. A .jsx file and a source string stay ES5.1, where
class syntax is a SyntaxError.

The test262 runner adds the class, super and new.target tests to its
ES2015 subset (1,125 tests). With the option, 554 of 554 negative
parse runs and 1,527 of 1,633 other runs pass; the failing runs use
Object.setPrototypeOf, RegExp.prototype.flags, function name
properties, a configurable length, the caller and arguments
restrictions, or super and new.target in direct eval.

Docs: docs/mcp.md, docs/target-app-parity.md.
2026-11-22 01:17:22 -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 b172e3672d JavaScript: for each evaluates its target before reading the value
A for each loop read the property's value before evaluating its target,
so a target such as (o.p = 2, t).v, t[(o.p = 3, 'w')] or a bare
@[(o.p = 2, 'k')] stored the value from before the target ran. The
target's object and name are now evaluated first and the value is read
after them (ECMA-357 section 12.3).
2026-11-11 20:39:02 -08:00
dotCooCoo db97cc1a8f JavaScript: a bare E4X name inside with or a filter can be assigned
With Options::e4x set, an E4X name standing alone (@a, @ns::a, @[expr],
ns::a, *) is now a valid target for =, compound assignment, ++, --,
delete and for/for each loops, as well as a read. The target is the
nearest XML or XMLList value in scope whose [[HasProperty]] accepts the
name (ECMA-357 section 11.1). The name is evaluated once, and the
target resolves before the right-hand side runs.

When no XML value in scope holds the name, a read or write throws a
ReferenceError and creates no child or attribute. A read no longer
falls back to the first XML value in scope, so a filter such as
list.(@id == '1') throws when an item has no @id and no outer XML
value holds one, instead of treating that item as not matching.
2026-11-11 19:35:59 -08:00
dotCooCoo c4d323eb28 Merge main into feat/js-e4x-xml
# Conflicts:
#	crates/js/src/interp.rs
2026-11-11 07:48:21 -08:00
dotCooCoo af22ac8f50 Scripts: $.stack names a declared function after its declaring function returns
The compiler now keeps a function declaration's name with its code, so
$.stack no longer shows [anonymous] for a declared function that is
called after the function that declared it has returned. The member test
expects "Web" for $.os in the wasm build, as the engine gives there.
2026-11-11 04:23:32 -08:00
dotCooCoo 08eca05731 Scripts: #strict on runs the script with strict write checks instead of refusing it
`#strict on` and `//@strict on` no longer end the run as unsupported. They
turn on the checks the dollar-object help page gives for `$.strict`
(https://extendscript.docsforadobe.dev/extendscript-tools-features/dollar-object/):
an assignment to a read-only property throws a TypeError, and so does a new
property on an object that takes none.

VectorCraft's own rules: a getter-only property counts as read-only; the
objects that take no new properties are the non-extensible ones
(preventExtensions, seal, freeze, and the frozen vc and $ objects); the last
`#strict` line of the script and its includes sets the whole run, and runs
without one are unchanged; eval and Function take the checks of the code
that compiles them; a file $.evalFile runs keeps its own line's checks for
its code and functions, or takes the caller's without one. The rest of ES5
strict mode stays with 'use strict'.

The js crate carries the setting per compiled source
(Realm::set_strict_writes, and a strict_writes callback on
HostItem::Evaluator), and applies it only to property assignments.
2026-11-11 02:04:49 -08:00
dotCooCoo 693031c509 Scripts: #include and the other preprocessor lines run, and $.evalFile runs a file
Before a script runs, `script.run` reads its preprocessor lines (`#` or
`//@` at the start of a line, outside strings and comments):

- `#include` and `//@include` put another file's text in place of the
  line, looked for beside the including file, then in each
  `#includepath` folder, then in each `JSINCLUDE` folder. A later
  `#includepath` replaces the list.
- `#script` names the run unless `name` is given; `#target` takes any
  value; `#strict off` is taken. `#strict on`, `#targetengine` and
  `#engine` are refused as unsupported, and any other `#name` as
  unknown.

`$.evalFile(path, timeout?)` runs a file in the same global environment
and returns its last value, `$.fileName` is the file being run and
`$.includePath` the include folders.

A script run from a file reads these files only in its folder and the
folders below it. Paths with a `..` name, links or junctions that lead
out, device names, streams and network paths are refused; a script
given as text reads none. A run reads at most 64 files 16 levels deep,
32 MiB of source in all and 1,024 paths looked up. An error in an
included or evaluated file is reported at that file's line and column,
and the report's new `file` field names it.

Docs: docs/mcp.md (script.run, Script Console), docs/target-app-parity.md.
2026-11-10 21:59:22 -08:00
dotCooCoo 01673695af JavaScript: a computed XML name or attribute run cannot add markup
An embedded expression used as a tag or attribute name must now be one XML
name, and one used as a run of attributes must hold only name="value"
attributes separated by white space. Anything else throws SyntaxError, so a
script string cannot add an attribute, close the tag or add a child.

{name}={value} in a tag now reads as a computed attribute name, as in the
example in ECMA-357 section 11.1.4.
2026-11-09 07:47:29 -08:00
dotCooCoo f85c555014 JavaScript: run E4X XML literals and the XML, XMLList, Namespace and QName objects behind an option
With `Options::e4x` set, vectorcraft-js runs ECMA-357 (2nd edition):
XML and XMLList literals with embedded expressions, the `..`, `.@`,
`.*`, `.()` and `::` selectors, assignment and `delete` on selected
nodes, `for each`, `default xml namespace`, and the four objects with
their methods and settings. The option is off by default, and without
it the syntax and globals do not exist.

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.
`XML.prototype.xpath` is not provided.
2026-11-09 06:50:32 -08:00
dotCooCoo bf1145edd5 JavaScript: vectorcraft-js runs ES5 scripts with a garbage-collected heap and execution limits
Squashed from #6178 onto main.
2026-11-09 00:29:52 +07:00