Skip to content

Commit

Permalink
[NTI] Fix crash with invalid function bind.
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=127578737
  • Loading branch information
dimvar authored and blickly committed Jul 15, 2016
1 parent f476227 commit af9cf94
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/com/google/javascript/jscomp/GlobalTypeInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
import com.google.javascript.rhino.TypeI;
import com.google.javascript.rhino.TypeIRegistry;
import com.google.javascript.rhino.jstype.JSTypeNative;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
Expand Down Expand Up @@ -2160,7 +2159,8 @@ private DeclaredFunctionType getDeclaredFunctionTypeFromContext(
if (NodeUtil.isFunctionBind(maybeBind) && !NodeUtil.isGoogPartial(maybeBind)) {
Node call = maybeBind.getParent();
Bind bindComponents = convention.describeFunctionBind(call, true, false);
JSType recvType = simpleInferExprType(bindComponents.thisValue);
JSType recvType = bindComponents.thisValue == null
? null : simpleInferExprType(bindComponents.thisValue);
if (recvType == null) {
return null;
}
Expand Down
4 changes: 4 additions & 0 deletions test/com/google/javascript/jscomp/NewTypeInferenceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12799,6 +12799,10 @@ public void testFunctionBind() {
" this.p = 123;",
"}",
"(function(x) { this.p - x; }).bind(new Foo, 321);"));

typeCheck(
"(function() {}).bind();",
NewTypeInference.WRONG_ARGUMENT_COUNT);
}

public void testClosureStyleFunctionBind() {
Expand Down

0 comments on commit af9cf94

Please sign in to comment.