Skip to content

Commit 392767a

Browse files
committed
Fixes #3143 -- Potential memory leaks caused by use of fat arrow next to other (non-fat-arrow-using) long-lived closures.
1 parent 928f949 commit 392767a

File tree

2 files changed

+66
-55
lines changed

2 files changed

+66
-55
lines changed

lib/coffee-script/nodes.js

+55-50
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/nodes.coffee

+11-5
Original file line numberDiff line numberDiff line change
@@ -1288,6 +1288,15 @@ exports.Code = class Code extends Base
12881288
# arrow, generates a wrapper that saves the current value of `this` through
12891289
# a closure.
12901290
compileNode: (o) ->
1291+
1292+
# Handle bound functions early.
1293+
if @bound and not @wrapped and not @static
1294+
@wrapped = yes
1295+
wrapper = new Code [new Param new Literal '_this'], new Block [this]
1296+
boundfunc = new Call(wrapper, [new Literal 'this'])
1297+
boundfunc.updateLocationDataIfMissing @locationData
1298+
return boundfunc.compileNode(o)
1299+
12911300
o.scope = new Scope o.scope, @body, this
12921301
o.scope.shared = del(o, 'sharedScope')
12931302
o.indent += TAB
@@ -1327,11 +1336,8 @@ exports.Code = class Code extends Base
13271336
node.error "multiple parameters named '#{name}'" if name in uniqs
13281337
uniqs.push name
13291338
@body.makeReturn() unless wasEmpty or @noReturn
1330-
if @bound
1331-
if o.scope.parent.method?.bound
1332-
@bound = @context = o.scope.parent.method.context
1333-
else if not @static
1334-
o.scope.parent.assign '_this', 'this'
1339+
if @bound and o.scope.parent.method?.bound
1340+
@bound = @context = o.scope.parent.method.context
13351341
idt = o.indent
13361342
code = 'function'
13371343
code += ' ' + @name if @ctor

0 commit comments

Comments
 (0)