Merge pull request #11692 from Snuffleupagus/no-shadow-prepare

Move `IsLittleEndianCached`/`IsEvalSupportedCached` to `src/shared/util.js`, and rename the `isSpace` helper function to `isWhiteSpace`
This commit is contained in:
Tim van der Meij 2020-03-12 23:31:07 +01:00 committed by GitHub
commit a23ce6b483
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 48 additions and 54 deletions

View File

@ -161,7 +161,7 @@ function readUint32(data, offset) {
} }
// Checks if ch is one of the following characters: SPACE, TAB, CR or LF. // Checks if ch is one of the following characters: SPACE, TAB, CR or LF.
function isSpace(ch) { function isWhiteSpace(ch) {
return ch === 0x20 || ch === 0x09 || ch === 0x0d || ch === 0x0a; return ch === 0x20 || ch === 0x09 || ch === 0x0d || ch === 0x0a;
} }
@ -176,5 +176,5 @@ export {
readInt8, readInt8,
readUint16, readUint16,
readUint32, readUint32,
isSpace, isWhiteSpace,
}; };

View File

@ -42,7 +42,7 @@ import {
} from "./primitives.js"; } from "./primitives.js";
import { import {
getInheritableProperty, getInheritableProperty,
isSpace, isWhiteSpace,
MissingDataException, MissingDataException,
XRefEntryException, XRefEntryException,
XRefParseException, XRefParseException,
@ -598,7 +598,7 @@ class PDFDocument {
let ch; let ch;
do { do {
ch = stream.getByte(); ch = stream.getByte();
} while (isSpace(ch)); } while (isWhiteSpace(ch));
let str = ""; let str = "";
while (ch >= /* Space = */ 0x20 && ch <= /* '9' = */ 0x39) { while (ch >= /* Space = */ 0x20 && ch <= /* '9' = */ 0x39) {
str += String.fromCharCode(ch); str += String.fromCharCode(ch);

View File

@ -58,7 +58,11 @@ import {
getUnicodeRangeFor, getUnicodeRangeFor,
mapSpecialUnicodeValues, mapSpecialUnicodeValues,
} from "./unicode.js"; } from "./unicode.js";
import { isSpace, MissingDataException, readUint32 } from "./core_utils.js"; import {
isWhiteSpace,
MissingDataException,
readUint32,
} from "./core_utils.js";
import { FontRendererFactory } from "./font_renderer.js"; import { FontRendererFactory } from "./font_renderer.js";
import { IdentityCMap } from "./cmap.js"; import { IdentityCMap } from "./cmap.js";
import { Stream } from "./stream.js"; import { Stream } from "./stream.js";
@ -3413,7 +3417,7 @@ var Type1Font = (function Type1FontClosure() {
if (j >= signatureLength) { if (j >= signatureLength) {
// `signature` found, skip over whitespace. // `signature` found, skip over whitespace.
i += j; i += j;
while (i < streamBytesLength && isSpace(streamBytes[i])) { while (i < streamBytesLength && isWhiteSpace(streamBytes[i])) {
i++; i++;
} }
found = true; found = true;

View File

@ -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;

View File

@ -43,7 +43,7 @@ import {
Name, Name,
Ref, Ref,
} from "./primitives.js"; } from "./primitives.js";
import { isSpace, MissingDataException } from "./core_utils.js"; import { isWhiteSpace, MissingDataException } from "./core_utils.js";
import { CCITTFaxStream } from "./ccitt_stream.js"; import { CCITTFaxStream } from "./ccitt_stream.js";
import { Jbig2Stream } from "./jbig2_stream.js"; import { Jbig2Stream } from "./jbig2_stream.js";
import { JpegStream } from "./jpeg_stream.js"; import { JpegStream } from "./jpeg_stream.js";
@ -270,7 +270,7 @@ class Parser {
// Ensure that we don't accidentally truncate the inline image, when the // Ensure that we don't accidentally truncate the inline image, when the
// data is immediately followed by the "EI" marker (fixes issue10388.pdf). // data is immediately followed by the "EI" marker (fixes issue10388.pdf).
if (!isSpace(ch)) { if (!isWhiteSpace(ch)) {
endOffset--; endOffset--;
} }
return stream.pos - endOffset - startPos; return stream.pos - endOffset - startPos;
@ -394,7 +394,7 @@ class Parser {
ch = stream.peekByte(); ch = stream.peekByte();
// Handle corrupt PDF documents which contains whitespace "inside" of // Handle corrupt PDF documents which contains whitespace "inside" of
// the EOD marker (fixes issue10614.pdf). // the EOD marker (fixes issue10614.pdf).
while (isSpace(ch)) { while (isWhiteSpace(ch)) {
stream.skip(); stream.skip();
ch = stream.peekByte(); ch = stream.peekByte();
} }
@ -640,7 +640,7 @@ class Parser {
// Ensure that the byte immediately following the truncated // Ensure that the byte immediately following the truncated
// endstream command is a space, to prevent false positives. // endstream command is a space, to prevent false positives.
const lastByte = stream.peekBytes(end + 1)[end]; const lastByte = stream.peekBytes(end + 1)[end];
if (!isSpace(lastByte)) { if (!isWhiteSpace(lastByte)) {
break; break;
} }
info( info(
@ -886,7 +886,7 @@ class Lexer {
if ( if (
divideBy === 10 && divideBy === 10 &&
sign === 0 && sign === 0 &&
(isSpace(ch) || ch === /* EOF = */ -1) (isWhiteSpace(ch) || ch === /* EOF = */ -1)
) { ) {
// This is consistent with Adobe Reader (fixes issue9252.pdf). // This is consistent with Adobe Reader (fixes issue9252.pdf).
warn("Lexer.getNumber - treating a single decimal point as zero."); warn("Lexer.getNumber - treating a single decimal point as zero.");

View File

@ -16,7 +16,7 @@
import { FormatError, shadow } from "../shared/util.js"; import { FormatError, shadow } from "../shared/util.js";
import { EOF } from "./primitives.js"; import { EOF } from "./primitives.js";
import { isSpace } from "./core_utils.js"; import { isWhiteSpace } from "./core_utils.js";
class PostScriptParser { class PostScriptParser {
constructor(lexer) { constructor(lexer) {
@ -193,7 +193,7 @@ class PostScriptLexer {
} }
} else if (ch === /* '%' = */ 0x25) { } else if (ch === /* '%' = */ 0x25) {
comment = true; comment = true;
} else if (!isSpace(ch)) { } else if (!isWhiteSpace(ch)) {
break; break;
} }
ch = this.nextChar(); ch = this.nextChar();

View File

@ -21,7 +21,7 @@
import { FormatError, stringToBytes, unreachable } from "../shared/util.js"; import { FormatError, stringToBytes, unreachable } from "../shared/util.js";
import { isDict } from "./primitives.js"; import { isDict } from "./primitives.js";
import { isSpace } from "./core_utils.js"; import { isWhiteSpace } from "./core_utils.js";
var Stream = (function StreamClosure() { var Stream = (function StreamClosure() {
function Stream(arrayBuffer, start, length, dict) { function Stream(arrayBuffer, start, length, dict) {
@ -1001,7 +1001,7 @@ var Ascii85Stream = (function Ascii85StreamClosure() {
var str = this.str; var str = this.str;
var c = str.getByte(); var c = str.getByte();
while (isSpace(c)) { while (isWhiteSpace(c)) {
c = str.getByte(); c = str.getByte();
} }
@ -1026,7 +1026,7 @@ var Ascii85Stream = (function Ascii85StreamClosure() {
input[0] = c; input[0] = c;
for (i = 1; i < 5; ++i) { for (i = 1; i < 5; ++i) {
c = str.getByte(); c = str.getByte();
while (isSpace(c)) { while (isWhiteSpace(c)) {
c = str.getByte(); c = str.getByte();
} }

View File

@ -14,7 +14,7 @@
*/ */
import { getEncoding } from "./encodings.js"; import { getEncoding } from "./encodings.js";
import { isSpace } from "./core_utils.js"; import { isWhiteSpace } from "./core_utils.js";
import { Stream } from "./stream.js"; import { Stream } from "./stream.js";
import { warn } from "../shared/util.js"; import { warn } from "../shared/util.js";
@ -524,7 +524,7 @@ var Type1Parser = (function Type1ParserClosure() {
} }
} else if (ch === /* '%' = */ 0x25) { } else if (ch === /* '%' = */ 0x25) {
comment = true; comment = true;
} else if (!isSpace(ch)) { } else if (!isWhiteSpace(ch)) {
break; break;
} }
ch = this.nextChar(); ch = this.nextChar();
@ -537,7 +537,7 @@ var Type1Parser = (function Type1ParserClosure() {
do { do {
token += String.fromCharCode(ch); token += String.fromCharCode(ch);
ch = this.nextChar(); ch = this.nextChar();
} while (ch >= 0 && !isSpace(ch) && !isSpecial(ch)); } while (ch >= 0 && !isWhiteSpace(ch) && !isSpecial(ch));
return token; return token;
}, },

View File

@ -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) {

View File

@ -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,

View File

@ -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,

View File

@ -16,7 +16,7 @@
import { Dict, Ref } from "../../src/core/primitives.js"; import { Dict, Ref } from "../../src/core/primitives.js";
import { import {
getInheritableProperty, getInheritableProperty,
isSpace, isWhiteSpace,
log2, log2,
toRomanNumerals, toRomanNumerals,
} from "../../src/core/core_utils.js"; } from "../../src/core/core_utils.js";
@ -197,18 +197,18 @@ describe("core_utils", function() {
}); });
}); });
describe("isSpace", function() { describe("isWhiteSpace", function() {
it("handles space characters", function() { it("handles space characters", function() {
expect(isSpace(0x20)).toEqual(true); expect(isWhiteSpace(0x20)).toEqual(true);
expect(isSpace(0x09)).toEqual(true); expect(isWhiteSpace(0x09)).toEqual(true);
expect(isSpace(0x0d)).toEqual(true); expect(isWhiteSpace(0x0d)).toEqual(true);
expect(isSpace(0x0a)).toEqual(true); expect(isWhiteSpace(0x0a)).toEqual(true);
}); });
it("handles non-space characters", function() { it("handles non-space characters", function() {
expect(isSpace(0x0b)).toEqual(false); expect(isWhiteSpace(0x0b)).toEqual(false);
expect(isSpace(null)).toEqual(false); expect(isWhiteSpace(null)).toEqual(false);
expect(isSpace(undefined)).toEqual(false); expect(isWhiteSpace(undefined)).toEqual(false);
}); });
}); });
}); });