2017-01-10 01:40:57 +09:00
|
|
|
/* Copyright 2017 Mozilla Foundation
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2017-04-17 05:30:27 +09:00
|
|
|
|
|
|
|
import {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
Cmd,
|
|
|
|
Dict,
|
|
|
|
isCmd,
|
|
|
|
isDict,
|
|
|
|
isName,
|
|
|
|
isRef,
|
|
|
|
isRefsEqual,
|
2020-06-07 22:06:54 +09:00
|
|
|
isStream,
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
Name,
|
|
|
|
Ref,
|
|
|
|
RefSet,
|
2020-07-12 18:51:27 +09:00
|
|
|
RefSetCache,
|
2020-01-02 20:00:16 +09:00
|
|
|
} from "../../src/core/primitives.js";
|
2020-06-07 22:06:54 +09:00
|
|
|
import { StringStream } from "../../src/core/stream.js";
|
2020-01-02 20:00:16 +09:00
|
|
|
import { XRefMock } from "./test_utils.js";
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
describe("primitives", function () {
|
|
|
|
describe("Name", function () {
|
|
|
|
it("should retain the given name", function () {
|
2020-06-07 22:04:24 +09:00
|
|
|
const givenName = "Font";
|
|
|
|
const name = Name.get(givenName);
|
2011-11-14 04:39:56 +09:00
|
|
|
expect(name.name).toEqual(givenName);
|
|
|
|
});
|
2016-08-03 23:37:04 +09:00
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
it("should create only one object for a name and cache it", function () {
|
2020-06-07 22:04:24 +09:00
|
|
|
const firstFont = Name.get("Font");
|
|
|
|
const secondFont = Name.get("Font");
|
|
|
|
const firstSubtype = Name.get("Subtype");
|
|
|
|
const secondSubtype = Name.get("Subtype");
|
2016-08-03 23:37:04 +09:00
|
|
|
|
|
|
|
expect(firstFont).toBe(secondFont);
|
|
|
|
expect(firstSubtype).toBe(secondSubtype);
|
|
|
|
expect(firstFont).not.toBe(firstSubtype);
|
|
|
|
});
|
2021-07-15 04:38:19 +09:00
|
|
|
|
|
|
|
it("should create only one object for *empty* names and cache it", function () {
|
|
|
|
const firstEmpty = Name.get("");
|
|
|
|
const secondEmpty = Name.get("");
|
|
|
|
const normalName = Name.get("string");
|
|
|
|
|
|
|
|
expect(firstEmpty).toBe(secondEmpty);
|
|
|
|
expect(firstEmpty).not.toBe(normalName);
|
|
|
|
});
|
2011-11-14 04:39:56 +09:00
|
|
|
});
|
2011-12-29 06:20:04 +09:00
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
describe("Cmd", function () {
|
|
|
|
it("should retain the given cmd name", function () {
|
2020-06-07 22:04:24 +09:00
|
|
|
const givenCmd = "BT";
|
|
|
|
const cmd = Cmd.get(givenCmd);
|
2011-12-29 06:20:04 +09:00
|
|
|
expect(cmd.cmd).toEqual(givenCmd);
|
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
it("should create only one object for a command and cache it", function () {
|
2020-06-07 22:04:24 +09:00
|
|
|
const firstBT = Cmd.get("BT");
|
|
|
|
const secondBT = Cmd.get("BT");
|
|
|
|
const firstET = Cmd.get("ET");
|
|
|
|
const secondET = Cmd.get("ET");
|
2016-08-03 23:37:04 +09:00
|
|
|
|
2011-12-29 06:20:04 +09:00
|
|
|
expect(firstBT).toBe(secondBT);
|
|
|
|
expect(firstET).toBe(secondET);
|
|
|
|
expect(firstBT).not.toBe(firstET);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
describe("Dict", function () {
|
2020-06-07 22:04:24 +09:00
|
|
|
const checkInvalidHasValues = function (dict) {
|
2011-12-29 21:06:06 +09:00
|
|
|
expect(dict.has()).toBeFalsy();
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
expect(dict.has("Prev")).toBeFalsy();
|
2011-12-29 21:06:06 +09:00
|
|
|
};
|
|
|
|
|
2020-06-07 22:04:24 +09:00
|
|
|
const checkInvalidKeyValues = function (dict) {
|
2011-12-29 21:06:06 +09:00
|
|
|
expect(dict.get()).toBeUndefined();
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
expect(dict.get("Prev")).toBeUndefined();
|
2021-11-10 06:39:21 +09:00
|
|
|
expect(dict.get("D", "Decode")).toBeUndefined();
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
expect(dict.get("FontFile", "FontFile2", "FontFile3")).toBeUndefined();
|
2011-12-29 21:06:06 +09:00
|
|
|
};
|
|
|
|
|
2020-06-07 22:04:24 +09:00
|
|
|
let emptyDict, dictWithSizeKey, dictWithManyKeys;
|
|
|
|
const storedSize = 42;
|
|
|
|
const testFontFile = "file1";
|
|
|
|
const testFontFile2 = "file2";
|
|
|
|
const testFontFile3 = "file3";
|
2011-12-29 21:06:06 +09:00
|
|
|
|
2021-04-11 03:21:31 +09:00
|
|
|
beforeAll(function () {
|
2011-12-29 21:06:06 +09:00
|
|
|
emptyDict = new Dict();
|
|
|
|
|
|
|
|
dictWithSizeKey = new Dict();
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
dictWithSizeKey.set("Size", storedSize);
|
2011-12-29 21:06:06 +09:00
|
|
|
|
|
|
|
dictWithManyKeys = new Dict();
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
dictWithManyKeys.set("FontFile", testFontFile);
|
|
|
|
dictWithManyKeys.set("FontFile2", testFontFile2);
|
|
|
|
dictWithManyKeys.set("FontFile3", testFontFile3);
|
2016-08-22 01:44:58 +09:00
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
afterAll(function () {
|
2016-08-22 01:44:58 +09:00
|
|
|
emptyDict = dictWithSizeKey = dictWithManyKeys = null;
|
2011-12-29 06:20:04 +09:00
|
|
|
});
|
|
|
|
|
2020-06-07 22:06:54 +09:00
|
|
|
it("should allow assigning an XRef table after creation", function () {
|
|
|
|
const dict = new Dict(null);
|
|
|
|
expect(dict.xref).toEqual(null);
|
|
|
|
|
|
|
|
const xref = new XRefMock([]);
|
|
|
|
dict.assignXref(xref);
|
|
|
|
expect(dict.xref).toEqual(xref);
|
|
|
|
});
|
|
|
|
|
2020-07-16 18:57:50 +09:00
|
|
|
it("should return correct size", function () {
|
|
|
|
const dict = new Dict(null);
|
|
|
|
expect(dict.size).toEqual(0);
|
|
|
|
|
|
|
|
dict.set("Type", Name.get("Page"));
|
|
|
|
expect(dict.size).toEqual(1);
|
|
|
|
|
|
|
|
dict.set("Contents", Ref.get(10, 0));
|
|
|
|
expect(dict.size).toEqual(2);
|
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
it("should return invalid values for unknown keys", function () {
|
2011-12-29 21:06:06 +09:00
|
|
|
checkInvalidHasValues(emptyDict);
|
|
|
|
checkInvalidKeyValues(emptyDict);
|
2011-12-29 06:20:04 +09:00
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
it("should return correct value for stored Size key", function () {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
expect(dictWithSizeKey.has("Size")).toBeTruthy();
|
2011-12-29 06:20:04 +09:00
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
expect(dictWithSizeKey.get("Size")).toEqual(storedSize);
|
|
|
|
expect(dictWithSizeKey.get("Prev", "Size")).toEqual(storedSize);
|
|
|
|
expect(dictWithSizeKey.get("Prev", "Root", "Size")).toEqual(storedSize);
|
2011-12-29 06:20:04 +09:00
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
it("should return invalid values for unknown keys when Size key is stored", function () {
|
2011-12-29 21:06:06 +09:00
|
|
|
checkInvalidHasValues(dictWithSizeKey);
|
|
|
|
checkInvalidKeyValues(dictWithSizeKey);
|
2011-12-29 06:20:04 +09:00
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
it("should not accept to set a key with an undefined value", function () {
|
Slightly simplify the lookup of data in `Dict.{get, getAsync, has}`
Note that `Dict.set` will only be called with values returned through `Parser.getObj`, and thus indirectly via `Lexer.getObj`. Since neither of those methods will ever return `undefined`, we can simply assert that that's the case when inserting data into the `Dict` and thus get rid of `in` checks when doing the data lookups.
In this case, since `Dict.set` is fairly hot, the patch utilizes an *inline check* and when necessary a direct call to `unreachable` to not affect performance of `gulp server/test` too much (rather than always just calling `assert`).
For very large and complex PDF files this will help performance *slightly*, since `Dict.{get, getAsync, has}` is called *a lot* during parsing in the worker.
This patch was tested using the PDF file from issue 2618, i.e. http://bugzilla-attachments.gnome.org/attachment.cgi?id=226471, with the following manifest file:
```
[
{ "id": "issue2618",
"file": "../web/pdfs/issue2618.pdf",
"md5": "",
"rounds": 250,
"type": "eq"
}
]
```
which gave the following results when comparing this patch against the `master` branch:
```
-- Grouped By browser, stat --
browser | stat | Count | Baseline(ms) | Current(ms) | +/- | % | Result(P<.05)
------- | ------------ | ----- | ------------ | ----------- | --- | ----- | -------------
Firefox | Overall | 250 | 2838 | 2820 | -18 | -0.65 | faster
Firefox | Page Request | 250 | 1 | 2 | 0 | 11.92 | slower
Firefox | Rendering | 250 | 2837 | 2818 | -19 | -0.65 | faster
```
2020-01-31 19:39:48 +09:00
|
|
|
const dict = new Dict();
|
2020-04-14 19:28:14 +09:00
|
|
|
expect(function () {
|
Slightly simplify the lookup of data in `Dict.{get, getAsync, has}`
Note that `Dict.set` will only be called with values returned through `Parser.getObj`, and thus indirectly via `Lexer.getObj`. Since neither of those methods will ever return `undefined`, we can simply assert that that's the case when inserting data into the `Dict` and thus get rid of `in` checks when doing the data lookups.
In this case, since `Dict.set` is fairly hot, the patch utilizes an *inline check* and when necessary a direct call to `unreachable` to not affect performance of `gulp server/test` too much (rather than always just calling `assert`).
For very large and complex PDF files this will help performance *slightly*, since `Dict.{get, getAsync, has}` is called *a lot* during parsing in the worker.
This patch was tested using the PDF file from issue 2618, i.e. http://bugzilla-attachments.gnome.org/attachment.cgi?id=226471, with the following manifest file:
```
[
{ "id": "issue2618",
"file": "../web/pdfs/issue2618.pdf",
"md5": "",
"rounds": 250,
"type": "eq"
}
]
```
which gave the following results when comparing this patch against the `master` branch:
```
-- Grouped By browser, stat --
browser | stat | Count | Baseline(ms) | Current(ms) | +/- | % | Result(P<.05)
------- | ------------ | ----- | ------------ | ----------- | --- | ----- | -------------
Firefox | Overall | 250 | 2838 | 2820 | -18 | -0.65 | faster
Firefox | Page Request | 250 | 1 | 2 | 0 | 11.92 | slower
Firefox | Rendering | 250 | 2837 | 2818 | -19 | -0.65 | faster
```
2020-01-31 19:39:48 +09:00
|
|
|
dict.set("Size");
|
|
|
|
}).toThrow(new Error('Dict.set: The "value" cannot be undefined.'));
|
2011-12-29 06:20:04 +09:00
|
|
|
|
Slightly simplify the lookup of data in `Dict.{get, getAsync, has}`
Note that `Dict.set` will only be called with values returned through `Parser.getObj`, and thus indirectly via `Lexer.getObj`. Since neither of those methods will ever return `undefined`, we can simply assert that that's the case when inserting data into the `Dict` and thus get rid of `in` checks when doing the data lookups.
In this case, since `Dict.set` is fairly hot, the patch utilizes an *inline check* and when necessary a direct call to `unreachable` to not affect performance of `gulp server/test` too much (rather than always just calling `assert`).
For very large and complex PDF files this will help performance *slightly*, since `Dict.{get, getAsync, has}` is called *a lot* during parsing in the worker.
This patch was tested using the PDF file from issue 2618, i.e. http://bugzilla-attachments.gnome.org/attachment.cgi?id=226471, with the following manifest file:
```
[
{ "id": "issue2618",
"file": "../web/pdfs/issue2618.pdf",
"md5": "",
"rounds": 250,
"type": "eq"
}
]
```
which gave the following results when comparing this patch against the `master` branch:
```
-- Grouped By browser, stat --
browser | stat | Count | Baseline(ms) | Current(ms) | +/- | % | Result(P<.05)
------- | ------------ | ----- | ------------ | ----------- | --- | ----- | -------------
Firefox | Overall | 250 | 2838 | 2820 | -18 | -0.65 | faster
Firefox | Page Request | 250 | 1 | 2 | 0 | 11.92 | slower
Firefox | Rendering | 250 | 2837 | 2818 | -19 | -0.65 | faster
```
2020-01-31 19:39:48 +09:00
|
|
|
expect(dict.has("Size")).toBeFalsy();
|
2011-12-29 06:20:04 +09:00
|
|
|
|
2011-12-29 21:06:06 +09:00
|
|
|
checkInvalidKeyValues(dict);
|
2011-12-29 06:20:04 +09:00
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
it("should return correct values for multiple stored keys", function () {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
expect(dictWithManyKeys.has("FontFile")).toBeTruthy();
|
|
|
|
expect(dictWithManyKeys.has("FontFile2")).toBeTruthy();
|
|
|
|
expect(dictWithManyKeys.has("FontFile3")).toBeTruthy();
|
2011-12-29 21:06:06 +09:00
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
expect(dictWithManyKeys.get("FontFile3")).toEqual(testFontFile3);
|
|
|
|
expect(dictWithManyKeys.get("FontFile2", "FontFile3")).toEqual(
|
|
|
|
testFontFile2
|
|
|
|
);
|
|
|
|
expect(
|
|
|
|
dictWithManyKeys.get("FontFile", "FontFile2", "FontFile3")
|
|
|
|
).toEqual(testFontFile);
|
2011-12-29 06:20:04 +09:00
|
|
|
});
|
|
|
|
|
2021-04-12 02:56:58 +09:00
|
|
|
it("should asynchronously fetch unknown keys", async function () {
|
2020-06-07 22:04:24 +09:00
|
|
|
const keyPromises = [
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
dictWithManyKeys.getAsync("Size"),
|
|
|
|
dictWithSizeKey.getAsync("FontFile", "FontFile2", "FontFile3"),
|
2016-08-22 01:44:58 +09:00
|
|
|
];
|
|
|
|
|
2021-04-12 02:56:58 +09:00
|
|
|
const values = await Promise.all(keyPromises);
|
|
|
|
expect(values[0]).toBeUndefined();
|
|
|
|
expect(values[1]).toBeUndefined();
|
2016-08-22 01:44:58 +09:00
|
|
|
});
|
|
|
|
|
2021-04-12 02:56:58 +09:00
|
|
|
it("should asynchronously fetch correct values for multiple stored keys", async function () {
|
2020-06-07 22:04:24 +09:00
|
|
|
const keyPromises = [
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
dictWithManyKeys.getAsync("FontFile3"),
|
|
|
|
dictWithManyKeys.getAsync("FontFile2", "FontFile3"),
|
|
|
|
dictWithManyKeys.getAsync("FontFile", "FontFile2", "FontFile3"),
|
2016-08-22 01:44:58 +09:00
|
|
|
];
|
|
|
|
|
2021-04-12 02:56:58 +09:00
|
|
|
const values = await Promise.all(keyPromises);
|
|
|
|
expect(values[0]).toEqual(testFontFile3);
|
|
|
|
expect(values[1]).toEqual(testFontFile2);
|
|
|
|
expect(values[2]).toEqual(testFontFile);
|
2016-08-22 01:44:58 +09:00
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
it("should callback for each stored key", function () {
|
2020-06-07 22:04:24 +09:00
|
|
|
const callbackSpy = jasmine.createSpy("spy on callback in dictionary");
|
2011-12-29 06:20:04 +09:00
|
|
|
|
2011-12-29 21:06:06 +09:00
|
|
|
dictWithManyKeys.forEach(callbackSpy);
|
2011-12-29 06:20:04 +09:00
|
|
|
|
2016-03-29 23:34:13 +09:00
|
|
|
expect(callbackSpy).toHaveBeenCalled();
|
2020-06-07 22:04:24 +09:00
|
|
|
const callbackSpyCalls = callbackSpy.calls;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
expect(callbackSpyCalls.argsFor(0)).toEqual(["FontFile", testFontFile]);
|
|
|
|
expect(callbackSpyCalls.argsFor(1)).toEqual(["FontFile2", testFontFile2]);
|
|
|
|
expect(callbackSpyCalls.argsFor(2)).toEqual(["FontFile3", testFontFile3]);
|
2016-03-29 23:34:13 +09:00
|
|
|
expect(callbackSpyCalls.count()).toEqual(3);
|
2011-12-29 06:20:04 +09:00
|
|
|
});
|
2016-08-03 23:37:04 +09:00
|
|
|
|
2021-04-12 02:56:58 +09:00
|
|
|
it("should handle keys pointing to indirect objects, both sync and async", async function () {
|
2020-06-07 22:04:24 +09:00
|
|
|
const fontRef = Ref.get(1, 0);
|
|
|
|
const xref = new XRefMock([{ ref: fontRef, data: testFontFile }]);
|
|
|
|
const fontDict = new Dict(xref);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
fontDict.set("FontFile", fontRef);
|
|
|
|
|
|
|
|
expect(fontDict.getRaw("FontFile")).toEqual(fontRef);
|
|
|
|
expect(fontDict.get("FontFile", "FontFile2", "FontFile3")).toEqual(
|
|
|
|
testFontFile
|
|
|
|
);
|
|
|
|
|
2021-04-12 02:56:58 +09:00
|
|
|
const value = await fontDict.getAsync(
|
|
|
|
"FontFile",
|
|
|
|
"FontFile2",
|
|
|
|
"FontFile3"
|
|
|
|
);
|
|
|
|
expect(value).toEqual(testFontFile);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
it("should handle arrays containing indirect objects", function () {
|
2020-06-07 22:04:24 +09:00
|
|
|
const minCoordRef = Ref.get(1, 0);
|
|
|
|
const maxCoordRef = Ref.get(2, 0);
|
|
|
|
const minCoord = 0;
|
|
|
|
const maxCoord = 1;
|
|
|
|
const xref = new XRefMock([
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
{ ref: minCoordRef, data: minCoord },
|
|
|
|
{ ref: maxCoordRef, data: maxCoord },
|
2016-08-03 23:37:04 +09:00
|
|
|
]);
|
2020-06-07 22:04:24 +09:00
|
|
|
const xObjectDict = new Dict(xref);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
xObjectDict.set("BBox", [minCoord, maxCoord, minCoordRef, maxCoordRef]);
|
2016-08-03 23:37:04 +09:00
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
expect(xObjectDict.get("BBox")).toEqual([
|
|
|
|
minCoord,
|
|
|
|
maxCoord,
|
|
|
|
minCoordRef,
|
|
|
|
maxCoordRef,
|
|
|
|
]);
|
|
|
|
expect(xObjectDict.getArray("BBox")).toEqual([
|
|
|
|
minCoord,
|
|
|
|
maxCoord,
|
|
|
|
minCoord,
|
|
|
|
maxCoord,
|
|
|
|
]);
|
2016-08-03 23:37:04 +09:00
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
it("should get all key names", function () {
|
2020-06-07 22:04:24 +09:00
|
|
|
const expectedKeys = ["FontFile", "FontFile2", "FontFile3"];
|
|
|
|
const keys = dictWithManyKeys.getKeys();
|
2016-08-03 23:37:04 +09:00
|
|
|
|
|
|
|
expect(keys.sort()).toEqual(expectedKeys);
|
|
|
|
});
|
|
|
|
|
2020-07-17 19:57:34 +09:00
|
|
|
it("should get all raw values", function () {
|
|
|
|
// Test direct objects:
|
|
|
|
const expectedRawValues1 = [testFontFile, testFontFile2, testFontFile3];
|
|
|
|
const rawValues1 = dictWithManyKeys.getRawValues();
|
|
|
|
|
|
|
|
expect(rawValues1.sort()).toEqual(expectedRawValues1);
|
|
|
|
|
|
|
|
// Test indirect objects:
|
|
|
|
const typeName = Name.get("Page");
|
|
|
|
const resources = new Dict(null),
|
|
|
|
resourcesRef = Ref.get(5, 0);
|
|
|
|
const contents = new StringStream("data"),
|
|
|
|
contentsRef = Ref.get(10, 0);
|
|
|
|
const xref = new XRefMock([
|
|
|
|
{ ref: resourcesRef, data: resources },
|
|
|
|
{ ref: contentsRef, data: contents },
|
|
|
|
]);
|
|
|
|
|
|
|
|
const dict = new Dict(xref);
|
|
|
|
dict.set("Type", typeName);
|
|
|
|
dict.set("Resources", resourcesRef);
|
|
|
|
dict.set("Contents", contentsRef);
|
|
|
|
|
|
|
|
const expectedRawValues2 = [contentsRef, resourcesRef, typeName];
|
|
|
|
const rawValues2 = dict.getRawValues();
|
|
|
|
|
|
|
|
expect(rawValues2.sort()).toEqual(expectedRawValues2);
|
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
it("should create only one object for Dict.empty", function () {
|
2020-06-07 22:04:24 +09:00
|
|
|
const firstDictEmpty = Dict.empty;
|
|
|
|
const secondDictEmpty = Dict.empty;
|
2016-08-03 23:37:04 +09:00
|
|
|
|
|
|
|
expect(firstDictEmpty).toBe(secondDictEmpty);
|
|
|
|
expect(firstDictEmpty).not.toBe(emptyDict);
|
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
it("should correctly merge dictionaries", function () {
|
2020-06-07 22:04:24 +09:00
|
|
|
const expectedKeys = ["FontFile", "FontFile2", "FontFile3", "Size"];
|
2016-08-03 23:37:04 +09:00
|
|
|
|
2020-06-07 22:04:24 +09:00
|
|
|
const fontFileDict = new Dict();
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
fontFileDict.set("FontFile", "Type1 font file");
|
2020-08-28 08:05:33 +09:00
|
|
|
const mergedDict = Dict.merge({
|
|
|
|
xref: null,
|
|
|
|
dictArray: [dictWithManyKeys, dictWithSizeKey, fontFileDict],
|
|
|
|
});
|
2020-06-07 22:04:24 +09:00
|
|
|
const mergedKeys = mergedDict.getKeys();
|
2016-08-03 23:37:04 +09:00
|
|
|
|
|
|
|
expect(mergedKeys.sort()).toEqual(expectedKeys);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
expect(mergedDict.get("FontFile")).toEqual(testFontFile);
|
2016-08-03 23:37:04 +09:00
|
|
|
});
|
2020-08-28 08:05:33 +09:00
|
|
|
|
|
|
|
it("should correctly merge sub-dictionaries", function () {
|
|
|
|
const localFontDict = new Dict();
|
|
|
|
localFontDict.set("F1", "Local font one");
|
|
|
|
|
|
|
|
const globalFontDict = new Dict();
|
|
|
|
globalFontDict.set("F1", "Global font one");
|
|
|
|
globalFontDict.set("F2", "Global font two");
|
|
|
|
globalFontDict.set("F3", "Global font three");
|
|
|
|
|
|
|
|
const localDict = new Dict();
|
|
|
|
localDict.set("Font", localFontDict);
|
|
|
|
|
|
|
|
const globalDict = new Dict();
|
|
|
|
globalDict.set("Font", globalFontDict);
|
|
|
|
|
|
|
|
const mergedDict = Dict.merge({
|
|
|
|
xref: null,
|
|
|
|
dictArray: [localDict, globalDict],
|
|
|
|
});
|
|
|
|
const mergedSubDict = Dict.merge({
|
|
|
|
xref: null,
|
|
|
|
dictArray: [localDict, globalDict],
|
|
|
|
mergeSubDicts: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
const mergedFontDict = mergedDict.get("Font");
|
|
|
|
const mergedSubFontDict = mergedSubDict.get("Font");
|
|
|
|
|
|
|
|
expect(mergedFontDict instanceof Dict).toEqual(true);
|
|
|
|
expect(mergedSubFontDict instanceof Dict).toEqual(true);
|
|
|
|
|
|
|
|
const mergedFontDictKeys = mergedFontDict.getKeys();
|
|
|
|
const mergedSubFontDictKeys = mergedSubFontDict.getKeys();
|
|
|
|
|
|
|
|
expect(mergedFontDictKeys).toEqual(["F1"]);
|
|
|
|
expect(mergedSubFontDictKeys).toEqual(["F1", "F2", "F3"]);
|
|
|
|
|
|
|
|
const mergedFontDictValues = mergedFontDict.getRawValues();
|
|
|
|
const mergedSubFontDictValues = mergedSubFontDict.getRawValues();
|
|
|
|
|
|
|
|
expect(mergedFontDictValues).toEqual(["Local font one"]);
|
|
|
|
expect(mergedSubFontDictValues).toEqual([
|
|
|
|
"Local font one",
|
|
|
|
"Global font two",
|
|
|
|
"Global font three",
|
|
|
|
]);
|
|
|
|
});
|
2011-12-29 06:20:04 +09:00
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
describe("Ref", function () {
|
2020-06-07 22:06:54 +09:00
|
|
|
it("should get a string representation", function () {
|
|
|
|
const nonZeroRef = Ref.get(4, 2);
|
|
|
|
expect(nonZeroRef.toString()).toEqual("4R2");
|
|
|
|
|
|
|
|
// If the generation number is 0, a shorter representation is used.
|
|
|
|
const zeroRef = Ref.get(4, 0);
|
|
|
|
expect(zeroRef.toString()).toEqual("4R");
|
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
it("should retain the stored values", function () {
|
2020-06-07 22:04:24 +09:00
|
|
|
const storedNum = 4;
|
|
|
|
const storedGen = 2;
|
|
|
|
const ref = Ref.get(storedNum, storedGen);
|
2011-12-29 06:20:04 +09:00
|
|
|
expect(ref.num).toEqual(storedNum);
|
|
|
|
expect(ref.gen).toEqual(storedGen);
|
|
|
|
});
|
2020-06-07 22:06:54 +09:00
|
|
|
|
|
|
|
it("should create only one object for a reference and cache it", function () {
|
|
|
|
const firstRef = Ref.get(4, 2);
|
|
|
|
const secondRef = Ref.get(4, 2);
|
|
|
|
const firstOtherRef = Ref.get(5, 2);
|
|
|
|
const secondOtherRef = Ref.get(5, 2);
|
|
|
|
|
|
|
|
expect(firstRef).toBe(secondRef);
|
|
|
|
expect(firstOtherRef).toBe(secondOtherRef);
|
|
|
|
expect(firstRef).not.toBe(firstOtherRef);
|
|
|
|
});
|
2011-12-29 06:20:04 +09:00
|
|
|
});
|
2012-01-08 05:22:22 +09:00
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
describe("RefSet", function () {
|
|
|
|
it("should have a stored value", function () {
|
2020-06-07 22:04:24 +09:00
|
|
|
const ref = Ref.get(4, 2);
|
|
|
|
const refset = new RefSet();
|
2012-01-08 05:22:22 +09:00
|
|
|
refset.put(ref);
|
|
|
|
expect(refset.has(ref)).toBeTruthy();
|
|
|
|
});
|
2020-04-14 19:28:14 +09:00
|
|
|
it("should not have an unknown value", function () {
|
2020-06-07 22:04:24 +09:00
|
|
|
const ref = Ref.get(4, 2);
|
|
|
|
const refset = new RefSet();
|
2012-01-08 05:22:22 +09:00
|
|
|
expect(refset.has(ref)).toBeFalsy();
|
|
|
|
|
|
|
|
refset.put(ref);
|
2020-06-07 22:04:24 +09:00
|
|
|
const anotherRef = Ref.get(2, 4);
|
2012-01-08 05:22:22 +09:00
|
|
|
expect(refset.has(anotherRef)).toBeFalsy();
|
|
|
|
});
|
|
|
|
});
|
2016-04-17 03:32:46 +09:00
|
|
|
|
2020-07-12 18:51:27 +09:00
|
|
|
describe("RefSetCache", function () {
|
|
|
|
const ref1 = Ref.get(4, 2);
|
|
|
|
const ref2 = Ref.get(5, 2);
|
|
|
|
const obj1 = Name.get("foo");
|
|
|
|
const obj2 = Name.get("bar");
|
|
|
|
let cache;
|
|
|
|
|
2021-04-11 03:21:31 +09:00
|
|
|
beforeEach(function () {
|
2020-07-12 18:51:27 +09:00
|
|
|
cache = new RefSetCache();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function () {
|
|
|
|
cache = null;
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should put, have and get a value", function () {
|
|
|
|
cache.put(ref1, obj1);
|
|
|
|
expect(cache.has(ref1)).toBeTruthy();
|
|
|
|
expect(cache.has(ref2)).toBeFalsy();
|
|
|
|
expect(cache.get(ref1)).toBe(obj1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should put, have and get a value by alias", function () {
|
|
|
|
cache.put(ref1, obj1);
|
|
|
|
cache.putAlias(ref2, ref1);
|
|
|
|
expect(cache.has(ref1)).toBeTruthy();
|
|
|
|
expect(cache.has(ref2)).toBeTruthy();
|
|
|
|
expect(cache.get(ref1)).toBe(obj1);
|
|
|
|
expect(cache.get(ref2)).toBe(obj1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should report the size of the cache", function () {
|
|
|
|
cache.put(ref1, obj1);
|
|
|
|
expect(cache.size).toEqual(1);
|
|
|
|
cache.put(ref2, obj2);
|
|
|
|
expect(cache.size).toEqual(2);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should clear the cache", function () {
|
|
|
|
cache.put(ref1, obj1);
|
|
|
|
expect(cache.size).toEqual(1);
|
|
|
|
cache.clear();
|
|
|
|
expect(cache.size).toEqual(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should support iteration", function () {
|
|
|
|
cache.put(ref1, obj1);
|
|
|
|
cache.put(ref2, obj2);
|
|
|
|
|
|
|
|
const values = [];
|
|
|
|
cache.forEach(function (value) {
|
|
|
|
values.push(value);
|
|
|
|
});
|
|
|
|
expect(values).toEqual([obj1, obj2]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
describe("isName", function () {
|
|
|
|
it("handles non-names", function () {
|
2020-06-07 22:04:24 +09:00
|
|
|
const nonName = {};
|
2016-08-03 23:37:04 +09:00
|
|
|
expect(isName(nonName)).toEqual(false);
|
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
it("handles names", function () {
|
2020-06-07 22:04:24 +09:00
|
|
|
const name = Name.get("Font");
|
2016-08-03 23:37:04 +09:00
|
|
|
expect(isName(name)).toEqual(true);
|
|
|
|
});
|
2016-08-04 21:57:31 +09:00
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
it("handles names with name check", function () {
|
2020-06-07 22:04:24 +09:00
|
|
|
const name = Name.get("Font");
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
expect(isName(name, "Font")).toEqual(true);
|
|
|
|
expect(isName(name, "Subtype")).toEqual(false);
|
2016-08-04 21:57:31 +09:00
|
|
|
});
|
2021-07-15 04:38:19 +09:00
|
|
|
|
|
|
|
it("handles *empty* names, with name check", function () {
|
|
|
|
const emptyName = Name.get("");
|
|
|
|
|
|
|
|
expect(isName(emptyName)).toEqual(true);
|
|
|
|
expect(isName(emptyName, "")).toEqual(true);
|
|
|
|
expect(isName(emptyName, "string")).toEqual(false);
|
|
|
|
});
|
2016-08-03 23:37:04 +09:00
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
describe("isCmd", function () {
|
|
|
|
it("handles non-commands", function () {
|
2020-06-07 22:04:24 +09:00
|
|
|
const nonCmd = {};
|
2016-08-03 23:37:04 +09:00
|
|
|
expect(isCmd(nonCmd)).toEqual(false);
|
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
it("handles commands", function () {
|
2020-06-07 22:04:24 +09:00
|
|
|
const cmd = Cmd.get("BT");
|
2016-08-03 23:37:04 +09:00
|
|
|
expect(isCmd(cmd)).toEqual(true);
|
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
it("handles commands with cmd check", function () {
|
2020-06-07 22:04:24 +09:00
|
|
|
const cmd = Cmd.get("BT");
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
expect(isCmd(cmd, "BT")).toEqual(true);
|
|
|
|
expect(isCmd(cmd, "ET")).toEqual(false);
|
2016-08-03 23:37:04 +09:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
describe("isDict", function () {
|
|
|
|
it("handles non-dictionaries", function () {
|
2020-06-07 22:04:24 +09:00
|
|
|
const nonDict = {};
|
2016-08-03 23:37:04 +09:00
|
|
|
expect(isDict(nonDict)).toEqual(false);
|
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
it("handles empty dictionaries with type check", function () {
|
2020-06-07 22:04:24 +09:00
|
|
|
const dict = Dict.empty;
|
2016-08-03 23:37:04 +09:00
|
|
|
expect(isDict(dict)).toEqual(true);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
expect(isDict(dict, "Page")).toEqual(false);
|
2016-04-17 03:32:46 +09:00
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
it("handles dictionaries with type check", function () {
|
2020-06-07 22:04:24 +09:00
|
|
|
const dict = new Dict();
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
dict.set("Type", Name.get("Page"));
|
|
|
|
expect(isDict(dict, "Page")).toEqual(true);
|
|
|
|
expect(isDict(dict, "Contents")).toEqual(false);
|
2016-08-03 23:37:04 +09:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
describe("isRef", function () {
|
|
|
|
it("handles non-refs", function () {
|
2020-06-07 22:04:24 +09:00
|
|
|
const nonRef = {};
|
2016-08-03 23:37:04 +09:00
|
|
|
expect(isRef(nonRef)).toEqual(false);
|
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
it("handles refs", function () {
|
2020-06-07 22:04:24 +09:00
|
|
|
const ref = Ref.get(1, 0);
|
2016-08-03 23:37:04 +09:00
|
|
|
expect(isRef(ref)).toEqual(true);
|
2016-04-17 03:32:46 +09:00
|
|
|
});
|
|
|
|
});
|
2016-05-16 23:28:25 +09:00
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
describe("isRefsEqual", function () {
|
|
|
|
it("should handle Refs pointing to the same object", function () {
|
2020-06-07 22:04:24 +09:00
|
|
|
const ref1 = Ref.get(1, 0);
|
|
|
|
const ref2 = Ref.get(1, 0);
|
2016-05-16 23:28:25 +09:00
|
|
|
expect(isRefsEqual(ref1, ref2)).toEqual(true);
|
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
it("should handle Refs pointing to different objects", function () {
|
2020-06-07 22:04:24 +09:00
|
|
|
const ref1 = Ref.get(1, 0);
|
|
|
|
const ref2 = Ref.get(2, 0);
|
2016-05-16 23:28:25 +09:00
|
|
|
expect(isRefsEqual(ref1, ref2)).toEqual(false);
|
|
|
|
});
|
|
|
|
});
|
2020-06-07 22:06:54 +09:00
|
|
|
|
|
|
|
describe("isStream", function () {
|
|
|
|
it("handles non-streams", function () {
|
|
|
|
const nonStream = {};
|
|
|
|
expect(isStream(nonStream)).toEqual(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("handles streams", function () {
|
|
|
|
const stream = new StringStream("foo");
|
|
|
|
expect(isStream(stream)).toEqual(true);
|
|
|
|
});
|
|
|
|
});
|
2011-11-14 04:39:56 +09:00
|
|
|
});
|