Skip to content

Commit b798fd8

Browse files
Merge pull request #20699 from Snuffleupagus/scripting-shorter
Slightly shorten some code in the `src/scripting_api/` folder
2 parents 62054ae + 350f3fa commit b798fd8

2 files changed

Lines changed: 14 additions & 28 deletions

File tree

src/scripting_api/app.js

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,10 @@ class App extends PDFObject {
152152
}
153153

154154
static _getLanguage(language) {
155-
const [main, sub] = language.toLowerCase().split(/[-_]/);
155+
const [main, sub] = language.toLowerCase().split(/[-_]/, 2);
156156
switch (main) {
157157
case "zh":
158-
if (sub === "cn" || sub === "sg") {
159-
return "CHS";
160-
}
161-
return "CHT";
158+
return sub === "cn" || sub === "sg" ? "CHS" : "CHT";
162159
case "da":
163160
return "DAN";
164161
case "de":
@@ -178,10 +175,7 @@ class App extends PDFObject {
178175
case "no":
179176
return "NOR";
180177
case "pt":
181-
if (sub === "br") {
182-
return "PTB";
183-
}
184-
return "ENU";
178+
return sub === "br" ? "PTB" : "ENU";
185179
case "fi":
186180
return "SUO";
187181
case "SV":
@@ -249,13 +243,10 @@ class App extends PDFObject {
249243
}
250244

251245
get fs() {
252-
if (this._fs === null) {
253-
this._fs = new Proxy(
254-
new FullScreen({ send: this._send }),
255-
this._proxyHandler
256-
);
257-
}
258-
return this._fs;
246+
return (this._fs ??= new Proxy(
247+
new FullScreen({ send: this._send }),
248+
this._proxyHandler
249+
));
259250
}
260251

261252
set fs(_) {
@@ -356,13 +347,10 @@ class App extends PDFObject {
356347
}
357348

358349
get thermometer() {
359-
if (this._thermometer === null) {
360-
this._thermometer = new Proxy(
361-
new Thermometer({ send: this._send }),
362-
this._proxyHandler
363-
);
364-
}
365-
return this._thermometer;
350+
return (this._thermometer ??= new Proxy(
351+
new Thermometer({ send: this._send }),
352+
this._proxyHandler
353+
));
366354
}
367355

368356
set thermometer(_) {

src/scripting_api/field.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -453,11 +453,9 @@ class Field extends PDFObject {
453453
return array;
454454
}
455455

456-
if (this._children === null) {
457-
this._children = this._document.obj._getTerminalChildren(this._fieldPath);
458-
}
459-
460-
return this._children;
456+
return (this._children ??= this._document.obj._getTerminalChildren(
457+
this._fieldPath
458+
));
461459
}
462460

463461
getLock() {

0 commit comments

Comments
 (0)