From 767ee7348624803e6f90cf111df8b917fac442fc Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Tue, 20 Jan 2015 19:19:24 +0100 Subject: [PATCH 1/3] test: strip copyright boilerplate Commit 3e1b1dd missed a few files in test/parallel, this commit rectifies that. Only test/parallel/test-url.js still has a copyright header. I left it in because the original author is neither an io.js contributor nor a StrongLoop employee. PR-URL: https://github.com/iojs/io.js/pull/527 Reviewed-By: Colin Ihrig --- .../test-event-emitter-get-max-listeners.js | 21 ------------------- test/parallel/test-fs-access.js | 21 ------------------- test/parallel/test-punycode.js | 20 ------------------ test/parallel/test-require-process.js | 21 ------------------- test/parallel/test-timers-unref-call.js | 14 ------------- test/parallel/test-v8-flags.js | 14 ------------- test/parallel/test-v8-stats.js | 14 ------------- 7 files changed, 125 deletions(-) diff --git a/test/parallel/test-event-emitter-get-max-listeners.js b/test/parallel/test-event-emitter-get-max-listeners.js index 8e47ef7a794141..8a1a2c8f98c6e8 100644 --- a/test/parallel/test-event-emitter-get-max-listeners.js +++ b/test/parallel/test-event-emitter-get-max-listeners.js @@ -1,24 +1,3 @@ -// Copyright io.js 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 EventEmitter = require('events'); diff --git a/test/parallel/test-fs-access.js b/test/parallel/test-fs-access.js index 3aa4b849f99b3c..3846b7b7b79caa 100644 --- a/test/parallel/test-fs-access.js +++ b/test/parallel/test-fs-access.js @@ -1,24 +1,3 @@ -// Copyright io.js 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 fs = require('fs'); diff --git a/test/parallel/test-punycode.js b/test/parallel/test-punycode.js index a601a4128db51a..4ac953849c0553 100644 --- a/test/parallel/test-punycode.js +++ b/test/parallel/test-punycode.js @@ -1,23 +1,3 @@ -// Copyright (C) 2011 by Ben Noordhuis -// -// 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 punycode = require('punycode'); var assert = require('assert'); diff --git a/test/parallel/test-require-process.js b/test/parallel/test-require-process.js index 2820c22eea92ec..4693b4984e6dfe 100644 --- a/test/parallel/test-require-process.js +++ b/test/parallel/test-require-process.js @@ -1,24 +1,3 @@ -// Copyright io.js 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 assert = require('assert'); var nativeProcess = require('process'); diff --git a/test/parallel/test-timers-unref-call.js b/test/parallel/test-timers-unref-call.js index b6f735754947f9..4f7865b8457601 100644 --- a/test/parallel/test-timers-unref-call.js +++ b/test/parallel/test-timers-unref-call.js @@ -1,17 +1,3 @@ -// Copyright (c) 2014, StrongLoop Inc. -// -// Permission to use, copy, modify, and/or distribute this software for any -// purpose with or without fee is hereby granted, provided that the above -// copyright notice and this permission notice appear in all copies. -// -// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - var common = require('../common'); var Timer = process.binding('timer_wrap').Timer; diff --git a/test/parallel/test-v8-flags.js b/test/parallel/test-v8-flags.js index 1397d8bedd46a5..886583e4c51229 100644 --- a/test/parallel/test-v8-flags.js +++ b/test/parallel/test-v8-flags.js @@ -1,17 +1,3 @@ -// Copyright (c) 2014, StrongLoop Inc. -// -// Permission to use, copy, modify, and/or distribute this software for any -// purpose with or without fee is hereby granted, provided that the above -// copyright notice and this permission notice appear in all copies. -// -// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - var common = require('../common'); var assert = require('assert'); var v8 = require('v8'); diff --git a/test/parallel/test-v8-stats.js b/test/parallel/test-v8-stats.js index d4623363a5e1a7..7acb9db1e04306 100644 --- a/test/parallel/test-v8-stats.js +++ b/test/parallel/test-v8-stats.js @@ -1,17 +1,3 @@ -// Copyright (c) 2014, StrongLoop Inc. -// -// Permission to use, copy, modify, and/or distribute this software for any -// purpose with or without fee is hereby granted, provided that the above -// copyright notice and this permission notice appear in all copies. -// -// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - var common = require('../common'); var assert = require('assert'); var v8 = require('v8'); From 77d68070dafe56b5593ad92759a57c64de6b4cf1 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Tue, 20 Jan 2015 19:24:36 +0100 Subject: [PATCH 2/3] test: fix event-emitter-get-max-listeners style Add missing commas in parallel/test-event-emitter-get-max-listeners. Comma-less style is fine and dandy but it throws off vim's autoindent. PR-URL: https://github.com/iojs/io.js/pull/527 Reviewed-By: Colin Ihrig --- test/parallel/test-event-emitter-get-max-listeners.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/parallel/test-event-emitter-get-max-listeners.js b/test/parallel/test-event-emitter-get-max-listeners.js index 8a1a2c8f98c6e8..bcaa70bd4a69f3 100644 --- a/test/parallel/test-event-emitter-get-max-listeners.js +++ b/test/parallel/test-event-emitter-get-max-listeners.js @@ -6,8 +6,8 @@ var emitter = new EventEmitter(); assert.strictEqual(emitter.getMaxListeners(), EventEmitter.defaultMaxListeners); -emitter.setMaxListeners(0) -assert.strictEqual(emitter.getMaxListeners(), 0) +emitter.setMaxListeners(0); +assert.strictEqual(emitter.getMaxListeners(), 0); -emitter.setMaxListeners(3) -assert.strictEqual(emitter.getMaxListeners(), 3) +emitter.setMaxListeners(3); +assert.strictEqual(emitter.getMaxListeners(), 3); From ee9cd004d8a211871439fc77c0696b79c5d0e52d Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Tue, 20 Jan 2015 19:30:50 +0100 Subject: [PATCH 3/3] lib: fix TypeError with EventEmitter#on() abuse Commit 2931348 added EventEmitter#getMaxListeners() but introduced a regression when people abuse EventEmitter.prototype.on.call() to call EventEmitter#on() on a non-EE object. Add a workaround for that. Fixes: https://github.com/iojs/io.js/issues/523 PR-URL: https://github.com/iojs/io.js/pull/527 Reviewed-By: Colin Ihrig --- lib/events.js | 13 ++++++++----- .../test-event-emitter-get-max-listeners.js | 5 +++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/events.js b/lib/events.js index 2f3215a4112ca7..3bc532e06f4a7d 100644 --- a/lib/events.js +++ b/lib/events.js @@ -46,11 +46,14 @@ EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) { return this; }; -EventEmitter.prototype.getMaxListeners = function getMaxListeners() { - if (!util.isUndefined(this._maxListeners)) - return this._maxListeners; - else +function $getMaxListeners(that) { + if (util.isUndefined(that._maxListeners)) return EventEmitter.defaultMaxListeners; + return that._maxListeners; +} + +EventEmitter.prototype.getMaxListeners = function getMaxListeners() { + return $getMaxListeners(this); }; EventEmitter.prototype.emit = function emit(type) { @@ -151,7 +154,7 @@ EventEmitter.prototype.addListener = function addListener(type, listener) { // Check for listener leak if (util.isObject(this._events[type]) && !this._events[type].warned) { - var m = this.getMaxListeners(); + var m = $getMaxListeners(this); if (m && m > 0 && this._events[type].length > m) { this._events[type].warned = true; console.error('(node) warning: possible EventEmitter memory ' + diff --git a/test/parallel/test-event-emitter-get-max-listeners.js b/test/parallel/test-event-emitter-get-max-listeners.js index bcaa70bd4a69f3..57430a4e9bec37 100644 --- a/test/parallel/test-event-emitter-get-max-listeners.js +++ b/test/parallel/test-event-emitter-get-max-listeners.js @@ -11,3 +11,8 @@ assert.strictEqual(emitter.getMaxListeners(), 0); emitter.setMaxListeners(3); assert.strictEqual(emitter.getMaxListeners(), 3); + +// https://github.com/iojs/io.js/issues/523 - second call should not throw. +var recv = {}; +EventEmitter.prototype.on.call(recv, 'event', function() {}); +EventEmitter.prototype.on.call(recv, 'event', function() {});