Fix static type checks in Handle and MaybeHandle
marja already introduced a std::is_base_of check in one of the Handle constructors. This CL uses this check for all templatized constructors in Handle and MaybeHandle instead of the current pointer assignment hack. R=marja@chromium.org, mstarzinger@chromium.org Change-Id: I0bdd77ccff4e95015e3b82e2db782a3ec57654fe Reviewed-on: https://chromium-review.googlesource.com/453480 Commit-Queue: Clemens Hammacher <clemensh@chromium.org> Reviewed-by: Marja Hölttä <marja@chromium.org> Reviewed-by: Michael Starzinger <mstarzinger@chromium.org> Cr-Commit-Position: refs/heads/master@{#43780}
This commit is contained in:
parent
d0e604bf26
commit
f2bab45967
@ -106,12 +106,9 @@ class Handle final : public HandleBase {
|
||||
// Constructor for handling automatic up casting.
|
||||
// Ex. Handle<JSFunction> can be passed when Handle<Object> is expected.
|
||||
template <typename S>
|
||||
V8_INLINE Handle(Handle<S> handle)
|
||||
: HandleBase(handle) {
|
||||
T* a = nullptr;
|
||||
S* b = nullptr;
|
||||
a = b; // Fake assignment to enforce type checks.
|
||||
USE(a);
|
||||
V8_INLINE Handle(Handle<S> handle) : HandleBase(handle) {
|
||||
// Type check:
|
||||
static_assert(std::is_base_of<T, S>::value, "static type violation");
|
||||
}
|
||||
|
||||
V8_INLINE T* operator->() const { return operator*(); }
|
||||
@ -192,10 +189,8 @@ class MaybeHandle final {
|
||||
template <typename S>
|
||||
V8_INLINE MaybeHandle(Handle<S> handle)
|
||||
: location_(reinterpret_cast<T**>(handle.location_)) {
|
||||
T* a = nullptr;
|
||||
S* b = nullptr;
|
||||
a = b; // Fake assignment to enforce type checks.
|
||||
USE(a);
|
||||
// Type check:
|
||||
static_assert(std::is_base_of<T, S>::value, "static type violation");
|
||||
}
|
||||
|
||||
// Constructor for handling automatic up casting.
|
||||
@ -203,10 +198,8 @@ class MaybeHandle final {
|
||||
template <typename S>
|
||||
V8_INLINE MaybeHandle(MaybeHandle<S> maybe_handle)
|
||||
: location_(reinterpret_cast<T**>(maybe_handle.location_)) {
|
||||
T* a = nullptr;
|
||||
S* b = nullptr;
|
||||
a = b; // Fake assignment to enforce type checks.
|
||||
USE(a);
|
||||
// Type check:
|
||||
static_assert(std::is_base_of<T, S>::value, "static type violation");
|
||||
}
|
||||
|
||||
template <typename S>
|
||||
|
Loading…
Reference in New Issue
Block a user