Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Commit

Permalink
Fix issue #1732 heapGraph crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
David Cai committed May 24, 2018
1 parent d1fd297 commit 4c5bc2f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
1 change: 1 addition & 0 deletions scripts/test-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ function runTest(name, code, options: PrepackOptions, args) {
options.invariantLevel = code.includes("// omit invariants") || args.verbose ? 0 : 99;
if (code.includes("// emit concrete model")) options.emitConcreteModel = true;
if (code.includes("// exceeds stack limit")) options.maxStackDepth = 10;
if (code.includes("// heapGraphFilePath")) options.heapGraphFormat = "VISJS";
if (code.includes("// react")) {
options.reactEnabled = true;
options.reactOutput = "jsx";
Expand Down
4 changes: 4 additions & 0 deletions src/serializer/serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ export class Serializer {
additionalFunctionValuesAndEffects,
referentializer
);
// Copying dERB map so cache lookup returns the same object, and the subsequent
// invariant in ModifiedBindingEntry's visit() passes.
heapRefCounter.declarativeEnvironmentRecordsBindings = residualHeapVisitor.declarativeEnvironmentRecordsBindings;
heapRefCounter.visitRoots();

const heapGraphGenerator = new ResidualHeapGraphGenerator(
Expand All @@ -193,6 +196,7 @@ export class Serializer {
heapRefCounter.getResult(),
referentializer
);
heapGraphGenerator.declarativeEnvironmentRecordsBindings = residualHeapVisitor.declarativeEnvironmentRecordsBindings;
heapGraphGenerator.visitRoots();
invariant(this.options.heapGraphFormat);
heapGraph = heapGraphGenerator.generateResult(this.options.heapGraphFormat);
Expand Down
5 changes: 3 additions & 2 deletions src/utils/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,11 @@ class ModifiedBindingEntry extends GeneratorEntry {
containingGenerator === this.containingGenerator,
"This entry requires effects to be applied and may not be moved"
);
invariant(this.modifiedBinding.value === this.newValue);
invariant(this.modifiedBinding.value === this.newValue, "ModifiedBinding's value has been improperly modified.");
let [residualBinding, newValue] = context.visitModifiedBinding(this.modifiedBinding);
invariant(this.residualFunctionBinding === undefined || this.residualFunctionBinding === residualBinding);
invariant(this.residualFunctionBinding === undefined || this.residualFunctionBinding === residualBinding, "ResidualFunctionBinding improperly mutated");
this.residualFunctionBinding = residualBinding;
this.modifiedBinding.value = newValue;
this.newValue = newValue;
return true;
}
Expand Down
18 changes: 18 additions & 0 deletions test/serializer/additional-functions/heapGraph.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Tests that code with heapgraph enabled doesn't crash.
// Regression test for issue #1732.

// heapGraphFilePath

(function () {
let a = global.__abstract ? __abstract("number", "5") : 5;
let b, c;
global.f = function() {
b = a + 42;
c = a + 42;
return b;
}
global.__optimize && __optimize(f);

})();

inspect = function() { return global.f(); }

0 comments on commit 4c5bc2f

Please sign in to comment.