mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 17:52:45 +00:00 
			
		
		
		
	LibWeb: Implement CSSStyleSheet.replace()
				
					
				
			This method asynchronously replaces the content of the given stylesheet with the content passed to it. An exception is thrown if this method is used by a stylesheet not created with the `CSSStyleSheet()` constructor.
This commit is contained in:
		
							parent
							
								
									d209d5a84f
								
							
						
					
					
						commit
						81c67d34eb
					
				
					 5 changed files with 118 additions and 3 deletions
				
			
		
							
								
								
									
										50
									
								
								Tests/LibWeb/Text/input/css/CSSStyleSheet-replace.html
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										50
									
								
								Tests/LibWeb/Text/input/css/CSSStyleSheet-replace.html
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,50 @@ | |||
| <!DOCTYPE html> | ||||
| <style> | ||||
|     .test { | ||||
|         font-size: 12px; | ||||
|     } | ||||
| </style> | ||||
| <script src="../include.js"></script> | ||||
| <script> | ||||
|     asyncTest(async done => { | ||||
|         const newStyle = ` | ||||
|         .test { | ||||
|             font-size: 14px; | ||||
|         } | ||||
|         .test2 { | ||||
|             font-size: 16px; | ||||
|         }`; | ||||
|         const newStyle2 = `.test { | ||||
|             padding: 100px; | ||||
|         }`; | ||||
| 
 | ||||
|         const nonConstructedSheet = document.styleSheets[0]; | ||||
|         try { | ||||
|             await nonConstructedSheet.replace(newStyle); | ||||
|             println("FAIL"); | ||||
|         } catch (e) { | ||||
|             println(`Exception thrown when calling replace() on non-constructed stylesheet: ${e.name}`); | ||||
|         } | ||||
| 
 | ||||
|         const sheet = new CSSStyleSheet(); | ||||
|         const cssRules = sheet.cssRules; | ||||
| 
 | ||||
|         await sheet.replace(newStyle); | ||||
|         println(`Number of CSS rules after replace(): ${sheet.cssRules.length}`); | ||||
|         for (const rule of sheet.cssRules) { | ||||
|             println(`Rule: ${rule.cssText}`); | ||||
|         } | ||||
| 
 | ||||
|         const cssRulesAfterReplace = sheet.cssRules; | ||||
|         println(`cssRules returns the same object before and after replace(): ${cssRules === cssRulesAfterReplace}`); | ||||
| 
 | ||||
|         const importRule = `@import url("test.css");`; | ||||
|         await sheet.replace(`${newStyle2} ${importRule}`); | ||||
| 
 | ||||
|         println(`@import rule should be not appear below:`); | ||||
|         for (const rule of sheet.cssRules) { | ||||
|             println(`Rule: ${rule.cssText}`); | ||||
|         } | ||||
|         done(); | ||||
|     }); | ||||
| </script> | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Tim Ledbetter
						Tim Ledbetter