summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorBen Noordhuis <info@bnoordhuis.nl>2014-05-05 16:48:51 +0200
committerTrevor Norris <trev.norris@gmail.com>2014-05-07 12:11:57 -0700
commit17fbdc18b8cec0b6b2827d9e3c6360b694e6e9c3 (patch)
tree2a865ae866b1fe35d294e2ccf16861c4ee74814e /test
parent120f7cf55fb977a145dca0ed840ea5a07730da05 (diff)
downloadnode-new-17fbdc18b8cec0b6b2827d9e3c6360b694e6e9c3.tar.gz
lib: name EventEmitter prototype methods
Before this commit the EventEmitter methods were anonymous functions. V8 tries to infer names for anonymous functions based on the execution context but it frequently gets it wrong and when that happens, the stack trace is usually confusing and unhelpful. This commit names all methods so V8 can fall back to the method.name property. The above gotcha applies to all anonymous functions but is exacerbated for EventEmitter methods because those are invoked with a plenitude of different receivers. Signed-off-by: Trevor Norris <trev.norris@gmail.com>
Diffstat (limited to 'test')
-rw-r--r--test/message/stdin_messages.out8
-rw-r--r--test/simple/test-event-emitter-method-names.js32
2 files changed, 36 insertions, 4 deletions
diff --git a/test/message/stdin_messages.out b/test/message/stdin_messages.out
index cd7c12a7b9..2dc4574bf6 100644
--- a/test/message/stdin_messages.out
+++ b/test/message/stdin_messages.out
@@ -8,7 +8,7 @@ SyntaxError: Strict mode code may not include a with statement
at Module._compile (module.js:*:*)
at evalScript (node.js:*:*)
at Socket.<anonymous> (node.js:*:*)
- at Socket.EventEmitter.emit (events.js:*:*)
+ at Socket.emit (events.js:*:*)
at _stream_readable.js:*:*
at process._tickCallback (node.js:*:*)
42
@@ -23,7 +23,7 @@ Error: hello
at Module._compile (module.js:*:*)
at evalScript (node.js:*:*)
at Socket.<anonymous> (node.js:*:*)
- at Socket.EventEmitter.emit (events.js:*:*)
+ at Socket.emit (events.js:*:*)
at _stream_readable.js:*:*
at process._tickCallback (node.js:*:*)
@@ -36,7 +36,7 @@ Error: hello
at Module._compile (module.js:*:*)
at evalScript (node.js:*:*)
at Socket.<anonymous> (node.js:*:*)
- at Socket.EventEmitter.emit (events.js:*:*)
+ at Socket.emit (events.js:*:*)
at _stream_readable.js:*:*
at process._tickCallback (node.js:*:*)
100
@@ -50,7 +50,7 @@ ReferenceError: y is not defined
at Module._compile (module.js:*:*)
at evalScript (node.js:*:*)
at Socket.<anonymous> (node.js:*:*)
- at Socket.EventEmitter.emit (events.js:*:*)
+ at Socket.emit (events.js:*:*)
at _stream_readable.js:*:*
at process._tickCallback (node.js:*:*)
diff --git a/test/simple/test-event-emitter-method-names.js b/test/simple/test-event-emitter-method-names.js
new file mode 100644
index 0000000000..e7c0f88e7a
--- /dev/null
+++ b/test/simple/test-event-emitter-method-names.js
@@ -0,0 +1,32 @@
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+var common = require('../common');
+var assert = require('assert');
+var events = require('events');
+
+var E = events.EventEmitter.prototype;
+assert.equal(E.constructor.name, 'EventEmitter');
+assert.equal(E.on, E.addListener); // Same method.
+Object.getOwnPropertyNames(E).forEach(function(name) {
+ if (name === 'constructor' || name === 'on') return;
+ assert.equal(E[name].name, name);
+});