mirror of
https://github.com/nodejs/node.git
synced 2025-05-01 08:42:45 +00:00

Previously, using Reflect.get/set or calling a member method like toString() detached from the instance would result in an obscure internal error. This adds a proper brand check and throws `ERR_INVALID_THIS` when appropriate. Signed-off-by: James M Snell <jasnell@gmail.com> PR-URL: https://github.com/nodejs/node/pull/39752 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Zijian Liu <lxxyxzj@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
46 lines
753 B
JavaScript
46 lines
753 B
JavaScript
'use strict';
|
|
|
|
require('../common');
|
|
|
|
const { URL } = require('url');
|
|
const assert = require('assert');
|
|
|
|
[
|
|
'toString',
|
|
'toJSON',
|
|
].forEach((i) => {
|
|
assert.throws(() => Reflect.apply(URL.prototype[i], [], {}), {
|
|
code: 'ERR_INVALID_THIS',
|
|
});
|
|
});
|
|
|
|
[
|
|
'href',
|
|
'protocol',
|
|
'username',
|
|
'password',
|
|
'host',
|
|
'hostname',
|
|
'port',
|
|
'pathname',
|
|
'search',
|
|
'hash',
|
|
].forEach((i) => {
|
|
assert.throws(() => Reflect.get(URL.prototype, i, {}), {
|
|
code: 'ERR_INVALID_THIS',
|
|
});
|
|
|
|
assert.throws(() => Reflect.set(URL.prototype, i, null, {}), {
|
|
code: 'ERR_INVALID_THIS',
|
|
});
|
|
});
|
|
|
|
[
|
|
'origin',
|
|
'searchParams',
|
|
].forEach((i) => {
|
|
assert.throws(() => Reflect.get(URL.prototype, i, {}), {
|
|
code: 'ERR_INVALID_THIS',
|
|
});
|
|
});
|