mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1022773 - Return value rooting for workers, r=bent
--HG-- extra : rebase_source : 5793c693fb00a71f203202beed491de8ef492093
This commit is contained in:
parent
abace8aef1
commit
36ca527ad7
@ -117,34 +117,37 @@ GetDataStoresStructuredCloneCallbacksRead(JSContext* aCx,
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
nsRefPtr<WorkerDataStore> workerStore =
|
||||
new WorkerDataStore(workerPrivate->GlobalScope());
|
||||
nsMainThreadPtrHandle<DataStore> backingStore = dataStoreholder;
|
||||
// Protect workerStoreObj from moving GC during ~nsRefPtr.
|
||||
JS::Rooted<JSObject*> workerStoreObj(aCx, nullptr);
|
||||
{
|
||||
nsRefPtr<WorkerDataStore> workerStore =
|
||||
new WorkerDataStore(workerPrivate->GlobalScope());
|
||||
nsMainThreadPtrHandle<DataStore> backingStore = dataStoreholder;
|
||||
|
||||
// When we're on the worker thread, prepare a DataStoreChangeEventProxy.
|
||||
nsRefPtr<DataStoreChangeEventProxy> eventProxy =
|
||||
new DataStoreChangeEventProxy(workerPrivate, workerStore);
|
||||
// When we're on the worker thread, prepare a DataStoreChangeEventProxy.
|
||||
nsRefPtr<DataStoreChangeEventProxy> eventProxy =
|
||||
new DataStoreChangeEventProxy(workerPrivate, workerStore);
|
||||
|
||||
// Add the DataStoreChangeEventProxy as an event listener on the main thread.
|
||||
nsRefPtr<DataStoreAddEventListenerRunnable> runnable =
|
||||
new DataStoreAddEventListenerRunnable(workerPrivate,
|
||||
backingStore,
|
||||
eventProxy);
|
||||
runnable->Dispatch(aCx);
|
||||
// Add the DataStoreChangeEventProxy as an event listener on the main thread.
|
||||
nsRefPtr<DataStoreAddEventListenerRunnable> runnable =
|
||||
new DataStoreAddEventListenerRunnable(workerPrivate,
|
||||
backingStore,
|
||||
eventProxy);
|
||||
runnable->Dispatch(aCx);
|
||||
|
||||
// Point WorkerDataStore to DataStore.
|
||||
workerStore->SetBackingDataStore(backingStore);
|
||||
// Point WorkerDataStore to DataStore.
|
||||
workerStore->SetBackingDataStore(backingStore);
|
||||
|
||||
JS::Rooted<JSObject*> global(aCx, JS::CurrentGlobalOrNull(aCx));
|
||||
if (!global) {
|
||||
MOZ_ASSERT(false, "cannot get global!");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
JS::Rooted<JSObject*> workerStoreObj(aCx, workerStore->WrapObject(aCx));
|
||||
if (!JS_WrapObject(aCx, &workerStoreObj)) {
|
||||
MOZ_ASSERT(false, "cannot wrap object for workerStoreObj!");
|
||||
return nullptr;
|
||||
JS::Rooted<JSObject*> global(aCx, JS::CurrentGlobalOrNull(aCx));
|
||||
if (!global) {
|
||||
MOZ_ASSERT(false, "cannot get global!");
|
||||
} else {
|
||||
workerStoreObj = workerStore->WrapObject(aCx);
|
||||
if (!JS_WrapObject(aCx, &workerStoreObj)) {
|
||||
MOZ_ASSERT(false, "cannot wrap object for workerStoreObj!");
|
||||
workerStoreObj = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return workerStoreObj;
|
||||
|
@ -300,6 +300,8 @@ struct WorkerStructuredCloneCallbacks
|
||||
Read(JSContext* aCx, JSStructuredCloneReader* aReader, uint32_t aTag,
|
||||
uint32_t aData, void* aClosure)
|
||||
{
|
||||
JS::Rooted<JSObject*> result(aCx);
|
||||
|
||||
// See if object is a nsIDOMFile pointer.
|
||||
if (aTag == DOMWORKER_SCTAG_FILE) {
|
||||
MOZ_ASSERT(!aData);
|
||||
@ -318,9 +320,12 @@ struct WorkerStructuredCloneCallbacks
|
||||
}
|
||||
#endif
|
||||
|
||||
nsRefPtr<DOMFile> file = new DOMFile(fileImpl);
|
||||
JSObject* jsFile = file::CreateFile(aCx, file);
|
||||
return jsFile;
|
||||
{
|
||||
// New scope to protect |result| from a moving GC during ~nsRefPtr.
|
||||
nsRefPtr<DOMFile> file = new DOMFile(fileImpl);
|
||||
result = file::CreateFile(aCx, file);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
// See if object is a nsIDOMBlob pointer.
|
||||
@ -341,9 +346,12 @@ struct WorkerStructuredCloneCallbacks
|
||||
}
|
||||
#endif
|
||||
|
||||
nsRefPtr<DOMFile> blob = new DOMFile(blobImpl);
|
||||
JSObject* jsBlob = file::CreateBlob(aCx, blob);
|
||||
return jsBlob;
|
||||
{
|
||||
// New scope to protect |result| from a moving GC during ~nsRefPtr.
|
||||
nsRefPtr<DOMFile> blob = new DOMFile(blobImpl);
|
||||
result = file::CreateBlob(aCx, blob);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
// See if the object is an ImageData.
|
||||
@ -360,11 +368,14 @@ struct WorkerStructuredCloneCallbacks
|
||||
}
|
||||
MOZ_ASSERT(dataArray.isObject());
|
||||
|
||||
// Construct the ImageData.
|
||||
nsRefPtr<ImageData> imageData = new ImageData(width, height,
|
||||
dataArray.toObject());
|
||||
// Wrap it in a JS::Value.
|
||||
return imageData->WrapObject(aCx);
|
||||
{
|
||||
// Construct the ImageData.
|
||||
nsRefPtr<ImageData> imageData = new ImageData(width, height,
|
||||
dataArray.toObject());
|
||||
// Wrap it in a JS::Value, protected from a moving GC during ~nsRefPtr.
|
||||
result = imageData->WrapObject(aCx);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Error(aCx, 0);
|
||||
|
Loading…
Reference in New Issue
Block a user