Skip to content

Commit

Permalink
Merge pull request #16440 from Snuffleupagus/more-modern-JS
Browse files Browse the repository at this point in the history
Introduce even more modern JavaScript features in the code-base
  • Loading branch information
Snuffleupagus authored May 18, 2023
2 parents e8537e4 + e803075 commit 3be66f5
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 31 deletions.
6 changes: 1 addition & 5 deletions src/core/ccitt.js
Original file line number Diff line number Diff line change
Expand Up @@ -477,11 +477,7 @@ class CCITTFaxDecoder {
this.byteAlign = options.EncodedByteAlign || false;
this.columns = options.Columns || 1728;
this.rows = options.Rows || 0;
let eoblock = options.EndOfBlock;
if (eoblock === null || eoblock === undefined) {
eoblock = true;
}
this.eoblock = eoblock;
this.eoblock = options.EndOfBlock ?? true;
this.black = options.BlackIs1 || false;

this.codingLine = new Uint32Array(this.columns + 1);
Expand Down
4 changes: 2 additions & 2 deletions src/core/colorspace.js
Original file line number Diff line number Diff line change
Expand Up @@ -928,8 +928,8 @@ const CalGrayCS = (function CalGrayCSClosure() {
"WhitePoint missing - required for color space CalGray"
);
}
blackPoint = blackPoint || [0, 0, 0];
gamma = gamma || 1;
blackPoint ||= [0, 0, 0];
gamma ||= 1;

// Translate arguments to spec variables.
this.XW = whitePoint[0];
Expand Down
2 changes: 1 addition & 1 deletion src/core/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -1702,7 +1702,7 @@ class PDFDocument {

get calculationOrderIds() {
const acroForm = this.catalog.acroForm;
if (!acroForm || !acroForm.has("CO")) {
if (!acroForm?.has("CO")) {
return shadow(this, "calculationOrderIds", null);
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/fonts.js
Original file line number Diff line number Diff line change
Expand Up @@ -2579,7 +2579,7 @@ class Font {
if (!isTrueType) {
const isComposite =
properties.composite &&
((properties.cidToGidMap || []).length > 0 ||
(properties.cidToGidMap?.length > 0 ||
!(properties.cMap instanceof IdentityCMap));
// OpenType font (skip composite fonts with non-default glyph mapping).
if (
Expand Down
2 changes: 1 addition & 1 deletion src/core/xfa/formcalc_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -1282,7 +1282,7 @@ class Parser {
tok = tok2 || this.lexer.next();
if (tok.id === TOKEN.step) {
[tok, step] = this.parseSimpleExpr();
tok = tok || this.lexer.next();
tok ||= this.lexer.next();
}

if (tok.id !== TOKEN.do) {
Expand Down
4 changes: 2 additions & 2 deletions src/core/xfa/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ class Border extends XFAObject {
const { edges } = this[$getExtra]();
const edgeStyles = edges.map(node => {
const style = node[$toStyle]();
style.color = style.color || "#000000";
style.color ||= "#000000";
return style;
});

Expand Down Expand Up @@ -3871,7 +3871,7 @@ class NumericEdit extends XFAObject {
attributes: {
type: "text",
fieldId: field[$uid],
dataId: (field[$data] && field[$data][$uid]) || field[$uid],
dataId: field[$data]?.[$uid] || field[$uid],
class: ["xfaTextfield"],
style,
"aria-label": ariaLabel(field),
Expand Down
2 changes: 1 addition & 1 deletion src/display/canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -2061,7 +2061,7 @@ class CanvasGraphics {
}

if (isAddToPathSet) {
const paths = this.pendingTextPaths || (this.pendingTextPaths = []);
const paths = (this.pendingTextPaths ||= []);
paths.push({
transform: getCurrentTransform(ctx),
x,
Expand Down
30 changes: 14 additions & 16 deletions src/display/display_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -760,22 +760,20 @@ class PDFDateString {
}

// Lazily initialize the regular expression.
if (!pdfDateStringRegex) {
pdfDateStringRegex = new RegExp(
"^D:" + // Prefix (required)
"(\\d{4})" + // Year (required)
"(\\d{2})?" + // Month (optional)
"(\\d{2})?" + // Day (optional)
"(\\d{2})?" + // Hour (optional)
"(\\d{2})?" + // Minute (optional)
"(\\d{2})?" + // Second (optional)
"([Z|+|-])?" + // Universal time relation (optional)
"(\\d{2})?" + // Offset hour (optional)
"'?" + // Splitting apostrophe (optional)
"(\\d{2})?" + // Offset minute (optional)
"'?" // Trailing apostrophe (optional)
);
}
pdfDateStringRegex ||= new RegExp(
"^D:" + // Prefix (required)
"(\\d{4})" + // Year (required)
"(\\d{2})?" + // Month (optional)
"(\\d{2})?" + // Day (optional)
"(\\d{2})?" + // Hour (optional)
"(\\d{2})?" + // Minute (optional)
"(\\d{2})?" + // Second (optional)
"([Z|+|-])?" + // Universal time relation (optional)
"(\\d{2})?" + // Offset hour (optional)
"'?" + // Splitting apostrophe (optional)
"(\\d{2})?" + // Offset minute (optional)
"'?" // Trailing apostrophe (optional)
);

// Optional fields that don't satisfy the requirements from the regular
// expression (such as incorrect digit counts or numbers that are out of
Expand Down
2 changes: 1 addition & 1 deletion src/scripting_api/field.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ class Field extends PDFObject {
nIdx = Array.isArray(this._currentValueIndices)
? this._currentValueIndices[0]
: this._currentValueIndices;
nIdx = nIdx || 0;
nIdx ||= 0;
}

if (nIdx < 0 || nIdx >= this.numItems) {
Expand Down
2 changes: 1 addition & 1 deletion web/chromecom.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ class ChromePreferences extends BasePreferences {
);

chrome.storage.managed.get(defaultManagedPrefs, function (items) {
items = items || defaultManagedPrefs;
items ||= defaultManagedPrefs;
// Migration logic for deprecated preferences: If the new preference
// is not defined by an administrator (i.e. the value is the same as
// the default value), and a deprecated preference is set with a
Expand Down

0 comments on commit 3be66f5

Please sign in to comment.