Hi all,
I'm trying to create a constructor function within Javascript that, when
called, creates a javascript object, then creates a C++ object and ties it
to an External field in a Persistent Handle for that Javascript Object.
Basically, the idea is kinda like this:
var element = new Rectangle( 0, 0, 0, 0 );
And this calls this function:
HandleScope handleScope;
if ( args.Length() != 4 ) { //top x, top y, width, height
v8::Handle<v8::Boolean> result( v8::Boolean::New( false ) );
return handleScope.Close( result );
}
float x = args[0]->ToNumber()->Value();
float y = args[1]->ToNumber()->Value();
float width = args[2]->ToNumber()->Value();
float height = args[3]->ToNumber()->Value();
Rectangle *rectangle = new Rectangle( x, y, width, height, Color( CM_HSV,
randFloat(), 1, 1 ) );
me->mRectangleProxy->newInstance( args.This(), rectangle );
return args.This();
...where mRectangleProxy->newInstance essentially does the following:
v8::HandleScope handleScope;
v8::Context::Scope contextScope( mContext->getV8Context() );
//make the object weak
Persistent<Object> obj = Persistent<Object>::New( object );
//V8::AdjustAmountOfExternalAllocatedMemory( sizeof( Rectangle ) );
obj.MakeWeak( instance, mDeleter );
obj->SetInternalField( 0, External::New( instance ) );
return obj;
Anyway, the object is created and all of its methods defined, but the
object itself has no prototype. This concerns me, as I'd rather have the
object be like any other JS object. Any ideas on what I'm doing incorrectly?
Thanks!
--
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users