mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-01 02:35:37 +01:00
Scripts: refuse unsafe close saves and refused multi-file writes up front
- A save of several files whose file access refuses one of them returns the refusal before any file goes to the writer, so a writer that does not check the file access writes nothing. - close(SaveOptions.SAVECHANGES) throws before writing, and leaves the document open, when the document's last save named some of its artboards, since saving with those options again could leave changes out of the file. - The script check no longer treats an object literal's saveAs or exportFile as the script's own when a function body assigns the variable without declaring it, or when the script assigns it as a property of this (the global object in global code and in a function called without a receiver). - The close-with-SAVECHANGES format test reads the saved PDF and checks that it holds the change made after the first save. - docs/mcp.md limits the "none of them is written" sentence for SVG linked images to refusals found before the first write, and documents the new close refusal.
This commit is contained in:
1 parent
887c67a8f1
commit
39c5e98a3e
7 files changed
+168
-14
No files matched your search
@@ -664,6 +664,46 @@ fn only_a_whole_var_value_makes_save_as_the_scripts_own() {
|
||||
assert_eq!(feature(&r, "file.write").map(|f| f.lines.as_slice()), Some(&[4, 7, 9, 11, 13, 14, 17][..]));
|
||||
}
|
||||
|
||||
/// A function body read before the literal that assigns its variable without declaring it may run
|
||||
/// after the literal, so the literal's `saveAs` keeps reporting the write; a body that declares the
|
||||
/// name assigns its own variable.
|
||||
#[test]
|
||||
fn a_function_read_earlier_that_assigns_the_variable_keeps_save_as_writing() {
|
||||
let r = report(concat!(
|
||||
"var f = new File(p);\n",
|
||||
"function choose() { d = app.activeDocument; }\n",
|
||||
"var d = {saveAs: function () {}};\n",
|
||||
"choose(); d.saveAs(f);\n",
|
||||
"function bump() { e++; }\n",
|
||||
"var e = {saveAs: function () {}};\n",
|
||||
"e.saveAs(f);\n",
|
||||
"function own() { var g; g = app.activeDocument; }\n",
|
||||
"var g = {saveAs: function () {}};\n",
|
||||
"g.saveAs(f);\n",
|
||||
));
|
||||
assert_eq!(feature(&r, "file.write").map(|f| f.lines.as_slice()), Some(&[4, 7][..]));
|
||||
}
|
||||
|
||||
/// Assigning a property of `this`, the global object in the global code and in a function called
|
||||
/// without a receiver, may give the global variable of that name another value, before or after
|
||||
/// its literal.
|
||||
#[test]
|
||||
fn assigning_a_property_of_this_keeps_save_as_writing() {
|
||||
let r = report(concat!(
|
||||
"var f = new File(p);\n",
|
||||
"var d = {saveAs: function () {}};\n",
|
||||
"this.d = app.activeDocument;\n",
|
||||
"d.saveAs(f);\n",
|
||||
"function swap() { this['e'] = app.activeDocument; }\n",
|
||||
"var e = {saveAs: function () {}};\n",
|
||||
"swap(); e.saveAs(f);\n",
|
||||
"var g = {saveAs: function () {}};\n",
|
||||
"this.other = 1;\n",
|
||||
"g.saveAs(f);\n",
|
||||
));
|
||||
assert_eq!(feature(&r, "file.write").map(|f| f.lines.as_slice()), Some(&[4, 7][..]));
|
||||
}
|
||||
|
||||
/// A `saveAs` key's value is a method of the script's own only when the whole value is one function
|
||||
/// expression: a value that goes on after the function's body, and a literal inside another, leave
|
||||
/// `saveAs` writing the file. A literal given to a function body's own variable at the end of the body
|
||||
|
||||
Reference in new issue
Block a user