Files
react-native/ReactCommon/react/renderer/core/Sealable.cpp
T
Joshua Gross 7f792c8376 ReactCommon/renderer/core: Migrate uses of NDEBUG to REACT_NATIVE_DEBUG + react_native_assert
Summary:
For better cross-platform consistency, migrate usages of NDEBUG to REACT_NATIVE_DEBUG. See flags.h for explanation.

Changelog: [Internal]

Reviewed By: PeteTheHeat

Differential Revision: D26695162

fbshipit-source-id: 5615355f76b9c78d0f8981b3443b7c5900939ede
2021-02-26 23:29:59 -08:00

67 lines
1.5 KiB
C++

/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include "Sealable.h"
#include <react/debug/flags.h>
#include <react/debug/react_native_assert.h>
namespace facebook {
namespace react {
/*
* Note:
* We must explicitly implement all *the rule of five* methods because:
* 1. Using `std::atomic` behind `sealed_` implicitly deletes default
* constructors;
* 2. We have to establish behaviour where any new cloned or moved instances
* of the object lose `sealed` flag.
*
* See more about the rule of three/five/zero:
* http://en.cppreference.com/w/cpp/language/rule_of_three
*/
#ifdef REACT_NATIVE_DEBUG
Sealable::Sealable() : sealed_(false) {}
Sealable::Sealable(const Sealable &other) : sealed_(false){};
Sealable::Sealable(Sealable &&other) noexcept : sealed_(false) {
other.ensureUnsealed();
};
Sealable::~Sealable() noexcept {};
Sealable &Sealable::operator=(const Sealable &other) {
ensureUnsealed();
return *this;
}
Sealable &Sealable::operator=(Sealable &&other) noexcept {
ensureUnsealed();
other.ensureUnsealed();
return *this;
}
void Sealable::seal() const {
sealed_ = true;
}
bool Sealable::getSealed() const {
return sealed_;
}
void Sealable::ensureUnsealed() const {
react_native_assert(!sealed_ && "Attempt to mutate a sealed object.");
}
#endif
} // namespace react
} // namespace facebook