From 7285bd87a18c8cc596536e933fcc02fbbd6bd320 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 22 Nov 2026 15:47:52 -0800 Subject: [PATCH] JavaScript: for-in, spread, Reflect.construct and eval follow the proxy and kept-realm rules - for-in skips a name made non-enumerable during the loop on an ordinary object as it does on a proxy, and a name a proxy's ownKeys trap lists without a descriptor no longer hides the same name further up the chain. - Spread treats a proxy on an array's prototype chain as code that can run on an index read, so a long array is not refused before its elements are read. - Reflect.construct with Number, String, Date or Function converts the arguments before it reads newTarget's prototype (ECMA-262 2020 sections 20.1.1.1, 21.1.1.1, 20.4.2 and 19.2.1.1.1). - Eval code outside strict mode code is checked against the let and const names of earlier runs when Options::es2015 is off. - Options::es2015's doc and the target-app-parity line describe a kept realm that gets Proxy and Reflect at its first run with the option. --- crates/js/src/es2015_tests.rs | 16 +++++++ crates/js/src/interp.rs | 79 ++++++++++++++++++++++++----------- crates/js/src/lib.rs | 5 ++- crates/js/src/proxy_tests.rs | 74 ++++++++++++++++++++++++++++++++ docs/target-app-parity.md | 2 +- 5 files changed, 149 insertions(+), 27 deletions(-) diff --git a/crates/js/src/es2015_tests.rs b/crates/js/src/es2015_tests.rs index 0173fb2d6c..53493ceb21 100644 --- a/crates/js/src/es2015_tests.rs +++ b/crates/js/src/es2015_tests.rs @@ -194,6 +194,22 @@ fn a_function_eval_declares_on_the_global_object_sees_global_lexical_bindings() assert_eq!(realm.run("function g() { eval('function inner() { return x; }'); return inner(); } g()"), Ok(JsValue::Number(7.0))); } +#[test] +fn eval_without_the_option_cannot_redeclare_an_earlier_runs_let() { + // An earlier run's `let` stays a `let` when the option is turned off: an eval `var` or + // function of the same name is a `SyntaxError`, and the binding keeps its value. + let mut realm = es(); + assert_eq!(realm.run("let x = 1; 0"), Ok(JsValue::Number(0.0))); + realm.set_es2015(false); + for src in ["eval('var x = 2')", "eval('function x() {}')", "(0, eval)('var x = 2')"] { + let r = realm.run(src); + assert!(matches!(&r, Err(RunError { message, .. }) if message.starts_with("SyntaxError")), "{src}: {r:?}"); + } + assert_eq!(realm.run("x === 1 && !this.hasOwnProperty('x')"), Ok(JsValue::Bool(true))); + // A name no `let` holds is still declared. + assert_eq!(realm.run("eval('var y = 3'); y"), Ok(JsValue::Number(3.0))); +} + #[test] fn a_global_var_makes_its_own_property_over_an_inherited_one() { // ECMA-262 2015 section 8.1.1.4.17 reads the global object's own property, so `var` makes a diff --git a/crates/js/src/interp.rs b/crates/js/src/interp.rs index 7862dbe3c6..b41d3609e0 100644 --- a/crates/js/src/interp.rs +++ b/crates/js/src/interp.rs @@ -2534,11 +2534,15 @@ impl Interp { } /// Whether reading the elements of `o` by index can run code: `o` or an object it inherits - /// from has an accessor property with an index name. Each object takes a unit of fuel. + /// from has an accessor property with an index name, or a proxy, whose traps answer the reads + /// that reach it, is on its prototype chain. Each object takes a unit of fuel. fn has_index_getter(&mut self, o: ObjId) -> JsResult { let mut cur = Some(o); while let Some(id) = cur { self.use_fuel()?; + if self.is_proxy(id) { + return Ok(true); + } let object = self.object(id)?; if object.props.iter().any(|(k, p)| matches!(p, Prop::Accessor { .. }) && array_index(k).is_some()) { return Ok(true); @@ -2652,7 +2656,8 @@ impl Interp { /// [`Self::enumerable_keys`] after the XML case. A proxy on the chain gives its names with its /// `ownKeys` trap, whether each is enumerable with its `getOwnPropertyDescriptor` trap and the - /// next object with its `getPrototypeOf` trap, which `temp_roots[slot]` keeps reachable. + /// next object with its `getPrototypeOf` trap, which `temp_roots[slot]` keeps reachable. A name + /// whose descriptor trap gives `undefined` does not hide the same name further up the chain. fn enumerable_keys_from(&mut self, id: ObjId, slot: usize) -> JsResult> { let mut seen = std::collections::HashSet::new(); let mut out = Vec::new(); @@ -2661,10 +2666,12 @@ impl Interp { if self.is_proxy(o) { for k in self.own_keys(o)? { self.use_fuel()?; - if !seen.insert(k.clone()) { + if seen.contains(&k) { continue; } - if self.get_own_property(o, &k)?.is_some_and(|p| p.enumerable()) { + let Some(p) = self.get_own_property(o, &k)? else { continue }; + seen.insert(k.clone()); + if p.enumerable() { out.push(k); } } @@ -2744,11 +2751,11 @@ impl Interp { } /// Whether `for-in` over `o` still visits `k` (section 12.6.4; ECMA-262 2020 section - /// 13.7.5.15): an object on the chain before any proxy has the property, or a proxy's - /// `getOwnPropertyDescriptor` trap gives an enumerable one, or the objects after a proxy - /// without the property have it. A name deleted, or on a proxy made non-enumerable, after the - /// names were listed is skipped. A proxy's `has` trap is not asked. Each proxy on the chain - /// takes a unit of fuel. + /// 13.7.5.15): the property found first on the chain, on an ordinary object or through a + /// proxy's `getOwnPropertyDescriptor` trap, is enumerable. After a proxy without the property, + /// the objects that follow it are searched. A name deleted or made non-enumerable after the + /// names were listed is skipped, on an ordinary object as on a proxy. A proxy's `has` trap is + /// not asked. Each proxy on the chain takes a unit of fuel. fn for_in_still_has(&mut self, o: ObjId, k: &[u16]) -> JsResult { let mark = self.temp_roots.len(); let r = self.for_in_still_has_rooted(o, k); @@ -2759,7 +2766,7 @@ impl Interp { fn for_in_still_has_rooted(&mut self, mut cur: ObjId, k: &[u16]) -> JsResult { loop { let p = match self.lookup(cur, k)? { - Lookup::Found(_) => return Ok(true), + Lookup::Found(prop) => return Ok(prop.enumerable()), Lookup::Missing => return Ok(false), Lookup::Proxy(p) => p, }; @@ -3039,19 +3046,24 @@ impl Interp { // With a different `newTarget` (`Reflect.construct`), the new object takes // its `prototype` when that is an object (ECMA-262 2020 section 9.1.14). An // argument given back and a proxy keep their own. `Object` makes a new object - // instead of converting its argument (section 19.1.1.1). - let proto = if same_value(&f, &new_target) { - None - } else { - match self.get_value(&new_target, &key("prototype"))? { - Value::Object(p) => { - self.temp_roots.push(Value::Object(p)); - Some(p) - } - _ => None, + // instead of converting its argument (section 19.1.1.1). `Number`, `String`, + // `Date` and `Function` convert their arguments before `prototype` is read + // (sections 20.1.1.1, 21.1.1.1, 20.4.2 and 19.2.1.1.1), so a conversion that + // throws reads nothing from `newTarget`. + let other_target = !same_value(&f, &new_target); + let converts_first = other_target && { + let i = &self.intrinsics; + let own = [i.number_proto, i.string_proto, i.date_proto, i.function_proto]; + match f.as_object().map(|c| self.ordinary_own_property(c, &key("prototype"))).transpose()?.flatten() { + Some(Prop::Data { value: Value::Object(p), .. }) => own.contains(&p), + _ => false, } }; - if !same_value(&f, &new_target) && f.as_object() == Some(self.intrinsics.object_ctor) { + let mut proto = None; + if other_target && !converts_first { + proto = self.prototype_of_new_target(&new_target)?; + } + if other_target && f.as_object() == Some(self.intrinsics.object_ctor) { let proto = proto.unwrap_or(self.intrinsics.object_proto); self.reserve_heap(OBJECT_BYTES)?; let obj = self.heap.alloc_object(Object::new(Class::Ordinary, Some(proto))); @@ -3061,6 +3073,11 @@ impl Interp { let r = native(self, Value::Undefined, &args, true); self.held_bytes = held; let v = r?; + if converts_first { + // The new object stays reachable while `prototype` is read. + self.temp_roots.push(v.clone()); + proto = self.prototype_of_new_target(&new_target)?; + } if let (Some(p), Value::Object(o)) = (proto, &v) && !self.is_proxy(*o) && !args.iter().any(|a| same_value(a, &v)) @@ -3075,6 +3092,18 @@ impl Interp { } } + /// The `prototype` of `newTarget` when it is an object, kept reachable in `temp_roots` + /// (ECMA-262 2020 section 9.1.14). + fn prototype_of_new_target(&mut self, new_target: &Value) -> JsResult> { + Ok(match self.get_value(new_target, &key("prototype"))? { + Value::Object(p) => { + self.temp_roots.push(Value::Object(p)); + Some(p) + } + _ => None, + }) + } + /// Construct (ECMA-262 2020 section 7.3.13) from Rust: runs a constructor written in /// JavaScript to its end. pub(crate) fn construct(&mut self, f: &Value, args: &[Value], new_target: &Value) -> JsResult { @@ -3618,12 +3647,14 @@ impl Interp { /// /// Gives the environment the code runs in: `env`, or with [`Options::es2015`] eval code's own /// environment of its `let` and `const` names. A script's `let` and `const` names go in the - /// global scope ([`Self::declare_global_lexical`]). + /// global scope ([`Self::declare_global_lexical`]). Eval code outside strict mode code is + /// checked against the `let` and `const` names around it ([`Self::check_eval_vars`]) with the + /// option on or off, so it also meets the names that earlier runs of a kept realm declared. fn instantiate_global(&mut self, code: &Rc, env: EnvId, var_env: EnvId, is_eval: bool) -> JsResult { let configurable = if is_eval { CONFIGURABLE } else { 0 }; - if is_eval && !code.strict && self.options.es2015 { + if is_eval && !code.strict { self.check_eval_vars(code, env, var_env)?; - if var_env == self.global_env { + if self.options.es2015 && var_env == self.global_env { self.check_global_functions(code)?; self.check_global_vars(code)?; } diff --git a/crates/js/src/lib.rs b/crates/js/src/lib.rs index f2ae96e581..3a8740c4d6 100644 --- a/crates/js/src/lib.rs +++ b/crates/js/src/lib.rs @@ -118,8 +118,9 @@ pub struct Options { /// template literals (tagged ones included), default and rest parameters, and spread in array /// literals, calls and `new`. Off, they are syntax errors and the language is ES5.1's. Code a /// script evaluates at run time (`eval`, `Function`) is read the way the realm reads scripts. - /// A realm made with it also has the globals `Proxy` and `Reflect`; turning it on later for a - /// realm made without it does not add them. + /// A realm made with it also has the globals `Proxy` and `Reflect`. A realm made without it + /// gets them at its first run with the option on, and keeps them when later runs turn it off. + /// A `Proxy` or `Reflect` global that an earlier run defined stays as it is. pub es2015: bool, } diff --git a/crates/js/src/proxy_tests.rs b/crates/js/src/proxy_tests.rs index ec993f914c..e84697eb69 100644 --- a/crates/js/src/proxy_tests.rs +++ b/crates/js/src/proxy_tests.rs @@ -324,6 +324,39 @@ fn reflect_construct_gives_a_built_in_object_the_prototype_of_new_target() { ); } +#[test] +fn reflect_construct_reads_new_target_prototype_after_number_and_string_convert() { + // `Number`, `String`, `Date` and `Function` convert their arguments before they read + // `newTarget.prototype`; `Array` and the error types read it first. + let made = "var log = []; + var nt = new Proxy(function () {}, { get: function (t, k) { log.push(k); return t[k]; } }); + var arg = { valueOf: function () { log.push('valueOf'); return 3; }, toString: function () { log.push('toString'); return 's'; } }; + var n = Reflect.construct(Number, [arg], nt), numberLog = log.join(); log = []; + var s = Reflect.construct(String, [arg], nt), stringLog = log.join(); log = []; + var d = Reflect.construct(Date, [arg], nt), dateLog = log.join(); log = []; + var e = Reflect.construct(Error, [arg], nt), errorLog = log.join(); log = []; + var proto = nt.prototype;"; + assert_eq!( + es().run(&format!("{made} [numberLog, stringLog, dateLog, errorLog].join(' | ')")), + Ok(JsValue::String("valueOf,prototype | toString,prototype | valueOf,prototype | prototype,toString".into())) + ); + truth(&format!( + "{made} Object.getPrototypeOf(n) === proto && Number.prototype.valueOf.call(n) === 3 + && Object.getPrototypeOf(s) === proto && String.prototype.toString.call(s) === 's' + && Object.getPrototypeOf(d) === proto && Date.prototype.getTime.call(d) === 3 && Object.getPrototypeOf(e) === proto" + )); + // A conversion that throws reads nothing from `newTarget`. + truth( + "var log = []; + var nt = new Proxy(function () {}, { get: function (t, k) { log.push(k); return t[k]; } }); + var bad = { valueOf: function () { throw 1; }, toString: function () { throw 1; } }; + var thrown = 0; + try { Reflect.construct(Number, [bad], nt); } catch (e) { thrown++; } + try { Reflect.construct(String, [bad], nt); } catch (e) { thrown++; } + thrown === 2 && log.length === 0", + ); +} + /// Runs `src` with a collection at every heap reservation, and checks that it gives `true`. fn truth_collecting(src: &str) { let mut realm = es(); @@ -419,6 +452,47 @@ fn arrays_json_for_in_and_keys_read_a_proxy_through_its_traps() { ); } +#[test] +fn for_in_reads_ordinary_and_proxy_names_by_the_same_rules() { + // A name made non-enumerable during the loop is skipped on an ordinary object, as on a proxy. + truth( + "var o = { a: 1, b: 2, c: 3 }, seen = []; + for (var k in o) { seen.push(k); if (k === 'a') Object.defineProperty(o, 'b', { enumerable: false }); } + var p = new Proxy({ a: 1, b: 2 }, {}), proxySeen = []; + for (var k in Object.create(p)) { proxySeen.push(k); if (k === 'a') Object.defineProperty(p, 'b', { enumerable: false }); } + seen.join() === 'a,c' && proxySeen.join() === 'a'", + ); + // A name the `ownKeys` trap lists without a descriptor does not hide an enumerable one further + // up the chain; a non-enumerable own property does. + truth( + "var p = new Proxy(Object.create({ x: 1, y: 2 }), { + ownKeys: function () { return ['x', 'y']; }, + getOwnPropertyDescriptor: function (t, k) { return k === 'y' ? { value: 0, enumerable: false, configurable: true } : undefined; } + }); + var seen = []; + for (var k in p) seen.push(k); + seen.join() === 'x'", + ); +} + +#[test] +fn spread_lets_a_proxy_on_the_prototype_chain_shrink_a_long_array() { + // A proxy's `get` trap answers for the indices the array does not hold, so the length is not + // refused before the elements are read. + truth( + "var a = []; a.length = 4294967295; + Reflect.setPrototypeOf(a, new Proxy({}, { get: function (t, k) { if (k === '0') a.length = 1; return 'v'; } })); + var r = [...a]; + r.length === 1 && r[0] === 'v'", + ); + // Without a proxy or a getter, the length is refused at once. + let src = "var a = []; a.length = 4294967295; [...a]"; + match es().run(src) { + Err(RunError { kind: RunErrorKind::Thrown, message, .. }) => assert!(message.starts_with("RangeError"), "{src}: {message}"), + other => panic!("{src}: {other:?}"), + } +} + #[test] fn instanceof_and_typeof_read_a_proxy() { truth( diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 405984ca5c..34e09f8112 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1080,7 +1080,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur - `vectorcraft-js` identifiers, written out or as `\uXXXX` and `\u{...}` escapes, take the characters Unicode's `ID_Start` and `ID_Continue` properties allow (https://www.unicode.org/reports/tr31/), plus `$` and, at the start, `_`, as later ECMAScript editions define them (https://tc39.es/ecma262/#sec-names-and-keywords). `Other_ID_Start` characters such as U+2118 and `Other_ID_Continue` characters such as U+00B7 and the zero width non-joiner and joiner are accepted, and no `Pattern_Syntax` or `Pattern_White_Space` character is. Letter categories come from Unicode 17.0, so U+088F starts an identifier and U+1ACF may follow its first character; characters assigned after Unicode 17.0 are not yet identifier characters. Tests: `crates/js/src/tests.rs` (`identifier_characters_are_unicode_17_id_start_and_id_continue`, which checks every code point, `identifiers_take_the_characters_unicode_17_assigned`, `identifiers_take_the_other_id_start_and_continue_characters`, `identifiers_refuse_pattern_syntax_surrogates_and_bad_escapes`, `no_pattern_syntax_or_white_space_character_is_an_identifier_character`). - `vectorcraft-js`'s `Realm` runs ECMAScript 5.1 scripts: the parsed script compiles to verified bytecode that a non-recursive interpreter runs, with closures, `this`, `arguments`, `with`, direct and indirect `eval`, `new Function`, `try`/`catch`/`finally`, labeled `break` and `continue`, and `for`-`in` in insertion order, over a mark-and-sweep heap, with the built-ins the next two entries list. Every run is bounded by fuel, heap bytes, frames, nested host calls and an interrupt flag (smaller defaults in the wasm build), and a run that reaches a limit stops with a limit error that `try` cannot catch. `cargo xtask test262` also runs the suite's ES5 language tests that need only the built-ins present: 4,280 of 4,286 runs pass (4 of the others expect the completion values of later editions, and 2 expect a configurable function `length`). The app does not call it yet. Tests: `crates/js/src/interp_tests.rs`, `crates/js/tests/test262.rs`. - With `Options::es2015`, `vectorcraft-js` also reads and runs these ECMAScript 2015 forms (https://262.ecma-international.org/6.0/): `let` and `const` with block scope and their temporal dead zone (a read or write before the declaration runs throws a `ReferenceError`, and a write to a `const` throws a `TypeError` in any code), a new `let` binding for each iteration of a `for` or `for`-`in` loop, function declarations scoped to their block, arrow functions with the `this` and `arguments` of the code around them and no `prototype`, template literals and tagged templates with one frozen strings object for each site, default and rest parameters with an `arguments` object that does not follow the parameters, and spread in array literals, calls and `new`. Spread reads arrays by index, reading the length again before each element, strings and `String` objects by code point, and objects with a `length` property by index, and throws a `TypeError` for any other value; that rule is VectorCraft's own until iterators are added. Spread and template objects take fuel for each element and count against the heap limit, and nested arrows and templates count against `Options::max_depth`. `script.run` sets the option for a `.js` file, and `eval`, `Function`, `#include` files and `$.evalFile` read code the way the script does; a `.jsx` file and a `source` string stay ES5.1. Destructuring, `for`-`of`, classes, generators and modules are still syntax errors. `cargo xtask test262` reads the suite's tests of these forms without and with the option: 390 of 390 negative parse runs and 533 of 708 other runs pass with it (373 and 27 without it). Of the 175 failing runs, 151 do not parse because the tests also use forms this list leaves out (classes, method definitions, destructuring, `for`-`of`, trailing commas in parameter lists, and a later edition's rule for escapes in tagged templates), and 24 expect function `name` properties, a configurable function `length` and the `caller` and `arguments` restrictions, ECMAScript 2015 rules that `vectorcraft-js` does not implement. Tests: `crates/js/src/es2015_tests.rs`, `crates/js/tests/test262.rs`, `crates/engine/src/tests/script_run.rs`. - - A realm made with `Options::es2015` also has `Proxy`, with `Proxy.revocable`, and `Reflect` with its thirteen functions (https://262.ecma-international.org/11.0/, sections 9.5, 26.1 and 26.2), with string property names. Every internal method of an object goes through one dispatch, so a proxy's traps run for property reads and writes, `in`, `delete`, `for`-`in`, `Object.keys` and the other `Object` functions, `instanceof`, calls and `new`, and when the proxy is a prototype or a `with` object; `Array.isArray`, `concat` and `JSON.stringify` treat a proxy of an array as an array. Each trap result is checked against the target's invariants (non-configurable and non-extensible targets, and `ownKeys` results with a duplicate or a value that is not a string), and a violation or an operation on a revoked proxy throws a `TypeError`. Traps take fuel and count against the limit on nested calls, so a trap that calls itself or a chain of proxies stops at a limit error, and a proxy given to the app in a command's params throws a `TypeError` naming it without running its traps. `script.run` gives a `.js` file both globals; a `.jsx` file and a `source` string have neither. `cargo xtask test262` runs the suite's `Proxy` and `Reflect` tests whose features are present: 573 of 663 runs pass with the option (0 without it). Of the 90 failing runs, 4 do not parse because the tests use method definitions, and 86 expect function `name` properties and a configurable function `length`, `Object.setPrototypeOf`, and integer keys listed before other keys, ECMAScript 2015 rules that `vectorcraft-js` does not implement. Tests: `crates/js/src/proxy_tests.rs`, `crates/js/tests/test262.rs`, `crates/engine/src/tests/script_run.rs`. + - A realm made with `Options::es2015` also has `Proxy`, with `Proxy.revocable`, and `Reflect` with its thirteen functions (https://262.ecma-international.org/11.0/, sections 9.5, 26.1 and 26.2), with string property names. Every internal method of an object goes through one dispatch, so a proxy's traps run for property reads and writes, `in`, `delete`, `for`-`in`, `Object.keys` and the other `Object` functions, `instanceof`, calls and `new`, and when the proxy is a prototype or a `with` object; `Array.isArray`, `concat` and `JSON.stringify` treat a proxy of an array as an array. Each trap result is checked against the target's invariants (non-configurable and non-extensible targets, and `ownKeys` results with a duplicate or a value that is not a string), and a violation or an operation on a revoked proxy throws a `TypeError`. Traps take fuel and count against the limit on nested calls, so a trap that calls itself or a chain of proxies stops at a limit error, and a proxy given to the app in a command's params throws a `TypeError` naming it without running its traps. `script.run` gives a `.js` file both globals; a `.jsx` file and a `source` string have neither in a new engine or in an engine that has not run a `.js` file. An engine that `#targetengine` keeps gets both globals at its first `.js` run and keeps them for later `.jsx` runs, which still read ES5.1. `cargo xtask test262` runs the suite's `Proxy` and `Reflect` tests whose features are present: 573 of 663 runs pass with the option (0 without it). Of the 90 failing runs, 4 do not parse because the tests use method definitions, and 86 expect function `name` properties and a configurable function `length`, `Object.setPrototypeOf`, and integer keys listed before other keys, ECMAScript 2015 rules that `vectorcraft-js` does not implement. Tests: `crates/js/src/proxy_tests.rs`, `crates/js/tests/test262.rs`, `crates/engine/src/tests/script_run.rs`. - `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`.