Skip to content

Commit 01ab95b

Browse files
committed
url: add Symbol.toStringTag to URLPattern
Define Symbol.toStringTag on URLPattern.prototype so its class string matches the Web IDL interface name. Add coverage for the property descriptor and Object.prototype.toString(). Fixes: #65924 Signed-off-by: XadillaX <i@2333.moe>
1 parent cb9b870 commit 01ab95b

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

‎src/node_url_pattern.cc‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,10 @@ static void Initialize(Local<Object> target,
687687
auto instance_template = ctor_tmpl->InstanceTemplate();
688688
auto prototype_template = ctor_tmpl->PrototypeTemplate();
689689
ctor_tmpl->SetClassName(FIXED_ONE_BYTE_STRING(isolate, "URLPattern"));
690+
prototype_template->Set(
691+
v8::Symbol::GetToStringTag(isolate),
692+
FIXED_ONE_BYTE_STRING(isolate, "URLPattern"),
693+
static_cast<PropertyAttribute>(ReadOnly | v8::DontEnum));
690694

691695
// The signature is used to prevent the property accessors from being
692696
// called on the wrong receiver object (`this`)

‎test/parallel/test-urlpattern.js‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,20 @@ require('../common');
55
const assert = require('assert');
66
const { URLPattern } = require('url');
77

8+
{
9+
assert.deepStrictEqual(
10+
Object.getOwnPropertyDescriptor(URLPattern.prototype, Symbol.toStringTag),
11+
{
12+
configurable: true,
13+
enumerable: false,
14+
value: 'URLPattern',
15+
writable: false,
16+
});
17+
assert.strictEqual(
18+
Object.prototype.toString.call(new URLPattern()),
19+
'[object URLPattern]');
20+
}
21+
822
// Verify that if an error is thrown while accessing any of the
923
// init options, the error is appropriately propagated.
1024
assert.throws(() => {

0 commit comments

Comments
 (0)