mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
This commit is contained in:
parent
bbf37e5229
commit
e4f47a05f6
3 changed files with 14 additions and 3 deletions
|
@ -60,7 +60,7 @@
|
|||
}
|
||||
};
|
||||
exports.eval = function(code, options) {
|
||||
var g, js, sandbox, _i, _len, _ref2;
|
||||
var g, js, k, o, sandbox, v, _i, _len, _ref2;
|
||||
if (options == null) {
|
||||
options = {};
|
||||
}
|
||||
|
@ -82,7 +82,13 @@
|
|||
}
|
||||
sandbox.__filename = options.filename || 'eval';
|
||||
sandbox.__dirname = path.dirname(sandbox.__filename);
|
||||
js = compile("_=(" + (code.trim()) + ")", options);
|
||||
o = {};
|
||||
for (k in options) {
|
||||
v = options[k];
|
||||
o[k] = v;
|
||||
}
|
||||
o.bare = true;
|
||||
js = compile("_=(" + (code.trim()) + ")", o);
|
||||
return vm.runInNewContext(js, sandbox, sandbox.__filename);
|
||||
};
|
||||
lexer = new Lexer;
|
||||
|
|
|
@ -87,7 +87,9 @@ exports.eval = (code, options = {}) ->
|
|||
sandbox.global.global = sandbox.global.root = sandbox.global.GLOBAL = sandbox
|
||||
sandbox.__filename = options.filename || 'eval'
|
||||
sandbox.__dirname = path.dirname sandbox.__filename
|
||||
js = compile "_=(#{code.trim()})", options
|
||||
o = {}; o[k] = v for k, v of options
|
||||
o.bare = on # ensure return value
|
||||
js = compile "_=(#{code.trim()})", o
|
||||
vm.runInNewContext js, sandbox, sandbox.__filename
|
||||
|
||||
# Instantiate a Lexer for our use here.
|
||||
|
|
|
@ -59,3 +59,6 @@ test "#1106: __proto__ compilation", ->
|
|||
object = eq
|
||||
@["__proto__"] = true
|
||||
ok __proto__
|
||||
|
||||
test "eval returns result when bare is false and filename is not set", ->
|
||||
ok 'passed' is CoffeeScript.eval '"passed"'
|
||||
|
|
Loading…
Add table
Reference in a new issue