96 lines
2.9 KiB
Diff
96 lines
2.9 KiB
Diff
--- ../node/lib/module.js 2013-08-22 13:55:28.000000000 +0200
|
|
+++ src/main/js/lib/module.js 2013-12-20 17:16:24.000000000 +0100
|
|
@@ -271,13 +271,20 @@
|
|
return [id, [path.dirname(parent.filename)]];
|
|
};
|
|
|
|
+var AccessController = java.security.AccessController;
|
|
+var PrivilegedAction = java.security.PrivilegedAction;
|
|
+var Server = Packages.com.oracle.avatar.js.Server;
|
|
|
|
Module._load = function(request, parent, isMain) {
|
|
if (parent) {
|
|
debug('Module._load REQUEST ' + (request) + ' parent: ' + parent.id);
|
|
}
|
|
|
|
- var filename = Module._resolveFilename(request, parent);
|
|
+ var filename = AccessController.doPrivileged(new PrivilegedAction() {
|
|
+ run: function() {
|
|
+ return Module._resolveFilename(request, parent);
|
|
+ }
|
|
+ });
|
|
|
|
var cachedModule = Module._cache[filename];
|
|
if (cachedModule) {
|
|
@@ -288,7 +295,12 @@
|
|
// REPL is a special case, because it needs the real require.
|
|
if (filename == 'repl') {
|
|
var replModule = new Module('repl');
|
|
- replModule._compile(NativeModule.getSource('repl'), 'repl.js');
|
|
+ AccessController.doPrivileged(new PrivilegedAction() {
|
|
+ run: function() {
|
|
+ replModule._compile(null, Server.getResource('/lib/repl.js'));
|
|
+ }
|
|
+ });
|
|
+
|
|
NativeModule._cache.repl = replModule;
|
|
return replModule.exports;
|
|
}
|
|
@@ -309,7 +321,11 @@
|
|
var hadException = true;
|
|
|
|
try {
|
|
+ AccessController.doPrivileged(new PrivilegedAction() {
|
|
+ run: function() {
|
|
module.load(filename);
|
|
+ }
|
|
+ });
|
|
hadException = false;
|
|
} finally {
|
|
if (hadException) {
|
|
@@ -373,8 +389,11 @@
|
|
// Returns exception if any
|
|
Module.prototype._compile = function(content, filename) {
|
|
var self = this;
|
|
+
|
|
// remove shebang
|
|
+ if(content != null) {
|
|
content = content.replace(/^\#\!.*/, '');
|
|
+ }
|
|
|
|
function require(path) {
|
|
return self.require(path);
|
|
@@ -434,7 +453,10 @@
|
|
}
|
|
|
|
// create wrapper function
|
|
- var wrapper = Module.wrap(content);
|
|
+ var wrapper = null;
|
|
+ if(content != null) {
|
|
+ wrapper = Module.wrap(content);
|
|
+ }
|
|
|
|
var compiledWrapper = runInThisContext(wrapper, filename, true);
|
|
if (global.v8debug) {
|
|
@@ -470,8 +492,7 @@
|
|
|
|
// Native extension for .js
|
|
Module._extensions['.js'] = function(module, filename) {
|
|
- var content = NativeModule.require('fs').readFileSync(filename, 'utf8');
|
|
- module._compile(stripBOM(content), filename);
|
|
+ module._compile(null, filename);
|
|
};
|
|
|
|
|
|
@@ -508,7 +529,9 @@
|
|
var homeDir = process.env.HOME;
|
|
}
|
|
|
|
- var paths = [path.resolve(process.execPath, '..', '..', 'lib', 'node')];
|
|
+ // Avatar.js: we do not install modules relative to the node.jar location
|
|
+ // but we look for modules (and test scripts) relative to the current dir)
|
|
+ var paths = [process.cwd()]; // [path.resolve(process.execPath, '..', '..', 'lib', 'node')];
|
|
|
|
if (homeDir) {
|
|
paths.unshift(path.resolve(homeDir, '.node_libraries'));
|