On Sat, Sep 25, 2010 at 5:45 PM, Brad <[email protected]> wrote:
> However, there is a C++ class String
> with real C++ functions on it. And a Handle<String> is just a (smart)
> pointer to an instance of that class.
>
Not really. Handle<String> is a smart pointer to String*.
There is no instance of String. V8 never created an instance of class
String. There is nothing that guarantees that what one finds in memory at
the address represented by a (tagged) String* corresponds to what a C++
compiler thinks should be an instance of String.
>From the standard: "a reference shall be initialized to refer to a valid
object or function".
There is no way for us to get a reference to a String in the first place
other than dereferencing a String*, which seems kind of dodgy because it
isn't really a pointer to a String.
We're cheating ("leveraging") the C++ type system to impose a hierarchy on
V8's heap objects. To actually imagine that there are C++ objects would be
carrying it a step to far.
In other words, it's not operator* that does the wrong thing, but
operator->.
> * It is safe to extract the object stored in the handle by
> * dereferencing the handle (for instance, to extract the Object* from
> * an Handle<Object>); the value will still be governed by a handle
> * behind the scenes and the same rules apply to these values as to
> * their handles.
>
Caveats: the raw pointer value is still governed by a handle so long as it
does not escape the handle scope of the handle. And the pointer will be
possibly invalid after a GC occurs.
> (After all, when you dereference a String*, you get a
> String&.)
We never dereference a String* :)
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev