mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
Fix issue #3498
This commit is contained in:
@@ -120,24 +120,27 @@
|
||||
};
|
||||
|
||||
exports["eval"] = function(code, options) {
|
||||
var Module, Script, js, k, o, r, sandbox, v, _i, _len, _module, _ref, _ref1, _require;
|
||||
var Module, createContext, isContext, js, k, o, r, sandbox, v, _i, _len, _module, _ref, _ref1, _ref2, _ref3, _require;
|
||||
if (options == null) {
|
||||
options = {};
|
||||
}
|
||||
if (!(code = code.trim())) {
|
||||
return;
|
||||
}
|
||||
Script = vm.Script;
|
||||
if (Script) {
|
||||
createContext = (_ref = vm.Script.createContext) != null ? _ref : vm.createContext;
|
||||
isContext = (_ref1 = vm.isContext) != null ? _ref1 : function(ctx) {
|
||||
return options.sandbox instanceof createContext().constructor;
|
||||
};
|
||||
if (createContext) {
|
||||
if (options.sandbox != null) {
|
||||
if (options.sandbox instanceof Script.createContext().constructor) {
|
||||
if (isContext(options.sandbox)) {
|
||||
sandbox = options.sandbox;
|
||||
} else {
|
||||
sandbox = Script.createContext();
|
||||
_ref = options.sandbox;
|
||||
for (k in _ref) {
|
||||
if (!__hasProp.call(_ref, k)) continue;
|
||||
v = _ref[k];
|
||||
sandbox = createContext();
|
||||
_ref2 = options.sandbox;
|
||||
for (k in _ref2) {
|
||||
if (!__hasProp.call(_ref2, k)) continue;
|
||||
v = _ref2[k];
|
||||
sandbox[k] = v;
|
||||
}
|
||||
}
|
||||
@@ -154,9 +157,9 @@
|
||||
return Module._load(path, _module, true);
|
||||
};
|
||||
_module.filename = sandbox.__filename;
|
||||
_ref1 = Object.getOwnPropertyNames(require);
|
||||
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
||||
r = _ref1[_i];
|
||||
_ref3 = Object.getOwnPropertyNames(require);
|
||||
for (_i = 0, _len = _ref3.length; _i < _len; _i++) {
|
||||
r = _ref3[_i];
|
||||
if (r !== 'paths') {
|
||||
_require[r] = require[r];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user