From e3d98c3e7ae39797dda9bdd3ffc0e1aea1077917 Mon Sep 17 00:00:00 2001 From: Khafra Date: Mon, 20 Mar 2023 18:01:41 -0400 Subject: [PATCH] buffer: use private properties for brand checks in File PR-URL: https://github.com/nodejs/node/pull/47154 Refs: https://github.com/nodejs/node/pull/46904 Reviewed-By: Yagiz Nizipli Reviewed-By: Luigi Pinca --- lib/internal/file.js | 9 --------- test/parallel/test-file.js | 17 +++++++++++------ 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/lib/internal/file.js b/lib/internal/file.js index 8ef858d67e2d9c..4c6ca4f61fa4d8 100644 --- a/lib/internal/file.js +++ b/lib/internal/file.js @@ -21,7 +21,6 @@ const { const { codes: { - ERR_INVALID_THIS, ERR_MISSING_ARGS, }, } = require('internal/errors'); @@ -64,18 +63,10 @@ class File extends Blob { } get name() { - if (!this || !(#name in this)) { - throw new ERR_INVALID_THIS('File'); - } - return this.#name; } get lastModified() { - if (!this || !(#name in this)) { - throw new ERR_INVALID_THIS('File'); - } - return this.#lastModified; } diff --git a/test/parallel/test-file.js b/test/parallel/test-file.js index 64a83f77ef919d..bfc4548421be23 100644 --- a/test/parallel/test-file.js +++ b/test/parallel/test-file.js @@ -146,10 +146,15 @@ const { inspect } = require('util'); { const getter = Object.getOwnPropertyDescriptor(File.prototype, 'name').get; - assert.throws( - () => getter.call(undefined), // eslint-disable-line no-useless-call - { - code: 'ERR_INVALID_THIS', - } - ); + + [ + undefined, + null, + true, + ].forEach((invalidThis) => { + assert.throws( + () => getter.call(invalidThis), + TypeError + ); + }); }