mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-01 02:35:37 +01:00
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.
This commit is contained in:
1 parent
b1e9a4cbb3
commit
e3077d3c1f
1 file changed
+6
-4
@@ -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
|
||||
|
||||
Reference in new issue
Block a user