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

Commit 40a2c90

Browse files
committed
meta: merge node/master into node-chakracore/master
Merge a322b8e as of 2017-12-04 This commit was automatically generated. For any problems, please contact jackhorton Reviewed-By: Taylor Woll <taylor.woll@microsoft.com>
2 parents 4a19a9b + a322b8e commit 40a2c90

18 files changed

+167
-106
lines changed

doc/api/console.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,19 @@ Defaults to `2`. To make it recurse indefinitely, pass `null`.
277277
Defaults to `false`. Colors are customizable; see
278278
[customizing `util.inspect()` colors][].
279279

280+
### console.dirxml(...data)
281+
<!-- YAML
282+
added: v8.0.0
283+
changes:
284+
- version: REPLACEME
285+
pr-url: https://github.com/nodejs/node/pull/17152
286+
description: "`console.dirxml` now calls `console.log` for its arguments."
287+
-->
288+
* `...data` {any}
289+
290+
This method calls `console.log()` passing it the arguments received.
291+
Please note that this method does not produce any XML formatting.
292+
280293
### console.error([data][, ...args])
281294
<!-- YAML
282295
added: v0.1.100
@@ -435,18 +448,6 @@ The following methods are exposed by the V8 engine in the general API but do
435448
not display anything unless used in conjunction with the [inspector][]
436449
(`--inspect` flag).
437450

438-
### console.dirxml(object)
439-
<!-- YAML
440-
added: v8.0.0
441-
-->
442-
* `object` {string}
443-
444-
This method does not display anything unless used in the inspector. The
445-
`console.dirxml()` method displays in `stdout` an XML interactive tree
446-
representation of the descendants of the specified `object` if possible, or the
447-
JavaScript representation if not. Calling `console.dirxml()` on an HTML or XML
448-
element is equivalent to calling `console.log()`.
449-
450451
### console.markTimeline(label)
451452
<!-- YAML
452453
added: v8.0.0

lib/console.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ Console.prototype.dir = function dir(object, options) {
172172
};
173173

174174

175+
Console.prototype.dirxml = Console.prototype.log;
176+
177+
175178
Console.prototype.time = function time(label = 'default') {
176179
// Coerces everything other than Symbol to a string
177180
label = `${label}`;

lib/domain.js

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@ const EventEmitter = require('events');
3131
const errors = require('internal/errors');
3232
const { createHook } = require('async_hooks');
3333

34-
// communicate with events module, but don't require that
35-
// module to have to load this one, since this module has
36-
// a few side effects.
37-
EventEmitter.usingDomains = true;
38-
3934
// overwrite process.domain with a getter/setter that will allow for more
4035
// effective optimizations
4136
var _domain = [null];
@@ -387,3 +382,49 @@ Domain.prototype.bind = function(cb) {
387382

388383
return runBound;
389384
};
385+
386+
// Override EventEmitter methods to make it domain-aware.
387+
EventEmitter.usingDomains = true;
388+
389+
const eventInit = EventEmitter.init;
390+
EventEmitter.init = function() {
391+
this.domain = null;
392+
if (exports.active && !(this instanceof exports.Domain)) {
393+
this.domain = exports.active;
394+
}
395+
396+
return eventInit.call(this);
397+
};
398+
399+
const eventEmit = EventEmitter.prototype.emit;
400+
EventEmitter.prototype.emit = function emit(...args) {
401+
const domain = this.domain;
402+
if (domain === null || domain === undefined || this === process) {
403+
return eventEmit.apply(this, args);
404+
}
405+
406+
const type = args[0];
407+
// edge case: if there is a domain and an existing non error object is given,
408+
// it should not be errorized
409+
// see test/parallel/test-event-emitter-no-error-provided-to-error-event.js
410+
if (type === 'error' && args.length > 1 && args[1] &&
411+
!(args[1] instanceof Error)) {
412+
domain.emit('error', args[1]);
413+
return false;
414+
}
415+
416+
domain.enter();
417+
try {
418+
return eventEmit.apply(this, args);
419+
} catch (er) {
420+
if (typeof er === 'object' && er !== null) {
421+
er.domainEmitter = this;
422+
er.domain = domain;
423+
er.domainThrown = false;
424+
}
425+
domain.emit('error', er);
426+
return false;
427+
} finally {
428+
domain.exit();
429+
}
430+
};

lib/events.js

Lines changed: 6 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
'use strict';
2323

24-
var domain;
2524
var spliceOne;
2625

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

35-
EventEmitter.usingDomains = false;
36-
37-
EventEmitter.prototype.domain = undefined;
3834
EventEmitter.prototype._events = undefined;
3935
EventEmitter.prototype._maxListeners = undefined;
4036

@@ -66,14 +62,6 @@ Object.defineProperty(EventEmitter, 'defaultMaxListeners', {
6662
});
6763

6864
EventEmitter.init = function() {
69-
this.domain = null;
70-
if (EventEmitter.usingDomains) {
71-
// if there is an active domain, then attach to it.
72-
domain = domain || require('domain');
73-
if (domain.active && !(this instanceof domain.Domain)) {
74-
this.domain = domain.active;
75-
}
76-
}
7765

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

117-
const domain = this.domain;
118-
119105
// If there is no 'error' event listener then throw.
120106
if (doError) {
121107
let er;
122108
if (args.length > 0)
123109
er = args[0];
124-
if (domain !== null && domain !== undefined) {
125-
if (!er) {
126-
const errors = lazyErrors();
127-
er = new errors.Error('ERR_UNHANDLED_ERROR');
128-
}
129-
if (typeof er === 'object' && er !== null) {
130-
er.domainEmitter = this;
131-
er.domain = domain;
132-
er.domainThrown = false;
133-
}
134-
domain.emit('error', er);
135-
} else if (er instanceof Error) {
110+
if (er instanceof Error) {
136111
throw er; // Unhandled 'error' event
137-
} else {
138-
// At least give some kind of context to the user
139-
const errors = lazyErrors();
140-
const err = new errors.Error('ERR_UNHANDLED_ERROR', er);
141-
err.context = er;
142-
throw err;
143112
}
144-
return false;
113+
// At least give some kind of context to the user
114+
const errors = lazyErrors();
115+
const err = new errors.Error('ERR_UNHANDLED_ERROR', er);
116+
err.context = er;
117+
throw err;
145118
}
146119

147120
const handler = events[type];
148121

149122
if (handler === undefined)
150123
return false;
151124

152-
let needDomainExit = false;
153-
if (domain !== null && domain !== undefined && this !== process) {
154-
domain.enter();
155-
needDomainExit = true;
156-
}
157-
158125
if (typeof handler === 'function') {
159126
handler.apply(this, args);
160127
} else {
@@ -164,9 +131,6 @@ EventEmitter.prototype.emit = function emit(type, ...args) {
164131
listeners[i].apply(this, args);
165132
}
166133

167-
if (needDomainExit)
168-
domain.exit();
169-
170134
return true;
171135
};
172136

src/env.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ void Environment::PrintSyncTrace() const {
173173
StackTrace::CurrentStackTrace(isolate(), 10, StackTrace::kDetailed);
174174

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

178178
for (int i = 0; i < stack->GetFrameCount() - 1; i++) {
179179
Local<StackFrame> stack_frame = stack->GetFrame(i);

src/inspector_agent.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ static int StartDebugSignalHandler() {
109109
CHECK_EQ(0, pthread_attr_destroy(&attr));
110110
if (err != 0) {
111111
fprintf(stderr, "node[%u]: pthread_create: %s\n",
112-
GetProcessId(), strerror(err));
112+
uv_os_getpid(), strerror(err));
113113
fflush(stderr);
114114
// Leave SIGUSR1 blocked. We don't install a signal handler,
115115
// receiving the signal would terminate the process.
@@ -144,7 +144,7 @@ static int StartDebugSignalHandler() {
144144
DWORD pid;
145145
LPTHREAD_START_ROUTINE* handler;
146146

147-
pid = GetCurrentProcessId();
147+
pid = uv_os_getpid();
148148

149149
if (GetDebugSignalHandlerMappingName(pid,
150150
mapping_name,
@@ -692,4 +692,3 @@ bool Agent::IsWaitingForConnect() {
692692

693693
} // namespace inspector
694694
} // namespace node
695-

src/node.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3144,7 +3144,7 @@ void SetupProcessObject(Environment* env,
31443144
process->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "env"), process_env);
31453145

31463146
READONLY_PROPERTY(process, "pid",
3147-
Integer::New(env->isolate(), GetProcessId()));
3147+
Integer::New(env->isolate(), uv_os_getpid()));
31483148
READONLY_PROPERTY(process, "features", GetFeatures(env));
31493149

31503150
CHECK(process->SetAccessor(env->context(),

src/node_internals.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,6 @@ void RegisterSignalHandler(int signal,
252252
bool reset_handler = false);
253253
#endif
254254

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

258257
std::string GetHumanReadableProcessName();

src/util.cc

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,9 @@
2222
#include "string_bytes.h"
2323
#include "node_buffer.h"
2424
#include "node_internals.h"
25+
#include "uv.h"
2526
#include <stdio.h>
2627

27-
#ifdef __POSIX__
28-
#include <unistd.h> // getpid()
29-
#endif
30-
31-
#ifdef _MSC_VER
32-
#include <windows.h> // GetCurrentProcessId()
33-
#endif
34-
3528
namespace node {
3629

3730
using v8::Isolate;
@@ -122,15 +115,7 @@ std::string GetHumanReadableProcessName() {
122115
void GetHumanReadableProcessName(char (*name)[1024]) {
123116
char title[1024] = "Node.js";
124117
uv_get_process_title(title, sizeof(title));
125-
snprintf(*name, sizeof(*name), "%s[%u]", title, GetProcessId());
126-
}
127-
128-
uint32_t GetProcessId() {
129-
#ifdef _WIN32
130-
return GetCurrentProcessId();
131-
#else
132-
return getpid();
133-
#endif
118+
snprintf(*name, sizeof(*name), "%s[%u]", title, uv_os_getpid());
134119
}
135120

136121
} // namespace node

test/common/README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,17 +127,18 @@ Returns a new promise that will propagate `promise` resolution or rejection if
127127
that happens within the `timeoutMs` timespan, or rejects with `error` as
128128
a reason otherwise.
129129

130-
### fixturesDir
131-
* [&lt;String>]
132-
133-
Path to the 'fixtures' directory.
134-
135130
### getArrayBufferViews(buf)
136131
* `buf` [&lt;Buffer>]
137132
* return [&lt;ArrayBufferView&#91;&#93;>]
138133

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

136+
### getCallSite(func)
137+
* `func` [&lt;Function>]
138+
* return [&lt;String>]
139+
140+
Returns the file name and line number for the provided Function.
141+
141142
### globalCheck
142143
* [&lt;Boolean>]
143144

0 commit comments

Comments
 (0)