mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
refactor(devtools): prevent exeception on state serializer (#55061)
`Object.getPrototypeOf(obj)` returns `null` if `obj` is an empty object. `Object.getOwnPropertyDescriptors` throws on `null`/`undefined` PR Close #55061
This commit is contained in:
committed by
Dylan Hunn
parent
e02bcf89cf
commit
9a9ce0d419
@@ -21,7 +21,8 @@ export function getKeys(obj: {}): string[] {
|
||||
obj = unwrapSignal(obj);
|
||||
const properties = Object.getOwnPropertyNames(obj);
|
||||
|
||||
const prototypeMembers = Object.getOwnPropertyDescriptors(Object.getPrototypeOf(obj));
|
||||
// Object.getPrototypeOf can return null, on empty objectwithout prototype for example
|
||||
const prototypeMembers = Object.getOwnPropertyDescriptors(Object.getPrototypeOf(obj) ?? {});
|
||||
|
||||
const ignoreList = ['__proto__'];
|
||||
const gettersAndSetters = Object.keys(prototypeMembers).filter((methodName) => {
|
||||
|
||||
+7
@@ -531,6 +531,13 @@ describe('deeplySerializeSelectedProperties', () => {
|
||||
expect(getKeys(instance)).toEqual(['baz', 'foo', 'bar']);
|
||||
});
|
||||
|
||||
it('getKeys should not throw on empty object without prototype', () => {
|
||||
// creates an object without a prototype
|
||||
const instance = Object.create(null);
|
||||
|
||||
expect(getKeys(instance)).toEqual([]);
|
||||
});
|
||||
|
||||
it('getKeys would ignore getters and setters for "__proto__"', () => {
|
||||
const instance = {
|
||||
baz: 2,
|
||||
|
||||
Reference in New Issue
Block a user