diff --git a/pkg/dev_compiler/lib/runtime/_errors.js b/pkg/dev_compiler/lib/runtime/_errors.js index 32b6ae01a8e1..0bb1a0f903cd 100644 --- a/pkg/dev_compiler/lib/runtime/_errors.js +++ b/pkg/dev_compiler/lib/runtime/_errors.js @@ -9,23 +9,24 @@ dart_library.library('dart_runtime/_errors', null, /* Imports */[ ], /* Lazy Imports */[ + 'dart_runtime/_operations', 'dart/core', 'dart/_js_helper' -], function(exports, core, _js_helper) { +], function(exports, operations, core, _js_helper) { 'use strict'; function throwNoSuchMethod(obj, name, pArgs, nArgs, extras) { - throw new core.NoSuchMethodError(obj, name, pArgs, nArgs, extras); + operations.throw(new core.NoSuchMethodError(obj, name, pArgs, nArgs, extras)); } exports.throwNoSuchMethod = throwNoSuchMethod; function throwCastError(actual, type) { - throw new _js_helper.CastErrorImplementation(actual, type); + operations.throw(new _js_helper.CastErrorImplementation(actual, type)); } exports.throwCastError = throwCastError; function throwAssertionError() { - throw new core.AssertionError(); + operations.throw(new core.AssertionError()); } exports.throwAssertionError = throwAssertionError; }); diff --git a/pkg/dev_compiler/lib/runtime/_types.js b/pkg/dev_compiler/lib/runtime/_types.js index af5e2d04d24f..482adf4fa1c7 100644 --- a/pkg/dev_compiler/lib/runtime/_types.js +++ b/pkg/dev_compiler/lib/runtime/_types.js @@ -139,6 +139,26 @@ dart_library.library('dart_runtime/_types', null, /* Imports */[ this.args = args; this.optionals = optionals; this.named = named; + + // TODO(vsm): This is just parameter metadata for now. + this.metadata = []; + function process(array, metadata) { + var result = []; + for (var i = 0; i < array.length; ++i) { + var arg = array[i]; + if (arg instanceof Array) { + metadata.push(arg.slice(1)); + result.push(arg[0]); + } else { + metadata.push([]); + result.push(arg); + } + } + return result; + } + this.args = process(this.args, this.metadata); + this.optionals = process(this.optionals, this.metadata); + // TODO(vsm): Add named arguments. this._canonize(); } _canonize() { @@ -202,6 +222,10 @@ dart_library.library('dart_runtime/_types', null, /* Imports */[ get named() { return this.functionType.named; } + + get metadata() { + return this.functionType.metadata; + } } function _functionType(definite, returnType, args, extra) { diff --git a/pkg/dev_compiler/lib/runtime/dart/_js_mirrors.js b/pkg/dev_compiler/lib/runtime/dart/_js_mirrors.js index e9d97229cd45..0051e8d903bb 100644 --- a/pkg/dev_compiler/lib/runtime/dart/_js_mirrors.js +++ b/pkg/dev_compiler/lib/runtime/dart/_js_mirrors.js @@ -53,6 +53,15 @@ dart_library.library('dart/_js_mirrors', null, /* Imports */[ _(reflectee) { this.reflectee = reflectee; } + get type() { + return dart.throw(new core.UnimplementedError("ClassMirror.type unimplemented")); + } + get hasReflectee() { + return dart.throw(new core.UnimplementedError("ClassMirror.hasReflectee unimplemented")); + } + delegate(invocation) { + return dart.throw(new core.UnimplementedError("ClassMirror.delegate unimplemented")); + } getField(symbol) { let name = getName(symbol); let field = _dload(this.reflectee, name); @@ -60,8 +69,8 @@ dart_library.library('dart/_js_mirrors', null, /* Imports */[ } setField(symbol, value) { let name = getName(symbol); - let field = _dput(this.reflectee, name, value); - return new JsInstanceMirror._(field); + _dput(this.reflectee, name, value); + return new JsInstanceMirror._(value); } invoke(symbol, args, namedArgs) { if (namedArgs === void 0) @@ -87,6 +96,7 @@ dart_library.library('dart/_js_mirrors', null, /* Imports */[ dart.setSignature(JsInstanceMirror, { constructors: () => ({_: [JsInstanceMirror, [core.Object]]}), methods: () => ({ + delegate: [dart.dynamic, [core.Invocation]], getField: [mirrors.InstanceMirror, [core.Symbol]], setField: [mirrors.InstanceMirror, [core.Symbol, core.Object]], invoke: [mirrors.InstanceMirror, [core.Symbol, core.List], [core.Map$(core.Symbol, dart.dynamic)]], @@ -121,35 +131,204 @@ dart_library.library('dart/_js_mirrors', null, /* Imports */[ let instance = new this[_cls](...args); return new JsInstanceMirror._(instance); } + get superinterfaces() { + let interfaces = this[_cls][dart.implements]; + if (interfaces == null) { + return dart.list([], mirrors.ClassMirror); + } + dart.throw(new core.UnimplementedError("ClassMirror.superinterfaces unimplemented")); + } + getField(fieldName) { + return dart.throw(new core.UnimplementedError("ClassMirror.getField unimplemented")); + } + invoke(memberName, positionalArguments, namedArguments) { + if (namedArguments === void 0) + namedArguments = null; + return dart.throw(new core.UnimplementedError("ClassMirror.invoke unimplemented")); + } + isAssignableTo(other) { + return dart.throw(new core.UnimplementedError("ClassMirror.isAssignable unimplemented")); + } + isSubclassOf(other) { + return dart.throw(new core.UnimplementedError("ClassMirror.isSubclassOf unimplemented")); + } + isSubtypeOf(other) { + return dart.throw(new core.UnimplementedError("ClassMirror.isSubtypeOf unimplemented")); + } + setField(fieldName, value) { + return dart.throw(new core.UnimplementedError("ClassMirror.setField unimplemented")); + } + get hasReflectedType() { + return dart.throw(new core.UnimplementedError("ClassMirror.hasReflectedType unimplemented")); + } + get instanceMembers() { + return dart.throw(new core.UnimplementedError("ClassMirror.instanceMembers unimplemented")); + } + get isAbstract() { + return dart.throw(new core.UnimplementedError("ClassMirror.isAbstract unimplemented")); + } + get isEnum() { + return dart.throw(new core.UnimplementedError("ClassMirror.isEnum unimplemented")); + } + get isOriginalDeclaration() { + return dart.throw(new core.UnimplementedError("ClassMirror.isOriginalDeclaration unimplemented")); + } + get isPrivate() { + return dart.throw(new core.UnimplementedError("ClassMirror.isPrivate unimplemented")); + } + get isTopLevel() { + return dart.throw(new core.UnimplementedError("ClassMirror.isTopLevel unimplemented")); + } + get location() { + return dart.throw(new core.UnimplementedError("ClassMirror.location unimplemented")); + } + get mixin() { + return dart.throw(new core.UnimplementedError("ClassMirror.mixin unimplemented")); + } + get originalDeclaration() { + return dart.throw(new core.UnimplementedError("ClassMirror.originalDeclaration unimplemented")); + } + get owner() { + return dart.throw(new core.UnimplementedError("ClassMirror.owner unimplemented")); + } + get qualifiedName() { + return dart.throw(new core.UnimplementedError("ClassMirror.qualifiedName unimplemented")); + } + get reflectedType() { + return dart.throw(new core.UnimplementedError("ClassMirror.reflectedType unimplemented")); + } + get staticMembers() { + return dart.throw(new core.UnimplementedError("ClassMirror.staticMembers unimplemented")); + } + get superclass() { + return dart.throw(new core.UnimplementedError("ClassMirror.superclass unimplemented")); + } + get typeArguments() { + return dart.throw(new core.UnimplementedError("ClassMirror.typeArguments unimplemented")); + } + get typeVariables() { + return dart.throw(new core.UnimplementedError("ClassMirror.typeVariables unimplemented")); + } } JsClassMirror[dart.implements] = () => [mirrors.ClassMirror]; dart.defineNamedConstructor(JsClassMirror, '_'); dart.setSignature(JsClassMirror, { constructors: () => ({_: [JsClassMirror, [core.Type]]}), - methods: () => ({newInstance: [mirrors.InstanceMirror, [core.Symbol, core.List], [core.Map$(core.Symbol, dart.dynamic)]]}) + methods: () => ({ + newInstance: [mirrors.InstanceMirror, [core.Symbol, core.List], [core.Map$(core.Symbol, dart.dynamic)]], + getField: [mirrors.InstanceMirror, [core.Symbol]], + invoke: [mirrors.InstanceMirror, [core.Symbol, core.List], [core.Map$(core.Symbol, dart.dynamic)]], + isAssignableTo: [core.bool, [mirrors.TypeMirror]], + isSubclassOf: [core.bool, [mirrors.ClassMirror]], + isSubtypeOf: [core.bool, [mirrors.TypeMirror]], + setField: [mirrors.InstanceMirror, [core.Symbol, core.Object]] + }) }); class JsTypeMirror extends core.Object { _(reflectedType) { this.reflectedType = reflectedType; + this.hasReflectedType = true; + } + isAssignableTo(other) { + return dart.throw(new core.UnimplementedError("TypeMirror.isAssignable unimplemented")); + } + isSubtypeOf(other) { + return dart.throw(new core.UnimplementedError("TypeMirror.isSubtypeOf unimplemented")); + } + get isOriginalDeclaration() { + return dart.throw(new core.UnimplementedError("TypeMirror.isOriginalDeclaration unimplemented")); + } + get isPrivate() { + return dart.throw(new core.UnimplementedError("TypeMirror.isPrivate unimplemented")); + } + get isTopLevel() { + return dart.throw(new core.UnimplementedError("TypeMirror.isTopLevel unimplemented")); + } + get location() { + return dart.throw(new core.UnimplementedError("TypeMirror.location unimplemented")); + } + get metadata() { + return dart.throw(new core.UnimplementedError("TypeMirror.metadata unimplemented")); + } + get originalDeclaration() { + return dart.throw(new core.UnimplementedError("TypeMirror.originalDeclaration unimplemented")); + } + get owner() { + return dart.throw(new core.UnimplementedError("TypeMirror.owner unimplemented")); + } + get qualifiedName() { + return dart.throw(new core.UnimplementedError("TypeMirror.qualifiedName unimplemented")); + } + get simpleName() { + return dart.throw(new core.UnimplementedError("TypeMirror.simpleName unimplemented")); + } + get typeArguments() { + return dart.throw(new core.UnimplementedError("TypeMirror.typeArguments unimplemented")); + } + get typeVariables() { + return dart.throw(new core.UnimplementedError("TypeMirror.typeVariables unimplemented")); } } JsTypeMirror[dart.implements] = () => [mirrors.TypeMirror]; dart.defineNamedConstructor(JsTypeMirror, '_'); dart.setSignature(JsTypeMirror, { - constructors: () => ({_: [JsTypeMirror, [core.Type]]}) + constructors: () => ({_: [JsTypeMirror, [core.Type]]}), + methods: () => ({ + isAssignableTo: [core.bool, [mirrors.TypeMirror]], + isSubtypeOf: [core.bool, [mirrors.TypeMirror]] + }) }); let _name = Symbol('_name'); class JsParameterMirror extends core.Object { - _(name, t) { - this.metadata = dart.list([], mirrors.InstanceMirror); + _(name, t, annotations) { this[_name] = name; this.type = new JsTypeMirror._(t); + this.metadata = core.List$(mirrors.InstanceMirror).from(annotations[dartx.map](dart.fn(a => new JsInstanceMirror._(a), JsInstanceMirror, [dart.dynamic]))); + } + get defaultValue() { + return dart.throw(new core.UnimplementedError("ParameterMirror.defaultValues unimplemented")); + } + get hasDefaultValue() { + return dart.throw(new core.UnimplementedError("ParameterMirror.hasDefaultValue unimplemented")); + } + get isConst() { + return dart.throw(new core.UnimplementedError("ParameterMirror.isConst unimplemented")); + } + get isFinal() { + return dart.throw(new core.UnimplementedError("ParameterMirror.isFinal unimplemented")); + } + get isNamed() { + return dart.throw(new core.UnimplementedError("ParameterMirror.isNamed unimplemented")); + } + get isOptional() { + return dart.throw(new core.UnimplementedError("ParameterMirror.isOptional unimplemented")); + } + get isPrivate() { + return dart.throw(new core.UnimplementedError("ParameterMirror.isPrivate unimplemented")); + } + get isStatic() { + return dart.throw(new core.UnimplementedError("ParameterMirror.isStatic unimplemented")); + } + get isTopLevel() { + return dart.throw(new core.UnimplementedError("ParameterMirror.isTopLevel unimplemented")); + } + get location() { + return dart.throw(new core.UnimplementedError("ParameterMirror.location unimplemented")); + } + get owner() { + return dart.throw(new core.UnimplementedError("ParameterMirror.owner unimplemented")); + } + get qualifiedName() { + return dart.throw(new core.UnimplementedError("ParameterMirror.qualifiedName unimplemented")); + } + get simpleName() { + return dart.throw(new core.UnimplementedError("ParameterMirror.simpleName unimplemented")); } } JsParameterMirror[dart.implements] = () => [mirrors.ParameterMirror]; dart.defineNamedConstructor(JsParameterMirror, '_'); dart.setSignature(JsParameterMirror, { - constructors: () => ({_: [JsParameterMirror, [core.String, core.Type]]}) + constructors: () => ({_: [JsParameterMirror, [core.String, core.Type, core.List]]}) }); let _method = Symbol('_method'); let _params = Symbol('_params'); @@ -177,16 +356,81 @@ dart_library.library('dart/_js_mirrors', null, /* Imports */[ let params = core.List$(mirrors.ParameterMirror).new(dart.notNull(args[dartx.length]) + dart.notNull(opts[dartx.length])); for (let i = 0; dart.notNull(i) < dart.notNull(args[dartx.length]); i = dart.notNull(i) + 1) { let type = args[dartx.get](i); - let param = new JsParameterMirror._('', dart.as(type, core.Type)); + let metadata = dart.dindex(dart.dload(ftype, 'metadata'), i); + let param = new JsParameterMirror._('', dart.as(type, core.Type), dart.as(metadata, core.List)); params[dartx.set](i, param); } for (let i = 0; dart.notNull(i) < dart.notNull(opts[dartx.length]); i = dart.notNull(i) + 1) { let type = opts[dartx.get](i); - let param = new JsParameterMirror._('', dart.as(type, core.Type)); + let metadata = dart.dindex(dart.dload(ftype, 'metadata'), dart.notNull(args[dartx.length]) + dart.notNull(i)); + let param = new JsParameterMirror._('', dart.as(type, core.Type), dart.as(metadata, core.List)); params[dartx.set](dart.notNull(i) + dart.notNull(args[dartx.length]), param); } return params; } + get isAbstract() { + return dart.throw(new core.UnimplementedError("MethodMirror.isAbstract unimplemented")); + } + get isConstConstructor() { + return dart.throw(new core.UnimplementedError("MethodMirror.isConstConstructor unimplemented")); + } + get isConstructor() { + return dart.throw(new core.UnimplementedError("MethodMirror.isConstructor unimplemented")); + } + get isFactoryConstructor() { + return dart.throw(new core.UnimplementedError("MethodMirror.isFactoryConstructor unimplemented")); + } + get isGenerativeConstructor() { + return dart.throw(new core.UnimplementedError("MethodMirror.isGenerativeConstructor unimplemented")); + } + get isGetter() { + return dart.throw(new core.UnimplementedError("MethodMirror.isGetter unimplemented")); + } + get isOperator() { + return dart.throw(new core.UnimplementedError("MethodMirror.isOperator unimplemented")); + } + get isPrivate() { + return dart.throw(new core.UnimplementedError("MethodMirror.isPrivate unimplemented")); + } + get isRedirectingConstructor() { + return dart.throw(new core.UnimplementedError("MethodMirror.isRedirectingConstructor unimplemented")); + } + get isRegularMethod() { + return dart.throw(new core.UnimplementedError("MethodMirror.isRegularMethod unimplemented")); + } + get isSetter() { + return dart.throw(new core.UnimplementedError("MethodMirror.isSetter unimplemented")); + } + get isStatic() { + return dart.throw(new core.UnimplementedError("MethodMirror.isStatic unimplemented")); + } + get isSynthetic() { + return dart.throw(new core.UnimplementedError("MethodMirror.isSynthetic unimplemented")); + } + get isTopLevel() { + return dart.throw(new core.UnimplementedError("MethodMirror.isTopLevel unimplemented")); + } + get location() { + return dart.throw(new core.UnimplementedError("MethodMirror.location unimplemented")); + } + get metadata() { + return dart.throw(new core.UnimplementedError("MethodMirror.metadata unimplemented")); + } + get owner() { + return dart.throw(new core.UnimplementedError("MethodMirror.owner unimplemented")); + } + get qualifiedName() { + return dart.throw(new core.UnimplementedError("MethodMirror.qualifiedName unimplemented")); + } + get returnType() { + return dart.throw(new core.UnimplementedError("MethodMirror.returnType unimplemented")); + } + get simpleName() { + return dart.throw(new core.UnimplementedError("MethodMirror.simpleName unimplemented")); + } + get source() { + return dart.throw(new core.UnimplementedError("MethodMirror.source unimplemented")); + } } JsMethodMirror[dart.implements] = () => [mirrors.MethodMirror]; dart.defineNamedConstructor(JsMethodMirror, '_'); diff --git a/pkg/dev_compiler/lib/runtime/dart_utils.js b/pkg/dev_compiler/lib/runtime/dart_utils.js index 70555c729187..a1c2bf9762b4 100644 --- a/pkg/dev_compiler/lib/runtime/dart_utils.js +++ b/pkg/dev_compiler/lib/runtime/dart_utils.js @@ -113,7 +113,7 @@ var dart_utils = show = getOwnNamesAndSymbols(from); } if (hide != void 0) { - var hideMap = new Map(hide); + var hideMap = new Set(hide); show = show.filter((k) => !hideMap.has(k)); } return copyTheseProperties(to, from, show); diff --git a/pkg/dev_compiler/lib/src/codegen/js_codegen.dart b/pkg/dev_compiler/lib/src/codegen/js_codegen.dart index ddae19b24c35..bb73a3cb104d 100644 --- a/pkg/dev_compiler/lib/src/codegen/js_codegen.dart +++ b/pkg/dev_compiler/lib/src/codegen/js_codegen.dart @@ -509,6 +509,7 @@ class JSCodegenVisitor extends GeneralizingAstVisitor { result.add(js.statement('#.values = dart.const(dart.list(#, #));', [id, values, _emitTypeName(type)])); + if (isPublic(type.name)) _addExport(type.name); return _statement(result); } @@ -751,7 +752,7 @@ class JSCodegenVisitor extends GeneralizingAstVisitor { for (ConstructorDeclaration node in ctors) { var memberName = _constructorName(node.element); var element = node.element; - var parts = _emitFunctionTypeParts(element.type); + var parts = _emitFunctionTypeParts(element.type, node.parameters); var property = new JS.Property(memberName, new JS.ArrayInitializer(parts)); tCtors.add(property); @@ -794,6 +795,7 @@ class JSCodegenVisitor extends GeneralizingAstVisitor { ])); } + // TODO(vsm): Make this optional per #268. // Metadata if (metadata.isNotEmpty) { body.add(js.statement('#[dart.metadata] = () => #;', [ @@ -1479,9 +1481,27 @@ class JSCodegenVisitor extends GeneralizingAstVisitor { JS.TemporaryId _getTemp(Element key, String name) => _temps.putIfAbsent(key, () => new JS.TemporaryId(name)); - JS.ArrayInitializer _emitTypeNames(List types) { - return new JS.ArrayInitializer( - new List.from(types.map(_emitTypeName))); + List _parameterMetadata(FormalParameter p) => + (p is NormalFormalParameter) + ? p.metadata + : (p as DefaultFormalParameter).parameter.metadata; + + JS.ArrayInitializer _emitTypeNames(List types, + [List parameters]) { + var result = []; + for (int i = 0; i < types.length; ++i) { + var metadata = + parameters != null ? _parameterMetadata(parameters[i]) : []; + var typeName = _emitTypeName(types[i]); + var value = typeName; + // TODO(vsm): Make this optional per #268. + if (metadata.isNotEmpty) { + metadata = metadata.map(_instantiateAnnotation).toList(); + value = new JS.ArrayInitializer([typeName]..addAll(metadata)); + } + result.add(value); + } + return new JS.ArrayInitializer(result); } JS.ObjectInitializer _emitTypeProperties(Map types) { @@ -1496,21 +1516,25 @@ class JSCodegenVisitor extends GeneralizingAstVisitor { /// Emit the pieces of a function type, as an array of return type, /// regular args, and optional/named args. - List _emitFunctionTypeParts(FunctionType type) { + List _emitFunctionTypeParts(FunctionType type, + [FormalParameterList parameterList]) { + var parameters = parameterList?.parameters; var returnType = type.returnType; var parameterTypes = type.normalParameterTypes; var optionalTypes = type.optionalParameterTypes; var namedTypes = type.namedParameterTypes; var rt = _emitTypeName(returnType); - var ra = _emitTypeNames(parameterTypes); + var ra = _emitTypeNames(parameterTypes, parameters); if (!namedTypes.isEmpty) { assert(optionalTypes.isEmpty); + // TODO(vsm): Pass in annotations here as well. var na = _emitTypeProperties(namedTypes); return [rt, ra, na]; } if (!optionalTypes.isEmpty) { assert(namedTypes.isEmpty); - var oa = _emitTypeNames(optionalTypes); + var oa = _emitTypeNames( + optionalTypes, parameters?.sublist(parameterTypes.length)); return [rt, ra, oa]; } return [rt, ra]; @@ -1694,7 +1718,7 @@ class JSCodegenVisitor extends GeneralizingAstVisitor { if (DynamicInvoke.get(target)) { code = 'dart.$DSEND(#, #, #)'; } else if (DynamicInvoke.get(node.methodName)) { - // This is a dynamic call to a statically know target. For example: + // This is a dynamic call to a statically known target. For example: // class Foo { Function bar; } // new Foo().bar(); // dynamic call code = 'dart.$DCALL(#.#, #)'; diff --git a/pkg/dev_compiler/test/codegen/expect/fieldtest.js b/pkg/dev_compiler/test/codegen/expect/fieldtest.js index f69baba971e9..fc4d670867ff 100644 --- a/pkg/dev_compiler/test/codegen/expect/fieldtest.js +++ b/pkg/dev_compiler/test/codegen/expect/fieldtest.js @@ -133,5 +133,6 @@ dart_library.library('fieldtest', null, /* Imports */[ exports.Generic = Generic; exports.StaticFieldOrder1 = StaticFieldOrder1; exports.StaticFieldOrder2 = StaticFieldOrder2; + exports.MyEnum = MyEnum; exports.main = main; }); diff --git a/pkg/dev_compiler/tool/input_sdk/private/js_mirrors.dart b/pkg/dev_compiler/tool/input_sdk/private/js_mirrors.dart index cc50f43c0a7e..71c108fc6078 100644 --- a/pkg/dev_compiler/tool/input_sdk/private/js_mirrors.dart +++ b/pkg/dev_compiler/tool/input_sdk/private/js_mirrors.dart @@ -4,7 +4,6 @@ library dart._js_mirrors; -import 'dart:collection'; import 'dart:mirrors'; import 'dart:_foreign_helper' show JS; import 'dart:_internal' as _internal; @@ -45,6 +44,13 @@ class JsInstanceMirror implements InstanceMirror { JsInstanceMirror._(this.reflectee); + ClassMirror get type => + throw new UnimplementedError("ClassMirror.type unimplemented"); + bool get hasReflectee => + throw new UnimplementedError("ClassMirror.hasReflectee unimplemented"); + delegate(Invocation invocation) => + throw new UnimplementedError("ClassMirror.delegate unimplemented"); + InstanceMirror getField(Symbol symbol) { var name = getName(symbol); var field = _dload(reflectee, name); @@ -53,8 +59,8 @@ class JsInstanceMirror implements InstanceMirror { InstanceMirror setField(Symbol symbol, Object value) { var name = getName(symbol); - var field = _dput(reflectee, name, value); - return new JsInstanceMirror._(field); + _dput(reflectee, name, value); + return new JsInstanceMirror._(value); } InstanceMirror invoke(Symbol symbol, List args, @@ -92,10 +98,11 @@ class JsClassMirror implements ClassMirror { : _cls = cls, simpleName = new Symbol(JS('String', '#.name', cls)) { // Load metadata. - var fn = JS('List', '#[dart.metadata]', _cls); + var fn = JS('Function', '#[dart.metadata]', _cls); _metadata = (fn == null) ? [] - : new List.from(fn().map((i) => new JsInstanceMirror._(i))); + : new List.from( + fn().map((i) => new JsInstanceMirror._(i))); // Load declarations. // TODO(vsm): This is only populating the default constructor right now. @@ -111,20 +118,139 @@ class JsClassMirror implements ClassMirror { var instance = JS('', 'new #(...#)', _cls, args); return new JsInstanceMirror._(instance); } + + List get superinterfaces { + var interfaces = JS('Function', '#[dart.implements]', _cls); + if (interfaces == null) { + return []; + } + throw new UnimplementedError("ClassMirror.superinterfaces unimplemented"); + } + + // TODO(vsm): Implement + InstanceMirror getField(Symbol fieldName) => + throw new UnimplementedError("ClassMirror.getField unimplemented"); + InstanceMirror invoke(Symbol memberName, List positionalArguments, + [Map namedArguments]) => + throw new UnimplementedError("ClassMirror.invoke unimplemented"); + bool isAssignableTo(TypeMirror other) => + throw new UnimplementedError("ClassMirror.isAssignable unimplemented"); + bool isSubclassOf(ClassMirror other) => + throw new UnimplementedError("ClassMirror.isSubclassOf unimplemented"); + bool isSubtypeOf(TypeMirror other) => + throw new UnimplementedError("ClassMirror.isSubtypeOf unimplemented"); + InstanceMirror setField(Symbol fieldName, Object value) => + throw new UnimplementedError("ClassMirror.setField unimplemented"); + bool get hasReflectedType => throw new UnimplementedError( + "ClassMirror.hasReflectedType unimplemented"); + Map get instanceMembers => + throw new UnimplementedError("ClassMirror.instanceMembers unimplemented"); + bool get isAbstract => + throw new UnimplementedError("ClassMirror.isAbstract unimplemented"); + bool get isEnum => + throw new UnimplementedError("ClassMirror.isEnum unimplemented"); + bool get isOriginalDeclaration => throw new UnimplementedError( + "ClassMirror.isOriginalDeclaration unimplemented"); + bool get isPrivate => + throw new UnimplementedError("ClassMirror.isPrivate unimplemented"); + bool get isTopLevel => + throw new UnimplementedError("ClassMirror.isTopLevel unimplemented"); + SourceLocation get location => + throw new UnimplementedError("ClassMirror.location unimplemented"); + ClassMirror get mixin => + throw new UnimplementedError("ClassMirror.mixin unimplemented"); + TypeMirror get originalDeclaration => throw new UnimplementedError( + "ClassMirror.originalDeclaration unimplemented"); + DeclarationMirror get owner => + throw new UnimplementedError("ClassMirror.owner unimplemented"); + Symbol get qualifiedName => + throw new UnimplementedError("ClassMirror.qualifiedName unimplemented"); + Type get reflectedType => + throw new UnimplementedError("ClassMirror.reflectedType unimplemented"); + Map get staticMembers => + throw new UnimplementedError("ClassMirror.staticMembers unimplemented"); + ClassMirror get superclass => + throw new UnimplementedError("ClassMirror.superclass unimplemented"); + List get typeArguments => + throw new UnimplementedError("ClassMirror.typeArguments unimplemented"); + List get typeVariables => + throw new UnimplementedError("ClassMirror.typeVariables unimplemented"); } class JsTypeMirror implements TypeMirror { + // TODO(vsm): Support original declarations, etc., where there is no actual + // reflected type. final Type reflectedType; + final bool hasReflectedType = true; JsTypeMirror._(this.reflectedType); + + // TODO(vsm): Implement + bool isAssignableTo(TypeMirror other) => + throw new UnimplementedError("TypeMirror.isAssignable unimplemented"); + bool isSubtypeOf(TypeMirror other) => + throw new UnimplementedError("TypeMirror.isSubtypeOf unimplemented"); + bool get isOriginalDeclaration => throw new UnimplementedError( + "TypeMirror.isOriginalDeclaration unimplemented"); + bool get isPrivate => + throw new UnimplementedError("TypeMirror.isPrivate unimplemented"); + bool get isTopLevel => + throw new UnimplementedError("TypeMirror.isTopLevel unimplemented"); + SourceLocation get location => + throw new UnimplementedError("TypeMirror.location unimplemented"); + List get metadata => + throw new UnimplementedError("TypeMirror.metadata unimplemented"); + TypeMirror get originalDeclaration => throw new UnimplementedError( + "TypeMirror.originalDeclaration unimplemented"); + DeclarationMirror get owner => + throw new UnimplementedError("TypeMirror.owner unimplemented"); + Symbol get qualifiedName => + throw new UnimplementedError("TypeMirror.qualifiedName unimplemented"); + Symbol get simpleName => + throw new UnimplementedError("TypeMirror.simpleName unimplemented"); + List get typeArguments => + throw new UnimplementedError("TypeMirror.typeArguments unimplemented"); + List get typeVariables => + throw new UnimplementedError("TypeMirror.typeVariables unimplemented"); } class JsParameterMirror implements ParameterMirror { final String _name; final TypeMirror type; - final List metadata = []; - - JsParameterMirror._(this._name, Type t) : type = new JsTypeMirror._(t); + final List metadata; + + JsParameterMirror._(this._name, Type t, List annotations) + : type = new JsTypeMirror._(t), + metadata = new List.from( + annotations.map((a) => new JsInstanceMirror._(a))); + + // TODO(vsm): Implement + InstanceMirror get defaultValue => throw new UnimplementedError( + "ParameterMirror.defaultValues unimplemented"); + bool get hasDefaultValue => throw new UnimplementedError( + "ParameterMirror.hasDefaultValue unimplemented"); + bool get isConst => + throw new UnimplementedError("ParameterMirror.isConst unimplemented"); + bool get isFinal => + throw new UnimplementedError("ParameterMirror.isFinal unimplemented"); + bool get isNamed => + throw new UnimplementedError("ParameterMirror.isNamed unimplemented"); + bool get isOptional => + throw new UnimplementedError("ParameterMirror.isOptional unimplemented"); + bool get isPrivate => + throw new UnimplementedError("ParameterMirror.isPrivate unimplemented"); + bool get isStatic => + throw new UnimplementedError("ParameterMirror.isStatic unimplemented"); + bool get isTopLevel => + throw new UnimplementedError("ParameterMirror.isTopLevel unimplemented"); + SourceLocation get location => + throw new UnimplementedError("ParameterMirror.location unimplemented"); + DeclarationMirror get owner => + throw new UnimplementedError("ParameterMirror.owner unimplemented"); + Symbol get qualifiedName => throw new UnimplementedError( + "ParameterMirror.qualifiedName unimplemented"); + Symbol get simpleName => + throw new UnimplementedError("ParameterMirror.simpleName unimplemented"); } class JsMethodMirror implements MethodMirror { @@ -155,18 +281,64 @@ class JsMethodMirror implements MethodMirror { for (var i = 0; i < args.length; ++i) { var type = args[i]; + var metadata = ftype.metadata[i]; // TODO(vsm): Recover the param name. - var param = new JsParameterMirror._('', type); + var param = new JsParameterMirror._('', type, metadata); params[i] = param; } for (var i = 0; i < opts.length; ++i) { var type = opts[i]; + var metadata = ftype.metadata[args.length + i]; // TODO(vsm): Recover the param name. - var param = new JsParameterMirror._('', type); + var param = new JsParameterMirror._('', type, metadata); params[i + args.length] = param; } return params; } + + // TODO(vsm): Implement + bool get isAbstract => + throw new UnimplementedError("MethodMirror.isAbstract unimplemented"); + bool get isConstConstructor => throw new UnimplementedError( + "MethodMirror.isConstConstructor unimplemented"); + bool get isConstructor => + throw new UnimplementedError("MethodMirror.isConstructor unimplemented"); + bool get isFactoryConstructor => throw new UnimplementedError( + "MethodMirror.isFactoryConstructor unimplemented"); + bool get isGenerativeConstructor => throw new UnimplementedError( + "MethodMirror.isGenerativeConstructor unimplemented"); + bool get isGetter => + throw new UnimplementedError("MethodMirror.isGetter unimplemented"); + bool get isOperator => + throw new UnimplementedError("MethodMirror.isOperator unimplemented"); + bool get isPrivate => + throw new UnimplementedError("MethodMirror.isPrivate unimplemented"); + bool get isRedirectingConstructor => throw new UnimplementedError( + "MethodMirror.isRedirectingConstructor unimplemented"); + bool get isRegularMethod => throw new UnimplementedError( + "MethodMirror.isRegularMethod unimplemented"); + bool get isSetter => + throw new UnimplementedError("MethodMirror.isSetter unimplemented"); + bool get isStatic => + throw new UnimplementedError("MethodMirror.isStatic unimplemented"); + bool get isSynthetic => + throw new UnimplementedError("MethodMirror.isSynthetic unimplemented"); + bool get isTopLevel => + throw new UnimplementedError("MethodMirror.isTopLevel unimplemented"); + SourceLocation get location => + throw new UnimplementedError("MethodMirror.location unimplemented"); + List get metadata => + throw new UnimplementedError("MethodMirror.metadata unimplemented"); + DeclarationMirror get owner => + throw new UnimplementedError("MethodMirror.owner unimplemented"); + Symbol get qualifiedName => + throw new UnimplementedError("MethodMirror.qualifiedName unimplemented"); + TypeMirror get returnType => + throw new UnimplementedError("MethodMirror.returnType unimplemented"); + Symbol get simpleName => + throw new UnimplementedError("MethodMirror.simpleName unimplemented"); + String get source => + throw new UnimplementedError("MethodMirror.source unimplemented"); } diff --git a/pkg/dev_compiler/tool/sdk_expected_errors.txt b/pkg/dev_compiler/tool/sdk_expected_errors.txt index 3a56d4475da7..f85ef85ff19a 100644 --- a/pkg/dev_compiler/tool/sdk_expected_errors.txt +++ b/pkg/dev_compiler/tool/sdk_expected_errors.txt @@ -376,10 +376,4 @@ warning: [DownCastImplicit] list (Object) will need runtime check to cast to typ warning: [DownCastComposite] callMethod('splice', [index, 1])[0] (dynamic) will need runtime check to cast to type E (dart:js, line 404, col 12) warning: [DownCastComposite] callMethod('pop') (dynamic) will need runtime check to cast to type E (dart:js, line 409, col 12) warning: [DownCastImplicit] ms (num) will need runtime check to cast to type int (dart:js, line 486, col 52) -severe: [AnalyzerMessage] Missing concrete implementation of getter 'VariableMirror.isStatic', getter 'VariableMirror.isFinal', getter 'DeclarationMirror.owner', getter 'ParameterMirror.isOptional' and 9 more (dart:_js_mirrors, line 122, col 7) -severe: [AnalyzerMessage] Missing concrete implementation of getter 'TypeMirror.typeArguments', getter 'TypeMirror.isOriginalDeclaration', getter 'DeclarationMirror.owner', getter 'DeclarationMirror.location' and 10 more (dart:_js_mirrors, line 116, col 7) -severe: [AnalyzerMessage] Missing concrete implementation of getter 'MethodMirror.isSetter', getter 'MethodMirror.isConstructor', getter 'MethodMirror.isConstConstructor', getter 'MethodMirror.isAbstract' and 17 more (dart:_js_mirrors, line 130, col 7) -severe: [AnalyzerMessage] Missing concrete implementation of getter 'InstanceMirror.type', getter 'InstanceMirror.hasReflectee' and 'InstanceMirror.delegate' (dart:_js_mirrors, line 43, col 7) -severe: [AnalyzerMessage] Missing concrete implementation of getter 'TypeMirror.typeArguments', getter 'ClassMirror.superinterfaces', getter 'TypeMirror.isOriginalDeclaration', getter 'ClassMirror.staticMembers' and 19 more (dart:_js_mirrors, line 80, col 7) -severe: [AnalyzerMessage] The argument type 'void' cannot be assigned to the parameter type 'Object' (dart:_js_mirrors, line 57, col 35) warning: [DownCastImplicit] (tm as ClassMirror).originalDeclaration (TypeMirror) will need runtime check to cast to type ClassMirror (dart:mirrors, line 171, col 10)