GeezerVison is showing github.com — url: create URLPattern result properties in WebIDL order · nodejs/node@236d7ca
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: src/node_url_pattern.cc +12-12Lines changed: 12 additions & 12 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -446,13 +446,13 @@ MaybeLocal<Object> URLPattern::URLPatternComponentResult::ToJSObject( | 446 | 446 | auto tmpl = env->urlpatterncomponentresult_template(); | 447 | 447 | if (tmpl.IsEmpty()) { | 448 | 448 | static constexpr std::string_view namesVec[] = { | 449 | | - "input", | 450 | 449 | "groups", | | 450 | + "input", | 451 | 451 | }; | 452 | 452 | tmpl = DictionaryTemplate::New(isolate, namesVec); | 453 | 453 | env->set_urlpatterncomponentresult_template(tmpl); | 454 | 454 | } | 455 | | - MaybeLocal<Value> values[] = {input, parsed_group}; | | 455 | + MaybeLocal<Value> values[] = {parsed_group, input}; | 456 | 456 | return NewDictionaryInstance(env->context(), tmpl, values); | 457 | 457 | } | 458 | 458 |
| @@ -463,22 +463,24 @@ MaybeLocal<Value> URLPattern::URLPatternResult::ToJSValue( | 463 | 463 | auto tmpl = env->urlpatternresult_template(); | 464 | 464 | if (tmpl.IsEmpty()) { | 465 | 465 | static constexpr std::string_view namesVec[] = { | | 466 | + "hash", | | 467 | + "hostname", | 466 | 468 | "inputs", | 467 | | - "protocol", | 468 | | - "username", | 469 | 469 | "password", | 470 | | - "hostname", | 471 | | - "port", | 472 | 470 | "pathname", | | 471 | + "port", | | 472 | + "protocol", | 473 | 473 | "search", | 474 | | - "hash", | | 474 | + "username", | 475 | 475 | }; | 476 | 476 | tmpl = DictionaryTemplate::New(isolate, namesVec); | 477 | 477 | env->set_urlpatternresult_template(tmpl); | 478 | 478 | } | 479 | 479 |
| 480 | 480 | size_t index = 0; | 481 | 481 | MaybeLocal<Value> vals[] = { | | 482 | + URLPatternComponentResult::ToJSObject(env, result.hash), | | 483 | + URLPatternComponentResult::ToJSObject(env, result.hostname), | 482 | 484 | Array::New(env->context(), | 483 | 485 | result.inputs.size(), | 484 | 486 | [&index, &inputs = result.inputs, env]() { | @@ -493,14 +495,12 @@ MaybeLocal<Value> URLPattern::URLPatternResult::ToJSValue( | 493 | 495 | return URLPatternInit::ToJsObject(env, init); | 494 | 496 | } | 495 | 497 | }), | 496 | | - URLPatternComponentResult::ToJSObject(env, result.protocol), | 497 | | - URLPatternComponentResult::ToJSObject(env, result.username), | 498 | 498 | URLPatternComponentResult::ToJSObject(env, result.password), | 499 | | - URLPatternComponentResult::ToJSObject(env, result.hostname), | 500 | | - URLPatternComponentResult::ToJSObject(env, result.port), | 501 | 499 | URLPatternComponentResult::ToJSObject(env, result.pathname), | | 500 | + URLPatternComponentResult::ToJSObject(env, result.port), | | 501 | + URLPatternComponentResult::ToJSObject(env, result.protocol), | 502 | 502 | URLPatternComponentResult::ToJSObject(env, result.search), | 503 | | - URLPatternComponentResult::ToJSObject(env, result.hash)}; | | 503 | + URLPatternComponentResult::ToJSObject(env, result.username)}; | 504 | 504 | return NewDictionaryInstanceNullProto(env->context(), tmpl, vals); | 505 | 505 | } | 506 | 506 |
| |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-urlpattern.js +24Lines changed: 24 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -26,3 +26,27 @@ assert.throws(() => { | 26 | 26 | }, { | 27 | 27 | message: 'boom' | 28 | 28 | }); | | 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 | +} |
|