Feature #165

avatar

Reconsider root<T> API

Added by Ash Berlin 255 days ago. Updated 146 days ago.

Status:New Start:11/16/2009
Priority:Normal Due date:
Assigned to:- % Done:

0%

Category:C++-API
Target version:0.10

Description

So the changes that Aristid landed as part of #147 seemed to cause compilation problems on OSX - related to a probably bug in Apple's build of GCC. Ignoring the fact that there is a bug in that gcc, the problem was that roots are not currently copyable.

From an API user point of view, it would make a lot more sense if you could copy root objects. As they currently stand they are too expensive to copy.

Idea 1

One solution would be to make them much cheaper copy - probably by making them behave like pointers (i.e. have operator ->() and operator *() methods.)

Currently, since root< object > inherits object you can do:

root_object obj(...);
obj.set_property(...);

Under the this idea, it would change to obj->set_property. If we go with this route, we should probably change the class name to avoid confusion – Perhaps to handle. Yes this is what v8 uses, its not entirely unintentional. -- in v8 Handle<> is the base class shared by Persistent<> (which is what we are talking about here), and Local<> which is tied to a HandleScope object – which is similar but not quite the same as our local_root_scope (HandleScope protects all local handles created while it is alive, where as our local_root_scope only protects newly created values.)

Anyway - the v8 handle API:

Point* p = ...;
Local<Object> obj = point_templ->NewInstance();
obj->SetInternalField(0, External::New(p));

Idea2

The other idea is to have a shared-resource (a ref counter or similar) in the root object, and only remove the root when the last root<> goes out of scope. Copying an object or similar shouldn't be too expensive, and the root object will share the underlying JSObject* or jsval.

The first idea might be a better idea as it might make adding a v8 engine easier.


Related issues

blocks Feature #12 Evaluate conversion API Assigned 03/29/2009

History

Updated by Aristid Breitkreuz 255 days ago

avatar

Idea 2 would not work because each copy has a different gcptr.

But generally I like this, because it would make a lot of things easier.

Updated by Aristid Breitkreuz 255 days ago

avatar
  • Category set to C++-API
  • Target version set to 0.9

If we can, we should do this API-breaking thing in 0.9.

Updated by Aristid Breitkreuz 231 days ago

avatar
  • Target version changed from 0.9 to 0.10

Also available in: Atom PDF