Skip to content

Add WebIDL sequence return values - #8412

Merged
bors-servo merged 4 commits into
servo:masterfrom
emilio:webidl-sequence-return
Nov 11, 2015
Merged

bors-servo merged 4 commits into
servo:masterfrom
emilio:webidl-sequence-return

Conversation

@emilio

@emilio emilio commented Nov 8, 2015

Copy link
Copy Markdown
Member

And use it for WebGLRenderingContext::getSupportedExtensions.
Part of #544

Review on Reviewable

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Nov 8, 2015
@highfive

highfive commented Nov 8, 2015

Copy link
Copy Markdown

warning Warning warning

  • These commits modify unsafe code. Please review it carefully!

@emilio

emilio commented Nov 8, 2015

Copy link
Copy Markdown
Member Author

r? @jdm

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not 100% sure about if this is correct, I tested it and it worked though.

@jdm jdm added S-needs-code-changes Changes have not yet been made that were requested by a reviewer. and removed S-awaiting-review There is new code that needs to be reviewed. labels Nov 8, 2015
@jdm

jdm commented Nov 8, 2015

Copy link
Copy Markdown
Member

-S-awaiting-review +S-needs-code-changes


Reviewed 2 of 2 files at r1, 2 of 2 files at r2, 4 of 4 files at r3.
Review status: all files reviewed at latest revision, 3 unresolved discussions.


components/script/dom/bindings/conversions.rs, line 817 [r1] (raw file):
There are a couple unsafe things about, this, unfortunately. If obj.to_jsval triggers a GC, all of the previous elements that have been been will become dangling pointers since they're not rooted. We should do this instead:

let mut js_objects = RootedVec::new();
for obj in &self {
    let mut val = RootedValue::new(cx, UndefinedValue());
    obj.to_jsval(cx, val.handle_mut());
    js_objects.push(val.handle().get());
}

This will ensure that each converted value is stored in a rooted vector, so subsequent conversions will not risk GCing them.


components/script/dom/bindings/conversions.rs, line 827 [r1] (raw file):
ObjectValue, since we've already checked the presence of null.


components/script/dom/bindings/conversions.rs, line 814 [r3] (raw file):
See below :) from_marked_location is a huge red flag, in general, since it means "I swear that the address I'm passing here is known to the GC".


Comments from the review on Reviewable.io

@emilio

emilio commented Nov 8, 2015

Copy link
Copy Markdown
Member Author

Review status: all files reviewed at latest revision, 3 unresolved discussions.


components/script/dom/bindings/conversions.rs, line 817 [r1] (raw file):
Trying this I get an error (JSVal is not traceable). I guess I can use a plain Vec<RootedValue> (the values are rooted so there should be no problem), and later get the handles?

            let js_objects: Vec<RootedValue> = self.iter().map(|obj| {                      
                let mut val = RootedValue::new(cx, UndefinedValue());
                obj.to_jsval(cx, val.handle_mut());
                val
            }).collect();                                                                   

            let values: Vec<JSVal> = js_objects.iter()                                      
                                               .map(|obj| obj.handle().get())               
                                               .collect(); 

I think this is correct (even though I'm not too happy with the double vector, but I guess we should keep the RootedValues while using the JSValues), am I right?


components/script/dom/bindings/conversions.rs, line 814 [r3] (raw file):
Thanks!
I supposed there would be issues with GC, I'm not familiar with the SpiderMonkey API.


Comments from the review on Reviewable.io

@highfive highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-needs-code-changes Changes have not yet been made that were requested by a reviewer. labels Nov 8, 2015
@emilio

emilio commented Nov 8, 2015

Copy link
Copy Markdown
Member Author

Review status: 6 of 7 files reviewed at latest revision, 3 unresolved discussions.


components/script/dom/bindings/conversions.rs, line 817 [r1] (raw file):
My fault, this crashes.


components/script/dom/bindings/conversions.rs, line 827 [r1] (raw file):
Done.


Comments from the review on Reviewable.io

@emilio
emilio force-pushed the webidl-sequence-return branch from 52e8021 to b19267a Compare November 8, 2015 17:22
@emilio

emilio commented Nov 8, 2015

Copy link
Copy Markdown
Member Author

Review status: 6 of 7 files reviewed at latest revision, 3 unresolved discussions.


components/script/dom/bindings/conversions.rs, line 817 [r1] (raw file):
I ended up using Heap<JSValue>, and it works fine (passes the test adding a few strings to getSupportedExtensions).

May yo review it to see if there might be any issue with GC, or if this can be done in a more performant way? :)

TL;DR; here is the relevant code:

let mut js_objects = RootedVec::new();
 
for obj in self.iter() {
    let mut heap = Heap::default();
    let mut val = RootedValue::new(cx, UndefinedValue());
    obj.to_jsval(cx, val.handle_mut());
    heap.set(val.handle().get());
    js_objects.push(heap);
}
 
let values: Vec<JSVal> = js_objects.iter()
                                   .map(|heap| heap.handle().get())
                                   .collect();

Comments from the review on Reviewable.io

@Ms2ger

Ms2ger commented Nov 10, 2015

Copy link
Copy Markdown
Contributor

I wonder if we should have a fn push(&mut self, Handle<T>) for RootedVec<Heap<T>>. @nox?

@jdm

jdm commented Nov 11, 2015

Copy link
Copy Markdown
Member

-S-awaiting-review +S-needs-code-changes +S-awaiting-answer


Reviewed 1 of 1 files at r4.
Review status: all files reviewed at latest revision, 3 unresolved discussions.


components/script/dom/bindings/conversions.rs, line 820 [r4] (raw file):
I think the order here should be:

let mut val = RootedValue::new(cx, UndefinedValue());
obj.to_jsval(cx, val.handle_mut());
js_objects.push(Heap::default());
js_objects.iter_mut().last().unwrap().set(val.handle().get());

components/script/dom/bindings/conversions.rs, line 825 [r4] (raw file):
The fact that we need to create a new vector with bare Value types gives me pause. I think we need to sort out whether we should be using RootedVec<Value> or RootedVec<Heap<Value>> before I can finish this review.


components/script/dom/bindings/conversions.rs, line 836 [r4] (raw file):
&*js_array instead of transmuting, please.


Comments from the review on Reviewable.io

@jdm jdm added S-awaiting-answer Someone asked a question that requires an answer. S-needs-code-changes Changes have not yet been made that were requested by a reviewer. and removed S-awaiting-review There is new code that needs to be reviewed. labels Nov 11, 2015
@bors-servo

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #8197) made this pull request unmergeable. Please resolve the merge conflicts.

@highfive highfive added S-needs-rebase There are merge conflict errors. and removed S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. labels Nov 11, 2015
@emilio
emilio force-pushed the webidl-sequence-return branch from b19267a to 105f2e9 Compare November 11, 2015 17:10
@highfive highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-needs-code-changes Changes have not yet been made that were requested by a reviewer. labels Nov 11, 2015
@emilio
emilio force-pushed the webidl-sequence-return branch from 105f2e9 to 1f00c14 Compare November 11, 2015 17:12
@emilio

emilio commented Nov 11, 2015

Copy link
Copy Markdown
Member Author

Review status: 4 of 7 files reviewed at latest revision, 3 unresolved discussions.


components/script/dom/bindings/conversions.rs, line 820 [r4] (raw file):
I changed the implementation to take rid of this, using JS_NewArrayObject1 (the overload with predefined length instead of values) and JS_DefineElement (to set numeric properties).

This also solves the double vector issue, and the RootedVec/Heap stuff.


components/script/dom/bindings/conversions.rs, line 825 [r4] (raw file):
See above.


components/script/dom/bindings/conversions.rs, line 836 [r4] (raw file):
Done.


Comments from the review on Reviewable.io

@emilio
emilio force-pushed the webidl-sequence-return branch from 1f00c14 to 71fdb60 Compare November 11, 2015 17:24
@jdm jdm added S-needs-code-changes Changes have not yet been made that were requested by a reviewer. and removed S-awaiting-review There is new code that needs to be reviewed. S-awaiting-answer Someone asked a question that requires an answer. S-needs-rebase There are merge conflict errors. labels Nov 11, 2015
@jdm

jdm commented Nov 11, 2015

Copy link
Copy Markdown
Member

Great; only nits remaining!
-S-needs-rebase -S-awaiting-review -S-awaiting-answer +S-needs-code-changes


Reviewed 3 of 3 files at r5.
Review status: 6 of 7 files reviewed at latest revision, 3 unresolved discussions.


components/script/dom/bindings/conversions.rs, line 820 [r4] (raw file):
Great solution :)


components/script/dom/bindings/conversions.rs, line 43 [r5] (raw file):
js::JSPROP_ENUMERATE


components/script/dom/bindings/conversions.rs, line 820 [r5] (raw file):
No need for get() here; Handle<T> dereferences to &T.


components/script/dom/bindings/conversions.rs, line 822 [r5] (raw file):
for (index, obj) in self.iter().enumerate() {


Comments from the review on Reviewable.io

@jdm

jdm commented Nov 11, 2015

Copy link
Copy Markdown
Member

Reviewed 1 of 1 files at r6.
Review status: all files reviewed at latest revision, 2 unresolved discussions.


Comments from the review on Reviewable.io

@emilio
emilio force-pushed the webidl-sequence-return branch from 71fdb60 to e33330d Compare November 11, 2015 17:30
@highfive highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-needs-code-changes Changes have not yet been made that were requested by a reviewer. labels Nov 11, 2015
@emilio

emilio commented Nov 11, 2015

Copy link
Copy Markdown
Member Author

Review status: 6 of 7 files reviewed at latest revision, 2 unresolved discussions.


components/script/dom/bindings/conversions.rs, line 820 [r5] (raw file):
Done.


components/script/dom/bindings/conversions.rs, line 822 [r5] (raw file):
Good catch (sorry, I have little time and I tried to do it as quickly as possible).


Comments from the review on Reviewable.io

@jdm

jdm commented Nov 11, 2015

Copy link
Copy Markdown
Member

@bors-servo: r+


Reviewed 1 of 1 files at r7.
Review status: all files reviewed at latest revision, all discussions resolved.


Comments from the review on Reviewable.io

@bors-servo

Copy link
Copy Markdown
Contributor

📌 Commit e33330d has been approved by jdm

@highfive highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-awaiting-review There is new code that needs to be reviewed. labels Nov 11, 2015
@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Testing commit e33330d with merge 12f6ba2...

bors-servo pushed a commit that referenced this pull request Nov 11, 2015
Add WebIDL sequence return values

And use it for `WebGLRenderingContext::getSupportedExtensions`.
Part of #544

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8412)
<!-- Reviewable:end -->
@bors-servo

Copy link
Copy Markdown
Contributor

💔 Test failed - linux-rel

@highfive highfive added S-tests-failed The changes caused existing tests to fail. and removed S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. labels Nov 11, 2015
@jdm

jdm commented Nov 11, 2015

Copy link
Copy Markdown
Member

@bors-servo

Copy link
Copy Markdown
Contributor

⚡ Previous build results for android, gonk, linux-dev, mac-dev-ref-unit, mac-rel-css, mac-rel-wpt are reusable. Rebuilding only linux-rel...

@bors-servo

Copy link
Copy Markdown
Contributor

☀️ Test successful - android, gonk, linux-dev, linux-rel, mac-dev-ref-unit, mac-rel-css, mac-rel-wpt

@bors-servo
bors-servo merged commit e33330d into servo:master Nov 11, 2015
@bors-servo bors-servo mentioned this pull request Nov 11, 2015
@SimonSapin SimonSapin removed the S-tests-failed The changes caused existing tests to fail. label Jan 27, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants