Merge pull request #12543 from Snuffleupagus/openActionMap

Use a `Map`, rather than an `Object`, internally in the `Catalog.openAction` getter (PR 11644 follow-up)
This commit is contained in:
Tim van der Meij 2020-10-28 22:21:49 +01:00 committed by GitHub
commit 7853d9798b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 23 additions and 19 deletions

View File

@ -25,6 +25,7 @@ import {
isBool, isBool,
isNum, isNum,
isString, isString,
objectFromEntries,
PermissionFlag, PermissionFlag,
shadow, shadow,
stringToPDFString, stringToPDFString,
@ -786,7 +787,7 @@ class Catalog {
*/ */
get openAction() { get openAction() {
const obj = this._catDict.get("OpenAction"); const obj = this._catDict.get("OpenAction");
let openAction = null; const openActionMap = new Map();
if (isDict(obj)) { if (isDict(obj)) {
// Convert the OpenAction dictionary into a format that works with // Convert the OpenAction dictionary into a format that works with
@ -798,23 +799,18 @@ class Catalog {
Catalog.parseDestDictionary({ destDict, resultObj }); Catalog.parseDestDictionary({ destDict, resultObj });
if (Array.isArray(resultObj.dest)) { if (Array.isArray(resultObj.dest)) {
if (!openAction) { openActionMap.set("dest", resultObj.dest);
openAction = Object.create(null);
}
openAction.dest = resultObj.dest;
} else if (resultObj.action) { } else if (resultObj.action) {
if (!openAction) { openActionMap.set("action", resultObj.action);
openAction = Object.create(null);
}
openAction.action = resultObj.action;
} }
} else if (Array.isArray(obj)) { } else if (Array.isArray(obj)) {
if (!openAction) { openActionMap.set("dest", obj);
openAction = Object.create(null);
} }
openAction.dest = obj; return shadow(
} this,
return shadow(this, "openAction", openAction); "openAction",
openActionMap.size > 0 ? objectFromEntries(openActionMap) : null
);
} }
get attachments() { get attachments() {

View File

@ -13,6 +13,8 @@
* limitations under the License. * limitations under the License.
*/ */
import { objectFromEntries } from "../shared/util.js";
/** /**
* Key/value storage for annotation data in forms. * Key/value storage for annotation data in forms.
*/ */
@ -67,7 +69,7 @@ class AnnotationStorage {
if (this._storage.size === 0) { if (this._storage.size === 0) {
return null; return null;
} }
return Object.fromEntries(this._storage); return objectFromEntries(this._storage);
} }
get size() { get size() {

View File

@ -13,7 +13,7 @@
* limitations under the License. * limitations under the License.
*/ */
import { assert } from "../shared/util.js"; import { assert, objectFromEntries } from "../shared/util.js";
import { SimpleXMLParser } from "../shared/xml_parser.js"; import { SimpleXMLParser } from "../shared/xml_parser.js";
class Metadata { class Metadata {
@ -118,7 +118,7 @@ class Metadata {
} }
getAll() { getAll() {
return Object.fromEntries(this._metadataMap); return objectFromEntries(this._metadataMap);
} }
has(name) { has(name) {

View File

@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import { warn } from "../shared/util.js"; import { objectFromEntries, warn } from "../shared/util.js";
class OptionalContentGroup { class OptionalContentGroup {
constructor(name, intent) { constructor(name, intent) {
@ -145,7 +145,7 @@ class OptionalContentConfig {
if (!this._groups.size) { if (!this._groups.size) {
return null; return null;
} }
return Object.fromEntries(this._groups); return objectFromEntries(this._groups);
} }
getGroup(id) { getGroup(id) {

View File

@ -585,6 +585,11 @@ function string32(value) {
); );
} }
// Ensures that the returned Object has a `null` prototype.
function objectFromEntries(iterable) {
return Object.assign(Object.create(null), Object.fromEntries(iterable));
}
// Checks the endianness of the platform. // Checks the endianness of the platform.
function isLittleEndian() { function isLittleEndian() {
const buffer8 = new Uint8Array(4); const buffer8 = new Uint8Array(4);
@ -1035,6 +1040,7 @@ export {
isString, isString,
isSameOrigin, isSameOrigin,
createValidAbsoluteUrl, createValidAbsoluteUrl,
objectFromEntries,
IsLittleEndianCached, IsLittleEndianCached,
IsEvalSupportedCached, IsEvalSupportedCached,
removeNullCharacters, removeNullCharacters,