Bug 53752 - [JSC binding] Inconsistent behavior of DOMStringMap
Summary: [JSC binding] Inconsistent behavior of DOMStringMap
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: 528+ (Nightly build)
Hardware: PC OS X 10.5
: P2 Normal
Assignee: Kent Tamura
URL:
Keywords:
Depends on:
Blocks: 53578
  Show dependency treegraph
 
Reported: 2011-02-03 20:33 PST by Kent Tamura
Modified: 2011-10-07 00:05 PDT (History)
3 users (show)

See Also:


Attachments
Incomplete patch (3.98 KB, patch)
2011-02-06 18:20 PST, Kent Tamura
no flags Details | Formatted Diff | Diff
Patch (9.22 KB, patch)
2011-10-06 01:59 PDT, Kent Tamura
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Kent Tamura 2011-02-03 20:33:31 PST
The behavior of the current JSC binding for DOMStringMap is:
  put: Handle JavaScript property first, then handle HTML attribute if there is not JS property.
  delete: ditto.
  get: Handle HTML attribute, then handle JavaScript property.

The get operation is inconsistent with put/delete.  So, we have the following curious behavior:

1> document.body.dataset.toString
function toString() { ...
2> document.body.setAttribute('data-to-string', 'attr')
3> document.body.dataset.toString
  "attr"
4> document.body.dataset.toString = function() { return "dataset"; }
5> document.body.dataset.toString
  "attr"

Even if one sets a new value to .toString [4], .toString doesn't return the new value [5].  It's not good.

I think it's reasonable to handle JavaScript properties first to protect JavaScript Object behavior.  However, we should do it in the get operation too and should give up providing "data-to-string" attribute via HTMLElement::dataset for consistency.
Comment 1 Kent Tamura 2011-02-06 18:20:07 PST
Created attachment 81440 [details]
Incomplete patch

The last test (delete div.dataset.foobarbaz) doesn't work.
Comment 2 Kent Tamura 2011-10-06 01:39:05 PDT
(In reply to comment #0)
> I think it's reasonable to handle JavaScript properties first to protect JavaScript Object behavior.  However, we should do it in the get operation too and should give up providing "data-to-string" attribute via HTMLElement::dataset for consistency.

I changed my mind. Both of Firefox and Opera always handles data-* attributes first.  We had better follow them.
Comment 3 Kent Tamura 2011-10-06 01:59:48 PDT
Created attachment 109933 [details]
Patch
Comment 4 Darin Adler 2011-10-06 14:01:55 PDT
Comment on attachment 109933 [details]
Patch

Looks good.
Comment 5 Kent Tamura 2011-10-06 15:58:31 PDT
Comment on attachment 109933 [details]
Patch

Thank you for reviewing.
Comment 6 WebKit Review Bot 2011-10-06 19:43:59 PDT
Comment on attachment 109933 [details]
Patch

Clearing flags on attachment: 109933

Committed r96893: <http://trac.webkit.org/changeset/96893>
Comment 7 WebKit Review Bot 2011-10-06 19:44:04 PDT
All reviewed patches have been landed.  Closing bug.
Comment 8 Kent Tamura 2011-10-07 00:05:44 PDT
A follow-up test change: http://trac.webkit.org/changeset/96911