GeezerVison is showing github.com — inspector: implemented V8InspectorClient::resourceNameToUrl · nodejs/node@f66e9ab
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: src/inspector_agent.cc +32Lines changed: 32 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 6 | 6 | #include "inspector/tracing_agent.h" | 7 | 7 | #include "node/inspector/protocol/Protocol.h" | 8 | 8 | #include "node_internals.h" | | 9 | +#include "node_url.h" | 9 | 10 | #include "v8-inspector.h" | 10 | 11 | #include "v8-platform.h" | 11 | 12 |
| @@ -375,6 +376,25 @@ void NotifyClusterWorkersDebugEnabled(Environment* env) { | 375 | 376 | MakeCallback(env->isolate(), process_object, emit_fn.As<Function>(), | 376 | 377 | arraysize(argv), argv, {0, 0}); | 377 | 378 | } | | 379 | + | | 380 | +#ifdef _WIN32 | | 381 | +bool IsFilePath(const std::string& path) { | | 382 | + // '\\' | | 383 | + if (path.length() > 2 && path[0] == '\\' && path[1] == '\\') | | 384 | + return true; | | 385 | + // '[A-Z]:[/\\]' | | 386 | + if (path.length() < 3) | | 387 | + return false; | | 388 | + if ((path[0] >= 'A' && path[0] <= 'Z') || (path[0] >= 'a' && path[0] <= 'z')) | | 389 | + return path[1] == ':' && (path[2] == '/' || path[2] == '\\'); | | 390 | + return false; | | 391 | +} | | 392 | +#else | | 393 | +bool IsFilePath(const std::string& path) { | | 394 | + return path.length() && path[0] == '/'; | | 395 | +} | | 396 | +#endif // __POSIX__ | | 397 | + | 378 | 398 | } // namespace | 379 | 399 |
| 380 | 400 | class NodeInspectorClient : public V8InspectorClient { | @@ -601,6 +621,18 @@ class NodeInspectorClient : public V8InspectorClient { | 601 | 621 | return env_->isolate_data()->platform()->CurrentClockTimeMillis(); | 602 | 622 | } | 603 | 623 |
| | 624 | + std::unique_ptr<StringBuffer> resourceNameToUrl( | | 625 | + const StringView& resource_name_view) override { | | 626 | + std::string resource_name = | | 627 | + protocol::StringUtil::StringViewToUtf8(resource_name_view); | | 628 | + if (!IsFilePath(resource_name)) | | 629 | + return nullptr; | | 630 | + node::url::URL url = node::url::URL::FromFilePath(resource_name); | | 631 | + // TODO(ak239spb): replace this code with url.href(). | | 632 | + // Refs: https://github.com/nodejs/node/issues/22610 | | 633 | + return Utf8ToStringView(url.protocol() + "//" + url.path()); | | 634 | + } | | 635 | + | 604 | 636 | node::Environment* env_; | 605 | 637 | bool is_main_; | 606 | 638 | bool running_nested_loop_ = false; | |
Collapse file Copy file name to clipboardExpand all lines: test/cctest/test_url.cc -4Lines changed: 0 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -124,10 +124,6 @@ TEST_F(URLTest, FromFilePath) { | 124 | 124 | file_url = URL::FromFilePath("b:\\a\\%%.js"); | 125 | 125 | EXPECT_EQ("file:", file_url.protocol()); | 126 | 126 | EXPECT_EQ("/b:/a/%25%25.js", file_url.path()); | 127 | | - | 128 | | - file_url = URL::FromFilePath("\\\\host\\a\\b\\c"); | 129 | | - EXPECT_EQ("file:", file_url.protocol()); | 130 | | - EXPECT_EQ("host/a/b/c", file_url.path()); | 131 | 127 | #else | 132 | 128 | file_url = URL::FromFilePath("/"); | 133 | 129 | EXPECT_EQ("file:", file_url.protocol()); | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-inspector-multisession-js.js +4-2Lines changed: 4 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +// Flags: --expose-internals | 1 | 2 | 'use strict'; | 2 | 3 | const common = require('../common'); | 3 | 4 |
| @@ -6,6 +7,7 @@ common.skipIfInspectorDisabled(); | 6 | 7 | const assert = require('assert'); | 7 | 8 | const { Session } = require('inspector'); | 8 | 9 | const path = require('path'); | | 10 | +const { pathToFileURL } = require('url'); | 9 | 11 |
| 10 | 12 | function debugged() { | 11 | 13 | return 42; | @@ -32,8 +34,8 @@ async function test() { | 32 | 34 |
| 33 | 35 | await new Promise((resolve, reject) => { | 34 | 36 | session1.post('Debugger.setBreakpointByUrl', { | 35 | | - 'lineNumber': 9, | 36 | | - 'url': path.resolve(__dirname, __filename), | | 37 | + 'lineNumber': 12, | | 38 | + 'url': pathToFileURL(path.resolve(__dirname, __filename)).toString(), | 37 | 39 | 'columnNumber': 0, | 38 | 40 | 'condition': '' | 39 | 41 | }, (error, result) => { | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-v8-coverage.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -97,7 +97,7 @@ function getFixtureCoverage(fixtureFile, coverageDirectory) { | 97 | 97 | for (const coverageFile of coverageFiles) { | 98 | 98 | const coverage = require(path.join(coverageDirectory, coverageFile)); | 99 | 99 | for (const fixtureCoverage of coverage.result) { | 100 | | - if (fixtureCoverage.url.indexOf(`${path.sep}${fixtureFile}`) !== -1) { | | 100 | + if (fixtureCoverage.url.indexOf(`/${fixtureFile}`) !== -1) { | 101 | 101 | return fixtureCoverage; | 102 | 102 | } | 103 | 103 | } | |
Collapse file Copy file name to clipboardExpand all lines: test/sequential/test-inspector-bindings.js +4-2Lines changed: 4 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +// Flags: --expose-internals | 1 | 2 | 'use strict'; | 2 | 3 | const common = require('../common'); | 3 | 4 | common.skipIfInspectorDisabled(); | 4 | 5 | const assert = require('assert'); | 5 | 6 | const inspector = require('inspector'); | 6 | 7 | const path = require('path'); | | 8 | +const { pathToFileURL } = require('url'); | 7 | 9 |
| 8 | 10 | // This test case will set a breakpoint 4 lines below | 9 | 11 | function debuggedFunction() { | @@ -84,8 +86,8 @@ function testSampleDebugSession() { | 84 | 86 | }, TypeError); | 85 | 87 | session.post('Debugger.enable', () => cbAsSecondArgCalled = true); | 86 | 88 | session.post('Debugger.setBreakpointByUrl', { | 87 | | - 'lineNumber': 12, | 88 | | - 'url': path.resolve(__dirname, __filename), | | 89 | + 'lineNumber': 14, | | 90 | + 'url': pathToFileURL(path.resolve(__dirname, __filename)).toString(), | 89 | 91 | 'columnNumber': 0, | 90 | 92 | 'condition': '' | 91 | 93 | }); | |
Collapse file Copy file name to clipboardExpand all lines: test/sequential/test-inspector-break-when-eval.js +3-2Lines changed: 3 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -5,6 +5,7 @@ common.skipIfInspectorDisabled(); | 5 | 5 | const assert = require('assert'); | 6 | 6 | const { NodeInstance } = require('../common/inspector-helper.js'); | 7 | 7 | const fixtures = require('../common/fixtures'); | | 8 | +const { pathToFileURL } = require('url'); | 8 | 9 |
| 9 | 10 | const script = fixtures.path('inspector-global-function.js'); | 10 | 11 |
| @@ -26,7 +27,7 @@ async function breakOnLine(session) { | 26 | 27 | const commands = [ | 27 | 28 | { 'method': 'Debugger.setBreakpointByUrl', | 28 | 29 | 'params': { 'lineNumber': 9, | 29 | | - 'url': script, | | 30 | + 'url': pathToFileURL(script).toString(), | 30 | 31 | 'columnNumber': 0, | 31 | 32 | 'condition': '' | 32 | 33 | } | @@ -45,7 +46,7 @@ async function breakOnLine(session) { | 45 | 46 | } | 46 | 47 | ]; | 47 | 48 | session.send(commands); | 48 | | - await session.waitForBreakOnLine(9, script); | | 49 | + await session.waitForBreakOnLine(9, pathToFileURL(script).toString()); | 49 | 50 | } | 50 | 51 |
| 51 | 52 | async function stepOverConsoleStatement(session) { | |
Collapse file Copy file name to clipboardExpand all lines: test/sequential/test-inspector-debug-brk-flag.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -24,7 +24,7 @@ async function testBreakpointOnStart(session) { | 24 | 24 | ]; | 25 | 25 |
| 26 | 26 | session.send(commands); | 27 | | - await session.waitForBreakOnLine(0, session.scriptPath()); | | 27 | + await session.waitForBreakOnLine(0, session.scriptURL()); | 28 | 28 | } | 29 | 29 |
| 30 | 30 | async function runTests() { | |
Collapse file Copy file name to clipboardExpand all lines: test/sequential/test-inspector-exception.js +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -7,6 +7,7 @@ common.skipIfInspectorDisabled(); | 7 | 7 |
| 8 | 8 | const assert = require('assert'); | 9 | 9 | const { NodeInstance } = require('../common/inspector-helper.js'); | | 10 | +const { pathToFileURL } = require('url'); | 10 | 11 |
| 11 | 12 | const script = fixtures.path('throws_error.js'); | 12 | 13 |
| @@ -29,7 +30,7 @@ async function testBreakpointOnStart(session) { | 29 | 30 | ]; | 30 | 31 |
| 31 | 32 | await session.send(commands); | 32 | | - await session.waitForBreakOnLine(0, script); | | 33 | + await session.waitForBreakOnLine(0, pathToFileURL(script).toString()); | 33 | 34 | } | 34 | 35 |
| 35 | 36 |
| |
Collapse file Copy file name to clipboard +40Lines changed: 40 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +'use strict'; | | 2 | +const common = require('../common'); | | 3 | + | | 4 | +common.skipIfInspectorDisabled(); | | 5 | + | | 6 | +(async function test() { | | 7 | + const { strictEqual } = require('assert'); | | 8 | + const { Session } = require('inspector'); | | 9 | + const { promisify } = require('util'); | | 10 | + const vm = require('vm'); | | 11 | + const session = new Session(); | | 12 | + session.connect(); | | 13 | + session.post = promisify(session.post); | | 14 | + await session.post('Debugger.enable'); | | 15 | + await check('http://example.com', 'http://example.com'); | | 16 | + await check(undefined, 'evalmachine.<anonymous>'); | | 17 | + await check('file:///foo.js', 'file:///foo.js'); | | 18 | + await check('file:///foo.js', 'file:///foo.js'); | | 19 | + await check('foo.js', 'foo.js'); | | 20 | + await check('[eval]', '[eval]'); | | 21 | + await check('%.js', '%.js'); | | 22 | + | | 23 | + if (common.isWindows) { | | 24 | + await check('C:\\foo.js', 'file:///C:/foo.js'); | | 25 | + await check('C:\\a\\b\\c\\foo.js', 'file:///C:/a/b/c/foo.js'); | | 26 | + await check('a:\\%.js', 'file:///a:/%25.js'); | | 27 | + } else { | | 28 | + await check('/foo.js', 'file:///foo.js'); | | 29 | + await check('/a/b/c/d/foo.js', 'file:///a/b/c/d/foo.js'); | | 30 | + await check('/%%%.js', 'file:///%25%25%25.js'); | | 31 | + } | | 32 | + | | 33 | + async function check(filename, expected) { | | 34 | + const promise = | | 35 | + new Promise((resolve) => session.once('inspectorNotification', resolve)); | | 36 | + new vm.Script('42', { filename }).runInThisContext(); | | 37 | + const { params: { url } } = await promise; | | 38 | + strictEqual(url, expected); | | 39 | + } | | 40 | +})(); |
Collapse file Copy file name to clipboardExpand all lines: test/sequential/test-inspector.js +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -68,15 +68,15 @@ async function testBreakpointOnStart(session) { | 68 | 68 | ]; | 69 | 69 |
| 70 | 70 | await session.send(commands); | 71 | | - await session.waitForBreakOnLine(0, session.scriptPath()); | | 71 | + await session.waitForBreakOnLine(0, session.scriptURL()); | 72 | 72 | } | 73 | 73 |
| 74 | 74 | async function testBreakpoint(session) { | 75 | 75 | console.log('[test]', 'Setting a breakpoint and verifying it is hit'); | 76 | 76 | const commands = [ | 77 | 77 | { 'method': 'Debugger.setBreakpointByUrl', | 78 | 78 | 'params': { 'lineNumber': 5, | 79 | | - 'url': session.scriptPath(), | | 79 | + 'url': session.scriptURL(), | 80 | 80 | 'columnNumber': 0, | 81 | 81 | 'condition': '' | 82 | 82 | } | @@ -91,7 +91,7 @@ async function testBreakpoint(session) { | 91 | 91 | `Script source is wrong: ${scriptSource}`); | 92 | 92 |
| 93 | 93 | await session.waitForConsoleOutput('log', ['A message', 5]); | 94 | | - const paused = await session.waitForBreakOnLine(5, session.scriptPath()); | | 94 | + const paused = await session.waitForBreakOnLine(5, session.scriptURL()); | 95 | 95 | const scopeId = paused.params.callFrames[0].scopeChain[0].object.objectId; | 96 | 96 |
| 97 | 97 | console.log('[test]', 'Verify we can read current application state'); | |
|