fix AST_Function scope invariance (#2052)

improve function name hack in `run_code()`
This commit is contained in:
Alex Lam S.L
2017-06-04 19:27:43 +08:00
committed by GitHub
parent 84634da4b5
commit 540220b91b
4 changed files with 44 additions and 13 deletions

View File

@@ -26,16 +26,18 @@ var FUNC_TOSTRING = [
" var i = this.name;",
' if (typeof i != "number") {',
" i = ++id;",
].concat(Object.getOwnPropertyDescriptor(Function.prototype, "name").configurable ? [
' Object.defineProperty(this, "name", {',
" get: function() {",
" return i;",
" }",
" });",
] : [], [
" }",
' return "[Function: " + i + "]";',
" }",
"}();",
].join("\n");
]).join("\n");
exports.run_code = function(code) {
var stdout = "";
var original_write = process.stdout.write;