-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
url,lib: pass urlsearchparams-constructor.any.js #39944
url,lib: pass urlsearchparams-constructor.any.js #39944
Conversation
64340bb
to
2e3cdde
Compare
9143796
to
fe1db8f
Compare
lib/internal/url.js
Outdated
@@ -191,7 +209,7 @@ class URLSearchParams { | |||
this[searchParams] = childParams.slice(); | |||
} else if (method !== null && method !== undefined) { | |||
if (typeof method !== 'function') { | |||
throw new ERR_ARG_NOT_ITERABLE('Query pairs'); | |||
throwTypeError(new ERR_ARG_NOT_ITERABLE('Query pairs')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you look at lib/internals/errors.js
, you'll see that ERR_ARG_NOT_ITERABLE
is already a TypeError
.
lib/internal/url.js
Outdated
@@ -201,7 +219,8 @@ class URLSearchParams { | |||
if ((typeof pair !== 'object' && typeof pair !== 'function') || | |||
pair === null || | |||
typeof pair[SymbolIterator] !== 'function') { | |||
throw new ERR_INVALID_TUPLE('Each query pair', '[name, value]'); | |||
throwTypeError( | |||
new ERR_INVALID_TUPLE('Each query pair', '[name, value]')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ERR_INVALID_TUPLE
is already a TypeError
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It needs error.constructor equals to TypeError. So inheritance is not allowed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would argue that's a bug in the test harness and not our implementation.
const e = new ERR_INVALID_TUPLE('a', 'b');
console.log(e instanceof TypeError); // true
The spec text says only to throw a TypeError
, and that is what we're doing here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
our internal errors already satisfy this constraint:
> try { new URLSearchParams([1]) } catch(err) { console.log(err.constructor === TypeError) }
true
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 ways to resolve it:
- Ignore this case:
new URLSearchParams(DOMException.prototype)
; - Fix the code to pass wpt.
Both of the two ways are OK, but current code can't pass that case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was fixed in #33857
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll take a look later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But new URLSearchParams(DOMException.prototype); is thrown by DOMException.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@targos You're right. The only thing I should fix for error handling is the ERR_INVALID_THIS
in lib/internal/per_context/domexception.js
.
lib/internal/url.js
Outdated
|
||
throw new TypeError(message); // eslint-disable-line | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not the correct way of handling this. If you take a look at lib/internals/errors.js
, you'll see that some error codes have multiple types in their list... for instance ERR_INVALID_STATE
lists Error
, TypeError
, and RangeError
. To create an ERR_INVALID_STATE
error this is a TypeError
, you simply do new ERR_INVALID_STATE.TypeError("message")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The TypeError
handling in this is not correct. Haven't looked at the rest yet.
7b72a8c
to
4c101fc
Compare
I've fixed them. |
/ping @jasnell |
/ping @jasnell again :) |
/ping @jasnell |
@nodejs/url |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
/ping @jasnell |
@@ -11,6 +11,12 @@ runner.setScriptModifier((obj) => { | |||
// created via `document.createElement`. So we need to ignore them and just | |||
// test `URL`. | |||
obj.code = obj.code.replace(/\["url", "a", "area"\]/, '[ "url" ]'); | |||
} else if (obj.filename.includes('urlsearchparams-constructor.any.js')) { | |||
// Ignore test named `URLSearchParams constructor, FormData.` because we do | |||
// not have `FormData`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we decided to add FormData later someone might miss removing this. It would be worthwhile making this replacement dependent on whether FormData is undefined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. I've add typeof FormData === 'undefined'
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/ping @jasnell
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/ping @jasnell
4c101fc
to
4b8ea64
Compare
This comment has been minimized.
This comment has been minimized.
According to WPT: 1. `URLSearchParams` constructor should throw exactly `TypeError` if any Error occurrs. 2. When a record passed to `URLSearchParams` constructor, two different key may result same after `toUVString()`. We should leave only the later one.
4b8ea64
to
c2e77f2
Compare
/ping @jasnell Could you please take a minute to review this PR again? Thanks. |
/ping @jasnell |
1 similar comment
/ping @jasnell |
/ping @jasnell again. |
Hi @jasnell, would you please to review this PR again? |
/ping @jasnell |
1 similar comment
/ping @jasnell |
/ping @jasnell again |
/ping @jasnell |
According to WPT:
URLSearchParams
constructor should throw exactlyTypeError
if anyError occurrs.
URLSearchParams
constructor, two differentkey may result same after
toUVString()
. We should leave only thelater one.