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.
|
||||
|
||||
***/
|
||||
(function ( rootDir, modulePaths, hooks ) {
|
||||
(function ( rootDir, modulePaths, hooks, evaluate ) {
|
||||
|
||||
var File = java.io.File,
|
||||
FileReader = java.io.FileReader,
|
||||
|
@ -242,8 +242,12 @@ When resolving module names to file paths, ScriptCraft uses the following rules.
|
|||
}
|
||||
var compiledWrapper = null;
|
||||
try {
|
||||
compiledWrapper = eval(code);
|
||||
compiledWrapper = evaluate(code);
|
||||
} 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
|
||||
+ " line #" + e.lineNumber
|
||||
+ " : " + e.message, canonizedFilename, e.lineNumber );
|
||||
|
|
|
@ -428,7 +428,9 @@ function __onEnable ( __engine, __plugin, __script )
|
|||
BufferedReader = java.io.BufferedReader,
|
||||
PrintWriter = java.io.PrintWriter,
|
||||
FileWriter = java.io.FileWriter;
|
||||
|
||||
var debug = function(msg){
|
||||
java.lang.System.out.println('DEBUG:' + msg);
|
||||
};
|
||||
var _canonize = function( file ) {
|
||||
return '' + file.getCanonicalPath().replaceAll( '\\\\', '/' );
|
||||
};
|
||||
|
@ -457,14 +459,13 @@ function __onEnable ( __engine, __plugin, __script )
|
|||
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' ) {
|
||||
global.eval = function( str ) {
|
||||
return __engine.eval( str );
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
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 );
|
||||
global.console = require('console');
|
||||
|
|
Reference in a new issue