From b19c00468027e6f333cffee792b93abf961fc5b9 Mon Sep 17 00:00:00 2001 From: satyr Date: Tue, 21 Sep 2010 16:53:58 +0900 Subject: [PATCH] made wrapper function keep current `this` --- lib/browser.js | 2 +- lib/cake.js | 2 +- lib/coffee-script.js | 2 +- lib/command.js | 2 +- lib/grammar.js | 2 +- lib/helpers.js | 2 +- lib/index.js | 2 +- lib/lexer.js | 2 +- lib/nodes.js | 4 ++-- lib/optparse.js | 2 +- lib/repl.js | 2 +- lib/rewriter.js | 2 +- lib/scope.js | 2 +- src/nodes.coffee | 2 +- 14 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/browser.js b/lib/browser.js index a9b6c68d..f470e208 100644 --- a/lib/browser.js +++ b/lib/browser.js @@ -39,4 +39,4 @@ attachEvent('onload', processScripts); } } -})(); +}).call(this); diff --git a/lib/cake.js b/lib/cake.js index e9d1aa3e..1544c54f 100755 --- a/lib/cake.js +++ b/lib/cake.js @@ -81,4 +81,4 @@ puts("No such task: \"" + (task) + "\""); return process.exit(1); }; -})(); +}).call(this); diff --git a/lib/coffee-script.js b/lib/coffee-script.js index e95f8b21..b75db804 100755 --- a/lib/coffee-script.js +++ b/lib/coffee-script.js @@ -73,4 +73,4 @@ } }; parser.yy = require('./nodes'); -})(); +}).call(this); diff --git a/lib/command.js b/lib/command.js index f81925e0..a6d5576a 100644 --- a/lib/command.js +++ b/lib/command.js @@ -245,4 +245,4 @@ puts("CoffeeScript version " + (CoffeeScript.VERSION)); return process.exit(0); }; -})(); +}).call(this); diff --git a/lib/grammar.js b/lib/grammar.js index 00fa9714..aee57c6c 100644 --- a/lib/grammar.js +++ b/lib/grammar.js @@ -644,4 +644,4 @@ operators: operators.reverse(), startSymbol: 'Root' }); -})(); +}).call(this); diff --git a/lib/helpers.js b/lib/helpers.js index 7c7e5baa..5bb8d34a 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -96,4 +96,4 @@ delete obj[key]; return val; }); -})(); +}).call(this); diff --git a/lib/index.js b/lib/index.js index f10e70a6..6b65054d 100644 --- a/lib/index.js +++ b/lib/index.js @@ -7,4 +7,4 @@ val = _ref[key]; (exports[key] = val); } -})(); +}).call(this); diff --git a/lib/lexer.js b/lib/lexer.js index ad2615f8..ec05b88f 100644 --- a/lib/lexer.js +++ b/lib/lexer.js @@ -654,4 +654,4 @@ 'not': '!', '===': '==' }; -})(); +}).call(this); diff --git a/lib/nodes.js b/lib/nodes.js index 896ade10..02b0b87d 100644 --- a/lib/nodes.js +++ b/lib/nodes.js @@ -233,7 +233,7 @@ o.scope = new Scope(null, this, null); code = this.compileWithDeclarations(o); code = code.replace(TRAILING_WHITESPACE, ''); - return o.noWrap ? code : ("(function() {\n" + (code) + "\n})();\n"); + return o.noWrap ? code : ("(function() {\n" + (code) + "\n}).call(this);\n"); }; Expressions.prototype.compileWithDeclarations = function(o) { var code; @@ -1971,4 +1971,4 @@ Scope.root.assign(ref, UTILITIES[name]); return ref; }; -})(); +}).call(this); diff --git a/lib/optparse.js b/lib/optparse.js index 5b63a8ad..2bfde43e 100755 --- a/lib/optparse.js +++ b/lib/optparse.js @@ -112,4 +112,4 @@ } return result; }; -})(); +}).call(this); diff --git a/lib/repl.js b/lib/repl.js index bb62ff45..e0903b23 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -35,4 +35,4 @@ }); repl.on('line', run); repl.prompt(); -})(); +}).call(this); diff --git a/lib/rewriter.js b/lib/rewriter.js index 8d6e0a0a..05d7be22 100644 --- a/lib/rewriter.js +++ b/lib/rewriter.js @@ -416,4 +416,4 @@ SINGLE_LINERS = ['ELSE', "->", "=>", 'TRY', 'FINALLY', 'THEN']; SINGLE_CLOSERS = ['TERMINATOR', 'CATCH', 'FINALLY', 'ELSE', 'OUTDENT', 'LEADING_WHEN']; LINEBREAKS = ['TERMINATOR', 'INDENT', 'OUTDENT']; -})(); +}).call(this); diff --git a/lib/scope.js b/lib/scope.js index 6719df37..6396d525 100644 --- a/lib/scope.js +++ b/lib/scope.js @@ -134,4 +134,4 @@ }; return Scope; }).call(this); -})(); +}).call(this); diff --git a/src/nodes.coffee b/src/nodes.coffee index 075ced69..77c4e0ed 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -210,7 +210,7 @@ exports.Expressions = class Expressions extends BaseNode o.scope = new Scope(null, this, null) code = @compileWithDeclarations(o) code = code.replace(TRAILING_WHITESPACE, '') - if o.noWrap then code else "(function() {\n#{code}\n})();\n" + if o.noWrap then code else "(function() {\n#{code}\n}).call(this);\n" # Compile the expressions body for the contents of a function, with # declarations of all inner variables pushed up to the top.