Skip to content

Commit a91a55a

Browse files
JiaLiPassionkara
authored andcommitted
fix(zone.js): browser-legacy should not reference Zone (angular#32016)
PR Close angular#32016
1 parent 48487cb commit a91a55a

File tree

4 files changed

+25
-11
lines changed

4 files changed

+25
-11
lines changed

packages/zone.js/lib/browser/api-util.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {globalSources, patchEventPrototype, patchEventTarget, zoneSymbolEventNam
1010
import {ADD_EVENT_LISTENER_STR, ArraySlice, FALSE_STR, ObjectCreate, ObjectDefineProperty, ObjectGetOwnPropertyDescriptor, REMOVE_EVENT_LISTENER_STR, TRUE_STR, ZONE_SYMBOL_PREFIX, attachOriginToPatched, bindArguments, isBrowser, isIEOrEdge, isMix, isNode, patchClass, patchMacroTask, patchMethod, patchOnProperties, wrapWithCurrentZone} from '../common/utils';
1111

1212
import {patchCallbacks} from './browser-util';
13-
import {_redefineProperty} from './define-property';
1413
import {eventNames, filterProperties} from './property-descriptor';
1514

1615
Zone.__load_patch('util', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
@@ -44,7 +43,7 @@ Zone.__load_patch('util', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
4443
api.wrapWithCurrentZone = wrapWithCurrentZone;
4544
api.filterProperties = filterProperties;
4645
api.attachOriginToPatched = attachOriginToPatched;
47-
api._redefineProperty = _redefineProperty;
46+
api._redefineProperty = Object.defineProperty;
4847
api.patchCallbacks = patchCallbacks;
4948
api.getGlobalObjects = () =>
5049
({globalSources, zoneSymbolEventNames, eventNames, isBrowser, isMix, isNode, TRUE_STR,

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

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

13-
import {propertyPatch} from './define-property';
13+
import {_redefineProperty, propertyPatch} from './define-property';
1414
import {eventTargetLegacyPatch} from './event-target-legacy';
1515
import {propertyDescriptorLegacyPatch} from './property-descriptor-legacy';
1616
import {registerElementPatch} from './register-element';
1717

1818
(function(_global: any) {
19-
_global[Zone.__symbol__('legacyPatch')] = function() {
19+
const symbolPrefix = _global['__Zone_symbol_prefix'] || '__zone_symbol__';
20+
function __symbol__(name: string) { return symbolPrefix + name; }
21+
_global[__symbol__('legacyPatch')] = function() {
2022
const Zone = _global['Zone'];
21-
Zone.__load_patch('defineProperty', () => { propertyPatch(); });
23+
Zone.__load_patch('defineProperty', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
24+
api._redefineProperty = _redefineProperty;
25+
propertyPatch();
26+
});
2227
Zone.__load_patch('registerElement', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
2328
registerElementPatch(global, api);
2429
});

packages/zone.js/lib/browser/define-property.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,19 @@
1111
* things like redefining `createdCallback` on an element.
1212
*/
1313

14-
const zoneSymbol = Zone.__symbol__;
15-
const _defineProperty = (Object as any)[zoneSymbol('defineProperty')] = Object.defineProperty;
16-
const _getOwnPropertyDescriptor = (Object as any)[zoneSymbol('getOwnPropertyDescriptor')] =
17-
Object.getOwnPropertyDescriptor;
18-
const _create = Object.create;
19-
const unconfigurablesKey = zoneSymbol('unconfigurables');
14+
let zoneSymbol: any;
15+
let _defineProperty: any;
16+
let _getOwnPropertyDescriptor: any;
17+
let _create: any;
18+
let unconfigurablesKey: any;
2019

2120
export function propertyPatch() {
21+
zoneSymbol = Zone.__symbol__;
22+
_defineProperty = (Object as any)[zoneSymbol('defineProperty')] = Object.defineProperty;
23+
_getOwnPropertyDescriptor = (Object as any)[zoneSymbol('getOwnPropertyDescriptor')] =
24+
Object.getOwnPropertyDescriptor;
25+
_create = Object.create;
26+
unconfigurablesKey = zoneSymbol('unconfigurables');
2227
Object.defineProperty = function(obj: any, prop: string, desc: any) {
2328
if (isUnconfigurable(obj, prop)) {
2429
throw new TypeError('Cannot assign to read only property \'' + prop + '\' of ' + obj);

packages/zone.js/test/BUILD.bazel

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,11 @@ karma_tests = {
235235
"//packages/zone.js/dist:zone-evergreen-dist-dev-test",
236236
"//packages/zone.js/dist:zone-testing-dist-dev-test",
237237
],
238+
"browser_legacy_test": [
239+
"//packages/zone.js/dist:zone-legacy-dist-dev-test",
240+
"//packages/zone.js/dist:zone-evergreen-dist-dev-test",
241+
"//packages/zone.js/dist:zone-testing-dist-dev-test",
242+
],
238243
}
239244

240245
karma_test(

0 commit comments

Comments
 (0)