8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
ERR_INVALID_THIS
1 parent 1ee539a commit d07ce8eCopy full SHA for d07ce8e
lib/internal/fs/dir.js
@@ -18,6 +18,7 @@ const {
18
codes: {
19
ERR_DIR_CLOSED,
20
ERR_DIR_CONCURRENT_OPERATION,
21
+ ERR_INVALID_THIS,
22
ERR_MISSING_ARGS,
23
},
24
} = require('internal/errors');
@@ -67,6 +68,8 @@ class Dir {
67
68
}
69
70
get path() {
71
+ if (!(#path in this))
72
+ throw new ERR_INVALID_THIS('Dir');
73
return this.#path;
74
75
lib/internal/fs/streams.js
@@ -26,6 +26,7 @@ const {
26
validateBoolean,
27
validateFunction,
28
validateInteger,
29
+ validateThisInternalField,
30
} = require('internal/validators');
31
const { errorOrDestroy } = require('internal/streams/destroy');
32
const fs = require('fs');
@@ -231,9 +232,11 @@ ObjectSetPrototypeOf(ReadStream, Readable);
231
232
ObjectDefineProperty(ReadStream.prototype, 'autoClose', {
233
__proto__: null,
234
get() {
235
+ validateThisInternalField(this, kFs, 'ReadStream');
236
return this._readableState.autoDestroy;
237
238
set(val) {
239
240
this._readableState.autoDestroy = val;
241
242
});
@@ -400,9 +403,11 @@ ObjectSetPrototypeOf(WriteStream, Writable);
400
403
ObjectDefineProperty(WriteStream.prototype, 'autoClose', {
401
404
402
405
406
+ validateThisInternalField(this, kFs, 'WriteStream');
407
return this._writableState.autoDestroy;
408
409
410
411
this._writableState.autoDestroy = val;
412
413
test/parallel/test-fs-opendir.js
@@ -18,6 +18,13 @@ files.forEach(function(filename) {
fs.closeSync(fs.openSync(path.join(testDir, filename), 'w'));
+function assertDir(dir) {
+ assert(dir instanceof fs.Dir);
+ assert.throws(() => dir.constructor.prototype.path, {
+ code: 'ERR_INVALID_THIS',
25
+ });
+}
+
function assertDirent(dirent) {
assert(dirent instanceof fs.Dirent);
assert.strictEqual(dirent.isFile(), true);
@@ -45,6 +52,7 @@ const invalidCallbackObj = {
45
52
// Check the opendir Sync version
46
53
{
47
54
const dir = fs.opendirSync(testDir);
55
+ assertDir(dir);
48
56
const entries = files.map(() => {
49
57
const dirent = dir.readSync();
50
58
assertDirent(dirent);
@@ -67,6 +75,7 @@ const invalidCallbackObj = {
76
// Check the opendir async version
77
fs.opendir(testDir, common.mustSucceed((dir) => {
78
79
let sync = true;
80
dir.read(common.mustSucceed((dirent) => {
81
assert(!sync);
@@ -120,6 +129,7 @@ fs.opendir(__filename, common.mustCall(function(e) {
120
129
async function doPromiseTest() {
121
130
// Check the opendir Promise version
122
131
const dir = await fs.promises.opendir(testDir);
132
123
133
const entries = [];
124
134
125
135
let i = files.length;
test/parallel/test-fs-write-stream-autoclose-option.js
@@ -56,3 +56,7 @@ function next3() {
}));
59
60
+assert.throws(() => fs.WriteStream.prototype.autoClose, {
61
62
+});