diff --git a/packages/zone.js/lib/browser/api-util.ts b/packages/zone.js/lib/browser/api-util.ts index 6c3e90fcb3..b192db2a4e 100644 --- a/packages/zone.js/lib/browser/api-util.ts +++ b/packages/zone.js/lib/browser/api-util.ts @@ -10,7 +10,6 @@ import {globalSources, patchEventPrototype, patchEventTarget, zoneSymbolEventNam 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'; import {patchCallbacks} from './browser-util'; -import {_redefineProperty} from './define-property'; import {eventNames, filterProperties} from './property-descriptor'; Zone.__load_patch('util', (global: any, Zone: ZoneType, api: _ZonePrivate) => { @@ -44,7 +43,7 @@ Zone.__load_patch('util', (global: any, Zone: ZoneType, api: _ZonePrivate) => { api.wrapWithCurrentZone = wrapWithCurrentZone; api.filterProperties = filterProperties; api.attachOriginToPatched = attachOriginToPatched; - api._redefineProperty = _redefineProperty; + api._redefineProperty = Object.defineProperty; api.patchCallbacks = patchCallbacks; api.getGlobalObjects = () => ({globalSources, zoneSymbolEventNames, eventNames, isBrowser, isMix, isNode, TRUE_STR, diff --git a/packages/zone.js/lib/browser/browser-legacy.ts b/packages/zone.js/lib/browser/browser-legacy.ts index d536151398..cf7d917e08 100644 --- a/packages/zone.js/lib/browser/browser-legacy.ts +++ b/packages/zone.js/lib/browser/browser-legacy.ts @@ -10,15 +10,20 @@ * @suppress {missingRequire} */ -import {propertyPatch} from './define-property'; +import {_redefineProperty, propertyPatch} from './define-property'; import {eventTargetLegacyPatch} from './event-target-legacy'; import {propertyDescriptorLegacyPatch} from './property-descriptor-legacy'; import {registerElementPatch} from './register-element'; (function(_global: any) { - _global[Zone.__symbol__('legacyPatch')] = function() { + const symbolPrefix = _global['__Zone_symbol_prefix'] || '__zone_symbol__'; + function __symbol__(name: string) { return symbolPrefix + name; } + _global[__symbol__('legacyPatch')] = function() { const Zone = _global['Zone']; - Zone.__load_patch('defineProperty', () => { propertyPatch(); }); + Zone.__load_patch('defineProperty', (global: any, Zone: ZoneType, api: _ZonePrivate) => { + api._redefineProperty = _redefineProperty; + propertyPatch(); + }); Zone.__load_patch('registerElement', (global: any, Zone: ZoneType, api: _ZonePrivate) => { registerElementPatch(global, api); }); diff --git a/packages/zone.js/lib/browser/define-property.ts b/packages/zone.js/lib/browser/define-property.ts index 7c00a68e12..68d4860251 100644 --- a/packages/zone.js/lib/browser/define-property.ts +++ b/packages/zone.js/lib/browser/define-property.ts @@ -11,14 +11,19 @@ * things like redefining `createdCallback` on an element. */ -const zoneSymbol = Zone.__symbol__; -const _defineProperty = (Object as any)[zoneSymbol('defineProperty')] = Object.defineProperty; -const _getOwnPropertyDescriptor = (Object as any)[zoneSymbol('getOwnPropertyDescriptor')] = - Object.getOwnPropertyDescriptor; -const _create = Object.create; -const unconfigurablesKey = zoneSymbol('unconfigurables'); +let zoneSymbol: any; +let _defineProperty: any; +let _getOwnPropertyDescriptor: any; +let _create: any; +let unconfigurablesKey: any; export function propertyPatch() { + zoneSymbol = Zone.__symbol__; + _defineProperty = (Object as any)[zoneSymbol('defineProperty')] = Object.defineProperty; + _getOwnPropertyDescriptor = (Object as any)[zoneSymbol('getOwnPropertyDescriptor')] = + Object.getOwnPropertyDescriptor; + _create = Object.create; + unconfigurablesKey = zoneSymbol('unconfigurables'); Object.defineProperty = function(obj: any, prop: string, desc: any) { if (isUnconfigurable(obj, prop)) { throw new TypeError('Cannot assign to read only property \'' + prop + '\' of ' + obj); diff --git a/packages/zone.js/test/BUILD.bazel b/packages/zone.js/test/BUILD.bazel index 045b544986..6c30bd4810 100644 --- a/packages/zone.js/test/BUILD.bazel +++ b/packages/zone.js/test/BUILD.bazel @@ -235,6 +235,11 @@ karma_tests = { "//packages/zone.js/dist:zone-evergreen-dist-dev-test", "//packages/zone.js/dist:zone-testing-dist-dev-test", ], + "browser_legacy_test": [ + "//packages/zone.js/dist:zone-legacy-dist-dev-test", + "//packages/zone.js/dist:zone-evergreen-dist-dev-test", + "//packages/zone.js/dist:zone-testing-dist-dev-test", + ], } karma_test(