context.js (3314B)
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 import { 6 validateNavigateContext, 7 validateContext, 8 validateSelectedFrame, 9 validateBreakpoint, 10 validateSource, 11 validateSourceActor, 12 validateThreadFrames, 13 validateFrame, 14 } from "../../../utils/context"; 15 16 function validateActionContext(getState, action) { 17 if (action.type == "COMMAND" && action.status == "done") { 18 // The thread will have resumed execution since the action was initiated, 19 // so just make sure we haven't navigated. 20 validateNavigateContext(getState(), action.cx); 21 return; 22 } 23 24 // Validate using all available information in the context. 25 validateContext(getState(), action.cx); 26 } 27 28 // Middleware which looks for actions that have a cx property and ignores 29 // them if the context is no longer valid. 30 function context({ getState }) { 31 return next => action => { 32 if ("cx" in action) { 33 validateActionContext(getState, action); 34 } 35 36 // Validate actions specific to a Source object. 37 // This will throw if the source has been removed, 38 // i.e. when the source has been removed from all the threads where it existed. 39 if ("source" in action) { 40 validateSource(getState(), action.source); 41 } 42 43 // Validate actions specific to a Source Actor object. 44 // This will throw if the source actor has been removed, 45 // i.e. when the source actor's thread has been removed. 46 if ("sourceActor" in action) { 47 validateSourceActor(getState(), action.sourceActor); 48 } 49 50 // Similar to sourceActor assertion, but with a distinct attribute name 51 if ("generatedSourceActor" in action) { 52 validateSourceActor(getState(), action.generatedSourceActor); 53 } 54 55 // Validate actions specific to a given breakpoint. 56 // This will throw if the breakpoint's location is obsolete. 57 // i.e. when the related source has been removed. 58 if ("breakpoint" in action) { 59 validateBreakpoint(getState(), action.breakpoint); 60 } 61 62 // Validate actions specific to the currently selected paused frame. 63 // It will throw if we resumed or moved to another frame in the call stack. 64 // 65 // Ignore falsy selectedFrame as sometimes it can be null 66 // for expression actions. 67 if (action.selectedFrame) { 68 validateSelectedFrame(getState(), action.selectedFrame); 69 } 70 71 // Validate actions specific to a given pause location. 72 // This will throw if we resumed or paused in another location. 73 // Compared to selected frame, this would not throw if we moved to another frame in the call stack. 74 if ("thread" in action && "frames" in action) { 75 validateThreadFrames(getState(), action.thread, action.frames); 76 } 77 78 // Validate actions specific to a given frame while being paused. 79 // This will throw if we resumed or paused in another location. 80 // But compared to selected frame, this would not throw if we moved to another frame in the call stack. 81 // This ends up being similar to "pause location" case, but with different arguments. 82 if ("frame" in action) { 83 validateFrame(getState(), action.frame); 84 } 85 86 return next(action); 87 }; 88 } 89 90 export { context };