mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-26 01:58:06 +02:00
Use the ESLint no-restricted-syntax
rule to prevent direct usage of new Cmd()
/new Name()
/new Ref()
Given that all of these primitives implement caching, to avoid unnecessarily duplicating those objects *a lot* during parsing, it would thus be good to actually enforce usage of `Cmd.get()`/`Name.get()`/`Ref.get()` in the code-base. Luckily it turns out that there's an ESLint rule, which is fairly easy to use, that can be used to disallow arbitrary JavaScript syntax. Please find additional details about the ESLint rule at https://eslint.org/docs/rules/no-restricted-syntax
This commit is contained in:
parent
3472b671e7
commit
bf09d79eea
3 changed files with 32 additions and 15 deletions
|
@ -29,6 +29,7 @@ var Name = (function NameClosure() {
|
|||
|
||||
Name.get = function Name_get(name) {
|
||||
var nameValue = nameCache[name];
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
return nameValue ? nameValue : (nameCache[name] = new Name(name));
|
||||
};
|
||||
|
||||
|
@ -50,6 +51,7 @@ var Cmd = (function CmdClosure() {
|
|||
|
||||
Cmd.get = function Cmd_get(cmd) {
|
||||
var cmdValue = cmdCache[cmd];
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
return cmdValue ? cmdValue : (cmdCache[cmd] = new Cmd(cmd));
|
||||
};
|
||||
|
||||
|
@ -195,6 +197,7 @@ var Ref = (function RefClosure() {
|
|||
Ref.get = function(num, gen) {
|
||||
const key = gen === 0 ? `${num}R` : `${num}R${gen}`;
|
||||
const refValue = refCache[key];
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
return refValue ? refValue : (refCache[key] = new Ref(num, gen));
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue