From e3077d3c1f4e6a34a4237e7233ef40d033bd668b Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 29 Nov 2026 14:18:39 -0800 Subject: [PATCH] Script check: test the computed-key case of an own saveAs in its own script A computed key such as c[k] = w makes the check unsure for the whole script, so since the last commit every saveAs in that script counts as a write, the ones before the computed key included. The test put that case in the same script as the others, so the own saveAs calls it expected to write nothing were reported. The computed-key case now has its own script and assertion, and the other cases keep theirs. --- crates/scriptcheck/src/tests.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/crates/scriptcheck/src/tests.rs b/crates/scriptcheck/src/tests.rs index 61474e854f..0493014da0 100644 --- a/crates/scriptcheck/src/tests.rs +++ b/crates/scriptcheck/src/tests.rs @@ -671,18 +671,16 @@ fn the_scripts_own_save_as_writes_no_file() { fn a_changed_or_shared_own_save_as_writes_a_file() { let r = report(concat!( "var f = new File(p);\n", - "var a = {saveAs: function () {}}; var b = {saveAs: function () {}}; var c = {saveAs: function () {}};\n", + "var a = {saveAs: function () {}}; var b = {saveAs: function () {}};\n", "var d = {saveAs: function () {}}; var e = {saveAs: function () {}}; var g = {saveAs: function () {}};\n", "a.saveAs(f); b['saveAs'](f); a.n = 1; a.n;\n", "a.saveAs = app.activeDocument.saveAs;\n", "b['saveAs'] = w;\n", - "c[k] = w;\n", "delete d.saveAs;\n", "var h = e;\n", "use(g);\n", "a.saveAs(f);\n", "b.saveAs(f);\n", - "c.saveAs(f);\n", "d.saveAs(f);\n", "e.saveAs(f);\n", "g['saveAs'](f);\n", @@ -693,7 +691,11 @@ fn a_changed_or_shared_own_save_as_writes_a_file() { "q['saveAs'](f);\n", "s.saveAs(f);\n", )); - assert_eq!(feature(&r, "file.write").map(|f| f.lines.as_slice()), Some(&[11, 12, 13, 14, 15, 16, 18, 19, 21, 22][..])); + assert_eq!(feature(&r, "file.write").map(|f| f.lines.as_slice()), Some(&[10, 11, 12, 13, 14, 16, 17, 19, 20][..])); + // A computed key may name any variable, so every `saveAs` in the script may write, the ones + // before the computed key included. + let r = report("var f = new File(p);\nvar c = {saveAs: function () {}};\nc.saveAs(f);\nc[k] = w;\nc.saveAs(f);\n"); + assert_eq!(feature(&r, "file.write").map(|f| f.lines.as_slice()), Some(&[3, 5][..])); } /// Only a `var` statement directly in a function body or the global code that gives its first name