Skip to content

Commit

Permalink
Merge pull request #1951 from alubbe/fix-memory-leak
Browse files Browse the repository at this point in the history
fixed memory leak caused by compileDebug flag
  • Loading branch information
ForbesLindesay committed May 18, 2015
2 parents 8a7c718 + 23fe2df commit f2a1882
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
6 changes: 3 additions & 3 deletions lib/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,11 @@ Compiler.prototype = {
var debug = this.debug;

if (debug) {
this.buf.push('jade_debug.unshift({ lineno: ' + node.line
+ ', filename: ' + (node.filename
this.buf.push('jade_debug.unshift(new jade.DebugItem( ' + node.line
+ ', ' + (node.filename
? utils.stringify(node.filename)
: 'jade_debug[0].filename')
+ ' });');
+ ' ));');
}

// Massive hack to fix our context
Expand Down
4 changes: 2 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ exports.compile = function(str, options){
var parsed = parse(str, options);
if (options.compileDebug !== false) {
fn = [
'var jade_debug = [{ lineno: 1, filename: ' + filename + ' }];'
'var jade_debug = [ new jade.DebugItem( 1, ' + filename + ' ) ];'
, 'try {'
, parsed.body
, '} catch (err) {'
Expand Down Expand Up @@ -256,7 +256,7 @@ exports.compileClientWithDependenciesTracked = function(str, options){
var parsed = parse(str, options);
if (options.compileDebug) {
fn = [
'var jade_debug = [{ lineno: 1, filename: ' + filename + ' }];'
'var jade_debug = [ new jade.DebugItem( 1, ' + filename + ' ) ];'
, 'try {'
, parsed.body
, '} catch (err) {'
Expand Down
5 changes: 5 additions & 0 deletions lib/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,3 +230,8 @@ exports.rethrow = function rethrow(err, filename, lineno, str){
+ '\n' + context + '\n\n' + err.message;
throw err;
};

exports.DebugItem = function DebugItem(lineno, filename) {
this.lineno = lineno;
this.filename = filename;
}
12 changes: 10 additions & 2 deletions test/unit.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

var runtime = require('../lib/runtime')
, merge = runtime.merge;
, merge = runtime.merge
, DebugItem = runtime.DebugItem;

describe('merge(a, b, escaped)', function(){
it('should merge classes into strings', function(){
Expand Down Expand Up @@ -37,4 +38,11 @@ describe('merge(a, b, escaped)', function(){
merge({ class: ['foo', null, 'bar'] }, { class: [undefined, null, 0, 'baz'] })
.should.eql({ class: ['foo', 'bar', 0, 'baz'] });
})
})
})

describe('DebugItem', function(){
it('should instantiate objects with lineno and filename properties', function(){
new DebugItem(42, "/path/to/file")
.should.eql({ lineno: 42, filename: "/path/to/file" });
})
})

0 comments on commit f2a1882

Please sign in to comment.