Skip to content

Commit

Permalink
[NTI] Implement FunctionTypeI#hasProperties() in NTI. Note that this …
Browse files Browse the repository at this point in the history
…is a small change to the OTI behavior, since previously it would return true based on a lazily-initialized prototype property, but since function prototypes are eagerly initialized in NTI and nobody was depending on that specific detail, it's been changed for compatibility.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=165060640
  • Loading branch information
shicks authored and Tyler Breisacher committed Aug 15, 2017
1 parent c43f230 commit 906545e
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/com/google/javascript/jscomp/newtypes/JSType.java
Original file line number Diff line number Diff line change
Expand Up @@ -1936,7 +1936,8 @@ public final List<String> getTypeParameters() {

@Override
public final boolean hasProperties() {
throw new UnsupportedOperationException("hasProperties not implemented yet");
checkState(this.isFunctionType());
return getObjTypeIfSingletonObj().isFunctionWithProperties();
}

@Override
Expand Down
3 changes: 1 addition & 2 deletions src/com/google/javascript/rhino/FunctionTypeI.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,12 @@ public interface FunctionTypeI extends TypeI {
* This is only valid for constructors and interfaces, and will not be
* null. This allows a downward traversal of the subtype graph.
*/
// TODO(sdh): change the name to getDirectSubTypes()
Iterable<FunctionTypeI> getDirectSubTypes();

/** Gets the type of {@code this} in this function. */
TypeI getTypeOfThis();

/** Whether this FunctionTypeI is a function with properties. */
/** Whether this function type has any properties (not counting "prototype"). */
boolean hasProperties();

void setSource(Node n);
Expand Down
3 changes: 0 additions & 3 deletions src/com/google/javascript/rhino/jstype/FunctionType.java
Original file line number Diff line number Diff line change
Expand Up @@ -1425,9 +1425,6 @@ public TypeI convertMethodToFunction() {

@Override
public boolean hasProperties() {
if (prototypeSlot != null) {
return true;
}
return !super.getOwnPropertyNames().isEmpty();
}

Expand Down

0 comments on commit 906545e

Please sign in to comment.