Closed
Bug 649672
Opened 14 years ago
Closed 14 years ago
File.slice has different semantics from Array.slice and String.slice
Categories
(Core :: DOM: Core & HTML, defect)
Core
DOM: Core & HTML
Tracking
()
RESOLVED
FIXED
People
(Reporter: sicking, Assigned: sicking)
Details
(Keywords: dev-doc-complete)
Attachments
(1 file)
17.29 KB,
patch
|
khuey
:
review+
dbaron
:
approval-mozilla-aurora+
dveditz
:
approval2.0+
|
Details | Diff | Splinter Review |
File.slice takes start+length, Array.slice and String.slice takes start+end.
The proposed way to fix it for now is to remove the unprefixed function and add a prefixed function which uses the correct semantics. If we're quick about this we can hopefully get chrome and opera to follow.
A few months down the road we should be able to unprefix with the correct semantics.
Assignee | ||
Updated•14 years ago
|
OS: Mac OS X → All
Hardware: x86 → All
Assignee | ||
Updated•14 years ago
|
blocking2.0: --- → ?
Assignee | ||
Comment 1•14 years ago
|
||
Assignee: nobody → jonas
Attachment #525718 -
Flags: review?(khuey)
Comment 2•14 years ago
|
||
So we will break the websites that uses .slice(), right?
I don't think there's a lot, but just want to make sure we spread the word.
Comment 3•14 years ago
|
||
(In reply to comment #2)
> So we will break the websites that uses .slice(), right?
> I don't think there's a lot, but just want to make sure we spread the word.
If a website use .slice with no feature detection, yes. But they shouldn't. Given that Firefox has .slice since a few weeks, that should be very common.
Comment 4•14 years ago
|
||
(In reply to comment #3)
> Given that Firefox has .slice since a few weeks, that should be very common.
... shouldn't be very common.
Comment on attachment 525718 [details] [diff] [review]
Patch to fix
>@@ -240,44 +241,80 @@ nsDOMFile::GetType(nsAString &aType)
> AppendUTF8toUTF16(mimeType, mContentType);
> }
>
> aType = mContentType;
>
> return NS_OK;
> }
>
>-// Makes sure that aStart and aStart + aLength is less then or equal to aSize
>+// Makes sure that aStart and aEnd is less then or equal to aSize and greater
>+// than 0
> void
>-ClampToSize(PRUint64 aSize, PRUint64& aStart, PRUint64& aLength)
>+ClampToSize(PRInt64 aSize, PRInt64& aStart, PRInt64& aEnd)
Now that we're handling negative indices, lets call this "ParseSize" or something similar. Update the comment too.
> {
>- if (aStart > aSize) {
>- aStart = aLength = 0;
>+ CheckedInt64 newStartOffset = aStart;
>+ if (aStart < -aSize) {
>+ newStartOffset = 0;
> }
>- CheckedUint64 endOffset = aStart;
>- endOffset += aLength;
>- if (!endOffset.valid() || endOffset.value() > aSize) {
>- aLength = aSize - aStart;
>+ else if (aStart < 0) {
>+ newStartOffset += aSize;
>+ }
>+ else if (aStart > aSize) {
>+ newStartOffset = aSize;
>+ }
>+ CheckedInt64 newEndOffset = aEnd;
>+ if (aEnd < -aSize) {
>+ newEndOffset = 0;
>+ }
>+ else if (aEnd < 0) {
>+ newEndOffset += aSize;
>+ }
>+ else if (aEnd > aSize) {
>+ newEndOffset = aSize;
>+ }
>+
>+ if (!newStartOffset.valid() || !newEndOffset.valid() ||
>+ newStartOffset.value() >= newEndOffset.value()) {
>+ aStart = aEnd = 0;
>+ }
>+ else {
>+ aStart = newStartOffset.value();
>+ aEnd = newEndOffset.value();
> }
> }
It took me a minute or two, but I believe the logic here and in the rest of the patch is correct. Test it thoroughly please :-)
r=me with that.
Attachment #525718 -
Flags: review?(khuey) → review+
Updated•14 years ago
|
blocking2.0: ? → Macaw+
Comment 6•14 years ago
|
||
Comment on attachment 525718 [details] [diff] [review]
Patch to fix
Approved for the mozilla2.0 repository, a=dveditz for release-drivers
Attachment #525718 -
Flags: approval2.0+
Assignee | ||
Comment 7•14 years ago
|
||
Assignee | ||
Comment 8•14 years ago
|
||
Comment on attachment 525718 [details] [diff] [review]
Patch to fix
Would like to fix this on aurora for parity with FF4. This will help us fix a bad spec issue which was found late in the game (after FF4 shipped and aurora branched).
Attachment #525718 -
Flags: approval-mozilla-aurora?
Updated•14 years ago
|
Keywords: dev-doc-needed
Comment 9•14 years ago
|
||
Is this something that will ship in a Firefox 4.0.1 or something then?
Comment 10•14 years ago
|
||
Yes, it will ship in Macaw (which will be 4.0.1 unless a need to have a chemspill between then arises)
Comment 11•14 years ago
|
||
So this is removing blob.slice() (and by extension File.slice()) and replacing it with mozSlice() with updated syntax, if I'm reading this code right?
Assignee | ||
Comment 12•14 years ago
|
||
Yes, that is correct.
It also makes the second argument optional (defaulting to "end of the file") as well as allows negative indexes.
If an index is negative it's treated as an offset from the end.
Comment 13•14 years ago
|
||
Documentation updated:
https://developer.mozilla.org/en/DOM/Blob
https://developer.mozilla.org/en/DOM/File
And mentioned on Firefox 5 for developers.
Keywords: dev-doc-needed → dev-doc-complete
Comment on attachment 525718 [details] [diff] [review]
Patch to fix
approved for mozilla-aurora, from triage meeting
Attachment #525718 -
Flags: approval-mozilla-aurora? → approval-mozilla-aurora+
Comment 15•14 years ago
|
||
This needs to land RSN now to make the ff5 train...
Assignee | ||
Comment 16•14 years ago
|
||
http://hg.mozilla.org/mozilla-aurora/rev/8c6e0aeb35ee
Checked in to aurora. Sorry for dropping the ball for so long.
status-firefox5:
--- → fixed
Updated•6 years ago
|
Component: DOM → DOM: Core & HTML
You need to log in
before you can comment on or make changes to this bug.
Description
•