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

Wed, 14 Apr 2021 02:51:20 -0700

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
v8-dev@googlegroups.com
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 v8-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-dev/CAH3p7oNJesNF0CuAsGe4O1UZoZGkio1ggZw_orGW3e4FLcTEhA%40mail.gmail.com.

Reply via email to