Merge pull request #13786 from Snuffleupagus/rm-more-src-core-closures

Remove a couple of small closures in `src/core/` code
This commit is contained in:
Tim van der Meij 2021-07-24 14:26:57 +02:00 committed by GitHub
commit 687cfcecd4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 106 additions and 111 deletions

View File

@ -517,11 +517,11 @@ function isPDFFunction(v) {
return fnDict.has("FunctionType"); return fnDict.has("FunctionType");
} }
const PostScriptStack = (function PostScriptStackClosure() {
const MAX_STACK_SIZE = 100;
// eslint-disable-next-line no-shadow
class PostScriptStack { class PostScriptStack {
static get MAX_STACK_SIZE() {
return shadow(this, "MAX_STACK_SIZE", 100);
}
constructor(initialStack) { constructor(initialStack) {
this.stack = !initialStack this.stack = !initialStack
? [] ? []
@ -529,7 +529,7 @@ const PostScriptStack = (function PostScriptStackClosure() {
} }
push(value) { push(value) {
if (this.stack.length >= MAX_STACK_SIZE) { if (this.stack.length >= PostScriptStack.MAX_STACK_SIZE) {
throw new Error("PostScript function stack overflow."); throw new Error("PostScript function stack overflow.");
} }
this.stack.push(value); this.stack.push(value);
@ -543,7 +543,7 @@ const PostScriptStack = (function PostScriptStackClosure() {
} }
copy(n) { copy(n) {
if (this.stack.length + n >= MAX_STACK_SIZE) { if (this.stack.length + n >= PostScriptStack.MAX_STACK_SIZE) {
throw new Error("PostScript function stack overflow."); throw new Error("PostScript function stack overflow.");
} }
const stack = this.stack; const stack = this.stack;
@ -581,9 +581,6 @@ const PostScriptStack = (function PostScriptStackClosure() {
} }
} }
return PostScriptStack;
})();
class PostScriptEvaluator { class PostScriptEvaluator {
constructor(operators) { constructor(operators) {
this.operators = operators; this.operators = operators;

View File

@ -109,22 +109,22 @@ const PostScriptTokenTypes = {
IFELSE: 5, IFELSE: 5,
}; };
const PostScriptToken = (function PostScriptTokenClosure() {
const opCache = Object.create(null);
// eslint-disable-next-line no-shadow
class PostScriptToken { class PostScriptToken {
static get opCache() {
return shadow(this, "opCache", Object.create(null));
}
constructor(type, value) { constructor(type, value) {
this.type = type; this.type = type;
this.value = value; this.value = value;
} }
static getOperator(op) { static getOperator(op) {
const opValue = opCache[op]; const opValue = PostScriptToken.opCache[op];
if (opValue) { if (opValue) {
return opValue; return opValue;
} }
return (opCache[op] = new PostScriptToken( return (PostScriptToken.opCache[op] = new PostScriptToken(
PostScriptTokenTypes.OPERATOR, PostScriptTokenTypes.OPERATOR,
op op
)); ));
@ -162,8 +162,6 @@ const PostScriptToken = (function PostScriptTokenClosure() {
); );
} }
} }
return PostScriptToken;
})();
class PostScriptLexer { class PostScriptLexer {
constructor(stream) { constructor(stream) {