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:
commit
687cfcecd4
@ -517,72 +517,69 @@ function isPDFFunction(v) {
|
|||||||
return fnDict.has("FunctionType");
|
return fnDict.has("FunctionType");
|
||||||
}
|
}
|
||||||
|
|
||||||
const PostScriptStack = (function PostScriptStackClosure() {
|
class PostScriptStack {
|
||||||
const MAX_STACK_SIZE = 100;
|
static get MAX_STACK_SIZE() {
|
||||||
|
return shadow(this, "MAX_STACK_SIZE", 100);
|
||||||
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line no-shadow
|
constructor(initialStack) {
|
||||||
class PostScriptStack {
|
this.stack = !initialStack
|
||||||
constructor(initialStack) {
|
? []
|
||||||
this.stack = !initialStack
|
: Array.prototype.slice.call(initialStack, 0);
|
||||||
? []
|
}
|
||||||
: Array.prototype.slice.call(initialStack, 0);
|
|
||||||
|
push(value) {
|
||||||
|
if (this.stack.length >= PostScriptStack.MAX_STACK_SIZE) {
|
||||||
|
throw new Error("PostScript function stack overflow.");
|
||||||
}
|
}
|
||||||
|
this.stack.push(value);
|
||||||
|
}
|
||||||
|
|
||||||
push(value) {
|
pop() {
|
||||||
if (this.stack.length >= MAX_STACK_SIZE) {
|
if (this.stack.length <= 0) {
|
||||||
throw new Error("PostScript function stack overflow.");
|
throw new Error("PostScript function stack underflow.");
|
||||||
}
|
|
||||||
this.stack.push(value);
|
|
||||||
}
|
}
|
||||||
|
return this.stack.pop();
|
||||||
|
}
|
||||||
|
|
||||||
pop() {
|
copy(n) {
|
||||||
if (this.stack.length <= 0) {
|
if (this.stack.length + n >= PostScriptStack.MAX_STACK_SIZE) {
|
||||||
throw new Error("PostScript function stack underflow.");
|
throw new Error("PostScript function stack overflow.");
|
||||||
}
|
|
||||||
return this.stack.pop();
|
|
||||||
}
|
}
|
||||||
|
const stack = this.stack;
|
||||||
copy(n) {
|
for (let i = stack.length - n, j = n - 1; j >= 0; j--, i++) {
|
||||||
if (this.stack.length + n >= MAX_STACK_SIZE) {
|
stack.push(stack[i]);
|
||||||
throw new Error("PostScript function stack overflow.");
|
|
||||||
}
|
|
||||||
const stack = this.stack;
|
|
||||||
for (let i = stack.length - n, j = n - 1; j >= 0; j--, i++) {
|
|
||||||
stack.push(stack[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
index(n) {
|
|
||||||
this.push(this.stack[this.stack.length - n - 1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// rotate the last n stack elements p times
|
|
||||||
roll(n, p) {
|
|
||||||
const stack = this.stack;
|
|
||||||
const l = stack.length - n;
|
|
||||||
const r = stack.length - 1;
|
|
||||||
const c = l + (p - Math.floor(p / n) * n);
|
|
||||||
|
|
||||||
for (let i = l, j = r; i < j; i++, j--) {
|
|
||||||
const t = stack[i];
|
|
||||||
stack[i] = stack[j];
|
|
||||||
stack[j] = t;
|
|
||||||
}
|
|
||||||
for (let i = l, j = c - 1; i < j; i++, j--) {
|
|
||||||
const t = stack[i];
|
|
||||||
stack[i] = stack[j];
|
|
||||||
stack[j] = t;
|
|
||||||
}
|
|
||||||
for (let i = c, j = r; i < j; i++, j--) {
|
|
||||||
const t = stack[i];
|
|
||||||
stack[i] = stack[j];
|
|
||||||
stack[j] = t;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return PostScriptStack;
|
index(n) {
|
||||||
})();
|
this.push(this.stack[this.stack.length - n - 1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// rotate the last n stack elements p times
|
||||||
|
roll(n, p) {
|
||||||
|
const stack = this.stack;
|
||||||
|
const l = stack.length - n;
|
||||||
|
const r = stack.length - 1;
|
||||||
|
const c = l + (p - Math.floor(p / n) * n);
|
||||||
|
|
||||||
|
for (let i = l, j = r; i < j; i++, j--) {
|
||||||
|
const t = stack[i];
|
||||||
|
stack[i] = stack[j];
|
||||||
|
stack[j] = t;
|
||||||
|
}
|
||||||
|
for (let i = l, j = c - 1; i < j; i++, j--) {
|
||||||
|
const t = stack[i];
|
||||||
|
stack[i] = stack[j];
|
||||||
|
stack[j] = t;
|
||||||
|
}
|
||||||
|
for (let i = c, j = r; i < j; i++, j--) {
|
||||||
|
const t = stack[i];
|
||||||
|
stack[i] = stack[j];
|
||||||
|
stack[j] = t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class PostScriptEvaluator {
|
class PostScriptEvaluator {
|
||||||
constructor(operators) {
|
constructor(operators) {
|
||||||
|
@ -109,61 +109,59 @@ const PostScriptTokenTypes = {
|
|||||||
IFELSE: 5,
|
IFELSE: 5,
|
||||||
};
|
};
|
||||||
|
|
||||||
const PostScriptToken = (function PostScriptTokenClosure() {
|
class PostScriptToken {
|
||||||
const opCache = Object.create(null);
|
static get opCache() {
|
||||||
|
return shadow(this, "opCache", Object.create(null));
|
||||||
// eslint-disable-next-line no-shadow
|
|
||||||
class PostScriptToken {
|
|
||||||
constructor(type, value) {
|
|
||||||
this.type = type;
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
static getOperator(op) {
|
|
||||||
const opValue = opCache[op];
|
|
||||||
if (opValue) {
|
|
||||||
return opValue;
|
|
||||||
}
|
|
||||||
return (opCache[op] = new PostScriptToken(
|
|
||||||
PostScriptTokenTypes.OPERATOR,
|
|
||||||
op
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
static get LBRACE() {
|
|
||||||
return shadow(
|
|
||||||
this,
|
|
||||||
"LBRACE",
|
|
||||||
new PostScriptToken(PostScriptTokenTypes.LBRACE, "{")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
static get RBRACE() {
|
|
||||||
return shadow(
|
|
||||||
this,
|
|
||||||
"RBRACE",
|
|
||||||
new PostScriptToken(PostScriptTokenTypes.RBRACE, "}")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
static get IF() {
|
|
||||||
return shadow(
|
|
||||||
this,
|
|
||||||
"IF",
|
|
||||||
new PostScriptToken(PostScriptTokenTypes.IF, "IF")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
static get IFELSE() {
|
|
||||||
return shadow(
|
|
||||||
this,
|
|
||||||
"IFELSE",
|
|
||||||
new PostScriptToken(PostScriptTokenTypes.IFELSE, "IFELSE")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return PostScriptToken;
|
|
||||||
})();
|
constructor(type, value) {
|
||||||
|
this.type = type;
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
static getOperator(op) {
|
||||||
|
const opValue = PostScriptToken.opCache[op];
|
||||||
|
if (opValue) {
|
||||||
|
return opValue;
|
||||||
|
}
|
||||||
|
return (PostScriptToken.opCache[op] = new PostScriptToken(
|
||||||
|
PostScriptTokenTypes.OPERATOR,
|
||||||
|
op
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
static get LBRACE() {
|
||||||
|
return shadow(
|
||||||
|
this,
|
||||||
|
"LBRACE",
|
||||||
|
new PostScriptToken(PostScriptTokenTypes.LBRACE, "{")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
static get RBRACE() {
|
||||||
|
return shadow(
|
||||||
|
this,
|
||||||
|
"RBRACE",
|
||||||
|
new PostScriptToken(PostScriptTokenTypes.RBRACE, "}")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
static get IF() {
|
||||||
|
return shadow(
|
||||||
|
this,
|
||||||
|
"IF",
|
||||||
|
new PostScriptToken(PostScriptTokenTypes.IF, "IF")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
static get IFELSE() {
|
||||||
|
return shadow(
|
||||||
|
this,
|
||||||
|
"IFELSE",
|
||||||
|
new PostScriptToken(PostScriptTokenTypes.IFELSE, "IFELSE")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class PostScriptLexer {
|
class PostScriptLexer {
|
||||||
constructor(stream) {
|
constructor(stream) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user