Skip to content

Commit 36bc164

Browse files
authored
fix(core): AugmentObject should handle the constructor property correctly (#12744)
1 parent af5b64a commit 36bc164

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

Diff for: packages/workflow/src/AugmentObject.ts

+3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export function augmentArray<T>(data: T[]): T[] {
3636
return Reflect.deleteProperty(getData(), key);
3737
},
3838
get(target, key: string, receiver): unknown {
39+
if (key === 'constructor') return Array;
3940
const value = Reflect.get(newData ?? target, key, receiver) as unknown;
4041
const newValue = augment(value);
4142
if (newValue !== value) {
@@ -83,6 +84,8 @@ export function augmentObject<T extends object>(data: T): T {
8384

8485
const proxy = new Proxy(data, {
8586
get(target, key: string, receiver): unknown {
87+
if (key === 'constructor') return Object;
88+
8689
if (deletedProperties.has(key)) {
8790
return undefined;
8891
}

Diff for: packages/workflow/test/AugmentObject.test.ts

+28
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ describe('AugmentObject', () => {
1010

1111
const augmentedObject = augmentArray(originalObject);
1212

13+
expect(augmentedObject.constructor.name).toEqual('Array');
14+
1315
expect(augmentedObject.push(5)).toEqual(6);
1416
expect(augmentedObject).toEqual([1, 2, 3, 4, null, 5]);
1517
expect(originalObject).toEqual(copyOriginal);
@@ -207,6 +209,8 @@ describe('AugmentObject', () => {
207209

208210
const augmentedObject = augmentObject(originalObject);
209211

212+
expect(augmentedObject.constructor.name).toEqual('Object');
213+
210214
augmentedObject[1] = 911;
211215
expect(originalObject[1]).toEqual(11);
212216
expect(augmentedObject[1]).toEqual(911);
@@ -589,5 +593,29 @@ describe('AugmentObject', () => {
589593
delete augmentedObject.toString;
590594
expect(augmentedObject.toString).toBeUndefined();
591595
});
596+
597+
test('should handle constructor property correctly', () => {
598+
const originalObject: any = {
599+
a: {
600+
b: {
601+
c: {
602+
d: '4',
603+
},
604+
},
605+
},
606+
};
607+
const augmentedObject = augmentObject(originalObject);
608+
609+
expect(augmentedObject.constructor.name).toEqual('Object');
610+
expect(augmentedObject.a.constructor.name).toEqual('Object');
611+
expect(augmentedObject.a.b.constructor.name).toEqual('Object');
612+
expect(augmentedObject.a.b.c.constructor.name).toEqual('Object');
613+
614+
augmentedObject.constructor = {};
615+
expect(augmentedObject.constructor.name).toEqual('Object');
616+
617+
delete augmentedObject.constructor;
618+
expect(augmentedObject.constructor.name).toEqual('Object');
619+
});
592620
});
593621
});

0 commit comments

Comments
 (0)