Closed Bug 492219 Opened 15 years ago Closed 15 years ago

localStorage's constructor should be Storage

Categories

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

1.9.1 Branch
defect
Not set
normal

Tracking

()

VERIFIED FIXED

People

(Reporter: sephr, Assigned: mayhemer)

References

Details

(Keywords: verified1.9.1)

Attachments

(4 files, 2 obsolete files)

User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.0.10) Gecko/2009042523 Ubuntu/9.04 (jaunty) Firefox/3.0.10 GTB5 Build Identifier: localStorage currently has the constructor, Storage2 while globalStorage items currently have Storage as a constructor. This would break any webapps that extend Storage.prototype to extend globalStorage items AND localStorage for WebKit. I suggest making globalStorage items and localStorage both have same constructor. Reproducible: Always Steps to Reproduce: 1. Storage.prototype.foo = function() { return 123; } 2. localStorage.foo() 3. globalStorage[location.hostname].foo() Actual Results: localStorage.foo() throws and error and globalStorage[location.hostname].foo() returns 123. Expected Results: localStorage.foo() and globalStorage[location.hostname].foo() both return 123.
Attached file testcase
Blocks: 422526
Flags: blocking1.9.1?
Version: unspecified → 1.9.1 Branch
This bug breaks the Noteboard webapp at noteboard.eligrey.com. Line 188 @ http://noteboard.eligrey.com/noteboard.full.js defines Storage.prototype.itemExists expecting it to be accessible via localStorage.itemExits. For Safari and Firefox <3.5 this works fine. If the script detects globalStorage but no localStorage, it defines localStorage as globalStorage[location.hostname]. Due to Firefox >=3.5 not inheriting the properties set on Storage.prototype, the webapp doesn't work any more. I have discontinued development of Noteboard a while back due to it not being that useful, but Google Analytics reports to me that there are still quite a few people who use this webapp daily.
Assignee: nobody → honzab.moz
Suggestion: drop globalStorage or at least stop supporting its compatibility. It was already drop from the spec anyway. To explain why there is Storage2: globalStorage items are using an old interface (nsIDOMStorage) that returns nsIDOMStorageItem for each key in the storage (when using getItem), it has attributes 'value' and 'secure'. But, localStorage was re-specified to return the value for a key directly (so, it returns DOMString for each key in the storage). localStorage (and sessionStorage will be, bug 455070) is implemented by a different C++ class then globalStorage items. This was necessary to let XPConnect correctly distinguish between the two interfaces (a single class implementing both interfaces didn't work - we was not able to control which interface is exposed to scripts, getItem methods on both interfaces had the same name but a different signature). To achieve it, there are Storage and Storage2 DOM class implementations. We have NS_DEFINE_CLASSINFO_DATA(Storage, nsStorageSH) for globalStorage items and NS_DEFINE_CLASSINFO_DATA(Storage2, nsStorage2SH) for localStorage. I'd rename Storage to StorageObsolete or something like that and Storage2 to Storage. This should be IMO fixed after bug 455070 because it would badly effect sessionStorage. Opinions?
Blocks: 486654
No longer blocks: 422526
Status: UNCONFIRMED → ASSIGNED
Depends on: 455070
Ever confirmed: true
Blocking, and I think the rename of Storage to StorageObsolete etc is the way to go here. The sooner we do this the better.
Flags: blocking1.9.1? → blocking1.9.1+
Attached patch v1 (obsolete) — Splinter Review
Storage -> StorageObsolete (affects globalStorage items) Storage2 -> Storage (now localStorage's constructor is Storage)
Attachment #377177 - Flags: review?(jst)
Whiteboard: [has patch][needs review jst]
Attachment #377177 - Flags: superreview+
Attachment #377177 - Flags: review?(jst)
Attachment #377177 - Flags: review+
Keywords: checkin-needed
Whiteboard: [has patch][needs review jst] → [has patch][ready to land]
This looks bad. The assertion checks that a dom class name (e.g. Storage) is the name of an interface we demand to use (e.g. nsIDOMStorage); a part w/o the "nsIDOM" is compared. This means API change, we must rename the interface. jst or someone else should approve such a change.
As this will effect sessionStorage too, we should also consider getting bug 455070 to 1.9.1. It's waiting for months for a regular review...
Global replace patch. Interfaces are renamed and both their iids were changed.
Attachment #377177 - Attachment is obsolete: true
Attachment #377668 - Flags: review?(jst)
Comment on attachment 377668 [details] [diff] [review] v2 [Checkin comment 11] Looks good.
Attachment #377668 - Flags: superreview+
Attachment #377668 - Flags: review?(jst)
Attachment #377668 - Flags: review+
Status: ASSIGNED → RESOLVED
Closed: 15 years ago
Resolution: --- → FIXED
Attachment #377668 - Attachment description: v2 → v2 [Checkin comment 11]
Whiteboard: [has patch] → [has patch][baking on trunk since May 16th]
Why no iid rev on nsIDocShell here? I guess existing C++ code would just keep working, since nothing other than interface names changed? But it still seems more correct to rev the iid to me... And how do you plan to do the equivalent change on 1.9.1 where you can't change nsIDocShell? Or is this change compatible enough that we can do it there?
(In reply to comment #12) > Why no iid rev on nsIDocShell here? I guess existing C++ code would just keep > working, since nothing other than interface names changed? But it still seems > more correct to rev the iid to me... > > And how do you plan to do the equivalent change on 1.9.1 where you can't change > nsIDocShell? Or is this change compatible enough that we can do it there? It is just a rename, unrecompiled C code will be ok with it from the binary point of view. But what's wrong is that doing QI to nsIDOMStorage or nsIDOMStorageObsolete fails in such an unrecompiled code - iid has changed to new ones in both cases. So, my solution for 1.9.1 is NOT TO CHANGE iid of the renamed interfaces, so there will be no iid change in the whole patch, unrecompiled code will be happy. When binary extension developers will recompile with this patch, their build will break and they have to fix manually. Probably start a thread about this on dev.platform? For the trunk only we should probably have a fix to change iids of all remaining affected interfaces (nsIDocShell.idl nsIDOMStorageList.idl nsIDOMStorageManager.idl nsIDOMStorageWindow.idl) Reopening, there is apparently still a work to do.
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
Updating iids of all affected interface. This patch is intended to land only on trunk.
Attachment #378008 - Flags: review?(bzbarsky)
Attached patch v1 for 1.9.1 (obsolete) — Splinter Review
Ok, in this patch nsIDOMStorageObsolete has the same iid as nsIDOMStorage had before. Same applies to the new nsIDOMStorage and nsIDOMStorage2. If you agree on this change we can take it to 1.9.1. If not, my experience is not that good to find a different solution at the moment.
Attachment #378033 - Flags: review?(bzbarsky)
Attachment #378008 - Flags: review?(bzbarsky) → review+
If the only issue here is the naming of the relevant prototype in the DOM, then for branch it might make sense to leave all the IDL as-is, having C++ consumers deal with the difference in naming between C++ and the DOM but not having any changes from the current setup in terms of code they write, and changing the naming in the DOM by just changing NS_DEFINE_CLASSINFO_DATA(Storage, nsStorageSH, flags) to NS_DEFINE_CLASSINFO_DATA_WITH_NAME(Storage, StorageObsolete, nsStorageSH, flags) in nsDOMClassInfo.cpp. And similarly for Storage2, using Storage as the name. Is there some obvious issue left that that wouldn't resolve as far as branch is concerned?
(In reply to comment #16) > If the only issue here is the naming of the relevant prototype in the DOM, then > for branch it might make sense to leave all the IDL as-is, having C++ consumers > deal with the difference in naming between C++ and the DOM but not having any > changes from the current setup in terms of code they write, and changing the > naming in the DOM by just changing > > NS_DEFINE_CLASSINFO_DATA(Storage, nsStorageSH, flags) > > to > > NS_DEFINE_CLASSINFO_DATA_WITH_NAME(Storage, StorageObsolete, nsStorageSH, > flags) > > in nsDOMClassInfo.cpp. And similarly for Storage2, using Storage as the name. > Is there some obvious issue left that that wouldn't resolve as far as branch is > concerned? It doesn't work. With patch like this: - NS_DEFINE_CLASSINFO_DATA(Storage, nsStorageSH, + NS_DEFINE_CLASSINFO_DATA_WITH_NAME(Storage, StorageObsolete, nsStorageSH, - NS_DEFINE_CLASSINFO_DATA(Storage2, nsStorage2SH, + NS_DEFINE_CLASSINFO_DATA_WITH_NAME(Storage2, Storage, nsStorage2SH, I got the constructor I want but it still fails on the assertion here: NS_ASSERTION(nsCRT::strcmp(CutPrefix(name), mData->mName) == 0, "...")
Attachment #378008 - Attachment description: trunk-only fix, iid update, v1 → trunk-only fix, iid update, v1 [Checkin comment 18]
All work for the trunk has been done. If we don't agree on the 1.9.1 patch then it seems good to open a new bug.
Status: REOPENED → RESOLVED
Closed: 15 years ago15 years ago
Resolution: --- → FIXED
You probably also need to use DOM_CLASSINFO_MAP_BEGIN_NO_CLASS_IF instead of DOM_CLASSINFO_MAP_BEGIN for those classes. Double-check with jst, though? I _think_ that should do the right thing, but he'd know for sure. You can take whatever approach for 1.9.1 you prefer; if you prefer to spin off a separate bug, please do.
Attachment #378033 - Attachment is obsolete: true
Attachment #378033 - Flags: review?(bzbarsky)
Successfully tested, fixes the problem w/o any moves with interfaces.
Attachment #378575 - Flags: review?(bzbarsky)
Comment on attachment 378575 [details] [diff] [review] v1 for 1.9.1 [Checkin comment 23] Looks great.
Attachment #378575 - Flags: review?(bzbarsky) → review+
Attachment #378575 - Attachment description: v1 for 1.9.1 → v1 for 1.9.1 [Checkin comment 23]
Keywords: fixed1.9.1
Whiteboard: [has patch][baking on trunk since May 16th]
added to mochiTest, verified FIXED on builds using the attached testcase: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1pre) Gecko/20090602 Shiretoko/3.5pre ID:20090602044233 and Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2a1pre) Gecko/20090601 Minefield/3.6a1pre ID:20090601041706
Status: RESOLVED → VERIFIED
Flags: in-testsuite+
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: