tor-browser

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

allocations.js (1264B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 "use strict";
      6 
      7 const { assert } = require("resource://devtools/shared/DevToolsUtils.js");
      8 const { actions } = require("resource://devtools/client/memory/constants.js");
      9 
     10 const handlers = Object.create(null);
     11 
     12 handlers[actions.TOGGLE_RECORD_ALLOCATION_STACKS_START] = function (state) {
     13  assert(
     14    !state.togglingInProgress,
     15    "Changing recording state must not be reentrant."
     16  );
     17 
     18  return {
     19    recording: !state.recording,
     20    togglingInProgress: true,
     21  };
     22 };
     23 
     24 handlers[actions.TOGGLE_RECORD_ALLOCATION_STACKS_END] = function (state) {
     25  assert(
     26    state.togglingInProgress,
     27    "Should not complete changing recording state if we weren't changing " +
     28      "recording state already."
     29  );
     30 
     31  return {
     32    recording: state.recording,
     33    togglingInProgress: false,
     34  };
     35 };
     36 
     37 const DEFAULT_ALLOCATIONS_STATE = {
     38  recording: false,
     39  togglingInProgress: false,
     40 };
     41 
     42 module.exports = function (state = DEFAULT_ALLOCATIONS_STATE, action) {
     43  const handle = handlers[action.type];
     44  if (handle) {
     45    return handle(state, action);
     46  }
     47  return state;
     48 };