Bug 1550519 - Show a translucent parent highlight when a subgrid is highlighted....
[gecko.git] / dom / workers / JSSettings.h
blob7fe0da9c7750df77f7c91173ce975a689386549d
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 "jsapi.h"
13 #include "js/ContextOptions.h"
14 #include "js/GCAPI.h"
15 #include "mozilla/Maybe.h"
16 #include "nsString.h"
17 #include "nsTArray.h"
19 namespace mozilla {
20 namespace dom {
21 namespace workerinternals {
23 // Random unique constant to facilitate JSPrincipal debugging
24 const uint32_t kJSPrincipalsDebugToken = 0x7e2df9d2;
26 struct JSSettings {
27 enum {
28 // All the GC parameters that we support.
29 JSSettings_JSGC_MAX_BYTES = 0,
30 JSSettings_JSGC_MAX_MALLOC_BYTES,
31 JSSettings_JSGC_HIGH_FREQUENCY_TIME_LIMIT,
32 JSSettings_JSGC_LOW_FREQUENCY_HEAP_GROWTH,
33 JSSettings_JSGC_HIGH_FREQUENCY_HEAP_GROWTH_MIN,
34 JSSettings_JSGC_HIGH_FREQUENCY_HEAP_GROWTH_MAX,
35 JSSettings_JSGC_HIGH_FREQUENCY_LOW_LIMIT,
36 JSSettings_JSGC_HIGH_FREQUENCY_HIGH_LIMIT,
37 JSSettings_JSGC_ALLOCATION_THRESHOLD,
38 JSSettings_JSGC_SLICE_TIME_BUDGET,
39 JSSettings_JSGC_DYNAMIC_HEAP_GROWTH,
40 JSSettings_JSGC_DYNAMIC_MARK_SLICE,
41 // JSGC_MODE not supported
43 // This must be last so that we get an accurate count.
44 kGCSettingsArraySize
47 struct JSGCSetting {
48 mozilla::Maybe<JSGCParamKey> key;
49 uint32_t value;
51 JSGCSetting() : key(), value(0) {}
54 // There are several settings that we know we need so it makes sense to
55 // preallocate here.
56 typedef JSGCSetting JSGCSettingsArray[kGCSettingsArraySize];
58 // Settings that change based on chrome/content context.
59 struct JSContentChromeSettings {
60 JS::RealmOptions realmOptions;
61 int32_t maxScriptRuntime;
63 JSContentChromeSettings() : realmOptions(), maxScriptRuntime(0) {}
66 JSContentChromeSettings chrome;
67 JSContentChromeSettings content;
68 JSGCSettingsArray gcSettings;
69 JS::ContextOptions contextOptions;
71 #ifdef JS_GC_ZEAL
72 uint8_t gcZeal;
73 uint32_t gcZealFrequency;
74 #endif
76 JSSettings()
77 #ifdef JS_GC_ZEAL
78 : gcZeal(0),
79 gcZealFrequency(0)
80 #endif
82 for (uint32_t index = 0; index < ArrayLength(gcSettings); index++) {
83 new (gcSettings + index) JSGCSetting();
87 bool ApplyGCSetting(JSGCParamKey aKey, uint32_t aValue) {
88 JSSettings::JSGCSetting* firstEmptySetting = nullptr;
89 JSSettings::JSGCSetting* foundSetting = nullptr;
91 for (uint32_t index = 0; index < ArrayLength(gcSettings); index++) {
92 JSSettings::JSGCSetting& setting = gcSettings[index];
93 if (setting.key.isSome() && *setting.key == aKey) {
94 foundSetting = &setting;
95 break;
97 if (!firstEmptySetting && setting.key.isNothing()) {
98 firstEmptySetting = &setting;
102 if (aValue) {
103 if (!foundSetting) {
104 foundSetting = firstEmptySetting;
105 if (!foundSetting) {
106 NS_ERROR("Not enough space for this value!");
107 return false;
110 foundSetting->key = mozilla::Some(aKey);
111 foundSetting->value = aValue;
112 return true;
115 if (foundSetting) {
116 foundSetting->key.reset();
117 return true;
120 return false;
124 } // namespace workerinternals
125 } // namespace dom
126 } // namespace mozilla
128 #endif // mozilla_dom_workerinternals_JSSettings_h