fix(zone.js): move property patch to legacy (#31660)

Close #31659

PR Close #31660
This commit is contained in:
JiaLiPassion 2019-07-20 00:00:33 +09:00 committed by Miško Hevery
parent a182714703
commit 716af1059c
3 changed files with 17 additions and 5 deletions

View File

@ -10,6 +10,7 @@
* @suppress {missingRequire} * @suppress {missingRequire}
*/ */
import {propertyPatch} from './define-property';
import {eventTargetLegacyPatch} from './event-target-legacy'; import {eventTargetLegacyPatch} from './event-target-legacy';
import {propertyDescriptorLegacyPatch} from './property-descriptor-legacy'; import {propertyDescriptorLegacyPatch} from './property-descriptor-legacy';
import {registerElementPatch} from './register-element'; import {registerElementPatch} from './register-element';
@ -17,6 +18,7 @@ import {registerElementPatch} from './register-element';
(function(_global: any) { (function(_global: any) {
_global[Zone.__symbol__('legacyPatch')] = function() { _global[Zone.__symbol__('legacyPatch')] = function() {
const Zone = _global['Zone']; const Zone = _global['Zone'];
Zone.__load_patch('defineProperty', () => { propertyPatch(); });
Zone.__load_patch('registerElement', (global: any, Zone: ZoneType, api: _ZonePrivate) => { Zone.__load_patch('registerElement', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
registerElementPatch(global, api); registerElementPatch(global, api);
}); });

View File

@ -15,7 +15,6 @@ import {patchTimer} from '../common/timers';
import {ZONE_SYMBOL_ADD_EVENT_LISTENER, ZONE_SYMBOL_REMOVE_EVENT_LISTENER, patchClass, patchMethod, patchPrototype, scheduleMacroTaskWithCurrentZone, zoneSymbol} from '../common/utils'; import {ZONE_SYMBOL_ADD_EVENT_LISTENER, ZONE_SYMBOL_REMOVE_EVENT_LISTENER, patchClass, patchMethod, patchPrototype, scheduleMacroTaskWithCurrentZone, zoneSymbol} from '../common/utils';
import {patchCustomElements} from './custom-elements'; import {patchCustomElements} from './custom-elements';
import {propertyPatch} from './define-property';
import {eventTargetPatch, patchEvent} from './event-target'; import {eventTargetPatch, patchEvent} from './event-target';
import {propertyDescriptorPatch} from './property-descriptor'; import {propertyDescriptorPatch} from './property-descriptor';
@ -68,7 +67,6 @@ Zone.__load_patch('EventTarget', (global: any, Zone: ZoneType, api: _ZonePrivate
Zone.__load_patch('on_property', (global: any, Zone: ZoneType, api: _ZonePrivate) => { Zone.__load_patch('on_property', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
propertyDescriptorPatch(api, global); propertyDescriptorPatch(api, global);
propertyPatch();
}); });
Zone.__load_patch('customElements', (global: any, Zone: ZoneType, api: _ZonePrivate) => { Zone.__load_patch('customElements', (global: any, Zone: ZoneType, api: _ZonePrivate) => {

View File

@ -13,15 +13,27 @@ describe('defineProperty', function() {
.not.toThrow(); .not.toThrow();
}); });
it('should not throw error when try to defineProperty with a frozen desc', function() { it('should not be able to change a frozen desc', function() {
const obj = {}; const obj = {};
const desc = Object.freeze({value: null, writable: true}); const desc = Object.freeze({value: null, writable: true});
Object.defineProperty(obj, 'prop', desc); Object.defineProperty(obj, 'prop', desc);
let objDesc: any = Object.getOwnPropertyDescriptor(obj, 'prop');
expect(objDesc.writable).toBeTruthy();
try {
Object.defineProperty(obj, 'prop', {configurable: true, writable: true, value: 'test'});
} catch (err) {
}
objDesc = Object.getOwnPropertyDescriptor(obj, 'prop');
expect(objDesc.configurable).toBeFalsy();
}); });
it('should not throw error when try to defineProperty with a frozen obj', function() { it('should not throw error when try to defineProperty with a frozen obj', function() {
const obj = {}; const obj = {};
Object.freeze(obj); Object.freeze(obj);
Object.defineProperty(obj, 'prop', {configurable: true, writable: true, value: 'value'}); try {
Object.defineProperty(obj, 'prop', {configurable: true, writable: true, value: 'value'});
} catch (err) {
}
expect((obj as any).prop).toBeFalsy();
}); });
}); });