Changeset 142440 in webkit
- Timestamp:
- Feb 11, 2013 1:39:32 AM (11 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r142439 r142440 1 2013-02-11 John J. Barton <johnjbarton@chromium.org> 2 3 Web Inspector: Don't throw exceptions in WebInspector.Color 4 https://bugs.webkit.org/show_bug.cgi?id=104835 5 6 Reviewed by Vsevolod Vlasov. 7 8 Added case to test parsing 'none' from border style 9 10 * inspector/styles/styles-invalid-color-values-expected.txt: 11 * inspector/styles/styles-invalid-color-values.html: 12 1 13 2013-02-11 Andrey Lushnikov <lushnikov@chromium.org> 2 14 -
trunk/LayoutTests/inspector/styles/styles-invalid-color-values-expected.txt
r96543 r142440 74 74 hsla: hsla(0, 100%, 50%, 1) 75 75 76 Running: testInvalidColors 77 78 SUCCESS: parsed invalid color none to null 79 -
trunk/LayoutTests/inspector/styles/styles-invalid-color-values.html
r125965 r142440 18 18 'rgba(255, 0, 0, -5)', // clipped to rgba(255,0,0,0) 19 19 'rgba(255, 0, 0, 5)', // clipped to rgba(255,0,0,1) 20 ]; 21 22 var invalidColors = [ 23 // An invalid color, eg a value for a shorthand like 'border' which can have a color 24 'none', 20 25 ]; 21 26 … … 27 32 next(); 28 33 }, 34 function testInvalidColors(next) 35 { 36 for (var i = 0; i < invalidColors.length; ++i) 37 dumpErrorsForInvalidColor(invalidColors[i]); 38 next(); 39 }, 29 40 ]); 41 42 function dumpErrorsForInvalidColor(colorString) 43 { 44 var color = WebInspector.Color.parse(colorString); 45 if (!color) { 46 InspectorTest.addResult(""); 47 InspectorTest.addResult("SUCCESS: parsed invalid color " + colorString + " to null"); 48 return; 49 } else { 50 InspectorTest.addResult(""); 51 InspectorTest.addResult("FAIL: invalid color " + colorString + " did not parse to to null"); 52 } 53 } 30 54 31 55 function dumpColorRepresentationsForColor(colorString) 32 56 { 33 try { 34 var color = new WebInspector.Color(colorString); 35 } catch (e) { 36 InspectorTest.addResult("FAIL: Error parsing color '" + colorString + "'."); 57 var color = WebInspector.Color.parse(colorString); 58 if (!color) 37 59 return; 38 }39 60 40 61 InspectorTest.addResult(""); -
trunk/Source/WebCore/ChangeLog
r142439 r142440 1 2013-02-11 John J. Barton <johnjbarton@chromium.org> 2 3 Web Inspector: Don't throw exceptions in WebInspector.Color 4 https://bugs.webkit.org/show_bug.cgi?id=104835 5 6 Reviewed by Vsevolod Vlasov. 7 8 WebInspector.Color.parse() returns a Color from a string, or null; 9 Ctor calls now call parse(); 10 In the StylesSideBarPane, test null rather than catch(e). 11 12 Added case to inspector/styles/styles-invalid-color-values.html 13 14 * inspector/front-end/Color.js: 15 (WebInspector.Color): 16 (WebInspector.Color.parse): 17 (WebInspector.Color.fromRGBA): 18 (WebInspector.Color.fromRGB): 19 (WebInspector.Color.prototype.toString): 20 (WebInspector.Color.prototype._parse.this.alpha.set 0): 21 (WebInspector.Color.prototype._parse.this.nickname.set 2): 22 (WebInspector.Color.prototype._parse.this.hsla.set 1): 23 (WebInspector.Color.prototype._parse.this.rgba.set 0): 24 (WebInspector.Color.prototype._parse.set WebInspector): 25 (WebInspector.Color.prototype._parse): 26 * inspector/front-end/Spectrum.js: 27 (WebInspector.Spectrum.prototype.get color): 28 * inspector/front-end/StylesSidebarPane.js: 29 1 30 2013-02-11 Andrey Lushnikov <lushnikov@chromium.org> 2 31 -
trunk/Source/WebCore/inspector/front-end/Color.js
r139334 r142440 29 29 30 30 /** 31 * @constructor 31 * Don't call directly, use WebInspector.Color.parse(). 32 * @constructor 32 33 */ 33 34 WebInspector.Color = function(str) 34 35 { 35 36 this.value = str; 36 this._parse();37 37 } 38 38 39 WebInspector.Color.parse = function(str) 40 { 41 var maybeColor = new WebInspector.Color(str); 42 return maybeColor._parse() ? maybeColor : null; 43 } 39 44 /** 40 45 * @param {number=} a … … 42 47 WebInspector.Color.fromRGBA = function(r, g, b, a) 43 48 { 44 return new WebInspector.Color("rgba(" + r + "," + g + "," + b + "," + (typeof a === "undefined" ? 1 : a) + ")");49 return WebInspector.Color.parse("rgba(" + r + "," + g + "," + b + "," + (typeof a === "undefined" ? 1 : a) + ")"); 45 50 } 46 51 47 52 WebInspector.Color.fromRGB = function(r, g, b) 48 53 { 49 return new WebInspector.Color("rgb(" + r + "," + g + "," + b + ")");54 return WebInspector.Color.parse("rgb(" + r + "," + g + "," + b + ")"); 50 55 } 51 56 … … 207 212 } 208 213 209 throw "invalid color format";214 return "invalid color format: " + format; 210 215 }, 211 216 … … 433 438 this.nickname = set[2]; 434 439 this.alpha = set[0][3]; 435 return ;440 return true; 436 441 } 437 442 … … 462 467 this.hex = WebInspector.Color.Nicknames[nickname]; 463 468 } else // unknown name 464 throw "unknown color name";469 return false; 465 470 } else if (match[4]) { // hsl 466 471 this.format = "hsl"; … … 480 485 } 481 486 482 return ;487 return true; 483 488 } 484 489 … … 500 505 } 501 506 502 return ;507 return true; 503 508 } 504 509 505 510 // Could not parse as a valid color 506 throw "could not parse color";511 return false; 507 512 } 508 513 } -
trunk/Source/WebCore/inspector/front-end/Spectrum.js
r133582 r142440 282 282 if (!colorValue) 283 283 colorValue = color.toString(); // this.outputColorFormat can be invalid for current color (e.g. "nickname"). 284 return new WebInspector.Color(colorValue);284 return WebInspector.Color.parse(colorValue); 285 285 }, 286 286 -
trunk/Source/WebCore/inspector/front-end/StylesSidebarPane.js
r142132 r142440 1757 1757 function processColor(text) 1758 1758 { 1759 try { 1760 var color = new WebInspector.Color(text); 1761 } catch (e) { 1759 var color = WebInspector.Color.parse(text); 1760 1761 // We can be called with valid non-color values of |text| (like 'none' from border style) 1762 if (!color) 1762 1763 return document.createTextNode(text); 1763 } 1764 1764 1765 1765 var format = getFormat(); 1766 1766 var hasSpectrum = self._parentPane;
Note: See TracChangeset
for help on using the changeset viewer.