Permalink
Browse files

removed warnings for node >= v0.3.2

  • Loading branch information...
1 parent 74e30c7 commit a7037e72a23e905e7ce35356222646f652fabdc2 Julien Polo committed Jan 3, 2011
Showing with 23 additions and 18 deletions.
  1. +12 −10 lib/lint/formatter/callback.js
  2. +11 −8 lib/lint/parser.js
@@ -3,12 +3,16 @@
* Import
*/
var util = require(process.binding('natives').util ? 'util' : 'sys');
-var Script = process.binding('evals').Script;
+var runScript = process.binding('natives').vm ? require('vm').runInNewContext : function (code, sandbox, filename) {
+ var scriptObj = new process.binding('evals').Script(code, filename);
+
+ return scriptObj.runInNewContext(sandbox);
+};
var formatter = require('../formatter');
/**
* Formatter constructor
- *
+ *
* @constructor
* @extends lint.formatter.Base
* @param {Object} options
@@ -17,14 +21,14 @@ function Formatter(options) {
options = options || {};
this._callback = null;
this._callbackName = 'format';
-
+
formatter.Base.call(this, options);
}
util.inherits(Formatter, formatter.Base);
/**
* Configure the Formatter
- *
+ *
* @param {Object} options
* @return this
*/
@@ -36,14 +40,12 @@ Formatter.prototype.configure = function (options) {
if (options.callback !== undefined) {
if (typeof(options.callback) === 'string') {
var scriptObj, env;
-
+
env = {};
- scriptObj = new Script(options.callback, __filename);
- scriptObj.runInNewContext(env);
-
+ runScript(options.callback, env, __filename);
options.callback = env[this._callbackName];
}
-
+
if (typeof(options.callback) === 'function') {
this._callback = options.callback;
} else {
@@ -55,7 +57,7 @@ Formatter.prototype.configure = function (options) {
};
/**
- *
+ *
* @return {string}
*/
Formatter.prototype._formatNormal = function (report) {
View
@@ -6,12 +6,15 @@
*/
var fs = require('fs');
var path = require('path');
+var compile = process.binding('natives').vm ? require('vm').runInThisContext : process.compile;
+
/**
* Constants
*/
var JSLINT_PATH = path.join(path.dirname(fs.realpathSync(__filename)), 'jslint.js');
-process.compile(fs.readFileSync(JSLINT_PATH, 'utf8'), JSLINT_PATH);
+
+compile(fs.readFileSync(JSLINT_PATH, 'utf8'), JSLINT_PATH);
var NODE_CONFIG = {
maxerr: 10000,
@@ -91,7 +94,7 @@ function Parser(options) {
/**
* Configure the parser
- *
+ *
* @param {Object} options
* @return this
*/
@@ -148,7 +151,7 @@ Parser.prototype.validate = function (force) {
if (this._report === null || force) {
config = {};
-
+
//Import default node preferences
if (this._config.node) {
for (property in NODE_CONFIG) {
@@ -157,17 +160,17 @@ Parser.prototype.validate = function (force) {
}
}
}
-
+
//Import configured preferences
for (property in this._config) {
if (this._config.hasOwnProperty(property)) {
config[property] = this._config[property];
}
}
-
-
+
+
result = JSLINT(this._source, config);
-
+
this._report = [];
errors = JSLINT.data().errors || [];
errors.forEach(function (error) {
@@ -233,6 +236,6 @@ exports.isValidFileSync = function isValidFileSync(filePath, options) {
data = fs.readFileSync(filePath);
parser = new Parser(options);
result = parser.update(data).isValid();
-
+
return result;
};

0 comments on commit a7037e7

Please sign in to comment.