Scripts: null exportForScreens arguments throw, and a read before a closing brace is shared

- Document.exportForScreens throws a TypeError for null in place of the
  options, itemToExport or fileNamePrefix, as exportFile does for null
  options, instead of taking the defaults.
- The script checker counts a variable read just before the `}` that
  closes a function body (`function get() { return $.global['local'] }`)
  as read in that body, so a later literal's saveAs is no longer exempt.
This commit is contained in:
dotCooCoo committed 2026-12-04 16:04:49 -08:00
1 parent ddfc1c4c7a
commit 8b82ccf327
6 files changed
+50 -7

No files matched your search

@@ -38,6 +38,7 @@
//! accepted at its default and throws at any other value, and a property the pages do not list
//! throws an error that names it, unless it is `undefined`. The options object's class must be
//! the one of `exportFormat`, and an omitted options object takes the defaults a new one holds.
//! `null` in place of the options, `itemToExport` or `fileNamePrefix` throws a TypeError.
use std::rc::Rc;
@@ -442,7 +443,10 @@ fn doc_export_for_screens(h: &Host, a: &[Data]) -> Answer {
let doc = this_doc(h, a)?;
let folder = folder_path(arg(a, 1))?;
let (mut row, class) = format(arg(a, 2))?;
let options = given(arg(a, 3)).filter(|d| !matches!(d, Data::Null));
let options = given(arg(a, 3));
if matches!(options, Some(Data::Null)) {
return Err(HostError::Type("the options must be an object".into()));
}
let mut q = params(class, options)?;
if class.name == PNG24.name {
background(&mut q);
@@ -453,8 +457,8 @@ fn doc_export_for_screens(h: &Host, a: &[Data]) -> Answer {
size(&mut q)?;
}
row.extend(q);
let exports = exports(given(arg(a, 4)).filter(|d| !matches!(d, Data::Null)))?;
let prefix = match given(arg(a, 5)).filter(|d| !matches!(d, Data::Null)) {
let exports = exports(given(arg(a, 4)))?;
let prefix = match given(arg(a, 5)) {
None => None,
Some(Data::String(s)) if s.len() > MAX_TEXT_BYTES => return Err(HostError::Range("fileNamePrefix is too long".into())),
Some(Data::String(s)) => Some(s.clone()),