FileHandle: Better handling of the end of file state

RESOLVED FIXED in Firefox 15



7 years ago
7 years ago


(Reporter: janv, Assigned: janv)



Firefox Tracking Flags

(firefox13 affected, firefox14 unaffected, firefox15 verified, firefox16 fixed)



(2 attachments, 3 obsolete attachments)

Comment hidden (empty)

Comment 1

7 years ago
Created attachment 629786 [details] [diff] [review]

- readAsArrayBuffer(), readAsText() and truncate() throws when the location is in the end of file state (LL_MAXUINT / Infinity)
- write() behaves as append() when in the end of file state
- it's possible to set the state by calling |.location = Infinity|

I'll write a test, but I need feedback on this approach first
Attachment #629786 - Flags: feedback?(jonas)
I'd rather that .write throws when in the end-of-file state. Seems strange that someone would call .append and then .write. That way we are also free to make write-after-append work however we want later if we decide to. I.e. we could change it so that .append doesn't affect .location at all if we decide that's better behavior.

I'd rather make |.location = null| be what puts us in the end-of-file state. That way x.location = x.location is always a no-op.
Oh, and we should make .location return null in the end-of-file state. That way we can define it as |attribute long long? location| in the idl once we use WebIDL.

Comment 4

7 years ago
Created attachment 629886 [details] [diff] [review]
Attachment #629786 - Attachment is obsolete: true
Attachment #629786 - Flags: feedback?(jonas)
Attachment #629886 - Flags: review?(jonas)
Comment on attachment 629886 [details] [diff] [review]

Review of attachment 629886 [details] [diff] [review]:

::: dom/file/LockedFile.cpp
@@ +516,5 @@
> +  }
> +  else {
> +    if (mLocation <= JSVAL_INT_MAX) {
> +      *aLocation = INT_TO_JSVAL(mLocation);
> +    }

I don't think you need this special-case. Just use JS_NewNumberValue all the time.

@@ +730,5 @@
>    nsresult rv = helper->Enqueue();
>    if (aOptionalArgCount) {
> +    mLocation = aSize;

Wait, this needs to be |mLocation = location|, right? Otherwise mLocation will be set to 0 if the argument isn't specified. Sorry, I missed this in the previous patch that already landed.
Attachment #629886 - Flags: review?(jonas) → review+

Comment 6

7 years ago
Created attachment 633831 [details] [diff] [review]
updated patch
Assignee: nobody → Jan.Varga
Attachment #633831 - Flags: review?(jonas)
Comment on attachment 633831 [details] [diff] [review]
updated patch

Review of attachment 633831 [details] [diff] [review]:


::: dom/file/LockedFile.cpp
@@ +533,5 @@
> +    return NS_OK;
> +  }
> +
> +  PRUint64 location;
> +  if (xpc::ValueToUint64(aCx, aLocation, &location)) {

Nit: I would have reversed the check here and put the error handling in the branch. As to keep the common code flow to be the one that reaches the end of the function. Up to you.

@@ +708,5 @@
> +  PRUint64 location;
> +  if (aOptionalArgCount) {
> +    // Just in case someone calls us from C++
> +    if (aSize == LL_MAXUINT) {
> +      return NS_ERROR_TYPE_ERR;

I'd prefer to just MOZ_ASSERT that aSize != LL_MAXUINT. That's a better way to keep people from doing that.
Attachment #633831 - Flags: review?(jonas) → review+


7 years ago
Attachment #629886 - Attachment is obsolete: true

Comment 8

7 years ago
Both comments addressed.
Last Resolved: 7 years ago
Resolution: --- → FIXED
This breaks my OpenBSD builds..

dom/file/LockedFile.cpp:537: error: invalid conversion from 'PRUint64*' to 'uint64_t*'

xpc::ValueToUint64 expects a uint64_t* as last arg and gets a PRUint64*. Trying some casting vodoo..
Comment on attachment 633831 [details] [diff] [review]
updated patch

[Approval Request Comment]
Bug caused by (feature/regressing bug #): 
Bug 726593

User impact if declined: 
Would result in that web developers would have a somewhat inconsistent behavior for the new FileHandle API. Ideally developers would be able to stop worrying about this after 6 weeks when FF16 is released, but we're still not great at getting users to the latest version.

I.e. we'd like to fix known issues in the first release of this API.

Testing completed (on m-c, etc.): 
Patch includes thorough automated tests.

Risk to taking this patch (and alternatives if risky):
Very low risk. Only affects an API which was added in Firefox 15, so no existing websites or internal code uses it.

Absolute worst case this API doesn't work in Firefox 15, but even that is very unlikely since the patch only affects edge cases and is will testsed.

String or UUID changes made by this patch: 
Changes the UUID of an interface introduced in Firefox 15.
No string changes.
Attachment #633831 - Flags: approval-mozilla-aurora?
Created attachment 633888 [details] [diff] [review]
cast location to uint64_t*

Attached patch fixes the build for me, dunno if that's the best fix.
Comment on attachment 633888 [details] [diff] [review]
cast location to uint64_t*

I think it'd be better to change 'location' to be of type uint64_t. And, only if needed, add a cast when assigning into mLocation.

Comment 13

7 years ago
yeah, could you try something like:

uint64_t location;
if (!xpc::ValueToUint64(aCx, aLocation, &location)) {

mLocation = location; // eventually change to: mLocation = static_cast<PRUint64>(location);


7 years ago
OS: Mac OS X → All
Hardware: x86 → All
Target Milestone: --- → mozilla16
Created attachment 633895 [details] [diff] [review]
declare location as uint64_t

That also works, and it even seems the cast when assigning to mLocation isnt needed.
Attachment #633888 - Attachment is obsolete: true
Attachment #633895 - Flags: review?(Jan.Varga)


7 years ago
Attachment #633895 - Flags: review?(Jan.Varga) → review+
Comment on attachment 633831 [details] [diff] [review]
updated patch

[Triage Comment]
Risk and UUID changes are limited to the new API. Approving for Aurora 15.
Attachment #633831 - Flags: approval-mozilla-aurora? → approval-mozilla-aurora+
To whoever commits that to aurora (i can, if needed...) dont forget to also take :)
status-firefox13: --- → affected
status-firefox14: --- → unaffected
status-firefox15: --- → fixed
status-firefox16: --- → fixed
You need to log in before you can comment on or make changes to this bug.