Skip to content

Commit a7ebf5a

Browse files
trotylvicb
authored andcommitted
fix(core): properly handle function without prototype in reflector (#22284)
closes #19978 PR Close #22284
1 parent b42921b commit a7ebf5a

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

packages/core/src/reflection/reflection_capabilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ function convertTsickleDecoratorIntoMetadata(decoratorInvocations: any[]): any[]
252252
}
253253

254254
function getParentCtor(ctor: Function): Type<any> {
255-
const parentProto = Object.getPrototypeOf(ctor.prototype);
255+
const parentProto = ctor.prototype ? Object.getPrototypeOf(ctor.prototype) : null;
256256
const parentCtor = parentProto ? parentProto.constructor : null;
257257
// Note: We always use `Object` as the null value
258258
// to simplify checking later on.

packages/core/test/reflection/reflector_spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,13 @@ class TestObj {
181181
expect(DELEGATE_CTOR.exec(ChildNoCtorPrivateProps.toString())).toBeTruthy();
182182
expect(DELEGATE_CTOR.exec(ChildWithCtor.toString())).toBeFalsy();
183183
});
184+
185+
it('should not throw when no prototype on type', () => {
186+
// Cannot test arrow function here due to the compilation
187+
const dummyArrowFn = function() {};
188+
Object.defineProperty(dummyArrowFn, 'prototype', {value: undefined});
189+
expect(() => reflector.annotations(dummyArrowFn as any)).not.toThrow();
190+
});
184191
});
185192

186193
describe('inheritance with decorators', () => {

0 commit comments

Comments
 (0)