0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
Commit Graph

60 Commits

Author SHA1 Message Date
Trevor Norris
8ca43a7f40 events: ensure usingDomain is always boolean
Small addition to ensure that exports.usingDomains is always a bool.
2013-03-01 17:36:47 -08:00
Trevor Norris
75305f3bab events: add check for listeners length
Ability to return just the length of listeners for a given type, using
EventEmitter.listenerCount(emitter, event). This will be a lot cheaper
than creating a copy of the listeners array just to check its length.
2013-03-01 17:36:47 -08:00
isaacs
b7d76a1a7b Revert "events: Don't crash on events named __proto__"
Unfortunately, it's just too slow to do this in events.js.  Users will
just have to live with not having events named __proto__ or toString.

This reverts commit b48e303af0.
2013-01-17 13:20:22 -08:00
isaacs
b48e303af0 events: Don't crash on events named __proto__
This prefixes all event names internally with 'ev'.
2013-01-17 09:21:45 -08:00
isaacs
ec8ebaf300 domain: use camelCase instead of snake_case
While it's true that error objects have a history of getting snake_case
properties attached by the host system, it's a point of confusion to
Node users that comes up a lot.  It's still 'experimental', so best to
change this sooner rather than later.
2012-12-29 10:37:31 -08:00
isaacs
77ed12fe7a Merge remote-tracking branch 'ry/v0.8' into master
Conflicts:
	AUTHORS
	ChangeLog
	deps/uv/test/test-spawn.c
	deps/uv/uv.gyp
	src/cares_wrap.cc
	src/node.cc
	src/node_version.h
	test/simple/test-buffer.js
	tools/gyp/pylib/gyp/common.py
	tools/install.py
2012-12-13 16:57:58 -08:00
Ryunosuke SATO
0506d294dc events: fix typos in code comment
- newListeners -> newListener
2012-12-10 13:08:26 +01:00
Ryunosuke SATO
eb502205d5 events: setMaxListeners() should not have side effects
This object initialization has been unnecessary since 12cf730b.

Ref #3803.
2012-12-10 13:07:35 +01:00
Ryunosuke SATO
1c7acd2c84 events: use assigned variable instead of arguments
Always `arguments[0]` is used when `EventEmitter#emit` called.
Using assigned variable is faster than `arguments[0]`.
2012-12-10 13:04:46 +01:00
Ryunosuke SATO
0397223ab4 events: use null assignment instead of deleting property 2012-12-10 08:59:14 +01:00
isaacs
45a13d9674 events: Don't clobber pre-existing _events obj in EE ctor 2012-10-25 13:37:08 -07:00
isaacs
c7b2e29e5e events: Make the EventEmitter class monomorphic
Always add domain, _events, and _maxListeners properties, set to the
default values at first.

Leads to a very very slight perf improvement when using setMaxListeners,
or dealing with a lot of EE objects that don't have any listeners.
2012-10-25 07:51:05 -07:00
isaacs
ae40f1c438 Merge remote-tracking branch 'ry/v0.8' into v0.8-merge
Conflicts:
	AUTHORS
	ChangeLog
	deps/openssl/openssl.gyp
	deps/uv/src/unix/linux/linux-core.c
	deps/uv/src/unix/process.c
	deps/uv/src/unix/stream.c
	deps/v8/src/arm/builtins-arm.cc
	deps/v8/src/arm/code-stubs-arm.cc
	deps/v8/src/arm/full-codegen-arm.cc
	lib/tls.js
	src/node_version.h
	test/simple/test-http-client-timeout-agent.js
2012-09-28 09:47:48 -07:00
Ben Noordhuis
56668f54d1 events: speed up .removeAllListeners() 2012-09-22 03:48:59 +02:00
Ben Noordhuis
b7fd55e9a0 events: speed up newListener/removeListener events 2012-09-22 03:48:59 +02:00
Ben Noordhuis
84221fd1d6 events: add 'removeListener' event 2012-09-22 03:48:59 +02:00
isaacs
0400571676 domain: Properly exit() on domain disposal
This addresses #4034.  There are two problems happening:

1. The domain is not exited automatically when calling dispose() on it.
Then, since the domain is disposed, attempting to exit it again will do
nothing.

2. The active domain is stored on process.domain.  Since thrown errors
call `process.emit('uncaughtException', er)`, and the process is an
event emitter with a `.domain` member, it re-enters the domain a second
time before calling the error handler, pushing it onto the stack again.

Thus, if the handler calls `domain.dispose()`, then the domain is now on
the stack twice, and cannot be exited properly.  Since the domain is
disposed, any subsequent IO will be no-op'ed, since we've declared that
this context is done and best forgotten.

The solution here is twofold:

1. In EventEmitter.emit, do not enter the domain if `this===process`.
2. Automatically exit the domain when calling `domain.dispose()`.
2012-09-21 09:22:50 -07:00
isaacs
50c7d80fb0 events: emitter.listeners() should not have side effects
Fixes #3803
2012-08-13 19:04:40 +02:00
Joe Andaverde
20e12e4be3 events: make .listeners() return a copy
Make EventEmitter.listeners(event) return a copy of the listeners array instead
of the array itself.

Fixes #3442.
2012-07-27 20:28:51 +02:00
Nathan Rajlich
713b9249e1 Revert "events: don't delete the listeners array in removeListener()"
This reverts commit 928ea564d1.

Keeping the original Array instance in-place essentially causes a memory leak
on EventEmitters that use an infinite number of event names (an incrementing
counter, for example), which isn't an unreasonable thing to want to do.

Fixes #3702.
2012-07-12 15:43:35 -07:00
Maciej Małecki
3db2e034c4 events: cache domain module locally
It's faster than calling `require` every time we create an
`EventEmitter`.
2012-06-17 13:07:20 -07:00
Reid Burke
c9a1b5d162 Fix #3425: removeAllListeners should delete array
When removeAllListeners is called, the listeners array
is deleted to maintain compatibility with v0.6.

Reverts "events: don't delete the listeners array"

This reverts commit 78dc13fbf9.

Conflicts:

	test/simple/test-event-emitter-remove-all-listeners.js
2012-06-14 17:26:50 -07:00
isaacs
963459d736 Domain feature
This is a squashed commit of the main work done on the domains-wip branch.

The original commit messages are preserved for posterity:

* Implicitly add EventEmitters to active domain
* Implicitly add timers to active domain
* domain: add members, remove ctor cb
* Don't hijack bound callbacks for Domain error events
* Add dispose method
* Add domain.remove(ee) method
* A test of multiple domains in process at once
* Put the active domain on the process object
* Only intercept error arg if explicitly requested
* Typo
* Don't auto-add new domains to the current domain

    While an automatic parent/child relationship is sort of neat,
    and leads to some nice error-bubbling characteristics, it also
    results in keeping a reference to every EE and timer created,
    unless domains are explicitly disposed of.

* Explicitly adding one domain to another is still fine, of course.
* Don't allow circular domain->domain memberships
* Disposing of a domain removes it from its parent
* Domain disposal turns functions into no-ops
* More documentation of domains
* More thorough dispose() semantics
* An example using domains in an HTTP server
* Don't handle errors on a disposed domain
* Need to push, even if the same domain is entered multiple times
* Array.push is too slow for the EE Ctor
* lint domain
* domain: docs
* Also call abort and destroySoon to clean up event emitters
* domain: Wrap destroy methods in a try/catch
* Attach tick callbacks to active domain
* domain: Only implicitly bind timers, not explicitly
* domain: Don't fire timers when disposed.
* domain: Simplify naming so that MakeCallback works on Timers
* Add setInterval and nextTick to domain test
* domain: Make stack private
2012-04-17 13:14:55 -07:00
Maciej Małecki
f065c87bcf events: remove misleading comment 2012-04-15 15:52:56 +02:00
Nathan Rajlich
928ea564d1 events: don't delete the listeners array in removeListener() 2012-03-15 17:01:29 -07:00
Ben Noordhuis
78dc13fbf9 events: don't delete the listeners array
The documentation implies that .removeAllListeners() leaves the listeners array
untouched. Make it so.
2012-03-16 00:20:10 +01:00
Roly Fentanes
db8940dae2 newListener emits correct fn when using once
Fixes #2826.
2012-02-25 15:37:38 +09:00
Ryunosuke SATO
22d7fe1206 events: fix checking max listeners with 1
Fixes #2490.
2012-01-09 04:02:01 +01:00
Siddharth Mahendraker
12cf730b69 events: separate maxListeners and _events
Fixes #1479.
Fixes #1923.
2011-10-30 02:14:30 +01:00
Ryan Dahl
4ef8f06fe6 Finally remove node::EventEmitter 2011-07-19 01:46:38 -07:00
Ryan Dahl
91f1b250ec mraleph emit hack 2011-07-08 17:08:52 -07:00
Ryan Dahl
85bc8d02fa Merge branch 'v0.4'
Conflicts:
	src/node_crypto.cc
2011-05-16 19:29:02 -07:00
koichik
80c2fe9456 Fix event listener leak check timing
Fixes #1041.
2011-05-14 14:43:00 -07:00
Felix Geisendörfer
bc8489580c Allow to remove all EventEmitter listeners at once
This patch adds support for calling EventEmitter#removeAllListeners
with no parameters in order to remove all listeners as once.

See discussion: https://groups.google.com/forum/#!topic/nodejs-dev/Mcyal1ThTHY

Closes GH-889.
2011-04-12 14:47:16 -07:00
Ryan Dahl
bfa9db9dd6 Merge branch 'v0.4'
Conflicts:
	src/node_version.h
	test/simple/test-buffer.js
2011-04-03 23:42:56 -07:00
Arnout Kazemier
53bec1c862 Added support for removing .once listeners
Closes GH-806.
2011-03-25 11:51:29 -07:00
Aaron Heckmann
a4dad95be3 EventEmitter#once only takes instanceof function 2011-03-18 11:18:40 -07:00
Ryan Dahl
55048cdf79 Update copyright headers 2011-03-14 17:37:05 -07:00
Ryan Dahl
81d3de7e6d setMaxListeners should initialize _events 2011-03-07 13:16:00 -08:00
Ryan Dahl
9da75f39d9 Print error when EventEmitters get too many listeners 2011-01-10 13:48:35 -08:00
Daniel C
ca8cc71bd0 EventEmitter.prototype.once should "return this;" 2010-12-30 18:58:43 -08:00
Ryan Dahl
09329cbb04 more lint 2010-12-01 17:43:30 -08:00
Jeremy Martin
144b2a5338 Fix number of args emitted by EventEmitter during "fast case" (lte 3 args) 2010-11-29 17:25:50 -08:00
Peteris Krumins
a6ee3bac85 Add EventEmitter.prototype.once 2010-10-16 20:43:09 -07:00
Micheil Smith
c1aa8ea944 Removed deprecated events.Promise 2010-10-11 16:16:18 -07:00
Joshaven Potter
3d4e4d8909 syntax fixes to pass jslint 2010-10-06 20:40:57 -07:00
isaacs
e9b6b0b327 Report "weird" errors a little better.
There are a few kinds of errors that are very confusing.
1. Errors raised in nextTick
2. Errors emitted on the "error" event
3. RangeErrors that crash the program (or anything without a stack trace)

Long traces will make make these better, of course.  In the meantime, this
adds a few handy signposts (in the form of better error reporting and
comments on the otherwise inscrutable code printed to the terminal) that can
help new users find the cause, or at least, ask for help more effectively.
2010-10-02 06:44:28 -07:00
Herbert Vojčík
3e0a8f3ad8 Common subexpression in emit. 2010-09-16 13:47:43 -07:00
Ryan Dahl
6bdc42cee7 shorten some lines in events.js 2010-09-15 15:47:28 -07:00
Ryan Dahl
ae8f8e7258 Optimize emit for two arguments 2010-09-15 15:20:04 -07:00