Skip to content

Commit

Permalink
Implement more of dart:mirrors
Browse files Browse the repository at this point in the history
This unblocks angular.

See #199

[email protected]

Review URL: https://codereview.chromium.org/1252953003 .
  • Loading branch information
vsmenon committed Aug 7, 2015
1 parent ae53ea3 commit c010093
Show file tree
Hide file tree
Showing 8 changed files with 498 additions and 38 deletions.
9 changes: 5 additions & 4 deletions pkg/dev_compiler/lib/runtime/_errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
24 changes: 24 additions & 0 deletions pkg/dev_compiler/lib/runtime/_types.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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) {
Expand Down
262 changes: 253 additions & 9 deletions pkg/dev_compiler/lib/runtime/dart/_js_mirrors.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,24 @@ 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);
return new JsInstanceMirror._(field);
}
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)
Expand All @@ -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)]],
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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, '_');
Expand Down
Loading

0 comments on commit c010093

Please sign in to comment.