mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-07 04:26:32 +08:00
In the Chromium backend engineers can use `DCHECK()` to ensure certain invariants are held, but only execute these assertions in a debug build. [1] Release builds do not ship with DCHECKS enabled. In a similar fashion, introduce a build-time generated function `DHCECK` that is only generated when `devtools_dcheck_always_on` is set as GN arg. By default, `is_debug` builds enable `devtools_dcheck_always_on`. However, in a release build, you can explicitly set `devtools_dcheck_always_on` to `true` to achieve the same effect. When the GN arg is set, the build generates the `dcheck.js` file with an implementation that checks the condition and fails if it is not met. When the arg is not set, the function implementation remains empty and becomes a noop. To make sure that these functions calls are removed in a release build (rather than being a noop), the terser configuration is updated to treat these functions as pure. As such, terser will remove any calls if the function implementation is empty. In a release build that explicitly turns out the dchecks, terser will not remove the function calls. Lastly, to make sure that all code related to the dcheck is removed, the condition needs to be a lambda. If we were to make it a raw boolean, then `terser` would not be able to determine whether it can remove the condition itself and would leave that behind. In other words, the `DCHECK` call would still leave some artifacts behind, namely the condition computation itself. By making it a lambda, terser can deduce that the lambda creation has no side-effect and remove the lambda if the `DHCECK` call is removed. R=aerotwist@chromium.org [1]: https://chromium.googlesource.com/chromium/src/+/HEAD/styleguide/c++/c++.md#check_dcheck_and-notreached Bug: none Change-Id: Ic396f102141d9eb67c8690bd2a601b56061b9d8c Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2894390 Auto-Submit: Tim van der Lippe <tvanderlippe@chromium.org> Reviewed-by: Paul Lewis <aerotwist@chromium.org> Reviewed-by: Jack Franklin <jacktfranklin@chromium.org> Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org> Commit-Queue: Jack Franklin <jacktfranklin@chromium.org>
5 lines
239 B
TypeScript
5 lines
239 B
TypeScript
// Copyright 2021 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
export function DCHECK(condition: () => boolean, message?: string): void;
|