Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upRoot sequence<any> params using CustomAutoRooter #19644
Conversation
highfive
commented
Dec 25, 2017
|
Thanks for the pull request, and welcome! The Servo team is excited to review your changes, and you should hear from @asajeffrey (or someone else) soon. |
highfive
commented
Dec 25, 2017
|
Heads up! This PR modifies the following files:
|
highfive
commented
Dec 25, 2017
|
This is a good start. I'd like to see what it looks like if we don't overload isMember, as well as having a test that verifies that it works correctly. |
| @@ -700,6 +700,8 @@ def wrapObjectTemplate(templateBody, nullValue, isDefinitelyObject, type, | |||
| assert not (isEnforceRange and isClamp) # These are mutually exclusive | |||
|
|
|||
| if type.isSequence() or type.isRecord(): | |||
| if isArgument and type_needs_auto_root(type): | |||
| isMember = "AutoRoot" | |||
This comment has been minimized.
This comment has been minimized.
jdm
Dec 29, 2017
Member
Rather than overloading isMember for this, I think we should add a new isAutoRooted argument to getJSToNativeConversionInfo. I think we could remove this logic and just pass isAutoRooted=isAutoRooted to the getJSToNativeConversionInfo on the next line.
| @@ -709,6 +711,9 @@ def wrapObjectTemplate(templateBody, nullValue, isDefinitelyObject, type, | |||
| if type.nullable(): | |||
| declType = CGWrapper(declType, pre="Option<", post=" >") | |||
|
|
|||
| if (isArgument and type_needs_auto_root(type)): | |||
This comment has been minimized.
This comment has been minimized.
| default = "UndefinedValue()" | ||
| else: | ||
| raise TypeError("Can't handle non-null, non-undefined default value here") | ||
| return handleOptional("${val}.get()", declType, default) |
This comment has been minimized.
This comment has been minimized.
jdm
Dec 29, 2017
Member
Rather than duplicate this code, I would prefer to have a special check around declType.
| template, replacementVariables, declType, "arg%d" % index) | ||
| template, replacementVariables, declType, arg) | ||
|
|
||
| # TODO: Only for sequence<{any,object}> now |
This comment has been minimized.
This comment has been minimized.
jdm
Dec 29, 2017
Member
Why is this TODO necessary? Isn't this check encapsulated in type_needs_auto_root?
| @@ -449,6 +450,10 @@ impl TestBindingMethods for TestBinding { | |||
| fn PassCallbackFunction(&self, _: Rc<Function>) {} | |||
| fn PassCallbackInterface(&self, _: Rc<EventListener>) {} | |||
| fn PassSequence(&self, _: Vec<i32>) {} | |||
| #[allow(unsafe_code)] | |||
| unsafe fn PassAnySequence(&self, _: *mut JSContext, _: CustomAutoRooterGuard<Vec<JSVal>>) {} | |||
This comment has been minimized.
This comment has been minimized.
jdm
Dec 29, 2017
Member
It would be useful to have an automated test that verifies that the values passed in actually make sense, since that was a problem with the old sequence<any> code. Perhaps have a method that accepts a sequence and returns it, and compare the array values in JS?
|
I addressed the review comments in the new commit. I still have to include a test for that. @jdm I have a question regarding adding the test. I figured it'd be good to check if the values inside passed sequence in some test function receiving sequence are not all undefined? Or maybe use specific ones? In the latter case, given how far away the actual tests in html are from testbinding.rs file, I'm not sure the specified value usage will be clear.
|
|
Added an additional WPT test. Hope this is what you had in mind, didn't touch Servo tests before |
a08c5db
to
7b66289
|
Thanks a lot for finally fixing this! :) |
| def argument_type(descriptorProvider, ty, optional=False, defaultValue=None, variadic=False): | ||
| info = getJSToNativeConversionInfo( | ||
| ty, descriptorProvider, isArgument=True) | ||
| ty, descriptorProvider, isArgument=True, | ||
| isAutoRooted=True if type_needs_auto_root(ty) else False) |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
The codegen changes look much nicer. Thanks! |
| </head> | ||
| <script> | ||
| test(function() { | ||
| function assert_array_equals(lhs, rhs) { |
This comment has been minimized.
This comment has been minimized.
jdm
Jan 3, 2018
Member
This should already exist: http://web-platform-tests.org/writing-tests/testharness-api.html
This comment has been minimized.
This comment has been minimized.
| assert_array_equals(seq, t.anySequencePassthrough(seq)); | ||
|
|
||
| var seq = new Array(null, {'inner': 1, 'a': 'as', 'toString': function() { seq = null; return Object.prototype.toString(this); }}, {'inner': 2}, null, undefined); | ||
| assert_array_equals(seq, t.anySequencePassthrough(seq)); |
This comment has been minimized.
This comment has been minimized.
jdm
Jan 3, 2018
Member
Just to verify, have you checked if any of these tests fail without your codegen changes?
This comment has been minimized.
This comment has been minimized.
Xanewok
Jan 3, 2018
Author
Contributor
Yes. Previously, with Xanewok@01d1039:
var seq = [5, "str", { key: "val" }, undefined];
console.log("seq: " + seq);
var lvalue = t.anySequencePassthrough(seq);
console.log("lvalue: " + lvalue);
console.log("rvalue: " + t.anySequencePassthrough(seq));
assert_array_equals(seq, t.anySequencePassthrough(seq), "Returned simple array is the same");errors with:
0:13.20 PROCESS_OUTPUT: Thread-TestrunnerManager-1 (pid:27314) "seq: 5,str,[object Object],"
0:13.20 PROCESS_OUTPUT: Thread-TestrunnerManager-1 (pid:27314) "lvalue: 0,5e-324,5e-324,5e-324"
0:13.20 PROCESS_OUTPUT: Thread-TestrunnerManager-1 (pid:27314) "rvalue: 0,5e-324,5e-324,5e-324"
...
Expected PASS, got FAIL
assert_array_equals: Returned simple array is the same property 0, expected 0 but got 5
This comment has been minimized.
This comment has been minimized.
Remove FromJSValConvertible implementation for HandleValue Needed for servo/servo#19644. Removes FromJSValConvertible implementations for `HandleValue`, so `Vec<HandleValue>` conversion is impossible. Also adds the implementation for `*mut JSObject` so the `sequence<object>` -> `CustomAutoRooterGuard<Vec<*mut JSObject>>` conversion works. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/rust-mozjs/388) <!-- Reviewable:end -->
|
Once servo/rust-mozjs#388 merges then we can update this to not use the branch. |
Remove FromJSValConvertible implementation for HandleValue Needed for servo/servo#19644. Removes FromJSValConvertible implementations for `HandleValue`, so `Vec<HandleValue>` conversion is impossible. Also adds the implementation for `*mut JSObject` so the `sequence<object>` -> `CustomAutoRooterGuard<Vec<*mut JSObject>>` conversion works. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/rust-mozjs/388) <!-- Reviewable:end -->
|
|
Remove FromJSValConvertible implementation for HandleValue Needed for servo/servo#19644. Removes FromJSValConvertible implementations for `HandleValue`, so `Vec<HandleValue>` conversion is impossible. Also adds the implementation for `*mut JSObject` so the `sequence<object>` -> `CustomAutoRooterGuard<Vec<*mut JSObject>>` conversion works. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/rust-mozjs/388) <!-- Reviewable:end -->
|
Upstream PR merged. |
Also pulls in mozjs 0.1.10 to support the change.
|
r? @jdm |
|
@bors-servo r+ |
|
|
Root sequence<any> params using CustomAutoRooter <!-- Please describe your changes on the following line: --> Attempt at #16678. At the moment this pulls an external [remove-handle-conv](https://github.com/Xanewok/rust-mozjs/tree/remove-handle-conv) branch for rust-mozjs (removing `FromJSValConvertible` implementation for `HandleValue` and adding one for `*mut JSObject`) In short, this roots the `sequence<any>` and `sequence<object>` function arguments using `CustomAutoRooter` (introduced in servo/rust-mozjs#382). As per #16678 (comment) the underlying vector contains raw gc thing pointers instead of handles. To do that, this introduces new possible `isMember = "AutoRoot"` value in CodegenRust.py. The rooted argument is passed to a function wrapped in a `CustomAutoRooterGuard` [RAII root guard](https://github.com/servo/rust-mozjs/blob/ed5e37a288b5738d9b571b8100b4a22a2c00f075/src/rust.rs#L586-L588) (e.g. as `CustomAutoRooterGuard<Vec<JSVal>>`) I felt quite out of my depth when trying to adapt CodegenRust.py code, so I'd appreciate any help with how can be done better/in a more clean manner. Also the name `CustomAutoRooterGuard` is quite lengthy, so I'm also open to changing it (`AutoRoot`? `AutoRootGuard`?) --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [x] These changes fix #16678 (github issue number if applicable). <!-- Either: --> - [X] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/19644) <!-- Reviewable:end -->
|
|
Xanewok commentedDec 25, 2017
•
edited
Attempt at #16678. At the moment this pulls an external remove-handle-conv branch for rust-mozjs (removing
FromJSValConvertibleimplementation forHandleValueand adding one for*mut JSObject)In short, this roots the
sequence<any>andsequence<object>function arguments usingCustomAutoRooter(introduced in servo/rust-mozjs#382).As per #16678 (comment) the underlying vector contains raw gc thing pointers instead of handles. To do that, this introduces new possible
isMember = "AutoRoot"value in CodegenRust.py.The rooted argument is passed to a function wrapped in a
CustomAutoRooterGuardRAII root guard (e.g. asCustomAutoRooterGuard<Vec<JSVal>>)I felt quite out of my depth when trying to adapt CodegenRust.py code, so I'd appreciate any help with how can be done better/in a more clean manner.
Also the name
CustomAutoRooterGuardis quite lengthy, so I'm also open to changing it (AutoRoot?AutoRootGuard?)./mach build -ddoes not report any errors./mach test-tidydoes not report any errorsThis change is