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

Commit 3acc43a

Browse files
authored
Merge branch 'master' into socketio
2 parents 2469bc9 + 2dc7e5c commit 3acc43a

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

NON-STANDARD-APIS.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,20 @@ import 'zone.js/dist/zone-patch-rxjs';
162162

163163
* electron
164164

165+
In electron, we patched the following APIs with `zone.js`
166+
167+
1. Browser API
168+
2. NodeJS
169+
3. Electorn Native API
170+
165171
## Usage.
166172

167-
add following line into `polyfill.ts` after load zone-mix.
173+
add/update following line into `polyfill.ts`.
168174

169175
```
170-
import 'zone.js/dist/zone-patch-electron';
176+
//import 'zone.js/dist/zone'; // originally added by angular-cli, comment it out
177+
import 'zone.js/dist/zone-mix'; // add zone-mix to patch both Browser and Nodejs
178+
import 'zone.js/dist/zone-patch-electron'; // add zone-patch-electron to patch Electron native API
171179
```
172180

173181
there is a sample repo [zone-electron](https://github.com/JiaLiPassion/zone-electron) here
@@ -189,4 +197,3 @@ user need to patch `io` themselves just like following code.
189197

190198
please reference the sample repo [zone-socketio](https://github.com/JiaLiPassion/zone-socketio) about
191199
detail usage.
192-

lib/common/to-string.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@ import {zoneSymbol} from './utils';
99

1010
// override Function.prototype.toString to make zone.js patched function
1111
// look like native function
12-
Zone.__load_patch('toString', (global: any, Zone: ZoneType) => {
12+
Zone.__load_patch('toString', (global: any) => {
1313
// patch Func.prototype.toString to let them look like native
14-
const originalFunctionToString = (Zone as any)['__zone_symbol__originalToString'] =
15-
Function.prototype.toString;
14+
const originalFunctionToString = Function.prototype.toString;
1615

1716
const ORIGINAL_DELEGATE_SYMBOL = zoneSymbol('OriginalDelegate');
1817
const PROMISE_SYMBOL = zoneSymbol('Promise');
1918
const ERROR_SYMBOL = zoneSymbol('Error');
20-
Function.prototype.toString = function() {
19+
const newFunctionToString = function toString() {
2120
if (typeof this === 'function') {
2221
const originalDelegate = this[ORIGINAL_DELEGATE_SYMBOL];
2322
if (originalDelegate) {
@@ -42,6 +41,8 @@ Zone.__load_patch('toString', (global: any, Zone: ZoneType) => {
4241
}
4342
return originalFunctionToString.apply(this, arguments);
4443
};
44+
(newFunctionToString as any)[ORIGINAL_DELEGATE_SYMBOL] = originalFunctionToString;
45+
Function.prototype.toString = newFunctionToString;
4546

4647

4748
// patch Object.prototype.toString to let them look like native

test/common/toString.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ describe('global function patch', () => {
3636
expect(Function.prototype.toString.call(Error)).toContain('[native code]');
3737
});
3838

39+
it('Function toString should look like native', () => {
40+
expect(Function.prototype.toString.call(Function.prototype.toString)).toContain('[native code]');
41+
});
42+
3943
it('EventTarget addEventListener should look like native', ifEnvSupports('HTMLElement', () => {
4044
expect(Function.prototype.toString.call(HTMLElement.prototype.addEventListener))
4145
.toContain('[native code]');

0 commit comments

Comments
 (0)