This repository has been archived by the owner on Apr 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement v8 Inspector Protocol (#329)
Debug agent now can choose to use either Inspector API (node >= 8) or v8 debug API.
- Loading branch information
1 parent
015f29c
commit 3114892
Showing
16 changed files
with
1,725 additions
and
603 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/** | ||
* Copyright 2017 Google Inc. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
import * as semver from 'semver'; | ||
|
||
import * as apiTypes from '../types/api-types'; | ||
import {Logger} from '../types/common-types'; | ||
|
||
import {DebugAgentConfig} from './config'; | ||
import {ScanStats} from './scanner'; | ||
import {SourceMapper} from './sourcemapper'; | ||
|
||
|
||
export interface DebugApi { | ||
set: (breakpoint: apiTypes.Breakpoint, cb: (err: Error|null) => void) => void; | ||
clear: | ||
(breakpoint: apiTypes.Breakpoint, cb: (err: Error|null) => void) => void; | ||
wait: | ||
(breakpoint: apiTypes.Breakpoint, | ||
callback: (err?: Error) => void) => void; | ||
log: | ||
(breakpoint: apiTypes.Breakpoint, | ||
print: (format: string, exps: string[]) => void, | ||
shouldStop: () => boolean) => void; | ||
disconnect: () => void; | ||
numBreakpoints_: () => number; | ||
numListeners_: () => number; | ||
} | ||
|
||
interface DebugApiConstructor { | ||
new(logger_: Logger, config_: DebugAgentConfig, jsFiles_: ScanStats, | ||
sourcemapper_: SourceMapper): DebugApi; | ||
} | ||
|
||
class DummyDebugApi implements DebugApi { | ||
constructor( | ||
logger: Logger, _config: DebugAgentConfig, _jsFiles: ScanStats, | ||
_sourcemapper: SourceMapper) { | ||
logger.error( | ||
'Debug agent cannot get node version. Cloud debugger is disabled.'); | ||
} | ||
set(_breakpoint: apiTypes.Breakpoint, cb: (err: Error|null) => void): void { | ||
return setImmediate(() => { | ||
cb(new Error('no debugapi running.')); | ||
}); | ||
} | ||
clear(_breakpoint: apiTypes.Breakpoint, cb: (err: Error|null) => void): void { | ||
return setImmediate(() => { | ||
cb(new Error('no debugapi running.')); | ||
}); | ||
} | ||
wait(_breakpoint: apiTypes.Breakpoint, cb: (err?: Error) => void): void { | ||
return setImmediate(() => { | ||
cb(new Error('no debugapi running.')); | ||
}); | ||
} | ||
log: | ||
(breakpoint: apiTypes.Breakpoint, | ||
print: (format: string, exps: string[]) => void, | ||
shouldStop: () => boolean) => void; | ||
disconnect: () => void; | ||
numBreakpoints_: () => number; | ||
numListeners_: () => number; | ||
} | ||
|
||
let debugApiConstructor: DebugApiConstructor; | ||
const nodeVersion = /v(\d+\.\d+\.\d+)/.exec(process.version); | ||
|
||
if (!nodeVersion || nodeVersion.length < 2) { | ||
debugApiConstructor = DummyDebugApi; | ||
} else if (semver.satisfies(nodeVersion[1], '>=8')) { | ||
const inspectorapi = require('./inspectordebugapi'); | ||
debugApiConstructor = inspectorapi.InspectorDebugApi; | ||
} else { | ||
const v8debugapi = require('./v8debugapi'); | ||
debugApiConstructor = v8debugapi.V8DebugApi; | ||
} | ||
|
||
export const MODULE_WRAP_PREFIX_LENGTH = | ||
require('module').wrap('☃').indexOf('☃'); | ||
|
||
let singleton: DebugApi; | ||
|
||
export function create( | ||
logger: Logger, config: DebugAgentConfig, jsFiles: ScanStats, | ||
sourcemapper: SourceMapper): DebugApi { | ||
if (singleton && !config.forceNewAgent_) { | ||
return singleton; | ||
} else if (singleton) { | ||
singleton.disconnect(); | ||
} | ||
|
||
singleton = new debugApiConstructor(logger, config, jsFiles, sourcemapper); | ||
return singleton; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.