Skip to content

Commit

Permalink
buffer: use private properties for brand checks in File
Browse files Browse the repository at this point in the history
PR-URL: #47154
Refs: #46904
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
KhafraDev authored and RafaelGSS committed Apr 7, 2023
1 parent a3bffba commit e3d98c3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
9 changes: 0 additions & 9 deletions lib/internal/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const {

const {
codes: {
ERR_INVALID_THIS,
ERR_MISSING_ARGS,
},
} = require('internal/errors');
Expand Down Expand Up @@ -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;
}

Expand Down
17 changes: 11 additions & 6 deletions test/parallel/test-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
});
}

0 comments on commit e3d98c3

Please sign in to comment.