Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
lib: make validateInternalField() throw ERR_INVALID_THIS
  • Loading branch information
LiviaMedeiros committed Jun 19, 2025
commit b8de1acf7c38fbd075c213d10b685a41333b65fe
2 changes: 1 addition & 1 deletion 2 lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -1541,7 +1541,7 @@ E('ERR_INVALID_SYNC_FORK_INPUT',
'Asynchronous forks do not support ' +
'Buffer, TypedArray, DataView or string input: %s',
TypeError);
E('ERR_INVALID_THIS', 'Value of "this" must be of type %s', TypeError);
E('ERR_INVALID_THIS', 'Value of "this" must be of type %s', TypeError, HideStackFramesError);
E('ERR_INVALID_TUPLE', '%s must be an iterable %s tuple', TypeError);
E('ERR_INVALID_TYPESCRIPT_SYNTAX', '%s', SyntaxError);
E('ERR_INVALID_URI', 'URI malformed', URIError);
Expand Down
9 changes: 8 additions & 1 deletion 9 lib/internal/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const {
codes: {
ERR_INVALID_ARG_TYPE: { HideStackFramesError: ERR_INVALID_ARG_TYPE },
ERR_INVALID_ARG_VALUE: { HideStackFramesError: ERR_INVALID_ARG_VALUE },
ERR_INVALID_THIS: { HideStackFramesError: ERR_INVALID_THIS },
ERR_OUT_OF_RANGE: { HideStackFramesError: ERR_OUT_OF_RANGE },
ERR_SOCKET_BAD_PORT: { HideStackFramesError: ERR_SOCKET_BAD_PORT },
ERR_UNKNOWN_SIGNAL: { HideStackFramesError: ERR_UNKNOWN_SIGNAL },
Expand Down Expand Up @@ -526,9 +527,15 @@ const validateLinkHeaderFormat = hideStackFrames((value, name) => {
}
});

/**
* Validate provided `this` object by checking that it has specific own property
* @param {any} object
* @param {string|symbol} fieldKey
* @param {string} className
*/
const validateInternalField = hideStackFrames((object, fieldKey, className) => {
if (typeof object !== 'object' || object === null || !ObjectPrototypeHasOwnProperty(object, fieldKey)) {
throw new ERR_INVALID_ARG_TYPE('this', className, object);
throw new ERR_INVALID_THIS(className);
}
});

Expand Down
5 changes: 1 addition & 4 deletions 5 test/parallel/test-vm-module-basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,7 @@ const util = require('util');
for (const value of [null, { __proto__: null }, SourceTextModule.prototype]) {
assert.throws(
() => m[util.inspect.custom].call(value),
{
code: 'ERR_INVALID_ARG_TYPE',
message: /The "this" argument must be an instance of Module/,
},
{ code: 'ERR_INVALID_THIS' },
);
}
}
Expand Down
10 changes: 2 additions & 8 deletions 10 test/parallel/test-vm-module-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,7 @@ async function checkInvalidOptionForEvaluate() {
['link', 'evaluate'].forEach(async (method) => {
await assert.rejects(async () => {
await Module.prototype[method]();
}, {
code: 'ERR_INVALID_ARG_TYPE',
message: /The "this" argument must be an instance of Module/
});
}, { code: 'ERR_INVALID_THIS' });
});
}
}
Expand All @@ -240,10 +237,7 @@ function checkInvalidCachedData() {
}

function checkGettersErrors() {
const expectedError = {
code: 'ERR_INVALID_ARG_TYPE',
message: /The "this" argument must be an instance of (?:Module|SourceTextModule)/,
};
const expectedError = { code: 'ERR_INVALID_THIS' };
const getters = ['identifier', 'context', 'namespace', 'status', 'error'];
getters.forEach((getter) => {
assert.throws(() => {
Expand Down
5 changes: 1 addition & 4 deletions 5 test/parallel/test-vm-module-synthetic.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,7 @@ const assert = require('assert');
for (const value of [null, {}, SyntheticModule.prototype]) {
assert.throws(() => {
SyntheticModule.prototype.setExport.call(value, 'foo');
}, {
code: 'ERR_INVALID_ARG_TYPE',
message: /The "this" argument must be an instance of SyntheticModule/
});
}, { code: 'ERR_INVALID_THIS' });
}

})().then(common.mustCall());
Morty Proxy This is a proxified and sanitized view of the page, visit original site.