Skip to content

Commit

Permalink
Do not attempt to create implicit vars in the global scope.
Browse files Browse the repository at this point in the history
Fixes a rare stack overflow error.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=189643811
  • Loading branch information
tbreisacher authored and brad4d committed Mar 20, 2018
1 parent c28b1bd commit e97a14b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/com/google/javascript/jscomp/TypedScope.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ TypedVar declare(String name, Node nameNode,

@Override
TypedVar makeImplicitVar(ImplicitVar var) {
if (this.isGlobal()) {
// TODO(sdh): This is incorrect for 'global this', but since that's currently not handled
// by this code, it's okay to bail out now until we find the root cause. See b/74980936.
return null;
}
return new TypedVar(false, var.name, null, getImplicitVarType(var), this, -1, null);
}

Expand Down
23 changes: 23 additions & 0 deletions test/com/google/javascript/jscomp/TypedScopeCreatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2091,6 +2091,29 @@ public void testGenerator2() {
assertEquals("Generator<?>", findNameType("g", globalScope).toString());
}

// Just check that this doesn't cause a StackOverflowError.
public void testArgumentsStackOverflow() {
String js = lines(
"/**",
" * @fileoverview",
" * @suppress {es5Strict}",
" */",
"",
"function getStackTrace() {",
" try {",
" throw new Error();",
" } catch (e) {",
" return 0;",
" }",
"",
" if (typeof (arguments.caller) != 'undefined') {}",
"",
" return '';",
"}",
"");
testSame(js);
}

public void testMemoization() throws Exception {
Node root1 = createEmptyRoot();
Node root2 = createEmptyRoot();
Expand Down

0 comments on commit e97a14b

Please sign in to comment.