Closed Bug 761159 Opened 12 years ago Closed 12 years ago

FileHandle: Better handling of the end of file state

Categories

(Core :: DOM: Core & HTML, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla16
Tracking Status
firefox13 --- affected
firefox14 --- unaffected
firefox15 --- verified
firefox16 --- fixed

People

(Reporter: janv, Assigned: janv)

Details

Attachments

(2 files, 3 obsolete files)

      No description provided.
Attached patch patch (obsolete) — Splinter 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.
Attached patch patch (obsolete) — Splinter Review
Attachment #629786 - Attachment is obsolete: true
Attachment #629786 - Flags: feedback?(jonas)
Attachment #629886 - Flags: review?(jonas)
Comment on attachment 629886 [details] [diff] [review]
patch

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();
>    NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_FILEHANDLE_UNKNOWN_ERR);
>  
>    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+
Attached patch updated patchSplinter Review
Assignee: nobody → Jan.Varga
Status: NEW → ASSIGNED
Attachment #633831 - Flags: review?(jonas)
Comment on attachment 633831 [details] [diff] [review]
updated patch

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

r=me

::: 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+
Attachment #629886 - Attachment is obsolete: true
Both comments addressed.

http://hg.mozilla.org/mozilla-central/rev/0ee6b0ed0446
Status: ASSIGNED → RESOLVED
Closed: 12 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?
Attached patch cast location to uint64_t* (obsolete) — Splinter Review
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.
yeah, could you try something like:

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

mLocation = location; // eventually change to: mLocation = static_cast<PRUint64>(location);
OS: Mac OS X → All
Hardware: x86 → All
Target Milestone: --- → mozilla16
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)
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 https://hg.mozilla.org/mozilla-central/rev/449cfd3737cd :)
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: