Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/actions/pause.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,17 @@ export function resumed() {
export function paused(pauseInfo: Pause) {
return async function({ dispatch, getState, client, sourceMaps }: ThunkArgs) {
let { frames, why, loadedObjects } = pauseInfo;

frames = await updateFrameLocations(frames, sourceMaps);
const frame = frames[0];

const scopes = await client.getFrameScopes(frame);

dispatch({
type: "PAUSED",
pauseInfo: { why, frame, frames },
frames: frames,
scopes,
selectedFrameId: frame.id,
loadedObjects: loadedObjects || []
});
Expand Down Expand Up @@ -184,14 +188,18 @@ export function breakOnNext() {
* @static
*/
export function selectFrame(frame: Frame) {
return ({ dispatch }: ThunkArgs) => {
return async ({ dispatch, client }: ThunkArgs) => {
dispatch(evaluateExpressions(frame.id));
dispatch(
selectSource(frame.location.sourceId, { line: frame.location.line })
);

const scopes = await client.getFrameScopes(frame);

dispatch({
type: "SELECT_FRAME",
frame
frame,
scopes
});
};
}
Expand Down
3 changes: 3 additions & 0 deletions src/actions/tests/ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ const threadClient = {
})
);
},
getFrameScopes: function() {
return Promise.resolve({});
},
evaluate: function(expression) {
return new Promise((resolve, reject) =>
resolve({
Expand Down
4 changes: 3 additions & 1 deletion src/actions/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {
GeneratedLocation,
SourceText,
Frame,
Scope,
Why
} from "debugger-html";

Expand Down Expand Up @@ -167,6 +168,7 @@ type PauseAction =
frame: Frame,
isInterrupted?: boolean
},
scopes: Scope[],
frames: Frame[],
selectedFrameId: string,
loadedObjects: LoadedObject[]
Expand All @@ -177,7 +179,7 @@ type PauseAction =
shouldIgnoreCaughtExceptions: boolean
}
| { type: "COMMAND", value: void }
| { type: "SELECT_FRAME", frame: Frame }
| { type: "SELECT_FRAME", frame: Frame, scopes: Scope[] }
| {
type: "LOAD_OBJECT_PROPERTIES",
objectId: string,
Expand Down
10 changes: 10 additions & 0 deletions src/client/firefox/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import type {
BreakpointId,
BreakpointResult,
Frame,
FrameId,
ActorId,
Location,
Expand Down Expand Up @@ -193,6 +194,14 @@ function getProperties(grip: Grip): Promise<*> {
});
}

async function getFrameScopes(frame: Frame): Promise<*> {
if (frame.scope) {
return frame.scope;
}

return threadClient.getEnvironment(frame.id);
}

function pauseOnExceptions(
shouldPauseOnExceptions: boolean,
shouldIgnoreCaughtExceptions: boolean
Expand Down Expand Up @@ -260,6 +269,7 @@ const clientCommands = {
navigate,
reload,
getProperties,
getFrameScopes,
pauseOnExceptions,
prettyPrint,
disablePrettyPrint,
Expand Down
13 changes: 5 additions & 8 deletions src/client/firefox/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function createFrame(frame: FramePacket): Frame {
};
}

function createSource(source: SourcePayload): Source {
export function createSource(source: SourcePayload): Source {
return {
id: source.actor,
url: source.url,
Expand All @@ -41,7 +41,10 @@ function createSource(source: SourcePayload): Source {
};
}

function createPause(packet: PausedPacket, response: FramesResponse): any {
export function createPause(
packet: PausedPacket,
response: FramesResponse
): any {
// NOTE: useful when the debugger is already paused
const frame = packet.frame || response.frames[0];

Expand All @@ -50,9 +53,3 @@ function createPause(packet: PausedPacket, response: FramesResponse): any {
frames: response.frames.map(createFrame)
});
}

module.exports = {
createFrame,
createSource,
createPause
};
1 change: 1 addition & 0 deletions src/client/firefox/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ export type ThreadClient = {
interrupt: () => Promise<*>,
eventListeners: () => Promise<*>,
getFrames: (number, number) => FramesResponse,
getEnvironment: () => Promise<*>,
addListener: (string, Function) => void,
getSources: () => Promise<SourcesPacket>,
reconfigure: ({ observeAsmJS: boolean }) => Promise<*>,
Expand Down
2 changes: 1 addition & 1 deletion src/components/Editor/Tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class SourceTabs extends PureComponent {
selectedSource: SourceRecord,
selectSource: (string, ?Object) => any,
closeTab: string => any,
closeTabs: List<string> => any,
closeTabs: (List<string>) => any,
toggleProjectSearch: () => any,
togglePrettyPrint: string => any,
togglePaneCollapse: () => any,
Expand Down
3 changes: 2 additions & 1 deletion src/components/Editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,8 @@ Editor.contextTypes = {

const expressionsSel = state => state.expressions.expressions;
const getExpressionSel = createSelector(expressionsSel, expressions => input =>
expressions.find(exp => exp.input == input));
expressions.find(exp => exp.input == input)
);

export default connect(
state => {
Expand Down
37 changes: 27 additions & 10 deletions src/components/SecondaryPanes/Scopes.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import { DOM as dom, PropTypes, PureComponent, createFactory } from "react";
import { bindActionCreators } from "redux";
import { connect } from "react-redux";
import actions from "../../actions";
import { getSelectedFrame, getLoadedObjects, getPause } from "../../selectors";
import {
getSelectedFrame,
getLoadedObjects,
getFrameScopes,
getPause
} from "../../selectors";
import { getScopes } from "../../utils/scopes";

import _ObjectInspector from "../shared/ObjectInspector";
Expand All @@ -21,12 +26,12 @@ class Scopes extends PureComponent {
};

constructor(props, ...args) {
const { pauseInfo, selectedFrame } = props;
const { pauseInfo, selectedFrame, frameScopes } = props;

super(props, ...args);

this.state = {
scopes: getScopes(pauseInfo, selectedFrame)
scopes: getScopes(pauseInfo, selectedFrame, frameScopes)
};
}

Expand All @@ -37,7 +42,11 @@ class Scopes extends PureComponent {

if (pauseInfoChanged || selectedFrameChange) {
this.setState({
scopes: getScopes(nextProps.pauseInfo, nextProps.selectedFrame)
scopes: getScopes(
nextProps.pauseInfo,
nextProps.selectedFrame,
nextProps.frameScopes
)
});
}
}
Expand Down Expand Up @@ -66,16 +75,24 @@ Scopes.propTypes = {
pauseInfo: PropTypes.object,
loadedObjects: PropTypes.object,
loadObjectProperties: PropTypes.func,
selectedFrame: PropTypes.object
selectedFrame: PropTypes.object,
frameScopes: PropTypes.object
};

Scopes.displayName = "Scopes";

export default connect(
state => ({
pauseInfo: getPause(state),
selectedFrame: getSelectedFrame(state),
loadedObjects: getLoadedObjects(state)
}),
state => {
const selectedFrame = getSelectedFrame(state);
const frameScopes = selectedFrame
? getFrameScopes(state, selectedFrame.id)
: null;
return {
selectedFrame,
pauseInfo: getPause(state),
frameScopes: frameScopes,
loadedObjects: getLoadedObjects(state)
};
},
dispatch => bindActionCreators(actions, dispatch)
)(Scopes);
25 changes: 23 additions & 2 deletions src/reducers/pause.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type PauseState = {
pause: ?any,
isWaitingOnBreak: boolean,
frames: ?(any[]),
frameScopes: any,
selectedFrameId: ?string,
loadedObjects: Object,
shouldPauseOnExceptions: boolean,
Expand All @@ -24,6 +25,7 @@ export const State = (): PauseState => ({
isWaitingOnBreak: false,
frames: undefined,
selectedFrameId: undefined,
frameScopes: {},
loadedObjects: {},
shouldPauseOnExceptions: prefs.pauseOnExceptions,
shouldIgnoreCaughtExceptions: prefs.ignoreCaughtExceptions,
Expand All @@ -33,9 +35,17 @@ export const State = (): PauseState => ({
function update(state: PauseState = State(), action: Action): PauseState {
switch (action.type) {
case "PAUSED": {
const { selectedFrameId, frames, loadedObjects, pauseInfo } = action;
const {
selectedFrameId,
frames,
scopes,
loadedObjects,
pauseInfo
} = action;
pauseInfo.isInterrupted = pauseInfo.why.type === "interrupted";

const frameScopes = { [selectedFrameId]: scopes };

// turn this into an object keyed by object id
let objectMap = {};
loadedObjects.forEach(obj => {
Expand All @@ -47,6 +57,7 @@ function update(state: PauseState = State(), action: Action): PauseState {
pause: pauseInfo,
selectedFrameId,
frames,
frameScopes,
loadedObjects: objectMap
});
}
Expand Down Expand Up @@ -75,7 +86,13 @@ function update(state: PauseState = State(), action: Action): PauseState {
return Object.assign({}, state, { isWaitingOnBreak: true });

case "SELECT_FRAME":
return Object.assign({}, state, { selectedFrameId: action.frame.id });
const { frame, scopes } = action;
const selectedFrameId = frame.id;
return {
...state,
frameScopes: { ...state.frameScopes, [selectedFrameId]: scopes },
selectedFrameId
};

case "LOAD_OBJECT_PROPERTIES":
if (action.status === "start") {
Expand Down Expand Up @@ -172,6 +189,10 @@ export function getFrames(state: OuterState) {
return state.pause.frames;
}

export function getFrameScopes(state: OuterState, frameId: string) {
return state.pause.frameScopes[frameId];
}

const getSelectedFrameId = createSelector(getPauseState, pauseWrapper => {
return pauseWrapper.selectedFrameId;
});
Expand Down
1 change: 1 addition & 0 deletions src/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ module.exports = {
getChromeScopes: pause.getChromeScopes,
getLoadedObjects: pause.getLoadedObjects,
getLoadedObject: pause.getLoadedObject,
getFrameScopes: pause.getFrameScopes,
getObjectProperties: pause.getObjectProperties,
getIsWaitingOnBreak: pause.getIsWaitingOnBreak,
getShouldPauseOnExceptions: pause.getShouldPauseOnExceptions,
Expand Down
3 changes: 2 additions & 1 deletion src/utils/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ const displayNameMap = {
},
React: {
// eslint-disable-next-line max-len
"ReactCompositeComponent._renderValidatedComponentWithoutOwnerOrContext/renderedElement<": "Render"
"ReactCompositeComponent._renderValidatedComponentWithoutOwnerOrContext/renderedElement<":
"Render"
},
Webpack: {
// eslint-disable-next-line camelcase
Expand Down
3 changes: 2 additions & 1 deletion src/utils/parser/tests/fixtures/var.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var foo = 1;
let bar = 2;
const baz = 3;
const a = 4, b = 5;
const a = 4,
b = 5;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const b = 5; would be easier to read

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed, it's prettier tho

9 changes: 6 additions & 3 deletions src/utils/scopes.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import toPairs from "lodash/toPairs";
const get = require("lodash/get");

import type { Frame, Pause } from "debugger-html";
import type { Frame, Pause, Scope } from "debugger-html";

type ScopeData = {
name: string,
Expand Down Expand Up @@ -69,13 +69,16 @@ function getThisVariable(frame: any, path: string) {

export function getScopes(
pauseInfo: Pause,
selectedFrame: Frame
selectedFrame: Frame,
selectedScope: ?Scope
): ?(ScopeData[]) {
if (!pauseInfo || !selectedFrame) {
return null;
}

let selectedScope = selectedFrame.scope;
// NOTE: it's possible that we're inspecting an old server
// that does not support getting frame scopes directly
selectedScope = selectedScope || selectedFrame.scope;

if (!selectedScope) {
return null;
Expand Down
3 changes: 2 additions & 1 deletion src/utils/tests/scopes.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ const errorGrip = {
kind: "Error",
name: "Error",
message: "blah",
stack: "onclick@http://localhost:8000/examples/doc-return-values.html:1:18\n",
stack:
"onclick@http://localhost:8000/examples/doc-return-values.html:1:18\n",
fileName: "http://localhost:8000/examples/doc-return-values.html",
lineNumber: 1,
columnNumber: 18
Expand Down