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);
|
throw new NoAnnotationError(typeOrFunc, params);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function _defaulVisiblity(typeOrFunc) {
|
function _defaulVisiblity(typeOrFunc) {
|
||||||
try {
|
if (!(typeOrFunc instanceof Type)) return unbounded;
|
||||||
if (!(typeOrFunc instanceof Type)) return unbounded;
|
|
||||||
var f =
|
// TODO: vsavkin revisit this after clarifying lookup rules
|
||||||
ListWrapper.filter(reflector.annotations(typeOrFunc), s => s instanceof InjectableMetadata);
|
if (!reflector.isReflectionEnabled()) return unbounded;
|
||||||
return f.length === 0 ? unbounded : f[0].visibility;
|
|
||||||
} catch (e) {
|
var f =
|
||||||
return unbounded;
|
ListWrapper.filter(reflector.annotations(typeOrFunc), s => s instanceof InjectableMetadata);
|
||||||
}
|
return f.length === 0 ? unbounded : f[0].visibility;
|
||||||
}
|
}
|
||||||
|
|
||||||
function _createDependency(token, optional, visibility, depProps): Dependency {
|
function _createDependency(token, optional, visibility, depProps): Dependency {
|
||||||
|
|
|
@ -3,6 +3,7 @@ import {GetterFn, SetterFn, MethodFn} from './types';
|
||||||
import {List} from 'angular2/src/facade/collection';
|
import {List} from 'angular2/src/facade/collection';
|
||||||
|
|
||||||
export interface PlatformReflectionCapabilities {
|
export interface PlatformReflectionCapabilities {
|
||||||
|
isReflectionEnabled(): boolean;
|
||||||
factory(type: Type): Function;
|
factory(type: Type): Function;
|
||||||
interfaces(type: Type): List<any>;
|
interfaces(type: Type): List<any>;
|
||||||
parameters(type: Type): List<List<any>>;
|
parameters(type: Type): List<List<any>>;
|
||||||
|
|
|
@ -7,6 +7,10 @@ import 'platform_reflection_capabilities.dart';
|
||||||
import 'package:angular2/src/facade/lang.dart';
|
import 'package:angular2/src/facade/lang.dart';
|
||||||
|
|
||||||
class NoReflectionCapabilities implements PlatformReflectionCapabilities {
|
class NoReflectionCapabilities implements PlatformReflectionCapabilities {
|
||||||
|
bool isReflectionEnabled() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
Function factory(Type type) {
|
Function factory(Type type) {
|
||||||
throw "Cannot find reflection information on ${stringify(type)}";
|
throw "Cannot find reflection information on ${stringify(type)}";
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,10 @@ import 'platform_reflection_capabilities.dart';
|
||||||
class ReflectionCapabilities implements PlatformReflectionCapabilities {
|
class ReflectionCapabilities implements PlatformReflectionCapabilities {
|
||||||
ReflectionCapabilities([metadataReader]) {}
|
ReflectionCapabilities([metadataReader]) {}
|
||||||
|
|
||||||
|
bool isReflectionEnabled() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
Function factory(Type type) {
|
Function factory(Type type) {
|
||||||
ClassMirror classMirror = reflectType(type);
|
ClassMirror classMirror = reflectType(type);
|
||||||
MethodMirror ctor = classMirror.declarations[classMirror.simpleName];
|
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; }
|
constructor(reflect?: any) { this._reflect = isPresent(reflect) ? reflect : global.Reflect; }
|
||||||
|
|
||||||
|
isReflectionEnabled(): boolean { return true; }
|
||||||
|
|
||||||
factory(t: Type): Function {
|
factory(t: Type): Function {
|
||||||
switch (t.length) {
|
switch (t.length) {
|
||||||
case 0:
|
case 0:
|
||||||
|
|
|
@ -27,6 +27,8 @@ export class Reflector {
|
||||||
this.reflectionCapabilities = reflectionCapabilities;
|
this.reflectionCapabilities = reflectionCapabilities;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isReflectionEnabled(): boolean { return this.reflectionCapabilities.isReflectionEnabled(); }
|
||||||
|
|
||||||
registerFunction(func: Function, funcInfo: StringMap<string, any>): void {
|
registerFunction(func: Function, funcInfo: StringMap<string, any>): void {
|
||||||
this._injectableInfo.set(func, funcInfo);
|
this._injectableInfo.set(func, funcInfo);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,8 @@ class NullReflectionCapabilities implements ReflectionCapabilities {
|
||||||
|
|
||||||
_notImplemented(String name) => throw 'Not implemented: $name';
|
_notImplemented(String name) => throw 'Not implemented: $name';
|
||||||
|
|
||||||
|
bool isReflectionEnabled() { return false; }
|
||||||
|
|
||||||
Function factory(Type type) => _notImplemented('factory');
|
Function factory(Type type) => _notImplemented('factory');
|
||||||
|
|
||||||
List<List> parameters(typeOrFunc) => _notImplemented('parameters');
|
List<List> parameters(typeOrFunc) => _notImplemented('parameters');
|
||||||
|
|
Loading…
Reference in New Issue