Move IsLittleEndianCached
and IsEvalSupportedCached
to src/shared/util.js
Rather than duplicating the lookup and caching in multiple files, it seems easier to simply move all of this functionality into `src/shared/util.js` instead. This will also help avoid a bunch of ESLint errors once the `no-shadow` rule is eventually enabled.
This commit is contained in:
parent
6db8e085ee
commit
e4758beaaa
@ -17,19 +17,12 @@ import {
|
|||||||
FormatError,
|
FormatError,
|
||||||
info,
|
info,
|
||||||
isBool,
|
isBool,
|
||||||
isEvalSupported,
|
IsEvalSupportedCached,
|
||||||
shadow,
|
|
||||||
unreachable,
|
unreachable,
|
||||||
} from "../shared/util.js";
|
} from "../shared/util.js";
|
||||||
import { isDict, isStream } from "./primitives.js";
|
import { isDict, isStream } from "./primitives.js";
|
||||||
import { PostScriptLexer, PostScriptParser } from "./ps_parser.js";
|
import { PostScriptLexer, PostScriptParser } from "./ps_parser.js";
|
||||||
|
|
||||||
const IsEvalSupportedCached = {
|
|
||||||
get value() {
|
|
||||||
return shadow(this, "value", isEvalSupported());
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
class PDFFunctionFactory {
|
class PDFFunctionFactory {
|
||||||
constructor({ xref, isEvalSupported = true }) {
|
constructor({ xref, isEvalSupported = true }) {
|
||||||
this.xref = xref;
|
this.xref = xref;
|
||||||
|
@ -18,7 +18,7 @@ import {
|
|||||||
IDENTITY_MATRIX,
|
IDENTITY_MATRIX,
|
||||||
ImageKind,
|
ImageKind,
|
||||||
info,
|
info,
|
||||||
isLittleEndian,
|
IsLittleEndianCached,
|
||||||
isNum,
|
isNum,
|
||||||
OPS,
|
OPS,
|
||||||
shadow,
|
shadow,
|
||||||
@ -46,12 +46,6 @@ var MAX_SIZE_TO_COMPILE = 1000;
|
|||||||
|
|
||||||
var FULL_CHUNK_HEIGHT = 16;
|
var FULL_CHUNK_HEIGHT = 16;
|
||||||
|
|
||||||
var IsLittleEndianCached = {
|
|
||||||
get value() {
|
|
||||||
return shadow(IsLittleEndianCached, "value", isLittleEndian());
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
function addContextCurrentTransform(ctx) {
|
function addContextCurrentTransform(ctx) {
|
||||||
// If the context doesn't expose a `mozCurrentTransform`, add a JS based one.
|
// If the context doesn't expose a `mozCurrentTransform`, add a JS based one.
|
||||||
if (!ctx.mozCurrentTransform) {
|
if (!ctx.mozCurrentTransform) {
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
import {
|
import {
|
||||||
assert,
|
assert,
|
||||||
bytesToString,
|
bytesToString,
|
||||||
isEvalSupported,
|
IsEvalSupportedCached,
|
||||||
shadow,
|
shadow,
|
||||||
string32,
|
string32,
|
||||||
unreachable,
|
unreachable,
|
||||||
@ -337,12 +337,6 @@ if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
|
|||||||
};
|
};
|
||||||
} // End of PDFJSDev.test('CHROME || GENERIC')
|
} // End of PDFJSDev.test('CHROME || GENERIC')
|
||||||
|
|
||||||
const IsEvalSupportedCached = {
|
|
||||||
get value() {
|
|
||||||
return shadow(this, "value", isEvalSupported());
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
class FontFaceObject {
|
class FontFaceObject {
|
||||||
constructor(
|
constructor(
|
||||||
translatedData,
|
translatedData,
|
||||||
|
@ -547,14 +547,18 @@ function string32(value) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lazy test the endianness of the platform
|
// Checks the endianness of the platform.
|
||||||
// NOTE: This will be 'true' for simulated TypedArrays
|
|
||||||
function isLittleEndian() {
|
function isLittleEndian() {
|
||||||
const buffer8 = new Uint8Array(4);
|
const buffer8 = new Uint8Array(4);
|
||||||
buffer8[0] = 1;
|
buffer8[0] = 1;
|
||||||
const view32 = new Uint32Array(buffer8.buffer, 0, 1);
|
const view32 = new Uint32Array(buffer8.buffer, 0, 1);
|
||||||
return view32[0] === 1;
|
return view32[0] === 1;
|
||||||
}
|
}
|
||||||
|
const IsLittleEndianCached = {
|
||||||
|
get value() {
|
||||||
|
return shadow(this, "value", isLittleEndian());
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
// Checks if it's possible to eval JS expressions.
|
// Checks if it's possible to eval JS expressions.
|
||||||
function isEvalSupported() {
|
function isEvalSupported() {
|
||||||
@ -565,6 +569,11 @@ function isEvalSupported() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
const IsEvalSupportedCached = {
|
||||||
|
get value() {
|
||||||
|
return shadow(this, "value", isEvalSupported());
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
const rgbBuf = ["rgb(", 0, ",", 0, ",", 0, ")"];
|
const rgbBuf = ["rgb(", 0, ",", 0, ",", 0, ")"];
|
||||||
|
|
||||||
@ -918,8 +927,8 @@ export {
|
|||||||
isString,
|
isString,
|
||||||
isSameOrigin,
|
isSameOrigin,
|
||||||
createValidAbsoluteUrl,
|
createValidAbsoluteUrl,
|
||||||
isLittleEndian,
|
IsLittleEndianCached,
|
||||||
isEvalSupported,
|
IsEvalSupportedCached,
|
||||||
removeNullCharacters,
|
removeNullCharacters,
|
||||||
setVerbosityLevel,
|
setVerbosityLevel,
|
||||||
shadow,
|
shadow,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user