Hello guys,
I'm trying to "wrap" a C++ object to JavaScript with this notorious
technique:
//------------------------------------------------------------------------
/// Wraps C++ instance to JS object.
v8::Persistent<v8::Object> wrap( T * object )
//------------------------------------------------------------------------
{
// Make sure we have only one JS object per C++ instance.
Instances::iterator it = m_instances.find( object );
if( it != m_instances.end() )
return it->second;
// Create an instance of JS object
v8::Persistent<v8::Object>
js_object( v8::Persistent<v8::Object>::New(m_t_object->GetFunction()-
>NewInstance()) );
// Make the handle weak
js_object.MakeWeak( object, &TClass<W,T>::destructorCall );
// Register the JS object with the C++ instance
m_instances.insert( std::make_pair( object, js_object ) );
// Set the internal field value to the C++ object
js_object->SetInternalField( 0, v8::External::New( object ) );
return js_object;
}
However a returned object has no class name set, so the "instanceof"
operator does not work. From what I've learned, the "instanceof"
operator works using the object.prototype.constructor property, though
I'm not sure how to correctly set it up in this wrap function.
Any ideas?
--
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users