Catch V8 exceptions in CSS paint and layout worklets

CSSPaintDefinition::Paint calls MaybeCreatePaintInstance before it
starts a v8::TryCatch scope. If the constructor of a paint class
throws an exception during synchronous paint, the exception stays on
the V8 isolate. When the worklet scope ends, the exception goes to page
script and can cause a crash.

CSSLayoutDefinition has the same problem. CreateInstance,
Instance::Layout, and Instance::IntrinsicSizes call worklet
constructors and callbacks without a v8::TryCatch scope. If one of
these calls throws an exception during synchronous layout, the
exception stays on the V8 isolate and can cause a crash.

This change prevents the crash:

- In CSSPaintDefinition::Paint, check script_state_->ContextIsValid()
  before ScriptState::Scope. Move v8::TryCatch before
  MaybeCreatePaintInstance so that it catches exceptions from both the
  constructor and paint().
- In CSSLayoutDefinition, add v8::TryCatch with SetVerbose(true) to
  CreateInstance, Instance::Layout, and Instance::IntrinsicSizes. Put
  v8::TryCatch outside V8RunMicrotasksScope so that microtasks do not
  run when a callback throws an exception.
- Add web platform tests and a PaintWorkletTest unit test to check that
  these exceptions do not go to page script.

Bug: 589449226
Change-Id: I6fdd8912277a3ad415f8cbc9f434cd276b4bd27e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/8858448
Commit-Queue: Robert Flack <flackr@chromium.org>
Reviewed-by: Ian Kilpatrick <ikilpatrick@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1754193}
2 files changed
tree: 755e4a1aa89031a04c7958d99902b38e55241ca1
  1. .github/
  2. .well-known/
  3. accelerometer/
  4. accessibility/
  5. accname/
  6. acid/
  7. ai/
  8. ambient-light/
  9. animation-worklet/
  10. annotation-model/
  11. annotation-protocol/
  12. annotation-vocab/
  13. apng/
  14. appmanifest/
  15. aria/
  16. audio-output/
  17. audio-session/
  18. autoplay-policy-detection/
  19. avif/
  20. background-fetch/
  21. background-sync/
  22. badging/
  23. battery-status/
  24. beacon/
  25. bluetooth/
  26. captured-mouse-events/
  27. clear-site-data/
  28. client-hints/
  29. clipboard-apis/
  30. close-watcher/
  31. common/
  32. compat/
  33. compression/
  34. compute-pressure/
  35. conformance-checkers/
  36. connection-allowlist/
  37. console/
  38. contacts/
  39. container-timing/
  40. content-dpr/
  41. content-index/
  42. content-security-policy/
  43. contenteditable/
  44. cookies/
  45. cookiestore/
  46. core-aam/
  47. cors/
  48. cpu-performance/
  49. credential-management/
  50. css/
  51. cssom/
  52. custom-elements/
  53. delegated-ink/
  54. density-size-correction/
  55. deprecation-reporting/
  56. device-bound-session-credentials/
  57. device-memory/
  58. device-posture/
  59. digital-credentials/
  60. direct-sockets/
  61. docs/
  62. document-picture-in-picture/
  63. document-policy/
  64. dom/
  65. domparsing/
  66. domxpath/
  67. dpub-aam/
  68. dpub-aria/
  69. ecmascript/
  70. editing/
  71. element-timing/
  72. encoding/
  73. encoding-detection/
  74. encrypted-media/
  75. entries-api/
  76. event-timing/
  77. eventsource/
  78. eyedropper/
  79. fedcm/
  80. fenced-frame/
  81. fetch/
  82. file-system-access/
  83. FileAPI/
  84. focus/
  85. font-access/
  86. fonts/
  87. forced-colors-mode/
  88. fs/
  89. fullscreen/
  90. gamepad/
  91. generic-sensor/
  92. geolocation/
  93. geolocation-sensor/
  94. gif/
  95. gpc/
  96. graphics-aam/
  97. graphics-aria/
  98. gyroscope/
  99. hr-time/
  100. hsts/
  101. html/
  102. html-aam/
  103. html-longdesc/
  104. html-media-capture/
  105. html-ruby-extensions/
  106. https-upgrades/
  107. idle-detection/
  108. imagebitmap-renderingcontext/
  109. images/
  110. import-maps/
  111. IndexedDB/
  112. inert/
  113. infrastructure/
  114. input-device-capabilities/
  115. input-events/
  116. installedapp/
  117. interfaces/
  118. intersection-observer/
  119. intervention-reporting/
  120. is-input-pending/
  121. jpegxl/
  122. js/
  123. js-self-profiling/
  124. keyboard-lock/
  125. keyboard-map/
  126. largest-contentful-paint/
  127. layout-instability/
  128. loading/
  129. long-animation-frame/
  130. longtask-timing/
  131. magnetometer/
  132. managed/
  133. mathml/
  134. mathml-aam/
  135. measure-memory/
  136. media/
  137. media-capabilities/
  138. media-playback-quality/
  139. media-source/
  140. mediacapture-extensions/
  141. mediacapture-fromelement/
  142. mediacapture-handle/
  143. mediacapture-image/
  144. mediacapture-insertable-streams/
  145. mediacapture-record/
  146. mediacapture-region/
  147. mediacapture-streams/
  148. mediasession/
  149. merchant-validation/
  150. mimesniff/
  151. mixed-content/
  152. mst-content-hint/
  153. nav-tracking-mitigations/
  154. navigation-api/
  155. navigation-timing/
  156. netinfo/
  157. network-error-logging/
  158. notifications/
  159. old-tests/
  160. orientation-event/
  161. orientation-sensor/
  162. page-lifecycle/
  163. page-visibility/
  164. paint-timing/
  165. payment-method-basic-card/
  166. payment-method-id/
  167. payment-method-manifest/
  168. payment-request/
  169. performance-timeline/
  170. periodic-background-sync/
  171. permissions/
  172. permissions-policy/
  173. permissions-request/
  174. permissions-revoke/
  175. picture-in-picture/
  176. png/
  177. pointerevents/
  178. pointerlock/
  179. preload/
  180. presentation-api/
  181. print/
  182. private-click-measurement/
  183. proximity/
  184. push-api/
  185. quirks/
  186. referrer-policy/
  187. remote-playback/
  188. reporting/
  189. requestidlecallback/
  190. resize-observer/
  191. resource-timing/
  192. resources/
  193. sanitizer-api/
  194. savedata/
  195. scheduler/
  196. screen-capture/
  197. screen-details/
  198. screen-orientation/
  199. screen-wake-lock/
  200. scroll-animations/
  201. scroll-performance-timing/
  202. scroll-to-text-fragment/
  203. secure-contexts/
  204. secure-payment-confirmation/
  205. selection/
  206. serial/
  207. server-timing/
  208. service-workers/
  209. shadow-dom/
  210. shape-detection/
  211. signed-exchange/
  212. soft-navigation-heuristics/
  213. speculation-rules/
  214. speech-api/
  215. storage/
  216. storage-access-api/
  217. streams/
  218. subapps/
  219. subresource-integrity/
  220. svg/
  221. svg-aam/
  222. third_party/
  223. timing-entrytypes-registry/
  224. tools/
  225. touch-events/
  226. trust-tokens/
  227. trusted-types/
  228. ua-client-hints/
  229. uievents/
  230. upgrade-insecure-requests/
  231. url/
  232. urlpattern/
  233. user-timing/
  234. vibration/
  235. video-rvfc/
  236. viewport/
  237. viewport-segments/
  238. virtual-keyboard/
  239. visual-viewport/
  240. wai-aria/
  241. wasm/
  242. web-animations/
  243. web-based-payment-handler/
  244. web-bundle/
  245. web-extensions/
  246. web-install/
  247. web-locks/
  248. web-monetization/
  249. web-nfc/
  250. web-otp/
  251. web-share/
  252. webaudio/
  253. webauthn/
  254. webcodecs/
  255. WebCryptoAPI/
  256. webdriver/
  257. webgl/
  258. webgpu/
  259. webhid/
  260. webidl/
  261. webmcp/
  262. webmessaging/
  263. webmidi/
  264. webnn/
  265. webrtc/
  266. webrtc-encoded-transform/
  267. webrtc-extensions/
  268. webrtc-ice/
  269. webrtc-identity/
  270. webrtc-priority/
  271. webrtc-stats/
  272. webrtc-svc/
  273. websockets/
  274. webstorage/
  275. webtransport/
  276. webusb/
  277. webvtt/
  278. webxr/
  279. window-management/
  280. workers/
  281. worklets/
  282. x-frame-options/
  283. xhr/
  284. xml/
  285. .azure-pipelines.yml
  286. .gitattributes
  287. .gitignore
  288. .mailmap
  289. .python-version
  290. .taskcluster.yml
  291. CODE_OF_CONDUCT.md
  292. CODEOWNERS
  293. CONTRIBUTING.md
  294. LICENSE.md
  295. lint.ignore
  296. README.md
  297. wpt
  298. wpt.py
README.md

The web-platform-tests Project

Taskcluster CI Status documentation manifest Python 3

The web-platform-tests Project is a cross-browser test suite for the Web-platform stack. Writing tests in a way that allows them to be run in all browsers gives browser projects confidence that they are shipping software that is compatible with other implementations, and that later implementations will be compatible with their implementations. This in turn gives Web authors/developers confidence that they can actually rely on the Web platform to deliver on the promise of working across browsers and devices without needing extra layers of abstraction to paper over the gaps left by specification editors and implementors.

The most important sources of information and activity are:

  • github.com/web-platform-tests/wpt: the canonical location of the project's source code revision history and the discussion forum for changes to the code
  • web-platform-tests.org: the documentation website; details how to set up the project, how to write tests, how to give and receive peer review, how to serve as an administrator, and more
  • wpt.live: a public deployment of the test suite, allowing anyone to run the tests by visiting from an Internet-enabled browser of their choice
  • wpt.fyi: an archive of test results collected from an array of web browsers on a regular basis
  • Real-time chat room: the wpt:matrix.org matrix channel; includes participants located around the world, but busiest during the European working day.
  • Mailing list: a public and low-traffic discussion list
  • RFCs: a repo for requesting comments on substantial changes that would impact other stakeholders or users; people who work on WPT infra are encouraged to watch the repo.

If you'd like clarification about anything, don't hesitate to ask in the chat room or on the mailing list.

Setting Up the Repo

Clone or otherwise get https://github.com/web-platform-tests/wpt.

Note: because of the frequent creation and deletion of branches in this repo, it is recommended to “prune” stale branches when fetching updates, i.e. use git pull --prune (or git fetch -p && git merge).

Running the Tests

See the documentation website and in particular the system setup for running tests locally.

Command Line Tools

The wpt command provides a frontend to a variety of tools for working with and running web-platform-tests. Some of the most useful commands are:

  • wpt serve - For starting the wpt http server
  • wpt run - For running tests in a browser
  • wpt lint - For running the lint against all tests
  • wpt manifest - For updating or generating a MANIFEST.json test manifest
  • wpt install - For installing the latest release of a browser or webdriver server on the local machine.
  • wpt serve-wave - For starting the wpt http server and the WAVE test runner. For more details on how to use the WAVE test runner see the documentation.

Windows Notes

On Windows wpt commands must be prefixed with python or the path to the python binary (if python is not in your %PATH%).

python wpt [command]

Alternatively, you may also use Bash on Ubuntu on Windows in the Windows 10 Anniversary Update build, then access your windows partition from there to launch wpt commands.

Please make sure git and your text editor do not automatically convert line endings, as it will cause lint errors. For git, please set git config core.autocrlf false in your working tree.

Publication

The master branch is automatically synced to wpt.live and w3c-test.org.

Contributing

Save the Web, Write Some Tests!

Absolutely everyone is welcome to contribute to test development. No test is too small or too simple, especially if it corresponds to something for which you've noted an interoperability bug in a browser.

The way to contribute is just as usual:

  • Fork this repository (and make sure you're still relatively in sync with it if you forked a while ago).
  • Create a branch for your changes: git checkout -b topic.
  • Make your changes.
  • Run ./wpt lint as described above.
  • Commit locally and push that to your repo.
  • Create a pull request based on the above.

AI Policy

Use of LLMs to help author tests is generally acceptable, but every change must be attributable to a human who understands and can take responsibility for the proposed change.

Use of LLMs to participate in discussions is generally not acceptable; any LLM-generated content must either be from a bot account or contained inside a <blockquote> (for short contributions of at most one paragraph) or <details> element.

For full details see the Policy for LLM Use

Issues with web-platform-tests

If you spot an issue with a test and are not comfortable providing a pull request per above to fix it, please file a new issue. Thank you!