Skip to content

Commit 236d7ca

Browse files
Archkonaduh95
authored andcommitted
url: create URLPattern result properties in WebIDL order
Reorder the URLPatternResult and URLPatternComponentResult dictionary templates, together with their value arrays, to follow the lexicographical member order required by WebIDL. Signed-off-by: Archkon <180910180+Archkon@users.noreply.github.com> PR-URL: #64733 Fixes: #64732 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Filip Skokan <panva.ip@gmail.com>
1 parent 4345185 commit 236d7ca

2 files changed

Lines changed: 36 additions & 12 deletions

File tree

src/node_url_pattern.cc

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -446,13 +446,13 @@ MaybeLocal<Object> URLPattern::URLPatternComponentResult::ToJSObject(
446446
auto tmpl = env->urlpatterncomponentresult_template();
447447
if (tmpl.IsEmpty()) {
448448
static constexpr std::string_view namesVec[] = {
449-
"input",
450449
"groups",
450+
"input",
451451
};
452452
tmpl = DictionaryTemplate::New(isolate, namesVec);
453453
env->set_urlpatterncomponentresult_template(tmpl);
454454
}
455-
MaybeLocal<Value> values[] = {input, parsed_group};
455+
MaybeLocal<Value> values[] = {parsed_group, input};
456456
return NewDictionaryInstance(env->context(), tmpl, values);
457457
}
458458

@@ -463,22 +463,24 @@ MaybeLocal<Value> URLPattern::URLPatternResult::ToJSValue(
463463
auto tmpl = env->urlpatternresult_template();
464464
if (tmpl.IsEmpty()) {
465465
static constexpr std::string_view namesVec[] = {
466+
"hash",
467+
"hostname",
466468
"inputs",
467-
"protocol",
468-
"username",
469469
"password",
470-
"hostname",
471-
"port",
472470
"pathname",
471+
"port",
472+
"protocol",
473473
"search",
474-
"hash",
474+
"username",
475475
};
476476
tmpl = DictionaryTemplate::New(isolate, namesVec);
477477
env->set_urlpatternresult_template(tmpl);
478478
}
479479

480480
size_t index = 0;
481481
MaybeLocal<Value> vals[] = {
482+
URLPatternComponentResult::ToJSObject(env, result.hash),
483+
URLPatternComponentResult::ToJSObject(env, result.hostname),
482484
Array::New(env->context(),
483485
result.inputs.size(),
484486
[&index, &inputs = result.inputs, env]() {
@@ -493,14 +495,12 @@ MaybeLocal<Value> URLPattern::URLPatternResult::ToJSValue(
493495
return URLPatternInit::ToJsObject(env, init);
494496
}
495497
}),
496-
URLPatternComponentResult::ToJSObject(env, result.protocol),
497-
URLPatternComponentResult::ToJSObject(env, result.username),
498498
URLPatternComponentResult::ToJSObject(env, result.password),
499-
URLPatternComponentResult::ToJSObject(env, result.hostname),
500-
URLPatternComponentResult::ToJSObject(env, result.port),
501499
URLPatternComponentResult::ToJSObject(env, result.pathname),
500+
URLPatternComponentResult::ToJSObject(env, result.port),
501+
URLPatternComponentResult::ToJSObject(env, result.protocol),
502502
URLPatternComponentResult::ToJSObject(env, result.search),
503-
URLPatternComponentResult::ToJSObject(env, result.hash)};
503+
URLPatternComponentResult::ToJSObject(env, result.username)};
504504
return NewDictionaryInstanceNullProto(env->context(), tmpl, vals);
505505
}
506506

test/parallel/test-urlpattern.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,27 @@ assert.throws(() => {
2626
}, {
2727
message: 'boom'
2828
});
29+
30+
{
31+
const result = new URLPattern({ pathname: '/:value' })
32+
.exec('https://example.com/test');
33+
34+
assert.deepStrictEqual(Object.keys(result), [
35+
'hash',
36+
'hostname',
37+
'inputs',
38+
'password',
39+
'pathname',
40+
'port',
41+
'protocol',
42+
'search',
43+
'username',
44+
]);
45+
assert.deepStrictEqual(Object.keys(result.pathname), [
46+
'groups',
47+
'input',
48+
]);
49+
assert.strictEqual(result.hostname.input, 'example.com');
50+
assert.strictEqual(result.pathname.input, '/test');
51+
assert.strictEqual(result.pathname.groups.value, 'test');
52+
}

0 commit comments

Comments
 (0)