mirror of
https://github.com/facebookarchive/prepack.git
synced 2024-10-26 23:32:02 +03:00
Fix additional functions refactor
Summary: Fix for bug NTillmann encountered with the additional functions refactor. Every function references itself through its `arguments`, so additional functions were recursively trying to visit themselves while visiting their arguments. It doesn't make sense to visit a function from its own scope, so we add a check to the visitor preventing this. Closes https://github.com/facebook/prepack/pull/1508 Differential Revision: D7130078 Pulled By: cblappert fbshipit-source-id: ecb0497456169f3ff41c89f2fcf17e3ae9670d96
This commit is contained in:
parent
69ebd09e8d
commit
2b600a3d56
@ -786,10 +786,12 @@ export class ResidualHeapVisitor {
|
||||
} else if (val instanceof FunctionValue) {
|
||||
// Function declarations should get hoisted in common scope so that instances only get allocated once
|
||||
let parentScope = this.scope;
|
||||
this._withScope(this.commonScope, () => {
|
||||
invariant(val instanceof FunctionValue);
|
||||
if (this.preProcessValue(val)) this.visitValueFunction(val, parentScope);
|
||||
});
|
||||
// Every function references itself through arguments, prevent the recursive double-visit
|
||||
if (this.scope !== val && this.commonScope !== val)
|
||||
this._withScope(this.commonScope, () => {
|
||||
invariant(val instanceof FunctionValue);
|
||||
if (this.preProcessValue(val)) this.visitValueFunction(val, parentScope);
|
||||
});
|
||||
} else if (val instanceof SymbolValue) {
|
||||
if (this.preProcessValue(val)) this.visitValueSymbol(val);
|
||||
} else {
|
||||
|
15
test/serializer/additional-functions/self_referential.js
Normal file
15
test/serializer/additional-functions/self_referential.js
Normal file
@ -0,0 +1,15 @@
|
||||
// does not contain:x = 5;
|
||||
|
||||
function func1() {
|
||||
let x = 5;
|
||||
let z = [ func1 ];
|
||||
return z;
|
||||
}
|
||||
|
||||
if (global.__registerAdditionalFunctionToPrepack) {
|
||||
__registerAdditionalFunctionToPrepack(func1);
|
||||
}
|
||||
|
||||
inspect = function() {
|
||||
return func1()[0] === func1()[0];
|
||||
}
|
Loading…
Reference in New Issue
Block a user