JS: fix remaining tests. Suppress extensionFromTopLevelUnitOneStringArg.kt, use another approach to check whether object's property accessed via this

This commit is contained in:
Alexey Andreev
2016-09-06 12:10:51 +03:00
parent 44f7a94380
commit 0c3c2af76d
3 changed files with 45 additions and 8 deletions
@@ -173,6 +173,42 @@ public class DirectiveTestUtils {
}
};
private static final DirectiveHandler ONLY_THIS_QUALIFIED_REFERENCES = new DirectiveHandler("ONLY_THIS_QUALIFIED_REFERENCES") {
@Override
void processEntry(@NotNull JsNode ast, @NotNull ArgumentsHelper arguments) throws Exception {
String fieldName = arguments.getPositionalArgument(0);
QualifiedReferenceCollector collector = new QualifiedReferenceCollector(fieldName);
ast.accept(collector);
assertTrue("No reference to field '" + fieldName + "' found", collector.hasReferences);
assertTrue("There are references to field '" + fieldName + "' not qualified by 'this' literal",
collector.allReferencesQualifiedByThis);
}
};
static class QualifiedReferenceCollector extends RecursiveJsVisitor {
private final String nameToSearch;
boolean hasReferences;
boolean allReferencesQualifiedByThis = true;
public QualifiedReferenceCollector(String nameToSearch) {
this.nameToSearch = nameToSearch;
}
@Override
public void visitNameRef(@NotNull JsNameRef nameRef) {
super.visitNameRef(nameRef);
JsName name = nameRef.getName();
if (name == null) return;
if (name.getIdent().equals(nameToSearch)) {
hasReferences = true;
if (!(nameRef.getQualifier() instanceof JsLiteral.JsThisRef)) {
allReferencesQualifiedByThis = false;
}
}
}
}
private static final DirectiveHandler HAS_INLINE_METADATA = new DirectiveHandler("CHECK_HAS_INLINE_METADATA") {
@Override
void processEntry(@NotNull JsNode ast, @NotNull ArgumentsHelper arguments) throws Exception {
@@ -199,6 +235,7 @@ public class DirectiveTestUtils {
FUNCTION_CALLED_IN_SCOPE,
FUNCTION_NOT_CALLED_IN_SCOPE,
FUNCTIONS_HAVE_SAME_LINES,
ONLY_THIS_QUALIFIED_REFERENCES,
COUNT_LABELS,
COUNT_VARS,
COUNT_BREAKS,
@@ -20,7 +20,12 @@ fun box(): String {
if (a.result != "OK") return a.result
// TODO: uncomment when KT-13312 gets fixed
/*
val a1 = A()
run(a1, "OK", A::foo)
return a.result
if (a1.result != "OK) return a1.result
*/
return "OK"
}
@@ -1,18 +1,13 @@
// ONLY_THIS_QUALIFIED_REFERENCES: foo_qltb3l$
package foo
object A {
private val foo = 23
fun bar(): Int {
// Erase object so that we ensure that access to 'foo' property is performed via 'this'
// It's no crucial from runtime standpoind, but JS code looks more concise and natural this way.
erase()
return foo
}
fun erase() {
js("_.foo.A = null")
}
}
fun box(): String {