Moved definition of CookieJar.cookies because it caused TypeError on constructor

Creating new CookieJar instance while passing array of Cookies as third argument causes typeError
`new CookieJar('', 'r', cookies)`

```(node:29588) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'get' of undefined
    at CookieJar.addCookie (\node_modules\node-fetch-cookies\src\cookie-jar.mjs:44:26)
    at \node_modules\node-fetch-cookies\src\cookie-jar.mjs:15:44
    at CoreMongooseArray.forEach (<anonymous>)
    at new CookieJar (\node_modules\node-fetch-cookies\src\cookie-jar.mjs:15:21)```
This commit is contained in:
sliterok 2020-05-29 19:26:47 +05:00 committed by GitHub
parent a691a46ffb
commit 63fe16443e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5,6 +5,8 @@ import {paramError, CookieParseError} from "./errors.mjs";
export default class CookieJar { export default class CookieJar {
constructor(file, flags = "rw", cookies, cookieIgnoreCallback) { constructor(file, flags = "rw", cookies, cookieIgnoreCallback) {
this.cookies = new Map();
if(file && typeof file !== "string") if(file && typeof file !== "string")
throw paramError("Second", "file", "new CookieJar()", "string"); throw paramError("Second", "file", "new CookieJar()", "string");
if(typeof flags !== "string") if(typeof flags !== "string")
@ -22,7 +24,6 @@ export default class CookieJar {
throw paramError("Fourth", "cookieIgnoreCallback", "new CookieJar()", "function"); throw paramError("Fourth", "cookieIgnoreCallback", "new CookieJar()", "function");
this.file = file; this.file = file;
this.flags = flags; this.flags = flags;
this.cookies = new Map();
this.cookieIgnoreCallback = cookieIgnoreCallback; this.cookieIgnoreCallback = cookieIgnoreCallback;
} }
addCookie(cookie, fromURL) { addCookie(cookie, fromURL) {