angular-cn/packages/core/test/acceptance
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
..
BUILD.bazel fix(ivy): module with providers are processed too early (#30688) 2019-05-31 09:48:39 -07:00
attributes_spec.ts perf(ivy): chain multiple attribute instructions (#31152) 2019-06-24 12:33:49 -07:00
change_detection_spec.ts test(core): update core tests (unrelated to queries) to use static flag (#30626) 2019-05-23 10:31:32 -07:00
common_integration_spec.ts test(ivy): move common integration tests to acceptance (#30213) 2019-05-14 11:37:50 -07:00
component_spec.ts fix(ivy): injecting incorrect Renderer2 into child components (#31063) 2019-06-24 11:33:31 -07:00
content_spec.ts refactor(ivy): simplify `walkTNodeTree` method for readability (#31182) 2019-06-25 17:03:51 -07:00
di_spec.ts fix(ivy): sync ViewRefs between multiple ViewContainerRefs (#30985) 2019-06-21 10:18:06 -07:00
directive_spec.ts test(core): update core tests (unrelated to queries) to use static flag (#30626) 2019-05-23 10:31:32 -07:00
discover_utils_spec.ts test(core): update core tests (unrelated to queries) to use static flag (#30626) 2019-05-23 10:31:32 -07:00
embedded_views_spec.ts fix(ivy): unable to bind to implicit receiver in embedded views (#30897) 2019-06-11 14:29:42 -07:00
exports_spec.ts refactor(ivy): move exports tests to acceptance (#30157) 2019-04-26 16:37:34 -07:00
host_binding_spec.ts test(core): update core tests (unrelated to queries) to use static flag (#30626) 2019-05-23 10:31:32 -07:00
i18n_spec.ts fix(ivy): reprojected ICU expression nodes when creating embedded views (#30979) 2019-06-18 09:48:46 -07:00
inherit_definition_feature_spec.ts test(ivy): Add TODOs (#30522) 2019-05-17 09:56:49 -07:00
integration_spec.ts fix(ivy): don't mask errors by calling lifecycle hooks after a crash (#31244) 2019-06-26 08:01:14 -07:00
lifecycle_spec.ts test(core): update core tests (unrelated to queries) to use static flag (#30626) 2019-05-23 10:31:32 -07:00
listener_spec.ts test(core): update core tests (unrelated to queries) to use static flag (#30626) 2019-05-23 10:31:32 -07:00
outputs_spec.ts test(core): update core tests (unrelated to queries) to use static flag (#30626) 2019-05-23 10:31:32 -07:00
pipe_spec.ts test(core): update core tests (unrelated to queries) to use static flag (#30626) 2019-05-23 10:31:32 -07:00
property_binding_spec.ts test(ivy): move property render3 tests to acceptance (#30426) 2019-05-14 09:39:22 -07:00
property_interpolation_spec.ts test(ivy): move property and attribute tests to acceptance (#30321) 2019-05-09 11:23:35 -07:00
providers_spec.ts fix(ivy): support injection flags for provider deps without new (#30216) 2019-04-30 20:37:56 -07:00
pure_function_spec.ts test(ivy): pure function acceptance tests (#30406) 2019-05-13 10:55:59 -07:00
query_spec.ts test(core): update query-specific tests in core (#30626) 2019-05-23 10:31:32 -07:00
renderer_factory_spec.ts test(ivy): move render3 renderer_factory tests to acceptance (#30435) 2019-05-14 09:36:24 -07:00
router_integration_spec.ts fix(ivy): module with providers are processed too early (#30688) 2019-05-31 09:48:39 -07:00
styling_next_spec.ts feat(ivy): in `ngDevMode` use named object literals and arrays for easier debugging/profiling (#30542) 2019-06-04 12:01:46 -07:00
styling_spec.ts fix(ivy): unable to bind SafeValue to clip-path (#30491) 2019-05-16 14:40:21 -07:00
template_ref_spec.ts test(core): update core tests (unrelated to queries) to use static flag (#30626) 2019-05-23 10:31:32 -07:00
text_spec.ts perf(ivy): remove check for function type in renderStringify (#30838) 2019-06-06 13:47:41 -07:00
view_container_ref_spec.ts fix(ivy): don't throw when attempting to destroy a destroyed ComponentRef (#31022) 2019-06-14 10:44:30 -07:00
view_insertion_spec.ts test(core): add missing static flag to view_insertion test view queries (#30967) 2019-06-11 09:37:19 -07:00
view_ref_spec.ts test(ivy): fix failing view ref test (#29178) 2019-03-07 18:56:22 -08:00