From 393e443e2cd1ad6be0b8e487f494788ca4ed0cbd Mon Sep 17 00:00:00 2001 From: Khafra <42794878+KhafraDev@users.noreply.github.com> Date: Sat, 18 Mar 2023 17:54:19 -0400 Subject: [PATCH] buffer: use private properties for brand checks in File --- 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 + ); + }); }