MCPcopy Create free account
hub / github.com/Snapchat/Valdi / prepare

Method prepare

valdi/vscode_debugger/src/adapter/evaluator.ts:96–119  ·  view source on GitHub ↗

* @inheritdoc

(
    expression: string,
  )

Source from the content-addressed store, hash-verified

94 * @inheritdoc
95 */
96 public prepare(
97 expression: string,
98 ): { canEvaluateDirectly: boolean; invoke: PreparedCallFrameExpr } {
99 // CDP gives us a way to evaluate a function in the context of a given
100 // object ID. What we do to make returnValue work is to hoist the return
101 // object onto `globalThis`, replace reference in the expression, then
102 // evalute the expression and unhoist it from the globals.
103 const hoistedVar = hoistedPrefix + randomBytes(8).toString('hex');
104 const modified = this.replaceReturnValue(expression, hoistedVar);
105 if (!modified) {
106 return {
107 canEvaluateDirectly: true,
108 invoke: params => this.cdp.Debugger.evaluateOnCallFrame({ ...params, expression }),
109 };
110 }
111
112 return {
113 canEvaluateDirectly: false,
114 invoke: params =>
115 this.hoistReturnValue(hoistedVar).then(() =>
116 this.cdp.Debugger.evaluateOnCallFrame({ ...params, expression: modified }),
117 ),
118 };
119 }
120
121 /**
122 * @inheritdoc

Callers 1

evaluateMethod · 0.95

Calls 5

replaceReturnValueMethod · 0.95
hoistReturnValueMethod · 0.95
evaluateOnCallFrameMethod · 0.80
toStringMethod · 0.65
thenMethod · 0.65

Tested by

no test coverage detected