Bug 841067 - Bind methods before injecting them in FrameWorker. r=markh

Otherwise, they won't get invoked with the proper |this|.
This commit is contained in:
Bobby Holley 2013-02-14 10:40:15 +01:00
Родитель 3fb3394bb8
Коммит 8963699245
1 изменённых файлов: 9 добавлений и 3 удалений

Просмотреть файл

@ -130,12 +130,18 @@ FrameWorker.prototype = {
'setInterval', 'setTimeout', 'XMLHttpRequest',
'MozBlobBuilder', 'FileReader', 'Blob',
'location'];
// Bug 798660 - XHR and WebSocket have issues in a sandbox and need
// to be unwrapped to work
let needsWaive = ['XMLHttpRequest', 'WebSocket'];
// Methods need to be bound with the proper |this|.
let needsBind = ['atob', 'btoa', 'dump', 'setInterval', 'clearInterval',
'setTimeout', 'clearTimeout'];
workerAPI.forEach(function(fn) {
try {
// Bug 798660 - XHR and WebSocket have issues in a sandbox and need
// to be unwrapped to work
if (fn == "XMLHttpRequest" || fn == "WebSocket")
if (needsWaive.indexOf(fn) != -1)
sandbox[fn] = XPCNativeWrapper.unwrap(workerWindow)[fn];
else if (needsBind.indexOf(fn) != -1)
sandbox[fn] = workerWindow[fn].bind(workerWindow);
else
sandbox[fn] = workerWindow[fn];
}