Skip to content

Commit 7ffb9fa

Browse files
committed
Fix namespaces
1 parent e5814d7 commit 7ffb9fa

File tree

4 files changed

+111
-20
lines changed

4 files changed

+111
-20
lines changed

dwds/debug_extension/web/background.dart

+5-5
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ enum DebuggerTrigger { extensionIcon, dartPanel, dwds }
132132

133133
void main() {
134134
// Start debugging when a user clicks the Dart Debug Extension:
135-
ChromeBrowserAction.onClickedAddListener(allowInterop((_) {
135+
ChromeBrowserActionOnClicked.addListener(allowInterop((_) {
136136
_startDebugging(DebuggerTrigger.extensionIcon);
137137
}));
138138

@@ -141,14 +141,14 @@ void main() {
141141

142142
// Attaches a debug session to the app when the extension receives a
143143
// Runtime.executionContextCreated event from Chrome:
144-
ChromeDebugger.onEventAddListener(allowInterop(_maybeAttachDebugSession));
144+
ChromeDebuggerOnEvent.addListener(allowInterop(_maybeAttachDebugSession));
145145

146146
// When a Dart application tab is closed, detach the corresponding debug
147147
// session:
148148
tabsOnRemovedAddListener(allowInterop(_removeAndDetachDebugSessionForTab));
149149

150150
// When a debug session is detached, remove the reference to it:
151-
ChromeDebugger.onDetachAddListener(
151+
ChromeDebuggerOnDetach.addListener(
152152
allowInterop((Debuggee source, DetachReason reason) {
153153
_removeDebugSessionForTab(source.tabId);
154154
}));
@@ -157,7 +157,7 @@ void main() {
157157
tabsOnCreatedAddListener(allowInterop(_maybeSaveDevToolsTabId));
158158

159159
// Forward debugger events to the backend if applicable.
160-
ChromeDebugger.onEventAddListener(allowInterop(_filterAndForwardToBackend));
160+
ChromeDebuggerOnEvent.addListener(allowInterop(_filterAndForwardToBackend));
161161

162162
// Maybe update the extension icon when a user clicks the tab:
163163
tabsOnActivatedAddListener(allowInterop((ActiveInfo info) {
@@ -169,7 +169,7 @@ void main() {
169169
allowInterop(_handleMessageFromExternalExtensions));
170170

171171
// Message forwarder enabling communication with external Chrome extensions:
172-
ChromeDebugger.onEventAddListener(
172+
ChromeDebuggerOnEvent.addListener(
173173
allowInterop(_forwardMessageToExternalExtensions));
174174

175175
// Maybe update the extension icon when the window focus changes:
+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
(function() {
2+
var _currentDirectory = (function () {
3+
var _url;
4+
var lines = new Error().stack.split('\n');
5+
function lookupUrl() {
6+
if (lines.length > 2) {
7+
var match = lines[1].match(/^\s+at (.+):\d+:\d+$/);
8+
// Chrome.
9+
if (match) return match[1];
10+
// Chrome nested eval case.
11+
match = lines[1].match(/^\s+at eval [(](.+):\d+:\d+[)]$/);
12+
if (match) return match[1];
13+
// Edge.
14+
match = lines[1].match(/^\s+at.+\((.+):\d+:\d+\)$/);
15+
if (match) return match[1];
16+
// Firefox.
17+
match = lines[0].match(/[<][@](.+):\d+:\d+$/)
18+
if (match) return match[1];
19+
}
20+
// Safari.
21+
return lines[0].match(/(.+):\d+:\d+$/)[1];
22+
}
23+
_url = lookupUrl();
24+
var lastSlash = _url.lastIndexOf('/');
25+
if (lastSlash == -1) return _url;
26+
var currentDirectory = _url.substring(0, lastSlash + 1);
27+
return currentDirectory;
28+
})();
29+
30+
var baseUrl = (function () {
31+
// Attempt to detect --precompiled mode for tests, and set the base url
32+
// appropriately, otherwise set it to '/'.
33+
var pathParts = location.pathname.split("/");
34+
if (pathParts[0] == "") {
35+
pathParts.shift();
36+
}
37+
if (pathParts.length > 1 && pathParts[1] == "test") {
38+
return "/" + pathParts.slice(0, 2).join("/") + "/";
39+
}
40+
// Attempt to detect base url using <base href> html tag
41+
// base href should start and end with "/"
42+
if (typeof document !== 'undefined') {
43+
var el = document.getElementsByTagName('base');
44+
if (el && el[0] && el[0].getAttribute("href") && el[0].getAttribute
45+
("href").startsWith("/") && el[0].getAttribute("href").endsWith("/")){
46+
return el[0].getAttribute("href");
47+
}
48+
}
49+
// return default value
50+
return "/";
51+
}());
52+
53+
54+
var mapperUri = baseUrl + "packages/build_web_compilers/src/" +
55+
"dev_compiler_stack_trace/stack_trace_mapper.dart.js";
56+
var requireUri = baseUrl +
57+
"packages/build_web_compilers/src/dev_compiler/require.js";
58+
var mainUri = _currentDirectory + "background.dart.bootstrap";
59+
60+
if (typeof document != 'undefined') {
61+
var el = document.createElement("script");
62+
el.defer = true;
63+
el.async = false;
64+
el.src = mapperUri;
65+
document.head.appendChild(el);
66+
67+
el = document.createElement("script");
68+
el.defer = true;
69+
el.async = false;
70+
el.src = requireUri;
71+
el.setAttribute("data-main", mainUri);
72+
document.head.appendChild(el);
73+
} else {
74+
importScripts(mapperUri, requireUri);
75+
require.config({
76+
baseUrl: baseUrl,
77+
});
78+
// TODO: update bootstrap code to take argument - dart-lang/build#1115
79+
window = self;
80+
require([mainUri + '.js']);
81+
}
82+
})();

dwds/debug_extension/web_api/chrome_browser_action.dart

+8-5
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,18 @@
44

55
import 'package:js/js.dart';
66

7-
@JS()
7+
@JS('chrome.browserAction')
88
class ChromeBrowserAction {
9-
@JS('chrome.browserAction.onClicked.addListener')
10-
external static void onClickedAddListener(Function callback);
11-
12-
@JS('chrome.browserAction.setIcon')
9+
@JS('setIcon')
1310
external static void setIcon(IconInfo iconInfo);
1411
}
1512

13+
@JS('chrome.browserAction.onClicked')
14+
class ChromeBrowserActionOnClicked {
15+
@JS('addListener')
16+
external static void addListener(Function callback);
17+
}
18+
1619
@JS()
1720
@anonymous
1821
class IconInfo {

dwds/debug_extension/web_api/chrome_debugger.dart

+16-10
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,32 @@
44

55
import 'package:js/js.dart';
66

7-
@JS()
7+
@JS('chrome.debugger')
88
class ChromeDebugger {
9-
@JS('chrome.debugger.attach')
9+
@JS('attach')
1010
external static void attach(
1111
Debuggee target, String requiredVersion, Function callback);
1212

13-
@JS('chrome.debugger.detach')
13+
@JS('detach')
1414
external static void detach(Debuggee target, Function callback);
1515

16-
@JS('chrome.debugger.onDetach.addListener')
17-
external static dynamic onDetachAddListener(Function callback);
18-
19-
@JS('chrome.debugger.onEvent.addListener')
20-
external static dynamic onEventAddListener(Function callback);
21-
22-
@JS('chrome.debugger.sendCommand')
16+
@JS('sendCommand')
2317
external static void sendCommand(
2418
Debuggee target, String method, Object? commandParams, Function callback);
2519
}
2620

21+
@JS('chrome.debugger.onDetach')
22+
class ChromeDebuggerOnDetach {
23+
@JS('addListener')
24+
external static dynamic addListener(Function callback);
25+
}
26+
27+
@JS('chrome.debugger.onEvent')
28+
class ChromeDebuggerOnEvent {
29+
@JS('addListener')
30+
external static dynamic addListener(Function callback);
31+
}
32+
2733
@JS()
2834
@anonymous
2935
class Debuggee {

0 commit comments

Comments
 (0)