Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public async handleOnPaused(notification: Crdp.Debugger.PausedEvent): Promise {
if (notification.hitBreakpoints && notification.hitBreakpoints.length) {
// If breakOnLoadStrategy is set to regex, we may have hit a stopOnEntry breakpoint we put.
// So we need to resolve all the pending breakpoints in this script and then decide to continue or not
if (this._breakOnLoadStrategy === 'regex') {
let shouldContinue = await this.handleStopOnEntryBreakpointAndContinue(notification);
return shouldContinue;
}
} else if (this.isInstrumentationPause(notification)) {
// This is fired when Chrome stops on the first line of a script when using the setInstrumentationBreakpoint API
const pausedScriptId = notification.callFrames[0].location.scriptId;
// Now we wait for all the pending breakpoints to be resolved and then continue
await this._chromeDebugAdapter.getBreakpointsResolvedDefer(pausedScriptId).promise;
logger.log('BreakOnLoadHelper: Finished waiting for breakpoints to get resolved.');
let shouldContinue = this._doesDOMInstrumentationRecieveExtraEvent || await this.handleStopOnEntryBreakpointAndContinue(notification);
return shouldContinue;
}
return false;
}
if (!scriptUrlPath || !scriptUrlPath.startsWith('/')) {
return '';
}
const mappingKeys = Object.keys(pathMapping)
.sort((a, b) => b.length - a.length);
for (let pattern of mappingKeys) {
// empty pattern match nothing use / to match root
if (!pattern) {
continue;
}
const mappingRHS = pathMapping[pattern];
if (pattern[0] !== '/') {
logger.log(`PathMapping keys should be absolute: ${pattern}`);
pattern = '/' + pattern;
}
if (pathMappingPatternMatchesPath(pattern, scriptUrlPath)) {
return toClientPath(pattern, mappingRHS, scriptUrlPath);
}
}
return '';
}
private async _downloadSourceMapContents(sourceMapUri: string): Promise {
// use sha256 to ensure the hash value can be used in filenames
let cachedSourcemapPath: string;
if (this._enableSourceMapCaching) {
const hash = crypto.createHash('sha256').update(sourceMapUri).digest('hex');
const cachePath = path.join(os.tmpdir(), 'com.microsoft.VSCode', 'node-debug2', 'sm-cache');
cachedSourcemapPath = path.join(cachePath, hash);
const exists = utils.existsSync(cachedSourcemapPath);
if (exists) {
logger.log(`Sourcemaps.downloadSourceMapContents: Reading cached sourcemap file from ${cachedSourcemapPath}`);
return this.loadSourceMapContents(cachedSourcemapPath);
}
}
const responseText = await utils.getURL(sourceMapUri);
if (cachedSourcemapPath && this._enableSourceMapCaching) {
logger.log(`Sourcemaps.downloadSourceMapContents: Caching sourcemap file at ${cachedSourcemapPath}`);
await utils.writeFileP(cachedSourcemapPath, responseText);
}
return responseText;
}
}
getMapForGeneratedPath(pathToGenerated: string, originalUrlToGenerated: string | undefined, mapPath: string, isVSClient = false): Promise {
let msg = `SourceMaps.getMapForGeneratedPath: Finding SourceMap for ${pathToGenerated} by URI: ${mapPath}`;
if (this._pathMapping) {
msg += ` and webRoot/pathMapping: ${JSON.stringify(this._pathMapping)}`;
}
logger.log(msg);
// For an inlined sourcemap, mapPath is a data URI containing a blob of base64 encoded data, starting
// with a tag like "data:application/json;charset:utf-8;base64,". The data should start after the last comma.
let sourceMapContentsP: Promise;
if (mapPath.indexOf('data:application/json') >= 0) {
// Sourcemap is inlined
logger.log(`SourceMaps.getMapForGeneratedPath: Using inlined sourcemap in ${pathToGenerated}`);
sourceMapContentsP = Promise.resolve(this.getInlineSourceMapContents(mapPath));
} else {
const accessPath = isInternalRemotePath(pathToGenerated) && originalUrlToGenerated ?
originalUrlToGenerated :
pathToGenerated;
sourceMapContentsP = this.getSourceMapContent(accessPath, mapPath);
}
return sourceMapContentsP.then(contents => {
if (contents) {
try {
// Throws for invalid JSON
return new SourceMap(pathToGenerated, contents, this._pathMapping, this._sourceMapPathOverrides, isVSClient);
} catch (e) {
logger.error(`SourceMaps.getMapForGeneratedPath: exception while processing path: ${pathToGenerated}, sourcemap: ${mapPath}\n${e.stack}`);
return null;
export function mapRemoteClientToInternalPath(remoteUri: string): string {
if (remoteUri.startsWith(remoteUriScheme + ':')) {
const uri = URI.parse(remoteUri);
const uriPath = getFsPath(uri);
const driveLetterMatch = uriPath.match(/^[A-Za-z]:/);
let internalPath: string;
if (!!driveLetterMatch) {
internalPath = path.win32.join(driveLetterMatch[0], remotePathComponent, uriPath.substr(2));
} else {
internalPath = path.posix.join('/', remotePathComponent, uriPath);
}
logger.log(`remoteMapper: mapping remote uri ${remoteUri} to internal path: ${internalPath}`);
return internalPath;
} else {
return remoteUri;
}
}
protected async onBPRecipeStatusChanged(statusChanged: BPRecipeStatusChanged): Promise {
/**
* The breakpoints gets assigned at the end of the setBreakpoints request
* We need to prevent BPStatusChanged from being sent while we are processing a setBreakpoints request event, because they might
* try to reference a breakpoint for which the client doesn't yet have an id
*/
logger.log(`Waiting for set breakpoints on flight requests`);
this._inFlightRequests.then(() => this._eventsToClientReporter.sendBPStatusChanged({ reason: 'changed', bpRecipeStatus: statusChanged.status }), rejection => {
logger.error(`Failed to send a breakpoint status update: ${rejection}`);
});
}
}
contentsP = new Promise((resolve, reject) => {
logger.log(`SourceMaps.loadSourceMapContents: Reading local sourcemap file from ${mapPathOrURL}`);
fs.readFile(mapPathOrURL, (err, data) => {
if (err) {
logger.log(`SourceMaps.loadSourceMapContents: Could not read sourcemap file - ` + err.message);
resolve(null);
} else {
resolve(data && data.toString());
}
});
});
}
private loadSourceMapContents(mapPathOrURL: string): Promise {
let contentsP: Promise;
if (utils.isURL(mapPathOrURL) && !utils.isFileUrl(mapPathOrURL)) {
logger.log(`SourceMaps.loadSourceMapContents: Downloading sourcemap file from ${mapPathOrURL}`);
contentsP = this.downloadSourceMapContents(mapPathOrURL).catch(e => {
logger.log(`SourceMaps.loadSourceMapContents: Could not download sourcemap from ${mapPathOrURL}`);
return null;
});
} else {
mapPathOrURL = utils.canonicalizeUrl(mapPathOrURL);
contentsP = new Promise((resolve, reject) => {
logger.log(`SourceMaps.loadSourceMapContents: Reading local sourcemap file from ${mapPathOrURL}`);
fs.readFile(mapPathOrURL, (err, data) => {
if (err) {
logger.log(`SourceMaps.loadSourceMapContents: Could not read sourcemap file - ` + err.message);
resolve(null);
} else {
resolve(data && data.toString());
}
});
public getTargetPathFromClientPath(localPath: string): string {
localPath = super.getTargetPathFromClientPath(localPath) || localPath;
if (!this.shouldMapPaths(localPath)) return localPath;
const relPath = relative(this._localRoot, localPath);
if (relPath.startsWith('../')) return '';
let remotePath = join(this._remoteRoot, relPath);
remotePath = utils.fixDriveLetterAndSlashes(remotePath, /*uppercaseDriveLetter=*/true);
logger.log(`Mapped localToRemote: ${localPath} -> ${remotePath}`);
return remotePath;
}
}
public shouldPauseForBreakpoint(): boolean {
++this._currentHitCount;
const shouldPause = this._shouldPauseCondition(this._currentHitCount);
logger.log(`Evaluating hit count breakpoint: ${this.hitCountBPRecipe}. Hit count: ${this._currentHitCount}. Should pause: ${shouldPause}`);
return shouldPause;
}