Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
TimothyGu committed Apr 25, 2017
1 parent 71a31ff commit b43cdee
Show file tree
Hide file tree
Showing 15 changed files with 32 additions and 34 deletions.
11 changes: 4 additions & 7 deletions doc/api/errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -602,10 +602,7 @@ semantics for determining whether a path can be used is platform-dependent.
### ERR_INVALID_THIS

The `'ERR_INVALID_THIS'` error code is used generically to identify that a
Node.js API function is called with an incompatible `this` value. Its use is
currently limited to the [WHATWG URL API][] to satisfy specification
requirements, but may be expanded to other areas of the Node.js API in the
future.
Node.js API function is called with an incompatible `this` value.

Example:

Expand All @@ -623,9 +620,9 @@ urlSearchParams.has.call(buf, 'foo');

An error with code `'ERR_INVALID_TUPLE'` is thrown when an element in the
`iterable` provided to the [WHATWG][WHATWG URL API] [`URLSearchParams`
constructor][`new URLSearchParams(iterable)`] does not represent a name/value
tuple -- that is, if an element is not iterable, or does not consist of exactly
two elements.
constructor][`new URLSearchParams(iterable)`] does not represent a `[name,
value]` tuple that is, if an element is not iterable, or does not consist of
exactly two elements.

<a id="ERR_INVALID_URL"></a>
### ERR_INVALID_URL
Expand Down
9 changes: 4 additions & 5 deletions lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,11 @@ E('ERR_ARG_NOT_ITERABLE', '%s must be iterable');
E('ERR_ASSERTION', (msg) => msg);
E('ERR_INVALID_ARG_TYPE', invalidArgType);
E('ERR_INVALID_CALLBACK', 'callback must be a function');
E('ERR_INVALID_FILE_URL_HOST', 'File URL host must %s');
E('ERR_INVALID_FILE_URL_PATH', 'File URL path must %s');
E('ERR_INVALID_THIS', 'Value of this must be of type %s');
E('ERR_INVALID_FILE_URL_HOST', 'File URL host %s');
E('ERR_INVALID_FILE_URL_PATH', 'File URL path %s');
E('ERR_INVALID_THIS', 'Value of "this" must be of type %s');
E('ERR_INVALID_TUPLE', '%s must be an iterable %s tuple');
E('ERR_INVALID_URL',
(input) => `Invalid URL${input !== undefined ? `: ${input}` : ''}`);
E('ERR_INVALID_URL', 'Invalid URL: %s');
E('ERR_INVALID_URL_SCHEME',
(expected) => `The URL must be ${oneOf(expected, 'scheme')}`);
E('ERR_MISSING_ARGS', missingArgs);
Expand Down
16 changes: 9 additions & 7 deletions lib/internal/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ class URLSearchParams {
if (typeof pair !== 'object' ||
typeof pair[Symbol.iterator] !== 'function') {
throw new errors.TypeError('ERR_INVALID_TUPLE', 'Each query pair',
'name/value');
'[name, value]');
}
pairs.push(Array.from(pair));
}
Expand All @@ -830,7 +830,7 @@ class URLSearchParams {
for (const pair of pairs) {
if (pair.length !== 2) {
throw new errors.TypeError('ERR_INVALID_TUPLE', 'Each query pair',
'name/value');
'[name, value]');
}
const key = toUSVString(pair[0]);
const value = toUSVString(pair[1]);
Expand Down Expand Up @@ -1302,8 +1302,9 @@ function getPathFromURLWin32(url) {
var third = pathname.codePointAt(n + 2) | 0x20;
if ((pathname[n + 1] === '2' && third === 102) || // 2f 2F /
(pathname[n + 1] === '5' && third === 99)) { // 5c 5C \
return new errors.TypeError('ERR_INVALID_FILE_URL_PATH',
'not include encoded \\ or / characters');
return new errors.TypeError(
'ERR_INVALID_FILE_URL_PATH',
'must not include encoded \\ or / characters');
}
}
}
Expand All @@ -1322,7 +1323,8 @@ function getPathFromURLWin32(url) {
var sep = pathname[2];
if (letter < 97 || letter > 122 || // a..z A..Z
(sep !== ':')) {
return new errors.TypeError('ERR_INVALID_FILE_URL_PATH', 'be absolute');
return new errors.TypeError('ERR_INVALID_FILE_URL_PATH',
'must be absolute');
}
return pathname.slice(1);
}
Expand All @@ -1331,15 +1333,15 @@ function getPathFromURLWin32(url) {
function getPathFromURLPosix(url) {
if (url.hostname !== '') {
return new errors.TypeError('ERR_INVALID_FILE_URL_HOST',
`be "localhost" or empty on ${platform}`);
`must be "localhost" or empty on ${platform}`);
}
var pathname = url.pathname;
for (var n = 0; n < pathname.length; n++) {
if (pathname[n] === '%') {
var third = pathname.codePointAt(n + 2) | 0x20;
if (pathname[n + 1] === '2' && third === 102) {
return new errors.TypeError('ERR_INVALID_FILE_URL_PATH',
'not include encoded / characters');
'must not include encoded / characters');
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-whatwg-url-searchparams-append.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ test(function() {
}, common.expectsError({
code: 'ERR_INVALID_THIS',
type: TypeError,
message: 'Value of this must be of type URLSearchParams'
message: 'Value of "this" must be of type URLSearchParams'
}));
assert.throws(() => {
params.append('a');
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-whatwg-url-searchparams-constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ test(() => {
const tupleError = common.expectsError({
code: 'ERR_INVALID_TUPLE',
type: TypeError,
message: 'Each query pair must be an iterable name/value tuple'
message: 'Each query pair must be an iterable [name, value] tuple'
});

let params;
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-whatwg-url-searchparams-delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ test(function() {
}, common.expectsError({
code: 'ERR_INVALID_THIS',
type: TypeError,
message: 'Value of this must be of type URLSearchParams'
message: 'Value of "this" must be of type URLSearchParams'
}));
assert.throws(() => {
params.delete();
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-whatwg-url-searchparams-entries.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ assert.throws(() => {
}, common.expectsError({
code: 'ERR_INVALID_THIS',
type: TypeError,
message: 'Value of this must be of type URLSearchParamsIterator'
message: 'Value of "this" must be of type URLSearchParamsIterator'
}));
assert.throws(() => {
params.entries.call(undefined);
}, common.expectsError({
code: 'ERR_INVALID_THIS',
type: TypeError,
message: 'Value of this must be of type URLSearchParams'
message: 'Value of "this" must be of type URLSearchParams'
}));
2 changes: 1 addition & 1 deletion test/parallel/test-whatwg-url-searchparams-foreach.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ test(function() {
}, common.expectsError({
code: 'ERR_INVALID_THIS',
type: TypeError,
message: 'Value of this must be of type URLSearchParams'
message: 'Value of "this" must be of type URLSearchParams'
}));
}
2 changes: 1 addition & 1 deletion test/parallel/test-whatwg-url-searchparams-get.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ test(function() {
}, common.expectsError({
code: 'ERR_INVALID_THIS',
type: TypeError,
message: 'Value of this must be of type URLSearchParams'
message: 'Value of "this" must be of type URLSearchParams'
}));
assert.throws(() => {
params.get();
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-whatwg-url-searchparams-getall.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ test(function() {
}, common.expectsError({
code: 'ERR_INVALID_THIS',
type: TypeError,
message: 'Value of this must be of type URLSearchParams'
message: 'Value of "this" must be of type URLSearchParams'
}));
assert.throws(() => {
params.getAll();
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-whatwg-url-searchparams-has.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ test(function() {
}, common.expectsError({
code: 'ERR_INVALID_THIS',
type: TypeError,
message: 'Value of this must be of type URLSearchParams'
message: 'Value of "this" must be of type URLSearchParams'
}));
assert.throws(() => {
params.has();
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-whatwg-url-searchparams-keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ assert.throws(() => {
}, common.expectsError({
code: 'ERR_INVALID_THIS',
type: TypeError,
message: 'Value of this must be of type URLSearchParamsIterator'
message: 'Value of "this" must be of type URLSearchParamsIterator'
}));
assert.throws(() => {
params.keys.call(undefined);
}, common.expectsError({
code: 'ERR_INVALID_THIS',
type: TypeError,
message: 'Value of this must be of type URLSearchParams'
message: 'Value of "this" must be of type URLSearchParams'
}));
2 changes: 1 addition & 1 deletion test/parallel/test-whatwg-url-searchparams-set.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ test(function() {
}, common.expectsError({
code: 'ERR_INVALID_THIS',
type: TypeError,
message: 'Value of this must be of type URLSearchParams'
message: 'Value of "this" must be of type URLSearchParams'
}));
assert.throws(() => {
params.set('a');
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-whatwg-url-searchparams-stringifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,6 @@ test(function() {
}, common.expectsError({
code: 'ERR_INVALID_THIS',
type: TypeError,
message: 'Value of this must be of type URLSearchParams'
message: 'Value of "this" must be of type URLSearchParams'
}));
}
4 changes: 2 additions & 2 deletions test/parallel/test-whatwg-url-searchparams-values.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ assert.throws(() => {
}, common.expectsError({
code: 'ERR_INVALID_THIS',
type: TypeError,
message: 'Value of this must be of type URLSearchParamsIterator'
message: 'Value of "this" must be of type URLSearchParamsIterator'
}));
assert.throws(() => {
params.values.call(undefined);
}, common.expectsError({
code: 'ERR_INVALID_THIS',
type: TypeError,
message: 'Value of this must be of type URLSearchParams'
message: 'Value of "this" must be of type URLSearchParams'
}));

0 comments on commit b43cdee

Please sign in to comment.