Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge 'ry/master' into require-rewrite-wip

Conflicts:
	src/node.js
  • Loading branch information...
commit 7d18aefe2e843f2a126586d561ac07e83cd7b23a 2 parents 75f2ad6 + 9e8afe9
@isaacs authored
View
2  lib/events.js
@@ -1,6 +1,6 @@
exports.EventEmitter = process.EventEmitter;
-// process.EventEmitter is defined in src/events.cc
+// process.EventEmitter is defined in src/node_events.cc
// process.EventEmitter.prototype.emit() is also defined there.
process.EventEmitter.prototype.addListener = function (type, listener) {
if (!(listener instanceof Function)) {
View
4 src/node.cc
@@ -859,6 +859,8 @@ Handle<Value> EvalCX(const Arguments& args) {
Local<String> code = args[0]->ToString();
Local<Object> sandbox = args.Length() > 1 ? args[1]->ToObject()
: Object::New();
+ Local<String> filename = args.Length() > 2 ? args[2]->ToString()
+ : String::New("evalcx");
// Create the new context
Persistent<Context> context = Context::New();
@@ -878,7 +880,7 @@ Handle<Value> EvalCX(const Arguments& args) {
// Catch errors
TryCatch try_catch;
- Local<Script> script = Script::Compile(code, String::New("evalcx"));
+ Local<Script> script = Script::Compile(code, filename);
Handle<Value> result;
if (script.IsEmpty()) {
View
3  src/node_events.cc
@@ -50,7 +50,6 @@ static bool ReallyEmit(Handle<Object> self,
Local<Object> events = events_v->ToObject();
Local<Value> listeners_v = events->Get(event);
- Local<Function> listener;
TryCatch try_catch;
@@ -66,7 +65,7 @@ static bool ReallyEmit(Handle<Object> self,
}
} else if (listeners_v->IsArray()) {
- Local<Array> listeners = Local<Array>::Cast(listeners_v);
+ Local<Array> listeners = Local<Array>::Cast(listeners_v->ToObject()->Clone());
for (uint32_t i = 0; i < listeners->Length(); i++) {
Local<Value> listener_v = listeners->Get(i);
View
25 test/simple/test-event-emitter-modify-in-emit.js
@@ -8,6 +8,7 @@ var e = new events.EventEmitter();
function callback1() {
callbacks_called.push("callback1");
e.addListener("foo", callback2);
+ e.addListener("foo", callback3);
e.removeListener("foo", callback1);
}
@@ -16,23 +17,39 @@ function callback2() {
e.removeListener("foo", callback2);
}
+function callback3() {
+ callbacks_called.push("callback3");
+ e.removeListener("foo", callback3);
+}
+
e.addListener("foo", callback1);
assert.equal(1, e.listeners("foo").length);
e.emit("foo");
-assert.equal(1, e.listeners("foo").length);
+assert.equal(2, e.listeners("foo").length);
assert.deepEqual(["callback1"], callbacks_called);
e.emit("foo");
assert.equal(0, e.listeners("foo").length);
-assert.deepEqual(["callback1", "callback2"], callbacks_called);
+assert.deepEqual(["callback1", "callback2", "callback3"], callbacks_called);
e.emit("foo");
assert.equal(0, e.listeners("foo").length);
-assert.deepEqual(["callback1", "callback2"], callbacks_called);
+assert.deepEqual(["callback1", "callback2", "callback3"], callbacks_called);
e.addListener("foo", callback1);
e.addListener("foo", callback2);
assert.equal(2, e.listeners("foo").length)
e.removeAllListeners("foo")
-assert.equal(0, e.listeners("foo").length)
+assert.equal(0, e.listeners("foo").length)
+
+// Verify that removing callbacks while in emit allows emits to propagate to
+// all listeners
+callbacks_called = [ ];
+
+e.addListener("foo", callback2);
+e.addListener("foo", callback3);
+assert.equal(2, e.listeners("foo").length)
+e.emit("foo");
+assert.deepEqual(["callback2", "callback3"], callbacks_called);
+assert.equal(0, e.listeners("foo").length)

0 comments on commit 7d18aef

Please sign in to comment.
Something went wrong with that request. Please try again.