diff --git a/sdk/lib/_internal/lib/js_mirrors.dart b/sdk/lib/_internal/lib/js_mirrors.dart index 3ddd2dc3261..1d1c8252fed 100644 --- a/sdk/lib/_internal/lib/js_mirrors.dart +++ b/sdk/lib/_internal/lib/js_mirrors.dart @@ -834,11 +834,20 @@ class JsMethodMirror extends JsDeclarationMirror implements MethodMirror { return _metadata.map(reflect).toList(); } + Symbol get constructorName { + // TODO(ahe): I believe it is more appropriate to throw an exception or + // return null. + if (!isConstructor) return const Symbol(''); + String name = n(simpleName); + int index = name.indexOf('.'); + if (index == -1) return const Symbol(''); + return s(name.substring(index + 1)); + } + // TODO(ahe): Implement these. bool get isAbstract => throw new UnimplementedError(); bool get isRegularMethod => throw new UnimplementedError(); bool get isOperator => throw new UnimplementedError(); - Symbol get constructorName => throw new UnimplementedError(); bool get isConstConstructor => throw new UnimplementedError(); bool get isGenerativeConstructor => throw new UnimplementedError(); bool get isRedirectingConstructor => throw new UnimplementedError(); diff --git a/tests/lib/mirrors/constructors_test.dart b/tests/lib/mirrors/constructors_test.dart index 89fc8747862..b42472f2016 100644 --- a/tests/lib/mirrors/constructors_test.dart +++ b/tests/lib/mirrors/constructors_test.dart @@ -52,4 +52,14 @@ main() { for (var constructor in bizConstructors.values) { expect('[]', constructor.parameters); } + + expect('[s()]', + fooConstructors.values.map((m) => m.constructorName).toList()); + expect('[s()]', + barConstructors.values.map((m) => m.constructorName).toList()); + expect('[s(named)]', + bazConstructors.values.map((m) => m.constructorName).toList()); + expect('[s(), s(named)]', + bizConstructors.values.map((m) => m.constructorName).toList() + ..sort(compareSymbols)); } diff --git a/tests/lib/mirrors/stringify.dart b/tests/lib/mirrors/stringify.dart index ba5407bef5f..e8c31a8ad9f 100644 --- a/tests/lib/mirrors/stringify.dart +++ b/tests/lib/mirrors/stringify.dart @@ -103,3 +103,7 @@ stringify(value) { } expect(expected, actual) => Expect.stringEquals(expected, stringify(actual)); + +compareSymbols(Symbol a, Symbol b) { + return MirrorSystem.getName(a).compareTo(MirrorSystem.getName(b)); +}