Closed Bug 1328835 Opened 9 years ago Closed 9 years ago

Unable to define a getter on dataset objects

Categories

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

defect
Not set
normal

Tracking

()

RESOLVED DUPLICATE of bug 1301754

People

(Reporter: jandem, Unassigned)

References

Details

Noticed this while writing tests for bug 965992. The test below alerts |123| and |number| in Safari and Chrome. In Firefox, however, I get |undefined| and |string|. We seem to define a data property with value "undefined" instead of the getter? <script> var o = document.documentElement.dataset; Object.defineProperty(o, "foobar", {get: function() { return 123; }}); alert(o.foobar); alert(typeof o.foobar); </script>
Flags: needinfo?(bzbarsky)
I imagine the bug here is that we do if (!ConvertJSValueToString(cx, desc.value(), eStringify, eStringify, value)) { in DOMProxyHandler::defineProperty without checking desc.isDataDescriptor(), while the WebIDL standard states > If the result of calling IsDataDescriptor(Desc) is false, then return false. at https://heycam.github.io/webidl/#legacy-platform-object-defineownproperty step 2.2.2.1.
Oh. Right. This thing has a named setter/creator, so using it for accessor props for the bug 965992 tests is not a good idea. I had forgotten about that part. Per spec, that defineProperty call should throw. Bug 1301754 tracks the fact that we don't throw; https://bugs.chromium.org/p/chromium/issues/detail?id=645542 is the Chromium bug. For the tests in bug 965992, probably best to just use an HTMLFormElement instead; I'm pretty sure that will not switch away from its current shadowing behavior (which I can't say for document). So: <!DOCTYPE html> <form></form> <script> var form = document.querySelector("form"); </script>
Status: NEW → RESOLVED
Closed: 9 years ago
Flags: needinfo?(bzbarsky)
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.