Optimize 2D Canvas style setters

This CL eliminates unnecessary conditional branches, switch statements
and function call overhead when setting the fillStyle and strokeStyle
attributes of CanvasRenderingContext2D.

This change also updates the 2d.gradient.object.update.html tests to
make them more robust. Before this change, blink was not spec
compliant and the existing test did not catch it. The problem
was that because blink was deferring the evaluation of the
CanvasGradient until the time of first draw, it was catching changes
to the CanvasGradient that were made after setting fillStyle. So the
test was not robust enough to truly verify that the CanvasGradient
object is live. The test now modifies the CanvasGradient between
consecutive draws, which is the test that the old implementation would
have failed because the gradient would have been baked-in after the
first draw.

This change improves MotionMark Canvas Lines by 0.4% on M1 MacOS

Bug: 1430274
Change-Id: Iaaad63df54eeb62c3ae91f621922976c5a82d0b6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4407944
Reviewed-by: Jean-Philippe Gravel <jpgravel@chromium.org>
Reviewed-by: Aaron Krajeski <aaronhk@chromium.org>
Code-Coverage: Findit <findit-for-me@appspot.gserviceaccount.com>
Commit-Queue: Justin Novosad <junov@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1136002}
diff --git a/html/canvas/element/fill-and-stroke-styles/2d.gradient.object.update.html b/html/canvas/element/fill-and-stroke-styles/2d.gradient.object.update.html
index b54b110..6f36317 100644
--- a/html/canvas/element/fill-and-stroke-styles/2d.gradient.object.update.html
+++ b/html/canvas/element/fill-and-stroke-styles/2d.gradient.object.update.html
@@ -23,6 +23,7 @@
 g.addColorStop(0, '#f00');
 g.addColorStop(1, '#f00');
 ctx.fillStyle = g;
+ctx.fillRect(0, 0, 100, 50);
 g.addColorStop(0.1, '#0f0');
 g.addColorStop(0.9, '#0f0');
 ctx.fillRect(0, 0, 100, 50);
diff --git a/html/canvas/offscreen/fill-and-stroke-styles/2d.gradient.object.update.html b/html/canvas/offscreen/fill-and-stroke-styles/2d.gradient.object.update.html
index 05f8e74..175c3a2 100644
--- a/html/canvas/offscreen/fill-and-stroke-styles/2d.gradient.object.update.html
+++ b/html/canvas/offscreen/fill-and-stroke-styles/2d.gradient.object.update.html
@@ -24,6 +24,7 @@
 g.addColorStop(0, '#f00');
 g.addColorStop(1, '#f00');
 ctx.fillStyle = g;
+ctx.fillRect(0, 0, 100, 50);
 g.addColorStop(0.1, '#0f0');
 g.addColorStop(0.9, '#0f0');
 ctx.fillRect(0, 0, 100, 50);
diff --git a/html/canvas/offscreen/fill-and-stroke-styles/2d.gradient.object.update.worker.js b/html/canvas/offscreen/fill-and-stroke-styles/2d.gradient.object.update.worker.js
index 5960d0a..7672114 100644
--- a/html/canvas/offscreen/fill-and-stroke-styles/2d.gradient.object.update.worker.js
+++ b/html/canvas/offscreen/fill-and-stroke-styles/2d.gradient.object.update.worker.js
@@ -20,6 +20,7 @@
 g.addColorStop(0, '#f00');
 g.addColorStop(1, '#f00');
 ctx.fillStyle = g;
+ctx.fillRect(0, 0, 100, 50);
 g.addColorStop(0.1, '#0f0');
 g.addColorStop(0.9, '#0f0');
 ctx.fillRect(0, 0, 100, 50);
diff --git a/html/canvas/tools/yaml/element/fill-and-stroke-styles.yaml b/html/canvas/tools/yaml/element/fill-and-stroke-styles.yaml
index fe7b884..9d35dde 100644
--- a/html/canvas/tools/yaml/element/fill-and-stroke-styles.yaml
+++ b/html/canvas/tools/yaml/element/fill-and-stroke-styles.yaml
@@ -452,6 +452,7 @@
     g.addColorStop(0, '#f00');
     g.addColorStop(1, '#f00');
     ctx.fillStyle = g;
+    ctx.fillRect(0, 0, 100, 50);
     g.addColorStop(0.1, '#0f0');
     g.addColorStop(0.9, '#0f0');
     ctx.fillRect(0, 0, 100, 50);
diff --git a/html/canvas/tools/yaml/offscreen/fill-and-stroke-styles.yaml b/html/canvas/tools/yaml/offscreen/fill-and-stroke-styles.yaml
index 9d34588..a0eca74 100644
--- a/html/canvas/tools/yaml/offscreen/fill-and-stroke-styles.yaml
+++ b/html/canvas/tools/yaml/offscreen/fill-and-stroke-styles.yaml
@@ -292,6 +292,7 @@
     g.addColorStop(0, '#f00');
     g.addColorStop(1, '#f00');
     ctx.fillStyle = g;
+    ctx.fillRect(0, 0, 100, 50);
     g.addColorStop(0.1, '#0f0');
     g.addColorStop(0.9, '#0f0');
     ctx.fillRect(0, 0, 100, 50);