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 upSupport JS typed arrays as arguments and in WebIDL unions #20267
Conversation
highfive
commented
Mar 10, 2018
|
Heads up! This PR modifies the following files:
|
highfive
commented
Mar 10, 2018
|
|
ea99f23
to
65c6011
|
Gecko's solution for the nullable name is here. We should be able to do the same thing at https://github.com/servo/servo/pull/20267/files#diff-60d01595cff328c165842fea9e4ccbc2R885. |
| @@ -870,8 +870,50 @@ def wrapObjectTemplate(templateBody, nullValue, isDefinitelyObject, type, | |||
|
|
|||
| return handleOptional(templateBody, declType, handleDefaultNull("None")) | |||
|
|
|||
| if type.isSpiderMonkeyInterface(): | |||
| raise TypeError("Can't handle SpiderMonkey interface arguments yet") | |||
| if type.isTypedArray() or type.isArrayBuffer() or type.isArrayBufferView() or type.isSharedArrayBuffer(): | |||
This comment has been minimized.
This comment has been minimized.
jdm
Mar 12, 2018
Member
This particular check is repeated in enough places that we should put it behind a descriptive is_typed_array function.
| # Any code to convert to Object is unused, since we're already converting | ||
| # from an Object value. | ||
| if t.name == 'Object': | ||
| return CGGeneric('') |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Xanewok
Mar 13, 2018
Author
Contributor
Same as above: the type of object members in Unions are currently RootedTraceableBox<Heap<*mut JSObject>> and so we need to convert the incoming raw *mut JSObject somehow; with this we generate a used TryConvertToObject with proper body (constructing a RootedTraceableBox from a boxed Heap value with the raw object pointer)
| if hasObjectTypes: | ||
| # "object" is not distinguishable from other types | ||
| assert not object or not (interfaceObject or arrayObject or dateObject or callbackObject or mozMapObject) | ||
| templateBody = CGList([], "\n") | ||
| if object: | ||
| templateBody.append(object) |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Xanewok
Mar 13, 2018
Author
Contributor
Related to #20265, but I'll leave a note here: without this the contents of if value.get().is_object() { ... } are not generated in from_jsval conversion function
| @@ -428,6 +429,9 @@ impl TestBindingMethods for TestBinding { | |||
| fn PassByteString(&self, _: ByteString) {} | |||
| fn PassEnum(&self, _: TestEnum) {} | |||
| fn PassInterface(&self, _: &Blob) {} | |||
| fn PassTypedArray(&self, _: CustomAutoRooterGuard<typedarray::Int8Array>) {} | |||
| fn PassTypedArray2(&self, _: CustomAutoRooterGuard<typedarray::ArrayBuffer>) {} | |||
| fn PassTypedArray3(&self, _: CustomAutoRooterGuard<typedarray::ArrayBufferView>) {} | |||
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Xanewok
Mar 13, 2018
Author
Contributor
How should we deal with nullable CustomAutoRooterGuard<Option<Typedarray::Int8Array>> types then? Should we simply pass only reference to rooted arguments, hiding the CustomAutoRooterGuard 'implementation detail'?
This comment has been minimized.
This comment has been minimized.
jdm
Mar 13, 2018
Member
Hmm. Ideally we would have Option<CustomAutoRooterGuard<Typedarray::Int8Array>> instead. Possibly that just requires rearranging the code that applies the CustomAutoRooterGuard templated type?
This comment has been minimized.
This comment has been minimized.
|
|
||
| if isMember in ("Dictionary", "Union"): | ||
| # TODO: Do we need to do the same for dictionaries? |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Xanewok
Mar 13, 2018
•
Author
Contributor
(This is related to #20265, I should've separated the changes in both PRs clearly, I'm sorry)
So I just checked and currently dictionaries are flagged as #[must_root] and their constructor first allocates a dict using RootedTraceableBox with defaults and only then sets values.
With this approach having Heap<*mut JSObject> as dictionary members suffices and moving the dict box is safe, as long as it's not consumed to retrieve the inner value.
Should I still pursue this, then?
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
jdm
Mar 13, 2018
Member
Let's leave the current implementation then, since it is less unsafe than previously believed.
This comment has been minimized.
This comment has been minimized.
Xanewok
Mar 13, 2018
Author
Contributor
It seems it didn't require additional work and even simplified the codegen slightly, but I can then not include the change for object in dictionaries here
|
|
6254c68
to
477c7ff
| @@ -6418,6 +6468,9 @@ def type_needs_tracing(t): | |||
| if t.isUnion(): | |||
| return any(type_needs_tracing(member) for member in t.flatMemberTypes) | |||
|
|
|||
| if t.isTypedArray() or t.isArrayBuffer() or t.isArrayBufferView() or t.isSharedArrayBuffer(): | |||
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Waiting on merging the changes upstream in rust-mozjs, of course. |
Add TypedArray API using Heap-wrapped objects Needed for servo/servo#20267. This changes TypedArray wrapper type to only contain typed array-related logic and not handle rooting, and introduces 2 different possible storage options for wrapped objects - `*mut JSObject`, can be rooted on stack (e.g. using CustomAutoRooter) - `Box<Heap<*mut JSObject>>`, can be rooted on heap with `JSTraceable` trait (implemented on Servo side) Since the API changes are breaking, I bumped minor version so that Servo will not break when updating. r? @jdm <!-- 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/397) <!-- Reviewable:end -->
477c7ff
to
857e484
|
|
|
…newok Support JS typed arrays as arguments and in WebIDL unions <!-- Please describe your changes on the following line: --> Supersedes #20205. This brings support to receiving typed arrays as function arguments (those are stack-rooted with CustomAutoRooter) and also being a member of a union (which is basically heap-rooted? similarly to other webidl unions). This is based on my other PR #20265 (which means it has to pull an external rust-mozjs branch and contains some also slightly unrelated changes here) since it shares `RootedTraceableBox::from_box` here and some other additional changes at rust-mozjs, but it can be easily separated if needed. I tried adding support to nullable typed arrays but couldn't work around an issue of codegen always sticking a "OrNull" at the end of my type (presumably because of [this](https://github.com/servo/servo/blob/master/components/script/dom/bindings/codegen/parser/WebIDL.py#L2241)?). How would I go about avoiding the suffix with nullable arguments? If we were to add also support for nullable typed arrays then I think we wouldn't be blocked anymore on this in WebGL 1.0. r? @jdm --- <!-- 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 - [ ] These changes fix #__ (github issue number if applicable). <!-- Either: --> - [ ] 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/20267) <!-- Reviewable:end -->
|
|
|
Error when running ./mach filter-intermittents (output here)
|
|
@bors-servo retry |
|
|
|
|
Retrying as in #20265 (comment): cc @jdm @bors-servo retry |
|
|
|
|
Xanewok commentedMar 10, 2018
•
edited
Supersedes #20205.
This brings support to receiving typed arrays as function arguments (those are stack-rooted with CustomAutoRooter) and also being a member of a union (which is basically heap-rooted? similarly to other webidl unions).
This is based on my other PR #20265 (which means it has to pull an external rust-mozjs branch and contains some also slightly unrelated changes here) since it shares
RootedTraceableBox::from_boxhere and some other additional changes at rust-mozjs, but it can be easily separated if needed.I tried adding support to nullable typed arrays but couldn't work around an issue of codegen always sticking a "OrNull" at the end of my type (presumably because of this?). How would I go about avoiding the suffix with nullable arguments?
If we were to add also support for nullable typed arrays then I think we wouldn't be blocked anymore on this in WebGL 1.0.
r? @jdm
./mach build -ddoes not report any errors./mach test-tidydoes not report any errorsThis change is