Unable to define a getter on dataset objects

RESOLVED DUPLICATE of bug 1301754

Status

()

Core
DOM: Core & HTML
RESOLVED DUPLICATE of bug 1301754
a year ago
a year ago

People

(Reporter: jandem, Unassigned)

Tracking

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

a year ago
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>
(Reporter)

Updated

a year ago
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
Last Resolved: a year ago
Flags: needinfo?(bzbarsky)
Resolution: --- → DUPLICATE
Duplicate of bug: 1301754
You need to log in before you can comment on or make changes to this bug.