// Copyright 2016 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. namespace WTF { template bool isInBounds(From value) { return true; } template To safeCast(From value) { if (!isInBounds(value)) return 0; return static_cast(value); } template class Checked { public: template Checked(const Checked& rhs){ if (rhs.hasOverflowed()) this->overflowed(); if (!isInBounds(rhs.m_value)) this->overflowed(); m_value = static_cast(rhs.m_value); } bool hasOverflowed() const { return false; } void overflowed() { } private: T m_value; }; template To bitwise_cast(From from) { static_assert(sizeof(To) == sizeof(From), "msg"); return reinterpret_cast(from); } } // namespace WTF namespace mojo { template struct ArrayTraits; template struct ArrayTraits> { static bool HasOverflowed(WTF::Checked& input) { // |hasOverflowed| below should be rewritten to |HasOverflowed| // (because this is a method of WTF::Checked; it doesn't matter // that we are not in WTF namespace *here*). return input.hasOverflowed(); } }; } // namespace mojo using WTF::bitwise_cast; using WTF::safeCast;