Skip to content
This repository has been archived by the owner on Oct 2, 2021. It is now read-only.

Commit

Permalink
Fix bypassing node_internals overrides on adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
roblourens committed Oct 3, 2019
1 parent bdebbf2 commit d6aba9f
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 20 deletions.
10 changes: 5 additions & 5 deletions src/chrome/chromeDebugAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import { mapRemoteClientToInternalPath, mapInternalSourceToRemoteClient } from '
import { Breakpoints } from './breakpoints';
import { VariablesManager } from './variablesManager';
import { StackFrames } from './stackFrames';
import { ScriptContainer, Scripts } from './scripts';
import { ScriptContainer } from './scripts';
import { SmartStepper } from './smartStep';
import { ScriptSkipper } from './scriptSkipping';
let localize = nls.loadMessageBundle();
Expand Down Expand Up @@ -144,7 +144,7 @@ export abstract class ChromeDebugAdapter implements IDebugAdapter {

private _transformers: Transformers;

public constructor({ chromeConnection, lineColTransformer, sourceMapTransformer, pathTransformer, targetFilter, breakpoints }: IChromeDebugAdapterOpts,
public constructor({ chromeConnection, lineColTransformer, sourceMapTransformer, pathTransformer, targetFilter, breakpoints, scriptContainer }: IChromeDebugAdapterOpts,
session: ChromeDebugSession
) {
telemetry.setupEventHandler(e => session.sendEvent(e));
Expand All @@ -153,7 +153,7 @@ export abstract class ChromeDebugAdapter implements IDebugAdapter {
this._chromeConnection = new (chromeConnection || ChromeConnection)(undefined, targetFilter);
this.events = new StepProgressEventsEmitter(this._chromeConnection.events ? [this._chromeConnection.events] : []);

this._scriptContainer = new ScriptContainer();
this._scriptContainer = new (scriptContainer || ScriptContainer)();

this._transformers = {
lineColTransformer: new (lineColTransformer || LineColTransformer)(this._session),
Expand Down Expand Up @@ -1315,8 +1315,8 @@ export abstract class ChromeDebugAdapter implements IDebugAdapter {
return undefined;
}

public realPathToDisplayPath(realPath: string): string { return Scripts.realPathToDisplayPath(realPath); }
public displayPathToRealPath(displayPath: string): string { return Scripts.displayPathToRealPath(displayPath); }
public realPathToDisplayPath(realPath: string): string { return this._scriptContainer.realPathToDisplayPath(realPath); }
public displayPathToRealPath(displayPath: string): string { return this._scriptContainer.displayPathToRealPath(displayPath); }

/* __GDPR__
"ClientRequest/scopes" : {
Expand Down
2 changes: 2 additions & 0 deletions src/chrome/chromeDebugSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { telemetry, ExceptionType, IExecutionResultTelemetryProperties, Telemetr
import * as utils from '../utils';
import { ExecutionTimingsReporter, StepProgressEventsEmitter, IObservableEvents, IStepStartedEventsEmitter, IFinishedStartingUpEventsEmitter } from '../executionTimingsReporter';
import { Breakpoints } from './breakpoints';
import { ScriptContainer } from '../chrome/scripts';

export interface IChromeDebugAdapterOpts {
targetFilter?: ITargetFilter;
Expand All @@ -29,6 +30,7 @@ export interface IChromeDebugAdapterOpts {
lineColTransformer?: { new(session: any): LineColTransformer };

breakpoints?: typeof Breakpoints;
scriptContainer?: typeof ScriptContainer;
}

export interface IChromeDebugSessionOpts extends IChromeDebugAdapterOpts {
Expand Down
4 changes: 2 additions & 2 deletions src/chrome/scriptSkipping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { logger } from 'vscode-debugadapter';
import { IToggleSkipFileStatusArgs } from '../debugAdapterInterfaces';
import { ChromeConnection } from './chromeConnection';
import { Protocol as Crdp } from 'devtools-protocol';
import { ScriptContainer, Scripts } from './scripts';
import { ScriptContainer } from './scripts';
import { Transformers } from './chromeDebugAdapter';
import * as utils from '../utils';

Expand Down Expand Up @@ -50,7 +50,7 @@ export class ScriptSkipper {

// e.g. strip <node_internals>/
if (args.path) {
args.path = Scripts.displayPathToRealPath(args.path);
args.path = scripts.displayPathToRealPath(args.path);
}

const aPath = args.path || scripts.fakeUrlForSourceReference(args.sourceReference);
Expand Down
16 changes: 5 additions & 11 deletions src/chrome/scripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export class ScriptContainer {
public async scriptToSource(script: Crdp.Debugger.ScriptParsedEvent, origin: string, remoteAuthority?: string): Promise<DebugProtocol.Source> {
const sourceReference = this.getSourceReferenceForScriptId(script.scriptId);
const properlyCasedScriptUrl = utils.canonicalizeUrl(script.url);
const displayPath = Scripts.realPathToDisplayPath(properlyCasedScriptUrl);
const displayPath = this.realPathToDisplayPath(properlyCasedScriptUrl);

const exists = await utils.existsAsync(properlyCasedScriptUrl); // script.url can start with file:/// so we use the canonicalized version
const source = <DebugProtocol.Source>{
Expand Down Expand Up @@ -157,24 +157,18 @@ export class ScriptContainer {

public displayNameForSourceReference(sourceReference: number): string {
const handle = this._sourceHandles.get(sourceReference);
return (handle && Scripts.displayNameForScriptId(handle.scriptId)) || sourceReference + '';
return (handle && this.displayNameForScriptId(handle.scriptId)) || sourceReference + '';
}
}

/**
* A collection of pure functions dealing with scripts
*/
export namespace Scripts {

export function displayNameForScriptId(scriptId: number|string): string {
public displayNameForScriptId(scriptId: number|string): string {
return `${ChromeUtils.EVAL_NAME_PREFIX}${scriptId}`;
}

/**
* Called when returning a stack trace, for the path for Sources that have a sourceReference, so consumers can
* tweak it, since it's only for display.
*/
export function realPathToDisplayPath(realPath: string): string {
public realPathToDisplayPath(realPath: string): string {
if (ChromeUtils.isEvalScript(realPath)) {
return `${ChromeDebugAdapter.EVAL_ROOT}/${realPath}`;
}
Expand All @@ -185,7 +179,7 @@ export namespace Scripts {
/**
* Get the original path back from a displayPath created from `realPathToDisplayPath`
*/
export function displayPathToRealPath(displayPath: string): string {
public displayPathToRealPath(displayPath: string): string {
if (displayPath.startsWith(ChromeDebugAdapter.EVAL_ROOT)) {
return displayPath.substr(ChromeDebugAdapter.EVAL_ROOT.length + 1); // Trim "<eval>/"
}
Expand Down
4 changes: 2 additions & 2 deletions src/chrome/stackFrames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { IStackTraceResponseBody,
IInternalStackTraceResponseBody } from '../debugAdapterInterfaces';
import { Protocol as Crdp } from 'devtools-protocol';
import { Transformers } from './chromeDebugAdapter';
import { ScriptContainer, Scripts } from './scripts';
import { ScriptContainer } from './scripts';
import { SmartStepper } from './smartStep';
import { ScriptSkipper } from './scriptSkipping';

Expand Down Expand Up @@ -92,7 +92,7 @@ export class StackFrames {

// Allow consumer to adjust final path
if (frame.source.path && frame.source.sourceReference) {
frame.source.path = Scripts.realPathToDisplayPath(frame.source.path);
frame.source.path = scripts.realPathToDisplayPath(frame.source.path);
}

// And finally, remove the fake eval path and fix the name, if it was never resolved to a real path
Expand Down

0 comments on commit d6aba9f

Please sign in to comment.