Skip to content

Instantly share code, notes, and snippets.

@jasonLaster
Last active December 4, 2022 02:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasonLaster/03b9dcf7910fbd6e5d7c998f1f471577 to your computer and use it in GitHub Desktop.
Save jasonLaster/03b9dcf7910fbd6e5d7c998f1f471577 to your computer and use it in GitHub Desktop.

User

When will this function return null?


function CurrentLineHighlightSuspends({
  lineNumber,
  sourceId
}) {
  const client = useContext(ReplayClientContext);
  const {
    0: sourceSearchState
  } = useContext(SourceSearchContext);
  const {
    selectedPauseAndFrameId,
    previewLocation
  } = useContext(SelectedFrameContext);
  const {
    currentSearchResultLocation
  } = useContext(SourcesContext);
  if (previewLocation?.sourceId === sourceId) {
    if (previewLocation.line === lineNumber) {
      return /*#__PURE__*/ _jsx("div", {
        className: styles.CurrentExecutionPoint,
        "data-test-name": "CurrentExecutionPointLineHighlight"
      });
    }
    return null;
  }
  const frameId = selectedPauseAndFrameId?.frameId || null;
  const pauseId = selectedPauseAndFrameId?.pauseId || null;
  if (pauseId !== null && frameId !== null) {
    const frames = getFramesSuspense(client, pauseId);
    if (frames) {
      const correspondingSourceIds = client.getCorrespondingSourceIds(sourceId);
      const selectedFrame = frames.find(frame => frame.frameId === frameId);
      if (selectedFrame) {
        if (selectedFrame.location.find(location => {
            if (correspondingSourceIds.includes(location.sourceId)) {
              const correspondingLocations = client.getCorrespondingLocations(
                location);
              return correspondingLocations.findIndex(correspondingLocation =>
                correspondingLocation.line === lineNumber &&
                correspondingLocation.sourceId === sourceId) >= 0;
            }
          })) {
          return /*#__PURE__*/ _jsx("div", {
            className: styles.CurrentExecutionPoint,
            "data-test-name": "CurrentExecutionPointLineHighlight"
          });
        }
      }
    }
  }
  if (currentSearchResultLocation != null && currentSearchResultLocation
    .sourceId === sourceSearchState.currentScopeId &&
    currentSearchResultLocation.line === lineNumber) {
    return /*#__PURE__*/ _jsx("div", {
      className: styles.CurrentSearchResult,
      "data-test-name": "CurrentSearchResultHighlight"
    });
  }
  return null;
}

Bot

It looks like this function will return null when any of the following conditions are met:

  • If the previewLocation object is present and its sourceId property is equal to the sourceId parameter, but its line property is not equal to the lineNumber parameter.
  • If the selectedPauseAndFrameId object is present, but either its frameId or pauseId property is null.
  • If the selectedPauseAndFrameId object is present, pauseId is not null, frameId is not null, and getFramesSuspense(client, pauseId) returns a value, but no frame in the returned array has an id property that is equal to the frameId property of the selectedPauseAndFrameId object.
  • If the currentSearchResultLocation object is present, its sourceId property is equal to the currentScopeId property of the sourceSearchState object, but its line property is not equal to the lineNumber parameter.
    It is also worth noting that this function will only return null in cases where one of the above conditions is met and none of the other return statements in the function are executed.

User

Thanks. The previewLocation is null

Bot

In that case, the function will only return null if either of the following conditions are met:

  • If the selectedPauseAndFrameId object is present, but either its frameId or pauseId property is null.
  • If the selectedPauseAndFrameId object is present, pauseId is not null, frameId is not null, and getFramesSuspense(client, pauseId) returns a value, but no frame in the returned array has an id property that is equal to the frameId property of the selectedPauseAndFrameId object.
  • If the currentSearchResultLocation object is null, then it will not affect whether the function returns null or not.

User

Here is selectedPauseAndFrameId {pauseId: "0027f53e-8035-464e-b7a5-04a18e903a5f", frameId: "0"}

Bot

Based on the information you provided, it looks like the function will only return null if the following condition is met:

  • If the selectedPauseAndFrameId object is present, pauseId is not null, frameId is not null, and getFramesSuspense(client, pauseId) returns a value, but no frame in the returned array has an id property that is equal to the frameId property of the selectedPauseAndFrameId object.
    In other words, the function will only return null if getFramesSuspense(client, pauseId) returns an array of frames, but none of those frames have an id property that matches the frameId property of the selectedPauseAndFrameId object.

User

Thanks. Here's the result of getFramesSuspsense

[{"frameId":"0","functionLocation":[{"column":288382,"line":1,"sourceId":"9"},{"sourceId":"pp9","line":17491,"column":13},{"sourceId":"o9-122-f73cce-6da222","line":22,"column":16}],"functionName":"zs","location":[{"sourceId":"9","line":1,"column":288683,"functionId":"15900","offset":1048},{"sourceId":"pp9","line":17501,"column":5},{"sourceId":"o9-122-f73cce-6da222","line":73,"column":2}],"scopeChain":["13","14","15","16","4","5"],"this":{},"type":"call","originalScopeChain":["original:0:0","original:0:1"],"originalFunctionName":"TestCase"},{"frameId":"1","functionLocation":[{"column":64405,"line":1,"sourceId":"3"},{"sourceId":"pp3","line":3612,"column":13},{"sourceId":"o3-0-a9614f-644df4","line":171,"column":9},{"sourceId":"ppo3-0-a9614f-644df4","line":3775,"column":9}],"functionName":"Lo","location":[{"column":64534,"line":1,"sourceId":"3"},{"sourceId":"pp3","line":3619,"column":11},{"sourceId":"o3-0-a9614f-644df4","line":171,"column":136},{"sourceId":"ppo3-0-a9614f-644df4","line":3782,"column":5}],"scopeChain":["12","3","4","5"],"this":{},"type":"call","originalScopeChain":["original:1:0","original:1:1"],"originalFunctionName":"bi"},{"frameId":"2","functionLocation":[{"column":124207,"line":1,"sourceId":"3"},{"sourceId":"pp3","line":7176,"column":15},{"sourceId":"o3-0-a9614f-644df4","line":303,"column":3},{"sourceId":"ppo3-0-a9614f-644df4","line":7375,"column":4}],"functionName":"Di","location":[{"column":125352,"line":1,"sourceId":"3"},{"sourceId":"pp3","line":7239,"column":21},{"sourceId":"o3-0-a9614f-644df4","line":303,"column":385},{"sourceId":"ppo3-0-a9614f-644df4","line":7393,"column":9}],"scopeChain":["11","3","4","5"],"this":{},"type":"call","originalScopeChain":["original:2:0","original:2:1"]},{"frameId":"3","functionLocation":[{"column":111054,"line":1,"sourceId":"3"},{"sourceId":"pp3","line":6345,"column":13},{"sourceId":"o3-0-a9614f-644df4","line":290,"column":366},{"sourceId":"ppo3-0-a9614f-644df4","line":7000,"column":9}],"functionName":"Fc","location":[{"column":111066,"line":1,"sourceId":"3"},{"sourceId":"pp3","line":6346,"column":14},{"sourceId":"o3-0-a9614f-644df4","line":290,"column":378},{"sourceId":"ppo3-0-a9614f-644df4","line":7001,"column":9}],"scopeChain":["10","3","4","5"],"this":{},"type":"call","originalScopeChain":["original:3:0","original:3:1"],"originalFunctionName":"ll"},{"frameId":"4","functionLocation":[{"column":110973,"line":1,"sourceId":"3"},{"sourceId":"pp3","line":6337,"column":13},{"sourceId":"o3-0-a9614f-644df4","line":290,"column":289},{"sourceId":"ppo3-0-a9614f-644df4","line":6992,"column":9}],"functionName":"Lc","location":[{"column":110994,"line":1,"sourceId":"3"},{"sourceId":"pp3","line":6339,"column":8},{"sourceId":"o3-0-a9614f-644df4","line":290,"column":309},{"sourceId":"ppo3-0-a9614f-644df4","line":6993,"column":22}],"scopeChain":["9","3","4","5"],"this":{},"type":"call","originalScopeChain":["original:4:0","original:4:1"],"originalFunctionName":"kl"},{"frameId":"5","functionLocation":[{"column":110789,"line":1,"sourceId":"3"},{"sourceId":"pp3","line":6322,"column":13},{"sourceId":"o3-0-a9614f-644df4","line":290,"column":108},{"sourceId":"ppo3-0-a9614f-644df4","line":6971,"column":9}],"functionName":"Tc","location":[{"column":110855,"line":1,"sourceId":"3"},{"sourceId":"pp3","line":6327,"column":11},{"sourceId":"o3-0-a9614f-644df4","line":290,"column":169},{"sourceId":"ppo3-0-a9614f-644df4","line":6977,"column":9}],"scopeChain":["8","3","4","5"],"this":{},"type":"call","originalScopeChain":["original:5:0","original:5:1"],"originalFunctionName":"$k"},{"frameId":"6","functionLocation":[{"column":107830,"line":1,"sourceId":"3"},{"sourceId":"pp3","line":6115,"column":13},{"sourceId":"o3-0-a9614f-644df4","line":283,"column":145},{"sourceId":"ppo3-0-a9614f-644df4","line":6725,"column":9}],"functionName":"Sc","location":[{"column":107931,"line":1,"sourceId":"3"},{"sourceId":"pp3","line":6122,"column":14},{"sourceId":"o3-0-a9614f-644df4","line":283,"column":244},{"sourceId":"ppo3-0-a9614f-644df4","line":6732,"column":9}],"scopeChain":["7","3","4","5"],"this":{"value":null},"type":"call","originalScopeChain":["original:6:0","original:6:1"],"originalFunctionName":"Wk"},{"frameId":"7","functionLocation":[{"column":47383,"line":1,"sourceId":"3"},{"sourceId":"pp3","line":2641,"column":13},{"sourceId":"o3-0-a9614f-644df4","line":129,"column":9},{"sourceId":"ppo3-0-a9614f-644df4","line":2739,"column":9}],"functionName":"Hl","location":[{"column":47478,"line":1,"sourceId":"3"},{"sourceId":"pp3","line":2651,"column":15},{"sourceId":"o3-0-a9614f-644df4","line":129,"column":104},{"sourceId":"ppo3-0-a9614f-644df4","line":2749,"column":13}],"scopeChain":["6","3","4","5"],"this":{},"type":"call","originalScopeChain":["original:7:0","original:7:1"],"originalFunctionName":"mg"},{"frameId":"8","functionLocation":[{"column":105538,"line":1,"sourceId":"3"},{"sourceId":"pp3","line":5959,"column":66},{"sourceId":"o3-0-a9614f-644df4","line":278,"column":250},{"sourceId":"ppo3-0-a9614f-644df4","line":6536,"column":70}],"functionName":"gc/<","location":[{"column":105549,"line":1,"sourceId":"3"},{"sourceId":"pp3","line":5960,"column":23},{"sourceId":"o3-0-a9614f-644df4","line":278,"column":268},{"sourceId":"ppo3-0-a9614f-644df4","line":6537,"column":20}],"scopeChain":["1","2","3","4","5"],"this":{},"type":"call","originalScopeChain":["original:8:0","original:8:1","original:8:2"]}]Less

Chat

Based on the information you provided, it looks like this function will not return null because getFramesSuspense(client, pauseId) returns an array of frames, and at least one of those frames has an id property that matches the frameId property of the selectedPauseAndFrameId object (which is "0" in this case).

In other words, the function will not return null because the following condition is not met:

If the selectedPauseAndFrameId object is present, pauseId is not null, frameId is not null, and getFramesSuspense(client, pauseId) returns a value, but no frame in the returned array has an id property that is equal to the frameId property of the selectedPauseAndFrameId object. Instead, the function will continue to execute and one of the other return statements in the function will be executed.

User

it actually did return null

Chat

If the function is returning null, then it must be because one of the following conditions is met:

  • If the selectedPauseAndFrameId object is present, but either its frameId or pauseId property is null.
  • If the selectedPauseAndFrameId object is present, pauseId is not null, frameId is not null, and getFramesSuspense(client, pauseId) returns a value, but no frame in the returned array has an id property that is equal to the frameId property of the selectedPauseAndFrameId object.
  • If one of these conditions is not met, then the function should not be returning null.

Without more information about the specific values of the variables involved, it is difficult to say for certain why the function is returning null in your case. It is possible that the selectedPauseAndFrameId object is not actually present, or that its frameId or pauseId properties are null, or that getFramesSuspense(client, pauseId) is returning an empty array or some other value that is not an array of frames.

If you are still having trouble understanding why the function is returning null, I would recommend checking the values of the relevant variables and making sure that they match the conditions described above. You can also try adding some additional logging or debugging statements to the function to help you understand what is happening.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment