tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

JSSettings.h (1819B)


      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/. */
      6 
      7 #ifndef mozilla_dom_workerinternals_JSSettings_h
      8 #define mozilla_dom_workerinternals_JSSettings_h
      9 
     10 #include <stdint.h>
     11 
     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"
     18 
     19 namespace mozilla::dom::workerinternals {
     20 
     21 // Random unique constant to facilitate JSPrincipal debugging
     22 const uint32_t kJSPrincipalsDebugToken = 0x7e2df9d2;
     23 
     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;
     30 
     31    // For the IndexOf call below.
     32    bool operator==(JSGCParamKey k) const { return key == k; }
     33  };
     34 
     35  JS::RealmOptions chromeRealmOptions;
     36  JS::RealmOptions contentRealmOptions;
     37  CopyableTArray<JSGCSetting> gcSettings;
     38  JS::ContextOptions contextOptions;
     39 
     40 #ifdef JS_GC_ZEAL
     41  uint8_t gcZeal = 0;
     42  uint32_t gcZealFrequency = 0;
     43 #endif
     44 
     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;
     51    }
     52    if (gcSettings[index].value != aValue) {
     53      gcSettings[index].value = aValue;
     54      return true;
     55    }
     56    return false;
     57  }
     58 };
     59 
     60 }  // namespace mozilla::dom::workerinternals
     61 
     62 #endif  // mozilla_dom_workerinternals_JSSettings_h