Skip to content

Commit 970717a

Browse files
authored
Merge pull request #20684 from Snuffleupagus/src-rm-constructors
Remove unnecessary class constructors in the `src` folder
2 parents 34ba206 + 7fd9397 commit 970717a

9 files changed

Lines changed: 108 additions & 93 deletions

File tree

src/core/cff_parser.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,9 +1051,7 @@ class CFFHeader {
10511051
}
10521052

10531053
class CFFStrings {
1054-
constructor() {
1055-
this.strings = [];
1056-
}
1054+
strings = [];
10571055

10581056
get(index) {
10591057
if (index >= 0 && index <= NUM_STANDARD_CFF_STRINGS - 1) {
@@ -1087,10 +1085,9 @@ class CFFStrings {
10871085
}
10881086

10891087
class CFFIndex {
1090-
constructor() {
1091-
this.objects = [];
1092-
this.length = 0;
1093-
}
1088+
objects = [];
1089+
1090+
length = 0;
10941091

10951092
add(data) {
10961093
this.length += data.length;
@@ -1323,9 +1320,7 @@ class CFFFDSelect {
13231320
// Helper class to keep track of where an offset is within the data and helps
13241321
// filling in that offset once it's known.
13251322
class CFFOffsetTracker {
1326-
constructor() {
1327-
this.offsets = Object.create(null);
1328-
}
1323+
offsets = Object.create(null);
13291324

13301325
isTracking(key) {
13311326
return key in this.offsets;

src/core/dataset_reader.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,7 @@ function decodeString(str) {
2727
}
2828

2929
class DatasetXMLParser extends SimpleXMLParser {
30-
constructor(options) {
31-
super(options);
32-
this.node = null;
33-
}
30+
node = null;
3431

3532
onEndElement(name) {
3633
const node = super.onEndElement(name);

src/core/evaluator.js

Lines changed: 47 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5042,21 +5042,31 @@ class StateManager {
50425042
}
50435043

50445044
class TextState {
5045-
constructor() {
5046-
this.ctm = new Float32Array(IDENTITY_MATRIX);
5047-
this.fontName = null;
5048-
this.fontSize = 0;
5049-
this.loadedName = null;
5050-
this.font = null;
5051-
this.fontMatrix = FONT_IDENTITY_MATRIX;
5052-
this.textMatrix = IDENTITY_MATRIX.slice();
5053-
this.textLineMatrix = IDENTITY_MATRIX.slice();
5054-
this.charSpacing = 0;
5055-
this.wordSpacing = 0;
5056-
this.leading = 0;
5057-
this.textHScale = 1;
5058-
this.textRise = 0;
5059-
}
5045+
ctm = new Float32Array(IDENTITY_MATRIX);
5046+
5047+
fontName = null;
5048+
5049+
fontSize = 0;
5050+
5051+
loadedName = null;
5052+
5053+
font = null;
5054+
5055+
fontMatrix = FONT_IDENTITY_MATRIX;
5056+
5057+
textMatrix = IDENTITY_MATRIX.slice();
5058+
5059+
textLineMatrix = IDENTITY_MATRIX.slice();
5060+
5061+
charSpacing = 0;
5062+
5063+
wordSpacing = 0;
5064+
5065+
leading = 0;
5066+
5067+
textHScale = 1;
5068+
5069+
textRise = 0;
50605070

50615071
setTextMatrix(a, b, c, d, e, f) {
50625072
const m = this.textMatrix;
@@ -5105,24 +5115,28 @@ class TextState {
51055115
}
51065116

51075117
class EvalState {
5108-
constructor() {
5109-
this.ctm = new Float32Array(IDENTITY_MATRIX);
5110-
this.font = null;
5111-
this.textRenderingMode = TextRenderingMode.FILL;
5112-
this._fillColorSpace = this._strokeColorSpace = ColorSpaceUtils.gray;
5113-
this.patternFillColorSpace = null;
5114-
this.patternStrokeColorSpace = null;
5115-
5116-
// Path stuff.
5117-
this.currentPointX = this.currentPointY = 0;
5118-
this.pathMinMax = new Float32Array([
5119-
Infinity,
5120-
Infinity,
5121-
-Infinity,
5122-
-Infinity,
5123-
]);
5124-
this.pathBuffer = [];
5125-
}
5118+
ctm = new Float32Array(IDENTITY_MATRIX);
5119+
5120+
font = null;
5121+
5122+
textRenderingMode = TextRenderingMode.FILL;
5123+
5124+
_fillColorSpace = ColorSpaceUtils.gray;
5125+
5126+
_strokeColorSpace = ColorSpaceUtils.gray;
5127+
5128+
patternFillColorSpace = null;
5129+
5130+
patternStrokeColorSpace = null;
5131+
5132+
// Path stuff.
5133+
currentPointX = 0;
5134+
5135+
currentPointY = 0;
5136+
5137+
pathMinMax = new Float32Array([Infinity, Infinity, -Infinity, -Infinity]);
5138+
5139+
pathBuffer = [];
51265140

51275141
get fillColorSpace() {
51285142
return this._fillColorSpace;

src/core/function.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -836,9 +836,7 @@ class AstVariableDefinition extends AstNode {
836836
}
837837

838838
class ExpressionBuilderVisitor {
839-
constructor() {
840-
this.parts = [];
841-
}
839+
parts = [];
842840

843841
visitArgument(arg) {
844842
this.parts.push(

src/core/primitives.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -398,9 +398,7 @@ class RefSet {
398398
}
399399

400400
class RefSetCache {
401-
constructor() {
402-
this._map = new Map();
403-
}
401+
_map = new Map();
404402

405403
get size() {
406404
return this._map.size;

src/scripting_api/color.js

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,32 @@ import { ColorConverters } from "../shared/scripting_utils.js";
1717
import { PDFObject } from "./pdf_object.js";
1818

1919
class Color extends PDFObject {
20+
transparent = ["T"];
21+
22+
black = ["G", 0];
23+
24+
white = ["G", 1];
25+
26+
red = ["RGB", 1, 0, 0];
27+
28+
green = ["RGB", 0, 1, 0];
29+
30+
blue = ["RGB", 0, 0, 1];
31+
32+
cyan = ["CMYK", 1, 0, 0, 0];
33+
34+
magenta = ["CMYK", 0, 1, 0, 0];
35+
36+
yellow = ["CMYK", 0, 0, 1, 0];
37+
38+
dkGray = ["G", 0.25];
39+
40+
gray = ["G", 0.5];
41+
42+
ltGray = ["G", 0.75];
43+
2044
constructor() {
2145
super({});
22-
23-
this.transparent = ["T"];
24-
this.black = ["G", 0];
25-
this.white = ["G", 1];
26-
this.red = ["RGB", 1, 0, 0];
27-
this.green = ["RGB", 0, 1, 0];
28-
this.blue = ["RGB", 0, 0, 1];
29-
this.cyan = ["CMYK", 1, 0, 0, 0];
30-
this.magenta = ["CMYK", 0, 1, 0, 0];
31-
this.yellow = ["CMYK", 0, 0, 1, 0];
32-
this.dkGray = ["G", 0.25];
33-
this.gray = ["G", 0.5];
34-
this.ltGray = ["G", 0.75];
3546
}
3647

3748
static _isValidSpace(cColorSpace) {

src/scripting_api/fullscreen.js

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,25 @@ import { Cursor } from "./constants.js";
1717
import { PDFObject } from "./pdf_object.js";
1818

1919
class FullScreen extends PDFObject {
20-
constructor(data) {
21-
super(data);
22-
23-
this._backgroundColor = [];
24-
this._clickAdvances = true;
25-
this._cursor = Cursor.hidden;
26-
this._defaultTransition = "";
27-
this._escapeExits = true;
28-
this._isFullScreen = true;
29-
this._loop = false;
30-
this._timeDelay = 3600;
31-
this._usePageTiming = false;
32-
this._useTimer = false;
33-
}
20+
_backgroundColor = [];
21+
22+
_clickAdvances = true;
23+
24+
_cursor = Cursor.hidden;
25+
26+
_defaultTransition = "";
27+
28+
_escapeExits = true;
29+
30+
_isFullScreen = true;
31+
32+
_loop = false;
33+
34+
_timeDelay = 3600;
35+
36+
_usePageTiming = false;
37+
38+
_useTimer = false;
3439

3540
get backgroundColor() {
3641
return this._backgroundColor;

src/scripting_api/proxy.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,10 @@
1414
*/
1515

1616
class ProxyHandler {
17-
constructor() {
18-
// Don't dispatch an event for those properties.
19-
// - delay: allow to delay field redraw until delay is set to false.
20-
// Likely it's useless to implement that stuff.
21-
this.nosend = new Set(["delay"]);
22-
}
17+
// Don't dispatch an event for those properties.
18+
// - delay: allow to delay field redraw until delay is set to false.
19+
// Likely it's useless to implement that stuff.
20+
nosend = new Set(["delay"]);
2321

2422
get(obj, prop) {
2523
// script may add some properties to the object

src/scripting_api/thermometer.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,13 @@
1616
import { PDFObject } from "./pdf_object.js";
1717

1818
class Thermometer extends PDFObject {
19-
constructor(data) {
20-
super(data);
19+
_cancelled = false;
2120

22-
this._cancelled = false;
23-
this._duration = 100;
24-
this._text = "";
25-
this._value = 0;
26-
}
21+
_duration = 100;
22+
23+
_text = "";
24+
25+
_value = 0;
2726

2827
get cancelled() {
2928
return this._cancelled;

0 commit comments

Comments
 (0)