PR-URL: https://github.com/nodejs/node/pull/60728 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
40 lines
878 B
JavaScript
40 lines
878 B
JavaScript
'use strict';
|
|
|
|
require('../common');
|
|
|
|
const { URLPattern } = require('url');
|
|
const assert = 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;
|
|
assert.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;
|
|
|
|
assert.throws(() => test({}), {
|
|
message: 'Illegal invocation',
|
|
});
|
|
assert.throws(() => exec({}), {
|
|
message: 'Illegal invocation',
|
|
});
|