Bug 89697 - [JSC] CSSStyleDeclaration report incorrect descriptor
Summary: [JSC] CSSStyleDeclaration report incorrect descriptor
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Manuel Rego Casasnovas
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-06-21 15:40 PDT by Erik Arvidsson
Modified: 2014-04-14 04:22 PDT (History)
13 users (show)

See Also:


Attachments
Patch (4.66 KB, patch)
2013-06-07 13:24 PDT, Manuel Rego Casasnovas
no flags Details | Formatted Diff | Diff
Patch (4.76 KB, patch)
2013-08-05 01:48 PDT, Manuel Rego Casasnovas
no flags Details | Formatted Diff | Diff
Patch (4.84 KB, patch)
2014-04-14 02:49 PDT, Manuel Rego Casasnovas
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Erik Arvidsson 2012-06-21 15:40:58 PDT
The properties of the CSSStyleDeclaration are enumerable by the for in loop but the property descriptor reports them as non enumerable.

var style = document.getComputedStyle(document.body);
var descr = Object.getOwnPropertyDescriptor(style, 'color');
shouldBeTrue('descr.enumerable');
Comment 1 Manuel Rego Casasnovas 2013-06-07 13:15:05 PDT
(In reply to comment #0)
> The properties of the CSSStyleDeclaration are enumerable by the for in loop but the property descriptor reports them as non enumerable.
> 
> var style = document.getComputedStyle(document.body);
> var descr = Object.getOwnPropertyDescriptor(style, 'color');
> shouldBeTrue('descr.enumerable');

There's also more weird stuff regarding CSS2Properties in CSSStyleDeclaration.

For example if you get the descriptor of "color" property with Object.getOwnPropertyDescriptor() it returns:
Object {value: "", writable: false, enumerable: false, configurable: false}

So it appears as "writable: false" however things like the next line works properly:
style.color = "blue";

According to the spec (http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf) if writable is false you shouldn't be allowed to modify the value.

So it's clear that the descriptor is wrong.

BTW, the descriptor in Chrome is:
Object {value: "", writable: true, enumerable: true, configurable: true}
Comment 2 Manuel Rego Casasnovas 2013-06-07 13:24:30 PDT
Created attachment 204064 [details]
Patch
Comment 3 Manuel Rego Casasnovas 2013-06-07 13:28:50 PDT
Comment on attachment 204064 [details]
Patch

This patch changes the property descriptor.

However there's still an issue, as even when the descriptor now say "configurable: true" (like in Chrome), if you use Object.defineProperty() to change the descriptor the change is not working.

For example with the following code you don't get any message in the JavaScript console:
    Object.defineProperty(style, "color", {
        get : function(){ console.log("get color"); },
        set : function(x){ console.log("set color: " + x); },
    });

Anyway I think that we could report this as a different bug as it seems clear that current descriptor is not accurate with the behavior of CSS2Properties in CSSStyleDeclaration object.
Comment 4 Geoffrey Garen 2013-08-01 21:20:31 PDT
Comment on attachment 204064 [details]
Patch

Removing ReadOnly and DontEnum here is good.

But let's keep DontDelete (configurable: true) for now,  Since the property isn't delete-able, that's the most honest thing to report.
Comment 5 Manuel Rego Casasnovas 2013-08-05 01:48:48 PDT
Created attachment 208111 [details]
Patch
Comment 6 Benjamin Poulain 2014-04-13 23:19:01 PDT
Comment on attachment 208111 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=208111&action=review

The patch looks good. Some issue with the test. This will need a rebaseline.

> LayoutTests/ChangeLog:12
> +        * fast/js/cssstyledeclaration-properties-descriptor-expected.txt: Added.
> +        * fast/js/cssstyledeclaration-properties-descriptor.html: Added.
> +        * fast/js/script-tests/cssstyledeclaration-properties-descriptor.js: Added.

The test is at the wrong place, it should be in LayoutTests//fast/dom/CSSStyleDeclaration

> LayoutTests/fast/js/cssstyledeclaration-properties-descriptor.html:1
> +<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">

Please use the HTML5 doctype.

> LayoutTests/fast/js/cssstyledeclaration-properties-descriptor.html:4
> +<script src="resources/js-test-pre.js"></script>

This won't work anymore, the path has changed. :(

> LayoutTests/fast/js/cssstyledeclaration-properties-descriptor.html:7
> +<script src="script-tests/cssstyledeclaration-properties-descriptor.js"></script>

Please put the test code here instead of using a separate file.

The separate file thingy is the old style of WebKit. It makes it more painful to work on tests.

> LayoutTests/fast/js/script-tests/cssstyledeclaration-properties-descriptor.js:3
> +description(
> +"This tests the descriptor of CSSStyleDeclaration properties."
> +);

This should be on a single line.
Comment 7 Manuel Rego Casasnovas 2014-04-14 02:49:16 PDT
Created attachment 229275 [details]
Patch

Thanks for the review. Patch for landing applying review suggestions.
Comment 8 WebKit Commit Bot 2014-04-14 04:22:16 PDT
Comment on attachment 229275 [details]
Patch

Clearing flags on attachment: 229275

Committed r167240: <http://trac.webkit.org/changeset/167240>
Comment 9 WebKit Commit Bot 2014-04-14 04:22:21 PDT
All reviewed patches have been landed.  Closing bug.