New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implemented FileReader::readAsArrayBuffer #13729
Conversation
Heads up! This PR modifies the following files:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a review, but just some points I wanted to mention.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forgot to add the comments;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There! hopefully this will work...
|
||
// https://w3c.github.io/FileAPI/#dfn-readAsArrayBuffer | ||
#[allow(unsafe_code, unused_variables)] | ||
fn perform_readasarraybuffer(cx: *mut JSContext, data: ReadMetaData, bytes: &[u8]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There might be more than a few logical errors in this function, as I haven't asked anyone to look at this piece of code since the compiler didn't complain.
-> StringOrObject { | ||
unsafe { | ||
let length = bytes.len() as u32; | ||
let newArrayBuffer = JS_NewArrayBuffer(cx, length); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both FileAPI/reading-data-section/filereader_readAsArrayBuffer.html
and FileAPI/reading-data-section/filereader_result.html
crash at this point. There's very little information in the log to debug it, it only shows a stack trace. I still have to test for additional tests which have been mentioned in the issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to create a JSAutoCompartment value in this method before calling JS_NewArrayBuffer.
if let Some(FileReaderResult::ArrayBuffer_(ref heap)) = *fr.result.borrow() { | ||
if let StringOrObject::Object(obj) = output { | ||
unsafe { | ||
let tempr = heap.get_unsafe(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be done in a much better manner, but I don't know how.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use heap.set
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had tried that, but I throws a cannot borrow immutable borrowed content *heap as mutable
error. Trying that with a mutable reference throws a cannot borrow anonymous inner field as mutable
error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, use borrow_mut.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand....heap doesn't have a borrow_mut
method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*fr.result.borrow_mut()
and ref mut heap
should work :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@emilio it works. Thanks!
I suspect the crash is caused by a missing JS compartment. Try adding |
@@ -4191,7 +4197,7 @@ def get_match(name): | |||
|
|||
hasObjectTypes = interfaceObject or arrayObject or dateObject or nonPlatformObject or object or mozMapObject | |||
if hasObjectTypes: | |||
assert interfaceObject or arrayObject or mozMapObject | |||
assert interfaceObject or arrayObject or mozMapObject or object |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's update this to match Gecko's Codegen.py:
# "object" is not distinguishable from other types
assert not object or not (interfaceObject or arrayObject or dateObject or callbackObject or mozMapObject)
#[derive(HeapSizeOf, JSTraceable)] | ||
pub enum FileReaderResult { | ||
ArrayBuffer_(Heap<JSVal>), | ||
String_(DOMString), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove the _s from the names here.
@@ -159,6 +173,7 @@ impl FileReader { | |||
} | |||
|
|||
// https://w3c.github.io/FileAPI/#dfn-readAsText | |||
#[allow(unsafe_code, unused_variables)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's get rid of the unused_variables.
@@ -176,14 +191,26 @@ impl FileReader { | |||
fr.change_ready_state(FileReaderReadyState::Done); | |||
// Step 8.2 | |||
|
|||
let output = match data.function { | |||
let output: StringOrObject = match data.function { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have an idea that will lead to cleaner code - let's make the perform_foo
methods take a &self
argument, and have them store the value in self.result
, rather than returning it.
if let Some(FileReaderResult::ArrayBuffer_(ref heap)) = *fr.result.borrow() { | ||
if let StringOrObject::Object(obj) = output { | ||
unsafe { | ||
let tempr = heap.get_unsafe(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use heap.set
instead.
-> StringOrObject { | ||
unsafe { | ||
let length = bytes.len() as u32; | ||
let newArrayBuffer = JS_NewArrayBuffer(cx, length); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to create a JSAutoCompartment value in this method before calling JS_NewArrayBuffer.
-> StringOrObject { | ||
unsafe { | ||
let length = bytes.len() as u32; | ||
let newArrayBuffer = JS_NewArrayBuffer(cx, length); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use the new safe typed array APIs implemented in servo/rust-mozjs#304 . See the tests added there for examples.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't figure what the fourth parameter in create
should be... should I use the same macro to create it as specified in the tests or something else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something like
rooted!(in(cx) let mut buffer = ptr::null_mut());
assert!(Uint32Array::create(cx, length, Some(bytes), buffer.handle_mut()).is_ok());
StringOrObject::Object(buffer.get())
@@ -303,8 +355,19 @@ impl FileReaderMethods for FileReader { | |||
} | |||
|
|||
// https://w3c.github.io/FileAPI/#dfn-result | |||
fn GetResult(&self) -> Option<DOMString> { | |||
self.result.borrow().clone() | |||
#[allow(unsafe_code, unused_variables)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unused_variables
self.result.borrow().clone() | ||
#[allow(unsafe_code, unused_variables)] | ||
fn GetResult(&self, cx: *mut JSContext) -> Option<StringOrObject> { | ||
match *self.result.borrow() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.result.borrow().as_ref().map(|r| match r {
FileReaderResult::String(string) =>
StringOrObject::String(string.clone()),
FileReaderResult::ArrayBuffer(arr_buffer) => {
...
}
})
//readonly attribute FileReaderResult? result; | ||
readonly attribute DOMString? result; | ||
readonly attribute FileReaderResult? result; | ||
//readonly attribute DOMString? result; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can remove this now.
7fbf9b0
to
23def27
Compare
23def27
to
d8c6656
Compare
I implemented all the requested changes as a temporary commit so that it's easier to view the changes since the first commit. It would be a good idea to |
@bors-servo try |
Implemented FileReader::readAsArrayBuffer <!-- Please describe your changes on the following line: --> --- <!-- 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 #12555 <!-- Either: --> - [X] There are tests for these changes There's still some small issues, but I suppose most of the work is done: - test-tidy mentions a `method declared in webidl is missing a comment with a specification link` for the `getResult` method. - I get an 'unused code' warning for code present in `UnionTypes.rs`, which is auto-generated. Passing tests: - [x] `FileAPI/reading-data-section/filereader_result.html` - [x] `FileAPI/reading-data-section/filereader_readAsArrayBuffer.html` - [x] `FileAPI/idlharness.html` - [ ] `FileAPI/reading-data-section/FileReader-multiple-reads.html` <!-- 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/13729) <!-- Reviewable:end -->
💔 Test failed - linux-rel-wpt |
@bors-servo retry
|
Implemented FileReader::readAsArrayBuffer <!-- Please describe your changes on the following line: --> --- <!-- 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 #12555 <!-- Either: --> - [X] There are tests for these changes There's still some small issues, but I suppose most of the work is done: - test-tidy mentions a `method declared in webidl is missing a comment with a specification link` for the `getResult` method. - I get an 'unused code' warning for code present in `UnionTypes.rs`, which is auto-generated. Passing tests: - [x] `FileAPI/reading-data-section/filereader_result.html` - [x] `FileAPI/reading-data-section/filereader_readAsArrayBuffer.html` - [x] `FileAPI/idlharness.html` - [ ] `FileAPI/reading-data-section/FileReader-multiple-reads.html` <!-- 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/13729) <!-- Reviewable:end -->
💔 Test failed - linux-rel-wpt |
@bors-servo: retry |
Implemented FileReader::readAsArrayBuffer <!-- Please describe your changes on the following line: --> --- <!-- 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 #12555 <!-- Either: --> - [X] There are tests for these changes There's still some small issues, but I suppose most of the work is done: - test-tidy mentions a `method declared in webidl is missing a comment with a specification link` for the `getResult` method. - I get an 'unused code' warning for code present in `UnionTypes.rs`, which is auto-generated. Passing tests: - [x] `FileAPI/reading-data-section/filereader_result.html` - [x] `FileAPI/reading-data-section/filereader_readAsArrayBuffer.html` - [x] `FileAPI/idlharness.html` - [ ] `FileAPI/reading-data-section/FileReader-multiple-reads.html` <!-- 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/13729) <!-- Reviewable:end -->
@bors-servo retry |
Implemented FileReader::readAsArrayBuffer <!-- Please describe your changes on the following line: --> --- <!-- 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 #12555 <!-- Either: --> - [X] There are tests for these changes There's still some small issues, but I suppose most of the work is done: - test-tidy mentions a `method declared in webidl is missing a comment with a specification link` for the `getResult` method. - I get an 'unused code' warning for code present in `UnionTypes.rs`, which is auto-generated. Passing tests: - [x] `FileAPI/reading-data-section/filereader_result.html` - [x] `FileAPI/reading-data-section/filereader_readAsArrayBuffer.html` - [x] `FileAPI/idlharness.html` - [ ] `FileAPI/reading-data-section/FileReader-multiple-reads.html` <!-- 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/13729) <!-- Reviewable:end -->
☀️ Test successful - arm32, arm64, linux-dev, linux-rel-css, linux-rel-wpt, mac-dev-unit, mac-rel-css, mac-rel-wpt1, mac-rel-wpt2, windows-dev |
@cynicaldevil Generally it's not necessary to re-run try runs if the reported failures are all known intermittent ones. |
@jdm Does homu stop running after the first encountered error, or does it run the build on all platforms and then report all errors at once? |
@cynicaldevil Homu runs on all platforms, but only displays error results from one. |
I see. So what now? Is the PR ready to be merged? |
If you're ever in doubt about the status of a PR, the purple labels should help you understand. Right now it says S-awaiting-review, and your reviewer is @jdm. |
r=me once you squash all commits together. Thanks! |
c39939b
to
51ef05b
Compare
@Ms2ger Done! |
@bors-servo r=Ms2ger |
📌 Commit 51ef05b has been approved by |
Implemented FileReader::readAsArrayBuffer <!-- Please describe your changes on the following line: --> --- <!-- 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 #12555 <!-- Either: --> - [X] There are tests for these changes There's still some small issues, but I suppose most of the work is done: - test-tidy mentions a `method declared in webidl is missing a comment with a specification link` for the `getResult` method. - I get an 'unused code' warning for code present in `UnionTypes.rs`, which is auto-generated. Passing tests: - [x] `FileAPI/reading-data-section/filereader_result.html` - [x] `FileAPI/reading-data-section/filereader_readAsArrayBuffer.html` - [x] `FileAPI/idlharness.html` - [ ] `FileAPI/reading-data-section/FileReader-multiple-reads.html` <!-- 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/13729) <!-- Reviewable:end -->
☀️ Test successful - arm32, arm64, linux-dev, linux-rel-css, linux-rel-wpt, mac-dev-unit, mac-rel-css, mac-rel-wpt1, mac-rel-wpt2, windows-dev |
./mach build -d
does not report any errors./mach test-tidy
does not report any errorsThere's still some small issues, but I suppose most of the work is done:
method declared in webidl is missing a comment with a specification link
for thegetResult
method.UnionTypes.rs
, which is auto-generated.Passing tests:
FileAPI/reading-data-section/filereader_result.html
FileAPI/reading-data-section/filereader_readAsArrayBuffer.html
FileAPI/idlharness.html
FileAPI/reading-data-section/FileReader-multiple-reads.html
This change is