mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1045945 - Initialize the destroy principals callback for workers r=bent
This commit is contained in:
parent
3ef1f75536
commit
ceda575b38
@ -6,23 +6,37 @@
|
||||
#include "Principal.h"
|
||||
|
||||
#include "jsapi.h"
|
||||
#include "mozilla/Assertions.h"
|
||||
|
||||
BEGIN_WORKERS_NAMESPACE
|
||||
|
||||
JSPrincipals*
|
||||
GetWorkerPrincipal()
|
||||
{
|
||||
static Atomic<bool> sInitialized(false);
|
||||
static JSPrincipals sPrincipal;
|
||||
|
||||
bool isInitialized = sInitialized.exchange(true);
|
||||
if (!isInitialized) {
|
||||
sPrincipal.refcount = 1;
|
||||
/*
|
||||
* To make sure the the principals refcount is initialized to one, atomically
|
||||
* increment it on every pass though this function. If we discover this wasn't
|
||||
* the first time, decrement it again. This avoids the need for
|
||||
* synchronization.
|
||||
*/
|
||||
int32_t prevRefcount = sPrincipal.refcount++;
|
||||
if (prevRefcount > 0) {
|
||||
--sPrincipal.refcount;
|
||||
} else {
|
||||
#ifdef DEBUG
|
||||
sPrincipal.debugToken = kJSPrincipalsDebugToken;
|
||||
#endif
|
||||
}
|
||||
|
||||
return &sPrincipal;
|
||||
}
|
||||
|
||||
void
|
||||
DestroyWorkerPrincipals(JSPrincipals* aPrincipals)
|
||||
{
|
||||
MOZ_ASSERT_UNREACHABLE("Worker principals refcount should never fall below one");
|
||||
}
|
||||
|
||||
END_WORKERS_NAMESPACE
|
||||
|
@ -13,6 +13,9 @@ BEGIN_WORKERS_NAMESPACE
|
||||
JSPrincipals*
|
||||
GetWorkerPrincipal();
|
||||
|
||||
void
|
||||
DestroyWorkerPrincipals(JSPrincipals* aPrincipals);
|
||||
|
||||
END_WORKERS_NAMESPACE
|
||||
|
||||
#endif /* mozilla_dom_workers_principal_h__ */
|
||||
|
@ -61,6 +61,7 @@
|
||||
#include "nsThreadManager.h"
|
||||
#endif
|
||||
|
||||
#include "Principal.h"
|
||||
#include "ServiceWorker.h"
|
||||
#include "SharedWorker.h"
|
||||
#include "WorkerPrivate.h"
|
||||
@ -852,6 +853,7 @@ public:
|
||||
WORKER_DEFAULT_NURSERY_SIZE),
|
||||
mWorkerPrivate(aWorkerPrivate)
|
||||
{
|
||||
JS_InitDestroyPrincipalsCallback(Runtime(), DestroyWorkerPrincipals);
|
||||
}
|
||||
|
||||
~WorkerJSRuntime()
|
||||
|
@ -24,6 +24,8 @@ struct JSPrincipals {
|
||||
uint32_t debugToken;
|
||||
#endif
|
||||
|
||||
JSPrincipals() : refcount(0) {}
|
||||
|
||||
void setDebugToken(uint32_t token) {
|
||||
# ifdef JS_DEBUG
|
||||
debugToken = token;
|
||||
|
Loading…
Reference in New Issue
Block a user