MCPcopy
hub / github.com/microsoft/vscode-js-debug / ObjectVariable

Class ObjectVariable

src/adapter/variableStore.ts:884–975  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

882const NoCustomStringRepr = Symbol('NoStringRepr');
883
884class ObjectVariable extends Variable implements IMemoryReadable {
885 constructor(
886 context: VariableContext,
887 remoteObject: Cdp.Runtime.RemoteObject,
888 private customStringRepr?: string | typeof NoCustomStringRepr,
889 ) {
890 super(context, remoteObject);
891 }
892
893 public override async toDap(
894 previewContext: PreviewContextType,
895 valueFormat?: Dap.ValueFormat,
896 ): Promise<Dap.Variable> {
897 const [parentDap, value] = await Promise.all([
898 await super.toDap(previewContext, valueFormat),
899 await this.getValueRepresentation(previewContext),
900 ]);
901
902 return {
903 ...parentDap,
904 type: this.remoteObject.className || this.remoteObject.subtype || this.remoteObject.type,
905 variablesReference: this.id,
906 memoryReference: memoryReadableTypes.has(this.remoteObject.subtype)
907 ? String(this.id)
908 : undefined,
909 value,
910 };
911 }
912
913 private async getValueRepresentation(previewContext: PreviewContextType) {
914 if (typeof this.customStringRepr === 'string') {
915 return this.customStringRepr;
916 }
917
918 // for the first level of evaluations, toString it on-demand
919 if (
920 !this.context.parent
921 && this.remoteObject.objectId
922 && this.customStringRepr !== NoCustomStringRepr
923 ) {
924 try {
925 const ret = await this.context.cdp.Runtime.callFunctionOn({
926 functionDeclaration: getToStringIfCustom.decl(
927 `${customStringReprMaxLength}`,
928 this.context.customDescriptionGenerator || 'null',
929 ),
930 objectId: this.remoteObject.objectId,
931 returnByValue: true,
932 });
933 if (ret?.result.value) {
934 return (this.customStringRepr = localizeIndescribable(ret.result.value));
935 }
936 } catch (e) {
937 this.customStringRepr = NoCustomStringRepr;
938 // ignored
939 }
940 }
941

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected