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 92c86fd as of 2018-02-14
This commit was automatically generated. For any problems, please contact jackhorton

Reviewed-By: chakrabot <chakrabot@users.noreply.github.com>
  • Loading branch information
chakrabot committed Feb 14, 2018
2 parents 39dcd86 + 92c86fd commit 3785924
Show file tree
Hide file tree
Showing 44 changed files with 1,076 additions and 722 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ release.
<a href="doc/changelogs/CHANGELOG_V8.md#8.0.0">8.0.0</a><br/>
</td>
<td valign="top">
<b><a href="doc/changelogs/CHANGELOG_V6.md#6.12.3">6.12.3</a></b><br/>
<b><a href="doc/changelogs/CHANGELOG_V6.md#6.13.0">6.13.0</a></b><br/>
<a href="doc/changelogs/CHANGELOG_V6.md#6.12.3">6.12.3</a><br/>
<a href="doc/changelogs/CHANGELOG_V6.md#6.12.2">6.12.2</a><br/>
<a href="doc/changelogs/CHANGELOG_V6.md#6.12.1">6.12.1</a><br/>
<a href="doc/changelogs/CHANGELOG_V6.md#6.12.0">6.12.0</a><br/>
Expand Down
2 changes: 1 addition & 1 deletion benchmark/net/tcp-raw-c2s.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ function client(type, len) {
fail(err, 'write');
}

function afterWrite(err, handle, req) {
function afterWrite(err, handle) {
if (err)
fail(err, 'write');

Expand Down
4 changes: 2 additions & 2 deletions benchmark/net/tcp-raw-pipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function main({ dur, len, type }) {
if (err)
fail(err, 'write');

writeReq.oncomplete = function(status, handle, req, err) {
writeReq.oncomplete = function(status, handle, err) {
if (err)
fail(err, 'write');
};
Expand Down Expand Up @@ -130,7 +130,7 @@ function main({ dur, len, type }) {
fail(err, 'write');
}

function afterWrite(err, handle, req) {
function afterWrite(err, handle) {
if (err)
fail(err, 'write');

Expand Down
8 changes: 4 additions & 4 deletions benchmark/net/tcp-raw-s2c.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ function main({ dur, len, type }) {
fail(err, 'write');
} else if (!writeReq.async) {
process.nextTick(function() {
afterWrite(null, clientHandle, writeReq);
afterWrite(0, clientHandle);
});
}
}

function afterWrite(status, handle, req, err) {
if (err)
fail(err, 'write');
function afterWrite(status, handle) {
if (status)
fail(status, 'write');

while (clientHandle.writeQueueSize === 0)
write();
Expand Down
16 changes: 12 additions & 4 deletions doc/api/esm.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,22 @@ The resolve hook returns the resolved file URL and module format for a
given module specifier and parent file URL:

```js
import url from 'url';
const baseURL = new URL('file://');
baseURL.pathname = process.cwd() + '/';

export async function resolve(specifier, parentModuleURL, defaultResolver) {
export async function resolve(specifier,
parentModuleURL = baseURL,
defaultResolver) {
return {
url: new URL(specifier, parentModuleURL).href,
format: 'esm'
};
}
```

The default NodeJS ES module resolution function is provided as a third
The parentURL is provided as `undefined` when performing main Node.js load itself.

The default Node.js ES module resolution function is provided as a third
argument to the resolver for easy compatibility workflows.

In addition to returning the resolved file URL value, the resolve hook also
Expand Down Expand Up @@ -155,7 +160,10 @@ import Module from 'module';
const builtins = Module.builtinModules;
const JS_EXTENSIONS = new Set(['.js', '.mjs']);

export function resolve(specifier, parentModuleURL/*, defaultResolve */) {
const baseURL = new URL('file://');
baseURL.pathname = process.cwd() + '/';

export function resolve(specifier, parentModuleURL = baseURL, defaultResolve) {
if (builtins.includes(specifier)) {
return {
url: specifier,
Expand Down
165 changes: 162 additions & 3 deletions doc/changelogs/CHANGELOG_V6.md

Large diffs are not rendered by default.

92 changes: 32 additions & 60 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,20 @@ function copyObject(source) {
return target;
}

function handleErrorFromBinding(ctx) {
if (ctx.errno !== undefined) { // libuv error numbers
const err = errors.uvException(ctx);
Error.captureStackTrace(err, handleErrorFromBinding);
throw err;
} else if (ctx.error !== undefined) { // errors created in C++ land.
// TODO(joyeecheung): currently, ctx.error are encoding errors
// usually caused by memory problems. We need to figure out proper error
// code(s) for this.
Error.captureStackTrace(ctx.error, handleErrorFromBinding);
throw ctx.error;
}
}

// TODO(joyeecheung): explore how the deprecation could be solved via linting
// rules. See https://github.com/nodejs/node/pull/12976
function rethrow() {
Expand Down Expand Up @@ -405,10 +419,7 @@ fs.accessSync = function(path, mode) {

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

if (ctx.errno !== undefined) {
throw errors.uvException(ctx);
}
handleErrorFromBinding(ctx);
};

// fs.exists never throws even when the arguments are invalid - if there is
Expand Down Expand Up @@ -742,9 +753,7 @@ fs.closeSync = function(fd) {

const ctx = {};
binding.close(fd, undefined, ctx);
if (ctx.errno !== undefined) {
throw errors.uvException(ctx);
}
handleErrorFromBinding(ctx);
};

function modeNum(m, def) {
Expand Down Expand Up @@ -924,9 +933,7 @@ fs.renameSync = function(oldPath, newPath) {
const ctx = { path: oldPath, dest: newPath };
binding.rename(pathModule.toNamespacedPath(oldPath),
pathModule.toNamespacedPath(newPath), undefined, ctx);
if (ctx.errno !== undefined) {
throw errors.uvException(ctx);
}
handleErrorFromBinding(ctx);
};

fs.truncate = function(path, len, callback) {
Expand Down Expand Up @@ -994,9 +1001,7 @@ fs.ftruncateSync = function(fd, len = 0) {
len = Math.max(0, len);
const ctx = {};
binding.ftruncate(fd, len, undefined, ctx);
if (ctx.errno !== undefined) {
throw errors.uvException(ctx);
}
handleErrorFromBinding(ctx);
};

fs.rmdir = function(path, callback) {
Expand Down Expand Up @@ -1025,9 +1030,7 @@ fs.fdatasyncSync = function(fd) {
validateUint32(fd, 'fd');
const ctx = {};
binding.fdatasync(fd, undefined, ctx);
if (ctx.errno !== undefined) {
throw errors.uvException(ctx);
}
handleErrorFromBinding(ctx);
};

fs.fsync = function(fd, callback) {
Expand All @@ -1041,9 +1044,7 @@ fs.fsyncSync = function(fd) {
validateUint32(fd, 'fd');
const ctx = {};
binding.fsync(fd, undefined, ctx);
if (ctx.errno !== undefined) {
throw errors.uvException(ctx);
}
handleErrorFromBinding(ctx);
};

fs.mkdir = function(path, mode, callback) {
Expand Down Expand Up @@ -1114,9 +1115,7 @@ fs.fstatSync = function(fd) {
validateUint32(fd, 'fd');
const ctx = { fd };
binding.fstat(fd, undefined, ctx);
if (ctx.errno !== undefined) {
throw errors.uvException(ctx);
}
handleErrorFromBinding(ctx);
return statsFromValues();
};

Expand All @@ -1125,9 +1124,7 @@ fs.lstatSync = function(path) {
validatePath(path);
const ctx = { path };
binding.lstat(pathModule.toNamespacedPath(path), undefined, ctx);
if (ctx.errno !== undefined) {
throw errors.uvException(ctx);
}
handleErrorFromBinding(ctx);
return statsFromValues();
};

Expand All @@ -1136,9 +1133,7 @@ fs.statSync = function(path) {
validatePath(path);
const ctx = { path };
binding.stat(pathModule.toNamespacedPath(path), undefined, ctx);
if (ctx.errno !== undefined) {
throw errors.uvException(ctx);
}
handleErrorFromBinding(ctx);
return statsFromValues();
};

Expand All @@ -1159,14 +1154,7 @@ fs.readlinkSync = function(path, options) {
const ctx = { path };
const result = binding.readlink(pathModule.toNamespacedPath(path),
options.encoding, undefined, ctx);
if (ctx.errno !== undefined) {
throw errors.uvException(ctx);
} else if (ctx.error) {
// TODO(joyeecheung): this is an encoding error usually caused by memory
// problems. We need to figure out proper error code(s) for this.
Error.captureStackTrace(ctx.error);
throw ctx.error;
}
handleErrorFromBinding(ctx);
return result;
};

Expand Down Expand Up @@ -1235,9 +1223,7 @@ fs.symlinkSync = function(target, path, type) {
binding.symlink(preprocessSymlinkDestination(target, type, path),
pathModule.toNamespacedPath(path), flags, undefined, ctx);

if (ctx.errno !== undefined) {
throw errors.uvException(ctx);
}
handleErrorFromBinding(ctx);
};

fs.link = function(existingPath, newPath, callback) {
Expand Down Expand Up @@ -1266,9 +1252,7 @@ fs.linkSync = function(existingPath, newPath) {
const result = binding.link(pathModule.toNamespacedPath(existingPath),
pathModule.toNamespacedPath(newPath),
undefined, ctx);
if (ctx.errno !== undefined) {
throw errors.uvException(ctx);
}
handleErrorFromBinding(ctx);
return result;
};

Expand All @@ -1286,9 +1270,7 @@ fs.unlinkSync = function(path) {
validatePath(path);
const ctx = { path };
binding.unlink(pathModule.toNamespacedPath(path), undefined, ctx);
if (ctx.errno !== undefined) {
throw errors.uvException(ctx);
}
handleErrorFromBinding(ctx);
};

fs.fchmod = function(fd, mode, callback) {
Expand Down Expand Up @@ -1887,9 +1869,7 @@ fs.realpathSync = function realpathSync(p, options) {
if (isWindows && !knownHard[base]) {
const ctx = { path: base };
binding.lstat(pathModule.toNamespacedPath(base), undefined, ctx);
if (ctx.errno !== undefined) {
throw errors.uvException(ctx);
}
handleErrorFromBinding(ctx);
knownHard[base] = true;
}

Expand Down Expand Up @@ -1931,9 +1911,7 @@ fs.realpathSync = function realpathSync(p, options) {
var baseLong = pathModule.toNamespacedPath(base);
const ctx = { path: base };
binding.lstat(baseLong, undefined, ctx);
if (ctx.errno !== undefined) {
throw errors.uvException(ctx);
}
handleErrorFromBinding(ctx);

if ((statValues[1/*mode*/] & S_IFMT) !== S_IFLNK) {
knownHard[base] = true;
Expand All @@ -1956,13 +1934,9 @@ fs.realpathSync = function realpathSync(p, options) {
if (linkTarget === null) {
const ctx = { path: base };
binding.stat(baseLong, undefined, ctx);
if (ctx.errno !== undefined) {
throw errors.uvException(ctx);
}
handleErrorFromBinding(ctx);
linkTarget = binding.readlink(baseLong, undefined, undefined, ctx);
if (ctx.errno !== undefined) {
throw errors.uvException(ctx);
}
handleErrorFromBinding(ctx);
}
resolvedLink = pathModule.resolve(previous, linkTarget);

Expand All @@ -1981,9 +1955,7 @@ fs.realpathSync = function realpathSync(p, options) {
if (isWindows && !knownHard[base]) {
const ctx = { path: base };
binding.lstat(pathModule.toNamespacedPath(base), undefined, ctx);
if (ctx.errno !== undefined) {
throw errors.uvException(ctx);
}
handleErrorFromBinding(ctx);
knownHard[base] = true;
}
}
Expand Down
9 changes: 4 additions & 5 deletions lib/internal/http2/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1399,20 +1399,19 @@ function trackWriteState(stream, bytes) {
session[kHandle].chunksSentSinceLastWrite = 0;
}

function afterDoStreamWrite(status, handle, req) {
function afterDoStreamWrite(status, handle) {
const stream = handle[kOwner];
const session = stream[kSession];

stream[kUpdateTimer]();

const { bytes } = req;
const { bytes } = this;
stream[kState].writeQueueSize -= bytes;

if (session !== undefined)
session[kState].writeQueueSize -= bytes;
if (typeof req.callback === 'function')
req.callback(null);
req.handle = undefined;
if (typeof this.callback === 'function')
this.callback(null);
}

function streamOnResume() {
Expand Down
21 changes: 16 additions & 5 deletions lib/internal/loader/DefaultResolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const { URL } = require('url');
const CJSmodule = require('module');
const internalURLModule = require('internal/url');
const internalFS = require('internal/fs');
const NativeModule = require('native_module');
const { extname } = require('path');
Expand All @@ -11,6 +10,7 @@ const preserveSymlinks = !!process.binding('config').preserveSymlinks;
const errors = require('internal/errors');
const { resolve: moduleWrapResolve } = internalBinding('module_wrap');
const StringStartsWith = Function.call.bind(String.prototype.startsWith);
const { getURLFromFilePath, getPathFromURL } = require('internal/url');

const realpathCache = new Map();

Expand Down Expand Up @@ -57,7 +57,8 @@ function resolve(specifier, parentURL) {

let url;
try {
url = search(specifier, parentURL);
url = search(specifier,
parentURL || getURLFromFilePath(`${process.cwd()}/`).href);
} catch (e) {
if (typeof e.message === 'string' &&
StringStartsWith(e.message, 'Cannot find module'))
Expand All @@ -66,17 +67,27 @@ function resolve(specifier, parentURL) {
}

if (!preserveSymlinks) {
const real = realpathSync(internalURLModule.getPathFromURL(url), {
const real = realpathSync(getPathFromURL(url), {
[internalFS.realpathCacheKey]: realpathCache
});
const old = url;
url = internalURLModule.getURLFromFilePath(real);
url = getURLFromFilePath(real);
url.search = old.search;
url.hash = old.hash;
}

const ext = extname(url.pathname);
return { url: `${url}`, format: extensionFormatMap[ext] || ext };

let format = extensionFormatMap[ext];
if (!format) {
const isMain = parentURL === undefined;
if (isMain)
format = 'cjs';
else
throw new errors.Error('ERR_UNKNOWN_FILE_EXTENSION', url.pathname);
}

return { url: `${url}`, format };
}

module.exports = resolve;
Expand Down
Loading

0 comments on commit 3785924

Please sign in to comment.