Backed out changeset b09d48d2b473 (bug 1655101) for causing mochitest webgl failures...
[gecko.git] / dom / workers / JSSettings.h
blobaf2247a8479ad3d033c0bc9685baaf4d0efa7509
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 file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_workerinternals_JSSettings_h
8 #define mozilla_dom_workerinternals_JSSettings_h
10 #include <stdint.h>
12 #include "js/ContextOptions.h"
13 #include "js/GCAPI.h"
14 #include "js/RealmOptions.h"
15 #include "mozilla/Maybe.h"
16 #include "nsString.h"
17 #include "nsTArray.h"
19 namespace mozilla::dom::workerinternals {
21 // Random unique constant to facilitate JSPrincipal debugging
22 const uint32_t kJSPrincipalsDebugToken = 0x7e2df9d2;
24 struct JSSettings {
25 struct JSGCSetting {
26 JSGCParamKey key;
27 // Nothing() represents the default value, the result of calling
28 // JS_ResetGCParameter.
29 Maybe<uint32_t> value;
31 // For the IndexOf call below.
32 bool operator==(JSGCParamKey k) const { return key == k; }
35 JS::RealmOptions chromeRealmOptions;
36 JS::RealmOptions contentRealmOptions;
37 CopyableTArray<JSGCSetting> gcSettings;
38 JS::ContextOptions contextOptions;
40 #ifdef JS_GC_ZEAL
41 uint8_t gcZeal = 0;
42 uint32_t gcZealFrequency = 0;
43 #endif
45 // Returns whether there was a change in the setting.
46 bool ApplyGCSetting(JSGCParamKey aKey, Maybe<uint32_t> aValue) {
47 size_t index = gcSettings.IndexOf(aKey);
48 if (index == gcSettings.NoIndex) {
49 gcSettings.AppendElement(JSGCSetting{aKey, aValue});
50 return true;
52 if (gcSettings[index].value != aValue) {
53 gcSettings[index].value = aValue;
54 return true;
56 return false;
60 } // namespace mozilla::dom::workerinternals
62 #endif // mozilla_dom_workerinternals_JSSettings_h