Skip to content

Commit 716af10

Browse files
JiaLiPassionmhevery
authored andcommitted
fix(zone.js): move property patch to legacy (#31660)
Close #31659 PR Close #31660
1 parent a182714 commit 716af10

3 files changed

Lines changed: 17 additions & 5 deletions

File tree

packages/zone.js/lib/browser/browser-legacy.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@
1010
* @suppress {missingRequire}
1111
*/
1212

13+
import {propertyPatch} from './define-property';
1314
import {eventTargetLegacyPatch} from './event-target-legacy';
1415
import {propertyDescriptorLegacyPatch} from './property-descriptor-legacy';
1516
import {registerElementPatch} from './register-element';
1617

1718
(function(_global: any) {
1819
_global[Zone.__symbol__('legacyPatch')] = function() {
1920
const Zone = _global['Zone'];
21+
Zone.__load_patch('defineProperty', () => { propertyPatch(); });
2022
Zone.__load_patch('registerElement', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
2123
registerElementPatch(global, api);
2224
});

packages/zone.js/lib/browser/browser.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import {patchTimer} from '../common/timers';
1515
import {ZONE_SYMBOL_ADD_EVENT_LISTENER, ZONE_SYMBOL_REMOVE_EVENT_LISTENER, patchClass, patchMethod, patchPrototype, scheduleMacroTaskWithCurrentZone, zoneSymbol} from '../common/utils';
1616

1717
import {patchCustomElements} from './custom-elements';
18-
import {propertyPatch} from './define-property';
1918
import {eventTargetPatch, patchEvent} from './event-target';
2019
import {propertyDescriptorPatch} from './property-descriptor';
2120

@@ -68,7 +67,6 @@ Zone.__load_patch('EventTarget', (global: any, Zone: ZoneType, api: _ZonePrivate
6867

6968
Zone.__load_patch('on_property', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
7069
propertyDescriptorPatch(api, global);
71-
propertyPatch();
7270
});
7371

7472
Zone.__load_patch('customElements', (global: any, Zone: ZoneType, api: _ZonePrivate) => {

packages/zone.js/test/browser/define-property.spec.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,27 @@ describe('defineProperty', function() {
1313
.not.toThrow();
1414
});
1515

16-
it('should not throw error when try to defineProperty with a frozen desc', function() {
16+
it('should not be able to change a frozen desc', function() {
1717
const obj = {};
1818
const desc = Object.freeze({value: null, writable: true});
1919
Object.defineProperty(obj, 'prop', desc);
20+
let objDesc: any = Object.getOwnPropertyDescriptor(obj, 'prop');
21+
expect(objDesc.writable).toBeTruthy();
22+
try {
23+
Object.defineProperty(obj, 'prop', {configurable: true, writable: true, value: 'test'});
24+
} catch (err) {
25+
}
26+
objDesc = Object.getOwnPropertyDescriptor(obj, 'prop');
27+
expect(objDesc.configurable).toBeFalsy();
2028
});
2129

2230
it('should not throw error when try to defineProperty with a frozen obj', function() {
2331
const obj = {};
2432
Object.freeze(obj);
25-
Object.defineProperty(obj, 'prop', {configurable: true, writable: true, value: 'value'});
33+
try {
34+
Object.defineProperty(obj, 'prop', {configurable: true, writable: true, value: 'value'});
35+
} catch (err) {
36+
}
37+
expect((obj as any).prop).toBeFalsy();
2638
});
27-
});
39+
});

0 commit comments

Comments
 (0)