fix(di): do not use exceptions to detect if reflection is enabled
This commit is contained in:
parent
71c65b47f9
commit
a6210466c7
|
@ -450,16 +450,15 @@ function _extractToken(typeOrFunc, annotations /*List<any> | any*/,
|
|||
throw new NoAnnotationError(typeOrFunc, params);
|
||||
}
|
||||
}
|
||||
|
||||
function _defaulVisiblity(typeOrFunc) {
|
||||
try {
|
||||
if (!(typeOrFunc instanceof Type)) return unbounded;
|
||||
|
||||
// TODO: vsavkin revisit this after clarifying lookup rules
|
||||
if (!reflector.isReflectionEnabled()) return unbounded;
|
||||
|
||||
var f =
|
||||
ListWrapper.filter(reflector.annotations(typeOrFunc), s => s instanceof InjectableMetadata);
|
||||
return f.length === 0 ? unbounded : f[0].visibility;
|
||||
} catch (e) {
|
||||
return unbounded;
|
||||
}
|
||||
}
|
||||
|
||||
function _createDependency(token, optional, visibility, depProps): Dependency {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -10,6 +10,8 @@ class NullReflectionCapabilities implements ReflectionCapabilities {
|
|||
|
||||
_notImplemented(String name) => throw 'Not implemented: $name';
|
||||
|
||||
bool isReflectionEnabled() { return false; }
|
||||
|
||||
Function factory(Type type) => _notImplemented('factory');
|
||||
|
||||
List<List> parameters(typeOrFunc) => _notImplemented('parameters');
|
||||
|
|
Loading…
Reference in New Issue