-
Notifications
You must be signed in to change notification settings - Fork 30.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
src: prevent URLPattern property accessors from crashing on invalid this
PR-URL: #56877 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
- Loading branch information
Showing
2 changed files
with
63 additions
and
9 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,40 @@ | ||
'use strict'; | ||
|
||
require('../common'); | ||
|
||
const { URLPattern } = require('url'); | ||
const { throws } = require('assert'); | ||
|
||
const pattern = new URLPattern(); | ||
const proto = Object.getPrototypeOf(pattern); | ||
|
||
// Verifies that attempts to call the property getters on a URLPattern | ||
// with the incorrect `this` will not crash the process. | ||
[ | ||
'protocol', | ||
'username', | ||
'password', | ||
'hostname', | ||
'port', | ||
'pathname', | ||
'search', | ||
'hash', | ||
'hasRegExpGroups', | ||
].forEach((i) => { | ||
const prop = Object.getOwnPropertyDescriptor(proto, i).get; | ||
throws(() => prop({}), { | ||
message: 'Illegal invocation', | ||
}, i); | ||
}); | ||
|
||
// Verifies that attempts to call the exec and test functions | ||
// with the wrong this also throw | ||
|
||
const { test, exec } = pattern; | ||
|
||
throws(() => test({}), { | ||
message: 'Illegal invocation', | ||
}); | ||
throws(() => exec({}), { | ||
message: 'Illegal invocation', | ||
}); |