Re: [v8-dev] Constness behavior of Handle vs. Object

Wed, 14 Apr 2021 04:08:48 -0700

I would imagine this would be solvable by providing different overloads for
const and non-const operator-> (and operator*) in Handle.

On Wed, Apr 14, 2021 at 11:51 AM 'Jakob Gruber' via v8-dev <
[email protected]> wrote:

> Hi team,
>
> I came across this yesterday and found the behavior surprising, thus this
> quick fyi email.
>
> `Handle<Object>` and `Object` class members have different behavior wrt to
> const. The former behaves like a plain old C++ pointer (`ClassXYZ*`) while
> the latter behaves like an instance (`ClassXYZ`). This is a bit strange,
> since conceptually both `Handle<Object>` and `Object` otherwise behave like
> pointers underneath (e.g. `Object x; x = y;` is a reference copy, not a
> value-copy).
>
> Examples:
>
> class C {
>  void foo() const { x_.nonconst_function(); }  // compile-time error.
>  ClassXYZ x_;
> }
>
> class C' {
>  void foo() const { x_->nonconst_function(); }  // okay.
>  ClassXYZ* x_;
> }
>
> class C'' {
>  void foo() const { x_.nonconst_function(); }  // compile-time error.
>  Object x_;
> }
>
> class C''' {
>  void foo() const { x_->nonconst_function(); }  // okay.
>  Handle<Object> x_;
> }
>
> While not terribly important, equal behavior between Object and
> Handle<Object> would be more consistent.
>
> --
> --
> v8-dev mailing list
> [email protected]
> http://groups.google.com/group/v8-dev
> ---
> You received this message because you are subscribed to the Google Groups
> "v8-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/v8-dev/CAH3p7oNJesNF0CuAsGe4O1UZoZGkio1ggZw_orGW3e4FLcTEhA%40mail.gmail.com
> <https://groups.google.com/d/msgid/v8-dev/CAH3p7oNJesNF0CuAsGe4O1UZoZGkio1ggZw_orGW3e4FLcTEhA%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
-- 
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- 
You received this message because you are subscribed to the Google Groups 
"v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-dev/CAGRskv-jeyZU1eTq1Bxk9FzLOQ%2BPDDP97hDU_PHghkUQFb6Fkg%40mail.gmail.com.

Reply via email to