GeezerVison is showing github.com — url,lib: pass urlsearchparams-constructor.any.js · nodejs/node@01ad8de
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: lib/internal/per_context/domexception.js +24-9Lines changed: 24 additions & 9 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -10,12 +10,27 @@ const { | 10 | 10 | TypeError, | 11 | 11 | } = primordials; | 12 | 12 |
| 13 | | -class ERR_INVALID_THIS extends TypeError { | 14 | | - constructor(type) { | 15 | | - super('Value of "this" must be of ' + type); | 16 | | - } | 17 | | - | 18 | | - get code() { return 'ERR_INVALID_THIS'; } | | 13 | +function throwInvalidThisError(Base, type) { | | 14 | + const err = new Base(); | | 15 | + const key = 'ERR_INVALID_THIS'; | | 16 | + ObjectDefineProperties(err, { | | 17 | + message: { | | 18 | + value: `Value of "this" must be of ${type}`, | | 19 | + enumerable: false, | | 20 | + writable: true, | | 21 | + configurable: true, | | 22 | + }, | | 23 | + toString: { | | 24 | + value() { | | 25 | + return `${this.name} [${key}]: ${this.message}`; | | 26 | + }, | | 27 | + enumerable: false, | | 28 | + writable: true, | | 29 | + configurable: true, | | 30 | + }, | | 31 | + }); | | 32 | + err.code = key; | | 33 | + throw err; | 19 | 34 | } | 20 | 35 |
| 21 | 36 | let internalsMap; | @@ -51,7 +66,7 @@ class DOMException extends Error { | 51 | 66 | ensureInitialized(); | 52 | 67 | const internals = internalsMap.get(this); | 53 | 68 | if (internals === undefined) { | 54 | | - throw new ERR_INVALID_THIS('DOMException'); | | 69 | + throwInvalidThisError(TypeError, 'DOMException'); | 55 | 70 | } | 56 | 71 | return internals.name; | 57 | 72 | } | @@ -60,7 +75,7 @@ class DOMException extends Error { | 60 | 75 | ensureInitialized(); | 61 | 76 | const internals = internalsMap.get(this); | 62 | 77 | if (internals === undefined) { | 63 | | - throw new ERR_INVALID_THIS('DOMException'); | | 78 | + throwInvalidThisError(TypeError, 'DOMException'); | 64 | 79 | } | 65 | 80 | return internals.message; | 66 | 81 | } | @@ -69,7 +84,7 @@ class DOMException extends Error { | 69 | 84 | ensureInitialized(); | 70 | 85 | const internals = internalsMap.get(this); | 71 | 86 | if (internals === undefined) { | 72 | | - throw new ERR_INVALID_THIS('DOMException'); | | 87 | + throwInvalidThisError(TypeError, 'DOMException'); | 73 | 88 | } | 74 | 89 | const code = nameToCodeMap.get(internals.name); | 75 | 90 | return code === undefined ? 0 : code; | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/url.js +11-1Lines changed: 11 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -219,6 +219,7 @@ class URLSearchParams { | 219 | 219 | } else { | 220 | 220 | // Record<USVString, USVString> | 221 | 221 | // Need to use reflection APIs for full spec compliance. | | 222 | + const visited = {}; | 222 | 223 | this[searchParams] = []; | 223 | 224 | const keys = ReflectOwnKeys(init); | 224 | 225 | for (let i = 0; i < keys.length; i++) { | @@ -227,7 +228,16 @@ class URLSearchParams { | 227 | 228 | if (desc !== undefined && desc.enumerable) { | 228 | 229 | const typedKey = toUSVString(key); | 229 | 230 | const typedValue = toUSVString(init[key]); | 230 | | - this[searchParams].push(typedKey, typedValue); | | 231 | + | | 232 | + // Two different key may result same after `toUSVString()`, we only | | 233 | + // leave the later one. Refers to WPT. | | 234 | + if (visited[typedKey] !== undefined) { | | 235 | + this[searchParams][visited[typedKey]] = typedValue; | | 236 | + } else { | | 237 | + visited[typedKey] = ArrayPrototypePush(this[searchParams], | | 238 | + typedKey, | | 239 | + typedValue) - 1; | | 240 | + } | 231 | 241 | } | 232 | 242 | } | 233 | 243 | } | |
Collapse file Copy file name to clipboardExpand all lines: test/wpt/status/url.json -3Lines changed: 0 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 12 | 12 | "urlencoded-parser.any.js": { | 13 | 13 | "fail": "missing Request and Response" | 14 | 14 | }, | 15 | | - "urlsearchparams-constructor.any.js": { | 16 | | - "fail": "FormData is not defined" | 17 | | - }, | 18 | 15 | "url-constructor.any.js": { | 19 | 16 | "requires": ["small-icu"] | 20 | 17 | }, | |
Collapse file Copy file name to clipboardExpand all lines: test/wpt/test-url.js +9Lines changed: 9 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -11,6 +11,15 @@ runner.setScriptModifier((obj) => { | 11 | 11 | // created via `document.createElement`. So we need to ignore them and just | 12 | 12 | // test `URL`. | 13 | 13 | obj.code = obj.code.replace(/\["url", "a", "area"\]/, '[ "url" ]'); | | 14 | + } else if (typeof FormData === 'undefined' && // eslint-disable-line | | 15 | + obj.filename.includes('urlsearchparams-constructor.any.js')) { | | 16 | + // TODO(XadillaX): Remove this `else if` after `FormData` is supported. | | 17 | + | | 18 | + // Ignore test named `URLSearchParams constructor, FormData.` because we do | | 19 | + // not have `FormData`. | | 20 | + obj.code = obj.code.replace( | | 21 | + /('URLSearchParams constructor, object\.'\);[\w\W]+)test\(function\(\) {[\w\W]*?}, 'URLSearchParams constructor, FormData\.'\);/, | | 22 | + '$1'); | 14 | 23 | } | 15 | 24 | }); | 16 | 25 | runner.pretendGlobalThisAs('Window'); | |
|