Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(316)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/common/Worker.js

Issue 2239753003: DevTools: Make sure worker instance is not collected. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressing comment. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2014 Google Inc. All rights reserved. 2 * Copyright (C) 2014 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 42
43 var callback; 43 var callback;
44 /** @type {!Promise<!Worker|!SharedWorker>} */ 44 /** @type {!Promise<!Worker|!SharedWorker>} */
45 this._workerPromise = new Promise(fulfill => callback = fulfill); 45 this._workerPromise = new Promise(fulfill => callback = fulfill);
46 46
47 /** @type {!Worker|!SharedWorker} */ 47 /** @type {!Worker|!SharedWorker} */
48 var worker; 48 var worker;
49 var isSharedWorker = !!workerName; 49 var isSharedWorker = !!workerName;
50 if (isSharedWorker) { 50 if (isSharedWorker) {
51 worker = new SharedWorker(url, workerName); 51 worker = new SharedWorker(url, workerName);
52 worker.port.onmessage = onMessage; 52 worker.port.onmessage = onMessage.bind(this);
53 } else { 53 } else {
54 worker = new Worker(url); 54 worker = new Worker(url);
55 worker.onmessage = onMessage; 55 worker.onmessage = onMessage.bind(this);
56 } 56 }
57 // Hold a reference to worker until the promise is resolved.
58 // Otherwise the worker could be GCed.
59 this._workerProtect = worker;
57 60
58 /** 61 /**
59 * @param {!Event} event 62 * @param {!Event} event
63 * @this {WebInspector.Worker}
60 */ 64 */
61 function onMessage(event) 65 function onMessage(event)
62 { 66 {
63 console.assert(event.data === "workerReady"); 67 console.assert(event.data === "workerReady");
64 if (isSharedWorker) 68 if (isSharedWorker)
65 worker.port.onmessage = null; 69 worker.port.onmessage = null;
66 else 70 else
67 worker.onmessage = null; 71 worker.onmessage = null;
68 callback(worker); 72 callback(worker);
73 this._workerProtect = null;
69 } 74 }
70 } 75 }
71 76
72 WebInspector.Worker.prototype = { 77 WebInspector.Worker.prototype = {
73 /** 78 /**
74 * @param {*} message 79 * @param {*} message
75 */ 80 */
76 postMessage: function(message) 81 postMessage: function(message)
77 { 82 {
78 this._workerPromise.then(postToWorker.bind(this)); 83 this._workerPromise.then(postToWorker.bind(this));
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 */ 143 */
139 function setOnError(worker) 144 function setOnError(worker)
140 { 145 {
141 if (worker.port) 146 if (worker.port)
142 worker.port.onerror = listener; 147 worker.port.onerror = listener;
143 else 148 else
144 worker.onerror = listener; 149 worker.onerror = listener;
145 } 150 }
146 } 151 }
147 } 152 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698