Skip to content

Commit

Permalink
splits eval as key tests into browser and node test runs.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbildner committed Feb 23, 2015
1 parent 0ec9e03 commit b9b3a43
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 16 deletions.
28 changes: 18 additions & 10 deletions tests/unit/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1142,22 +1142,30 @@ exports.testUnCleanedForinifcheckneeded = function (test) {

// gh-738 "eval" as an object key should not cause `W061` warnngs
exports.testPermitEvalAsKey = function (test) {
var src = fs.readFileSync(__dirname + "/fixtures/gh-738.js", "utf8");
var srcNode = fs.readFileSync(__dirname + "/fixtures/gh-738-node.js", "utf8");
var srcBrowser = fs.readFileSync(__dirname + "/fixtures/gh-738-browser.js", "utf8");
// global calls to eval should still cause warning.
// test a mixture of permitted and disallowed calls
// `global#eval` in `node:true` should still cause warning
// `(document|window)#eval` in `browser:true` should still cause warning

// browser globals
TestRun(test)
.addError(21, "eval can be harmful.")
.addError(22, "eval can be harmful.")
.addError(23, "eval can be harmful.")
.addError(25, "eval can be harmful.")
.addError(26, "eval can be harmful.")
.addError(28, "eval can be harmful.")
.addError(29, "eval can be harmful.")
.addError(31, "eval can be harmful.")
.test(src, { browser: true, node: true });
.addError(17, "eval can be harmful.")
.addError(19, "eval can be harmful.")
.addError(20, "eval can be harmful.")
.addError(22, "eval can be harmful.")
.addError(23, "eval can be harmful.")
.addError(25, "eval can be harmful.")
.test(srcBrowser, { browser: true });

// node globals
TestRun(test)
.addError(18, "eval can be harmful.")
.addError(19, "eval can be harmful.")
.addError(20, "eval can be harmful.")
.addError(22, "eval can be harmful.")
.test(srcNode, { node: true });

test.done();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/* jshint browser:true */
/* jshint node:true */

// object with "eval" key
var obj = {
eval: function (str) {
Expand All @@ -17,9 +14,6 @@ var obj = {
obj["eval"]("console.log('hello world');");
obj.eval("console.log('hello world');");

// global use, forbidden
global["eval"]("console.log('hello world');");
global.eval("1+1");
eval("console.log('hello world');");

window.eval("4+2");
Expand Down
22 changes: 22 additions & 0 deletions tests/unit/fixtures/gh-738-node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// object with "eval" key
var obj = {
eval: function (str) {
return str;
},
wrapper: function (str) {
// method calling "eval" key from context
// permitted use
return this.eval(str);
}
};

// object-key use, permitted
obj["eval"]("console.log('hello world');");
obj.eval("console.log('hello world');");

// global use, forbidden
global["eval"]("console.log('hello world');");
global.eval("1+1");
eval("console.log('hello world');");

this.eval("2+2");

0 comments on commit b9b3a43

Please sign in to comment.