[dev-servo] DOM rooting is live

2014-05-03 Thread Josh Matthews
https://github.com/mozilla/servo/pull/2101 has finally merged, so here's 
what you need to know if you're writing DOM code now:


* members of DOM types that are themselves DOM types must use JS (eg. 
parent_node: Option>)
* all WebIDL methods for type Foo must be declared in a public 
FooMethods trait (except static Constructor methods, which still belong 
to Foo proper)

* all FooMethods traits must be implemented on JSRef<'a, Foo>
* all non-WebIDL methods must be declared in a FooHelpers trait and 
implemented on JSRef<'a, Foo>

* all functions that return a DOM type Foo must return Temporary
* all functions taking a DOM type Foo argument must now take &JSRef

In exchange for this slightly more complicated system of rules, we get 
freedom from garbage collection hazards and safety from accidentally 
breaking them. In particular, the following holds true:
* for any method called on a DOM type, the self pointer and any DOM 
object reachable via self will be rooted for the duration of the method call
* for any method call that accepts DOM type arguments, they will be 
rooted for the duration of the call
* for any DOM object returned from a function, it will remain rooted 
until its Temporary value goes out of scope


The only remaining thing to know is that in order to obtain a JSRef 
value out of a JS or Temporary value is to call the root() method, 
and then dereference it. As such, you will see lots of code like


> let window = self.window.root();
> do_something_with_window(&*window);

or

> let something = Something::new().root();
> something.do_something();

Learn to love it. When you find a type error where something is asking 
for a JSRef and you're not providing it, that's a potential GC hazard 
that the compiler is rejecting.


Cheers,
Josh
___
dev-servo mailing list
dev-servo@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-servo


Re: [dev-servo] DOM rooting is live

2014-05-03 Thread Patrick Walton

On 5/3/14 12:30 PM, Josh Matthews wrote:

Learn to love it. When you find a type error where something is asking
for a JSRef and you're not providing it, that's a potential GC hazard
that the compiler is rejecting.


Kudos! This is a major milestone.

Patrick

___
dev-servo mailing list
dev-servo@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-servo


Re: [dev-servo] DOM rooting is live

2014-05-03 Thread Manish Goregaokar
This is great!

-Manish Goregaokar


On Sun, May 4, 2014 at 1:04 AM, Patrick Walton  wrote:

> On 5/3/14 12:30 PM, Josh Matthews wrote:
>
>> Learn to love it. When you find a type error where something is asking
>> for a JSRef and you're not providing it, that's a potential GC hazard
>> that the compiler is rejecting.
>>
>
> Kudos! This is a major milestone.
>
> Patrick
>
>
> ___
> dev-servo mailing list
> dev-servo@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-servo
>
___
dev-servo mailing list
dev-servo@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-servo