Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit 6ca342a

Browse files
authored
Revert "fix(core): fix #405, refine the error message when zone.js already loaded. (#728)"
This reverts commit f3a3af3.
1 parent 4941141 commit 6ca342a

File tree

2 files changed

+4
-46
lines changed

2 files changed

+4
-46
lines changed

lib/zone.ts

+3-33
Original file line numberDiff line numberDiff line change
@@ -609,19 +609,7 @@ type AmbientZoneDelegate = ZoneDelegate;
609609

610610
const Zone: ZoneType = (function(global: any) {
611611
if (global['Zone']) {
612-
let zoneAlreadyLoadedMessage: string = 'Zone already loaded.';
613-
// try to findout the already loaded zone.js script file
614-
// require the loaded zone.js version to be newer than 0.8.6
615-
try {
616-
const LoadedZone: any = global['Zone'];
617-
const scriptFileName: string = LoadedZone['__zone_symbol__scriptFileName'];
618-
if (scriptFileName) {
619-
zoneAlreadyLoadedMessage =
620-
'Zone already loaded. The loaded Zone.js script file seems to be ' + scriptFileName;
621-
}
622-
} catch (error) {
623-
}
624-
throw new Error(zoneAlreadyLoadedMessage);
612+
throw new Error('Zone already loaded.');
625613
}
626614

627615
const NO_ZONE = {name: 'NO ZONE'};
@@ -636,17 +624,12 @@ const Zone: ZoneType = (function(global: any) {
636624

637625
static assertZonePatched() {
638626
if (global.Promise !== ZoneAwarePromise) {
639-
// try to findout the already loaded zone.js script file
640-
// require the loaded zone.js version to be newer than 0.8.6
641-
const scriptFileName: string = (Zone as any)[__symbol__('scriptFileName')];
642-
const scriptFileErrorMessage: string =
643-
scriptFileName ? 'the loaded Zone.js script file seems to be ' + scriptFileName : '';
644627
throw new Error(
645628
'Zone.js has detected that ZoneAwarePromise `(window|global).Promise` ' +
646629
'has been overwritten.\n' +
647630
'Most likely cause is that a Promise polyfill has been loaded ' +
648631
'after Zone.js (Polyfilling Promise api is not necessary when zone.js is loaded. ' +
649-
'If you must load one, do so before loading zone.js.)' + scriptFileErrorMessage);
632+
'If you must load one, do so before loading zone.js.)');
650633
}
651634
}
652635

@@ -1809,24 +1792,11 @@ const Zone: ZoneType = (function(global: any) {
18091792
// Chrome: at Zone.run (http://localhost:9876/base/build/lib/zone.js:100:24)
18101793
// FireFox: Zone.prototype.run@http://localhost:9876/base/build/lib/zone.js:101:24
18111794
// Safari: run@http://localhost:9876/base/build/lib/zone.js:101:24
1812-
let frameParts: string[] = frame.split('(');
1813-
let fnNamePart: string = frameParts[0];
1814-
1815-
let fnName: string = fnNamePart.split('@')[0];
1795+
let fnName: string = frame.split('(')[0].split('@')[0];
18161796
let frameType = FrameType.transition;
18171797
if (fnName.indexOf('ZoneAwareError') !== -1) {
18181798
zoneAwareFrame1 = frame;
18191799
zoneAwareFrame2 = frame.replace('Error.', '');
1820-
1821-
// try to find the filename where zone.js live with
1822-
let fileNamePart1: string = frameParts.length > 1 ? frameParts[1] : fnNamePart;
1823-
let fileNameParts: string[] = fileNamePart1.split('@');
1824-
let fileNamePart2: string =
1825-
fileNameParts.length > 1 ? fileNameParts[1] : fileNameParts[0];
1826-
// Keep a script file name in Zone, so when zone.js report 'already loaded'
1827-
// error, it can report which file include the loaded zone.js
1828-
(Zone as any)[__symbol__('scriptFileName')] = fileNamePart2;
1829-
18301800
blackListedStackFrames[zoneAwareFrame2] = FrameType.blackList;
18311801
}
18321802
if (fnName.indexOf('runGuarded') !== -1) {

test/common/zone.spec.ts

+1-13
Original file line numberDiff line numberDiff line change
@@ -328,24 +328,12 @@ describe('Zone', function() {
328328

329329
it('should throw when Promise has been patched', () => {
330330
class WrongPromise {}
331-
const errorMessage =
332-
'Zone.js has detected that ZoneAwarePromise `(window|global).Promise` ' +
333-
'has been overwritten.';
334-
const errorScriptMessage = 'the loaded Zone.js script file seems to be';
335331

336332
const ZoneAwarePromise = global.Promise;
337333
global.Promise = WrongPromise;
338334
try {
339335
expect(ZoneAwarePromise).toBeTruthy();
340-
try {
341-
Zone.assertZonePatched();
342-
} catch (error) {
343-
expect(error.message).toContain(errorMessage);
344-
expect(error.message).toContain(errorScriptMessage);
345-
const idx = error.message.lastIndexOf(errorScriptMessage);
346-
const fileName: string = error.message.slice(idx + errorScriptMessage.length);
347-
expect(fileName).toContain('zone.js');
348-
}
336+
expect(() => Zone.assertZonePatched()).toThrow();
349337
} finally {
350338
// restore it.
351339
global.Promise = ZoneAwarePromise;

0 commit comments

Comments
 (0)