| 1444 | } |
| 1445 | |
| 1446 | class Scope implements IVariableContainer { |
| 1447 | /** @inheritdoc */ |
| 1448 | public readonly id = getVariableId(); |
| 1449 | |
| 1450 | constructor( |
| 1451 | public readonly remoteObject: Cdp.Runtime.RemoteObject, |
| 1452 | private readonly context: VariableContext, |
| 1453 | public readonly ref: IScopeRef, |
| 1454 | private readonly extraProperties: IExtraProperty[], |
| 1455 | private readonly renameProvider: IRenameProvider, |
| 1456 | ) {} |
| 1457 | |
| 1458 | public async getChildren(_params: Dap.VariablesParams): Promise<IVariable[]> { |
| 1459 | const variables = await this.context.createObjectPropertyVars(this.remoteObject); |
| 1460 | const existing = new Set(variables.map(v => v.name)); |
| 1461 | for (const extraProperty of this.extraProperties) { |
| 1462 | if (!existing.has(extraProperty.name)) { |
| 1463 | variables.push( |
| 1464 | this.context.createVariableByType({ name: extraProperty.name }, extraProperty.value), |
| 1465 | ); |
| 1466 | } |
| 1467 | } |
| 1468 | |
| 1469 | return variables; |
| 1470 | } |
| 1471 | |
| 1472 | /** Maps any rename for the identifier in the current scope. */ |
| 1473 | public async getRename(forIdentifier: string) { |
| 1474 | const renames = await this.renameProvider.provideOnStackframe(this.ref.stackFrame); |
| 1475 | return renames.getOriginalName(forIdentifier, this.ref.stackFrame.rawPosition) |
| 1476 | || forIdentifier; |
| 1477 | } |
| 1478 | |
| 1479 | /** Sets a property of the scope */ |
| 1480 | public async setProperty(name: string, expression: string): Promise<Variable> { |
| 1481 | const evaluated = await this.context.cdp.Debugger.evaluateOnCallFrame({ |
| 1482 | expression: `${expression} ${getSourceSuffix()}`, |
| 1483 | callFrameId: this.ref.callFrameId, |
| 1484 | }); |
| 1485 | if (!evaluated) { |
| 1486 | throw new ProtocolError(errors.createUserError(l10n.t('Invalid expression'))); |
| 1487 | } |
| 1488 | if (evaluated.exceptionDetails) { |
| 1489 | throw new ProtocolError(errorFromException(evaluated.exceptionDetails)); |
| 1490 | } |
| 1491 | |
| 1492 | await this.context.cdp.Debugger.setVariableValue({ |
| 1493 | callFrameId: this.ref.callFrameId, |
| 1494 | scopeNumber: this.ref.scopeNumber, |
| 1495 | variableName: name, |
| 1496 | newValue: toCallArgument(evaluated.result), |
| 1497 | }); |
| 1498 | |
| 1499 | return this.context.createVariableByType({ name }, evaluated.result); |
| 1500 | } |
| 1501 | } |
| 1502 | |
| 1503 | export interface IExtraProperty { |
nothing calls this directly
no outgoing calls
no test coverage detected