Commit graph

39 commits

Author SHA1 Message Date
arturovt
2235699b65 refactor(zone.js): drop isIE checks (#61091)
This should not be considered as a breaking change, because Angular doesn't support IE.

PR Close #61091
2025-05-02 07:53:35 -07:00
Joey Perrott
9dbe6fc18b refactor: update license text to point to angular.dev (#57901)
Update license text to point to angular.dev instead of angular.io

PR Close #57901
2024-09-24 15:33:00 +02:00
Joey Perrott
f307e95459 refactor: migrate zone.js to prettier formatting (#55427)
Migrate formatting to prettier for zone.js from clang-format

PR Close #55427
2024-04-29 09:52:05 -07:00
Doug Parker
1b9c807efa refactor(zone.js): update Zone bundles to call patch* functions (#53443)
Since each patch no longer contains top-level side effects, each bundled entry point needs to import and call its associated patch. For the most part this just means that each entry point imports the associated patch and invokes it at the top-level scope.

Note that many of these entry points did not actually have a dependency on `Zone` and had no guarantee that it was loaded prior to execution. To maintain consistency, the missing dependencies on `Zone` are left as-is. They will use the global instance of `Zone` and if users fail to load it prior to importing a specific patch, then the patch will fail just as it did previously.

PR Close #53443
2024-03-15 18:11:33 -07:00
Doug Parker
a75d9de874 refactor(zone.js): wrap browser-legacy.ts in a patchBrowserLegacy function. (#53443)
This particular is slightly different from the others because it does not have a hard dependency on `Zone`. It doesn't actually use `Zone` directly during the patch because the patch just sets a `legacyPatch` global. To maintain consistency, this continues to use global `Zone` and does _not_ accept `Zone` as a parameter. While it's using a global in an inconvenient way, this isn't a problem right now because it doesn't cause or require a dependency on a top-level side effect.

PR Close #53443
2024-03-15 18:11:33 -07:00
Doug Parker
7c1991048b refactor(zone.js): wrap Zone.__load_patch calls in exported functions (#53443)
This removes top-level side effects from each of these files and drops the dependency on global `Zone`, instead allowing it to be provided to each patch as a parameter.

Most of these are pure mechanical transformations. A couple notable files which were somewhat unique:

* `async-test.ts`, `fake-async-test.ts`, and `wtf.ts` had unique IIFE usage and patch `Zone` itself. This removes the IIFE and exports the function instead.
* `jest.ts` and `jasmine.ts` have a unique `jest` global usage which needs to be declared.

PR Close #53443
2024-03-15 18:11:33 -07:00
arturovt
1c990cdb29 fix(zone.js): patch form-associated custom element callbacks (#50686)
This commit updates the implementation of the `customElements` patch and also
patches FACE callbacks (`formAssociatedCallback`, `formDisabledCallback`, `formResetCallback`
and `formStateRestoreCallback`). This now allows invoking those callbacks in the same zone
where the custom element has been defined.

PR Close #50686
2024-02-12 08:50:55 -08:00
Alan Agius
a8efc605ea feat(zone.js): remove legacy files and access to deep imports (#51752)
This commit removes access to deep imports and `zone-testing-bundle` and `zone-testing-node-bundle`

This commit removed access to deep and legacy `dist` imports. `zone-testing-bundle` and `zone-testing-node-bundle` are also no longer generated.

BREAKING CHANGE:
Deep and legacy `dist/` imports like `zone.js/bundles/zone-testing.js` and `zone.js/dist/zone` are no longer allowed. `zone-testing-bundle` and `zone-testing-node-bundle` are also no longer part of the package.

The proper way to import `zone.js` and `zone.js/testing` is:
```js
import 'zone.js';
import 'zone.js/testing';
```

PR Close #51752
2023-09-14 12:11:05 +02:00
Alan Agius
7837f7119f fix(zone.js): enable monkey patching of the queueMicrotask() API in node.js (#50530)
Similar to the browser, now we also monkey patch `queueMicrotask` in Node.js. This API was added in Node.js 11.

PR Close #50530
2023-06-07 12:42:33 -07:00
Jessica Janiuk
7567348c54 Revert "fix(zone.js): enable monkey patching of the queueMicrotask() API in node.js (#50467)" (#50529)
This reverts commit 381cb98226.

PR Close #50529
2023-05-31 09:57:42 -07:00
Alan Agius
381cb98226 fix(zone.js): enable monkey patching of the queueMicrotask() API in node.js (#50467)
Similar to the browser, now we also monkey patch `queueMicrotask` in Node.js. This API was added in Node.js 11.

PR Close #50467
2023-05-30 12:57:45 -07:00
John Vandenberg
c14c701775 docs: fix spelling (#46713)
PR Close #46713
2022-07-08 20:54:52 +00:00
arturovt
4ea70e36b9 fix(zone.js): swallow the error when the element callback is not patchable (#45400)
The `patchCallbacks` is used for patching the `document.registerElement` and
`customElements.define`. We explicitly wrap the patching code into try-catch since
callbacks may be already patched by other web components frameworks (e.g. LWC), and they
make those properties non-writable. This means that patching callback will throw an error
`cannot assign to read-only property`. See this code as an example:
https://github.com/salesforce/lwc/blob/master/packages/@lwc/engine-core/src/framework/base-bridge-element.ts#L180-L186
We don't want to stop the application rendering if we couldn't patch some
callback, e.g. `attributeChangedCallback`.

PR Close #42546

PR Close #45400
2022-03-25 16:31:09 -07:00
JiaLiPassion
b437d1238d fix(zone.js): defineProperties should also set symbol props (#45098)
Close #44095

Fix `defineProperties` patch not set `symbol` props issue.

Co-authored-by: varomodt<varomodt@users.noreply.github.com>
Co-authored-by: AndrewKushnir<AndrewKushnir@users.noreply.github.com>

PR Close #45098
2022-03-03 12:22:05 -08:00
JiaLiPassion
1b85811c00 refactor(zone.js): for legacy browser, still use hard coding eventNames (#40962)
For legacy browsers, we still use the eventNames array to patch event instead of
using `Object.getOwnPropertyNames()` to keep backward compatibility.

PR Close #40962
2022-03-01 18:41:15 +00:00
JiaLiPassion
0f298a13db refactor(zone.js): remove onProp eventNames array to reduce the bundle size (#40962)
Zone.js supports the google closure compiler in the advance optimization mode,
to prevent closure compiler modify the `onProperty` name such as `Element.prototype.onclick`,
Zone.js implements the `onProperty` patch logic by declaring all the
event names in the source code, this increases the bundle size and also require
updating the event names array to keep the information updated.

Now google closure compiler has the required event names defined in the built-in
externs files, so zone.js can use more simple implementation and decrease the bundle size
of zone.js (about 4k).

PR Close #40962
2022-03-01 18:41:15 +00:00
JiaLiPassion
008eaf3b7d fix(zone.js): should continue to executue listeners when throw error (#41562)
Close #41522

`zone.js` patches event listeners and run all event listeners together, if
one event handler throws error, the listeners afterward may not be invoked.

Reproduction:

```
export class AppComponent implements AfterViewInit {
  @ViewChild('btn') btn: ElementRef;
  title = 'event-error';

  constructor(private ngZone: NgZone) {}

  ngAfterViewInit() {
    this.ngZone.runOutsideAngular(() => {
      this.btn.nativeElement.addEventListener('click', () => {
        throw new Error('test1');
      });
      this.btn.nativeElement.addEventListener('click', () => {
        console.log('add eventlistener click');
      });
    });
  }
}
```

Until now no Angular users report this issue becuase in the `ngZone`, all
error will be caught and will not rethrow, so the event listeners afterward
will still continue to execute, but if the event handlers are outside of `ngZone`,
the error will break the execution.

This commit catch all errors, and after all event listeners finished invocation,
rethrow the errors in seperate `microTasks`, the reason I am using `microTask` here
is to handle multiple errors case.

PR Close #41562
2021-04-21 15:54:08 -07:00
Andrew Kushnir
d58747de8a Revert "fix(zone.js): should continue to executue listeners when throw error (#41562)" (#41707)
This reverts commit 5c48cd30b5.

Reason: that change introduces race conditions on CI.

PR Close #41707
2021-04-19 13:33:10 -07:00
JiaLiPassion
5c48cd30b5 fix(zone.js): should continue to executue listeners when throw error (#41562)
Close #41522

`zone.js` patches event listeners and run all event listeners together, if
one event handler throws error, the listeners afterward may not be invoked.

Reproduction:

```
export class AppComponent implements AfterViewInit {
  @ViewChild('btn') btn: ElementRef;
  title = 'event-error';

  constructor(private ngZone: NgZone) {}

  ngAfterViewInit() {
    this.ngZone.runOutsideAngular(() => {
      this.btn.nativeElement.addEventListener('click', () => {
        throw new Error('test1');
      });
      this.btn.nativeElement.addEventListener('click', () => {
        console.log('add eventlistener click');
      });
    });
  }
}
```

Until now no Angular users report this issue becuase in the `ngZone`, all
error will be caught and will not rethrow, so the event listeners afterward
will still continue to execute, but if the event handlers are outside of `ngZone`,
the error will break the execution.

This commit catch all errors, and after all event listeners finished invocation,
rethrow the errors in seperate `microTasks`, the reason I am using `microTask` here
is to handle multiple errors case.

PR Close #41562
2021-04-19 08:38:42 -07:00
Jon Jaques
d28197db15 refactor(zone.js): update Object.create params to match web platform (#34287)
This commit updates `Object.create` argument names used in Zone.js to match web platform.

PR Close #34287
2021-02-22 08:47:39 -08:00
JiaLiPassion
27358eb60f feat(zone.js): monkey patches queueMicrotask() (#38904)
Close #38863

Monkey patches `queueMicrotask()` API, so the callback runs in the zone
when scheduled, and also the task is run as `microTask`.

```
Zone.current.fork({
  name: 'queueMicrotask',
  onScheduleTask: (delegate: ZoneDelegate, curr: Zone, target: Zone, task: Task) => {
    logs.push(task.type);
    logs.push(task.source);
    return delegate.scheduleTask(target, task);
  }
}).run(() => {
    queueMicrotask(() => {
      expect(logs).toEqual(['microTask', 'queueMicrotask']);
      expect(Zone.current.name).toEqual('queueMicrotask');
      done();
  });
});

```

PR Close #38904
2020-11-05 11:23:33 -08:00
JiaLiPassion
d92a0dd72f fix(zone.js): should invoke xhr send task when no response error occurs (#38836)
Close #38795

in the XMLHttpRequest patch, when get `readystatechange` event, zone.js try to
invoke `load` event listener first, then call `invokeTask` to finish the
`XMLHttpRequest::send` macroTask, but if the request failed because the
server can not be reached, the `load` event listener will not be invoked,
so the `invokeTask` of the `XMLHttpRequest::send` will not be triggered either,
so we will have a non finished macroTask there which will make the Zone
not stable, also memory leak.

So in this PR, if the `XMLHttpRequest.status = 0` when we get the `readystatechange`
event, that means something wents wrong before we reached the server, we need to
invoke the task to finish the macroTask.

PR Close #38836
2020-09-18 11:19:37 -07:00
JiaLiPassion
40096bee00 fix(zone.js): run tests in umd format (#37582)
Since the `defineProperty` not swallow error any longer, now the tests compile
source code in `commonjs` mode, and the code generated includes the code like this
```
Object.defineProperty(exports, "__esModule", {value: true});
```

And the `exports` is undefined in some browsers, but the error is swallowed before
this PR, and all tests run successfully, but it is not correct behavior. After this PR,
the code above failed. So we need to compile the source code in `umd` mode.

PR Close #37582
2020-09-08 12:44:18 -07:00
JiaLiPassion
45a73dddfd fix(zone.js): defineProperty patch should not swallow error (#37582)
Close #37432

zone.js monkey patches the `Object.defineProperty` API long time ago
angular/zone.js@383b479
to resolve issues in very old version of Chrome web which override the
property of `CustomElements`, and this is not an issue any longer, so
we want to remove this monkey patch, since it may swallow the errors when the user
want to define property on unconfigurable or frozen object properties.
But currently there are several apps and tests depends on this patch, since
it also change the `configurable` property to `true` by default, so
in this PR we update the logic to not to swallow error any longer unless the property
is the callbacks of `document.registerElements`.

BREAKING CHANGE:

ZoneJS no longer swallows errors produced by `Object.defineProperty` calls.

Prior to this change, ZoneJS monkey patched `Object.defineProperty` and if there is an error
(such as the property is not configurable or not writable) the patched logic swallowed it
and only console.log was produced. This behavior used to hide real errors,
so the logic is now updated to trigger original errors (if any). One exception
where the patch remains in place is `document.registerElement`
(to allow smooth transition for code/polyfills that rely on old behavior in legacy browsers).
If your code relies on the old behavior (where errors were not thrown before),
you may need to update the logic to handle the errors that are no longer masked by ZoneJS patch.

PR Close #37582
2020-09-08 12:44:18 -07:00
JiaLiPassion
253337dc0a feat(zone.js): move MutationObserver/FileReader to different module (#31657)
Separate `EventTarget`, `FileReader`, `MutationObserver` and `IntersectionObserver` patches into different module.
So the user can disable those modules separately.

PR Close #31657
2020-07-24 15:12:28 -07:00
Joey Perrott
d1ea1f4c7f build: update license headers to reference Google LLC (#37205)
Update the license headers throughout the repository to reference Google LLC
rather than Google Inc, for the required license headers.

PR Close #37205
2020-05-26 14:26:58 -04:00
Alan Agius
13ba84731f build: prepare for TypeScript 3.9 (#36989)
- Fix several compilation errors
- Update @microsoft/api-extractor to be compatible with TypeScript 3.9

PR Close #36989
2020-05-14 10:50:28 -07:00
Joey Perrott
698b0288be build: reformat repo to new clang@1.4.0 (#36613)
PR Close #36613
2020-04-14 12:08:36 -07:00
JiaLiPassion
0f8e710c7c feat(zone.js): Monkey patch MessagePort.prototype onproperties (#34610)
Monkey patch `MessagePort.prototype.onmessage` and `MessagePort.prototype.onmessageerror` to make
these properties's value(callback function) run in the zone when these value are set.

PR Close #34610
2020-03-16 08:59:38 -07:00
Andrew Kushnir
71309d223d Revert "feat: Monkey patches MessagePort onproperties (onmessage/onmessageerror) (#34610)" (#35973)
This reverts commit 1882451ec0.

Reason: breaks some g3 targets.

PR Close #35973
2020-03-09 17:31:28 -04:00
JiaLiPassion
1882451ec0 feat: Monkey patches MessagePort onproperties (onmessage/onmessageerror) (#34610)
Close #34581

PR Close #34610
2020-03-09 12:20:46 -04:00
JiaLiPassion
71b8e271b3 fix: fixes typo of zone.js patch vrdisplaydisconnected property (#33581)
Close #33579

PR Close #33581
2019-11-18 15:46:52 -08:00
JiaLiPassion
a91a55a6d2 fix(zone.js): browser-legacy should not reference Zone (#32016)
PR Close #32016
2019-08-13 09:53:00 -07:00
JiaLiPassion
2c402d5c99 fix(zone.js): handle MSPointer event correctly (#31722)
Close #31699

PR Close #31722
2019-07-24 14:42:49 -07:00
JiaLiPassion
35a025fbca fix(zone.js): patch shadydom (#31717)
Close #31686

PR Close #31717
2019-07-24 14:42:14 -07:00
JiaLiPassion
716af1059c fix(zone.js): move property patch to legacy (#31660)
Close #31659

PR Close #31660
2019-07-24 14:36:43 -07:00
Paul Gschwendtner
60f58bf051 refactor: ensure zone.js can be built with typescript strict flag (#30993)
As part of FW-1265, the `zone.js` package is made compatible
with the TypeScript `--strict` flag. Read more about the strict flag [here](https://www.typescriptlang.org/docs/handbook/compiler-options.html)

PR Close #30993
2019-07-18 14:21:26 -07:00
Hamid
9204de96a1 fix: use the correct WTF array to iterate over (#31208)
PR Close #31208
2019-07-11 15:08:54 -04:00
JiaLiPassion
5eb7426216 build: move zone.js to angular repo (#30962)
PR Close #30962
2019-06-20 11:27:39 -07:00