/src/mozilla-central/dom/workers/Principal.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #include "Principal.h" |
8 | | |
9 | | #include "jsapi.h" |
10 | | #include "mozilla/Assertions.h" |
11 | | |
12 | | namespace mozilla { |
13 | | namespace dom { |
14 | | |
15 | | struct WorkerPrincipal final : public JSPrincipals |
16 | | { |
17 | 0 | bool write(JSContext* aCx, JSStructuredCloneWriter* aWriter) override { |
18 | 0 | MOZ_CRASH("WorkerPrincipal::write not implemented"); |
19 | 0 | return false; |
20 | 0 | } |
21 | | }; |
22 | | |
23 | | JSPrincipals* |
24 | | GetWorkerPrincipal() |
25 | 0 | { |
26 | 0 | static WorkerPrincipal sPrincipal; |
27 | 0 |
|
28 | 0 | /* |
29 | 0 | * To make sure the the principals refcount is initialized to one, atomically |
30 | 0 | * increment it on every pass though this function. If we discover this wasn't |
31 | 0 | * the first time, decrement it again. This avoids the need for |
32 | 0 | * synchronization. |
33 | 0 | */ |
34 | 0 | int32_t prevRefcount = sPrincipal.refcount++; |
35 | 0 | if (prevRefcount > 0) { |
36 | 0 | --sPrincipal.refcount; |
37 | 0 | } else { |
38 | | #ifdef DEBUG |
39 | | sPrincipal.debugToken = workerinternals::kJSPrincipalsDebugToken; |
40 | | #endif |
41 | | } |
42 | 0 |
|
43 | 0 | return &sPrincipal; |
44 | 0 | } |
45 | | |
46 | | void |
47 | | DestroyWorkerPrincipals(JSPrincipals* aPrincipals) |
48 | 0 | { |
49 | 0 | MOZ_ASSERT_UNREACHABLE("Worker principals refcount should never fall below one"); |
50 | 0 | } |
51 | | |
52 | | } // dom namespace |
53 | | } // mozilla namespace |