mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-26 10:08:06 +02:00
Ensure that Cmd
/Name
is only initialized with string arguments
Trying to use a non-string argument in either a `Cmd` or a `Name` is not intended, and would basically be an implementation error. Hence we can add a non-PRODUCTION check to enforce this, similar to the existing one used e.g. in the `Dict.set` method.
This commit is contained in:
parent
2bb96a708c
commit
ec87995050
3 changed files with 27 additions and 1 deletions
|
@ -24,6 +24,13 @@ const Name = (function NameClosure() {
|
|||
// eslint-disable-next-line no-shadow
|
||||
class Name {
|
||||
constructor(name) {
|
||||
if (
|
||||
(typeof PDFJSDev === "undefined" ||
|
||||
PDFJSDev.test("!PRODUCTION || TESTING")) &&
|
||||
typeof name !== "string"
|
||||
) {
|
||||
unreachable('Name: The "name" must be a string.');
|
||||
}
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
@ -47,6 +54,13 @@ const Cmd = (function CmdClosure() {
|
|||
// eslint-disable-next-line no-shadow
|
||||
class Cmd {
|
||||
constructor(cmd) {
|
||||
if (
|
||||
(typeof PDFJSDev === "undefined" ||
|
||||
PDFJSDev.test("!PRODUCTION || TESTING")) &&
|
||||
typeof cmd !== "string"
|
||||
) {
|
||||
unreachable('Cmd: The "cmd" must be a string.');
|
||||
}
|
||||
this.cmd = cmd;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue