mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-28 09:21:55 +01:00
JavaScript: for-of exits close the iterator outside the loop's handler
A return, or a break or continue to an outer statement, now closes a for-of loop's iterator after the loop's protected range. An exception from the iterator's return method reaches the catch clause around the loop instead of stopping the run with an internal error. Inner iterators are closed first, and a throwing inner close still closes the outer iterators. A hole in an array pattern steps the iterator without reading the result's value. A var pattern resolves each name before its value is read. A block function named like a destructured catch parameter is no longer also made a var (ECMA-262 11th edition sections B.3.3 and B.3.5). Throwing an exception on after an iterator is closed reads a finally block's mark only from the stack slot that holds the exception. Object patterns forget their shorthand defaults in one ordered pass over the markers inside the pattern, instead of comparing every marker in the script with every default in the pattern. docs/mcp.md says that a loop left early calls return only when the iterator has one and that an iterator whose next() throws is not closed, and that an engine's first run decides its built-ins while each run's script decides its syntax. docs/target-app-parity.md says the same.
This commit is contained in:
1 parent
f9d7fd23b4
commit
04557f4893
11 files changed
+180
-37
No files matched your search
@@ -326,8 +326,9 @@ fn a_js_script_reads_ecmascript_2015_and_a_jsx_script_does_not() {
|
||||
assert_eq!(modern["log"], json!([2]), "{modern}");
|
||||
let legacy = s.execute("script.run", &path(&write("third.jsx", "#targetengine kept\nvc.log(k2);\nconst c = 1;")));
|
||||
assert!(legacy.unwrap_err().to_string().contains("SyntaxError"));
|
||||
let legacy = s.execute("script.run", &path(&write("fourth.jsx", "#targetengine kept\nvc.log(k2 + kept);"))).unwrap();
|
||||
assert_eq!(legacy["log"], json!([3]), "{legacy}");
|
||||
let fourth = "#targetengine kept\nvc.log(k2 + kept);\ntry { eval('let x = 1'); } catch (e) { vc.log(e.name); }";
|
||||
let legacy = s.execute("script.run", &path(&write("fourth.jsx", fourth))).unwrap();
|
||||
assert_eq!(legacy["log"], json!([3, "SyntaxError"]), "{legacy}");
|
||||
// `for`-`of` and destructuring, in a new engine and in one a `.jsx` script made.
|
||||
let loops = "var s = 0;\nfor (const [a, { b = 1 }] of [[1, {}], [2, { b: 3 }]]) s += a + b;\nvar { p, q: [r] } = { p: 4, q: [5] };\nvc.log(s);\nvc.log(p + r);\nvc.log(typeof Symbol);";
|
||||
let r = s.execute("script.run", &path(&write("loops.js", loops))).unwrap();
|
||||
|
||||
@@ -211,6 +211,9 @@ pub(crate) enum Op {
|
||||
IterStep(u32),
|
||||
/// `record x₁…xₙ` → `record x₁…xₙ value`: the next value, `undefined` once it is done.
|
||||
IterValue(u32),
|
||||
/// `record` → `record`: steps the iterator without reading the result's `value`, for a hole
|
||||
/// in an array pattern.
|
||||
IterSkip,
|
||||
/// `record x₁…xₙ` → `record x₁…xₙ array`: the values left, in an array.
|
||||
IterRest(u32),
|
||||
/// `record` → nothing: closes the iterator unless it is done (IteratorClose).
|
||||
@@ -404,7 +407,7 @@ fn effect(op: Op, finally_tables: &[Vec<u32>]) -> Result<Effect, String> {
|
||||
Op::LoadParam(_) | Op::TemplateObject(_) => e(0, 1),
|
||||
Op::ArraySpread | Op::NewSpread => e(2, 1),
|
||||
Op::CallSpread(_) => e(3, 1),
|
||||
Op::ToStr | Op::GetIterator | Op::RequireObjectCoercible => e(1, 1),
|
||||
Op::ToStr | Op::GetIterator | Op::IterSkip | Op::RequireObjectCoercible => e(1, 1),
|
||||
Op::IterStep(t) => Effect { pops: 1, next: Some(2), jumps: vec![(t, 1)] },
|
||||
Op::IterValue(n) | Op::IterRest(n) => e(n.checked_add(1).ok_or("operand too large")?, n.checked_add(2).ok_or("operand too large")?),
|
||||
Op::PatternGet(n) => e(n.checked_add(2).ok_or("operand too large")?, n.checked_add(3).ok_or("operand too large")?),
|
||||
|
||||
@@ -65,8 +65,9 @@ enum Ctx {
|
||||
/// The protected part (and catch clause) of a `try` with a `finally` block.
|
||||
Finally { try_depth: u32, env_depth: u32, entry: Label, exits: Vec<Exit> },
|
||||
/// The body of a `for-of` loop, whose Iterator Record is the top value at `depth`: a jump
|
||||
/// out of the loop closes the iterator.
|
||||
Iterator { depth: u32, env_depth: u32 },
|
||||
/// out of the loop goes to the label `exits` holds for it, after the loop's protected range,
|
||||
/// where the iterator is closed and the jump goes on.
|
||||
Iterator { depth: u32, env_depth: u32, exits: Vec<(Exit, Label)> },
|
||||
}
|
||||
|
||||
struct FnCompiler<'a> {
|
||||
@@ -335,7 +336,14 @@ impl<'a> FnCompiler<'a> {
|
||||
work.extend(f.iter().rev().map(|&st| (st, nested || inner, s)));
|
||||
}
|
||||
if let Some(h) = handler {
|
||||
let s = enter(self.lexical_names(&h.body));
|
||||
// A `var` cannot redeclare a destructured catch parameter's names
|
||||
// (ECMA-262 11th edition section B.3.5), so a block function of that name
|
||||
// in the body is not also made a `var` (section B.3.3).
|
||||
let mut names = self.lexical_names(&h.body);
|
||||
if matches!(h.param, Binding::Pattern(_)) {
|
||||
names.extend(self.bound_keys(&h.param));
|
||||
}
|
||||
let s = enter(names);
|
||||
work.extend(h.body.iter().rev().map(|&st| (st, nested || inner, s)));
|
||||
}
|
||||
let s = enter(self.lexical_names(block));
|
||||
@@ -976,8 +984,9 @@ impl<'a> FnCompiler<'a> {
|
||||
self.route_through_finally(i, exit, try_depth, env_depth, entry)?;
|
||||
break;
|
||||
}
|
||||
Some(&Ctx::Iterator { depth, env_depth }) => {
|
||||
// The loop is left: its iterator is closed, a `return` keeping its value.
|
||||
Some(&Ctx::Iterator { depth, env_depth, .. }) => {
|
||||
// The loop is left: the jump goes past the loop's exception handler, where its
|
||||
// iterator is closed, a `return` keeping its value (see `for_of`).
|
||||
if exit == Exit::Return {
|
||||
let Some(under) = self.depth.checked_sub(1 + depth) else { return internal("stack below a for-of loop") };
|
||||
if under > 0 {
|
||||
@@ -988,8 +997,9 @@ impl<'a> FnCompiler<'a> {
|
||||
} else {
|
||||
self.unwind_to(depth, env_depth)?;
|
||||
}
|
||||
self.emit(Op::IterClose);
|
||||
self.env_depth = env_depth;
|
||||
let label = self.iterator_exit(i, exit)?;
|
||||
self.jump(Op::Jump, label);
|
||||
break;
|
||||
}
|
||||
None => return internal("context out of range"),
|
||||
}
|
||||
@@ -999,6 +1009,19 @@ impl<'a> FnCompiler<'a> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// The label where the `for-of` loop of the iterator context `ctx` closes its iterator for
|
||||
/// `exit` and goes on with it.
|
||||
fn iterator_exit(&mut self, ctx: usize, exit: Exit) -> CResult<Label> {
|
||||
let Some(Ctx::Iterator { exits, .. }) = self.contexts.get(ctx) else { return internal("not an iterator context") };
|
||||
if let Some(&(_, label)) = exits.iter().find(|(e, _)| *e == exit) {
|
||||
return Ok(label);
|
||||
}
|
||||
let label = self.new_label();
|
||||
let Some(Ctx::Iterator { exits, .. }) = self.contexts.get_mut(ctx) else { return internal("not an iterator context") };
|
||||
exits.push((exit, label));
|
||||
Ok(label)
|
||||
}
|
||||
|
||||
fn route_through_finally(&mut self, ctx: usize, exit: Exit, try_depth: u32, env_depth: u32, entry: Label) -> CResult<()> {
|
||||
let Some(Ctx::Finally { exits, .. }) = self.contexts.get_mut(ctx) else { return internal("not a finally context") };
|
||||
let k = match exits.iter().position(|e| *e == exit) {
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
//! reads each property by name. A target that is not a pattern is written as an assignment
|
||||
//! (`[a.b] = …`), a `var` or a `let`, `const`, parameter or catch binding, as [`Mode`] says.
|
||||
|
||||
use super::{CResult, Ctx, FnCompiler, internal, key_of, len_u32};
|
||||
use super::{CResult, Ctx, Exit, FnCompiler, internal, key_of, len_u32};
|
||||
use crate::ast::{Binding, Expr, ExprId, ForInTarget, LexKind, Property, PropertyKey, PropertyValue, StmtId};
|
||||
use crate::bytecode::{BlockScope, CodeKind, Op};
|
||||
use crate::heap::Key;
|
||||
@@ -75,8 +75,17 @@ impl FnCompiler<'_> {
|
||||
}
|
||||
|
||||
/// Pushes what writing to `target` needs before its value, and gives how many values that is:
|
||||
/// an assignment's object and key; nothing for a binding or a pattern.
|
||||
/// an assignment's object and key; a `var` name's reference, resolved before the value is
|
||||
/// read (sections 13.3.3.6 and 13.3.3.7); nothing for another binding or a pattern.
|
||||
fn target_refs(&mut self, target: ExprId, mode: Mode) -> CResult<u32> {
|
||||
if mode == Mode::Var
|
||||
&& let Some(Expr::Ident(name)) = self.ast.expr(target)
|
||||
{
|
||||
self.at(self.ast.expr_span(target).start);
|
||||
let n = self.var_name(name);
|
||||
self.emit(Op::RefVar(n));
|
||||
return Ok(1);
|
||||
}
|
||||
if mode != Mode::Assign || self.is_pattern(target) {
|
||||
return Ok(0);
|
||||
}
|
||||
@@ -102,7 +111,7 @@ impl FnCompiler<'_> {
|
||||
if mode == Mode::Lexical {
|
||||
self.emit(Op::InitVar(n));
|
||||
} else {
|
||||
self.emit(Op::SetVar(n));
|
||||
self.emit(Op::PutRef(n));
|
||||
self.emit(Op::Pop);
|
||||
}
|
||||
}
|
||||
@@ -132,8 +141,7 @@ impl FnCompiler<'_> {
|
||||
let start = self.pc();
|
||||
for element in elements {
|
||||
let Some(element) = *element else {
|
||||
self.emit(Op::IterValue(0));
|
||||
self.emit(Op::Pop);
|
||||
self.emit(Op::IterSkip);
|
||||
continue;
|
||||
};
|
||||
if let Some(Expr::Spread(target)) = self.ast.expr(element) {
|
||||
@@ -226,7 +234,7 @@ impl FnCompiler<'_> {
|
||||
let done = self.new_label();
|
||||
let close_throw = self.new_label();
|
||||
let after = self.new_label();
|
||||
self.contexts.push(Ctx::Iterator { depth: record, env_depth: outer_env });
|
||||
self.contexts.push(Ctx::Iterator { depth: record, env_depth: outer_env, exits: Vec::new() });
|
||||
self.bind(head);
|
||||
self.jump(Op::IterStep, done);
|
||||
let start = self.pc();
|
||||
@@ -244,7 +252,10 @@ impl FnCompiler<'_> {
|
||||
self.contexts.pop();
|
||||
r
|
||||
});
|
||||
self.contexts.pop();
|
||||
let exits = match self.contexts.pop() {
|
||||
Some(Ctx::Iterator { exits, .. }) => exits,
|
||||
_ => return internal("for-of context missing"),
|
||||
};
|
||||
r?;
|
||||
if scope.is_some() {
|
||||
self.emit(Op::PopEnv);
|
||||
@@ -260,6 +271,18 @@ impl FnCompiler<'_> {
|
||||
self.depth = record;
|
||||
self.emit(Op::IterClose);
|
||||
self.jump(Op::Jump, after);
|
||||
// `return` and jumps to outer statements close the iterator here, outside the range the
|
||||
// loop's handler covers, so an exception from `return` goes to the handlers around the
|
||||
// loop; the jump then goes on through them.
|
||||
for (exit, label) in exits {
|
||||
self.bind(label);
|
||||
self.depth = if exit == Exit::Return { record + 1 } else { record };
|
||||
self.env_depth = outer_env;
|
||||
self.emit(Op::IterClose);
|
||||
self.emit_exit(exit)?;
|
||||
}
|
||||
self.depth = record;
|
||||
self.env_depth = outer_env;
|
||||
self.bind(done);
|
||||
self.depth = record;
|
||||
self.emit(Op::Pop);
|
||||
|
||||
@@ -553,6 +553,21 @@ fn closing_an_iterator_reports_a_bad_return_unless_an_exception_is_on_its_way()
|
||||
return: function () { throw new SyntaxError('r'); } }; ";
|
||||
throws(&format!("{throwing} for (var x of t) break;"), "SyntaxError");
|
||||
truth(&format!("{throwing} var r; try {{ for (var x of t) throw 5; }} catch (e) {{ r = e; }} r === 5"));
|
||||
// A close that throws when `return` or a jump to an outer statement leaves the loop reaches
|
||||
// the enclosing catch clause. Inner iterators are closed first, and a throwing inner close
|
||||
// still closes the outer iterators.
|
||||
let caught = |src: &str| format!("{COUNTED}{throwing} var r; try {{ {src} }} catch (e) {{ r = e; }} r instanceof SyntaxError");
|
||||
for src in [
|
||||
"(function () { for (var x of t) return 1; })();",
|
||||
"(function () { for (var x of [1]) for (var y of t) return 1; })();",
|
||||
"outer: for (var i = 0; i < 2; i++) for (var x of t) continue outer;",
|
||||
"outer: for (var x of t) for (var y of [1, 2]) break outer;",
|
||||
"outer: for (var x of t) for (var y of it(5)) for (var z of it(5)) break outer;",
|
||||
] {
|
||||
truth(&format!("{} && closed === {}", caught(src), src.matches("it(5)").count()));
|
||||
}
|
||||
truth(&format!("{} && closed === 1", caught("outer: for (var x of it(5)) for (var y of t) break outer;")));
|
||||
truth(&format!("{} && closed === 1", caught("(function () { for (var x of it(5)) for (var y of t) return 1; })();")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -566,6 +581,10 @@ fn array_patterns_step_the_iterator_and_close_it() {
|
||||
counted("var [a, ...r] = it(2); closed === 0 && r.join() === '2'");
|
||||
counted("var [] = it(5); closed === 1");
|
||||
counted("var [a, b] = it(1); closed === 0 && b === undefined");
|
||||
// A hole steps the iterator without reading the result's `value`.
|
||||
let bad_value = "var t = it(5); t.next = function () { return { done: false, get value() { throw 4; } }; };";
|
||||
counted(&format!("{bad_value} var [,] = t; closed === 1"));
|
||||
counted(&format!("{bad_value} [,] = t; for (let [,] of [t]); closed === 2"));
|
||||
counted("try { var [a = (function () { throw 1; })()] = it(0); } catch (e) {} closed === 0");
|
||||
counted("try { var [a, b = (function () { throw 1; })()] = [1]; } catch (e) {} closed === 0");
|
||||
counted("var o = { set p(v) { throw 2; } }; try { [o.p] = it(5); } catch (e) {} closed === 1");
|
||||
@@ -584,6 +603,14 @@ fn object_patterns_read_properties_by_name() {
|
||||
"var order = []; var o = { get a() { order.push('a'); return 1; }, get b() { order.push('b'); return 2; } }; \
|
||||
var { b, a } = o; order.join() === 'b,a'",
|
||||
);
|
||||
// A `var` pattern's names are resolved before their values are read (sections 13.3.3.6
|
||||
// and 13.3.3.7).
|
||||
truth(
|
||||
"var o = { x: 0 }; var t = { [Symbol.iterator]: function () { return this; }, \
|
||||
next: function () { delete o.x; return { value: 1, done: false }; }, return: function () { return {}; } }; \
|
||||
with (o) { var [x] = t; } o.x === 1 && x === undefined",
|
||||
);
|
||||
truth("var o = { y: 0 }; with (o) { var { a: y } = { get a() { delete o.y; return 2; } }; } o.y === 2 && y === undefined");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -607,6 +634,11 @@ fn destructured_parameters_and_catch_clauses() {
|
||||
truth("function f({ a }) { var a; return a; } f({ a: 6 }) === 6");
|
||||
truth("var r; try { throw { m: 'x', d: [1] }; } catch ({ m, d: [n] }) { r = m + n; } r === 'x1'");
|
||||
truth("var r; try { throw [1, 2]; } catch ([a, b]) { r = function () { return a + b; }; } r() === 3");
|
||||
// A function in a block is not also made a `var` when that `var` would clash with a
|
||||
// destructured catch parameter (ECMA-262 11th edition sections B.3.3 and B.3.5).
|
||||
truth("function g() { try { throw [1]; } catch ([f]) { { function f() {} } } return typeof f; } g() === 'undefined'");
|
||||
truth("try { throw {}; } catch ({ h }) { { function h() {} } } typeof h === 'undefined'");
|
||||
truth("function g() { try { throw 1; } catch (f) { { function f() {} } } return typeof f; } g() === 'function'");
|
||||
throws("function f({ a }) {} f();", "TypeError");
|
||||
throws("try { throw null; } catch ({ a }) {}", "TypeError");
|
||||
throws("function f([a], b = a) {} f([]); f(undefined);", "TypeError");
|
||||
@@ -690,6 +722,19 @@ fn bad_patterns_are_syntax_errors() {
|
||||
truth("var of = [1]; var n = 0; for (var x of of) n += x; n === 1");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn large_patterns_take_their_shorthand_defaults() {
|
||||
let defaults = (0..20_000).map(|i| format!("a{i} = {i}")).collect::<Vec<_>>().join(", ");
|
||||
truth(&format!("({{ {defaults} }} = {{}}); a0 === 0 && a19999 === 19999"));
|
||||
truth(&format!("var f = ({{ {defaults} }}) => a19999; f({{}}) === 19999"));
|
||||
// A shorthand default inside a default value or a computed name is still an error.
|
||||
syntax(&format!("({{ {defaults}, b = {{ c = 1 }} }} = {{}});"));
|
||||
syntax(&format!("({{ [{{ c = 1 }}]: b, {defaults} }} = {{}});"));
|
||||
let small = "[{ b = 1 }] = [{}]; ".repeat(20_000);
|
||||
truth(&format!("var b; {small} b === 1"));
|
||||
syntax(&format!("var b; {small} ({{ c = 1 }});"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_realm_without_the_later_built_ins_walks_arrays_arguments_and_strings() {
|
||||
let mut realm = Realm::new();
|
||||
|
||||
@@ -1105,6 +1105,7 @@ impl Interp {
|
||||
Op::GetIterator => self.op_get_iterator(),
|
||||
Op::IterStep(t) => self.op_iter_step(t),
|
||||
Op::IterValue(n) => self.op_iter_value(n),
|
||||
Op::IterSkip => self.op_iter_skip(),
|
||||
Op::IterRest(n) => self.op_iter_rest(n),
|
||||
Op::IterClose => self.op_iter_close(),
|
||||
Op::IterCloseThrow => self.op_iter_close_throw(),
|
||||
@@ -1168,13 +1169,13 @@ impl Interp {
|
||||
self.passing = v.clone();
|
||||
self.throw_site = None;
|
||||
self.thrown_mark = None;
|
||||
let slot = self.stack.len();
|
||||
if let Value::Object(o) = v
|
||||
&& let Some(i) = self.finally_marks.iter().rposition(|&(id, _, _)| id == o)
|
||||
&& let Some(i) = self.finally_marks.iter().rposition(|&(id, _, s)| id == o && s == slot)
|
||||
{
|
||||
self.thrown_mark = self.finally_marks.get(i).map(|&(_, mark, _)| mark);
|
||||
self.finally_marks.truncate(i);
|
||||
}
|
||||
let slot = self.stack.len();
|
||||
if let Some(i) = self.finally_sites.iter().rposition(|&(_, s)| s == slot) {
|
||||
self.throw_site = self.finally_sites.get(i).map(|(site, _)| site.clone());
|
||||
self.finally_sites.truncate(i);
|
||||
|
||||
@@ -120,6 +120,12 @@ impl Interp {
|
||||
/// IteratorStep and IteratorValue (sections 7.4.5 and 7.4.4): the next value, or `None` when
|
||||
/// the iterator is done. The record stays done when the step throws.
|
||||
pub(crate) fn iter_next(&mut self, rec: ObjId) -> JsResult<Option<Value>> {
|
||||
self.iter_step(rec, true)
|
||||
}
|
||||
|
||||
/// IteratorStep (section 7.4.5), and IteratorValue when `read_value` is set: the next value
|
||||
/// (`undefined` when it is not read), or `None` when the iterator is done.
|
||||
fn iter_step(&mut self, rec: ObjId, read_value: bool) -> JsResult<Option<Value>> {
|
||||
let r = self.record(rec)?;
|
||||
if r.done {
|
||||
return Ok(None);
|
||||
@@ -138,6 +144,9 @@ impl Interp {
|
||||
if i.get_value(&result, &key("done"))?.truthy() {
|
||||
return Ok(None);
|
||||
}
|
||||
if !read_value {
|
||||
return Ok(Some(Value::Undefined));
|
||||
}
|
||||
i.get_value(&result, &key("value")).map(Some)
|
||||
})?;
|
||||
if value.is_some() {
|
||||
@@ -197,6 +206,13 @@ impl Interp {
|
||||
self.push(v)
|
||||
}
|
||||
|
||||
/// `record` → `record`: one step of the iterator, for a hole in an array pattern
|
||||
/// (section 13.3.3.6, Elision), which does not read the result's `value`.
|
||||
pub(crate) fn op_iter_skip(&mut self) -> JsResult<()> {
|
||||
let rec = self.record_at(0)?;
|
||||
self.iter_step(rec, false).map(drop)
|
||||
}
|
||||
|
||||
/// `record x₁…xₙ` → `record x₁…xₙ array`: an array of the values left.
|
||||
pub(crate) fn op_iter_rest(&mut self, under: u32) -> JsResult<()> {
|
||||
let rec = self.record_at(under as usize)?;
|
||||
|
||||
@@ -757,7 +757,8 @@ impl<'s> Parser<'s> {
|
||||
if starts_with_let {
|
||||
return Err(self.error_at_offset(self.ast.expr_span(expr).start, "a for-of loop's left-hand side cannot start with 'let'"));
|
||||
}
|
||||
// `for (async of …` is left to async arrow functions (ECMA-262 2017 section 13.7).
|
||||
// `for (async of …` is a SyntaxError, as ECMAScript 2021 has it (ECMA-262 12th
|
||||
// edition section 14.7.5, the lookahead restriction on `async of`).
|
||||
if async_of {
|
||||
return Err(self.error_at_offset(self.ast.expr_span(expr).start, "a for-of loop's left-hand side cannot be 'async'"));
|
||||
}
|
||||
|
||||
@@ -271,6 +271,7 @@ impl Parser<'_> {
|
||||
/// initializer in it are no longer errors.
|
||||
pub(super) fn check_assignment_pattern(&mut self, pattern: ExprId) -> Result<()> {
|
||||
let mut work = vec![pattern];
|
||||
let mut gaps = Vec::new();
|
||||
while let Some(id) = work.pop() {
|
||||
for target in self.pattern_targets(id)? {
|
||||
if self.is_pattern(target) {
|
||||
@@ -279,8 +280,9 @@ impl Parser<'_> {
|
||||
self.check_simple_target(target, "invalid destructuring target")?;
|
||||
}
|
||||
}
|
||||
self.take_covers(id);
|
||||
self.cover_gaps(id, &mut gaps);
|
||||
}
|
||||
self.take_covers(pattern, gaps);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -288,6 +290,7 @@ impl Parser<'_> {
|
||||
/// is a binding pattern: each target is a name written bare or a nested pattern.
|
||||
fn check_binding_pattern(&mut self, pattern: ExprId) -> Result<()> {
|
||||
let mut work = vec![pattern];
|
||||
let mut gaps = Vec::new();
|
||||
while let Some(id) = work.pop() {
|
||||
for target in self.pattern_targets(id)? {
|
||||
match self.ast.expr(target) {
|
||||
@@ -296,17 +299,16 @@ impl Parser<'_> {
|
||||
_ => return Err(self.error_at_offset(self.ast.expr_span(target).start, "invalid arrow function parameters")),
|
||||
}
|
||||
}
|
||||
self.take_covers(id);
|
||||
self.cover_gaps(id, &mut gaps);
|
||||
}
|
||||
self.take_covers(pattern, gaps);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Forgets the shorthand properties with an initializer that the object pattern `id` holds
|
||||
/// itself: each one's `=` lies between its target and its default value. One inside a default
|
||||
/// value or a computed name stays an error.
|
||||
fn take_covers(&mut self, id: ExprId) {
|
||||
/// Adds to `gaps` where the `=` of each shorthand property with an initializer that the
|
||||
/// object pattern `id` holds itself lies: between the property's target and its default value.
|
||||
fn cover_gaps(&self, id: ExprId, gaps: &mut Vec<(u32, u32)>) {
|
||||
let Some(Expr::Object(properties)) = self.ast.expr(id) else { return };
|
||||
let mut gaps = Vec::new();
|
||||
for p in properties {
|
||||
if let PropertyValue::Init(v) = p.value
|
||||
&& let Some(Expr::Assign { op: None, target, value }) = self.ast.expr(v)
|
||||
@@ -314,7 +316,33 @@ impl Parser<'_> {
|
||||
gaps.push((self.ast.expr_span(*target).end, self.ast.expr_span(*value).start));
|
||||
}
|
||||
}
|
||||
self.cover_inits.retain(|&at| !gaps.iter().any(|&(from, to)| from <= at && at < to));
|
||||
}
|
||||
|
||||
/// Forgets the shorthand properties with an initializer whose `=` lies in one of `gaps`, the
|
||||
/// gaps of the object patterns in `pattern`. One inside a default value or a computed name
|
||||
/// stays an error. The positions in `cover_inits` rise, so only those inside `pattern` are
|
||||
/// read, in one pass with the gaps sorted.
|
||||
fn take_covers(&mut self, pattern: ExprId, mut gaps: Vec<(u32, u32)>) {
|
||||
if gaps.is_empty() {
|
||||
return;
|
||||
}
|
||||
gaps.sort_unstable();
|
||||
let span = self.ast.expr_span(pattern);
|
||||
let lo = self.cover_inits.partition_point(|&at| at < span.start);
|
||||
let hi = self.cover_inits.partition_point(|&at| at < span.end).max(lo);
|
||||
let mut gaps = gaps.into_iter().peekable();
|
||||
let kept: Vec<u32> = self
|
||||
.cover_inits
|
||||
.get(lo..hi)
|
||||
.unwrap_or_default()
|
||||
.iter()
|
||||
.copied()
|
||||
.filter(|&at| {
|
||||
while gaps.next_if(|&(_, to)| to <= at).is_some() {}
|
||||
!gaps.peek().is_some_and(|&(from, to)| from <= at && at < to)
|
||||
})
|
||||
.collect();
|
||||
drop(self.cover_inits.splice(lo..hi, kept));
|
||||
}
|
||||
|
||||
/// An arrow function's parameter from its parenthesized head: `None` when `item` is neither a
|
||||
|
||||
+9
-7
@@ -2623,8 +2623,9 @@ declarations scoped to their block, arrow functions, template literals and tagge
|
||||
parameters, spread in array literals, calls and `new`, `for`-`of` loops, array and object destructuring in `var`,
|
||||
`let` and `const` declarations, assignments, parameters and `catch` clauses (with defaults, holes and rest elements),
|
||||
and shorthand and computed property names in object literals (https://262.ecma-international.org/11.0/). Spread,
|
||||
`for`-`of` and array patterns use the iterator protocol, and a loop or pattern left early calls the iterator's
|
||||
`return` method. Destructuring `undefined` or `null` throws a `TypeError`. Object rest properties
|
||||
`for`-`of` and array patterns use the iterator protocol. A loop or pattern left early, by `break`, `return`, a
|
||||
`continue` to an outer loop or an exception, calls the iterator's `return` method when it has one; an iterator whose
|
||||
`next()` throws or says it is done is not closed. Destructuring `undefined` or `null` throws a `TypeError`. Object rest properties
|
||||
(`{ a, ...rest }`, ECMAScript 2018) are syntax errors. In an engine that `#targetengine` keeps and a `.jsx` script
|
||||
started, which has no `Symbol`, spread, `for`-`of` and array patterns read arrays, `arguments` objects and strings
|
||||
(by code point), by index, and throw a `TypeError` for any other value; that rule is VectorCraft's own. `eval`, `Function`, `#include` files and `$.evalFile` read code the way the script does, and
|
||||
@@ -2657,11 +2658,12 @@ app through the global object `vc`, and writes to the Script Console and runs ot
|
||||
- `vc.args` gives a read-only copy of the `args` object each time it is read.
|
||||
- `vc.api.version` is `"1.0"`, and `vc.api.has(feature)` says whether the API has a feature.
|
||||
|
||||
A `.jsx` script and a `source` string do not have `Symbol` or the iterators of arrays, strings and `arguments`
|
||||
objects: `typeof Symbol` is `"undefined"`, and `Array.prototype.values`, `keys` and `entries` are not defined. A `.js`
|
||||
script that starts a new engine has them, through the JavaScript engine's ECMAScript 2015 mode (`Options::es2015` in
|
||||
`vectorcraft-js`), as `docs/target-app-parity.md` describes; an engine that `#targetengine` keeps has them only when a
|
||||
`.js` script started it.
|
||||
The first run in an engine decides which built-ins the engine has, and each run's script decides which syntax that
|
||||
run reads. A `.jsx` script or a `source` string that starts a new engine has no `Symbol` and no iterators of arrays,
|
||||
strings and `arguments` objects: `typeof Symbol` is `"undefined"`, and `Array.prototype.values`, `keys` and `entries`
|
||||
are not defined. A `.js` script that starts a new engine has them, through the JavaScript engine's ECMAScript 2015 mode
|
||||
(`Options::es2015` in `vectorcraft-js`), as `docs/target-app-parity.md` describes. An engine that `#targetengine` keeps
|
||||
has them only when a `.js` script started it, and then a later `.jsx` run in it has them too while it reads ES5.1 only.
|
||||
|
||||
Before any of the script runs, its preprocessor lines are read. The help page
|
||||
https://extendscript.docsforadobe.dev/extendscript-tools-features/preprocessor-directives/ describes these lines, and
|
||||
|
||||
@@ -1083,8 +1083,8 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
|
||||
- `vectorcraft-js` provides the ECMAScript 5.1 built-ins `Object` with its property-descriptor functions, `create`, `keys`, `seal` and `freeze` (section 15.2), `Function.prototype.bind` (15.3.4.5), `Array` with every ES5 method (15.4), the error types (15.11), `Math` (15.8), `JSON` with revivers, replacers and indentation (15.12), and the global functions with Annex B's `escape` and `unescape` (15.1, B.2). The array methods work on array-like objects. A method visits only the indices that exist when its range is longer than 4,096 indices and more than 8 times the properties on the object and its prototypes, so `new Array(4294967295).join("")` ends at once; a shorter range is visited index by index, holes included, and each index takes fuel. `join` writes a cycle back to an array as an empty string, `JSON.stringify` throws a `TypeError` on a cycle, and deep `JSON` nesting uses no native stack. Every loop takes fuel and every result is checked against the heap limit. `cargo xtask test262` runs the suite's ES5 built-in tests that need only these built-ins: 6,798 of 6,866 runs pass (the 34 failing tests expect rules of later editions). It also fetches the `json2.js` polyfill at a pinned commit and checks that its `stringify` and `parse` agree with the built-in `JSON`. Tests: `crates/js/src/builtins_tests.rs`, `crates/js/tests/test262.rs`, `crates/js/tests/json2.rs`.
|
||||
- `vectorcraft-js` has `String`, `Number`, `RegExp` and `Date` as ECMAScript 5.1 defines them (sections 15.5, 15.7, 15.9 and 15.10, https://262.ecma-international.org/5.1/), with Annex B's `substr`, `getYear`, `setYear` and `toGMTString`. `toFixed`, `toExponential` and `toPrecision` format a number from its exact decimal value, and `toString(radix)` writes any base from 2 to 36. Regular expressions (flags `g`, `i` and `m`) run on a backtracking matcher whose choice points and capture state count against the heap limit and which takes fuel for every step, so a catastrophic pattern stops at the fuel limit and 50,000 nested groups give a `SyntaxError` at the default depth limit. A string method that would build a string past the heap limit stops before it allocates. `Date` reads the clock and time zone the host sets (`Realm::set_clock`, `Realm::set_time_zone`; local time is UTC by default). `cargo xtask test262` runs the suite's `built-ins` tests for the four (https://github.com/tc39/test262): of the runs of the ES5 tests that need only the built-ins present, 1,379 of 1,411 pass for `String`, 298 of 298 for `Number`, 954 of 988 for `RegExp` and 8 of 8 for `Date`. The others expect later editions' rules (built-in functions whose `length` can be deleted, flags given with a RegExp object, a negative `lastIndex`, `RegExp.prototype` as a plain object, and `RegExp.prototype`'s `global`, `ignoreCase` and `multiline` properties that can be deleted). Tests: `crates/js/src/text_tests.rs`, `crates/js/tests/test262.rs`.
|
||||
- `cargo xtask test262` also reads the suite's Annex B tests (https://tc39.es/ecma262/#sec-additional-ecmascript-features-for-web-browsers), whichever edition they name. It parses the 819 tests under `test/annexB/language` without a feature tag in the modes their flags give, so a `for`-`in` variable with an initializer must parse in sloppy code and give a `SyntaxError` in strict code (682 of 843 runs pass), and it runs those tests and the `test/annexB/built-ins` tests for `String`, `Date`, `RegExp` and `Function` that need only the built-ins present (263 of 667 runs pass for the language tests and 56 of 252 for the built-ins). Failures go to `annexb-parse-failures.txt`, `annexb-language-failures.txt` and `annexb-builtins-failures.txt` beside the suite. A conformance failure does not fail the tests, but an interpreter panic fails `annex_b_runs`, so `cargo xtask test262` exits non-zero. A folder or file the runner cannot read also fails the test that reads it. The runner reads only regular files inside the suite, up to 8 MiB each, and does not follow symbolic links. Tests: `crates/js/tests/test262.rs`.
|
||||
- With `Options::es2015` set, which it is not by default, a `vectorcraft-js` realm also has `Symbol` (ECMA-262 11th edition, section 19.4, https://262.ecma-international.org/11.0/): `Symbol(description)`, which `new` refuses with a `TypeError`, the `description` getter, `toString`, `valueOf`, and `Symbol.for` and `Symbol.keyFor` over a registry that lasts as long as the realm. `typeof` gives `"symbol"`. Symbols are property keys: `Object.getOwnPropertySymbols` lists an object's Symbol keys in the order they were added, `Object.defineProperty`, `getOwnPropertyDescriptor`, `freeze`, `seal`, `in`, `delete` and `hasOwnProperty` take them, and `for`-`in`, `Object.keys`, `Object.getOwnPropertyNames` and `JSON.stringify` leave them out. `String(symbol)` and `symbol.toString()` give `Symbol(description)`; any other conversion of a Symbol to a string or a number, such as `Symbol() + ''`, throws a `TypeError`. A string such as `'0b10'` or `'0o2'` converts to a number, as section 7.1.3.1 gives. The well-known Symbols `Symbol.iterator`, `Symbol.asyncIterator`, `Symbol.hasInstance`, `Symbol.toPrimitive` and `Symbol.toStringTag` are defined: conversion to a primitive calls an object's `@@toPrimitive` method, `instanceof` calls the right side's `@@hasInstance` method, and `Object.prototype.toString` writes a string `@@toStringTag`; `JSON.stringify` calls a String or Number object's `@@toPrimitive` method too. `Date.prototype[Symbol.toPrimitive]` (section 20.4.4.45) converts a Date with `toString` first for the hints `"string"` and `"default"` and with `valueOf` first for `"number"`, so `date + 1` joins the date's string; an object without an `@@toPrimitive` method, a Date whose method is `null` included, tries `valueOf` first when no hint is given. Nothing reads `Symbol.asyncIterator` yet. `Array.prototype.values` (also `Array.prototype[Symbol.iterator]`), `keys` and `entries`, `String.prototype[Symbol.iterator]` and every `arguments` object's `Symbol.iterator` return iterators whose `next()` gives `{value, done}` objects; a string iterator steps by code point and keeps a surrogate pair together. An array iterator reads the `length` at each step, so it visits elements added during the walk. Each step takes fuel, as does each prototype a Symbol-keyed lookup passes, and each Symbol and registry entry counts against the heap limit. A realm without the option, including the one the app runs `.jsx` scripts in, has none of these names, and a host function that returns a Symbol there throws a `TypeError`. `for`-`of`, spread and array destructuring call `next()` (see the next line). `cargo xtask test262` runs the suite's tests of `Symbol`, `ArrayIteratorPrototype`, `StringIteratorPrototype`, `Object.getOwnPropertySymbols`, `Array.prototype.values`, `keys`, `entries` and `Symbol.iterator`, and `String.prototype[Symbol.iterator]` that need only these built-ins and parse as ES5, in such a realm: 164 of 216 runs pass (6 passed before), and the 52 others expect a configurable function `length` and a function `name` property. Tests: `crates/js/src/symbol_tests.rs`, `crates/js/tests/test262.rs`.
|
||||
- With `Options::es2015`, `vectorcraft-js` also reads and runs `for`-`of` loops and destructuring (ECMA-262 11th edition, sections 13.7.5, 12.15.5 and 13.3.3, https://262.ecma-international.org/11.0/). `for`-`of` takes `var`, `let` and `const` declarations, patterns and any assignment target, gives a `let` or `const` loop a new binding for each iteration, and calls the iterator's `return` method when `break`, `continue` to an outer loop, `return` or an exception leaves the loop early; an iterator that threw, or whose `next()` said it was done, is not closed, and an exception on its way out wins over one that `return` throws. Array patterns step the iterator with holes, defaults and a rest element, and close it when they stop before its end. Object patterns read names, string and number keys and computed keys, with defaults. Patterns work in `var`, `let` and `const` declarations, assignments (with any assignment target as a leaf, such as `[o.a, o["b"]] = …`), function and arrow parameters, and `catch` clauses, and nest. A default runs only when the value is `undefined`. Destructuring `undefined` or `null` throws a `TypeError`. Object literals also take shorthand properties (`{ a }`) and computed names (`{ [k]: v }`, `get [k]()`), Symbol keys included. Object rest properties (`{ a, ...rest }`, ECMAScript 2018) are syntax errors. In a realm made without the option that `Realm::set_es2015` later switches to it, which has no `Symbol.iterator` (an engine that `#targetengine` keeps after a `.jsx` script made it), `for`-`of`, spread and array patterns walk arrays, `arguments` objects and strings by code point, and other values are a `TypeError`; that rule is VectorCraft's own. Each step takes fuel, a rest element counts against the heap limit, and nested patterns count against `Options::max_depth`. `cargo xtask test262` reads the suite's tests under `language/statements/for-of`, `language/expressions/assignment/dstr` and the `dstr` folders of `var`, `let`, `const`, `function`, function expressions, arrow functions, `try`, `for` and `for`-`in` whose feature tags this engine has: 609 of 617 runs pass (529 before, most of them negative parse tests); the 8 others expect a function given as a default to take the name of its binding, a `name` property `vectorcraft-js` does not set. Tests: `crates/js/src/es2015_tests.rs`, `crates/js/tests/test262.rs`, `crates/engine/src/tests/script_run.rs`.
|
||||
- With `Options::es2015` set, which it is not by default, a `vectorcraft-js` realm also has `Symbol` (ECMA-262 11th edition, section 19.4, https://262.ecma-international.org/11.0/): `Symbol(description)`, which `new` refuses with a `TypeError`, the `description` getter, `toString`, `valueOf`, and `Symbol.for` and `Symbol.keyFor` over a registry that lasts as long as the realm. `typeof` gives `"symbol"`. Symbols are property keys: `Object.getOwnPropertySymbols` lists an object's Symbol keys in the order they were added, `Object.defineProperty`, `getOwnPropertyDescriptor`, `freeze`, `seal`, `in`, `delete` and `hasOwnProperty` take them, and `for`-`in`, `Object.keys`, `Object.getOwnPropertyNames` and `JSON.stringify` leave them out. `String(symbol)` and `symbol.toString()` give `Symbol(description)`; any other conversion of a Symbol to a string or a number, such as `Symbol() + ''`, throws a `TypeError`. A string such as `'0b10'` or `'0o2'` converts to a number, as section 7.1.3.1 gives. The well-known Symbols `Symbol.iterator`, `Symbol.asyncIterator`, `Symbol.hasInstance`, `Symbol.toPrimitive` and `Symbol.toStringTag` are defined: conversion to a primitive calls an object's `@@toPrimitive` method, `instanceof` calls the right side's `@@hasInstance` method, and `Object.prototype.toString` writes a string `@@toStringTag`; `JSON.stringify` calls a String or Number object's `@@toPrimitive` method too. `Date.prototype[Symbol.toPrimitive]` (section 20.4.4.45) converts a Date with `toString` first for the hints `"string"` and `"default"` and with `valueOf` first for `"number"`, so `date + 1` joins the date's string; an object without an `@@toPrimitive` method, a Date whose method is `null` included, tries `valueOf` first when no hint is given. Nothing reads `Symbol.asyncIterator` yet. `Array.prototype.values` (also `Array.prototype[Symbol.iterator]`), `keys` and `entries`, `String.prototype[Symbol.iterator]` and every `arguments` object's `Symbol.iterator` return iterators whose `next()` gives `{value, done}` objects; a string iterator steps by code point and keeps a surrogate pair together. An array iterator reads the `length` at each step, so it visits elements added during the walk. Each step takes fuel, as does each prototype a Symbol-keyed lookup passes, and each Symbol and registry entry counts against the heap limit. A realm made without the option, including one a `.jsx` script starts in the app, has none of these names, and `Realm::set_es2015` changes only the syntax later runs read, so a realm keeps the built-ins it was made with (an engine that `#targetengine` keeps after a `.js` script made it has them in later `.jsx` runs too); a host function that returns a Symbol while the option is off throws a `TypeError`. `for`-`of`, spread and array destructuring call `next()` (see the next line). `cargo xtask test262` runs the suite's tests of `Symbol`, `ArrayIteratorPrototype`, `StringIteratorPrototype`, `Object.getOwnPropertySymbols`, `Array.prototype.values`, `keys`, `entries` and `Symbol.iterator`, and `String.prototype[Symbol.iterator]` that need only these built-ins and parse as ES5, in such a realm: 164 of 216 runs pass (6 passed before), and the 52 others expect a configurable function `length` and a function `name` property. Tests: `crates/js/src/symbol_tests.rs`, `crates/js/tests/test262.rs`.
|
||||
- With `Options::es2015`, `vectorcraft-js` also reads and runs `for`-`of` loops and destructuring (ECMA-262 11th edition, sections 13.7.5, 12.15.5 and 13.3.3, https://262.ecma-international.org/11.0/). `for`-`of` takes `var`, `let` and `const` declarations, patterns and any assignment target, gives a `let` or `const` loop a new binding for each iteration, and calls the iterator's `return` method, when it has one, when `break`, `continue` to an outer loop, `return` or an exception leaves the loop early; an iterator whose `next()` threw or said it was done is not closed, and an exception on its way out wins over one that `return` throws. Array patterns step the iterator with holes, defaults and a rest element, and close it when they stop before its end. Object patterns read names, string and number keys and computed keys, with defaults. Patterns work in `var`, `let` and `const` declarations, assignments (with any assignment target as a leaf, such as `[o.a, o["b"]] = …`), function and arrow parameters, and `catch` clauses, and nest. A default runs only when the value is `undefined`. Destructuring `undefined` or `null` throws a `TypeError`. Object literals also take shorthand properties (`{ a }`) and computed names (`{ [k]: v }`, `get [k]()`), Symbol keys included. Object rest properties (`{ a, ...rest }`, ECMAScript 2018) are syntax errors. In a realm made without the option that `Realm::set_es2015` later switches to it, which has no `Symbol.iterator` (an engine that `#targetengine` keeps after a `.jsx` script made it), `for`-`of`, spread and array patterns walk arrays, `arguments` objects and strings by code point, and other values are a `TypeError`; that rule is VectorCraft's own. Each step takes fuel, a rest element counts against the heap limit, and nested patterns count against `Options::max_depth`. `cargo xtask test262` reads the suite's tests under `language/statements/for-of`, `language/expressions/assignment/dstr` and the `dstr` folders of `var`, `let`, `const`, `function`, function expressions, arrow functions, `try`, `for` and `for`-`in` whose feature tags this engine has: 609 of 617 runs pass (529 before, most of them negative parse tests); the 8 others expect a function given as a default to take the name of its binding, a `name` property `vectorcraft-js` does not set. Tests: `crates/js/src/es2015_tests.rs`, `crates/js/tests/test262.rs`, `crates/engine/src/tests/script_run.rs`.
|
||||
- Scripts: `cargo xtask corpus --scripts` fetches 397 public scripts and 1 file they include from 19 MIT and Apache-2.0 repositories at pinned commits into `corpus/scripts` (gitignored), each repository's license file beside its scripts. `xtask/script-corpus.txt` lists every file with its size and SHA-256, and a download is checked against both before it replaces anything; one more candidate is left out because it is over the 1 MiB limit for one script. `cargo xtask scripts --pass-rate [--report <path>]` runs each script headless in a process of its own (a new document, 5,000,000 instructions, no dialog answers, file reads only in its repository's folder and a new folder of its own, file writes only in that folder, no command it can start, stopped after 10 seconds) and writes a JSON report: the pass rate overall, per repository and for the scripts without dialogs or windows, how many parse, and each script's outcome. Script failures never fail the command, and without the corpus it skips. These limits are VectorCraft's own. Tests: `xtask/src/script_corpus.rs`, `crates/engine/tests/script_corpus.rs`.
|
||||
- With `Options::e4x` set, an E4X name standing alone (`@a`, `@ns::a`, `@[expr]`, `ns::a`, `*`) inside `with` or a filter predicate can be assigned, with `=` or a compound operator, incremented, decremented, deleted and used as a `for` or `for each` variable, as well as read. Each of these uses the nearest XML or XMLList value in scope that holds the name and evaluates the name once. When no XML value in scope holds the name, the read or write throws a `ReferenceError` before the right-hand side runs and creates no child or attribute, as ECMA-357 section 11.1 (https://ecma-international.org/publications-and-standards/standards/ecma-357/) specifies, so a filter such as `list.(@id == '1')` throws when an item has no `@id` and no outer XML value holds one. Tests: `crates/js/src/xml_tests.rs`.
|
||||
- `vectorcraft-js` runs ECMAScript for XML (ECMA-357, 2nd edition, https://ecma-international.org/publications-and-standards/standards/ecma-357/) when `Options::e4x` is set, which it is not by default: XML and XMLList literals with embedded `{}` expressions, the `..`, `.@`, `.*`, `.()` and `::` selectors, assignment and `delete` on selected nodes, `for each`, `default xml namespace`, and the `XML`, `XMLList`, `Namespace` and `QName` objects with their methods and settings. `xml.xpath(expression[, variables])` evaluates an XPath 1.0 expression (https://www.w3.org/TR/1999/REC-xpath-19991116/) with all 13 axes and the 27 core functions, and returns the selected nodes as an XMLList in document order without repeats. Each property of `variables` binds the variable of its name, an XMLList runs the expression on each of its elements in turn, and a prefix in a name test resolves through the context element's in-scope namespaces. An expression that breaks the grammar gives a `SyntaxError`; an unknown function, a wrong argument count, an unbound prefix or variable, and a result that is not a node-set or that holds the root or a namespace node give a `TypeError`. `id()` selects nothing, and evaluation uses no native stack, takes fuel and counts against the heap limit. `<!DOCTYPE>` in an XML string gives a `SyntaxError`. An XML declaration at the start of an XML string, after optional white space, is 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; any other declaration, or one with a character XML does not allow, gives a `SyntaxError`. The parser takes fuel for the length of every name, white space run and declaration it scans, and for the text it searched when a quote, CDATA section, comment or processing instruction is not closed. 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. Tests: `crates/js/src/xml_tests.rs`.
|
||||
|
||||
Reference in new issue
Block a user