fix(core): properly handle function without prototype in reflector (#22284)

closes #19978

PR Close #22284
This commit is contained in:
Trotyl 2018-02-18 17:22:23 +08:00 committed by Victor Berchet
parent b42921bbd2
commit a7ebf5aadd
2 changed files with 8 additions and 1 deletions

View File

@ -252,7 +252,7 @@ function convertTsickleDecoratorIntoMetadata(decoratorInvocations: any[]): any[]
} }
function getParentCtor(ctor: Function): Type<any> { function getParentCtor(ctor: Function): Type<any> {
const parentProto = Object.getPrototypeOf(ctor.prototype); const parentProto = ctor.prototype ? Object.getPrototypeOf(ctor.prototype) : null;
const parentCtor = parentProto ? parentProto.constructor : null; const parentCtor = parentProto ? parentProto.constructor : null;
// Note: We always use `Object` as the null value // Note: We always use `Object` as the null value
// to simplify checking later on. // to simplify checking later on.

View File

@ -181,6 +181,13 @@ class TestObj {
expect(DELEGATE_CTOR.exec(ChildNoCtorPrivateProps.toString())).toBeTruthy(); expect(DELEGATE_CTOR.exec(ChildNoCtorPrivateProps.toString())).toBeTruthy();
expect(DELEGATE_CTOR.exec(ChildWithCtor.toString())).toBeFalsy(); expect(DELEGATE_CTOR.exec(ChildWithCtor.toString())).toBeFalsy();
}); });
it('should not throw when no prototype on type', () => {
// Cannot test arrow function here due to the compilation
const dummyArrowFn = function() {};
Object.defineProperty(dummyArrowFn, 'prototype', {value: undefined});
expect(() => reflector.annotations(dummyArrowFn as any)).not.toThrow();
});
}); });
describe('inheritance with decorators', () => { describe('inheritance with decorators', () => {