mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-01 02:35:37 +01:00
Merge main into feat/scripts-api-d6-save-export-open
main's Document member list held saveAs and close as members that are not available yet; this branch's save_open members implement them, so the merge drops them from that list and keeps main's other entries. The script host test lists take main's members together with this branch's open, userInteractionLevel, fullName, path, saved and option classes, and the heap accounting keeps main's ModuleNamespace arm beside the FsEntry string arm.
This commit is contained in:
commit
b1e9a4cbb3
333 files changed
+22539
-2096
No files matched your search
@@ -65,6 +65,11 @@ impl Known {
|
||||
self.bound.len() + self.files.len().saturating_mul(2).saturating_sub(self.folders.len()) + usize::from(self.unsure)
|
||||
}
|
||||
|
||||
/// No variable holds a member chain or a File or Folder object. [`Known::unsure`] may be set.
|
||||
pub fn no_names(&self) -> bool {
|
||||
self.bound.is_empty() && self.files.is_empty()
|
||||
}
|
||||
|
||||
/// What `other` adds, up to [`crate::Limits::entries`] names of each kind: a name already
|
||||
/// bound keeps its chain. A name that holds a File or Folder object on both sides holds a Folder
|
||||
/// object only when both sides say so; otherwise it may hold a File object.
|
||||
|
||||
@@ -231,7 +231,9 @@ pub fn check(name: &str, bytes: &[u8], loader: Option<&mut dyn Loader>, limits:
|
||||
/// that includes nothing, so a variable a function uses before the global code assigns it holds
|
||||
/// what it is assigned. `first` holds the scan made with nothing known, which found `known`, and
|
||||
/// `pre` what came before it. A scan made with what the scans before it found, and that finds
|
||||
/// nothing more, is the report scan; no other scan is repeated.
|
||||
/// nothing more, is the report scan; no other scan is repeated. When `known` holds no name, `first`
|
||||
/// is the report: [`analyze::Known::unsure`] alone comes from `declared`, which the first scan
|
||||
/// already read.
|
||||
fn settle<'l>(
|
||||
first: report::Acc<'l>,
|
||||
pre: report::Acc<'l>,
|
||||
@@ -240,7 +242,7 @@ fn settle<'l>(
|
||||
braced: &[analyze::Braced],
|
||||
mut known: analyze::Known,
|
||||
) -> report::Acc<'l> {
|
||||
if known.len() == 0 {
|
||||
if known.no_names() {
|
||||
return first;
|
||||
}
|
||||
let entries = pre.limits.entries;
|
||||
|
||||
@@ -2188,12 +2188,41 @@ fn the_costliest_inputs_stay_within_five_steps_a_byte() {
|
||||
format!("\\u0061;function f({}) {{ var {}; }}", names.join(","), names.join(",")),
|
||||
format!("\\u0061;function f({}) {{}}", vec!["a"; 900].join(",")),
|
||||
format!("\\u0061;{}", "x=(".repeat(600)),
|
||||
format!("\\u0061;o[k];{}", "{".repeat(2_000)),
|
||||
] {
|
||||
let r = report(&src);
|
||||
assert!(r.steps <= 5 * src.len() + 16, "{} steps for {} bytes", r.steps, src.len());
|
||||
}
|
||||
}
|
||||
|
||||
/// The most steps a check of `bytes` without a loader may take. The text is read once for the
|
||||
/// escapes and once for the names declared, and a scan takes at most three steps a byte. A script
|
||||
/// whose variables hold nothing the check follows is scanned once: five steps a byte. Any other
|
||||
/// script is scanned up to five times (the first scan, three more while what its variables hold
|
||||
/// grows, and the report's): seventeen steps a byte.
|
||||
fn step_bound(bytes: &[u8]) -> usize {
|
||||
let limits = Limits::default();
|
||||
let mut acc = report::Acc::new(&limits);
|
||||
let (text, _) = decode(bytes);
|
||||
let (text, braced) = analyze::unescaped(text, &mut acc);
|
||||
let declared = analyze::declarations(&text, &mut acc);
|
||||
let known = analyze::scan(&text, &declared, &braced, None, std::rc::Rc::from([]), &analyze::Known::default(), &mut acc).known;
|
||||
let scans = if known.no_names() { 1 } else { 5 };
|
||||
(2 + 3 * scans) * bytes.len() + 16
|
||||
}
|
||||
|
||||
/// A name in brackets that is not one literal (`0[ \| … ]`) gives no variable a value, so the
|
||||
/// script is scanned once. The bytes are the ones a run of the property below found.
|
||||
#[test]
|
||||
fn a_script_that_binds_no_name_is_scanned_once() {
|
||||
let bytes: &[u8] = b"\x01\x01 \x010 !0!\x01!\x01#\x01#{#{ 0( #0\x01( \x01( {#{ # \x01#0:((0[\t \\| \x1b!!0:|!| 0) ) )] ! \x1b \x1b \x1b \\u\t\x01";
|
||||
assert_eq!(bytes.len(), 104);
|
||||
let r = check("a.jsx", bytes, None, &Limits::default());
|
||||
assert_eq!(r.kind, Kind::Script);
|
||||
assert_eq!(step_bound(bytes), 5 * bytes.len() + 16);
|
||||
assert!(r.steps <= 5 * bytes.len() + 16, "{} steps for {} bytes", r.steps, bytes.len());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lists_stop_at_their_limits_and_echoes_are_cut() {
|
||||
let mut s = String::new();
|
||||
@@ -2592,13 +2621,13 @@ proptest! {
|
||||
#[test]
|
||||
fn any_bytes_are_checked_in_linear_work(bytes in prop::collection::vec(any::<u8>(), 0..2_000), jsxbin in any::<bool>()) {
|
||||
let r = check(if jsxbin { "a.jsxbin" } else { "a.jsx" }, &bytes, None, &Limits::default());
|
||||
prop_assert!(r.steps <= 5 * bytes.len() + 16, "{} steps for {} bytes", r.steps, bytes.len());
|
||||
prop_assert!(r.steps <= step_bound(&bytes), "{} steps for {} bytes", r.steps, bytes.len());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn script_like_text_is_checked_in_linear_work(text in script_text()) {
|
||||
let r = report(&text);
|
||||
prop_assert!(r.steps <= 5 * text.len() + 16, "{} steps for {} bytes", r.steps, text.len());
|
||||
prop_assert!(r.steps <= step_bound(text.as_bytes()), "{} steps for {} bytes", r.steps, text.len());
|
||||
let limits = Limits::default();
|
||||
for list in [r.targets.len(), r.directives.len(), r.includes.len(), r.members.len(), r.types.len(), r.menu_strings.len(), r.problems.len()] {
|
||||
prop_assert!(list <= limits.entries);
|
||||
@@ -2702,3 +2731,25 @@ fn variables_that_settle_over_several_scans_stay_linear() {
|
||||
let r = report(&src);
|
||||
assert!(r.steps <= 9 * src.len() + 16, "{} steps for {} bytes", r.steps, src.len());
|
||||
}
|
||||
|
||||
/// A script whose declarations give names values the analysis doesn't read, and whose variables
|
||||
/// hold nothing the check knows, is scanned once: a second scan would find the same. The bytes are
|
||||
/// the input `any_bytes_are_checked_in_linear_work` shrank to when it found the second scan.
|
||||
#[test]
|
||||
fn a_script_that_is_only_unsure_is_scanned_once() {
|
||||
let bytes: &[u8] = &[
|
||||
1, 1, 32, 1, 48, 32, 33, 48, 33, 1, 33, 1, 35, 1, 35, 123, 35, 123, 32, 48, 40, 32, 35, 48, 1, 40, 32, 1, 40, 32, 32, 123, 35, 123, 32, 35,
|
||||
32, 1, 35, 48, 58, 40, 40, 48, 91, 9, 32, 92, 124, 32, 27, 33, 33, 48, 58, 124, 33, 124, 32, 48, 41, 32, 32, 41, 32, 41, 93, 32, 32, 32, 32,
|
||||
33, 32, 32, 32, 32, 27, 32, 32, 32, 32, 27, 32, 32, 32, 27, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 92, 117, 9, 1,
|
||||
];
|
||||
let limits = Limits::default();
|
||||
let mut acc = crate::report::Acc::new(&limits);
|
||||
let (text, _) = decode(bytes);
|
||||
let (text, braced) = analyze::unescaped(text, &mut acc);
|
||||
let declared = analyze::declarations(&text, &mut acc);
|
||||
let scan = analyze::scan(&text, &declared, &braced, None, std::rc::Rc::from([]), &analyze::Known::default(), &mut acc);
|
||||
assert!(scan.known.unsure && scan.known.bound.is_empty() && scan.known.files.is_empty());
|
||||
let r = check("a.jsx", bytes, None, &limits);
|
||||
assert_eq!(r.steps, acc.steps);
|
||||
assert!(r.steps <= 5 * bytes.len() + 16, "{} steps for {} bytes", r.steps, bytes.len());
|
||||
}
|
||||
Reference in new issue
Block a user