MCPcopy Index your code
hub / github.com/nodejs/node / generate_injection

Function generate_injection

deps/v8/tools/callstats.py:86–129  ·  view source on GitHub ↗
(f, sites, refreshes=0)

Source from the content-addressed store, hash-verified

84
85
86def generate_injection(f, sites, refreshes=0):
87 print("""\
88(function() {
89 var s = window.sessionStorage.getItem("refreshCounter");
90 var refreshTotal = """, refreshes, """;
91 var refreshCounter = s ? parseInt(s) : refreshTotal;
92 var refreshId = refreshTotal - refreshCounter;
93 if (refreshCounter > 0) {
94 window.sessionStorage.setItem("refreshCounter", refreshCounter-1);
95 }
96 function match(url, item) {
97 if ('regexp' in item) { return url.match(item.regexp) !== null };
98 var url_wanted = item.url;
99 /* Allow automatic redirections from http to https. */
100 if (url_wanted.startsWith("http://") && url.startsWith("https://")) {
101 url_wanted = "https://" + url_wanted.substr(7);
102 }
103 return url.startsWith(url_wanted);
104 };
105 function onLoad(url) {
106 for (var item of sites) {
107 if (!match(url, item)) continue;
108 var timeout = 'timeline' in item ? 2000 * item.timeline
109 : 'timeout' in item ? 1000 * (item.timeout - 3)
110 : 10000;
111 console.log("Setting time out of " + timeout + " for: " + url);
112 window.setTimeout(function() {
113 console.log("Time is out for: " + url);
114 var msg = "STATS: (" + refreshId + ") " + url;
115 %GetAndResetRuntimeCallStats(1, msg);
116 if (refreshCounter > 0) {
117 console.log(
118 "Refresh counter is " + refreshCounter + ", refreshing: " + url);
119 window.location.reload();
120 }
121 }, timeout);
122 return;
123 }
124 console.log("Ignoring: " + url);
125 };
126 var sites =
127 """, json.dumps(sites), """;
128 onLoad(window.location.href);
129})();""", file=f)
130
131def get_chrome_flags(js_flags, user_data_dir, arg_delimiter=""):
132 return [

Callers 1

start_replay_serverFunction · 0.85

Calls 1

printFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…