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");
}
const PostScriptStack = (function PostScriptStackClosure() {
const MAX_STACK_SIZE = 100;
// eslint-disable-next-line no-shadow
class PostScriptStack {
static get MAX_STACK_SIZE() {
return shadow(this, "MAX_STACK_SIZE", 100);
}
constructor(initialStack) {
this.stack = !initialStack
? []
@ -529,7 +529,7 @@ const PostScriptStack = (function PostScriptStackClosure() {
}
push(value) {
if (this.stack.length >= MAX_STACK_SIZE) {
if (this.stack.length >= PostScriptStack.MAX_STACK_SIZE) {
throw new Error("PostScript function stack overflow.");
}
this.stack.push(value);
@ -543,7 +543,7 @@ const PostScriptStack = (function PostScriptStackClosure() {
}
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.");
}
const stack = this.stack;
@ -581,9 +581,6 @@ const PostScriptStack = (function PostScriptStackClosure() {
}
}
return PostScriptStack;
})();
class PostScriptEvaluator {
constructor(operators) {
this.operators = operators;

View File

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