Skip to content
This repository has been archived by the owner on Oct 15, 2020. It is now read-only.

Commit

Permalink
meta: merge node/master into node-chakracore/master
Browse files Browse the repository at this point in the history
Merge 29423b4 as of 2017-11-25
This commit was automatically generated. For any problems, please contact jackhorton

Reviewed-By: chakrabot <chakrabot@users.noreply.github.com>
  • Loading branch information
chakrabot committed Dec 5, 2017
2 parents 4316cb7 + 29423b4 commit 3a6b048
Show file tree
Hide file tree
Showing 15 changed files with 318 additions and 284 deletions.
2 changes: 1 addition & 1 deletion doc/api/url.md
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,7 @@ changes:
The `url.format()` method returns a formatted URL string derived from
`urlObject`.

If `urlObject` is not an object or a string, `url.parse()` will throw a
If `urlObject` is not an object or a string, `url.format()` will throw a
[`TypeError`][].

The formatting process operates as follows:
Expand Down
3 changes: 2 additions & 1 deletion doc/onboarding-extras.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
| `bootstrap_node.js` | @fishrock123 |
| `doc/*`, `*.md` | @nodejs/documentation |
| `lib/assert` | @nodejs/testing |
| `lib/async_hooks` | @nodejs/async\_hooks for bugs/reviews (+ @nodejs/diagnostics for API) |
| `lib/buffer` | @nodejs/buffer |
| `lib/child_process` | @bnoordhuis, @cjihrig |
| `lib/cluster` | @bnoordhuis, @cjihrig, @mcollina |
Expand All @@ -29,8 +30,8 @@
| `src/node_crypto.*` | @nodejs/crypto |
| `test/*` | @nodejs/testing |
| `tools/eslint`, `.eslintrc` | @not-an-aardvark, @silverwind, @trott |
| async\_hooks | @nodejs/async\_hooks for bugs/reviews (+ @nodejs/diagnostics for API) |
| build | @nodejs/build |
| ES Modules | @bmeck, @Fishrock123, @guybedford, @MylesBorins, @targos |
| GYP | @nodejs/gyp |
| performance | @nodejs/performance |
| platform specific | @nodejs/platform-{aix,arm,freebsd,macos,ppc,smartos,s390,windows} |
Expand Down
18 changes: 17 additions & 1 deletion lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,11 @@ fs.access = function(path, mode, callback) {
if (handleError((path = getPathFromURL(path)), callback))
return;

if (typeof path !== 'string' && !(path instanceof Buffer)) {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'path',
['string', 'Buffer', 'URL']);
}

if (!nullCheck(path, callback))
return;

Expand All @@ -308,14 +313,25 @@ fs.access = function(path, mode, callback) {

fs.accessSync = function(path, mode) {
handleError((path = getPathFromURL(path)));

if (typeof path !== 'string' && !(path instanceof Buffer)) {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'path',
['string', 'Buffer', 'URL']);
}

nullCheck(path);

if (mode === undefined)
mode = fs.F_OK;
else
mode = mode | 0;

binding.access(pathModule.toNamespacedPath(path), mode);
const ctx = {};
binding.access(pathModule.toNamespacedPath(path), mode, undefined, ctx);

if (ctx.code !== undefined) {
throw new errors.uvException(ctx);
}
};

fs.exists = function(path, callback) {
Expand Down
42 changes: 42 additions & 0 deletions lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,49 @@ function E(sym, val) {
messages.set(sym, typeof val === 'function' ? val : String(val));
}

// JS counterpart of StringFromPath, although here path is a buffer.
function stringFromPath(path) {
const str = path.toString();
if (process.platform !== 'win32') {
return str;
}

if (str.startsWith('\\\\?\\UNC\\')) {
return '\\\\' + str.slice(8);
} else if (str.startsWith('\\\\?\\')) {
return str.slice(4);
}
return str;
}

// This creates an error compatible with errors produced in UVException
// using the context collected in CollectUVExceptionInfo
// The goal is to migrate them to ERR_* errors later when
// compatibility is not a concern
function uvException(ctx) {
const err = new Error();
err.errno = ctx.errno;
err.code = ctx.code;
err.syscall = ctx.syscall;

let message = `${ctx.code}: ${ctx.message}, ${ctx.syscall}`;
if (ctx.path) {
const path = stringFromPath(ctx.path);
message += ` '${path}'`;
err.path = path;
}
if (ctx.dest) {
const dest = stringFromPath(ctx.dest);
message += ` -> '${dest}'`;
err.dest = dest;
}
err.message = message;
Error.captureStackTrace(err, uvException);
return err;
}

module.exports = exports = {
uvException,
message,
Error: makeNodeError(Error),
TypeError: makeNodeError(TypeError),
Expand Down
Loading

0 comments on commit 3a6b048

Please sign in to comment.