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 a322b8e as of 2017-12-04
This commit was automatically generated. For any problems, please contact jackhorton

Reviewed-By: Taylor Woll <[email protected]>
  • Loading branch information
chakrabot committed Dec 7, 2017
2 parents 4a19a9b + a322b8e commit 40a2c90
Show file tree
Hide file tree
Showing 18 changed files with 167 additions and 106 deletions.
25 changes: 13 additions & 12 deletions doc/api/console.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,19 @@ Defaults to `2`. To make it recurse indefinitely, pass `null`.
Defaults to `false`. Colors are customizable; see
[customizing `util.inspect()` colors][].

### console.dirxml(...data)
<!-- YAML
added: v8.0.0
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/17152
description: "`console.dirxml` now calls `console.log` for its arguments."
-->
* `...data` {any}

This method calls `console.log()` passing it the arguments received.
Please note that this method does not produce any XML formatting.

### console.error([data][, ...args])
<!-- YAML
added: v0.1.100
Expand Down Expand Up @@ -435,18 +448,6 @@ The following methods are exposed by the V8 engine in the general API but do
not display anything unless used in conjunction with the [inspector][]
(`--inspect` flag).

### console.dirxml(object)
<!-- YAML
added: v8.0.0
-->
* `object` {string}

This method does not display anything unless used in the inspector. The
`console.dirxml()` method displays in `stdout` an XML interactive tree
representation of the descendants of the specified `object` if possible, or the
JavaScript representation if not. Calling `console.dirxml()` on an HTML or XML
element is equivalent to calling `console.log()`.

### console.markTimeline(label)
<!-- YAML
added: v8.0.0
Expand Down
3 changes: 3 additions & 0 deletions lib/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ Console.prototype.dir = function dir(object, options) {
};


Console.prototype.dirxml = Console.prototype.log;


Console.prototype.time = function time(label = 'default') {
// Coerces everything other than Symbol to a string
label = `${label}`;
Expand Down
51 changes: 46 additions & 5 deletions lib/domain.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ const EventEmitter = require('events');
const errors = require('internal/errors');
const { createHook } = require('async_hooks');

// communicate with events module, but don't require that
// module to have to load this one, since this module has
// a few side effects.
EventEmitter.usingDomains = true;

// overwrite process.domain with a getter/setter that will allow for more
// effective optimizations
var _domain = [null];
Expand Down Expand Up @@ -387,3 +382,49 @@ Domain.prototype.bind = function(cb) {

return runBound;
};

// Override EventEmitter methods to make it domain-aware.
EventEmitter.usingDomains = true;

const eventInit = EventEmitter.init;
EventEmitter.init = function() {
this.domain = null;
if (exports.active && !(this instanceof exports.Domain)) {
this.domain = exports.active;
}

return eventInit.call(this);
};

const eventEmit = EventEmitter.prototype.emit;
EventEmitter.prototype.emit = function emit(...args) {
const domain = this.domain;
if (domain === null || domain === undefined || this === process) {
return eventEmit.apply(this, args);
}

const type = args[0];
// edge case: if there is a domain and an existing non error object is given,
// it should not be errorized
// see test/parallel/test-event-emitter-no-error-provided-to-error-event.js
if (type === 'error' && args.length > 1 && args[1] &&
!(args[1] instanceof Error)) {
domain.emit('error', args[1]);
return false;
}

domain.enter();
try {
return eventEmit.apply(this, args);
} catch (er) {
if (typeof er === 'object' && er !== null) {
er.domainEmitter = this;
er.domain = domain;
er.domainThrown = false;
}
domain.emit('error', er);
return false;
} finally {
domain.exit();
}
};
48 changes: 6 additions & 42 deletions lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

'use strict';

var domain;
var spliceOne;

function EventEmitter() {
Expand All @@ -32,9 +31,6 @@ module.exports = EventEmitter;
// Backwards-compat with node 0.10.x
EventEmitter.EventEmitter = EventEmitter;

EventEmitter.usingDomains = false;

EventEmitter.prototype.domain = undefined;
EventEmitter.prototype._events = undefined;
EventEmitter.prototype._maxListeners = undefined;

Expand Down Expand Up @@ -66,14 +62,6 @@ Object.defineProperty(EventEmitter, 'defaultMaxListeners', {
});

EventEmitter.init = function() {
this.domain = null;
if (EventEmitter.usingDomains) {
// if there is an active domain, then attach to it.
domain = domain || require('domain');
if (domain.active && !(this instanceof domain.Domain)) {
this.domain = domain.active;
}
}

if (this._events === undefined ||
this._events === Object.getPrototypeOf(this)._events) {
Expand Down Expand Up @@ -114,47 +102,26 @@ EventEmitter.prototype.emit = function emit(type, ...args) {
else if (!doError)
return false;

const domain = this.domain;

// If there is no 'error' event listener then throw.
if (doError) {
let er;
if (args.length > 0)
er = args[0];
if (domain !== null && domain !== undefined) {
if (!er) {
const errors = lazyErrors();
er = new errors.Error('ERR_UNHANDLED_ERROR');
}
if (typeof er === 'object' && er !== null) {
er.domainEmitter = this;
er.domain = domain;
er.domainThrown = false;
}
domain.emit('error', er);
} else if (er instanceof Error) {
if (er instanceof Error) {
throw er; // Unhandled 'error' event
} else {
// At least give some kind of context to the user
const errors = lazyErrors();
const err = new errors.Error('ERR_UNHANDLED_ERROR', er);
err.context = er;
throw err;
}
return false;
// At least give some kind of context to the user
const errors = lazyErrors();
const err = new errors.Error('ERR_UNHANDLED_ERROR', er);
err.context = er;
throw err;
}

const handler = events[type];

if (handler === undefined)
return false;

let needDomainExit = false;
if (domain !== null && domain !== undefined && this !== process) {
domain.enter();
needDomainExit = true;
}

if (typeof handler === 'function') {
handler.apply(this, args);
} else {
Expand All @@ -164,9 +131,6 @@ EventEmitter.prototype.emit = function emit(type, ...args) {
listeners[i].apply(this, args);
}

if (needDomainExit)
domain.exit();

return true;
};

Expand Down
2 changes: 1 addition & 1 deletion src/env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ void Environment::PrintSyncTrace() const {
StackTrace::CurrentStackTrace(isolate(), 10, StackTrace::kDetailed);

fprintf(stderr, "(node:%u) WARNING: Detected use of sync API\n",
GetProcessId());
uv_os_getpid());

for (int i = 0; i < stack->GetFrameCount() - 1; i++) {
Local<StackFrame> stack_frame = stack->GetFrame(i);
Expand Down
5 changes: 2 additions & 3 deletions src/inspector_agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ static int StartDebugSignalHandler() {
CHECK_EQ(0, pthread_attr_destroy(&attr));
if (err != 0) {
fprintf(stderr, "node[%u]: pthread_create: %s\n",
GetProcessId(), strerror(err));
uv_os_getpid(), strerror(err));
fflush(stderr);
// Leave SIGUSR1 blocked. We don't install a signal handler,
// receiving the signal would terminate the process.
Expand Down Expand Up @@ -144,7 +144,7 @@ static int StartDebugSignalHandler() {
DWORD pid;
LPTHREAD_START_ROUTINE* handler;

pid = GetCurrentProcessId();
pid = uv_os_getpid();

if (GetDebugSignalHandlerMappingName(pid,
mapping_name,
Expand Down Expand Up @@ -692,4 +692,3 @@ bool Agent::IsWaitingForConnect() {

} // namespace inspector
} // namespace node

2 changes: 1 addition & 1 deletion src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3144,7 +3144,7 @@ void SetupProcessObject(Environment* env,
process->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "env"), process_env);

READONLY_PROPERTY(process, "pid",
Integer::New(env->isolate(), GetProcessId()));
Integer::New(env->isolate(), uv_os_getpid()));
READONLY_PROPERTY(process, "features", GetFeatures(env));

CHECK(process->SetAccessor(env->context(),
Expand Down
1 change: 0 additions & 1 deletion src/node_internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,6 @@ void RegisterSignalHandler(int signal,
bool reset_handler = false);
#endif

uint32_t GetProcessId();
bool SafeGetenv(const char* key, std::string* text);

std::string GetHumanReadableProcessName();
Expand Down
19 changes: 2 additions & 17 deletions src/util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,9 @@
#include "string_bytes.h"
#include "node_buffer.h"
#include "node_internals.h"
#include "uv.h"
#include <stdio.h>

#ifdef __POSIX__
#include <unistd.h> // getpid()
#endif

#ifdef _MSC_VER
#include <windows.h> // GetCurrentProcessId()
#endif

namespace node {

using v8::Isolate;
Expand Down Expand Up @@ -122,15 +115,7 @@ std::string GetHumanReadableProcessName() {
void GetHumanReadableProcessName(char (*name)[1024]) {
char title[1024] = "Node.js";
uv_get_process_title(title, sizeof(title));
snprintf(*name, sizeof(*name), "%s[%u]", title, GetProcessId());
}

uint32_t GetProcessId() {
#ifdef _WIN32
return GetCurrentProcessId();
#else
return getpid();
#endif
snprintf(*name, sizeof(*name), "%s[%u]", title, uv_os_getpid());
}

} // namespace node
11 changes: 6 additions & 5 deletions test/common/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,18 @@ Returns a new promise that will propagate `promise` resolution or rejection if
that happens within the `timeoutMs` timespan, or rejects with `error` as
a reason otherwise.

### fixturesDir
* [&lt;String>]

Path to the 'fixtures' directory.

### getArrayBufferViews(buf)
* `buf` [&lt;Buffer>]
* return [&lt;ArrayBufferView&#91;&#93;>]

Returns an instance of all possible `ArrayBufferView`s of the provided Buffer.

### getCallSite(func)
* `func` [&lt;Function>]
* return [&lt;String>]

Returns the file name and line number for the provided Function.

### globalCheck
* [&lt;Boolean>]

Expand Down
20 changes: 16 additions & 4 deletions test/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ const testRoot = process.env.NODE_TEST_DIR ?

const noop = () => {};

exports.fixturesDir = fixturesDir;

// Using a `.` prefixed name, which is the convention for "hidden" on POSIX,
// gets tools to ignore it by default or by simple rules, especially eslint.
let tmpDirName = '.tmp';
Expand Down Expand Up @@ -304,7 +302,7 @@ exports.childShouldThrowAndAbort = function() {

exports.ddCommand = function(filename, kilobytes) {
if (exports.isWindows) {
const p = path.resolve(exports.fixturesDir, 'create-file.js');
const p = path.resolve(fixturesDir, 'create-file.js');
return `"${process.argv[0]}" "${p}" "${filename}" ${kilobytes * 1024}`;
} else {
return `dd if=/dev/zero of="${filename}" bs=1024 count=${kilobytes}`;
Expand Down Expand Up @@ -569,9 +567,23 @@ exports.canCreateSymLink = function() {
return true;
};

exports.getCallSite = function getCallSite(top) {
const originalStackFormatter = Error.prepareStackTrace;
Error.prepareStackTrace = (err, stack) =>
`${stack[0].getFileName()}:${stack[0].getLineNumber()}`;
const err = new Error();
Error.captureStackTrace(err, top);
// with the V8 Error API, the stack is not formatted until it is accessed
err.stack;
Error.prepareStackTrace = originalStackFormatter;
return err.stack;
};

exports.mustNotCall = function(msg) {
const callSite = exports.getCallSite(exports.mustNotCall);
return function mustNotCall() {
assert.fail(msg || 'function should not have been called');
assert.fail(
`${msg || 'function should not have been called'} at ${callSite}`);
};
};

Expand Down
26 changes: 26 additions & 0 deletions test/parallel/test-common-must-not-call.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict';

const common = require('../common');
const assert = require('assert');
const path = require('path');

const message = 'message';
const testFunction = common.mustNotCall(message);

const validateError = common.mustCall((e) => {
const prefix = `${message} at `;
assert.ok(e.message.startsWith(prefix));
if (process.platform === 'win32') {
e.message = e.message.substring(2); // remove 'C:'
}
const [ fileName, lineNumber ] = e.message
.substring(prefix.length).split(':');
assert.strictEqual(path.basename(fileName), 'test-common-must-not-call.js');
assert.strictEqual(lineNumber, '8');
});

try {
testFunction();
} catch (e) {
validateError(e);
}
Loading

0 comments on commit 40a2c90

Please sign in to comment.