Hello,

I have the following situation. I have a C++ class (Point) and I
wrapped it inside a JS object. In JS, I do something like:

Point.prototype.testProperty="Hi there!"
var p=new Point(1,2);
for(var i in p)
{
    trace("property: "+i);
}

Unfortunately, p doesn't have any property called testProperty.
Similar thing works just fine with 100% JS managed objects:

function Circle(r){
    this.radius=r;
    this.print=function(){
        trace("Radius: "+r);
    }
}

Circle.prototype.border="thick";

var c=new Circle(100);
for(var i in c)
{
    trace("property: "+i);
}

And the output is:
property: radius
property: print
property: border


Is it possible to alter the prototype of a wrapped C++ object from JS
or not?


Here is the C++ relevant part:

Persistent<FunctionTemplate> _pointFunctionTemplate;

_pointFunctionTemplate =
Persistent<FunctionTemplate>::New(FunctionTemplate::New(pointConstructor));
_pointFunctionTemplate->SetClassName(String::New("Point"));
_pointFunctionTemplate->PrototypeTemplate()->SetInternalFieldCount(1);
global->Set(String::New("Point"), _pointFunctionTemplate);


and the pointConstructor function is this:

Handle<Value> pointConstructor(const Arguments& args) {
        Handle<Object> result = _pointFunctionTemplate->PrototypeTemplate()-
>NewInstance();
        Point *pPoint = new Point(args[0]->ToNumber()->Uint32Value(), args[1]-
>ToNumber()->Uint32Value());
        result->SetInternalField(0, External::New(pPoint));
        return result;
}

Thank you very much

-- 
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users

Reply via email to