aboutsummaryrefslogtreecommitdiffstats
path: root/tests/html/worker
diff options
context:
space:
mode:
authorJoe Wilm <jdwilm@gmail.com>2015-04-25 21:33:25 -0700
committerKeith Yeung <kungfukeith11@gmail.com>2016-04-07 18:54:32 -0400
commit229b1763217cf980d70cd9bf45c1469850b25dff (patch)
tree61146a81bb0df70e7ad09ef3c6f25968815dd846 /tests/html/worker
parentdc3f199043d4cf74b83f33c94960e199c0cfa7b3 (diff)
downloadservo-229b1763217cf980d70cd9bf45c1469850b25dff.tar.gz
servo-229b1763217cf980d70cd9bf45c1469850b25dff.zip
Implement Worker#terminate() (fixes #4427).
Adds support for terminating DOM workers. A closing flag was added to WorkerGlobalScope per the spec.
Diffstat (limited to 'tests/html/worker')
-rw-r--r--tests/html/worker/worker_post_block.js9
-rw-r--r--tests/html/worker/worker_post_interval.js6
-rw-r--r--tests/html/worker/worker_terminate.html48
3 files changed, 63 insertions, 0 deletions
diff --git a/tests/html/worker/worker_post_block.js b/tests/html/worker/worker_post_block.js
new file mode 100644
index 00000000000..a9837b71afd
--- /dev/null
+++ b/tests/html/worker/worker_post_block.js
@@ -0,0 +1,9 @@
+var prev = Date.now()
+for (var i=0; true; i++) {
+
+ if (i % 100000000 == 0) {
+ var now = Date.now();
+ postMessage(now - prev);
+ prev = now;
+ }
+}
diff --git a/tests/html/worker/worker_post_interval.js b/tests/html/worker/worker_post_interval.js
new file mode 100644
index 00000000000..ce1126136fa
--- /dev/null
+++ b/tests/html/worker/worker_post_interval.js
@@ -0,0 +1,6 @@
+var prev = Date.now()
+setInterval(function () {
+ var now = Date.now();
+ postMessage(now - prev);
+ prev = now;
+}, 500);
diff --git a/tests/html/worker/worker_terminate.html b/tests/html/worker/worker_terminate.html
new file mode 100644
index 00000000000..d6c40a5c69d
--- /dev/null
+++ b/tests/html/worker/worker_terminate.html
@@ -0,0 +1,48 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <title>Worker Test</title>
+</head>
+<body>
+<script>
+var workerPath = (function () {
+ var workerType;
+ switch (window.location.search.match(/worker=(\w+)/)[1]) {
+ case 'block':
+ workerType = 'block';
+ break;
+ default:
+ workerType = 'interval';
+ break;
+ }
+
+ return './worker_post_' + workerType + '.js';
+})();
+
+function startWorker() {
+ window.w = new Worker(workerPath);
+ w.onmessage = function(m) {
+ var p = document.createElement('p');
+ p.innerHTML = JSON.stringify(m.data);
+ document.body.appendChild(p);
+ };
+
+ var ps = document.getElementsByTagName('p');
+ while (ps.length) {
+ document.body.removeChild(ps[0]);
+ }
+}
+
+function stopWorker() {
+ if (w) {
+ w.terminate();
+ }
+
+ window.w = null;
+}
+</script>
+ <button onclick="startWorker()">Start Worker</button>
+ <button onclick="stopWorker()">Stop Worker</button>
+</body>
+</html>