Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace __proto__ references with inherits module #1753

Merged
merged 2 commits into from
Jul 5, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

var Runnable = require('./runnable');
var create = require('lodash.create');

/**
* Expose `Hook`.
Expand All @@ -25,7 +26,10 @@ function Hook(title, fn) {
/**
* Inherit from `Runnable.prototype`.
*/
Hook.prototype.__proto__ = Runnable.prototype;

Hook.prototype = create(Runnable.prototype, {
constructor: Hook
});

/**
* Get or set the test `err`.
Expand Down
5 changes: 4 additions & 1 deletion lib/reporters/dot.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

var Base = require('./base');
var create = require('lodash.create');
var color = Base.color;

/**
Expand Down Expand Up @@ -63,4 +64,6 @@ function Dot(runner) {
* Inherit from `Base.prototype`.
*/

Dot.prototype.__proto__ = Base.prototype;
Dot.prototype = create(Base.prototype, {
constructor: Dot
});
5 changes: 4 additions & 1 deletion lib/reporters/landing.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

var Base = require('./base');
var create = require('lodash.create');
var cursor = Base.cursor;
var color = Base.color;

Expand Down Expand Up @@ -89,4 +90,6 @@ function Landing(runner) {
* Inherit from `Base.prototype`.
*/

Landing.prototype.__proto__ = Base.prototype;
Landing.prototype = create(Base.prototype, {
constructor: Landing
});
5 changes: 4 additions & 1 deletion lib/reporters/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

var Base = require('./base');
var create = require('lodash.create');
var color = Base.color;
var cursor = Base.cursor;

Expand Down Expand Up @@ -58,4 +59,6 @@ function List(runner) {
* Inherit from `Base.prototype`.
*/

List.prototype.__proto__ = Base.prototype;
List.prototype = create(Base.prototype, {
constructor: List
});
5 changes: 4 additions & 1 deletion lib/reporters/min.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

var Base = require('./base');
var create = require('lodash.create');

/**
* Expose `Min`.
Expand Down Expand Up @@ -33,4 +34,6 @@ function Min(runner) {
* Inherit from `Base.prototype`.
*/

Min.prototype.__proto__ = Base.prototype;
Min.prototype = create(Base.prototype, {
constructor: Min
});
15 changes: 9 additions & 6 deletions lib/reporters/nyan.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

var Base = require('./base');
var create = require('lodash.create');

/**
* Expose `Dot`.
Expand Down Expand Up @@ -58,6 +59,14 @@ function NyanCat(runner) {
});
}

/**
* Inherit from `Base.prototype`.
*/

NyanCat.prototype = create(Base.prototype, {
constructor: NyanCat
});

/**
* Draw the nyan cat
*
Expand Down Expand Up @@ -253,9 +262,3 @@ NyanCat.prototype.rainbowify = function(str) {
function write(string) {
process.stdout.write(string);
}

/**
* Inherit from `Base.prototype`.
*/

NyanCat.prototype.__proto__ = Base.prototype;
5 changes: 4 additions & 1 deletion lib/reporters/progress.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

var Base = require('./base');
var create = require('lodash.create');
var color = Base.color;
var cursor = Base.cursor;

Expand Down Expand Up @@ -86,4 +87,6 @@ function Progress(runner, options) {
* Inherit from `Base.prototype`.
*/

Progress.prototype.__proto__ = Base.prototype;
Progress.prototype = create(Base.prototype, {
constructor: Progress
});
5 changes: 4 additions & 1 deletion lib/reporters/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

var Base = require('./base');
var create = require('lodash.create');
var color = Base.color;
var cursor = Base.cursor;

Expand Down Expand Up @@ -80,4 +81,6 @@ function Spec(runner) {
* Inherit from `Base.prototype`.
*/

Spec.prototype.__proto__ = Base.prototype;
Spec.prototype = create(Base.prototype, {
constructor: Spec
});
5 changes: 4 additions & 1 deletion lib/reporters/xunit.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

var Base = require('./base');
var create = require('lodash.create');
var fs = require('fs');
var escape = require('../utils').escape;

Expand Down Expand Up @@ -95,7 +96,9 @@ XUnit.prototype.done = function(failures, fn) {
* Inherit from `Base.prototype`.
*/

XUnit.prototype.__proto__ = Base.prototype;
XUnit.prototype = create(Base.prototype, {
constructor: XUnit
});

/**
* Write out the given line.
Expand Down
5 changes: 4 additions & 1 deletion lib/runnable.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

var EventEmitter = require('events').EventEmitter;
var Pending = require('./pending');
var create = require('lodash.create');
var debug = require('debug')('mocha:runnable');
var milliseconds = require('./ms');
var utils = require('./utils');
Expand Down Expand Up @@ -55,7 +56,9 @@ function Runnable(title, fn) {
* Inherit from `EventEmitter.prototype`.
*/

Runnable.prototype.__proto__ = EventEmitter.prototype;
Runnable.prototype = create(EventEmitter.prototype, {
constructor: Runnable
});

/**
* Set & get timeout `ms`.
Expand Down
5 changes: 4 additions & 1 deletion lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

var EventEmitter = require('events').EventEmitter;
var Pending = require('./pending');
var create = require('lodash.create');
var debug = require('debug')('mocha:runner');
var filter = require('./utils').filter;
var indexOf = require('./utils').indexOf;
Expand Down Expand Up @@ -86,7 +87,9 @@ Runner.immediately = global.setImmediate || process.nextTick;
* Inherit from `EventEmitter.prototype`.
*/

Runner.prototype.__proto__ = EventEmitter.prototype;
Runner.prototype = create(EventEmitter.prototype, {
constructor: Runner
});

/**
* Run tests with full titles matching `re`. Updates runner.total
Expand Down
5 changes: 4 additions & 1 deletion lib/suite.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

var EventEmitter = require('events').EventEmitter;
var Hook = require('./hook');
var create = require('lodash.create');
var debug = require('debug')('mocha:suite');
var milliseconds = require('./ms');
var utils = require('./utils');
Expand Down Expand Up @@ -66,7 +67,9 @@ function Suite(title, parentContext) {
* Inherit from `EventEmitter.prototype`.
*/

Suite.prototype.__proto__ = EventEmitter.prototype;
Suite.prototype = create(EventEmitter.prototype, {
constructor: Suite
});

/**
* Return a clone of this `Suite`.
Expand Down
5 changes: 4 additions & 1 deletion lib/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

var Runnable = require('./runnable');
var create = require('lodash.create');

/**
* Expose `Test`.
Expand All @@ -27,4 +28,6 @@ function Test(title, fn) {
* Inherit from `Runnable.prototype`.
*/

Test.prototype.__proto__ = Runnable.prototype;
Test.prototype = create(Runnable.prototype, {
constructor: Test
});
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@
"glob": "3.2.3",
"growl": "1.8.1",
"jade": "0.26.3",
"lodash.create": "^3.1.1",
"mkdirp": "0.5.0",
"supports-color": "1.2.0"
},
Expand Down
16 changes: 1 addition & 15 deletions support/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ args.forEach(function(file){
*/

function parse(js) {
return parseRequires(parseInheritance(js));
return parseRequires(js);
}

/**
Expand All @@ -52,20 +52,6 @@ function parseRequires(js) {
.replace(/require\('fs'\)/g , "require('browser/fs')");
}

/**
* Parse __proto__.
*/

function parseInheritance(js) {
return js
.replace(/^ *(\w+)\.prototype\.__proto__ * = *(\w+)\.prototype *;?/gm, function(_, child, parent){
return 'function F(){};\n'
+ 'F.prototype = ' + parent + '.prototype;\n'
+ child + '.prototype = new F;\n'
+ child + '.prototype.constructor = '+ child + ';\n';
});
}

/**
* Compile the files.
*/
Expand Down