angular-cn/packages/core
Alex Rickabaugh 32c760f5e7 fix(ivy): don't mask errors by calling lifecycle hooks after a crash (#31244)
The Angular runtime frequently calls into user code (for example, when
writing to a property binding). Since user code can throw errors, calls to
it are frequently wrapped in a try-finally block. In Ivy, the following
pattern is common:

```typescript
enterView();
try {
  callUserCode();
} finally {
  leaveView();
}
```

This has a significant problem, however: `leaveView` has a side effect: it
calls any pending lifecycle hooks that might've been scheduled during the
current round of change detection. Generally it's a bad idea to run
lifecycle hooks after the application has crashed. The application is in an
inconsistent state - directives may not be instantiated fully, queries may
not be resolved, bindings may not have been applied, etc. Invariants that
the app code relies upon may not hold. Further crashes or broken behavior
are likely.

Frequently, lifecycle hooks are used to make assertions about these
invariants. When these assertions fail, they will throw and "swallow" the
original error, making debugging of the problem much more difficult.

This commit modifies `leaveView` to understand whether the application is
currently crashing, via a parameter `safeToRunHooks`. This parameter is set
by modifying the above pattern:

```typescript
enterView();
let safeToRunHooks = false;
try {
  callUserCode();
  safeToRunHooks = true;
} finally {
  leaveView(..., safeToRunHooks);
}
```

If `callUserCode` crashes, then `safeToRunHooks` will never be set to `true`
and `leaveView` won't call any further user code. The original error will
then propagate back up the stack and be reported correctly. A test is added
to verify this behavior.

PR Close #31244
2019-06-26 08:01:14 -07:00
..
schematics Revert "build: update to rules_nodejs 0.32.2 (#31019)" (#31267) 2019-06-25 14:36:00 -07:00
src fix(ivy): don't mask errors by calling lifecycle hooks after a crash (#31244) 2019-06-26 08:01:14 -07:00
test fix(ivy): don't mask errors by calling lifecycle hooks after a crash (#31244) 2019-06-26 08:01:14 -07:00
testing fix(core): temporarily remove @deprecated jsdoc tag for a TextBedStatic.get overload (#30714) 2019-06-14 10:40:42 -07:00
BUILD.bazel build: convert entry_point to label (#30627) 2019-06-11 00:03:11 +00:00
PACKAGE.md docs: add package doc files (#26047) 2018-10-05 15:42:14 -07:00
index.ts refactor: move angular source to /packages rather than modules/@angular 2017-03-08 16:29:27 -08:00
package.json build: upgrade zone.js to 0.9.1 (#30260) 2019-05-10 14:25:56 -07:00
public_api.ts build: publish tree of files rather than FESMs (#18541) 2017-08-31 15:34:50 -07:00