Changeset 18320 in webkit


Ignore:
Timestamp:
Dec 19, 2006 10:56:45 AM (17 years ago)
Author:
ap
Message:

Reviewed by Darin.

http://bugs.webkit.org/show_bug.cgi?id=7296
JavaScript error not thrown when trying to set a CSS property to an invalid value

WebCore:

  • bindings/js/kjs_css.cpp: (KJS::DOMCSSStyleDeclaration::put): When not in Dashboard compatibility mode, raise exception for invalid values. Also removed an unnecessary call to removeProperty(), which prevented the property value from being preserved in error case.
  • css/CSSMutableStyleDeclaration.cpp: (WebCore::CSSMutableStyleDeclaration::setProperty): Moved the handling of empty property values here. Also removed an unnecessary call to removeProperty().

LayoutTests:

  • fast/block/positioning/relayout-on-position-change.html: This test was setting position property to an invalid value, expecting that it will be removed. Changed it to set the property to an empty value (now the test passes in Firefox, too).
  • fast/dom/css-set-property-exception-expected.txt:
  • fast/dom/css-set-property-exception.html: Updated the results, added a new case and made the output more verbose.
Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r18315 r18320  
     12006-12-19  Alexey Proskuryakov  <ap@webkit.org>
     2
     3        Reviewed by Darin.
     4
     5        http://bugs.webkit.org/show_bug.cgi?id=7296
     6        JavaScript error not thrown when trying to set a CSS property to an invalid value
     7
     8        * fast/block/positioning/relayout-on-position-change.html: This test was setting
     9        position property to an invalid value, expecting that it will be removed. Changed
     10        it to set the property to an empty value (now the test passes in Firefox, too).
     11
     12        * fast/dom/css-set-property-exception-expected.txt:
     13        * fast/dom/css-set-property-exception.html:
     14        Updated the results, added a new case and made the output more verbose.
     15
    1162006-12-18  Nikolas Zimmermann  <zimmermann@kde.org>
    217
  • trunk/LayoutTests/fast/block/positioning/relayout-on-position-change.html

    r12682 r18320  
    55{
    66    document.body.offsetTop;    // force layout
    7     document.getElementById('change').style.position = "none";
     7    document.getElementById('change').style.position = "";
    88}
    99</script>
  • trunk/LayoutTests/fast/dom/css-set-property-exception-expected.txt

    r11962 r18320  
    1 This test checks to see whether you get exceptions when setting a property with a "bad value". We preserve our historic behavior of never raising an exception when you set a CSS property using JavaScript property syntax. But we do raise exceptions when setting a property with setProperty.
     1Test for bug 7296.
    22
    3 The results below should show four successes, followed by two exceptions.
     3This test checks to see whether you get exceptions when setting a property with a "bad value". Setting using JavaScript property syntax and with setProperty() should behave the same.
    44
    5 This is the test element.
     5The results below should show success in cases 1, 3, 5, and 7.
    66
    7 Successfully set display to "block"; value is now "block".
    8 Successfully set display to ""; value is now "".
    9 Successfully set display to null; value is now "".
    10 Successfully set display to "block" with setProperty; value is now "block".
    11 Got exception trying to set display to "" with setProperty; value is now "".
    12 Got exception trying to set display to null with setProperty; value is now "".
     7It is OK if the order of properties changes from the expected results - IE 6 and Firefox 2 don't agree on it anyway.
    138
     9Successfully set display to "block"; cssText is now: "top: 0px; bottom: 1px; display: block; ".
     10Got exception trying to set display to "foobar"; cssText is now: "top: 0px; display: none; bottom: 1px; ".
     11Successfully set display to ""; cssText is now: "top: 0px; bottom: 1px; ".
     12Got exception trying to set display to null; cssText is now: "top: 0px; display: none; bottom: 1px; ".
     13Successfully set display to "block" with setProperty; cssText is now: "top: 0px; bottom: 1px; display: block; ".
     14Got exception trying to set display to "foobar" with setProperty; cssText is now: "top: 0px; display: none; bottom: 1px; ".
     15Successfully set display to "" with setProperty; cssText is now: "top: 0px; bottom: 1px; ".
     16Got exception trying to set display to null with setProperty; cssText is now: "top: 0px; display: none; bottom: 1px; ".
     17
  • trunk/LayoutTests/fast/dom/css-set-property-exception.html

    r11995 r18320  
    88    document.getElementById("console").appendChild(item);
    99}
     10function setInitialStyleForE()
     11{
     12    var e = document.getElementById('e');
     13
     14    e.style.top = "0px";
     15    e.style.bottom = "";
     16    e.style.display = "none";
     17    e.style.bottom = "1px";
     18}
    1019function test()
    1120{
     
    1524    var e = document.getElementById('e');
    1625
    17     e.style.display = "none";
     26    setInitialStyleForE();
    1827    try {
    1928        e.style.display = "block";
    20         log("Successfully set display to \"block\"; value is now \"" + e.style.display + "\".");
     29        log("Successfully set display to \"block\"; cssText is now: \"" + e.style.cssText + "\".");
    2130    } catch (exception) {
    22         log("Got exception trying to set display to \"block\"; value is now \"" + e.style.display + "\".");
     31        log("Got exception trying to set display to \"block\"; cssText is now: \"" + e.style.cssText + "\".");
    2332    }
    2433
    25     e.style.display = "none";
     34    setInitialStyleForE();
     35    try {
     36        e.style.display = "foobar";
     37        log("Successfully set display to \"foobar\"; cssText is now: \"" + e.style.cssText + "\".");
     38    } catch (exception) {
     39        log("Got exception trying to set display to \"foobar\"; cssText is now: \"" + e.style.cssText + "\".");
     40    }
     41
     42    setInitialStyleForE();
    2643    try {
    2744        e.style.display = "";
    28         log("Successfully set display to \"\"; value is now \"" + e.style.display + "\".");
     45        log("Successfully set display to \"\"; cssText is now: \"" + e.style.cssText + "\".");
    2946    } catch (exception) {
    30         log("Got exception trying to set display to \"\"; value is now \"" + e.style.display + "\".");
     47        log("Got exception trying to set display to \"\"; cssText is now: \"" + e.style.cssText + "\".");
    3148    }
    3249
    33     e.style.display = "none";
     50    setInitialStyleForE();
    3451    try {
    3552        e.style.display = null;
    36         log("Successfully set display to null; value is now \"" + e.style.display + "\".");
     53        log("Successfully set display to null; cssText is now: \"" + e.style.cssText + "\".");
    3754    } catch (exception) {
    38         log("Got exception trying to set display to null; value is now \"" + e.style.display + "\".");
     55        log("Got exception trying to set display to null; cssText is now: \"" + e.style.cssText + "\".");
    3956    }
    4057
    41     e.style.display = "none";
     58    setInitialStyleForE();
    4259    try {
    4360        e.style.setProperty("display", "block", "");
    44         log("Successfully set display to \"block\" with setProperty; value is now \"" + e.style.display + "\".");
     61        log("Successfully set display to \"block\" with setProperty; cssText is now: \"" + e.style.cssText + "\".");
    4562    } catch (exception) {
    46         log("Got exception trying to set display to \"block\" with setProperty; value is now \"" + e.style.display + "\".");
     63        log("Got exception trying to set display to \"block\" with setProperty; cssText is now: \"" + e.style.cssText + "\".");
    4764    }
    4865
    49     e.style.display = "none";
     66    setInitialStyleForE();
     67    try {
     68        e.style.setProperty("display", "foobar", "");
     69        log("Successfully set display to \"foobar\" with setProperty; cssText is now: \"" + e.style.cssText + "\".");
     70    } catch (exception) {
     71        log("Got exception trying to set display to \"foobar\" with setProperty; cssText is now: \"" + e.style.cssText + "\".");
     72    }
     73
     74    setInitialStyleForE();
    5075    try {
    5176        e.style.setProperty("display", "", "");
    52         log("Successfully set display to \"\" with setProperty; value is now \"" + e.style.display + "\".");
     77        log("Successfully set display to \"\" with setProperty; cssText is now: \"" + e.style.cssText + "\".");
    5378    } catch (exception) {
    54         log("Got exception trying to set display to \"\" with setProperty; value is now \"" + e.style.display + "\".");
     79        log("Got exception trying to set display to \"\" with setProperty; cssText is now: \"" + e.style.cssText + "\".");
    5580    }
    5681
    57     e.style.display = "none";
     82    setInitialStyleForE();
    5883    try {
    5984        e.style.setProperty("display", null, "");
    60         log("Successfully set display to null with setProperty; value is now \"" + e.style.display + "\".");
     85        log("Successfully set display to null with setProperty; cssText is now: \"" + e.style.cssText + "\".");
    6186    } catch (exception) {
    62         log("Got exception trying to set display to null with setProperty; value is now \"" + e.style.display + "\".");
     87        log("Got exception trying to set display to null with setProperty; cssText is now: \"" + e.style.cssText + "\".");
    6388    }
    6489}
     
    6691</head>
    6792<body onload="test();">
     93<p>Test for <a href="http://bugs.webkit.org/show_bug.cgi?id=7296">bug 7296</a>.</p>
    6894<p>This test checks to see whether you get exceptions when setting a property with a "bad value".
    69 We preserve our historic behavior of never raising an exception when you set a CSS property using JavaScript property syntax.
    70 But we do raise exceptions when setting a property with setProperty.</p>
    71 <p>The results below should show four successes, followed by two exceptions.</p>
     95Setting using JavaScript property syntax and with setProperty() should behave the same.</p>
     96<p>The results below should show success in cases 1, 3, 5, and 7.</p>
     97<P>It is OK if the order of properties changes from the expected results - IE 6 and Firefox 2 don't agree on it anyway.</p>
    7298<hr>
    7399<p id="e">This is the test element.</p>
  • trunk/WebCore/ChangeLog

    r18319 r18320  
     12006-12-19  Alexey Proskuryakov  <ap@webkit.org>
     2
     3        Reviewed by Darin.
     4
     5        http://bugs.webkit.org/show_bug.cgi?id=7296
     6        JavaScript error not thrown when trying to set a CSS property to an invalid value
     7
     8        * bindings/js/kjs_css.cpp:
     9        (KJS::DOMCSSStyleDeclaration::put): When not in Dashboard compatibility mode,
     10        raise exception for invalid values. Also removed an unnecessary call to
     11        removeProperty(), which prevented the property value from being preserved in
     12        error case.
     13
     14        * css/CSSMutableStyleDeclaration.cpp:
     15        (WebCore::CSSMutableStyleDeclaration::setProperty): Moved the handling of
     16        empty property values here. Also removed an unnecessary call to removeProperty().
     17
    1182006-12-19  Anders Carlsson  <acarlsson@apple.com>
    219
  • trunk/WebCore/bindings/js/kjs_css.cpp

    r16217 r18320  
    3535#include "CSSValueList.h"
    3636#include "Document.h"
     37#include "Frame.h"
    3738#include "HTMLNames.h"
    3839#include "HTMLStyleElement.h"
     
    4344#include "JSCSSValueList.h"
    4445#include "MediaList.h"
     46#include "Settings.h"
    4547#include "StyleSheetList.h"
    4648#include "kjs_dom.h"
     
    212214      bool pixelOrPos;
    213215      String prop = cssPropertyName(propertyName, &pixelOrPos);
    214       String propvalue = value->toString(exec);
     216      String propValue = value->toString(exec);
    215217      if (pixelOrPos)
    216         propvalue += "px";
     218        propValue += "px";
    217219#ifdef KJS_VERBOSE
    218220      kdDebug(6070) << "DOMCSSStyleDeclaration: prop=" << prop << " propvalue=" << propvalue << endl;
    219221#endif
    220       styleDecl.removeProperty(prop, exception);
    221       if (!exception && !propvalue.isEmpty()) {
    222         // We have to ignore exceptions here, because of the following unfortunate situation:
    223         //   1) Older versions ignored exceptions here by accident, because the put function
    224         //      that translated exceptions did not translate CSS exceptions.
    225         //   2) Gecko does not raise an exception in this case, although WinIE does.
    226         //   3) At least some Dashboard widgets are depending on this behavior.
    227         // It would be nice to fix this some day, perhaps with some kind of "quirks mode",
    228         // but it's likely that the Dashboard widgets are already using a strict mode DOCTYPE.
    229         ExceptionCode ec = 0;
    230         styleDecl.setProperty(prop, propvalue, ec);
    231       }
     222      ASSERT(styleDecl.stylesheet()->isCSSStyleSheet());
     223      if (Frame* frame = static_cast<CSSStyleSheet*>(styleDecl.stylesheet())->doc()->frame())
     224        if (frame->settings()->shouldUseDashboardBackwardCompatibilityMode()) {
     225          styleDecl.removeProperty(prop, exception);
     226          if (!exception) {
     227            ExceptionCode exceptionIgnored = 0;
     228            styleDecl.setProperty(prop, propValue, exceptionIgnored);
     229            return;
     230          }
     231        }
     232      styleDecl.setProperty(prop, propValue, exception);
    232233    } else {
    233234      DOMObject::put(exec, propertyName, value, attr);
  • trunk/WebCore/css/CSSMutableStyleDeclaration.cpp

    r14407 r18320  
    298298    ec = 0;
    299299
    300     removeProperty(propertyID);
    301 
     300    // Setting the value to an empty string just removes the property in both IE and Gecko.
     301    if (value.isEmpty()) {
     302        removeProperty(propertyID, notifyChanged, ec);
     303        return ec == 0;
     304    }
     305
     306    // When replacing an existing property value, this moves the property to the end of the list.
     307    // Firefox preserves the position, and MSIE moves the property to the beginning.
    302308    CSSParser parser(useStrictParsing());
    303309    bool success = parser.parseValue(this, propertyID, value, important);
Note: See TracChangeset for help on using the changeset viewer.