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.
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.
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.
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.
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.
- 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.
Assigning to a named child counts its list of the matching children, and
assigning through an empty XMLList counts the chain of targets it climbs,
before either changes the tree. copy(), toXMLString(), normalize(), the
`..` selector and the depth check on insertion hold the stack they keep
for each open level of the tree. Inserting an XMLList, and assigning one
to an item of an XMLList, hold their copy of the list's items.
copy() reads attributes in place, and toXMLString() reads attributes and
namespace declarations in place, instead of copying the lists. copy()
charges the declarations it copies before it copies them. Deleting by
name or assigning an attribute compacts the remaining links in place
instead of building a second list.
toXMLString() holds the set of prefixes a namespace lookup passes, and
picks a new nsN prefix in one pass over the declarations in scope
instead of rescanning them for each candidate.
The parser holds its open elements and their names, the text it gathers,
each tag's attribute values, the sets that check declarations and
attribute names, and its one copy of an element's namespaces, and it
charges the strings of the namespace declarations it makes. The
allowance it holds from the source's length covers the copy a value
takes as it becomes a string.
Comparing XML values, converting them to strings, assigning an XMLList
to an attribute, and reading a name, a qualifier, a namespace URI or
embedded text from a string built by joining strings flatten it with
flat_charged. An attribute name read from a string reserves its copy,
and an element name shares the string.
Docs: docs/target-app-parity.md.
$.line and $.stack counted lines in the run's expanded source. In code
that comes after an #include they gave lines that match no file, and
this included code in a file $.evalFile ran and code a named engine
kept from an earlier run.
Both now map each frame through the run's source maps, as uncaught
errors already were. $.stack writes each frame as name@file:line,
outermost first, with the run's name as the file of a script given as
source. Code that eval or Function compiled keeps the line of the
source they compiled, in [eval]; code whose place a named engine no
longer keeps is at line 0 of [unknown]. The 64-frame limit, [global]
and [anonymous] are unchanged.
Docs: docs/mcp.md, docs/target-app-parity.md.
$.fileName gave the file being run, so a function defined in a file
that #include inserted, in a file $.evalFile ran, or in an earlier run
of a named engine reported the calling file instead of its own.
- vectorcraft_js: HostItem::SiteGetter gives a getter the CallSite
(source tag, line, column) of the code that reads it.
- $.fileName maps that place through the run's source maps, or the
maps a named engine kept, to the file the code is in. It is empty in
code from a script given as source and in kept code whose map was
dropped. Code that eval or Function compiled still gets the file
being run.
Docs: docs/mcp.md, docs/target-app-parity.md.
The namespace list that inScopeNamespaces(), namespace(),
namespaceDeclarations(), the XPath namespace axis, XPath prefixes and
XPath name() collect from a node and its ancestors was built in Rust
buffers the heap limit did not see, so a node with many namespaces in
scope let a script grow past its limit.
The scope now holds the bytes of its list and prefix table until it is
dropped, and namespaceDeclarations() also holds its ancestor table and
the declarations it returns. The queried node stays rooted while the
scope is built, and each declaration is read in place instead of
copying every node's namespace list.
Other copies in the same files are held against the limit too:
- addNamespace(), setNamespace(), setName() and removeNamespace() read
an element's attributes one at a time instead of copying the list,
and removeNamespace() holds its walk stack.
- child(index), comments(), text(), elements(), processingInstructions()
and normalize() on an XMLList hold the copy of its items, and
replace() holds the copy of the children it matched.
- XPath name() holds the units of a prefixed name it builds.
- The XML, XMLList, Namespace and QName constructors, isXMLName(),
attribute(), namespace(), propertyIsEnumerable(), setName(),
setLocalName(), addNamespace(), removeNamespace() and setNamespace()
reserve the bytes of the flat copy of a long (rope) string argument
before they make it, and attribute() reserves the copy of a name
without its leading @.
- QName.prototype.toString() reserves its result before it builds it.
A script's File and Folder objects now open files for writing, appending
and editing, and copy, rename, remove and create files and folders. A
script reads and writes its run's temporary folder (Folder.temp) and its
own data folder (Folder.userData), kept between runs for a script run
from a file and inside Folder.temp for a script given as text. It reads
its own folder, and reaches other places only through File.openDialog,
File.saveDialog, Folder.selectDialog and the objects' openDlg, saveDlg and
selectDlg.
- A file dialog asks first. The person picks the file or folder with
Choose..., then allows it once or, for a script run from a file, always.
A kept grant is bound to the script's path, the SHA-256 of its text and
every source the run evaluated. It is withdrawn when a later run of the
script evaluates other code, including code an earlier run left in the
same named engine. It stays on the real path that was granted, so a
link put in that place later does not carry it elsewhere.
- A dialog's filter is a string of file types or a function that is
called with each file picked; multiSelect gives an array of the files
picked, at most 2,048, and the dialog says when more were left out.
- A folder's selectDlg opens the host's folder dialog in that folder,
also where the host shows file dialogs in line. Enter in the file
dialog denies, unless it goes to the focused Choose... button.
script.grants.revoke is refused with the busy error while a script
runs, as the run keeps the grants it started with.
- The paths a file dialog allows come only from the host's file dialog:
ui.dialog.set cannot set them. Only the person at the keyboard allows
access; Allow Once and Always Allow sent by automation are refused. The
dialog describes the access the run asked for, whatever its fields say.
- No grant reaches the settings folder, also when the script's own folder
holds it.
- A file left open is not written through a link put in place of its
folder since it was opened, and Folder.userData is null when the data
folder or the script's folder in it is a link.
- copy onto another link to the same file (a hard link) leaves the file's
bytes as they are, after the source's open objects have written what
they hold. Files are compared by identity (device and inode on Unix,
volume and file index on Windows).
- Folder.temp and Folder.userData check each folder they make against the
automation write roots first, and Folder.create() makes nothing when a
missing folder above the target is outside the places the script may
write.
- An open file holds at most 8 MiB, a run writes at most 32 MiB and keeps
at most 256 files open, and the files a run left open are written in
the order they were opened. Setting length and copying a file count the
bytes every open object of that file takes, and write checks the joined
text against the limit while joining it. The report names at most 4,096
written files and sets writtenMore when there were more.
- Errors a script sees are translated in every complete message catalog.
A function an earlier run of a named engine defined was reported without
a line, column or file when it threw in a later run. The realm now gives
each source a tag that stays the same from run to run (Realm::error_tag,
Realm::script_tag), and no two sources share one once the tags run out.
Each named engine keeps the source maps of its runs' scripts, included
files and $.evalFile files, within 8 MiB, dropping the oldest first, and
an error in kept code is reported at that file, line and column. The
report's name and the console line keep the calling run's name. For an
earlier script given as source, file is that run's name.
Docs: docs/mcp.md (Script engines), script.run params text,
docs/target-app-parity.md.
flat_charged and the property-key path now root the rope itself, so a string held only by
native code (a getter's result for ++o.x, a valueOf result, a toString key) still counts
what it holds when the reservation collects. The per-call roots for these cases are removed.
When the flattened copy of a String object's concatenated string would pass the heap limit
before a collection can run, the indexed read walks the rope to the unit instead, taking a
unit of fuel for each node it visits, so no copy is made.
- wrapping a string no longer flattens it, so Object(s).length and new String(s) on a large concatenated string make no copy and cannot collect while a call's operands are off the stack
- reading a String object's character by index, `in` and hasOwnProperty count the flattened copy at the next limit check, and the run ends before the copy when the fuel for it is not left
- unary plus on an object whose valueOf returns a concatenated string, and a property key from toString, keep that string rooted while its copy is reserved
- the unshift comment cites step 6 of section 15.4.4.13
Boxing the string receiver of a non-strict function flattens it, and reserving the copy can
collect. The callee, receiver and arguments are already off the stack at that point, so they
stay in the temporary roots until the frame holds them; before, an argument object could be
freed and its cell reused by the wrapper. new String(value) roots the converted string the
same way, so what the rope holds is still counted while its copy is reserved.
- the relational operators root both strings while flattening them, so the first copy still counts when the second one starts a collection
- join roots its separator for the whole join and each element while it is written, and JSON.stringify roots a string while it writes it
- a String object flattens its string when it is made, with the copy counted, so reading one of its characters copies nothing
xml.xpath(expression[, variables]) evaluates an XPath 1.0 expression
(https://www.w3.org/TR/1999/REC-xpath-19991116/) with the XML value as
the context node and returns the selected nodes as an XMLList, in
document order and without repeats. On an XMLList the expression runs
on each element in turn, and the results are joined.
- All 13 axes and the 27 core functions. id() selects nothing, since
E4X trees carry no DTD data.
- Each property of `variables` binds the variable of its name. A
prefix in a name test resolves through the context element's
in-scope namespaces; `xml` is always bound.
- An expression that breaks the grammar gives a SyntaxError. An
unknown function, a wrong argument count, an unbound prefix or
variable, a result that is not a node-set, and a result that holds
the root or a namespace node give a TypeError.
- The parser and the evaluator keep their state on their own stacks,
so expressions of any depth use no native stack; nesting past
Options::max_depth gives "nesting too deep". Traversal stacks, node
lists, strings and the values that string functions build count
against the heap limit, and every node visited and string read takes
fuel.
Docs: docs/target-app-parity.md (E4X line), crate doc in lib.rs.
The fuel and heap checks for a host evaluator's source were split into a third
before encoding and the rest after, so a source whose whole UTF-16 text did not
fit in the heap could still be encoded and parsed. The whole encoded size is now
reserved before encoding. A source over the source limit is still refused as a
syntax error.
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).
Flattening a concatenated string copies its units into a new buffer. The
string built-ins reserve that copy with flat_charged, but several other
paths flattened without it, so a script could build copies the heap limit
never saw:
- the relational operators (`<`, `>`, `<=`, `>=`) on two strings, `==`
between a string and a number, unary `+` and every other ToNumber of a
string, and reading a character by index (`s[0]`)
- a property name made from an object whose toString returns a long
string, and a long string used as a property name, which now reserves
its copy before it is made instead of after
- direct `eval` of a concatenated source
- `JSON.stringify` of a string value and its `space` argument
- `Array.prototype.join`'s separator and each string element it writes
Property names and eval source reserve the copy's heap bytes without
taking fuel.
Direct and indirect eval, Function and host evaluators parsed and compiled
their source before taking any fuel or checking the heap, so a script with a
small fuel limit could make the interpreter parse megabytes of source in a
handful of instructions. Interp::prepare_source now takes one unit of fuel for
each UTF-16 code unit and checks that the source text fits in the heap before
the source is flattened, parsed or compiled. A host evaluator's string takes
the fuel for a third of its bytes before it is encoded, and the rest after.
Limits::fuel and the maxFuel row in docs/mcp.md say so.
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.
An XML declaration at the start of XML or XMLList text was skipped up to
the next "?>" without being read. It is now 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, with optional white space before "?>". Any other
declaration gives "SyntaxError: invalid XML declaration", and a character
XML does not allow gives "invalid character in XML text". White space
before the declaration is still accepted.
The parser now takes fuel for the length of the declaration and the
white space before it, element and attribute names, white space in open
and closing tags, and the text it searched when an attribute value, CDATA
section, comment or processing instruction is not closed, or when "]]>"
or "<" stops a text run or attribute value. A long run in any of these
used the same fuel as a short one.
A finally block that break or continue leaves no longer keeps the saved
site of the exception it ran for. A Jump now removes the sites at or
above the stack's length, as a return already does, so a collection
after the stack grows back over that slot does not root and count the
old code.
New tests in crates/js/src/host_tests.rs: an error passed on by a
finally block that collects garbage under a 1 MiB heap is reported at
its throw; the saved site keeps direct eval code live through a
collection; a host abort inside a finally block leaves no saved site;
and break, continue and return out of a finally block drop the site.