Skip to content
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

Merged
merged 1 commit into from Oct 31, 2016

Conversation

nikhilshagri
Copy link
Contributor

@nikhilshagri nikhilshagri commented Oct 12, 2016


  • 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:

  • 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 Reviewable

@highfive
Copy link

Heads up! This PR modifies the following files:

  • @KiChjang: components/script/dom/bindings/codegen/CodegenRust.py, components/script/dom/webidls/FileReader.webidl, components/script/dom/filereader.rs

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Oct 12, 2016
@highfive
Copy link

warning Warning warning

  • These commits modify unsafe code. Please review it carefully!
  • These commits modify script code, but no tests are modified. Please consider adding a test!

Copy link
Contributor Author

@nikhilshagri nikhilshagri left a 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.

Copy link
Contributor Author

@nikhilshagri nikhilshagri left a 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;

Copy link
Contributor Author

@nikhilshagri nikhilshagri left a 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])
Copy link
Contributor Author

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);
Copy link
Contributor Author

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.

Copy link
Member

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();
Copy link
Contributor Author

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.

Copy link
Member

Choose a reason for hiding this comment

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

Use heap.set instead.

Copy link
Contributor Author

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.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, use borrow_mut.

Copy link
Contributor Author

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.

Copy link
Member

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 :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@emilio it works. Thanks!

@jdm
Copy link
Member

jdm commented Oct 12, 2016

I suspect the crash is caused by a missing JS compartment. Try adding let _ac = JSAutoCompartment::new(fr.global().r().get_cx(), &*fr.reflector().get_jsobject()); before the call to perform_readasarraybuffer?

jdm
jdm previously requested changes Oct 14, 2016
@@ -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
Copy link
Member

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),
Copy link
Member

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)]
Copy link
Member

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 {
Copy link
Member

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();
Copy link
Member

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);
Copy link
Member

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);
Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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)]
Copy link
Member

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() {
Copy link
Member

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;
Copy link
Member

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.

@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 Oct 14, 2016
@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 Oct 24, 2016
@nikhilshagri
Copy link
Contributor Author

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 this PR if there are no more changes, because there are some failing tests and we can have a record of them here.

@KiChjang
Copy link
Contributor

@bors-servo try

@bors-servo
Copy link
Contributor

⌛ Trying commit d8c6656 with merge ca2e93f...

bors-servo pushed a commit that referenced this pull request Oct 27, 2016
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
Copy link
Contributor

💔 Test failed - linux-rel-wpt

@highfive highfive added the S-tests-failed The changes caused existing tests to fail. label Oct 27, 2016
@KiChjang
Copy link
Contributor

@bors-servo retry

  • homu throws a fit

@bors-servo
Copy link
Contributor

⌛ Trying commit d8c6656 with merge adbf85b...

bors-servo pushed a commit that referenced this pull request Oct 27, 2016
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
Copy link
Contributor

💔 Test failed - linux-rel-wpt

@highfive highfive added the S-tests-failed The changes caused existing tests to fail. label Oct 27, 2016
@jdm
Copy link
Member

jdm commented Oct 28, 2016

@bors-servo: retry

@bors-servo
Copy link
Contributor

⌛ Trying commit d8c6656 with merge b262a94...

bors-servo pushed a commit that referenced this pull request Oct 28, 2016
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
Copy link
Contributor

⌛ Trying commit c39939b with merge b79f881...

bors-servo pushed a commit that referenced this pull request Oct 30, 2016
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
Copy link
Contributor

@jdm
Copy link
Member

jdm commented Oct 30, 2016

@cynicaldevil Generally it's not necessary to re-run try runs if the reported failures are all known intermittent ones.

@nikhilshagri
Copy link
Contributor Author

@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?

@KiChjang
Copy link
Contributor

KiChjang commented Oct 30, 2016

@cynicaldevil Homu runs on all platforms, but only displays error results from one.

@nikhilshagri
Copy link
Contributor Author

I see. So what now? Is the PR ready to be merged?

@KiChjang
Copy link
Contributor

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.

@Ms2ger
Copy link
Contributor

Ms2ger commented Oct 31, 2016

r=me once you squash all commits together. Thanks!

@Ms2ger Ms2ger added S-needs-squash Some (or all) of the commits in the PR should be combined. and removed S-awaiting-review There is new code that needs to be reviewed. labels Oct 31, 2016
@Ms2ger Ms2ger dismissed jdm’s stale review October 31, 2016 15:06

Stealing review

@Ms2ger Ms2ger assigned Ms2ger and unassigned jdm Oct 31, 2016
@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Oct 31, 2016
@nikhilshagri
Copy link
Contributor Author

@Ms2ger Done!

@KiChjang
Copy link
Contributor

@bors-servo r=Ms2ger

@bors-servo
Copy link
Contributor

📌 Commit 51ef05b has been approved by Ms2ger

@highfive highfive removed the S-awaiting-review There is new code that needs to be reviewed. label Oct 31, 2016
@bors-servo
Copy link
Contributor

⌛ Testing commit 51ef05b with merge ceb18e7...

@highfive highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-needs-squash Some (or all) of the commits in the PR should be combined. labels Oct 31, 2016
bors-servo pushed a commit that referenced this pull request Oct 31, 2016
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
Copy link
Contributor

@bors-servo bors-servo merged commit 51ef05b into servo:master Oct 31, 2016
@highfive highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Oct 31, 2016
@servo servo deleted a comment from AppleMango23 Feb 1, 2019
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.

Implement FileReader::readAsArrayBuffer
7 participants