Show correct lineNumber in require() errors on Nashorn (JRE8)
This commit is contained in:
parent
fce28567e6
commit
b7352ed962
2 changed files with 28 additions and 16 deletions
|
@ -60,7 +60,7 @@ module specification, the '.js' suffix is optional.
|
||||||
[cjsmodules]: http://wiki.commonjs.org/wiki/Modules/1.1.1.
|
[cjsmodules]: http://wiki.commonjs.org/wiki/Modules/1.1.1.
|
||||||
|
|
||||||
***/
|
***/
|
||||||
(function ( rootDir, modulePaths, hooks ) {
|
(function ( rootDir, modulePaths, hooks, evaluate ) {
|
||||||
|
|
||||||
var File = java.io.File,
|
var File = java.io.File,
|
||||||
FileReader = java.io.FileReader,
|
FileReader = java.io.FileReader,
|
||||||
|
@ -242,8 +242,12 @@ When resolving module names to file paths, ScriptCraft uses the following rules.
|
||||||
}
|
}
|
||||||
var compiledWrapper = null;
|
var compiledWrapper = null;
|
||||||
try {
|
try {
|
||||||
compiledWrapper = eval(code);
|
compiledWrapper = evaluate(code);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
/*
|
||||||
|
wph 20140313 JRE8 (nashorn) gives misleading linenumber of evaluating code not evaluated code.
|
||||||
|
This can be fixed by instead using __engine.eval
|
||||||
|
*/
|
||||||
throw new Error( "Error evaluating module " + path
|
throw new Error( "Error evaluating module " + path
|
||||||
+ " line #" + e.lineNumber
|
+ " line #" + e.lineNumber
|
||||||
+ " : " + e.message, canonizedFilename, e.lineNumber );
|
+ " : " + e.message, canonizedFilename, e.lineNumber );
|
||||||
|
|
|
@ -428,7 +428,9 @@ function __onEnable ( __engine, __plugin, __script )
|
||||||
BufferedReader = java.io.BufferedReader,
|
BufferedReader = java.io.BufferedReader,
|
||||||
PrintWriter = java.io.PrintWriter,
|
PrintWriter = java.io.PrintWriter,
|
||||||
FileWriter = java.io.FileWriter;
|
FileWriter = java.io.FileWriter;
|
||||||
|
var debug = function(msg){
|
||||||
|
java.lang.System.out.println('DEBUG:' + msg);
|
||||||
|
};
|
||||||
var _canonize = function( file ) {
|
var _canonize = function( file ) {
|
||||||
return '' + file.getCanonicalPath().replaceAll( '\\\\', '/' );
|
return '' + file.getCanonicalPath().replaceAll( '\\\\', '/' );
|
||||||
};
|
};
|
||||||
|
@ -457,14 +459,13 @@ function __onEnable ( __engine, __plugin, __script )
|
||||||
out.close();
|
out.close();
|
||||||
};
|
};
|
||||||
/*
|
/*
|
||||||
make sure eval is present
|
make sure eval is present: it's present on JRE 6, 7, and 8 on Linux
|
||||||
*/
|
*/
|
||||||
if ( typeof eval == 'undefined' ) {
|
if ( typeof eval == 'undefined' ) {
|
||||||
global.eval = function( str ) {
|
global.eval = function( str ) {
|
||||||
return __engine.eval( str );
|
return __engine.eval( str );
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Load the contents of the file and evaluate as javascript
|
Load the contents of the file and evaluate as javascript
|
||||||
*/
|
*/
|
||||||
|
@ -593,7 +594,14 @@ function __onEnable ( __engine, __plugin, __script )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
global.require = configRequire( jsPluginsRootDirName, modulePaths, requireHooks );
|
global.require = configRequire(
|
||||||
|
jsPluginsRootDirName,
|
||||||
|
modulePaths,
|
||||||
|
requireHooks,
|
||||||
|
function(code){
|
||||||
|
return __engine.eval(code);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
require('js-patch')( global );
|
require('js-patch')( global );
|
||||||
global.console = require('console');
|
global.console = require('console');
|
||||||
|
|
Reference in a new issue