Commit f2bab459 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

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: 's avatarMarja Hölttä <marja@chromium.org>
Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#43780}
parent d0e604bf
...@@ -106,12 +106,9 @@ class Handle final : public HandleBase { ...@@ -106,12 +106,9 @@ class Handle final : public HandleBase {
// Constructor for handling automatic up casting. // Constructor for handling automatic up casting.
// Ex. Handle<JSFunction> can be passed when Handle<Object> is expected. // Ex. Handle<JSFunction> can be passed when Handle<Object> is expected.
template <typename S> template <typename S>
V8_INLINE Handle(Handle<S> handle) V8_INLINE Handle(Handle<S> handle) : HandleBase(handle) {
: HandleBase(handle) { // Type check:
T* a = nullptr; static_assert(std::is_base_of<T, S>::value, "static type violation");
S* b = nullptr;
a = b; // Fake assignment to enforce type checks.
USE(a);
} }
V8_INLINE T* operator->() const { return operator*(); } V8_INLINE T* operator->() const { return operator*(); }
...@@ -192,10 +189,8 @@ class MaybeHandle final { ...@@ -192,10 +189,8 @@ class MaybeHandle final {
template <typename S> template <typename S>
V8_INLINE MaybeHandle(Handle<S> handle) V8_INLINE MaybeHandle(Handle<S> handle)
: location_(reinterpret_cast<T**>(handle.location_)) { : location_(reinterpret_cast<T**>(handle.location_)) {
T* a = nullptr; // Type check:
S* b = nullptr; static_assert(std::is_base_of<T, S>::value, "static type violation");
a = b; // Fake assignment to enforce type checks.
USE(a);
} }
// Constructor for handling automatic up casting. // Constructor for handling automatic up casting.
...@@ -203,10 +198,8 @@ class MaybeHandle final { ...@@ -203,10 +198,8 @@ class MaybeHandle final {
template <typename S> template <typename S>
V8_INLINE MaybeHandle(MaybeHandle<S> maybe_handle) V8_INLINE MaybeHandle(MaybeHandle<S> maybe_handle)
: location_(reinterpret_cast<T**>(maybe_handle.location_)) { : location_(reinterpret_cast<T**>(maybe_handle.location_)) {
T* a = nullptr; // Type check:
S* b = nullptr; static_assert(std::is_base_of<T, S>::value, "static type violation");
a = b; // Fake assignment to enforce type checks.
USE(a);
} }
template <typename S> template <typename S>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment