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
13 #include "js/ContextOptions.h"
15 #include "mozilla/Maybe.h"
21 namespace workerinternals
{
23 // Random unique constant to facilitate JSPrincipal debugging
24 const uint32_t kJSPrincipalsDebugToken
= 0x7e2df9d2;
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.
48 mozilla::Maybe
<JSGCParamKey
> key
;
51 JSGCSetting() : key(), value(0) {}
54 // There are several settings that we know we need so it makes sense to
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
;
73 uint32_t gcZealFrequency
;
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
;
97 if (!firstEmptySetting
&& setting
.key
.isNothing()) {
98 firstEmptySetting
= &setting
;
104 foundSetting
= firstEmptySetting
;
106 NS_ERROR("Not enough space for this value!");
110 foundSetting
->key
= mozilla::Some(aKey
);
111 foundSetting
->value
= aValue
;
116 foundSetting
->key
.reset();
124 } // namespace workerinternals
126 } // namespace mozilla
128 #endif // mozilla_dom_workerinternals_JSSettings_h