-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
url: throw invalid this on detached accessors
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 <[email protected]> PR-URL: #39752 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Zijian Liu <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
- Loading branch information
Showing
2 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
'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', | ||
}); | ||
}); |