* @inheritdoc
(
expression: string,
)
| 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 |
no test coverage detected