fix(di): do not use exceptions to detect if reflection is enabled
This commit is contained in:
@ -3,6 +3,7 @@ import {GetterFn, SetterFn, MethodFn} from './types';
|
||||
import {List} from 'angular2/src/facade/collection';
|
||||
|
||||
export interface PlatformReflectionCapabilities {
|
||||
isReflectionEnabled(): boolean;
|
||||
factory(type: Type): Function;
|
||||
interfaces(type: Type): List<any>;
|
||||
parameters(type: Type): List<List<any>>;
|
||||
|
@ -7,6 +7,10 @@ import 'platform_reflection_capabilities.dart';
|
||||
import 'package:angular2/src/facade/lang.dart';
|
||||
|
||||
class NoReflectionCapabilities implements PlatformReflectionCapabilities {
|
||||
bool isReflectionEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
Function factory(Type type) {
|
||||
throw "Cannot find reflection information on ${stringify(type)}";
|
||||
}
|
||||
|
@ -8,6 +8,10 @@ import 'platform_reflection_capabilities.dart';
|
||||
class ReflectionCapabilities implements PlatformReflectionCapabilities {
|
||||
ReflectionCapabilities([metadataReader]) {}
|
||||
|
||||
bool isReflectionEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
Function factory(Type type) {
|
||||
ClassMirror classMirror = reflectType(type);
|
||||
MethodMirror ctor = classMirror.declarations[classMirror.simpleName];
|
||||
|
@ -15,6 +15,8 @@ export class ReflectionCapabilities implements PlatformReflectionCapabilities {
|
||||
|
||||
constructor(reflect?: any) { this._reflect = isPresent(reflect) ? reflect : global.Reflect; }
|
||||
|
||||
isReflectionEnabled(): boolean { return true; }
|
||||
|
||||
factory(t: Type): Function {
|
||||
switch (t.length) {
|
||||
case 0:
|
||||
|
@ -27,6 +27,8 @@ export class Reflector {
|
||||
this.reflectionCapabilities = reflectionCapabilities;
|
||||
}
|
||||
|
||||
isReflectionEnabled(): boolean { return this.reflectionCapabilities.isReflectionEnabled(); }
|
||||
|
||||
registerFunction(func: Function, funcInfo: StringMap<string, any>): void {
|
||||
this._injectableInfo.set(func, funcInfo);
|
||||
}
|
||||
|
Reference in New Issue
Block a user