id
int32 0
58k
| repo
stringlengths 5
67
| path
stringlengths 4
116
| func_name
stringlengths 0
58
| original_string
stringlengths 52
373k
| language
stringclasses 1
value | code
stringlengths 52
373k
| code_tokens
list | docstring
stringlengths 4
11.8k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 86
226
|
|---|---|---|---|---|---|---|---|---|---|---|---|
17,700
|
google/tracing-framework
|
extensions/wtf-injector-firefox/lib/main.js
|
releaseMemoryObserver
|
function releaseMemoryObserver() {
// Only disable on last use.
if (!memoryObservationCount) {
return;
}
--memoryObservationCount;
if (memoryObservationCount) {
return;
}
// Unlisten for events.
Services.obs.removeObserver(
handleMemoryEvent, 'garbage-collection-statistics', false);
// Reset memory notification to its original state.
resetTemporaryPreference('javascript.options.mem.notify');
}
|
javascript
|
function releaseMemoryObserver() {
// Only disable on last use.
if (!memoryObservationCount) {
return;
}
--memoryObservationCount;
if (memoryObservationCount) {
return;
}
// Unlisten for events.
Services.obs.removeObserver(
handleMemoryEvent, 'garbage-collection-statistics', false);
// Reset memory notification to its original state.
resetTemporaryPreference('javascript.options.mem.notify');
}
|
[
"function",
"releaseMemoryObserver",
"(",
")",
"{",
"// Only disable on last use.",
"if",
"(",
"!",
"memoryObservationCount",
")",
"{",
"return",
";",
"}",
"--",
"memoryObservationCount",
";",
"if",
"(",
"memoryObservationCount",
")",
"{",
"return",
";",
"}",
"// Unlisten for events.",
"Services",
".",
"obs",
".",
"removeObserver",
"(",
"handleMemoryEvent",
",",
"'garbage-collection-statistics'",
",",
"false",
")",
";",
"// Reset memory notification to its original state.",
"resetTemporaryPreference",
"(",
"'javascript.options.mem.notify'",
")",
";",
"}"
] |
Releases a reference to the memory observer, stopping it if this was the
last reference.
|
[
"Releases",
"a",
"reference",
"to",
"the",
"memory",
"observer",
"stopping",
"it",
"if",
"this",
"was",
"the",
"last",
"reference",
"."
] |
495ced98de99a5895e484b2e09771edb42d3c7ab
|
https://github.com/google/tracing-framework/blob/495ced98de99a5895e484b2e09771edb42d3c7ab/extensions/wtf-injector-firefox/lib/main.js#L168-L184
|
17,701
|
google/tracing-framework
|
extensions/wtf-injector-firefox/lib/main.js
|
getCanonicalUrl
|
function getCanonicalUrl(url) {
// Trim the #fragment. We are unique to query string, though.
var hashIndex = url.indexOf('#');
if (hashIndex != -1) {
url = url.substring(0, hashIndex);
}
return url;
}
|
javascript
|
function getCanonicalUrl(url) {
// Trim the #fragment. We are unique to query string, though.
var hashIndex = url.indexOf('#');
if (hashIndex != -1) {
url = url.substring(0, hashIndex);
}
return url;
}
|
[
"function",
"getCanonicalUrl",
"(",
"url",
")",
"{",
"// Trim the #fragment. We are unique to query string, though.",
"var",
"hashIndex",
"=",
"url",
".",
"indexOf",
"(",
"'#'",
")",
";",
"if",
"(",
"hashIndex",
"!=",
"-",
"1",
")",
"{",
"url",
"=",
"url",
".",
"substring",
"(",
"0",
",",
"hashIndex",
")",
";",
"}",
"return",
"url",
";",
"}"
] |
Canonicalizes a URL so that it can be matched against.
@param {string} url URL.
@return {string} Canonical URL.
|
[
"Canonicalizes",
"a",
"URL",
"so",
"that",
"it",
"can",
"be",
"matched",
"against",
"."
] |
495ced98de99a5895e484b2e09771edb42d3c7ab
|
https://github.com/google/tracing-framework/blob/495ced98de99a5895e484b2e09771edb42d3c7ab/extensions/wtf-injector-firefox/lib/main.js#L199-L206
|
17,702
|
google/tracing-framework
|
extensions/wtf-injector-firefox/lib/main.js
|
function(url, worker) {
/**
* Page URL.
* @type {string}
*/
this.url = url;
/**
* Firefox tab handle.
* @type {!Tab}
*/
this.tab = worker.tab;
/**
* Page worker running the content script.
* @type {!Worker}
*/
this.worker = worker;
/**
* Pending debugger records.
* These are batched up so that we don't throw too many messages at the page.
* @type {!Array.<!Object>}
* @private
*/
this.debuggerRecords_ = [];
/**
* Periodic timer to transmit debugger data.
* @type {number}
* @private
*/
this.debuggerTransmitId_ = timers.setInterval((function() {
var records = this.debuggerRecords_;
if (records.length) {
this.debuggerRecords_ = [];
this.worker.port.emit('extension-event', JSON.stringify({
'command': 'debugger_data',
'records': records
}));
}
}).bind(this), 1000);
// Start watching GC events.
acquireMemoryObserver();
}
|
javascript
|
function(url, worker) {
/**
* Page URL.
* @type {string}
*/
this.url = url;
/**
* Firefox tab handle.
* @type {!Tab}
*/
this.tab = worker.tab;
/**
* Page worker running the content script.
* @type {!Worker}
*/
this.worker = worker;
/**
* Pending debugger records.
* These are batched up so that we don't throw too many messages at the page.
* @type {!Array.<!Object>}
* @private
*/
this.debuggerRecords_ = [];
/**
* Periodic timer to transmit debugger data.
* @type {number}
* @private
*/
this.debuggerTransmitId_ = timers.setInterval((function() {
var records = this.debuggerRecords_;
if (records.length) {
this.debuggerRecords_ = [];
this.worker.port.emit('extension-event', JSON.stringify({
'command': 'debugger_data',
'records': records
}));
}
}).bind(this), 1000);
// Start watching GC events.
acquireMemoryObserver();
}
|
[
"function",
"(",
"url",
",",
"worker",
")",
"{",
"/**\n * Page URL.\n * @type {string}\n */",
"this",
".",
"url",
"=",
"url",
";",
"/**\n * Firefox tab handle.\n * @type {!Tab}\n */",
"this",
".",
"tab",
"=",
"worker",
".",
"tab",
";",
"/**\n * Page worker running the content script.\n * @type {!Worker}\n */",
"this",
".",
"worker",
"=",
"worker",
";",
"/**\n * Pending debugger records.\n * These are batched up so that we don't throw too many messages at the page.\n * @type {!Array.<!Object>}\n * @private\n */",
"this",
".",
"debuggerRecords_",
"=",
"[",
"]",
";",
"/**\n * Periodic timer to transmit debugger data.\n * @type {number}\n * @private\n */",
"this",
".",
"debuggerTransmitId_",
"=",
"timers",
".",
"setInterval",
"(",
"(",
"function",
"(",
")",
"{",
"var",
"records",
"=",
"this",
".",
"debuggerRecords_",
";",
"if",
"(",
"records",
".",
"length",
")",
"{",
"this",
".",
"debuggerRecords_",
"=",
"[",
"]",
";",
"this",
".",
"worker",
".",
"port",
".",
"emit",
"(",
"'extension-event'",
",",
"JSON",
".",
"stringify",
"(",
"{",
"'command'",
":",
"'debugger_data'",
",",
"'records'",
":",
"records",
"}",
")",
")",
";",
"}",
"}",
")",
".",
"bind",
"(",
"this",
")",
",",
"1000",
")",
";",
"// Start watching GC events.",
"acquireMemoryObserver",
"(",
")",
";",
"}"
] |
Injected tab wrapper.
@param {string} url Canonical page URL.
@param {!Worker} worker Content script worker.
@constructor
|
[
"Injected",
"tab",
"wrapper",
"."
] |
495ced98de99a5895e484b2e09771edb42d3c7ab
|
https://github.com/google/tracing-framework/blob/495ced98de99a5895e484b2e09771edb42d3c7ab/extensions/wtf-injector-firefox/lib/main.js#L253-L298
|
|
17,703
|
google/tracing-framework
|
extensions/wtf-injector-firefox/lib/main.js
|
enableInjectionForUrl
|
function enableInjectionForUrl(url) {
var url = getCanonicalUrl(url);
if (activePageMods[url]) {
return;
}
// Enable injection.
setPagePreference(url, 'enabled', true);
// Grab current options. Note that if they change we need to re-enable
// injection to update the pagemod.
var pagePrefs = getPagePreferences(url);
var storedOptions = {};
try {
storedOptions = JSON.parse(pagePrefs.options);
} catch (e) {
}
// Override defaults with specified values.
// Except for a few that we don't want to track across session.
var pageOptions = {
// The presence of this indicates that the options come from the injector.
'wtf.injector': true,
// Larger buffers mean less waste when doing recordings with a large amount
// of data (like WebGL captures).
'wtf.trace.session.bufferSize': 6 * 1024 * 1024,
// This is pretty excessive, but keeps us from truncating WebGL traces.
// After this limit the file likely won't load due to v8 memory limits
// anyway.
'wtf.trace.session.maximumMemoryUsage': 512 * 1024 * 1024,
// TODO(benvanik): endpoints
// 'wtf.hud.app.mode': '',
// 'wtf.hud.app.endpoint': '',
'wtf.trace.provider.firefoxDebug.present': true,
// Turn on embed remote images by default.
// When we have the UI in the extension and can fetch non-origin URLs this
// won't be required. Note that we allow the page to override this setting.
'wtf.trace.provider.webgl.embedRemoteImages': true
};
for (var key in storedOptions) {
switch (key) {
case 'wtf.injector':
case 'wtf.hud.app.mode':
case 'wtf.hud.app.endpoint':
case 'wtf.addons':
case 'wtf.trace.provider.firefoxDebug.present':
continue;
}
pageOptions[key] = storedOptions[key];
}
// Create a page mod for the given URLs.
var mod = pageMod.PageMod({
include: [
url,
url + '#*'
],
contentScriptFile: self.data.url('content-script.js'),
contentScriptWhen: 'start',
contentScriptOptions: {
// Accessible as self.options in the content script.
wtfScriptContents: wtfScriptContents,
wtfOptions: pageOptions
},
attachTo: 'top',
onAttach: function(worker) {
var injectedTab = new InjectedTab(url, worker);
injectedTabs.push(injectedTab);
console.log('added worker for ' + url);
worker.port.on('page-event', function(data) {
injectedTab.dispatchEvent(JSON.parse(data));
});
worker.on('detach', function() {
console.log('detached worker for ' + url);
injectedTab.dispose();
for (var n = 0; n < injectedTabs.length; n++) {
if (injectedTabs[n].worker == worker) {
injectedTabs.splice(n, 1);
break;
}
}
});
}
});
activePageMods[url] = mod;
// Find tabs with the URL and reload.
reloadTabsMatchingUrl(url);
}
|
javascript
|
function enableInjectionForUrl(url) {
var url = getCanonicalUrl(url);
if (activePageMods[url]) {
return;
}
// Enable injection.
setPagePreference(url, 'enabled', true);
// Grab current options. Note that if they change we need to re-enable
// injection to update the pagemod.
var pagePrefs = getPagePreferences(url);
var storedOptions = {};
try {
storedOptions = JSON.parse(pagePrefs.options);
} catch (e) {
}
// Override defaults with specified values.
// Except for a few that we don't want to track across session.
var pageOptions = {
// The presence of this indicates that the options come from the injector.
'wtf.injector': true,
// Larger buffers mean less waste when doing recordings with a large amount
// of data (like WebGL captures).
'wtf.trace.session.bufferSize': 6 * 1024 * 1024,
// This is pretty excessive, but keeps us from truncating WebGL traces.
// After this limit the file likely won't load due to v8 memory limits
// anyway.
'wtf.trace.session.maximumMemoryUsage': 512 * 1024 * 1024,
// TODO(benvanik): endpoints
// 'wtf.hud.app.mode': '',
// 'wtf.hud.app.endpoint': '',
'wtf.trace.provider.firefoxDebug.present': true,
// Turn on embed remote images by default.
// When we have the UI in the extension and can fetch non-origin URLs this
// won't be required. Note that we allow the page to override this setting.
'wtf.trace.provider.webgl.embedRemoteImages': true
};
for (var key in storedOptions) {
switch (key) {
case 'wtf.injector':
case 'wtf.hud.app.mode':
case 'wtf.hud.app.endpoint':
case 'wtf.addons':
case 'wtf.trace.provider.firefoxDebug.present':
continue;
}
pageOptions[key] = storedOptions[key];
}
// Create a page mod for the given URLs.
var mod = pageMod.PageMod({
include: [
url,
url + '#*'
],
contentScriptFile: self.data.url('content-script.js'),
contentScriptWhen: 'start',
contentScriptOptions: {
// Accessible as self.options in the content script.
wtfScriptContents: wtfScriptContents,
wtfOptions: pageOptions
},
attachTo: 'top',
onAttach: function(worker) {
var injectedTab = new InjectedTab(url, worker);
injectedTabs.push(injectedTab);
console.log('added worker for ' + url);
worker.port.on('page-event', function(data) {
injectedTab.dispatchEvent(JSON.parse(data));
});
worker.on('detach', function() {
console.log('detached worker for ' + url);
injectedTab.dispose();
for (var n = 0; n < injectedTabs.length; n++) {
if (injectedTabs[n].worker == worker) {
injectedTabs.splice(n, 1);
break;
}
}
});
}
});
activePageMods[url] = mod;
// Find tabs with the URL and reload.
reloadTabsMatchingUrl(url);
}
|
[
"function",
"enableInjectionForUrl",
"(",
"url",
")",
"{",
"var",
"url",
"=",
"getCanonicalUrl",
"(",
"url",
")",
";",
"if",
"(",
"activePageMods",
"[",
"url",
"]",
")",
"{",
"return",
";",
"}",
"// Enable injection.",
"setPagePreference",
"(",
"url",
",",
"'enabled'",
",",
"true",
")",
";",
"// Grab current options. Note that if they change we need to re-enable",
"// injection to update the pagemod.",
"var",
"pagePrefs",
"=",
"getPagePreferences",
"(",
"url",
")",
";",
"var",
"storedOptions",
"=",
"{",
"}",
";",
"try",
"{",
"storedOptions",
"=",
"JSON",
".",
"parse",
"(",
"pagePrefs",
".",
"options",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"}",
"// Override defaults with specified values.",
"// Except for a few that we don't want to track across session.",
"var",
"pageOptions",
"=",
"{",
"// The presence of this indicates that the options come from the injector.",
"'wtf.injector'",
":",
"true",
",",
"// Larger buffers mean less waste when doing recordings with a large amount",
"// of data (like WebGL captures).",
"'wtf.trace.session.bufferSize'",
":",
"6",
"*",
"1024",
"*",
"1024",
",",
"// This is pretty excessive, but keeps us from truncating WebGL traces.",
"// After this limit the file likely won't load due to v8 memory limits",
"// anyway.",
"'wtf.trace.session.maximumMemoryUsage'",
":",
"512",
"*",
"1024",
"*",
"1024",
",",
"// TODO(benvanik): endpoints",
"// 'wtf.hud.app.mode': '',",
"// 'wtf.hud.app.endpoint': '',",
"'wtf.trace.provider.firefoxDebug.present'",
":",
"true",
",",
"// Turn on embed remote images by default.",
"// When we have the UI in the extension and can fetch non-origin URLs this",
"// won't be required. Note that we allow the page to override this setting.",
"'wtf.trace.provider.webgl.embedRemoteImages'",
":",
"true",
"}",
";",
"for",
"(",
"var",
"key",
"in",
"storedOptions",
")",
"{",
"switch",
"(",
"key",
")",
"{",
"case",
"'wtf.injector'",
":",
"case",
"'wtf.hud.app.mode'",
":",
"case",
"'wtf.hud.app.endpoint'",
":",
"case",
"'wtf.addons'",
":",
"case",
"'wtf.trace.provider.firefoxDebug.present'",
":",
"continue",
";",
"}",
"pageOptions",
"[",
"key",
"]",
"=",
"storedOptions",
"[",
"key",
"]",
";",
"}",
"// Create a page mod for the given URLs.",
"var",
"mod",
"=",
"pageMod",
".",
"PageMod",
"(",
"{",
"include",
":",
"[",
"url",
",",
"url",
"+",
"'#*'",
"]",
",",
"contentScriptFile",
":",
"self",
".",
"data",
".",
"url",
"(",
"'content-script.js'",
")",
",",
"contentScriptWhen",
":",
"'start'",
",",
"contentScriptOptions",
":",
"{",
"// Accessible as self.options in the content script.",
"wtfScriptContents",
":",
"wtfScriptContents",
",",
"wtfOptions",
":",
"pageOptions",
"}",
",",
"attachTo",
":",
"'top'",
",",
"onAttach",
":",
"function",
"(",
"worker",
")",
"{",
"var",
"injectedTab",
"=",
"new",
"InjectedTab",
"(",
"url",
",",
"worker",
")",
";",
"injectedTabs",
".",
"push",
"(",
"injectedTab",
")",
";",
"console",
".",
"log",
"(",
"'added worker for '",
"+",
"url",
")",
";",
"worker",
".",
"port",
".",
"on",
"(",
"'page-event'",
",",
"function",
"(",
"data",
")",
"{",
"injectedTab",
".",
"dispatchEvent",
"(",
"JSON",
".",
"parse",
"(",
"data",
")",
")",
";",
"}",
")",
";",
"worker",
".",
"on",
"(",
"'detach'",
",",
"function",
"(",
")",
"{",
"console",
".",
"log",
"(",
"'detached worker for '",
"+",
"url",
")",
";",
"injectedTab",
".",
"dispose",
"(",
")",
";",
"for",
"(",
"var",
"n",
"=",
"0",
";",
"n",
"<",
"injectedTabs",
".",
"length",
";",
"n",
"++",
")",
"{",
"if",
"(",
"injectedTabs",
"[",
"n",
"]",
".",
"worker",
"==",
"worker",
")",
"{",
"injectedTabs",
".",
"splice",
"(",
"n",
",",
"1",
")",
";",
"break",
";",
"}",
"}",
"}",
")",
";",
"}",
"}",
")",
";",
"activePageMods",
"[",
"url",
"]",
"=",
"mod",
";",
"// Find tabs with the URL and reload.",
"reloadTabsMatchingUrl",
"(",
"url",
")",
";",
"}"
] |
Enables injection for a URL and reloads tabs with that URL.
@param {string} url URL to activate on.
|
[
"Enables",
"injection",
"for",
"a",
"URL",
"and",
"reloads",
"tabs",
"with",
"that",
"URL",
"."
] |
495ced98de99a5895e484b2e09771edb42d3c7ab
|
https://github.com/google/tracing-framework/blob/495ced98de99a5895e484b2e09771edb42d3c7ab/extensions/wtf-injector-firefox/lib/main.js#L362-L457
|
17,704
|
google/tracing-framework
|
extensions/wtf-injector-firefox/lib/main.js
|
disableInjectionForUrl
|
function disableInjectionForUrl(url, opt_skipReload) {
var url = getCanonicalUrl(url);
// Disable injection.
setPagePreference(url, 'enabled', false);
// Find existing page mod and disable.
// This will detach workers in those tabs.
var mod = activePageMods[url];
if (!mod) {
return;
}
mod.destroy();
delete activePageMods[url];
if (!opt_skipReload) {
// Find tabs with the URL and reload.
reloadTabsMatchingUrl(url);
}
}
|
javascript
|
function disableInjectionForUrl(url, opt_skipReload) {
var url = getCanonicalUrl(url);
// Disable injection.
setPagePreference(url, 'enabled', false);
// Find existing page mod and disable.
// This will detach workers in those tabs.
var mod = activePageMods[url];
if (!mod) {
return;
}
mod.destroy();
delete activePageMods[url];
if (!opt_skipReload) {
// Find tabs with the URL and reload.
reloadTabsMatchingUrl(url);
}
}
|
[
"function",
"disableInjectionForUrl",
"(",
"url",
",",
"opt_skipReload",
")",
"{",
"var",
"url",
"=",
"getCanonicalUrl",
"(",
"url",
")",
";",
"// Disable injection.",
"setPagePreference",
"(",
"url",
",",
"'enabled'",
",",
"false",
")",
";",
"// Find existing page mod and disable.",
"// This will detach workers in those tabs.",
"var",
"mod",
"=",
"activePageMods",
"[",
"url",
"]",
";",
"if",
"(",
"!",
"mod",
")",
"{",
"return",
";",
"}",
"mod",
".",
"destroy",
"(",
")",
";",
"delete",
"activePageMods",
"[",
"url",
"]",
";",
"if",
"(",
"!",
"opt_skipReload",
")",
"{",
"// Find tabs with the URL and reload.",
"reloadTabsMatchingUrl",
"(",
"url",
")",
";",
"}",
"}"
] |
Disables injection for a URL and reloads tabs with that URL.
@param {string} url URL to activate on.
@param {boolean=} opt_skipReload Whether to skip reloading of pages.
|
[
"Disables",
"injection",
"for",
"a",
"URL",
"and",
"reloads",
"tabs",
"with",
"that",
"URL",
"."
] |
495ced98de99a5895e484b2e09771edb42d3c7ab
|
https://github.com/google/tracing-framework/blob/495ced98de99a5895e484b2e09771edb42d3c7ab/extensions/wtf-injector-firefox/lib/main.js#L465-L484
|
17,705
|
google/tracing-framework
|
extensions/wtf-injector-firefox/lib/main.js
|
toggleInjectionForActiveTab
|
function toggleInjectionForActiveTab() {
var url = tabs.activeTab.url;
if (!isInjectionEnabledForUrl(url)) {
enableInjectionForUrl(url);
} else {
disableInjectionForUrl(url);
}
}
|
javascript
|
function toggleInjectionForActiveTab() {
var url = tabs.activeTab.url;
if (!isInjectionEnabledForUrl(url)) {
enableInjectionForUrl(url);
} else {
disableInjectionForUrl(url);
}
}
|
[
"function",
"toggleInjectionForActiveTab",
"(",
")",
"{",
"var",
"url",
"=",
"tabs",
".",
"activeTab",
".",
"url",
";",
"if",
"(",
"!",
"isInjectionEnabledForUrl",
"(",
"url",
")",
")",
"{",
"enableInjectionForUrl",
"(",
"url",
")",
";",
"}",
"else",
"{",
"disableInjectionForUrl",
"(",
"url",
")",
";",
"}",
"}"
] |
Toggles injection for the currently active tab URL.
|
[
"Toggles",
"injection",
"for",
"the",
"currently",
"active",
"tab",
"URL",
"."
] |
495ced98de99a5895e484b2e09771edb42d3c7ab
|
https://github.com/google/tracing-framework/blob/495ced98de99a5895e484b2e09771edb42d3c7ab/extensions/wtf-injector-firefox/lib/main.js#L490-L497
|
17,706
|
google/tracing-framework
|
extensions/wtf-injector-firefox/lib/main.js
|
resetOptionsForActiveTab
|
function resetOptionsForActiveTab() {
var url = getCanonicalUrl(tabs.activeTab.url);
setPagePreference(url, 'options', '');
if (isInjectionEnabledForUrl(url)) {
disableInjectionForUrl(url, true);
enableInjectionForUrl(url);
}
}
|
javascript
|
function resetOptionsForActiveTab() {
var url = getCanonicalUrl(tabs.activeTab.url);
setPagePreference(url, 'options', '');
if (isInjectionEnabledForUrl(url)) {
disableInjectionForUrl(url, true);
enableInjectionForUrl(url);
}
}
|
[
"function",
"resetOptionsForActiveTab",
"(",
")",
"{",
"var",
"url",
"=",
"getCanonicalUrl",
"(",
"tabs",
".",
"activeTab",
".",
"url",
")",
";",
"setPagePreference",
"(",
"url",
",",
"'options'",
",",
"''",
")",
";",
"if",
"(",
"isInjectionEnabledForUrl",
"(",
"url",
")",
")",
"{",
"disableInjectionForUrl",
"(",
"url",
",",
"true",
")",
";",
"enableInjectionForUrl",
"(",
"url",
")",
";",
"}",
"}"
] |
Resets WTF options for the currently active tab URL.
|
[
"Resets",
"WTF",
"options",
"for",
"the",
"currently",
"active",
"tab",
"URL",
"."
] |
495ced98de99a5895e484b2e09771edb42d3c7ab
|
https://github.com/google/tracing-framework/blob/495ced98de99a5895e484b2e09771edb42d3c7ab/extensions/wtf-injector-firefox/lib/main.js#L503-L510
|
17,707
|
google/tracing-framework
|
extensions/wtf-injector-firefox/lib/main.js
|
setupContextMenu
|
function setupContextMenu() {
var enableContextMenuItem = contextMenu.Item({
label: 'Enable For This URL',
data: 'toggle',
contentScript:
"self.on('context', function(node) {" +
" var hasWtf = !!document.querySelector('.wtf_a');" +
" return !hasWtf ? 'Enable For This URL' : 'Disable For This URL';" +
"});"
});
var resetSettingsContextMenuItem = contextMenu.Item({
label: 'Reset Settings For This URL',
data: 'reset'
});
var showUiContextMenuItem = contextMenu.Item({
label: 'Show UI',
data: 'show_ui'
});
var rootContextMenuItem = contextMenu.Menu({
label: 'Tracing Framework',
items: [
enableContextMenuItem,
resetSettingsContextMenuItem,
contextMenu.Separator(),
showUiContextMenuItem
],
contentScript:
"self.on('click', function(node, data) {" +
" self.postMessage(data);" +
"});",
onMessage: function(action) {
switch (action) {
case 'toggle':
toggleInjectionForActiveTab();
break;
case 'reset':
resetOptionsForActiveTab();
break;
case 'show_ui':
showUi();
break;
}
}
});
}
|
javascript
|
function setupContextMenu() {
var enableContextMenuItem = contextMenu.Item({
label: 'Enable For This URL',
data: 'toggle',
contentScript:
"self.on('context', function(node) {" +
" var hasWtf = !!document.querySelector('.wtf_a');" +
" return !hasWtf ? 'Enable For This URL' : 'Disable For This URL';" +
"});"
});
var resetSettingsContextMenuItem = contextMenu.Item({
label: 'Reset Settings For This URL',
data: 'reset'
});
var showUiContextMenuItem = contextMenu.Item({
label: 'Show UI',
data: 'show_ui'
});
var rootContextMenuItem = contextMenu.Menu({
label: 'Tracing Framework',
items: [
enableContextMenuItem,
resetSettingsContextMenuItem,
contextMenu.Separator(),
showUiContextMenuItem
],
contentScript:
"self.on('click', function(node, data) {" +
" self.postMessage(data);" +
"});",
onMessage: function(action) {
switch (action) {
case 'toggle':
toggleInjectionForActiveTab();
break;
case 'reset':
resetOptionsForActiveTab();
break;
case 'show_ui':
showUi();
break;
}
}
});
}
|
[
"function",
"setupContextMenu",
"(",
")",
"{",
"var",
"enableContextMenuItem",
"=",
"contextMenu",
".",
"Item",
"(",
"{",
"label",
":",
"'Enable For This URL'",
",",
"data",
":",
"'toggle'",
",",
"contentScript",
":",
"\"self.on('context', function(node) {\"",
"+",
"\" var hasWtf = !!document.querySelector('.wtf_a');\"",
"+",
"\" return !hasWtf ? 'Enable For This URL' : 'Disable For This URL';\"",
"+",
"\"});\"",
"}",
")",
";",
"var",
"resetSettingsContextMenuItem",
"=",
"contextMenu",
".",
"Item",
"(",
"{",
"label",
":",
"'Reset Settings For This URL'",
",",
"data",
":",
"'reset'",
"}",
")",
";",
"var",
"showUiContextMenuItem",
"=",
"contextMenu",
".",
"Item",
"(",
"{",
"label",
":",
"'Show UI'",
",",
"data",
":",
"'show_ui'",
"}",
")",
";",
"var",
"rootContextMenuItem",
"=",
"contextMenu",
".",
"Menu",
"(",
"{",
"label",
":",
"'Tracing Framework'",
",",
"items",
":",
"[",
"enableContextMenuItem",
",",
"resetSettingsContextMenuItem",
",",
"contextMenu",
".",
"Separator",
"(",
")",
",",
"showUiContextMenuItem",
"]",
",",
"contentScript",
":",
"\"self.on('click', function(node, data) {\"",
"+",
"\" self.postMessage(data);\"",
"+",
"\"});\"",
",",
"onMessage",
":",
"function",
"(",
"action",
")",
"{",
"switch",
"(",
"action",
")",
"{",
"case",
"'toggle'",
":",
"toggleInjectionForActiveTab",
"(",
")",
";",
"break",
";",
"case",
"'reset'",
":",
"resetOptionsForActiveTab",
"(",
")",
";",
"break",
";",
"case",
"'show_ui'",
":",
"showUi",
"(",
")",
";",
"break",
";",
"}",
"}",
"}",
")",
";",
"}"
] |
Sets up the page context menu.
|
[
"Sets",
"up",
"the",
"page",
"context",
"menu",
"."
] |
495ced98de99a5895e484b2e09771edb42d3c7ab
|
https://github.com/google/tracing-framework/blob/495ced98de99a5895e484b2e09771edb42d3c7ab/extensions/wtf-injector-firefox/lib/main.js#L525-L569
|
17,708
|
google/tracing-framework
|
extensions/wtf-injector-firefox/lib/main.js
|
setupAddonBarWidget
|
function setupAddonBarWidget() {
var panel = panels.Panel({
width: 200,
height: 128,
contentURL: self.data.url('widget-panel.html'),
contentScriptFile: self.data.url('widget-panel.js')
});
panel.on('show', function() {
var url = getCanonicalUrl(tabs.activeTab.url);
if (!url.length) {
panel.port.emit('show', null);
} else {
panel.port.emit('show', {
'enabled': isInjectionEnabledForUrl(url)
});
}
});
panel.port.on('perform', function(action) {
switch (action) {
case 'toggle':
toggleInjectionForActiveTab();
panel.hide();
break;
case 'reset':
resetOptionsForActiveTab();
panel.hide();
break;
case 'show_ui':
showUi();
panel.hide();
break;
}
});
var widget = widgets.Widget({
id: 'wtf-toggle',
label: 'Toggle Web Tracing Framework',
contentURL: self.data.url('widget.html'),
contentScriptFile: self.data.url('widget.js'),
panel: panel
});
// Update the widget icon when the URL changes.
function tabChanged() {
var url = getCanonicalUrl(tabs.activeTab.url);
widget.port.emit('update', {
'enabled': url.length ? isInjectionEnabledForUrl(url) : false
});
};
tabs.on('open', tabChanged);
tabs.on('close', tabChanged);
tabs.on('ready', tabChanged);
tabs.on('activate', tabChanged);
tabs.on('deactivate', tabChanged);
}
|
javascript
|
function setupAddonBarWidget() {
var panel = panels.Panel({
width: 200,
height: 128,
contentURL: self.data.url('widget-panel.html'),
contentScriptFile: self.data.url('widget-panel.js')
});
panel.on('show', function() {
var url = getCanonicalUrl(tabs.activeTab.url);
if (!url.length) {
panel.port.emit('show', null);
} else {
panel.port.emit('show', {
'enabled': isInjectionEnabledForUrl(url)
});
}
});
panel.port.on('perform', function(action) {
switch (action) {
case 'toggle':
toggleInjectionForActiveTab();
panel.hide();
break;
case 'reset':
resetOptionsForActiveTab();
panel.hide();
break;
case 'show_ui':
showUi();
panel.hide();
break;
}
});
var widget = widgets.Widget({
id: 'wtf-toggle',
label: 'Toggle Web Tracing Framework',
contentURL: self.data.url('widget.html'),
contentScriptFile: self.data.url('widget.js'),
panel: panel
});
// Update the widget icon when the URL changes.
function tabChanged() {
var url = getCanonicalUrl(tabs.activeTab.url);
widget.port.emit('update', {
'enabled': url.length ? isInjectionEnabledForUrl(url) : false
});
};
tabs.on('open', tabChanged);
tabs.on('close', tabChanged);
tabs.on('ready', tabChanged);
tabs.on('activate', tabChanged);
tabs.on('deactivate', tabChanged);
}
|
[
"function",
"setupAddonBarWidget",
"(",
")",
"{",
"var",
"panel",
"=",
"panels",
".",
"Panel",
"(",
"{",
"width",
":",
"200",
",",
"height",
":",
"128",
",",
"contentURL",
":",
"self",
".",
"data",
".",
"url",
"(",
"'widget-panel.html'",
")",
",",
"contentScriptFile",
":",
"self",
".",
"data",
".",
"url",
"(",
"'widget-panel.js'",
")",
"}",
")",
";",
"panel",
".",
"on",
"(",
"'show'",
",",
"function",
"(",
")",
"{",
"var",
"url",
"=",
"getCanonicalUrl",
"(",
"tabs",
".",
"activeTab",
".",
"url",
")",
";",
"if",
"(",
"!",
"url",
".",
"length",
")",
"{",
"panel",
".",
"port",
".",
"emit",
"(",
"'show'",
",",
"null",
")",
";",
"}",
"else",
"{",
"panel",
".",
"port",
".",
"emit",
"(",
"'show'",
",",
"{",
"'enabled'",
":",
"isInjectionEnabledForUrl",
"(",
"url",
")",
"}",
")",
";",
"}",
"}",
")",
";",
"panel",
".",
"port",
".",
"on",
"(",
"'perform'",
",",
"function",
"(",
"action",
")",
"{",
"switch",
"(",
"action",
")",
"{",
"case",
"'toggle'",
":",
"toggleInjectionForActiveTab",
"(",
")",
";",
"panel",
".",
"hide",
"(",
")",
";",
"break",
";",
"case",
"'reset'",
":",
"resetOptionsForActiveTab",
"(",
")",
";",
"panel",
".",
"hide",
"(",
")",
";",
"break",
";",
"case",
"'show_ui'",
":",
"showUi",
"(",
")",
";",
"panel",
".",
"hide",
"(",
")",
";",
"break",
";",
"}",
"}",
")",
";",
"var",
"widget",
"=",
"widgets",
".",
"Widget",
"(",
"{",
"id",
":",
"'wtf-toggle'",
",",
"label",
":",
"'Toggle Web Tracing Framework'",
",",
"contentURL",
":",
"self",
".",
"data",
".",
"url",
"(",
"'widget.html'",
")",
",",
"contentScriptFile",
":",
"self",
".",
"data",
".",
"url",
"(",
"'widget.js'",
")",
",",
"panel",
":",
"panel",
"}",
")",
";",
"// Update the widget icon when the URL changes.",
"function",
"tabChanged",
"(",
")",
"{",
"var",
"url",
"=",
"getCanonicalUrl",
"(",
"tabs",
".",
"activeTab",
".",
"url",
")",
";",
"widget",
".",
"port",
".",
"emit",
"(",
"'update'",
",",
"{",
"'enabled'",
":",
"url",
".",
"length",
"?",
"isInjectionEnabledForUrl",
"(",
"url",
")",
":",
"false",
"}",
")",
";",
"}",
";",
"tabs",
".",
"on",
"(",
"'open'",
",",
"tabChanged",
")",
";",
"tabs",
".",
"on",
"(",
"'close'",
",",
"tabChanged",
")",
";",
"tabs",
".",
"on",
"(",
"'ready'",
",",
"tabChanged",
")",
";",
"tabs",
".",
"on",
"(",
"'activate'",
",",
"tabChanged",
")",
";",
"tabs",
".",
"on",
"(",
"'deactivate'",
",",
"tabChanged",
")",
";",
"}"
] |
Sets up the addon bar widget.
|
[
"Sets",
"up",
"the",
"addon",
"bar",
"widget",
"."
] |
495ced98de99a5895e484b2e09771edb42d3c7ab
|
https://github.com/google/tracing-framework/blob/495ced98de99a5895e484b2e09771edb42d3c7ab/extensions/wtf-injector-firefox/lib/main.js#L575-L629
|
17,709
|
google/tracing-framework
|
extensions/wtf-injector-firefox/lib/main.js
|
tabChanged
|
function tabChanged() {
var url = getCanonicalUrl(tabs.activeTab.url);
widget.port.emit('update', {
'enabled': url.length ? isInjectionEnabledForUrl(url) : false
});
}
|
javascript
|
function tabChanged() {
var url = getCanonicalUrl(tabs.activeTab.url);
widget.port.emit('update', {
'enabled': url.length ? isInjectionEnabledForUrl(url) : false
});
}
|
[
"function",
"tabChanged",
"(",
")",
"{",
"var",
"url",
"=",
"getCanonicalUrl",
"(",
"tabs",
".",
"activeTab",
".",
"url",
")",
";",
"widget",
".",
"port",
".",
"emit",
"(",
"'update'",
",",
"{",
"'enabled'",
":",
"url",
".",
"length",
"?",
"isInjectionEnabledForUrl",
"(",
"url",
")",
":",
"false",
"}",
")",
";",
"}"
] |
Update the widget icon when the URL changes.
|
[
"Update",
"the",
"widget",
"icon",
"when",
"the",
"URL",
"changes",
"."
] |
495ced98de99a5895e484b2e09771edb42d3c7ab
|
https://github.com/google/tracing-framework/blob/495ced98de99a5895e484b2e09771edb42d3c7ab/extensions/wtf-injector-firefox/lib/main.js#L618-L623
|
17,710
|
google/tracing-framework
|
bin/tool-runner.js
|
prepareDebug
|
function prepareDebug() {
// Import Closure Library and deps.js.
require('../src/wtf/bootstrap/node').importClosureLibrary([
'wtf_js-deps.js'
]);
// Disable asserts unless debugging - asserts cause all code to deopt.
if (debugMode) {
goog.require('goog.asserts');
goog.asserts.assert = function(condition, opt_message) {
console.assert(condition, opt_message);
return condition;
};
} else {
goog.DEBUG = false;
goog.require('goog.asserts');
goog.asserts.assert = function(condition) {
return condition;
};
}
// Load WTF and configure options.
goog.require('wtf');
wtf.NODE = true;
goog.require('wtf.db.exports');
goog.require('wtf.db.node');
}
|
javascript
|
function prepareDebug() {
// Import Closure Library and deps.js.
require('../src/wtf/bootstrap/node').importClosureLibrary([
'wtf_js-deps.js'
]);
// Disable asserts unless debugging - asserts cause all code to deopt.
if (debugMode) {
goog.require('goog.asserts');
goog.asserts.assert = function(condition, opt_message) {
console.assert(condition, opt_message);
return condition;
};
} else {
goog.DEBUG = false;
goog.require('goog.asserts');
goog.asserts.assert = function(condition) {
return condition;
};
}
// Load WTF and configure options.
goog.require('wtf');
wtf.NODE = true;
goog.require('wtf.db.exports');
goog.require('wtf.db.node');
}
|
[
"function",
"prepareDebug",
"(",
")",
"{",
"// Import Closure Library and deps.js.",
"require",
"(",
"'../src/wtf/bootstrap/node'",
")",
".",
"importClosureLibrary",
"(",
"[",
"'wtf_js-deps.js'",
"]",
")",
";",
"// Disable asserts unless debugging - asserts cause all code to deopt.",
"if",
"(",
"debugMode",
")",
"{",
"goog",
".",
"require",
"(",
"'goog.asserts'",
")",
";",
"goog",
".",
"asserts",
".",
"assert",
"=",
"function",
"(",
"condition",
",",
"opt_message",
")",
"{",
"console",
".",
"assert",
"(",
"condition",
",",
"opt_message",
")",
";",
"return",
"condition",
";",
"}",
";",
"}",
"else",
"{",
"goog",
".",
"DEBUG",
"=",
"false",
";",
"goog",
".",
"require",
"(",
"'goog.asserts'",
")",
";",
"goog",
".",
"asserts",
".",
"assert",
"=",
"function",
"(",
"condition",
")",
"{",
"return",
"condition",
";",
"}",
";",
"}",
"// Load WTF and configure options.",
"goog",
".",
"require",
"(",
"'wtf'",
")",
";",
"wtf",
".",
"NODE",
"=",
"true",
";",
"goog",
".",
"require",
"(",
"'wtf.db.exports'",
")",
";",
"goog",
".",
"require",
"(",
"'wtf.db.node'",
")",
";",
"}"
] |
Prepares the global context for running a tool with the debug WTF.
|
[
"Prepares",
"the",
"global",
"context",
"for",
"running",
"a",
"tool",
"with",
"the",
"debug",
"WTF",
"."
] |
495ced98de99a5895e484b2e09771edb42d3c7ab
|
https://github.com/google/tracing-framework/blob/495ced98de99a5895e484b2e09771edb42d3c7ab/bin/tool-runner.js#L32-L58
|
17,711
|
google/tracing-framework
|
bin/tool-runner.js
|
prepareRelease
|
function prepareRelease() {
// Load WTF binary. Search a few paths.
// TODO(benvanik): look in ENV?
var searchPaths = [
'.',
'./build-out',
'../build-out'
];
var modulePath = path.dirname(module.filename);
var wtfPath = null;
for (var n = 0; n < searchPaths.length; n++) {
var searchPath = path.join(
searchPaths[n], 'wtf_node_js_compiled.js');
searchPath = path.join(modulePath, searchPath);
if (fs.existsSync(searchPath)) {
wtfPath = path.relative(modulePath, searchPath);
break;
}
}
if (!wtfPath) {
console.log('Unable to find wtf_node_js_compiled.js');
process.exit(-1);
return;
}
var wtf = require(wtfPath.replace('.js', ''));
global.wtf = wtf;
}
|
javascript
|
function prepareRelease() {
// Load WTF binary. Search a few paths.
// TODO(benvanik): look in ENV?
var searchPaths = [
'.',
'./build-out',
'../build-out'
];
var modulePath = path.dirname(module.filename);
var wtfPath = null;
for (var n = 0; n < searchPaths.length; n++) {
var searchPath = path.join(
searchPaths[n], 'wtf_node_js_compiled.js');
searchPath = path.join(modulePath, searchPath);
if (fs.existsSync(searchPath)) {
wtfPath = path.relative(modulePath, searchPath);
break;
}
}
if (!wtfPath) {
console.log('Unable to find wtf_node_js_compiled.js');
process.exit(-1);
return;
}
var wtf = require(wtfPath.replace('.js', ''));
global.wtf = wtf;
}
|
[
"function",
"prepareRelease",
"(",
")",
"{",
"// Load WTF binary. Search a few paths.",
"// TODO(benvanik): look in ENV?",
"var",
"searchPaths",
"=",
"[",
"'.'",
",",
"'./build-out'",
",",
"'../build-out'",
"]",
";",
"var",
"modulePath",
"=",
"path",
".",
"dirname",
"(",
"module",
".",
"filename",
")",
";",
"var",
"wtfPath",
"=",
"null",
";",
"for",
"(",
"var",
"n",
"=",
"0",
";",
"n",
"<",
"searchPaths",
".",
"length",
";",
"n",
"++",
")",
"{",
"var",
"searchPath",
"=",
"path",
".",
"join",
"(",
"searchPaths",
"[",
"n",
"]",
",",
"'wtf_node_js_compiled.js'",
")",
";",
"searchPath",
"=",
"path",
".",
"join",
"(",
"modulePath",
",",
"searchPath",
")",
";",
"if",
"(",
"fs",
".",
"existsSync",
"(",
"searchPath",
")",
")",
"{",
"wtfPath",
"=",
"path",
".",
"relative",
"(",
"modulePath",
",",
"searchPath",
")",
";",
"break",
";",
"}",
"}",
"if",
"(",
"!",
"wtfPath",
")",
"{",
"console",
".",
"log",
"(",
"'Unable to find wtf_node_js_compiled.js'",
")",
";",
"process",
".",
"exit",
"(",
"-",
"1",
")",
";",
"return",
";",
"}",
"var",
"wtf",
"=",
"require",
"(",
"wtfPath",
".",
"replace",
"(",
"'.js'",
",",
"''",
")",
")",
";",
"global",
".",
"wtf",
"=",
"wtf",
";",
"}"
] |
Prepares the global context for running a tool with the release WTF.
|
[
"Prepares",
"the",
"global",
"context",
"for",
"running",
"a",
"tool",
"with",
"the",
"release",
"WTF",
"."
] |
495ced98de99a5895e484b2e09771edb42d3c7ab
|
https://github.com/google/tracing-framework/blob/495ced98de99a5895e484b2e09771edb42d3c7ab/bin/tool-runner.js#L64-L90
|
17,712
|
google/tracing-framework
|
src/wtf/app/addonmanager.js
|
createTabPanel
|
function createTabPanel(path, name, options, callback) {
tabbar.addPanel(new wtf.app.AddonTabPanel(
addon, documentView, path, name, options, callback));
}
|
javascript
|
function createTabPanel(path, name, options, callback) {
tabbar.addPanel(new wtf.app.AddonTabPanel(
addon, documentView, path, name, options, callback));
}
|
[
"function",
"createTabPanel",
"(",
"path",
",",
"name",
",",
"options",
",",
"callback",
")",
"{",
"tabbar",
".",
"addPanel",
"(",
"new",
"wtf",
".",
"app",
".",
"AddonTabPanel",
"(",
"addon",
",",
"documentView",
",",
"path",
",",
"name",
",",
"options",
",",
"callback",
")",
")",
";",
"}"
] |
Creates a new tab panel.
Part of the app addon API.
@param {string} path Path used for navigation.
@param {string} name Panel name.
@param {Object} options Options.
@param {wtf.app.AddonTabPanel.Callback} callback
A callback that creates an external panel.
|
[
"Creates",
"a",
"new",
"tab",
"panel",
".",
"Part",
"of",
"the",
"app",
"addon",
"API",
"."
] |
495ced98de99a5895e484b2e09771edb42d3c7ab
|
https://github.com/google/tracing-framework/blob/495ced98de99a5895e484b2e09771edb42d3c7ab/src/wtf/app/addonmanager.js#L183-L186
|
17,713
|
google/tracing-framework
|
extensions/wtf-injector-chrome/wtf-process.js
|
getFunctionName
|
function getFunctionName(node) {
function cleanupName(name) {
return name.replace(/[ \n]/g, '');
};
// Simple case of:
// function foo() {}
if (node.id) {
return cleanupName(node.id.name);
}
// get foo() {};
if (node.parent.kind == 'get' || node.parent.kind == 'set') {
return cleanupName(node.parent.key.name);
}
// var foo = function() {};
if (node.parent.type == 'VariableDeclarator') {
if (node.parent.id) {
return cleanupName(node.parent.id.name);
}
log('unknown var decl', node.parent);
return null;
}
// {foo: function() {}}
// {"foo": function() {}}
// {1: function() {}}
if (node.parent.type == 'Property') {
return cleanupName(node.parent.key.name || ''+node.parent.key.value);
}
// foo = function() {};
// Bar.foo = function() {};
if (node.parent.type == 'AssignmentExpression') {
// We are the RHS, LHS is something else.
var left = node.parent.left;
if (left.type == 'MemberExpression') {
// Bar.foo = function() {};
// left.object {type: 'Identifier', name: 'Bar'}
// left.property {type: 'Identifier', name: 'foo'}
// Object can be recursive MemberExpression's:
// Bar.prototype.foo = function() {};
// left.object {type: 'MemberExpression', ...}
// left.property {type: 'Identifier', name: 'foo'}
return cleanupName(left.source());
} else if (left.type == 'Identifier') {
return cleanupName(left.name);
}
log('unknown assignment LHS', left);
}
//log('unknown fn construct', node);
// TODO(benvanik): support jscompiler prototype alias:
// _.$JSCompiler_prototypeAlias$$ = _.$something;
// ...
// _.$JSCompiler_prototypeAlias$$.$unnamed = function() {};
// Recognize dart2js names.
var ret = null;
while (node.parent != null) {
node = node.parent;
if (node.type == 'Property') {
if (!ret) {
ret = node.key.name;
} else {
ret = node.key.name + '.' + ret;
}
}
}
return ret;
}
|
javascript
|
function getFunctionName(node) {
function cleanupName(name) {
return name.replace(/[ \n]/g, '');
};
// Simple case of:
// function foo() {}
if (node.id) {
return cleanupName(node.id.name);
}
// get foo() {};
if (node.parent.kind == 'get' || node.parent.kind == 'set') {
return cleanupName(node.parent.key.name);
}
// var foo = function() {};
if (node.parent.type == 'VariableDeclarator') {
if (node.parent.id) {
return cleanupName(node.parent.id.name);
}
log('unknown var decl', node.parent);
return null;
}
// {foo: function() {}}
// {"foo": function() {}}
// {1: function() {}}
if (node.parent.type == 'Property') {
return cleanupName(node.parent.key.name || ''+node.parent.key.value);
}
// foo = function() {};
// Bar.foo = function() {};
if (node.parent.type == 'AssignmentExpression') {
// We are the RHS, LHS is something else.
var left = node.parent.left;
if (left.type == 'MemberExpression') {
// Bar.foo = function() {};
// left.object {type: 'Identifier', name: 'Bar'}
// left.property {type: 'Identifier', name: 'foo'}
// Object can be recursive MemberExpression's:
// Bar.prototype.foo = function() {};
// left.object {type: 'MemberExpression', ...}
// left.property {type: 'Identifier', name: 'foo'}
return cleanupName(left.source());
} else if (left.type == 'Identifier') {
return cleanupName(left.name);
}
log('unknown assignment LHS', left);
}
//log('unknown fn construct', node);
// TODO(benvanik): support jscompiler prototype alias:
// _.$JSCompiler_prototypeAlias$$ = _.$something;
// ...
// _.$JSCompiler_prototypeAlias$$.$unnamed = function() {};
// Recognize dart2js names.
var ret = null;
while (node.parent != null) {
node = node.parent;
if (node.type == 'Property') {
if (!ret) {
ret = node.key.name;
} else {
ret = node.key.name + '.' + ret;
}
}
}
return ret;
}
|
[
"function",
"getFunctionName",
"(",
"node",
")",
"{",
"function",
"cleanupName",
"(",
"name",
")",
"{",
"return",
"name",
".",
"replace",
"(",
"/",
"[ \\n]",
"/",
"g",
",",
"''",
")",
";",
"}",
";",
"// Simple case of:",
"// function foo() {}",
"if",
"(",
"node",
".",
"id",
")",
"{",
"return",
"cleanupName",
"(",
"node",
".",
"id",
".",
"name",
")",
";",
"}",
"// get foo() {};",
"if",
"(",
"node",
".",
"parent",
".",
"kind",
"==",
"'get'",
"||",
"node",
".",
"parent",
".",
"kind",
"==",
"'set'",
")",
"{",
"return",
"cleanupName",
"(",
"node",
".",
"parent",
".",
"key",
".",
"name",
")",
";",
"}",
"// var foo = function() {};",
"if",
"(",
"node",
".",
"parent",
".",
"type",
"==",
"'VariableDeclarator'",
")",
"{",
"if",
"(",
"node",
".",
"parent",
".",
"id",
")",
"{",
"return",
"cleanupName",
"(",
"node",
".",
"parent",
".",
"id",
".",
"name",
")",
";",
"}",
"log",
"(",
"'unknown var decl'",
",",
"node",
".",
"parent",
")",
";",
"return",
"null",
";",
"}",
"// {foo: function() {}}",
"// {\"foo\": function() {}}",
"// {1: function() {}}",
"if",
"(",
"node",
".",
"parent",
".",
"type",
"==",
"'Property'",
")",
"{",
"return",
"cleanupName",
"(",
"node",
".",
"parent",
".",
"key",
".",
"name",
"||",
"''",
"+",
"node",
".",
"parent",
".",
"key",
".",
"value",
")",
";",
"}",
"// foo = function() {};",
"// Bar.foo = function() {};",
"if",
"(",
"node",
".",
"parent",
".",
"type",
"==",
"'AssignmentExpression'",
")",
"{",
"// We are the RHS, LHS is something else.",
"var",
"left",
"=",
"node",
".",
"parent",
".",
"left",
";",
"if",
"(",
"left",
".",
"type",
"==",
"'MemberExpression'",
")",
"{",
"// Bar.foo = function() {};",
"// left.object {type: 'Identifier', name: 'Bar'}",
"// left.property {type: 'Identifier', name: 'foo'}",
"// Object can be recursive MemberExpression's:",
"// Bar.prototype.foo = function() {};",
"// left.object {type: 'MemberExpression', ...}",
"// left.property {type: 'Identifier', name: 'foo'}",
"return",
"cleanupName",
"(",
"left",
".",
"source",
"(",
")",
")",
";",
"}",
"else",
"if",
"(",
"left",
".",
"type",
"==",
"'Identifier'",
")",
"{",
"return",
"cleanupName",
"(",
"left",
".",
"name",
")",
";",
"}",
"log",
"(",
"'unknown assignment LHS'",
",",
"left",
")",
";",
"}",
"//log('unknown fn construct', node);",
"// TODO(benvanik): support jscompiler prototype alias:",
"// _.$JSCompiler_prototypeAlias$$ = _.$something;",
"// ...",
"// _.$JSCompiler_prototypeAlias$$.$unnamed = function() {};",
"// Recognize dart2js names.",
"var",
"ret",
"=",
"null",
";",
"while",
"(",
"node",
".",
"parent",
"!=",
"null",
")",
"{",
"node",
"=",
"node",
".",
"parent",
";",
"if",
"(",
"node",
".",
"type",
"==",
"'Property'",
")",
"{",
"if",
"(",
"!",
"ret",
")",
"{",
"ret",
"=",
"node",
".",
"key",
".",
"name",
";",
"}",
"else",
"{",
"ret",
"=",
"node",
".",
"key",
".",
"name",
"+",
"'.'",
"+",
"ret",
";",
"}",
"}",
"}",
"return",
"ret",
";",
"}"
] |
Attempt to guess the names of functions.
|
[
"Attempt",
"to",
"guess",
"the",
"names",
"of",
"functions",
"."
] |
495ced98de99a5895e484b2e09771edb42d3c7ab
|
https://github.com/google/tracing-framework/blob/495ced98de99a5895e484b2e09771edb42d3c7ab/extensions/wtf-injector-chrome/wtf-process.js#L57-L129
|
17,714
|
google/tracing-framework
|
extensions/wtf-injector-chrome/popup.js
|
setupAddBox
|
function setupAddBox() {
var addBox = document.querySelector('.addRow input');
addBox.oninput = function() {
if (addBox.value == '') {
clearError();
return;
}
fetchAddonManifest(addBox.value);
};
function fetchAddonManifest(url) {
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.onerror = function() {
setError();
};
xhr.onload = function() {
var contentType = xhr.getResponseHeader('content-type') || '';
if (xhr.status != 200 ||
contentType.indexOf('/json') == -1) {
setError();
return;
}
var manifest;
try {
manifest = JSON.parse(xhr.responseText);
} catch (e) {
}
if (!manifest) {
setError();
return;
}
clearError();
addAddon(url, manifest);
};
try {
xhr.send(null);
} catch (e) {
setError();
}
};
function setError() {
addBox.classList.add('kTextFieldError');
};
function clearError() {
addBox.classList.remove('kTextFieldError');
};
function addAddon(url, manifest) {
_gaq.push(['_trackEvent', 'popup', 'addon_added']);
addBox.value = '';
port.postMessage({
command: 'add_addon',
url: url,
manifest: manifest
});
port.postMessage({
command: 'toggle_addon',
enabled: true,
url: url
});
};
}
|
javascript
|
function setupAddBox() {
var addBox = document.querySelector('.addRow input');
addBox.oninput = function() {
if (addBox.value == '') {
clearError();
return;
}
fetchAddonManifest(addBox.value);
};
function fetchAddonManifest(url) {
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.onerror = function() {
setError();
};
xhr.onload = function() {
var contentType = xhr.getResponseHeader('content-type') || '';
if (xhr.status != 200 ||
contentType.indexOf('/json') == -1) {
setError();
return;
}
var manifest;
try {
manifest = JSON.parse(xhr.responseText);
} catch (e) {
}
if (!manifest) {
setError();
return;
}
clearError();
addAddon(url, manifest);
};
try {
xhr.send(null);
} catch (e) {
setError();
}
};
function setError() {
addBox.classList.add('kTextFieldError');
};
function clearError() {
addBox.classList.remove('kTextFieldError');
};
function addAddon(url, manifest) {
_gaq.push(['_trackEvent', 'popup', 'addon_added']);
addBox.value = '';
port.postMessage({
command: 'add_addon',
url: url,
manifest: manifest
});
port.postMessage({
command: 'toggle_addon',
enabled: true,
url: url
});
};
}
|
[
"function",
"setupAddBox",
"(",
")",
"{",
"var",
"addBox",
"=",
"document",
".",
"querySelector",
"(",
"'.addRow input'",
")",
";",
"addBox",
".",
"oninput",
"=",
"function",
"(",
")",
"{",
"if",
"(",
"addBox",
".",
"value",
"==",
"''",
")",
"{",
"clearError",
"(",
")",
";",
"return",
";",
"}",
"fetchAddonManifest",
"(",
"addBox",
".",
"value",
")",
";",
"}",
";",
"function",
"fetchAddonManifest",
"(",
"url",
")",
"{",
"var",
"xhr",
"=",
"new",
"XMLHttpRequest",
"(",
")",
";",
"xhr",
".",
"open",
"(",
"'GET'",
",",
"url",
",",
"true",
")",
";",
"xhr",
".",
"onerror",
"=",
"function",
"(",
")",
"{",
"setError",
"(",
")",
";",
"}",
";",
"xhr",
".",
"onload",
"=",
"function",
"(",
")",
"{",
"var",
"contentType",
"=",
"xhr",
".",
"getResponseHeader",
"(",
"'content-type'",
")",
"||",
"''",
";",
"if",
"(",
"xhr",
".",
"status",
"!=",
"200",
"||",
"contentType",
".",
"indexOf",
"(",
"'/json'",
")",
"==",
"-",
"1",
")",
"{",
"setError",
"(",
")",
";",
"return",
";",
"}",
"var",
"manifest",
";",
"try",
"{",
"manifest",
"=",
"JSON",
".",
"parse",
"(",
"xhr",
".",
"responseText",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"}",
"if",
"(",
"!",
"manifest",
")",
"{",
"setError",
"(",
")",
";",
"return",
";",
"}",
"clearError",
"(",
")",
";",
"addAddon",
"(",
"url",
",",
"manifest",
")",
";",
"}",
";",
"try",
"{",
"xhr",
".",
"send",
"(",
"null",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"setError",
"(",
")",
";",
"}",
"}",
";",
"function",
"setError",
"(",
")",
"{",
"addBox",
".",
"classList",
".",
"add",
"(",
"'kTextFieldError'",
")",
";",
"}",
";",
"function",
"clearError",
"(",
")",
"{",
"addBox",
".",
"classList",
".",
"remove",
"(",
"'kTextFieldError'",
")",
";",
"}",
";",
"function",
"addAddon",
"(",
"url",
",",
"manifest",
")",
"{",
"_gaq",
".",
"push",
"(",
"[",
"'_trackEvent'",
",",
"'popup'",
",",
"'addon_added'",
"]",
")",
";",
"addBox",
".",
"value",
"=",
"''",
";",
"port",
".",
"postMessage",
"(",
"{",
"command",
":",
"'add_addon'",
",",
"url",
":",
"url",
",",
"manifest",
":",
"manifest",
"}",
")",
";",
"port",
".",
"postMessage",
"(",
"{",
"command",
":",
"'toggle_addon'",
",",
"enabled",
":",
"true",
",",
"url",
":",
"url",
"}",
")",
";",
"}",
";",
"}"
] |
Sets up the add addons box.
|
[
"Sets",
"up",
"the",
"add",
"addons",
"box",
"."
] |
495ced98de99a5895e484b2e09771edb42d3c7ab
|
https://github.com/google/tracing-framework/blob/495ced98de99a5895e484b2e09771edb42d3c7ab/extensions/wtf-injector-chrome/popup.js#L62-L126
|
17,715
|
google/tracing-framework
|
extensions/wtf-injector-chrome/popup.js
|
updateWithInfo
|
function updateWithInfo(info) {
var disableOverlay = document.querySelector('.disableOverlay');
var stopRecordingButton = document.querySelector('.buttonStopRecording');
var status = info.status;
switch (status) {
case 'instrumented':
// Instrumentation is enabled for the page.
disableOverlay.style.display = '';
stopRecordingButton.innerText = 'Stop Recording';
break;
case 'whitelisted':
// Tracing is enabled for the page.
disableOverlay.style.display = '';
stopRecordingButton.innerText = 'Stop Recording For This URL';
break;
default:
// Tracing is disabled for the page.
disableOverlay.style.display = 'none';
stopRecordingButton.innerText = '';
break;
}
buildAddonTable(info.all_addons, info.options['wtf.addons']);
}
|
javascript
|
function updateWithInfo(info) {
var disableOverlay = document.querySelector('.disableOverlay');
var stopRecordingButton = document.querySelector('.buttonStopRecording');
var status = info.status;
switch (status) {
case 'instrumented':
// Instrumentation is enabled for the page.
disableOverlay.style.display = '';
stopRecordingButton.innerText = 'Stop Recording';
break;
case 'whitelisted':
// Tracing is enabled for the page.
disableOverlay.style.display = '';
stopRecordingButton.innerText = 'Stop Recording For This URL';
break;
default:
// Tracing is disabled for the page.
disableOverlay.style.display = 'none';
stopRecordingButton.innerText = '';
break;
}
buildAddonTable(info.all_addons, info.options['wtf.addons']);
}
|
[
"function",
"updateWithInfo",
"(",
"info",
")",
"{",
"var",
"disableOverlay",
"=",
"document",
".",
"querySelector",
"(",
"'.disableOverlay'",
")",
";",
"var",
"stopRecordingButton",
"=",
"document",
".",
"querySelector",
"(",
"'.buttonStopRecording'",
")",
";",
"var",
"status",
"=",
"info",
".",
"status",
";",
"switch",
"(",
"status",
")",
"{",
"case",
"'instrumented'",
":",
"// Instrumentation is enabled for the page.",
"disableOverlay",
".",
"style",
".",
"display",
"=",
"''",
";",
"stopRecordingButton",
".",
"innerText",
"=",
"'Stop Recording'",
";",
"break",
";",
"case",
"'whitelisted'",
":",
"// Tracing is enabled for the page.",
"disableOverlay",
".",
"style",
".",
"display",
"=",
"''",
";",
"stopRecordingButton",
".",
"innerText",
"=",
"'Stop Recording For This URL'",
";",
"break",
";",
"default",
":",
"// Tracing is disabled for the page.",
"disableOverlay",
".",
"style",
".",
"display",
"=",
"'none'",
";",
"stopRecordingButton",
".",
"innerText",
"=",
"''",
";",
"break",
";",
"}",
"buildAddonTable",
"(",
"info",
".",
"all_addons",
",",
"info",
".",
"options",
"[",
"'wtf.addons'",
"]",
")",
";",
"}"
] |
Updates the popup with the given page information.
@param {!Object} info Page information.
|
[
"Updates",
"the",
"popup",
"with",
"the",
"given",
"page",
"information",
"."
] |
495ced98de99a5895e484b2e09771edb42d3c7ab
|
https://github.com/google/tracing-framework/blob/495ced98de99a5895e484b2e09771edb42d3c7ab/extensions/wtf-injector-chrome/popup.js#L133-L157
|
17,716
|
google/tracing-framework
|
extensions/wtf-injector-chrome/popup.js
|
buildAddonTable
|
function buildAddonTable(addons, enabledAddons) {
var tbody = document.querySelector('.addonPicker tbody');
// Remove all old content.
while (tbody.firstChild) {
tbody.firstChild.remove();
}
// Add empty row.
if (!addons.length) {
var tr = document.createElement('tr');
tr.className = 'emptyRow';
var td = document.createElement('td');
td.innerText = 'No addons added.';
tr.appendChild(td);
tbody.appendChild(tr);
}
// Build the table.
for (var n = 0; n < addons.length; n++) {
var extension = addons[n];
addExtensionRow(extension);
}
function addExtensionRow(extension) {
var isEnabled = enabledAddons.indexOf(extension.url) >= 0;;
var td = document.createElement('td');
var input = document.createElement('input');
input.type = 'checkbox';
input.checked = isEnabled;
td.appendChild(input);
var span = document.createElement('span');
span.innerText = extension.manifest.name;
span.title = extension.url;
td.appendChild(span);
var remove = document.createElement('td');
remove.className = 'remove';
var removeImg = document.createElement('img');
removeImg.title = 'Remove extension';
remove.appendChild(removeImg);
var tr = document.createElement('tr');
tr.appendChild(td);
tr.appendChild(remove);
tbody.appendChild(tr);
function changed() {
_gaq.push(['_trackEvent', 'popup', 'addon_toggled']);
port.postMessage({
command: 'toggle_extension',
enabled: input.checked,
url: extension.url
});
};
input.onchange = function() {
changed();
};
span.onclick = function() {
input.checked = !input.checked;
changed();
};
remove.onclick = function() {
_gaq.push(['_trackEvent', 'popup', 'addon_removed']);
if (isEnabled) {
port.postMessage({
command: 'toggle_addon',
enabled: false,
url: extension.url
});
}
port.postMessage({
command: 'remove_addon',
url: extension.url
});
};
};
}
|
javascript
|
function buildAddonTable(addons, enabledAddons) {
var tbody = document.querySelector('.addonPicker tbody');
// Remove all old content.
while (tbody.firstChild) {
tbody.firstChild.remove();
}
// Add empty row.
if (!addons.length) {
var tr = document.createElement('tr');
tr.className = 'emptyRow';
var td = document.createElement('td');
td.innerText = 'No addons added.';
tr.appendChild(td);
tbody.appendChild(tr);
}
// Build the table.
for (var n = 0; n < addons.length; n++) {
var extension = addons[n];
addExtensionRow(extension);
}
function addExtensionRow(extension) {
var isEnabled = enabledAddons.indexOf(extension.url) >= 0;;
var td = document.createElement('td');
var input = document.createElement('input');
input.type = 'checkbox';
input.checked = isEnabled;
td.appendChild(input);
var span = document.createElement('span');
span.innerText = extension.manifest.name;
span.title = extension.url;
td.appendChild(span);
var remove = document.createElement('td');
remove.className = 'remove';
var removeImg = document.createElement('img');
removeImg.title = 'Remove extension';
remove.appendChild(removeImg);
var tr = document.createElement('tr');
tr.appendChild(td);
tr.appendChild(remove);
tbody.appendChild(tr);
function changed() {
_gaq.push(['_trackEvent', 'popup', 'addon_toggled']);
port.postMessage({
command: 'toggle_extension',
enabled: input.checked,
url: extension.url
});
};
input.onchange = function() {
changed();
};
span.onclick = function() {
input.checked = !input.checked;
changed();
};
remove.onclick = function() {
_gaq.push(['_trackEvent', 'popup', 'addon_removed']);
if (isEnabled) {
port.postMessage({
command: 'toggle_addon',
enabled: false,
url: extension.url
});
}
port.postMessage({
command: 'remove_addon',
url: extension.url
});
};
};
}
|
[
"function",
"buildAddonTable",
"(",
"addons",
",",
"enabledAddons",
")",
"{",
"var",
"tbody",
"=",
"document",
".",
"querySelector",
"(",
"'.addonPicker tbody'",
")",
";",
"// Remove all old content.",
"while",
"(",
"tbody",
".",
"firstChild",
")",
"{",
"tbody",
".",
"firstChild",
".",
"remove",
"(",
")",
";",
"}",
"// Add empty row.",
"if",
"(",
"!",
"addons",
".",
"length",
")",
"{",
"var",
"tr",
"=",
"document",
".",
"createElement",
"(",
"'tr'",
")",
";",
"tr",
".",
"className",
"=",
"'emptyRow'",
";",
"var",
"td",
"=",
"document",
".",
"createElement",
"(",
"'td'",
")",
";",
"td",
".",
"innerText",
"=",
"'No addons added.'",
";",
"tr",
".",
"appendChild",
"(",
"td",
")",
";",
"tbody",
".",
"appendChild",
"(",
"tr",
")",
";",
"}",
"// Build the table.",
"for",
"(",
"var",
"n",
"=",
"0",
";",
"n",
"<",
"addons",
".",
"length",
";",
"n",
"++",
")",
"{",
"var",
"extension",
"=",
"addons",
"[",
"n",
"]",
";",
"addExtensionRow",
"(",
"extension",
")",
";",
"}",
"function",
"addExtensionRow",
"(",
"extension",
")",
"{",
"var",
"isEnabled",
"=",
"enabledAddons",
".",
"indexOf",
"(",
"extension",
".",
"url",
")",
">=",
"0",
";",
";",
"var",
"td",
"=",
"document",
".",
"createElement",
"(",
"'td'",
")",
";",
"var",
"input",
"=",
"document",
".",
"createElement",
"(",
"'input'",
")",
";",
"input",
".",
"type",
"=",
"'checkbox'",
";",
"input",
".",
"checked",
"=",
"isEnabled",
";",
"td",
".",
"appendChild",
"(",
"input",
")",
";",
"var",
"span",
"=",
"document",
".",
"createElement",
"(",
"'span'",
")",
";",
"span",
".",
"innerText",
"=",
"extension",
".",
"manifest",
".",
"name",
";",
"span",
".",
"title",
"=",
"extension",
".",
"url",
";",
"td",
".",
"appendChild",
"(",
"span",
")",
";",
"var",
"remove",
"=",
"document",
".",
"createElement",
"(",
"'td'",
")",
";",
"remove",
".",
"className",
"=",
"'remove'",
";",
"var",
"removeImg",
"=",
"document",
".",
"createElement",
"(",
"'img'",
")",
";",
"removeImg",
".",
"title",
"=",
"'Remove extension'",
";",
"remove",
".",
"appendChild",
"(",
"removeImg",
")",
";",
"var",
"tr",
"=",
"document",
".",
"createElement",
"(",
"'tr'",
")",
";",
"tr",
".",
"appendChild",
"(",
"td",
")",
";",
"tr",
".",
"appendChild",
"(",
"remove",
")",
";",
"tbody",
".",
"appendChild",
"(",
"tr",
")",
";",
"function",
"changed",
"(",
")",
"{",
"_gaq",
".",
"push",
"(",
"[",
"'_trackEvent'",
",",
"'popup'",
",",
"'addon_toggled'",
"]",
")",
";",
"port",
".",
"postMessage",
"(",
"{",
"command",
":",
"'toggle_extension'",
",",
"enabled",
":",
"input",
".",
"checked",
",",
"url",
":",
"extension",
".",
"url",
"}",
")",
";",
"}",
";",
"input",
".",
"onchange",
"=",
"function",
"(",
")",
"{",
"changed",
"(",
")",
";",
"}",
";",
"span",
".",
"onclick",
"=",
"function",
"(",
")",
"{",
"input",
".",
"checked",
"=",
"!",
"input",
".",
"checked",
";",
"changed",
"(",
")",
";",
"}",
";",
"remove",
".",
"onclick",
"=",
"function",
"(",
")",
"{",
"_gaq",
".",
"push",
"(",
"[",
"'_trackEvent'",
",",
"'popup'",
",",
"'addon_removed'",
"]",
")",
";",
"if",
"(",
"isEnabled",
")",
"{",
"port",
".",
"postMessage",
"(",
"{",
"command",
":",
"'toggle_addon'",
",",
"enabled",
":",
"false",
",",
"url",
":",
"extension",
".",
"url",
"}",
")",
";",
"}",
"port",
".",
"postMessage",
"(",
"{",
"command",
":",
"'remove_addon'",
",",
"url",
":",
"extension",
".",
"url",
"}",
")",
";",
"}",
";",
"}",
";",
"}"
] |
Builds the addon table.
@param {!Array.<!Object>} addons Addon information.
@param {!Array.<string>} enabledAddons Addons that are enabled.
|
[
"Builds",
"the",
"addon",
"table",
"."
] |
495ced98de99a5895e484b2e09771edb42d3c7ab
|
https://github.com/google/tracing-framework/blob/495ced98de99a5895e484b2e09771edb42d3c7ab/extensions/wtf-injector-chrome/popup.js#L165-L246
|
17,717
|
google/tracing-framework
|
extensions/wtf-injector-chrome/popup.js
|
openFileClicked
|
function openFileClicked() {
var inputElement = document.createElement('input');
inputElement['type'] = 'file';
inputElement['multiple'] = true;
inputElement['accept'] = [
'.wtf-trace,application/x-extension-wtf-trace',
'.wtf-json,application/x-extension-wtf-json',
'.wtf-calls,application/x-extension-wtf-calls',
'.cpuprofile,application/x-extension-cpuprofile',
'.part,application/x-extension-part'
].join(',');
inputElement.onchange = function(e) {
_gaq.push(['_trackEvent', 'popup', 'open_file']);
var fileEntries = [];
for (var n = 0; n < inputElement.files.length; n++) {
var file = inputElement.files[n];
var blob = new Blob([file], {
type: 'application/octet-stream'
});
var blobUrl = URL.createObjectURL(blob);
fileEntries.push({
name: file.name,
url: blobUrl,
size: blob.size
});
}
port.postMessage({
command: 'show_files',
files: fileEntries
});
window.close();
};
inputElement.click();
}
|
javascript
|
function openFileClicked() {
var inputElement = document.createElement('input');
inputElement['type'] = 'file';
inputElement['multiple'] = true;
inputElement['accept'] = [
'.wtf-trace,application/x-extension-wtf-trace',
'.wtf-json,application/x-extension-wtf-json',
'.wtf-calls,application/x-extension-wtf-calls',
'.cpuprofile,application/x-extension-cpuprofile',
'.part,application/x-extension-part'
].join(',');
inputElement.onchange = function(e) {
_gaq.push(['_trackEvent', 'popup', 'open_file']);
var fileEntries = [];
for (var n = 0; n < inputElement.files.length; n++) {
var file = inputElement.files[n];
var blob = new Blob([file], {
type: 'application/octet-stream'
});
var blobUrl = URL.createObjectURL(blob);
fileEntries.push({
name: file.name,
url: blobUrl,
size: blob.size
});
}
port.postMessage({
command: 'show_files',
files: fileEntries
});
window.close();
};
inputElement.click();
}
|
[
"function",
"openFileClicked",
"(",
")",
"{",
"var",
"inputElement",
"=",
"document",
".",
"createElement",
"(",
"'input'",
")",
";",
"inputElement",
"[",
"'type'",
"]",
"=",
"'file'",
";",
"inputElement",
"[",
"'multiple'",
"]",
"=",
"true",
";",
"inputElement",
"[",
"'accept'",
"]",
"=",
"[",
"'.wtf-trace,application/x-extension-wtf-trace'",
",",
"'.wtf-json,application/x-extension-wtf-json'",
",",
"'.wtf-calls,application/x-extension-wtf-calls'",
",",
"'.cpuprofile,application/x-extension-cpuprofile'",
",",
"'.part,application/x-extension-part'",
"]",
".",
"join",
"(",
"','",
")",
";",
"inputElement",
".",
"onchange",
"=",
"function",
"(",
"e",
")",
"{",
"_gaq",
".",
"push",
"(",
"[",
"'_trackEvent'",
",",
"'popup'",
",",
"'open_file'",
"]",
")",
";",
"var",
"fileEntries",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"n",
"=",
"0",
";",
"n",
"<",
"inputElement",
".",
"files",
".",
"length",
";",
"n",
"++",
")",
"{",
"var",
"file",
"=",
"inputElement",
".",
"files",
"[",
"n",
"]",
";",
"var",
"blob",
"=",
"new",
"Blob",
"(",
"[",
"file",
"]",
",",
"{",
"type",
":",
"'application/octet-stream'",
"}",
")",
";",
"var",
"blobUrl",
"=",
"URL",
".",
"createObjectURL",
"(",
"blob",
")",
";",
"fileEntries",
".",
"push",
"(",
"{",
"name",
":",
"file",
".",
"name",
",",
"url",
":",
"blobUrl",
",",
"size",
":",
"blob",
".",
"size",
"}",
")",
";",
"}",
"port",
".",
"postMessage",
"(",
"{",
"command",
":",
"'show_files'",
",",
"files",
":",
"fileEntries",
"}",
")",
";",
"window",
".",
"close",
"(",
")",
";",
"}",
";",
"inputElement",
".",
"click",
"(",
")",
";",
"}"
] |
Shows the UI and brings up the open file dialog.
|
[
"Shows",
"the",
"UI",
"and",
"brings",
"up",
"the",
"open",
"file",
"dialog",
"."
] |
495ced98de99a5895e484b2e09771edb42d3c7ab
|
https://github.com/google/tracing-framework/blob/495ced98de99a5895e484b2e09771edb42d3c7ab/extensions/wtf-injector-chrome/popup.js#L265-L300
|
17,718
|
google/tracing-framework
|
extensions/wtf-injector-chrome/popup.js
|
instrumentMemoryClicked
|
function instrumentMemoryClicked() {
_gaq.push(['_trackEvent', 'popup', 'instrument_memory']);
try {
new Function('return %GetHeapUsage()');
} catch (e) {
// Pop open docs page.
port.postMessage({
command: 'instrument',
type: 'memory',
needsHelp: true
});
return;
}
port.postMessage({
command: 'instrument',
type: 'memory'
});
window.close();
}
|
javascript
|
function instrumentMemoryClicked() {
_gaq.push(['_trackEvent', 'popup', 'instrument_memory']);
try {
new Function('return %GetHeapUsage()');
} catch (e) {
// Pop open docs page.
port.postMessage({
command: 'instrument',
type: 'memory',
needsHelp: true
});
return;
}
port.postMessage({
command: 'instrument',
type: 'memory'
});
window.close();
}
|
[
"function",
"instrumentMemoryClicked",
"(",
")",
"{",
"_gaq",
".",
"push",
"(",
"[",
"'_trackEvent'",
",",
"'popup'",
",",
"'instrument_memory'",
"]",
")",
";",
"try",
"{",
"new",
"Function",
"(",
"'return %GetHeapUsage()'",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"// Pop open docs page.",
"port",
".",
"postMessage",
"(",
"{",
"command",
":",
"'instrument'",
",",
"type",
":",
"'memory'",
",",
"needsHelp",
":",
"true",
"}",
")",
";",
"return",
";",
"}",
"port",
".",
"postMessage",
"(",
"{",
"command",
":",
"'instrument'",
",",
"type",
":",
"'memory'",
"}",
")",
";",
"window",
".",
"close",
"(",
")",
";",
"}"
] |
Toggles instrumented memory tracing.
|
[
"Toggles",
"instrumented",
"memory",
"tracing",
"."
] |
495ced98de99a5895e484b2e09771edb42d3c7ab
|
https://github.com/google/tracing-framework/blob/495ced98de99a5895e484b2e09771edb42d3c7ab/extensions/wtf-injector-chrome/popup.js#L347-L367
|
17,719
|
google/tracing-framework
|
src/wtf/trace/providers/webworkerprovider.js
|
createInjectionShim
|
function createInjectionShim(scriptUrl, workerId) {
// Hacky handling for blob URLs.
// Unfortunately Chrome doesn't like importScript on blobs inside of the
// workers, so we need to embed it.
var resolvedScriptUrl = null;
var scriptContents = null;
if (goog.string.startsWith(scriptUrl, 'blob:')) {
var xhr = new (goog.global['XMLHttpRequest']['raw'] || XMLHttpRequest)();
xhr.open('GET', scriptUrl, false);
xhr.send();
scriptContents = xhr.response;
} else {
resolvedScriptUrl = goog.Uri.resolve(baseUri, scriptUrl).toString();
}
var shimScriptLines = [
'this.WTF_WORKER_ID = ' + workerId + ';',
'this.WTF_WORKER_BASE_URI = "' + goog.global.location.href + '";',
'importScripts("' + wtfUrl + '");',
'wtf.trace.prepare({',
'});',
'wtf.trace.start();'
];
// Add the script import or directly embed the contents.
if (resolvedScriptUrl) {
shimScriptLines.push('importScripts("' + resolvedScriptUrl + '");');
} else if (scriptContents) {
shimScriptLines.push('// Embedded: ' + scriptUrl);
shimScriptLines.push(scriptContents);
}
var shimBlob = new Blob([shimScriptLines.join('\n')], {
'type': 'text/javascript'
});
var shimScriptUrl = goog.fs.createObjectUrl(shimBlob);
return shimScriptUrl;
}
|
javascript
|
function createInjectionShim(scriptUrl, workerId) {
// Hacky handling for blob URLs.
// Unfortunately Chrome doesn't like importScript on blobs inside of the
// workers, so we need to embed it.
var resolvedScriptUrl = null;
var scriptContents = null;
if (goog.string.startsWith(scriptUrl, 'blob:')) {
var xhr = new (goog.global['XMLHttpRequest']['raw'] || XMLHttpRequest)();
xhr.open('GET', scriptUrl, false);
xhr.send();
scriptContents = xhr.response;
} else {
resolvedScriptUrl = goog.Uri.resolve(baseUri, scriptUrl).toString();
}
var shimScriptLines = [
'this.WTF_WORKER_ID = ' + workerId + ';',
'this.WTF_WORKER_BASE_URI = "' + goog.global.location.href + '";',
'importScripts("' + wtfUrl + '");',
'wtf.trace.prepare({',
'});',
'wtf.trace.start();'
];
// Add the script import or directly embed the contents.
if (resolvedScriptUrl) {
shimScriptLines.push('importScripts("' + resolvedScriptUrl + '");');
} else if (scriptContents) {
shimScriptLines.push('// Embedded: ' + scriptUrl);
shimScriptLines.push(scriptContents);
}
var shimBlob = new Blob([shimScriptLines.join('\n')], {
'type': 'text/javascript'
});
var shimScriptUrl = goog.fs.createObjectUrl(shimBlob);
return shimScriptUrl;
}
|
[
"function",
"createInjectionShim",
"(",
"scriptUrl",
",",
"workerId",
")",
"{",
"// Hacky handling for blob URLs.",
"// Unfortunately Chrome doesn't like importScript on blobs inside of the",
"// workers, so we need to embed it.",
"var",
"resolvedScriptUrl",
"=",
"null",
";",
"var",
"scriptContents",
"=",
"null",
";",
"if",
"(",
"goog",
".",
"string",
".",
"startsWith",
"(",
"scriptUrl",
",",
"'blob:'",
")",
")",
"{",
"var",
"xhr",
"=",
"new",
"(",
"goog",
".",
"global",
"[",
"'XMLHttpRequest'",
"]",
"[",
"'raw'",
"]",
"||",
"XMLHttpRequest",
")",
"(",
")",
";",
"xhr",
".",
"open",
"(",
"'GET'",
",",
"scriptUrl",
",",
"false",
")",
";",
"xhr",
".",
"send",
"(",
")",
";",
"scriptContents",
"=",
"xhr",
".",
"response",
";",
"}",
"else",
"{",
"resolvedScriptUrl",
"=",
"goog",
".",
"Uri",
".",
"resolve",
"(",
"baseUri",
",",
"scriptUrl",
")",
".",
"toString",
"(",
")",
";",
"}",
"var",
"shimScriptLines",
"=",
"[",
"'this.WTF_WORKER_ID = '",
"+",
"workerId",
"+",
"';'",
",",
"'this.WTF_WORKER_BASE_URI = \"'",
"+",
"goog",
".",
"global",
".",
"location",
".",
"href",
"+",
"'\";'",
",",
"'importScripts(\"'",
"+",
"wtfUrl",
"+",
"'\");'",
",",
"'wtf.trace.prepare({'",
",",
"'});'",
",",
"'wtf.trace.start();'",
"]",
";",
"// Add the script import or directly embed the contents.",
"if",
"(",
"resolvedScriptUrl",
")",
"{",
"shimScriptLines",
".",
"push",
"(",
"'importScripts(\"'",
"+",
"resolvedScriptUrl",
"+",
"'\");'",
")",
";",
"}",
"else",
"if",
"(",
"scriptContents",
")",
"{",
"shimScriptLines",
".",
"push",
"(",
"'// Embedded: '",
"+",
"scriptUrl",
")",
";",
"shimScriptLines",
".",
"push",
"(",
"scriptContents",
")",
";",
"}",
"var",
"shimBlob",
"=",
"new",
"Blob",
"(",
"[",
"shimScriptLines",
".",
"join",
"(",
"'\\n'",
")",
"]",
",",
"{",
"'type'",
":",
"'text/javascript'",
"}",
")",
";",
"var",
"shimScriptUrl",
"=",
"goog",
".",
"fs",
".",
"createObjectUrl",
"(",
"shimBlob",
")",
";",
"return",
"shimScriptUrl",
";",
"}"
] |
Creates a shim script that injects WTF.
@param {string} scriptUrl Source script URL.
@param {number} workerId Unique worker ID.
@return {string} Shim script URL.
|
[
"Creates",
"a",
"shim",
"script",
"that",
"injects",
"WTF",
"."
] |
495ced98de99a5895e484b2e09771edb42d3c7ab
|
https://github.com/google/tracing-framework/blob/495ced98de99a5895e484b2e09771edb42d3c7ab/src/wtf/trace/providers/webworkerprovider.js#L276-L314
|
17,720
|
google/tracing-framework
|
src/wtf/trace/providers/webworkerprovider.js
|
function(scriptUrl) {
goog.base(this, descriptor);
/**
* Tracking ID.
* @type {number}
* @private
*/
this.workerId_ = nextWorkerId++;
// Create the child worker.
// If we are injecting generate a shim script and use that.
var newScriptUrl = scriptUrl;
if (injecting) {
newScriptUrl = createInjectionShim(scriptUrl, this.workerId_);
}
var scope = workerCtorEvent(scriptUrl, this.workerId_);
goog.global['Worker'] = originalWorker;
var previousGlobalWorker = goog.global['Worker'];
var handle;
try {
handle = new originalWorker(newScriptUrl);
} finally {
goog.global['Worker'] = previousGlobalWorker;
wtf.trace.leaveScope(scope);
}
/**
* Handle to the underlying worker instance.
* @type {!Worker}
* @private
*/
this.handle_ = handle;
/**
* Event type trackers, by name.
* @type {!Object.<Function>}
* @private
*/
this.trackers_ = {};
this.setEventHook('error', function(e) {
wtf.trace.appendScopeData('id', this.workerId_);
}, this);
this.setEventHook('message', function(e) {
wtf.trace.appendScopeData('id', this.workerId_);
}, this);
// Always hook onmessage.
// By doing it here we get first access to the event.
var self = this;
this.handle_.addEventListener('message', function(e) {
// Sniff provider messages.
if (!e.data['__wtf_worker_msg__']) {
return;
}
e['__wtf_ignore__'] = true;
var value = e.data['value'];
switch (e.data['command']) {
case 'snapshot':
var result = pendingSnapshots[value['id']];
delete pendingSnapshots[value['id']];
if (!result.getError()) {
result.setValue(value['data']);
}
break;
case 'close':
goog.array.remove(provider.childWorkers_, self);
break;
}
}, false);
provider.childWorkers_.push(this);
}
|
javascript
|
function(scriptUrl) {
goog.base(this, descriptor);
/**
* Tracking ID.
* @type {number}
* @private
*/
this.workerId_ = nextWorkerId++;
// Create the child worker.
// If we are injecting generate a shim script and use that.
var newScriptUrl = scriptUrl;
if (injecting) {
newScriptUrl = createInjectionShim(scriptUrl, this.workerId_);
}
var scope = workerCtorEvent(scriptUrl, this.workerId_);
goog.global['Worker'] = originalWorker;
var previousGlobalWorker = goog.global['Worker'];
var handle;
try {
handle = new originalWorker(newScriptUrl);
} finally {
goog.global['Worker'] = previousGlobalWorker;
wtf.trace.leaveScope(scope);
}
/**
* Handle to the underlying worker instance.
* @type {!Worker}
* @private
*/
this.handle_ = handle;
/**
* Event type trackers, by name.
* @type {!Object.<Function>}
* @private
*/
this.trackers_ = {};
this.setEventHook('error', function(e) {
wtf.trace.appendScopeData('id', this.workerId_);
}, this);
this.setEventHook('message', function(e) {
wtf.trace.appendScopeData('id', this.workerId_);
}, this);
// Always hook onmessage.
// By doing it here we get first access to the event.
var self = this;
this.handle_.addEventListener('message', function(e) {
// Sniff provider messages.
if (!e.data['__wtf_worker_msg__']) {
return;
}
e['__wtf_ignore__'] = true;
var value = e.data['value'];
switch (e.data['command']) {
case 'snapshot':
var result = pendingSnapshots[value['id']];
delete pendingSnapshots[value['id']];
if (!result.getError()) {
result.setValue(value['data']);
}
break;
case 'close':
goog.array.remove(provider.childWorkers_, self);
break;
}
}, false);
provider.childWorkers_.push(this);
}
|
[
"function",
"(",
"scriptUrl",
")",
"{",
"goog",
".",
"base",
"(",
"this",
",",
"descriptor",
")",
";",
"/**\n * Tracking ID.\n * @type {number}\n * @private\n */",
"this",
".",
"workerId_",
"=",
"nextWorkerId",
"++",
";",
"// Create the child worker.",
"// If we are injecting generate a shim script and use that.",
"var",
"newScriptUrl",
"=",
"scriptUrl",
";",
"if",
"(",
"injecting",
")",
"{",
"newScriptUrl",
"=",
"createInjectionShim",
"(",
"scriptUrl",
",",
"this",
".",
"workerId_",
")",
";",
"}",
"var",
"scope",
"=",
"workerCtorEvent",
"(",
"scriptUrl",
",",
"this",
".",
"workerId_",
")",
";",
"goog",
".",
"global",
"[",
"'Worker'",
"]",
"=",
"originalWorker",
";",
"var",
"previousGlobalWorker",
"=",
"goog",
".",
"global",
"[",
"'Worker'",
"]",
";",
"var",
"handle",
";",
"try",
"{",
"handle",
"=",
"new",
"originalWorker",
"(",
"newScriptUrl",
")",
";",
"}",
"finally",
"{",
"goog",
".",
"global",
"[",
"'Worker'",
"]",
"=",
"previousGlobalWorker",
";",
"wtf",
".",
"trace",
".",
"leaveScope",
"(",
"scope",
")",
";",
"}",
"/**\n * Handle to the underlying worker instance.\n * @type {!Worker}\n * @private\n */",
"this",
".",
"handle_",
"=",
"handle",
";",
"/**\n * Event type trackers, by name.\n * @type {!Object.<Function>}\n * @private\n */",
"this",
".",
"trackers_",
"=",
"{",
"}",
";",
"this",
".",
"setEventHook",
"(",
"'error'",
",",
"function",
"(",
"e",
")",
"{",
"wtf",
".",
"trace",
".",
"appendScopeData",
"(",
"'id'",
",",
"this",
".",
"workerId_",
")",
";",
"}",
",",
"this",
")",
";",
"this",
".",
"setEventHook",
"(",
"'message'",
",",
"function",
"(",
"e",
")",
"{",
"wtf",
".",
"trace",
".",
"appendScopeData",
"(",
"'id'",
",",
"this",
".",
"workerId_",
")",
";",
"}",
",",
"this",
")",
";",
"// Always hook onmessage.",
"// By doing it here we get first access to the event.",
"var",
"self",
"=",
"this",
";",
"this",
".",
"handle_",
".",
"addEventListener",
"(",
"'message'",
",",
"function",
"(",
"e",
")",
"{",
"// Sniff provider messages.",
"if",
"(",
"!",
"e",
".",
"data",
"[",
"'__wtf_worker_msg__'",
"]",
")",
"{",
"return",
";",
"}",
"e",
"[",
"'__wtf_ignore__'",
"]",
"=",
"true",
";",
"var",
"value",
"=",
"e",
".",
"data",
"[",
"'value'",
"]",
";",
"switch",
"(",
"e",
".",
"data",
"[",
"'command'",
"]",
")",
"{",
"case",
"'snapshot'",
":",
"var",
"result",
"=",
"pendingSnapshots",
"[",
"value",
"[",
"'id'",
"]",
"]",
";",
"delete",
"pendingSnapshots",
"[",
"value",
"[",
"'id'",
"]",
"]",
";",
"if",
"(",
"!",
"result",
".",
"getError",
"(",
")",
")",
"{",
"result",
".",
"setValue",
"(",
"value",
"[",
"'data'",
"]",
")",
";",
"}",
"break",
";",
"case",
"'close'",
":",
"goog",
".",
"array",
".",
"remove",
"(",
"provider",
".",
"childWorkers_",
",",
"self",
")",
";",
"break",
";",
"}",
"}",
",",
"false",
")",
";",
"provider",
".",
"childWorkers_",
".",
"push",
"(",
"this",
")",
";",
"}"
] |
Worker shim.
@param {string} scriptUrl Script URL.
@constructor
@extends {wtf.trace.eventtarget.BaseEventTarget}
|
[
"Worker",
"shim",
"."
] |
495ced98de99a5895e484b2e09771edb42d3c7ab
|
https://github.com/google/tracing-framework/blob/495ced98de99a5895e484b2e09771edb42d3c7ab/src/wtf/trace/providers/webworkerprovider.js#L322-L396
|
|
17,721
|
google/tracing-framework
|
src/wtf/trace/providers/webworkerprovider.js
|
sendMessage
|
function sendMessage(command, opt_value, opt_transfer) {
// TODO(benvanik): attempt to use webkitPostMessage
originalPostMessage.call(goog.global, {
'__wtf_worker_msg__': true,
'command': command,
'value': opt_value || null
}, []);
}
|
javascript
|
function sendMessage(command, opt_value, opt_transfer) {
// TODO(benvanik): attempt to use webkitPostMessage
originalPostMessage.call(goog.global, {
'__wtf_worker_msg__': true,
'command': command,
'value': opt_value || null
}, []);
}
|
[
"function",
"sendMessage",
"(",
"command",
",",
"opt_value",
",",
"opt_transfer",
")",
"{",
"// TODO(benvanik): attempt to use webkitPostMessage",
"originalPostMessage",
".",
"call",
"(",
"goog",
".",
"global",
",",
"{",
"'__wtf_worker_msg__'",
":",
"true",
",",
"'command'",
":",
"command",
",",
"'value'",
":",
"opt_value",
"||",
"null",
"}",
",",
"[",
"]",
")",
";",
"}"
] |
Sends an internal message to the worker.
@param {string} command Command name.
@param {*=} opt_value Command value.
@param {Array=} opt_transfer Transferrable values.
|
[
"Sends",
"an",
"internal",
"message",
"to",
"the",
"worker",
"."
] |
495ced98de99a5895e484b2e09771edb42d3c7ab
|
https://github.com/google/tracing-framework/blob/495ced98de99a5895e484b2e09771edb42d3c7ab/src/wtf/trace/providers/webworkerprovider.js#L641-L648
|
17,722
|
google/tracing-framework
|
bin/diff.js
|
runTool
|
function runTool(platform, args, done) {
var inputFile1 = args[0];
var inputFile2 = args[1];
var filterString = args[2];
if (!inputFile1 || !inputFile2) {
console.log('usage: diff.js file1.wtf-trace file2.wtf-trace [filter]');
done(1);
return;
}
console.log('Diffing ' + inputFile1 + ' and ' + inputFile2 + '...');
console.log('');
var filter = null;
if (filterString) {
filter = new wtf.db.Filter(filterString);
}
// Create databases for querying.
var db1 = null;
var db2 = null;
wtf.db.load(inputFile1, function(db) {
if (db instanceof Error) {
console.log('ERROR: unable to open ' + inputFile1, db);
done(1);
return;
}
db1 = db;
if (db1 && db2) {
diffDatabases(db1, db2, filter);
done(0);
}
});
wtf.db.load(inputFile2, function(db) {
if (db instanceof Error) {
console.log('ERROR: unable to open ' + inputFile2, db);
done(1);
return;
}
db2 = db;
if (db1 && db2) {
diffDatabases(db1, db2, filter);
done(0);
}
});
}
|
javascript
|
function runTool(platform, args, done) {
var inputFile1 = args[0];
var inputFile2 = args[1];
var filterString = args[2];
if (!inputFile1 || !inputFile2) {
console.log('usage: diff.js file1.wtf-trace file2.wtf-trace [filter]');
done(1);
return;
}
console.log('Diffing ' + inputFile1 + ' and ' + inputFile2 + '...');
console.log('');
var filter = null;
if (filterString) {
filter = new wtf.db.Filter(filterString);
}
// Create databases for querying.
var db1 = null;
var db2 = null;
wtf.db.load(inputFile1, function(db) {
if (db instanceof Error) {
console.log('ERROR: unable to open ' + inputFile1, db);
done(1);
return;
}
db1 = db;
if (db1 && db2) {
diffDatabases(db1, db2, filter);
done(0);
}
});
wtf.db.load(inputFile2, function(db) {
if (db instanceof Error) {
console.log('ERROR: unable to open ' + inputFile2, db);
done(1);
return;
}
db2 = db;
if (db1 && db2) {
diffDatabases(db1, db2, filter);
done(0);
}
});
}
|
[
"function",
"runTool",
"(",
"platform",
",",
"args",
",",
"done",
")",
"{",
"var",
"inputFile1",
"=",
"args",
"[",
"0",
"]",
";",
"var",
"inputFile2",
"=",
"args",
"[",
"1",
"]",
";",
"var",
"filterString",
"=",
"args",
"[",
"2",
"]",
";",
"if",
"(",
"!",
"inputFile1",
"||",
"!",
"inputFile2",
")",
"{",
"console",
".",
"log",
"(",
"'usage: diff.js file1.wtf-trace file2.wtf-trace [filter]'",
")",
";",
"done",
"(",
"1",
")",
";",
"return",
";",
"}",
"console",
".",
"log",
"(",
"'Diffing '",
"+",
"inputFile1",
"+",
"' and '",
"+",
"inputFile2",
"+",
"'...'",
")",
";",
"console",
".",
"log",
"(",
"''",
")",
";",
"var",
"filter",
"=",
"null",
";",
"if",
"(",
"filterString",
")",
"{",
"filter",
"=",
"new",
"wtf",
".",
"db",
".",
"Filter",
"(",
"filterString",
")",
";",
"}",
"// Create databases for querying.",
"var",
"db1",
"=",
"null",
";",
"var",
"db2",
"=",
"null",
";",
"wtf",
".",
"db",
".",
"load",
"(",
"inputFile1",
",",
"function",
"(",
"db",
")",
"{",
"if",
"(",
"db",
"instanceof",
"Error",
")",
"{",
"console",
".",
"log",
"(",
"'ERROR: unable to open '",
"+",
"inputFile1",
",",
"db",
")",
";",
"done",
"(",
"1",
")",
";",
"return",
";",
"}",
"db1",
"=",
"db",
";",
"if",
"(",
"db1",
"&&",
"db2",
")",
"{",
"diffDatabases",
"(",
"db1",
",",
"db2",
",",
"filter",
")",
";",
"done",
"(",
"0",
")",
";",
"}",
"}",
")",
";",
"wtf",
".",
"db",
".",
"load",
"(",
"inputFile2",
",",
"function",
"(",
"db",
")",
"{",
"if",
"(",
"db",
"instanceof",
"Error",
")",
"{",
"console",
".",
"log",
"(",
"'ERROR: unable to open '",
"+",
"inputFile2",
",",
"db",
")",
";",
"done",
"(",
"1",
")",
";",
"return",
";",
"}",
"db2",
"=",
"db",
";",
"if",
"(",
"db1",
"&&",
"db2",
")",
"{",
"diffDatabases",
"(",
"db1",
",",
"db2",
",",
"filter",
")",
";",
"done",
"(",
"0",
")",
";",
"}",
"}",
")",
";",
"}"
] |
Diff tool.
@param {!wtf.pal.IPlatform} platform Platform abstraction layer.
@param {!Array.<string>} args Command line arguments.
@param {function(number)} done Call to end the program with a return code.
|
[
"Diff",
"tool",
"."
] |
495ced98de99a5895e484b2e09771edb42d3c7ab
|
https://github.com/google/tracing-framework/blob/495ced98de99a5895e484b2e09771edb42d3c7ab/bin/diff.js#L26-L72
|
17,723
|
google/tracing-framework
|
third_party/d3/sankey.js
|
computeNodeLinks
|
function computeNodeLinks() {
nodes.forEach(function(node) {
node.sourceLinks = [];
node.targetLinks = [];
});
links.forEach(function(link) {
var source = link.source,
target = link.target;
if (typeof source === "number") source = link.source = nodes[link.source];
if (typeof target === "number") target = link.target = nodes[link.target];
source.sourceLinks.push(link);
target.targetLinks.push(link);
});
}
|
javascript
|
function computeNodeLinks() {
nodes.forEach(function(node) {
node.sourceLinks = [];
node.targetLinks = [];
});
links.forEach(function(link) {
var source = link.source,
target = link.target;
if (typeof source === "number") source = link.source = nodes[link.source];
if (typeof target === "number") target = link.target = nodes[link.target];
source.sourceLinks.push(link);
target.targetLinks.push(link);
});
}
|
[
"function",
"computeNodeLinks",
"(",
")",
"{",
"nodes",
".",
"forEach",
"(",
"function",
"(",
"node",
")",
"{",
"node",
".",
"sourceLinks",
"=",
"[",
"]",
";",
"node",
".",
"targetLinks",
"=",
"[",
"]",
";",
"}",
")",
";",
"links",
".",
"forEach",
"(",
"function",
"(",
"link",
")",
"{",
"var",
"source",
"=",
"link",
".",
"source",
",",
"target",
"=",
"link",
".",
"target",
";",
"if",
"(",
"typeof",
"source",
"===",
"\"number\"",
")",
"source",
"=",
"link",
".",
"source",
"=",
"nodes",
"[",
"link",
".",
"source",
"]",
";",
"if",
"(",
"typeof",
"target",
"===",
"\"number\"",
")",
"target",
"=",
"link",
".",
"target",
"=",
"nodes",
"[",
"link",
".",
"target",
"]",
";",
"source",
".",
"sourceLinks",
".",
"push",
"(",
"link",
")",
";",
"target",
".",
"targetLinks",
".",
"push",
"(",
"link",
")",
";",
"}",
")",
";",
"}"
] |
Populate the sourceLinks and targetLinks for each node. Also, if the source and target are not objects, assume they are indices.
|
[
"Populate",
"the",
"sourceLinks",
"and",
"targetLinks",
"for",
"each",
"node",
".",
"Also",
"if",
"the",
"source",
"and",
"target",
"are",
"not",
"objects",
"assume",
"they",
"are",
"indices",
"."
] |
495ced98de99a5895e484b2e09771edb42d3c7ab
|
https://github.com/google/tracing-framework/blob/495ced98de99a5895e484b2e09771edb42d3c7ab/third_party/d3/sankey.js#L82-L95
|
17,724
|
google/tracing-framework
|
extensions/wtf-injector-firefox/data/content-script.js
|
injectScriptFunction
|
function injectScriptFunction(fn, opt_args) {
// Format args as strings that can go in the source.
var args = opt_args || [];
for (var n = 0; n < args.length; n++) {
if (args[n] === undefined) {
args[n] = 'undefined';
} else if (args[n] === null) {
args[n] = 'null';
} else if (typeof args[n] == 'string') {
// TODO(benvanik): escape
args[n] = '"' + args[n] + '"';
} else if (typeof args[n] == 'object') {
args[n] = JSON.stringify(args[n]);
}
}
args = args.join(',');
// TODO(benvanik): escape fn source
var source = [
'(' + String(fn) + ')(' + args + ');',
'// Web Tracing Framework injected function: ' + fn.name,
'//# sourceURL=x://wtf-injector/' + fn.name
].join('\n');
// Create script tag.
var script = document.createElement('script');
script.text = source;
// Add to page.
injectScriptTag(script);
}
|
javascript
|
function injectScriptFunction(fn, opt_args) {
// Format args as strings that can go in the source.
var args = opt_args || [];
for (var n = 0; n < args.length; n++) {
if (args[n] === undefined) {
args[n] = 'undefined';
} else if (args[n] === null) {
args[n] = 'null';
} else if (typeof args[n] == 'string') {
// TODO(benvanik): escape
args[n] = '"' + args[n] + '"';
} else if (typeof args[n] == 'object') {
args[n] = JSON.stringify(args[n]);
}
}
args = args.join(',');
// TODO(benvanik): escape fn source
var source = [
'(' + String(fn) + ')(' + args + ');',
'// Web Tracing Framework injected function: ' + fn.name,
'//# sourceURL=x://wtf-injector/' + fn.name
].join('\n');
// Create script tag.
var script = document.createElement('script');
script.text = source;
// Add to page.
injectScriptTag(script);
}
|
[
"function",
"injectScriptFunction",
"(",
"fn",
",",
"opt_args",
")",
"{",
"// Format args as strings that can go in the source.",
"var",
"args",
"=",
"opt_args",
"||",
"[",
"]",
";",
"for",
"(",
"var",
"n",
"=",
"0",
";",
"n",
"<",
"args",
".",
"length",
";",
"n",
"++",
")",
"{",
"if",
"(",
"args",
"[",
"n",
"]",
"===",
"undefined",
")",
"{",
"args",
"[",
"n",
"]",
"=",
"'undefined'",
";",
"}",
"else",
"if",
"(",
"args",
"[",
"n",
"]",
"===",
"null",
")",
"{",
"args",
"[",
"n",
"]",
"=",
"'null'",
";",
"}",
"else",
"if",
"(",
"typeof",
"args",
"[",
"n",
"]",
"==",
"'string'",
")",
"{",
"// TODO(benvanik): escape",
"args",
"[",
"n",
"]",
"=",
"'\"'",
"+",
"args",
"[",
"n",
"]",
"+",
"'\"'",
";",
"}",
"else",
"if",
"(",
"typeof",
"args",
"[",
"n",
"]",
"==",
"'object'",
")",
"{",
"args",
"[",
"n",
"]",
"=",
"JSON",
".",
"stringify",
"(",
"args",
"[",
"n",
"]",
")",
";",
"}",
"}",
"args",
"=",
"args",
".",
"join",
"(",
"','",
")",
";",
"// TODO(benvanik): escape fn source",
"var",
"source",
"=",
"[",
"'('",
"+",
"String",
"(",
"fn",
")",
"+",
"')('",
"+",
"args",
"+",
"');'",
",",
"'// Web Tracing Framework injected function: '",
"+",
"fn",
".",
"name",
",",
"'//# sourceURL=x://wtf-injector/'",
"+",
"fn",
".",
"name",
"]",
".",
"join",
"(",
"'\\n'",
")",
";",
"// Create script tag.",
"var",
"script",
"=",
"document",
".",
"createElement",
"(",
"'script'",
")",
";",
"script",
".",
"text",
"=",
"source",
";",
"// Add to page.",
"injectScriptTag",
"(",
"script",
")",
";",
"}"
] |
Injects a function into the page.
@param {!Function} fn Function to inject.
@param {Array=} opt_args Arguments array. All must be string serializable.
|
[
"Injects",
"a",
"function",
"into",
"the",
"page",
"."
] |
495ced98de99a5895e484b2e09771edb42d3c7ab
|
https://github.com/google/tracing-framework/blob/495ced98de99a5895e484b2e09771edb42d3c7ab/extensions/wtf-injector-firefox/data/content-script.js#L48-L78
|
17,725
|
google/tracing-framework
|
extensions/wtf-injector-firefox/data/content-script.js
|
injectScriptFile
|
function injectScriptFile(url, rawText) {
var filename = url;
var lastSlash = url.lastIndexOf('/');
if (lastSlash != -1) {
filename = url.substr(lastSlash + 1);
}
var source = [
'(function() {' + rawText + '})();',
'// Web Tracing Framework injected file: ' + url,
'//# sourceURL=x://wtf-injector/' + filename
].join('\n');
// Setup script tag with the raw source.
var script = document.createElement('script');
script.type = 'text/javascript';
script.text = source;
// Add to page.
injectScriptTag(script);
}
|
javascript
|
function injectScriptFile(url, rawText) {
var filename = url;
var lastSlash = url.lastIndexOf('/');
if (lastSlash != -1) {
filename = url.substr(lastSlash + 1);
}
var source = [
'(function() {' + rawText + '})();',
'// Web Tracing Framework injected file: ' + url,
'//# sourceURL=x://wtf-injector/' + filename
].join('\n');
// Setup script tag with the raw source.
var script = document.createElement('script');
script.type = 'text/javascript';
script.text = source;
// Add to page.
injectScriptTag(script);
}
|
[
"function",
"injectScriptFile",
"(",
"url",
",",
"rawText",
")",
"{",
"var",
"filename",
"=",
"url",
";",
"var",
"lastSlash",
"=",
"url",
".",
"lastIndexOf",
"(",
"'/'",
")",
";",
"if",
"(",
"lastSlash",
"!=",
"-",
"1",
")",
"{",
"filename",
"=",
"url",
".",
"substr",
"(",
"lastSlash",
"+",
"1",
")",
";",
"}",
"var",
"source",
"=",
"[",
"'(function() {'",
"+",
"rawText",
"+",
"'})();'",
",",
"'// Web Tracing Framework injected file: '",
"+",
"url",
",",
"'//# sourceURL=x://wtf-injector/'",
"+",
"filename",
"]",
".",
"join",
"(",
"'\\n'",
")",
";",
"// Setup script tag with the raw source.",
"var",
"script",
"=",
"document",
".",
"createElement",
"(",
"'script'",
")",
";",
"script",
".",
"type",
"=",
"'text/javascript'",
";",
"script",
".",
"text",
"=",
"source",
";",
"// Add to page.",
"injectScriptTag",
"(",
"script",
")",
";",
"}"
] |
Injects a script file into the page.
@param {string} url Script URL.
@param {string} rawText Script raw text contents.
|
[
"Injects",
"a",
"script",
"file",
"into",
"the",
"page",
"."
] |
495ced98de99a5895e484b2e09771edb42d3c7ab
|
https://github.com/google/tracing-framework/blob/495ced98de99a5895e484b2e09771edb42d3c7ab/extensions/wtf-injector-firefox/data/content-script.js#L86-L106
|
17,726
|
google/tracing-framework
|
extensions/wtf-injector-firefox/data/content-script.js
|
startTracing
|
function startTracing(addons) {
// NOTE: this code is injected by string and cannot access any closure
// variables!
// Register addons.
for (var url in addons) {
var name = addons[url]['name'];
log('WTF Addon Installed: ' + name + ' (' + url + ')');
wtf.addon.registerAddon(url, addons[url]);
}
// Show HUD.
wtf.hud.prepare();
// Start recording.
wtf.trace.start();
}
|
javascript
|
function startTracing(addons) {
// NOTE: this code is injected by string and cannot access any closure
// variables!
// Register addons.
for (var url in addons) {
var name = addons[url]['name'];
log('WTF Addon Installed: ' + name + ' (' + url + ')');
wtf.addon.registerAddon(url, addons[url]);
}
// Show HUD.
wtf.hud.prepare();
// Start recording.
wtf.trace.start();
}
|
[
"function",
"startTracing",
"(",
"addons",
")",
"{",
"// NOTE: this code is injected by string and cannot access any closure",
"// variables!",
"// Register addons.",
"for",
"(",
"var",
"url",
"in",
"addons",
")",
"{",
"var",
"name",
"=",
"addons",
"[",
"url",
"]",
"[",
"'name'",
"]",
";",
"log",
"(",
"'WTF Addon Installed: '",
"+",
"name",
"+",
"' ('",
"+",
"url",
"+",
"')'",
")",
";",
"wtf",
".",
"addon",
".",
"registerAddon",
"(",
"url",
",",
"addons",
"[",
"url",
"]",
")",
";",
"}",
"// Show HUD.",
"wtf",
".",
"hud",
".",
"prepare",
"(",
")",
";",
"// Start recording.",
"wtf",
".",
"trace",
".",
"start",
"(",
")",
";",
"}"
] |
In-page trace preparation function.
This is directly inserted into the page and should run immediately after
the library has been loaded.
This function is stringified and passed to the page, so expect no closure
variables and all arguments must be serializable.
@param {!Object.<!Object>} addons A map of URL to addon JSON.
|
[
"In",
"-",
"page",
"trace",
"preparation",
"function",
".",
"This",
"is",
"directly",
"inserted",
"into",
"the",
"page",
"and",
"should",
"run",
"immediately",
"after",
"the",
"library",
"has",
"been",
"loaded",
"."
] |
495ced98de99a5895e484b2e09771edb42d3c7ab
|
https://github.com/google/tracing-framework/blob/495ced98de99a5895e484b2e09771edb42d3c7ab/extensions/wtf-injector-firefox/data/content-script.js#L165-L180
|
17,727
|
google/tracing-framework
|
src/wtf/trace/providers/xhrprovider.js
|
XMLHttpRequest
|
function XMLHttpRequest() {
var scope = ctorEvent();
goog.base(this, descriptor);
/**
* Real XHR.
* @type {!XMLHttpRequest}
* @private
*/
this.handle_ = new originalXhr();
/**
* Event type trackers, by name.
* @type {!Object.<Function>}
* @private
*/
this.trackers_ = {};
/**
* Properties, accumulated during setup before send().
* @type {!Object}
* @private
*/
this.props_ = {
'method': null,
'url': null,
'async': true,
'user': null,
'headers': {},
'timeout': 0,
'withCredentials': false,
'overrideMimeType': null,
'responseType': ''
};
/**
* Active flow, if any.
* @type {wtf.trace.Flow}
* @private
*/
this.flow_ = null;
// Always hook onreadystatechange.
// By doing it here we get first access to the event.
var self = this;
var handle = this.handle_;
var props = this.props_;
this.handle_.addEventListener('readystatechange', function(e) {
var flow = self.flow_;
if (!flow) {
return;
}
var value = undefined;
if (handle.readyState == 2) {
var headers = {};
var allHeaders = handle.getAllResponseHeaders().split('\r\n');
for (var n = 0; n < allHeaders.length; n++) {
if (allHeaders[n].length) {
var parts = allHeaders[n].split(':');
headers[parts[0]] = parts[1].substr(1);
}
}
value = {
'status': this.status,
'statusText': this.statusText,
'headers': headers
};
// TODO(benvanik): appendFlowData
}
// TODO(benvanik): response size/type/etc
// Extend flow, terminate if required.
if (handle.readyState < 4) {
wtf.trace.Flow.extend(flow, 'readyState: ' + handle.readyState, value);
} else {
wtf.trace.Flow.terminate(flow, 'readyState: ' + handle.readyState);
}
}, false);
// Add data to interesting events.
this.setEventHook('readystatechange', function(e) {
wtf.trace.appendScopeData('url', props['url']);
wtf.trace.appendScopeData('readyState', handle['readyState']);
});
this.setEventHook('load', function(e) {
wtf.trace.appendScopeData('url', props['url']);
});
wtf.trace.Scope.leave(scope);
}
|
javascript
|
function XMLHttpRequest() {
var scope = ctorEvent();
goog.base(this, descriptor);
/**
* Real XHR.
* @type {!XMLHttpRequest}
* @private
*/
this.handle_ = new originalXhr();
/**
* Event type trackers, by name.
* @type {!Object.<Function>}
* @private
*/
this.trackers_ = {};
/**
* Properties, accumulated during setup before send().
* @type {!Object}
* @private
*/
this.props_ = {
'method': null,
'url': null,
'async': true,
'user': null,
'headers': {},
'timeout': 0,
'withCredentials': false,
'overrideMimeType': null,
'responseType': ''
};
/**
* Active flow, if any.
* @type {wtf.trace.Flow}
* @private
*/
this.flow_ = null;
// Always hook onreadystatechange.
// By doing it here we get first access to the event.
var self = this;
var handle = this.handle_;
var props = this.props_;
this.handle_.addEventListener('readystatechange', function(e) {
var flow = self.flow_;
if (!flow) {
return;
}
var value = undefined;
if (handle.readyState == 2) {
var headers = {};
var allHeaders = handle.getAllResponseHeaders().split('\r\n');
for (var n = 0; n < allHeaders.length; n++) {
if (allHeaders[n].length) {
var parts = allHeaders[n].split(':');
headers[parts[0]] = parts[1].substr(1);
}
}
value = {
'status': this.status,
'statusText': this.statusText,
'headers': headers
};
// TODO(benvanik): appendFlowData
}
// TODO(benvanik): response size/type/etc
// Extend flow, terminate if required.
if (handle.readyState < 4) {
wtf.trace.Flow.extend(flow, 'readyState: ' + handle.readyState, value);
} else {
wtf.trace.Flow.terminate(flow, 'readyState: ' + handle.readyState);
}
}, false);
// Add data to interesting events.
this.setEventHook('readystatechange', function(e) {
wtf.trace.appendScopeData('url', props['url']);
wtf.trace.appendScopeData('readyState', handle['readyState']);
});
this.setEventHook('load', function(e) {
wtf.trace.appendScopeData('url', props['url']);
});
wtf.trace.Scope.leave(scope);
}
|
[
"function",
"XMLHttpRequest",
"(",
")",
"{",
"var",
"scope",
"=",
"ctorEvent",
"(",
")",
";",
"goog",
".",
"base",
"(",
"this",
",",
"descriptor",
")",
";",
"/**\n * Real XHR.\n * @type {!XMLHttpRequest}\n * @private\n */",
"this",
".",
"handle_",
"=",
"new",
"originalXhr",
"(",
")",
";",
"/**\n * Event type trackers, by name.\n * @type {!Object.<Function>}\n * @private\n */",
"this",
".",
"trackers_",
"=",
"{",
"}",
";",
"/**\n * Properties, accumulated during setup before send().\n * @type {!Object}\n * @private\n */",
"this",
".",
"props_",
"=",
"{",
"'method'",
":",
"null",
",",
"'url'",
":",
"null",
",",
"'async'",
":",
"true",
",",
"'user'",
":",
"null",
",",
"'headers'",
":",
"{",
"}",
",",
"'timeout'",
":",
"0",
",",
"'withCredentials'",
":",
"false",
",",
"'overrideMimeType'",
":",
"null",
",",
"'responseType'",
":",
"''",
"}",
";",
"/**\n * Active flow, if any.\n * @type {wtf.trace.Flow}\n * @private\n */",
"this",
".",
"flow_",
"=",
"null",
";",
"// Always hook onreadystatechange.",
"// By doing it here we get first access to the event.",
"var",
"self",
"=",
"this",
";",
"var",
"handle",
"=",
"this",
".",
"handle_",
";",
"var",
"props",
"=",
"this",
".",
"props_",
";",
"this",
".",
"handle_",
".",
"addEventListener",
"(",
"'readystatechange'",
",",
"function",
"(",
"e",
")",
"{",
"var",
"flow",
"=",
"self",
".",
"flow_",
";",
"if",
"(",
"!",
"flow",
")",
"{",
"return",
";",
"}",
"var",
"value",
"=",
"undefined",
";",
"if",
"(",
"handle",
".",
"readyState",
"==",
"2",
")",
"{",
"var",
"headers",
"=",
"{",
"}",
";",
"var",
"allHeaders",
"=",
"handle",
".",
"getAllResponseHeaders",
"(",
")",
".",
"split",
"(",
"'\\r\\n'",
")",
";",
"for",
"(",
"var",
"n",
"=",
"0",
";",
"n",
"<",
"allHeaders",
".",
"length",
";",
"n",
"++",
")",
"{",
"if",
"(",
"allHeaders",
"[",
"n",
"]",
".",
"length",
")",
"{",
"var",
"parts",
"=",
"allHeaders",
"[",
"n",
"]",
".",
"split",
"(",
"':'",
")",
";",
"headers",
"[",
"parts",
"[",
"0",
"]",
"]",
"=",
"parts",
"[",
"1",
"]",
".",
"substr",
"(",
"1",
")",
";",
"}",
"}",
"value",
"=",
"{",
"'status'",
":",
"this",
".",
"status",
",",
"'statusText'",
":",
"this",
".",
"statusText",
",",
"'headers'",
":",
"headers",
"}",
";",
"// TODO(benvanik): appendFlowData",
"}",
"// TODO(benvanik): response size/type/etc",
"// Extend flow, terminate if required.",
"if",
"(",
"handle",
".",
"readyState",
"<",
"4",
")",
"{",
"wtf",
".",
"trace",
".",
"Flow",
".",
"extend",
"(",
"flow",
",",
"'readyState: '",
"+",
"handle",
".",
"readyState",
",",
"value",
")",
";",
"}",
"else",
"{",
"wtf",
".",
"trace",
".",
"Flow",
".",
"terminate",
"(",
"flow",
",",
"'readyState: '",
"+",
"handle",
".",
"readyState",
")",
";",
"}",
"}",
",",
"false",
")",
";",
"// Add data to interesting events.",
"this",
".",
"setEventHook",
"(",
"'readystatechange'",
",",
"function",
"(",
"e",
")",
"{",
"wtf",
".",
"trace",
".",
"appendScopeData",
"(",
"'url'",
",",
"props",
"[",
"'url'",
"]",
")",
";",
"wtf",
".",
"trace",
".",
"appendScopeData",
"(",
"'readyState'",
",",
"handle",
"[",
"'readyState'",
"]",
")",
";",
"}",
")",
";",
"this",
".",
"setEventHook",
"(",
"'load'",
",",
"function",
"(",
"e",
")",
"{",
"wtf",
".",
"trace",
".",
"appendScopeData",
"(",
"'url'",
",",
"props",
"[",
"'url'",
"]",
")",
";",
"}",
")",
";",
"wtf",
".",
"trace",
".",
"Scope",
".",
"leave",
"(",
"scope",
")",
";",
"}"
] |
Proxy XHR.
@constructor
@extends {wtf.trace.eventtarget.BaseEventTarget}
|
[
"Proxy",
"XHR",
"."
] |
495ced98de99a5895e484b2e09771edb42d3c7ab
|
https://github.com/google/tracing-framework/blob/495ced98de99a5895e484b2e09771edb42d3c7ab/src/wtf/trace/providers/xhrprovider.js#L103-L193
|
17,728
|
google/tracing-framework
|
src/wtf/trace/providers/xhrprovider.js
|
setupProxyProperty
|
function setupProxyProperty(name, opt_setPropsValue) {
Object.defineProperty(ProxyXMLHttpRequest.prototype, name, {
'configurable': true,
'enumerable': true,
'get': function() {
return this.handle_[name];
},
'set': opt_setPropsValue ? function(value) {
this.props_[name] = value;
this.handle_[name] = value;
} : function(value) {
this.handle_[name] = value;
}
});
}
|
javascript
|
function setupProxyProperty(name, opt_setPropsValue) {
Object.defineProperty(ProxyXMLHttpRequest.prototype, name, {
'configurable': true,
'enumerable': true,
'get': function() {
return this.handle_[name];
},
'set': opt_setPropsValue ? function(value) {
this.props_[name] = value;
this.handle_[name] = value;
} : function(value) {
this.handle_[name] = value;
}
});
}
|
[
"function",
"setupProxyProperty",
"(",
"name",
",",
"opt_setPropsValue",
")",
"{",
"Object",
".",
"defineProperty",
"(",
"ProxyXMLHttpRequest",
".",
"prototype",
",",
"name",
",",
"{",
"'configurable'",
":",
"true",
",",
"'enumerable'",
":",
"true",
",",
"'get'",
":",
"function",
"(",
")",
"{",
"return",
"this",
".",
"handle_",
"[",
"name",
"]",
";",
"}",
",",
"'set'",
":",
"opt_setPropsValue",
"?",
"function",
"(",
"value",
")",
"{",
"this",
".",
"props_",
"[",
"name",
"]",
"=",
"value",
";",
"this",
".",
"handle_",
"[",
"name",
"]",
"=",
"value",
";",
"}",
":",
"function",
"(",
"value",
")",
"{",
"this",
".",
"handle_",
"[",
"name",
"]",
"=",
"value",
";",
"}",
"}",
")",
";",
"}"
] |
Sets up a proxy property, optionally setting a props bag value.
@param {string} name Property name.
@param {boolean=} opt_setPropsValue True to set a props value of the same
name with the given value.
|
[
"Sets",
"up",
"a",
"proxy",
"property",
"optionally",
"setting",
"a",
"props",
"bag",
"value",
"."
] |
495ced98de99a5895e484b2e09771edb42d3c7ab
|
https://github.com/google/tracing-framework/blob/495ced98de99a5895e484b2e09771edb42d3c7ab/src/wtf/trace/providers/xhrprovider.js#L251-L265
|
17,729
|
google/tracing-framework
|
extensions/wtf-injector-chrome/wtf-call-tracing.js
|
function(baseUrl, url) {
if (!resolveCache) {
var iframe = document.createElement('iframe');
document.documentElement.appendChild(iframe);
var doc = iframe.contentWindow.document;
var base = doc.createElement('base');
doc.documentElement.appendChild(base);
var a = doc.createElement('a');
doc.documentElement.appendChild(a);
iframe.parentNode.removeChild(iframe);
resolveCache = {
iframe: iframe,
base: base,
a: a
};
}
resolveCache.base.href = baseUrl;
resolveCache.a.href = url;
return resolveCache.a.href;
}
|
javascript
|
function(baseUrl, url) {
if (!resolveCache) {
var iframe = document.createElement('iframe');
document.documentElement.appendChild(iframe);
var doc = iframe.contentWindow.document;
var base = doc.createElement('base');
doc.documentElement.appendChild(base);
var a = doc.createElement('a');
doc.documentElement.appendChild(a);
iframe.parentNode.removeChild(iframe);
resolveCache = {
iframe: iframe,
base: base,
a: a
};
}
resolveCache.base.href = baseUrl;
resolveCache.a.href = url;
return resolveCache.a.href;
}
|
[
"function",
"(",
"baseUrl",
",",
"url",
")",
"{",
"if",
"(",
"!",
"resolveCache",
")",
"{",
"var",
"iframe",
"=",
"document",
".",
"createElement",
"(",
"'iframe'",
")",
";",
"document",
".",
"documentElement",
".",
"appendChild",
"(",
"iframe",
")",
";",
"var",
"doc",
"=",
"iframe",
".",
"contentWindow",
".",
"document",
";",
"var",
"base",
"=",
"doc",
".",
"createElement",
"(",
"'base'",
")",
";",
"doc",
".",
"documentElement",
".",
"appendChild",
"(",
"base",
")",
";",
"var",
"a",
"=",
"doc",
".",
"createElement",
"(",
"'a'",
")",
";",
"doc",
".",
"documentElement",
".",
"appendChild",
"(",
"a",
")",
";",
"iframe",
".",
"parentNode",
".",
"removeChild",
"(",
"iframe",
")",
";",
"resolveCache",
"=",
"{",
"iframe",
":",
"iframe",
",",
"base",
":",
"base",
",",
"a",
":",
"a",
"}",
";",
"}",
"resolveCache",
".",
"base",
".",
"href",
"=",
"baseUrl",
";",
"resolveCache",
".",
"a",
".",
"href",
"=",
"url",
";",
"return",
"resolveCache",
".",
"a",
".",
"href",
";",
"}"
] |
Resolves a URL to an absolute path.
@param {string} baseUrl Base URL.
@param {string} url Target URL.
|
[
"Resolves",
"a",
"URL",
"to",
"an",
"absolute",
"path",
"."
] |
495ced98de99a5895e484b2e09771edb42d3c7ab
|
https://github.com/google/tracing-framework/blob/495ced98de99a5895e484b2e09771edb42d3c7ab/extensions/wtf-injector-chrome/wtf-call-tracing.js#L88-L107
|
|
17,730
|
google/tracing-framework
|
src/wtf/trace/providers/websocketprovider.js
|
WebSocket
|
function WebSocket(url, opt_protocols) {
var scope = ctorEvent();
goog.base(this, descriptor);
/**
* Underlying WS.
* @type {!WebSocket}
* @private
*/
this.handle_ = arguments.length == 1 ?
new originalWs(url) :
new originalWs(url, opt_protocols);
/**
* Event type trackers, by name.
* @type {!Object.<Function>}
* @private
*/
this.trackers_ = {};
/**
* Properties, accumulated during setup before send().
* @type {!Object}
* @private
*/
this.props_ = {
'url': url,
'protocol': opt_protocols
};
wtf.trace.Scope.leave(scope);
}
|
javascript
|
function WebSocket(url, opt_protocols) {
var scope = ctorEvent();
goog.base(this, descriptor);
/**
* Underlying WS.
* @type {!WebSocket}
* @private
*/
this.handle_ = arguments.length == 1 ?
new originalWs(url) :
new originalWs(url, opt_protocols);
/**
* Event type trackers, by name.
* @type {!Object.<Function>}
* @private
*/
this.trackers_ = {};
/**
* Properties, accumulated during setup before send().
* @type {!Object}
* @private
*/
this.props_ = {
'url': url,
'protocol': opt_protocols
};
wtf.trace.Scope.leave(scope);
}
|
[
"function",
"WebSocket",
"(",
"url",
",",
"opt_protocols",
")",
"{",
"var",
"scope",
"=",
"ctorEvent",
"(",
")",
";",
"goog",
".",
"base",
"(",
"this",
",",
"descriptor",
")",
";",
"/**\n * Underlying WS.\n * @type {!WebSocket}\n * @private\n */",
"this",
".",
"handle_",
"=",
"arguments",
".",
"length",
"==",
"1",
"?",
"new",
"originalWs",
"(",
"url",
")",
":",
"new",
"originalWs",
"(",
"url",
",",
"opt_protocols",
")",
";",
"/**\n * Event type trackers, by name.\n * @type {!Object.<Function>}\n * @private\n */",
"this",
".",
"trackers_",
"=",
"{",
"}",
";",
"/**\n * Properties, accumulated during setup before send().\n * @type {!Object}\n * @private\n */",
"this",
".",
"props_",
"=",
"{",
"'url'",
":",
"url",
",",
"'protocol'",
":",
"opt_protocols",
"}",
";",
"wtf",
".",
"trace",
".",
"Scope",
".",
"leave",
"(",
"scope",
")",
";",
"}"
] |
Proxy WebSocket.
@constructor
@param {string} url Destination URL.
@param {string=} opt_protocols Optional protocol.
@extends {wtf.trace.eventtarget.BaseEventTarget}
|
[
"Proxy",
"WebSocket",
"."
] |
495ced98de99a5895e484b2e09771edb42d3c7ab
|
https://github.com/google/tracing-framework/blob/495ced98de99a5895e484b2e09771edb42d3c7ab/src/wtf/trace/providers/websocketprovider.js#L99-L130
|
17,731
|
google/tracing-framework
|
extensions/wtf-injector-chrome/options.js
|
function() {
/**
* Whether to show the page-action 'inject' icon.
* @type {boolean}
*/
this.showPageAction = true;
/**
* Whether to show the context menu items.
* @type {boolean}
*/
this.showContextMenu = false;
/**
* Whether to show the devtools panel.
* @type {boolean}
*/
this.showDevPanel = false;
/**
* A list of all added extensions, mapped by URL.
* @type {!Object.<!Object>}
* @private
*/
this.addons_ = {};
/**
* A map of instrumented tab IDs to their instrumentation options.
* If a tab has an entry in this map it is considered instrumented and
* that superceeds other whitelisting options.
* This is not saved (yet), as it's usually a one-off thing.
* @type {!Object.<number, Object>}
*/
this.instrumentedTabs_ = {};
/**
* A list of page match patterns that will have tracing on.
* @type {!Array.<string>}
* @private
*/
this.pageWhitelist_ = [];
/**
* A list of page match patterns that will have tracing off.
* @type {!Array.<string>}
* @private
*/
this.pageBlacklist_ = [];
/**
* A map of URLs to page options objects.
* @type {!Object.<!Object>}
* @private
*/
this.pageOptions_ = {};
/**
* Default endpoint to use for pages.
* @type {{mode: string, endpoint: string}}
* @private
*/
this.defaultEndpoint_ = {
mode: 'page',
endpoint: chrome.extension.getURL('app/maindisplay.html')
};
}
|
javascript
|
function() {
/**
* Whether to show the page-action 'inject' icon.
* @type {boolean}
*/
this.showPageAction = true;
/**
* Whether to show the context menu items.
* @type {boolean}
*/
this.showContextMenu = false;
/**
* Whether to show the devtools panel.
* @type {boolean}
*/
this.showDevPanel = false;
/**
* A list of all added extensions, mapped by URL.
* @type {!Object.<!Object>}
* @private
*/
this.addons_ = {};
/**
* A map of instrumented tab IDs to their instrumentation options.
* If a tab has an entry in this map it is considered instrumented and
* that superceeds other whitelisting options.
* This is not saved (yet), as it's usually a one-off thing.
* @type {!Object.<number, Object>}
*/
this.instrumentedTabs_ = {};
/**
* A list of page match patterns that will have tracing on.
* @type {!Array.<string>}
* @private
*/
this.pageWhitelist_ = [];
/**
* A list of page match patterns that will have tracing off.
* @type {!Array.<string>}
* @private
*/
this.pageBlacklist_ = [];
/**
* A map of URLs to page options objects.
* @type {!Object.<!Object>}
* @private
*/
this.pageOptions_ = {};
/**
* Default endpoint to use for pages.
* @type {{mode: string, endpoint: string}}
* @private
*/
this.defaultEndpoint_ = {
mode: 'page',
endpoint: chrome.extension.getURL('app/maindisplay.html')
};
}
|
[
"function",
"(",
")",
"{",
"/**\n * Whether to show the page-action 'inject' icon.\n * @type {boolean}\n */",
"this",
".",
"showPageAction",
"=",
"true",
";",
"/**\n * Whether to show the context menu items.\n * @type {boolean}\n */",
"this",
".",
"showContextMenu",
"=",
"false",
";",
"/**\n * Whether to show the devtools panel.\n * @type {boolean}\n */",
"this",
".",
"showDevPanel",
"=",
"false",
";",
"/**\n * A list of all added extensions, mapped by URL.\n * @type {!Object.<!Object>}\n * @private\n */",
"this",
".",
"addons_",
"=",
"{",
"}",
";",
"/**\n * A map of instrumented tab IDs to their instrumentation options.\n * If a tab has an entry in this map it is considered instrumented and\n * that superceeds other whitelisting options.\n * This is not saved (yet), as it's usually a one-off thing.\n * @type {!Object.<number, Object>}\n */",
"this",
".",
"instrumentedTabs_",
"=",
"{",
"}",
";",
"/**\n * A list of page match patterns that will have tracing on.\n * @type {!Array.<string>}\n * @private\n */",
"this",
".",
"pageWhitelist_",
"=",
"[",
"]",
";",
"/**\n * A list of page match patterns that will have tracing off.\n * @type {!Array.<string>}\n * @private\n */",
"this",
".",
"pageBlacklist_",
"=",
"[",
"]",
";",
"/**\n * A map of URLs to page options objects.\n * @type {!Object.<!Object>}\n * @private\n */",
"this",
".",
"pageOptions_",
"=",
"{",
"}",
";",
"/**\n * Default endpoint to use for pages.\n * @type {{mode: string, endpoint: string}}\n * @private\n */",
"this",
".",
"defaultEndpoint_",
"=",
"{",
"mode",
":",
"'page'",
",",
"endpoint",
":",
"chrome",
".",
"extension",
".",
"getURL",
"(",
"'app/maindisplay.html'",
")",
"}",
";",
"}"
] |
Options wrapper.
Saves settings with the Chrome settings store.
Settings are saved as a big blob to enable syncrhonous access to values.
@constructor
|
[
"Options",
"wrapper",
".",
"Saves",
"settings",
"with",
"the",
"Chrome",
"settings",
"store",
".",
"Settings",
"are",
"saved",
"as",
"a",
"big",
"blob",
"to",
"enable",
"syncrhonous",
"access",
"to",
"values",
"."
] |
495ced98de99a5895e484b2e09771edb42d3c7ab
|
https://github.com/google/tracing-framework/blob/495ced98de99a5895e484b2e09771edb42d3c7ab/extensions/wtf-injector-chrome/options.js#L34-L99
|
|
17,732
|
google/tracing-framework
|
bin/query.js
|
runTool
|
function runTool(platform, args, done) {
if (args.length < 1) {
console.log('usage: query.js file.wtf-trace "[query string]"');
done(1);
return;
}
var inputFile = args[0];
var exprArgs = args.slice(1);
var expr = exprArgs.join(' ').trim();
console.log('Querying ' + inputFile + '...');
// Create database for querying.
var loadStart = wtf.now();
wtf.db.load(inputFile, function(db) {
if (db instanceof Error) {
console.log('ERROR: unable to open ' + inputFile, db);
done(1);
return;
}
var loadDuration = wtf.now() - loadStart;
console.log('Database loaded in ' + loadDuration.toFixed(3) + 'ms');
console.log('');
queryDatabase(db, expr);
done(0);
});
}
|
javascript
|
function runTool(platform, args, done) {
if (args.length < 1) {
console.log('usage: query.js file.wtf-trace "[query string]"');
done(1);
return;
}
var inputFile = args[0];
var exprArgs = args.slice(1);
var expr = exprArgs.join(' ').trim();
console.log('Querying ' + inputFile + '...');
// Create database for querying.
var loadStart = wtf.now();
wtf.db.load(inputFile, function(db) {
if (db instanceof Error) {
console.log('ERROR: unable to open ' + inputFile, db);
done(1);
return;
}
var loadDuration = wtf.now() - loadStart;
console.log('Database loaded in ' + loadDuration.toFixed(3) + 'ms');
console.log('');
queryDatabase(db, expr);
done(0);
});
}
|
[
"function",
"runTool",
"(",
"platform",
",",
"args",
",",
"done",
")",
"{",
"if",
"(",
"args",
".",
"length",
"<",
"1",
")",
"{",
"console",
".",
"log",
"(",
"'usage: query.js file.wtf-trace \"[query string]\"'",
")",
";",
"done",
"(",
"1",
")",
";",
"return",
";",
"}",
"var",
"inputFile",
"=",
"args",
"[",
"0",
"]",
";",
"var",
"exprArgs",
"=",
"args",
".",
"slice",
"(",
"1",
")",
";",
"var",
"expr",
"=",
"exprArgs",
".",
"join",
"(",
"' '",
")",
".",
"trim",
"(",
")",
";",
"console",
".",
"log",
"(",
"'Querying '",
"+",
"inputFile",
"+",
"'...'",
")",
";",
"// Create database for querying.",
"var",
"loadStart",
"=",
"wtf",
".",
"now",
"(",
")",
";",
"wtf",
".",
"db",
".",
"load",
"(",
"inputFile",
",",
"function",
"(",
"db",
")",
"{",
"if",
"(",
"db",
"instanceof",
"Error",
")",
"{",
"console",
".",
"log",
"(",
"'ERROR: unable to open '",
"+",
"inputFile",
",",
"db",
")",
";",
"done",
"(",
"1",
")",
";",
"return",
";",
"}",
"var",
"loadDuration",
"=",
"wtf",
".",
"now",
"(",
")",
"-",
"loadStart",
";",
"console",
".",
"log",
"(",
"'Database loaded in '",
"+",
"loadDuration",
".",
"toFixed",
"(",
"3",
")",
"+",
"'ms'",
")",
";",
"console",
".",
"log",
"(",
"''",
")",
";",
"queryDatabase",
"(",
"db",
",",
"expr",
")",
";",
"done",
"(",
"0",
")",
";",
"}",
")",
";",
"}"
] |
Query tool.
@param {!wtf.pal.IPlatform} platform Platform abstraction layer.
@param {!Array.<string>} args Command line arguments.
@param {function(number)} done Call to end the program with a return code.
|
[
"Query",
"tool",
"."
] |
495ced98de99a5895e484b2e09771edb42d3c7ab
|
https://github.com/google/tracing-framework/blob/495ced98de99a5895e484b2e09771edb42d3c7ab/bin/query.js#L29-L59
|
17,733
|
google/tracing-framework
|
bin/query.js
|
queryDatabase
|
function queryDatabase(db, expr) {
// TODO(benvanik): allow the user to switch zone.
var zone = db.getZones()[0];
// If the user provided an expression on the command line, use that.
if (expr && expr.length) {
issue(expr);
return 0;
}
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.on('line', function(line) {
line = line.trim();
if (line == 'q' || line == 'quit') {
rl.close();
return;
}
issue(line);
rl.prompt();
});
rl.on('close', function() {
console.log('');
db.dispose();
process.exit(0);
});
rl.setPrompt('> ');
rl.prompt();
function issue(expr) {
console.log('Expression: ' + expr);
var result;
try {
result = zone.query(expr);
} catch (e) {
console.log(e);
return;
}
var xexpr = result.getCompiledExpression();
console.log(xexpr.toString());
console.log('');
var resultValue = result.getValue();
if (resultValue instanceof wtf.db.EventIterator) {
var it = resultValue;
if (!it.getCount()) {
console.log('Nothing matched');
} else {
console.log('Results: (' + it.getCount() + ' total)');
for (; !it.done(); it.next()) {
util.logEvent(it, zone);
}
}
} else if (typeof resultValue == 'boolean' ||
typeof resultValue == 'number' ||
typeof resultValue == 'string') {
console.log('Result:');
logResult(resultValue);
} else if (!resultValue) {
// Note we test this after so that 0/strings/etc are handled.
console.log('Nothing matched');
} else if (resultValue.length) {
console.log('Results: (' + resultValue.length + ' total)');
for (var n = 0; n < resultValue.length; n++) {
logResult(resultValue[n]);
}
} else {
console.log('Result:');
logResult(resultValue);
}
console.log('');
console.log('Took ' + result.getDuration().toFixed(3) + 'ms');
}
}
|
javascript
|
function queryDatabase(db, expr) {
// TODO(benvanik): allow the user to switch zone.
var zone = db.getZones()[0];
// If the user provided an expression on the command line, use that.
if (expr && expr.length) {
issue(expr);
return 0;
}
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.on('line', function(line) {
line = line.trim();
if (line == 'q' || line == 'quit') {
rl.close();
return;
}
issue(line);
rl.prompt();
});
rl.on('close', function() {
console.log('');
db.dispose();
process.exit(0);
});
rl.setPrompt('> ');
rl.prompt();
function issue(expr) {
console.log('Expression: ' + expr);
var result;
try {
result = zone.query(expr);
} catch (e) {
console.log(e);
return;
}
var xexpr = result.getCompiledExpression();
console.log(xexpr.toString());
console.log('');
var resultValue = result.getValue();
if (resultValue instanceof wtf.db.EventIterator) {
var it = resultValue;
if (!it.getCount()) {
console.log('Nothing matched');
} else {
console.log('Results: (' + it.getCount() + ' total)');
for (; !it.done(); it.next()) {
util.logEvent(it, zone);
}
}
} else if (typeof resultValue == 'boolean' ||
typeof resultValue == 'number' ||
typeof resultValue == 'string') {
console.log('Result:');
logResult(resultValue);
} else if (!resultValue) {
// Note we test this after so that 0/strings/etc are handled.
console.log('Nothing matched');
} else if (resultValue.length) {
console.log('Results: (' + resultValue.length + ' total)');
for (var n = 0; n < resultValue.length; n++) {
logResult(resultValue[n]);
}
} else {
console.log('Result:');
logResult(resultValue);
}
console.log('');
console.log('Took ' + result.getDuration().toFixed(3) + 'ms');
}
}
|
[
"function",
"queryDatabase",
"(",
"db",
",",
"expr",
")",
"{",
"// TODO(benvanik): allow the user to switch zone.",
"var",
"zone",
"=",
"db",
".",
"getZones",
"(",
")",
"[",
"0",
"]",
";",
"// If the user provided an expression on the command line, use that.",
"if",
"(",
"expr",
"&&",
"expr",
".",
"length",
")",
"{",
"issue",
"(",
"expr",
")",
";",
"return",
"0",
";",
"}",
"var",
"rl",
"=",
"readline",
".",
"createInterface",
"(",
"{",
"input",
":",
"process",
".",
"stdin",
",",
"output",
":",
"process",
".",
"stdout",
"}",
")",
";",
"rl",
".",
"on",
"(",
"'line'",
",",
"function",
"(",
"line",
")",
"{",
"line",
"=",
"line",
".",
"trim",
"(",
")",
";",
"if",
"(",
"line",
"==",
"'q'",
"||",
"line",
"==",
"'quit'",
")",
"{",
"rl",
".",
"close",
"(",
")",
";",
"return",
";",
"}",
"issue",
"(",
"line",
")",
";",
"rl",
".",
"prompt",
"(",
")",
";",
"}",
")",
";",
"rl",
".",
"on",
"(",
"'close'",
",",
"function",
"(",
")",
"{",
"console",
".",
"log",
"(",
"''",
")",
";",
"db",
".",
"dispose",
"(",
")",
";",
"process",
".",
"exit",
"(",
"0",
")",
";",
"}",
")",
";",
"rl",
".",
"setPrompt",
"(",
"'> '",
")",
";",
"rl",
".",
"prompt",
"(",
")",
";",
"function",
"issue",
"(",
"expr",
")",
"{",
"console",
".",
"log",
"(",
"'Expression: '",
"+",
"expr",
")",
";",
"var",
"result",
";",
"try",
"{",
"result",
"=",
"zone",
".",
"query",
"(",
"expr",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"console",
".",
"log",
"(",
"e",
")",
";",
"return",
";",
"}",
"var",
"xexpr",
"=",
"result",
".",
"getCompiledExpression",
"(",
")",
";",
"console",
".",
"log",
"(",
"xexpr",
".",
"toString",
"(",
")",
")",
";",
"console",
".",
"log",
"(",
"''",
")",
";",
"var",
"resultValue",
"=",
"result",
".",
"getValue",
"(",
")",
";",
"if",
"(",
"resultValue",
"instanceof",
"wtf",
".",
"db",
".",
"EventIterator",
")",
"{",
"var",
"it",
"=",
"resultValue",
";",
"if",
"(",
"!",
"it",
".",
"getCount",
"(",
")",
")",
"{",
"console",
".",
"log",
"(",
"'Nothing matched'",
")",
";",
"}",
"else",
"{",
"console",
".",
"log",
"(",
"'Results: ('",
"+",
"it",
".",
"getCount",
"(",
")",
"+",
"' total)'",
")",
";",
"for",
"(",
";",
"!",
"it",
".",
"done",
"(",
")",
";",
"it",
".",
"next",
"(",
")",
")",
"{",
"util",
".",
"logEvent",
"(",
"it",
",",
"zone",
")",
";",
"}",
"}",
"}",
"else",
"if",
"(",
"typeof",
"resultValue",
"==",
"'boolean'",
"||",
"typeof",
"resultValue",
"==",
"'number'",
"||",
"typeof",
"resultValue",
"==",
"'string'",
")",
"{",
"console",
".",
"log",
"(",
"'Result:'",
")",
";",
"logResult",
"(",
"resultValue",
")",
";",
"}",
"else",
"if",
"(",
"!",
"resultValue",
")",
"{",
"// Note we test this after so that 0/strings/etc are handled.",
"console",
".",
"log",
"(",
"'Nothing matched'",
")",
";",
"}",
"else",
"if",
"(",
"resultValue",
".",
"length",
")",
"{",
"console",
".",
"log",
"(",
"'Results: ('",
"+",
"resultValue",
".",
"length",
"+",
"' total)'",
")",
";",
"for",
"(",
"var",
"n",
"=",
"0",
";",
"n",
"<",
"resultValue",
".",
"length",
";",
"n",
"++",
")",
"{",
"logResult",
"(",
"resultValue",
"[",
"n",
"]",
")",
";",
"}",
"}",
"else",
"{",
"console",
".",
"log",
"(",
"'Result:'",
")",
";",
"logResult",
"(",
"resultValue",
")",
";",
"}",
"console",
".",
"log",
"(",
"''",
")",
";",
"console",
".",
"log",
"(",
"'Took '",
"+",
"result",
".",
"getDuration",
"(",
")",
".",
"toFixed",
"(",
"3",
")",
"+",
"'ms'",
")",
";",
"}",
"}"
] |
Runs a REPL that queries a database.
@param {!wtf.db.Database} db Database.
@param {string} expr Query string.
|
[
"Runs",
"a",
"REPL",
"that",
"queries",
"a",
"database",
"."
] |
495ced98de99a5895e484b2e09771edb42d3c7ab
|
https://github.com/google/tracing-framework/blob/495ced98de99a5895e484b2e09771edb42d3c7ab/bin/query.js#L67-L147
|
17,734
|
google/tracing-framework
|
bin/save-trace.js
|
handlePost
|
function handlePost(req, res) {
var length = parseInt(req.headers['content-length'], 10);
if (length <= 0) {
res.end();
return;
}
var filename = req.headers['x-filename'] || 'save-trace.wtf-trace';
var writable = fs.createWriteStream(filename, {flags: 'w'});
req.on('data', function(chunk) {
writable.write(chunk);
});
req.on('end', function() {
console.log(filename);
writable.end();
res.end();
});
}
|
javascript
|
function handlePost(req, res) {
var length = parseInt(req.headers['content-length'], 10);
if (length <= 0) {
res.end();
return;
}
var filename = req.headers['x-filename'] || 'save-trace.wtf-trace';
var writable = fs.createWriteStream(filename, {flags: 'w'});
req.on('data', function(chunk) {
writable.write(chunk);
});
req.on('end', function() {
console.log(filename);
writable.end();
res.end();
});
}
|
[
"function",
"handlePost",
"(",
"req",
",",
"res",
")",
"{",
"var",
"length",
"=",
"parseInt",
"(",
"req",
".",
"headers",
"[",
"'content-length'",
"]",
",",
"10",
")",
";",
"if",
"(",
"length",
"<=",
"0",
")",
"{",
"res",
".",
"end",
"(",
")",
";",
"return",
";",
"}",
"var",
"filename",
"=",
"req",
".",
"headers",
"[",
"'x-filename'",
"]",
"||",
"'save-trace.wtf-trace'",
";",
"var",
"writable",
"=",
"fs",
".",
"createWriteStream",
"(",
"filename",
",",
"{",
"flags",
":",
"'w'",
"}",
")",
";",
"req",
".",
"on",
"(",
"'data'",
",",
"function",
"(",
"chunk",
")",
"{",
"writable",
".",
"write",
"(",
"chunk",
")",
";",
"}",
")",
";",
"req",
".",
"on",
"(",
"'end'",
",",
"function",
"(",
")",
"{",
"console",
".",
"log",
"(",
"filename",
")",
";",
"writable",
".",
"end",
"(",
")",
";",
"res",
".",
"end",
"(",
")",
";",
"}",
")",
";",
"}"
] |
Save the posted trace file to local directory.
|
[
"Save",
"the",
"posted",
"trace",
"file",
"to",
"local",
"directory",
"."
] |
495ced98de99a5895e484b2e09771edb42d3c7ab
|
https://github.com/google/tracing-framework/blob/495ced98de99a5895e484b2e09771edb42d3c7ab/bin/save-trace.js#L33-L52
|
17,735
|
google/tracing-framework
|
bin/save-trace.js
|
handleOptions
|
function handleOptions(req, res) {
var acrh = req.headers['access-control-request-headers'];
var origin = req.headers['origin'];
if (acrh) res.setHeader('Access-Control-Allow-Headers', acrh);
if (origin) res.setHeader('Access-Control-Allow-Origin', origin);
res.end();
}
|
javascript
|
function handleOptions(req, res) {
var acrh = req.headers['access-control-request-headers'];
var origin = req.headers['origin'];
if (acrh) res.setHeader('Access-Control-Allow-Headers', acrh);
if (origin) res.setHeader('Access-Control-Allow-Origin', origin);
res.end();
}
|
[
"function",
"handleOptions",
"(",
"req",
",",
"res",
")",
"{",
"var",
"acrh",
"=",
"req",
".",
"headers",
"[",
"'access-control-request-headers'",
"]",
";",
"var",
"origin",
"=",
"req",
".",
"headers",
"[",
"'origin'",
"]",
";",
"if",
"(",
"acrh",
")",
"res",
".",
"setHeader",
"(",
"'Access-Control-Allow-Headers'",
",",
"acrh",
")",
";",
"if",
"(",
"origin",
")",
"res",
".",
"setHeader",
"(",
"'Access-Control-Allow-Origin'",
",",
"origin",
")",
";",
"res",
".",
"end",
"(",
")",
";",
"}"
] |
Echo CORS headers.
|
[
"Echo",
"CORS",
"headers",
"."
] |
495ced98de99a5895e484b2e09771edb42d3c7ab
|
https://github.com/google/tracing-framework/blob/495ced98de99a5895e484b2e09771edb42d3c7ab/bin/save-trace.js#L55-L61
|
17,736
|
google/tracing-framework
|
extensions/wtf-injector-chrome/third_party/falafel.js
|
match
|
function match(value) {
var token = lookahead();
return token.type === Token.Punctuator && token.value === value;
}
|
javascript
|
function match(value) {
var token = lookahead();
return token.type === Token.Punctuator && token.value === value;
}
|
[
"function",
"match",
"(",
"value",
")",
"{",
"var",
"token",
"=",
"lookahead",
"(",
")",
";",
"return",
"token",
".",
"type",
"===",
"Token",
".",
"Punctuator",
"&&",
"token",
".",
"value",
"===",
"value",
";",
"}"
] |
Return true if the next token matches the specified punctuator.
|
[
"Return",
"true",
"if",
"the",
"next",
"token",
"matches",
"the",
"specified",
"punctuator",
"."
] |
495ced98de99a5895e484b2e09771edb42d3c7ab
|
https://github.com/google/tracing-framework/blob/495ced98de99a5895e484b2e09771edb42d3c7ab/extensions/wtf-injector-chrome/third_party/falafel.js#L1245-L1248
|
17,737
|
google/tracing-framework
|
extensions/wtf-injector-chrome/third_party/falafel.js
|
matchKeyword
|
function matchKeyword(keyword) {
var token = lookahead();
return token.type === Token.Keyword && token.value === keyword;
}
|
javascript
|
function matchKeyword(keyword) {
var token = lookahead();
return token.type === Token.Keyword && token.value === keyword;
}
|
[
"function",
"matchKeyword",
"(",
"keyword",
")",
"{",
"var",
"token",
"=",
"lookahead",
"(",
")",
";",
"return",
"token",
".",
"type",
"===",
"Token",
".",
"Keyword",
"&&",
"token",
".",
"value",
"===",
"keyword",
";",
"}"
] |
Return true if the next token matches the specified keyword
|
[
"Return",
"true",
"if",
"the",
"next",
"token",
"matches",
"the",
"specified",
"keyword"
] |
495ced98de99a5895e484b2e09771edb42d3c7ab
|
https://github.com/google/tracing-framework/blob/495ced98de99a5895e484b2e09771edb42d3c7ab/extensions/wtf-injector-chrome/third_party/falafel.js#L1252-L1255
|
17,738
|
google/tracing-framework
|
extensions/wtf-injector-chrome/third_party/falafel.js
|
parseMultiplicativeExpression
|
function parseMultiplicativeExpression() {
var expr = parseUnaryExpression();
while (match('*') || match('/') || match('%')) {
expr = {
type: Syntax.BinaryExpression,
operator: lex().value,
left: expr,
right: parseUnaryExpression()
};
}
return expr;
}
|
javascript
|
function parseMultiplicativeExpression() {
var expr = parseUnaryExpression();
while (match('*') || match('/') || match('%')) {
expr = {
type: Syntax.BinaryExpression,
operator: lex().value,
left: expr,
right: parseUnaryExpression()
};
}
return expr;
}
|
[
"function",
"parseMultiplicativeExpression",
"(",
")",
"{",
"var",
"expr",
"=",
"parseUnaryExpression",
"(",
")",
";",
"while",
"(",
"match",
"(",
"'*'",
")",
"||",
"match",
"(",
"'/'",
")",
"||",
"match",
"(",
"'%'",
")",
")",
"{",
"expr",
"=",
"{",
"type",
":",
"Syntax",
".",
"BinaryExpression",
",",
"operator",
":",
"lex",
"(",
")",
".",
"value",
",",
"left",
":",
"expr",
",",
"right",
":",
"parseUnaryExpression",
"(",
")",
"}",
";",
"}",
"return",
"expr",
";",
"}"
] |
11.5 Multiplicative Operators
|
[
"11",
".",
"5",
"Multiplicative",
"Operators"
] |
495ced98de99a5895e484b2e09771edb42d3c7ab
|
https://github.com/google/tracing-framework/blob/495ced98de99a5895e484b2e09771edb42d3c7ab/extensions/wtf-injector-chrome/third_party/falafel.js#L1789-L1802
|
17,739
|
google/tracing-framework
|
extensions/wtf-injector-chrome/third_party/falafel.js
|
parseEqualityExpression
|
function parseEqualityExpression() {
var expr = parseRelationalExpression();
while (match('==') || match('!=') || match('===') || match('!==')) {
expr = {
type: Syntax.BinaryExpression,
operator: lex().value,
left: expr,
right: parseRelationalExpression()
};
}
return expr;
}
|
javascript
|
function parseEqualityExpression() {
var expr = parseRelationalExpression();
while (match('==') || match('!=') || match('===') || match('!==')) {
expr = {
type: Syntax.BinaryExpression,
operator: lex().value,
left: expr,
right: parseRelationalExpression()
};
}
return expr;
}
|
[
"function",
"parseEqualityExpression",
"(",
")",
"{",
"var",
"expr",
"=",
"parseRelationalExpression",
"(",
")",
";",
"while",
"(",
"match",
"(",
"'=='",
")",
"||",
"match",
"(",
"'!='",
")",
"||",
"match",
"(",
"'==='",
")",
"||",
"match",
"(",
"'!=='",
")",
")",
"{",
"expr",
"=",
"{",
"type",
":",
"Syntax",
".",
"BinaryExpression",
",",
"operator",
":",
"lex",
"(",
")",
".",
"value",
",",
"left",
":",
"expr",
",",
"right",
":",
"parseRelationalExpression",
"(",
")",
"}",
";",
"}",
"return",
"expr",
";",
"}"
] |
11.9 Equality Operators
|
[
"11",
".",
"9",
"Equality",
"Operators"
] |
495ced98de99a5895e484b2e09771edb42d3c7ab
|
https://github.com/google/tracing-framework/blob/495ced98de99a5895e484b2e09771edb42d3c7ab/extensions/wtf-injector-chrome/third_party/falafel.js#L1862-L1875
|
17,740
|
google/tracing-framework
|
extensions/wtf-injector-chrome/third_party/falafel.js
|
parseLogicalANDExpression
|
function parseLogicalANDExpression() {
var expr = parseBitwiseORExpression();
while (match('&&')) {
lex();
expr = {
type: Syntax.LogicalExpression,
operator: '&&',
left: expr,
right: parseBitwiseORExpression()
};
}
return expr;
}
|
javascript
|
function parseLogicalANDExpression() {
var expr = parseBitwiseORExpression();
while (match('&&')) {
lex();
expr = {
type: Syntax.LogicalExpression,
operator: '&&',
left: expr,
right: parseBitwiseORExpression()
};
}
return expr;
}
|
[
"function",
"parseLogicalANDExpression",
"(",
")",
"{",
"var",
"expr",
"=",
"parseBitwiseORExpression",
"(",
")",
";",
"while",
"(",
"match",
"(",
"'&&'",
")",
")",
"{",
"lex",
"(",
")",
";",
"expr",
"=",
"{",
"type",
":",
"Syntax",
".",
"LogicalExpression",
",",
"operator",
":",
"'&&'",
",",
"left",
":",
"expr",
",",
"right",
":",
"parseBitwiseORExpression",
"(",
")",
"}",
";",
"}",
"return",
"expr",
";",
"}"
] |
11.11 Binary Logical Operators
|
[
"11",
".",
"11",
"Binary",
"Logical",
"Operators"
] |
495ced98de99a5895e484b2e09771edb42d3c7ab
|
https://github.com/google/tracing-framework/blob/495ced98de99a5895e484b2e09771edb42d3c7ab/extensions/wtf-injector-chrome/third_party/falafel.js#L1929-L1943
|
17,741
|
google/tracing-framework
|
src/wtf/bootstrap/node.js
|
fileExistsSync
|
function fileExistsSync(path) {
if (fs.existsSync) {
return fs.existsSync(path);
} else {
try {
fs.statSync(path);
return true;
} catch (e) {
return false;
}
}
}
|
javascript
|
function fileExistsSync(path) {
if (fs.existsSync) {
return fs.existsSync(path);
} else {
try {
fs.statSync(path);
return true;
} catch (e) {
return false;
}
}
}
|
[
"function",
"fileExistsSync",
"(",
"path",
")",
"{",
"if",
"(",
"fs",
".",
"existsSync",
")",
"{",
"return",
"fs",
".",
"existsSync",
"(",
"path",
")",
";",
"}",
"else",
"{",
"try",
"{",
"fs",
".",
"statSync",
"(",
"path",
")",
";",
"return",
"true",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"return",
"false",
";",
"}",
"}",
"}"
] |
Checks to see if a file exists.
Compatibility shim for old node.js' that lack fs.existsSync.
@param {string} path File path.
@return {boolean} True if the file exists.
|
[
"Checks",
"to",
"see",
"if",
"a",
"file",
"exists",
".",
"Compatibility",
"shim",
"for",
"old",
"node",
".",
"js",
"that",
"lack",
"fs",
".",
"existsSync",
"."
] |
495ced98de99a5895e484b2e09771edb42d3c7ab
|
https://github.com/google/tracing-framework/blob/495ced98de99a5895e484b2e09771edb42d3c7ab/src/wtf/bootstrap/node.js#L96-L107
|
17,742
|
google/tracing-framework
|
extensions/wtf-injector-chrome/debugger.js
|
function(tabId, pageOptions) {
/**
* Target tab ID.
* @type {number}
* @private
*/
this.tabId_ = tabId;
/**
* Target debugee.
* @type {!Object}
* @private
*/
this.debugee_ = {
tabId: this.tabId_
};
/**
* Page options.
* @type {!Object}
* @private
*/
this.pageOptions_ = pageOptions;
/**
* A list of timeline records that have been recorded.
* @type {!Array.<!Array>}
* @private
*/
this.records_ = [];
/**
* Whether this debugger is attached.
* @type {boolean}
* @private
*/
this.attached_ = false;
/**
* Interval ID used for polling memory statistics.
* @type {number|null}
* @private
*/
this.memoryPollIntervalId_ = null;
/**
* The time of the first GC event inside of an event tree.
* Frequently the timeline will send 2-3 GC events with the same time.
* De-dupe those by tracking the first GC and ignoring the others.
* @type {number}
* @private
*/
this.lastGcStartTime_ = 0;
// Register us for dispatch.
Debugger.dispatchTable_.register(this.tabId_, this);
// Attach to the target tab.
try {
chrome.debugger.attach(this.debugee_, '1.0', (function() {
this.attached_ = true;
this.beginListening_();
}).bind(this));
} catch (e) {
// This is likely an exception saying the debugger is already attached,
// as Chrome has started throwing this in some versions. There's seriously
// like 10 different ways they report errors like this and it's different
// in every version. Sigh.
}
}
|
javascript
|
function(tabId, pageOptions) {
/**
* Target tab ID.
* @type {number}
* @private
*/
this.tabId_ = tabId;
/**
* Target debugee.
* @type {!Object}
* @private
*/
this.debugee_ = {
tabId: this.tabId_
};
/**
* Page options.
* @type {!Object}
* @private
*/
this.pageOptions_ = pageOptions;
/**
* A list of timeline records that have been recorded.
* @type {!Array.<!Array>}
* @private
*/
this.records_ = [];
/**
* Whether this debugger is attached.
* @type {boolean}
* @private
*/
this.attached_ = false;
/**
* Interval ID used for polling memory statistics.
* @type {number|null}
* @private
*/
this.memoryPollIntervalId_ = null;
/**
* The time of the first GC event inside of an event tree.
* Frequently the timeline will send 2-3 GC events with the same time.
* De-dupe those by tracking the first GC and ignoring the others.
* @type {number}
* @private
*/
this.lastGcStartTime_ = 0;
// Register us for dispatch.
Debugger.dispatchTable_.register(this.tabId_, this);
// Attach to the target tab.
try {
chrome.debugger.attach(this.debugee_, '1.0', (function() {
this.attached_ = true;
this.beginListening_();
}).bind(this));
} catch (e) {
// This is likely an exception saying the debugger is already attached,
// as Chrome has started throwing this in some versions. There's seriously
// like 10 different ways they report errors like this and it's different
// in every version. Sigh.
}
}
|
[
"function",
"(",
"tabId",
",",
"pageOptions",
")",
"{",
"/**\n * Target tab ID.\n * @type {number}\n * @private\n */",
"this",
".",
"tabId_",
"=",
"tabId",
";",
"/**\n * Target debugee.\n * @type {!Object}\n * @private\n */",
"this",
".",
"debugee_",
"=",
"{",
"tabId",
":",
"this",
".",
"tabId_",
"}",
";",
"/**\n * Page options.\n * @type {!Object}\n * @private\n */",
"this",
".",
"pageOptions_",
"=",
"pageOptions",
";",
"/**\n * A list of timeline records that have been recorded.\n * @type {!Array.<!Array>}\n * @private\n */",
"this",
".",
"records_",
"=",
"[",
"]",
";",
"/**\n * Whether this debugger is attached.\n * @type {boolean}\n * @private\n */",
"this",
".",
"attached_",
"=",
"false",
";",
"/**\n * Interval ID used for polling memory statistics.\n * @type {number|null}\n * @private\n */",
"this",
".",
"memoryPollIntervalId_",
"=",
"null",
";",
"/**\n * The time of the first GC event inside of an event tree.\n * Frequently the timeline will send 2-3 GC events with the same time.\n * De-dupe those by tracking the first GC and ignoring the others.\n * @type {number}\n * @private\n */",
"this",
".",
"lastGcStartTime_",
"=",
"0",
";",
"// Register us for dispatch.",
"Debugger",
".",
"dispatchTable_",
".",
"register",
"(",
"this",
".",
"tabId_",
",",
"this",
")",
";",
"// Attach to the target tab.",
"try",
"{",
"chrome",
".",
"debugger",
".",
"attach",
"(",
"this",
".",
"debugee_",
",",
"'1.0'",
",",
"(",
"function",
"(",
")",
"{",
"this",
".",
"attached_",
"=",
"true",
";",
"this",
".",
"beginListening_",
"(",
")",
";",
"}",
")",
".",
"bind",
"(",
"this",
")",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"// This is likely an exception saying the debugger is already attached,",
"// as Chrome has started throwing this in some versions. There's seriously",
"// like 10 different ways they report errors like this and it's different",
"// in every version. Sigh.",
"}",
"}"
] |
Debugger data proxy.
This connects to a tab and sets up a debug session that is used for reading
out events from the page.
@param {number} tabId Tab ID.
@param {!Object} pageOptions Page options.
@constructor
|
[
"Debugger",
"data",
"proxy",
".",
"This",
"connects",
"to",
"a",
"tab",
"and",
"sets",
"up",
"a",
"debug",
"session",
"that",
"is",
"used",
"for",
"reading",
"out",
"events",
"from",
"the",
"page",
"."
] |
495ced98de99a5895e484b2e09771edb42d3c7ab
|
https://github.com/google/tracing-framework/blob/495ced98de99a5895e484b2e09771edb42d3c7ab/extensions/wtf-injector-chrome/debugger.js#L133-L202
|
|
17,743
|
google/tracing-framework
|
bin/generate-webgl-app.js
|
copyFile
|
function copyFile(src, dest) {
var content = fs.readFileSync(src, 'binary');
fs.writeFileSync(dest, content, 'binary');
}
|
javascript
|
function copyFile(src, dest) {
var content = fs.readFileSync(src, 'binary');
fs.writeFileSync(dest, content, 'binary');
}
|
[
"function",
"copyFile",
"(",
"src",
",",
"dest",
")",
"{",
"var",
"content",
"=",
"fs",
".",
"readFileSync",
"(",
"src",
",",
"'binary'",
")",
";",
"fs",
".",
"writeFileSync",
"(",
"dest",
",",
"content",
",",
"'binary'",
")",
";",
"}"
] |
Copy DLLs to output path.
|
[
"Copy",
"DLLs",
"to",
"output",
"path",
"."
] |
495ced98de99a5895e484b2e09771edb42d3c7ab
|
https://github.com/google/tracing-framework/blob/495ced98de99a5895e484b2e09771edb42d3c7ab/bin/generate-webgl-app.js#L378-L381
|
17,744
|
google/tracing-framework
|
src/wtf/wtf.js
|
computeInner
|
function computeInner(iterations) {
var dummy = 0;
for (var n = 0; n < iterations; n++) {
// We don't have to worry about this being entirely removed (yet), as
// JITs don't seem to consider now() as not having side-effects.
dummy += wtf.now();
}
return dummy;
}
|
javascript
|
function computeInner(iterations) {
var dummy = 0;
for (var n = 0; n < iterations; n++) {
// We don't have to worry about this being entirely removed (yet), as
// JITs don't seem to consider now() as not having side-effects.
dummy += wtf.now();
}
return dummy;
}
|
[
"function",
"computeInner",
"(",
"iterations",
")",
"{",
"var",
"dummy",
"=",
"0",
";",
"for",
"(",
"var",
"n",
"=",
"0",
";",
"n",
"<",
"iterations",
";",
"n",
"++",
")",
"{",
"// We don't have to worry about this being entirely removed (yet), as",
"// JITs don't seem to consider now() as not having side-effects.",
"dummy",
"+=",
"wtf",
".",
"now",
"(",
")",
";",
"}",
"return",
"dummy",
";",
"}"
] |
This is in a function so that v8 can JIT it easier. We then run it a few times to try to factor out the JIT time.
|
[
"This",
"is",
"in",
"a",
"function",
"so",
"that",
"v8",
"can",
"JIT",
"it",
"easier",
".",
"We",
"then",
"run",
"it",
"a",
"few",
"times",
"to",
"try",
"to",
"factor",
"out",
"the",
"JIT",
"time",
"."
] |
495ced98de99a5895e484b2e09771edb42d3c7ab
|
https://github.com/google/tracing-framework/blob/495ced98de99a5895e484b2e09771edb42d3c7ab/src/wtf/wtf.js#L220-L228
|
17,745
|
google/tracing-framework
|
bin/instrument.js
|
processFile
|
function processFile(argv, inputPath, opt_outputPath) {
// Setup output path.
var outputPath = opt_outputPath;
if (!opt_outputPath) {
var ext = path.extname(inputPath);
if (ext.length) {
outputPath = inputPath.substr(0, inputPath.length - ext.length) +
'.instrumented' + ext;
} else {
outputPath = inputPath + '.instrumented.js';
}
}
var sourceCode = fs.readFileSync(inputPath).toString();
// TODO(benvanik): support setting the module ID?
var targetCode = transformCode(0, inputPath, sourceCode, argv);
console.log('Writing ' + outputPath + '...');
fs.writeFileSync(outputPath, targetCode);
fs.chmodSync(outputPath, fs.statSync(inputPath).mode);
}
|
javascript
|
function processFile(argv, inputPath, opt_outputPath) {
// Setup output path.
var outputPath = opt_outputPath;
if (!opt_outputPath) {
var ext = path.extname(inputPath);
if (ext.length) {
outputPath = inputPath.substr(0, inputPath.length - ext.length) +
'.instrumented' + ext;
} else {
outputPath = inputPath + '.instrumented.js';
}
}
var sourceCode = fs.readFileSync(inputPath).toString();
// TODO(benvanik): support setting the module ID?
var targetCode = transformCode(0, inputPath, sourceCode, argv);
console.log('Writing ' + outputPath + '...');
fs.writeFileSync(outputPath, targetCode);
fs.chmodSync(outputPath, fs.statSync(inputPath).mode);
}
|
[
"function",
"processFile",
"(",
"argv",
",",
"inputPath",
",",
"opt_outputPath",
")",
"{",
"// Setup output path.",
"var",
"outputPath",
"=",
"opt_outputPath",
";",
"if",
"(",
"!",
"opt_outputPath",
")",
"{",
"var",
"ext",
"=",
"path",
".",
"extname",
"(",
"inputPath",
")",
";",
"if",
"(",
"ext",
".",
"length",
")",
"{",
"outputPath",
"=",
"inputPath",
".",
"substr",
"(",
"0",
",",
"inputPath",
".",
"length",
"-",
"ext",
".",
"length",
")",
"+",
"'.instrumented'",
"+",
"ext",
";",
"}",
"else",
"{",
"outputPath",
"=",
"inputPath",
"+",
"'.instrumented.js'",
";",
"}",
"}",
"var",
"sourceCode",
"=",
"fs",
".",
"readFileSync",
"(",
"inputPath",
")",
".",
"toString",
"(",
")",
";",
"// TODO(benvanik): support setting the module ID?",
"var",
"targetCode",
"=",
"transformCode",
"(",
"0",
",",
"inputPath",
",",
"sourceCode",
",",
"argv",
")",
";",
"console",
".",
"log",
"(",
"'Writing '",
"+",
"outputPath",
"+",
"'...'",
")",
";",
"fs",
".",
"writeFileSync",
"(",
"outputPath",
",",
"targetCode",
")",
";",
"fs",
".",
"chmodSync",
"(",
"outputPath",
",",
"fs",
".",
"statSync",
"(",
"inputPath",
")",
".",
"mode",
")",
";",
"}"
] |
Processes a single input file.
@param {!Object} argv Parsed arguments.
@param {string} inputPath Input file path.
@param {string=} opt_outputPath Output file path.
|
[
"Processes",
"a",
"single",
"input",
"file",
"."
] |
495ced98de99a5895e484b2e09771edb42d3c7ab
|
https://github.com/google/tracing-framework/blob/495ced98de99a5895e484b2e09771edb42d3c7ab/bin/instrument.js#L333-L354
|
17,746
|
google/tracing-framework
|
bin/instrument.js
|
handler
|
function handler(req, res) {
// Support both the ?url= mode and the X-WTF-URL header.
var targetUrl;
if (req.headers['x-wtf-url']) {
targetUrl = req.headers['x-wtf-url'];
} else {
var parsedUrl = url.parse(req.url, true);
var query = parsedUrl.query;
targetUrl = query.url;
}
if (!targetUrl || targetUrl.indexOf('http') != 0) {
res.writeHead(404, ['Content-Type', 'text/plain']);
res.end();
return;
}
res.on('error', function(e) {
console.log('ERROR (source): ' + e);
});
var targetModule = targetUrl.indexOf('https') == 0 ? https : http;
targetModule.get(targetUrl, function(originalRes) {
// Eat errors, otherwise the app will die.
originalRes.on('error', function(e) {
console.log('ERROR (target): ' + e);
});
// Pull out content type to see if we are interested in it.
var supportedContentType = false;
var contentType = originalRes.headers['content-type'];
if (contentType && contentType.indexOf(';') != 0) {
contentType = contentType.substr(0, contentType.indexOf(';'));
}
switch (contentType) {
case 'text/javascript':
case 'application/javascript':
supportedContentType = true;
break;
}
// Also parse the URL - some servers don't return content type for some
// reason.
var supportedPath = false;
var contentUrl = url.parse(targetUrl);
if (path.extname(contentUrl.pathname) == '.js') {
supportedPath = true;
}
if (supportedContentType || supportedPath) {
var headers = [];
for (var key in originalRes.headers) {
if (key == 'content-length') {
continue;
}
headers.push([key, originalRes.headers[key]]);
}
res.writeHead(originalRes.statusCode, headers);
injectStream(targetUrl, originalRes, res);
} else {
console.log('Pass-through: ' + targetUrl, contentType);
res.writeHead(originalRes.statusCode, originalRes.headers);
originalRes.pipe(res);
}
}).on('error', function(e) {
console.log(e);
res.writeHead(404, ['Content-Type', 'text/plain']);
res.end(e.message);
});
}
|
javascript
|
function handler(req, res) {
// Support both the ?url= mode and the X-WTF-URL header.
var targetUrl;
if (req.headers['x-wtf-url']) {
targetUrl = req.headers['x-wtf-url'];
} else {
var parsedUrl = url.parse(req.url, true);
var query = parsedUrl.query;
targetUrl = query.url;
}
if (!targetUrl || targetUrl.indexOf('http') != 0) {
res.writeHead(404, ['Content-Type', 'text/plain']);
res.end();
return;
}
res.on('error', function(e) {
console.log('ERROR (source): ' + e);
});
var targetModule = targetUrl.indexOf('https') == 0 ? https : http;
targetModule.get(targetUrl, function(originalRes) {
// Eat errors, otherwise the app will die.
originalRes.on('error', function(e) {
console.log('ERROR (target): ' + e);
});
// Pull out content type to see if we are interested in it.
var supportedContentType = false;
var contentType = originalRes.headers['content-type'];
if (contentType && contentType.indexOf(';') != 0) {
contentType = contentType.substr(0, contentType.indexOf(';'));
}
switch (contentType) {
case 'text/javascript':
case 'application/javascript':
supportedContentType = true;
break;
}
// Also parse the URL - some servers don't return content type for some
// reason.
var supportedPath = false;
var contentUrl = url.parse(targetUrl);
if (path.extname(contentUrl.pathname) == '.js') {
supportedPath = true;
}
if (supportedContentType || supportedPath) {
var headers = [];
for (var key in originalRes.headers) {
if (key == 'content-length') {
continue;
}
headers.push([key, originalRes.headers[key]]);
}
res.writeHead(originalRes.statusCode, headers);
injectStream(targetUrl, originalRes, res);
} else {
console.log('Pass-through: ' + targetUrl, contentType);
res.writeHead(originalRes.statusCode, originalRes.headers);
originalRes.pipe(res);
}
}).on('error', function(e) {
console.log(e);
res.writeHead(404, ['Content-Type', 'text/plain']);
res.end(e.message);
});
}
|
[
"function",
"handler",
"(",
"req",
",",
"res",
")",
"{",
"// Support both the ?url= mode and the X-WTF-URL header.",
"var",
"targetUrl",
";",
"if",
"(",
"req",
".",
"headers",
"[",
"'x-wtf-url'",
"]",
")",
"{",
"targetUrl",
"=",
"req",
".",
"headers",
"[",
"'x-wtf-url'",
"]",
";",
"}",
"else",
"{",
"var",
"parsedUrl",
"=",
"url",
".",
"parse",
"(",
"req",
".",
"url",
",",
"true",
")",
";",
"var",
"query",
"=",
"parsedUrl",
".",
"query",
";",
"targetUrl",
"=",
"query",
".",
"url",
";",
"}",
"if",
"(",
"!",
"targetUrl",
"||",
"targetUrl",
".",
"indexOf",
"(",
"'http'",
")",
"!=",
"0",
")",
"{",
"res",
".",
"writeHead",
"(",
"404",
",",
"[",
"'Content-Type'",
",",
"'text/plain'",
"]",
")",
";",
"res",
".",
"end",
"(",
")",
";",
"return",
";",
"}",
"res",
".",
"on",
"(",
"'error'",
",",
"function",
"(",
"e",
")",
"{",
"console",
".",
"log",
"(",
"'ERROR (source): '",
"+",
"e",
")",
";",
"}",
")",
";",
"var",
"targetModule",
"=",
"targetUrl",
".",
"indexOf",
"(",
"'https'",
")",
"==",
"0",
"?",
"https",
":",
"http",
";",
"targetModule",
".",
"get",
"(",
"targetUrl",
",",
"function",
"(",
"originalRes",
")",
"{",
"// Eat errors, otherwise the app will die.",
"originalRes",
".",
"on",
"(",
"'error'",
",",
"function",
"(",
"e",
")",
"{",
"console",
".",
"log",
"(",
"'ERROR (target): '",
"+",
"e",
")",
";",
"}",
")",
";",
"// Pull out content type to see if we are interested in it.",
"var",
"supportedContentType",
"=",
"false",
";",
"var",
"contentType",
"=",
"originalRes",
".",
"headers",
"[",
"'content-type'",
"]",
";",
"if",
"(",
"contentType",
"&&",
"contentType",
".",
"indexOf",
"(",
"';'",
")",
"!=",
"0",
")",
"{",
"contentType",
"=",
"contentType",
".",
"substr",
"(",
"0",
",",
"contentType",
".",
"indexOf",
"(",
"';'",
")",
")",
";",
"}",
"switch",
"(",
"contentType",
")",
"{",
"case",
"'text/javascript'",
":",
"case",
"'application/javascript'",
":",
"supportedContentType",
"=",
"true",
";",
"break",
";",
"}",
"// Also parse the URL - some servers don't return content type for some",
"// reason.",
"var",
"supportedPath",
"=",
"false",
";",
"var",
"contentUrl",
"=",
"url",
".",
"parse",
"(",
"targetUrl",
")",
";",
"if",
"(",
"path",
".",
"extname",
"(",
"contentUrl",
".",
"pathname",
")",
"==",
"'.js'",
")",
"{",
"supportedPath",
"=",
"true",
";",
"}",
"if",
"(",
"supportedContentType",
"||",
"supportedPath",
")",
"{",
"var",
"headers",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"key",
"in",
"originalRes",
".",
"headers",
")",
"{",
"if",
"(",
"key",
"==",
"'content-length'",
")",
"{",
"continue",
";",
"}",
"headers",
".",
"push",
"(",
"[",
"key",
",",
"originalRes",
".",
"headers",
"[",
"key",
"]",
"]",
")",
";",
"}",
"res",
".",
"writeHead",
"(",
"originalRes",
".",
"statusCode",
",",
"headers",
")",
";",
"injectStream",
"(",
"targetUrl",
",",
"originalRes",
",",
"res",
")",
";",
"}",
"else",
"{",
"console",
".",
"log",
"(",
"'Pass-through: '",
"+",
"targetUrl",
",",
"contentType",
")",
";",
"res",
".",
"writeHead",
"(",
"originalRes",
".",
"statusCode",
",",
"originalRes",
".",
"headers",
")",
";",
"originalRes",
".",
"pipe",
"(",
"res",
")",
";",
"}",
"}",
")",
".",
"on",
"(",
"'error'",
",",
"function",
"(",
"e",
")",
"{",
"console",
".",
"log",
"(",
"e",
")",
";",
"res",
".",
"writeHead",
"(",
"404",
",",
"[",
"'Content-Type'",
",",
"'text/plain'",
"]",
")",
";",
"res",
".",
"end",
"(",
"e",
".",
"message",
")",
";",
"}",
")",
";",
"}"
] |
Handles both HTTP and HTTPS requests.
|
[
"Handles",
"both",
"HTTP",
"and",
"HTTPS",
"requests",
"."
] |
495ced98de99a5895e484b2e09771edb42d3c7ab
|
https://github.com/google/tracing-framework/blob/495ced98de99a5895e484b2e09771edb42d3c7ab/bin/instrument.js#L395-L463
|
17,747
|
google/tracing-framework
|
extensions/wtf-injector-chrome/wtf-injector.js
|
fetchOptions
|
function fetchOptions() {
/**
* Name of the cookie that contains the options for the injection.
* The data is just a blob GUID that is used to construct a URL to the blob
* exposed by the extension.
* @const
* @type {string}
*/
var WTF_OPTIONS_COOKIE = 'wtf';
/**
* Cookie used for instrumentation options.
* @const
* @type {string}
*/
var WTF_INSTRUMENTATION_COOKIE = 'wtfi';
// Check for the injection cookie.
var optionsUuid = null;
var instrumentationOptions = null;
var cookies = document.cookie.split('; ');
for (var n = 0; n < cookies.length; n++) {
if (cookies[n].lastIndexOf(WTF_OPTIONS_COOKIE + '=') == 0) {
optionsUuid = cookies[n].substr(cookies[n].indexOf('=') + 1);
}
if (cookies[n].lastIndexOf(WTF_INSTRUMENTATION_COOKIE + '=') == 0) {
instrumentationOptions = cookies[n].substr(cookies[n].indexOf('=') + 1);
}
}
if (!optionsUuid && !instrumentationOptions) {
return null;
}
// If we have an instrumentation cookie we use that and go into
// instrumentation mode.
if (instrumentationOptions) {
instrumentationOptions = JSON.parse(instrumentationOptions);
instrumentationOptions['__instrumented__'] = true;
return instrumentationOptions;
}
// Fetch the options from the extension.
// This is complicated by a regression in Chrome that prevents the blob trick
// from working in certain versions. We try that first (as it's the best) and
// if it fails we fallback to a nasty HTTP header trick.
// https://code.google.com/p/chromium/issues/detail?id=295829
// blob:chrome-extension%3A//[extension id]/[options uuid]
var blobUrl = 'blob:' +
chrome.extension.getURL(optionsUuid).replace(':', '%3A');
var headerUrl =
'http://tracing-framework.appspot.com/tab-options/' + optionsUuid;
try {
var xhr = new XMLHttpRequest();
xhr.open('GET', blobUrl, false);
xhr.send(null);
if (xhr.status != 200) {
log('Failed to load WTF injection options:',
blobUrl,
xhr.status, xhr.statusText);
return null;
}
return JSON.parse(xhr.responseText);
} catch(e) {
log('Failed to parse WTF injection options (falling back to headers)... ' +
'See https://code.google.com/p/chromium/issues/detail?id=295829');
// Try the headers.
try {
var xhr = new XMLHttpRequest();
xhr.open('GET', headerUrl, false);
xhr.send(null);
var optionsData = xhr.getResponseHeader('X-WTF-Options');
if (!optionsData) {
log('Failed to load WTF injection options from header:' + headerUrl);
log('Using defaults for settings :(');
return {
'wtf.injector': true,
'wtf.injector.failed': true,
'wtf.trace.session.bufferSize': 6 * 1024 * 1024,
'wtf.trace.session.maximumMemoryUsage': 512 * 1024 * 1024,
'wtf.trace.provider.chromeDebug.present': true,
'wtf.trace.provider.chromeDebug.tracing': false
};
}
return JSON.parse(optionsData);
} catch(e) {
log('Really failed to fetch WTF injection options, aborting', e);
// Try again!
window.setTimeout(function() {
window.location.reload();
}, 100);
return null;
}
}
return null;
}
|
javascript
|
function fetchOptions() {
/**
* Name of the cookie that contains the options for the injection.
* The data is just a blob GUID that is used to construct a URL to the blob
* exposed by the extension.
* @const
* @type {string}
*/
var WTF_OPTIONS_COOKIE = 'wtf';
/**
* Cookie used for instrumentation options.
* @const
* @type {string}
*/
var WTF_INSTRUMENTATION_COOKIE = 'wtfi';
// Check for the injection cookie.
var optionsUuid = null;
var instrumentationOptions = null;
var cookies = document.cookie.split('; ');
for (var n = 0; n < cookies.length; n++) {
if (cookies[n].lastIndexOf(WTF_OPTIONS_COOKIE + '=') == 0) {
optionsUuid = cookies[n].substr(cookies[n].indexOf('=') + 1);
}
if (cookies[n].lastIndexOf(WTF_INSTRUMENTATION_COOKIE + '=') == 0) {
instrumentationOptions = cookies[n].substr(cookies[n].indexOf('=') + 1);
}
}
if (!optionsUuid && !instrumentationOptions) {
return null;
}
// If we have an instrumentation cookie we use that and go into
// instrumentation mode.
if (instrumentationOptions) {
instrumentationOptions = JSON.parse(instrumentationOptions);
instrumentationOptions['__instrumented__'] = true;
return instrumentationOptions;
}
// Fetch the options from the extension.
// This is complicated by a regression in Chrome that prevents the blob trick
// from working in certain versions. We try that first (as it's the best) and
// if it fails we fallback to a nasty HTTP header trick.
// https://code.google.com/p/chromium/issues/detail?id=295829
// blob:chrome-extension%3A//[extension id]/[options uuid]
var blobUrl = 'blob:' +
chrome.extension.getURL(optionsUuid).replace(':', '%3A');
var headerUrl =
'http://tracing-framework.appspot.com/tab-options/' + optionsUuid;
try {
var xhr = new XMLHttpRequest();
xhr.open('GET', blobUrl, false);
xhr.send(null);
if (xhr.status != 200) {
log('Failed to load WTF injection options:',
blobUrl,
xhr.status, xhr.statusText);
return null;
}
return JSON.parse(xhr.responseText);
} catch(e) {
log('Failed to parse WTF injection options (falling back to headers)... ' +
'See https://code.google.com/p/chromium/issues/detail?id=295829');
// Try the headers.
try {
var xhr = new XMLHttpRequest();
xhr.open('GET', headerUrl, false);
xhr.send(null);
var optionsData = xhr.getResponseHeader('X-WTF-Options');
if (!optionsData) {
log('Failed to load WTF injection options from header:' + headerUrl);
log('Using defaults for settings :(');
return {
'wtf.injector': true,
'wtf.injector.failed': true,
'wtf.trace.session.bufferSize': 6 * 1024 * 1024,
'wtf.trace.session.maximumMemoryUsage': 512 * 1024 * 1024,
'wtf.trace.provider.chromeDebug.present': true,
'wtf.trace.provider.chromeDebug.tracing': false
};
}
return JSON.parse(optionsData);
} catch(e) {
log('Really failed to fetch WTF injection options, aborting', e);
// Try again!
window.setTimeout(function() {
window.location.reload();
}, 100);
return null;
}
}
return null;
}
|
[
"function",
"fetchOptions",
"(",
")",
"{",
"/**\n * Name of the cookie that contains the options for the injection.\n * The data is just a blob GUID that is used to construct a URL to the blob\n * exposed by the extension.\n * @const\n * @type {string}\n */",
"var",
"WTF_OPTIONS_COOKIE",
"=",
"'wtf'",
";",
"/**\n * Cookie used for instrumentation options.\n * @const\n * @type {string}\n */",
"var",
"WTF_INSTRUMENTATION_COOKIE",
"=",
"'wtfi'",
";",
"// Check for the injection cookie.",
"var",
"optionsUuid",
"=",
"null",
";",
"var",
"instrumentationOptions",
"=",
"null",
";",
"var",
"cookies",
"=",
"document",
".",
"cookie",
".",
"split",
"(",
"'; '",
")",
";",
"for",
"(",
"var",
"n",
"=",
"0",
";",
"n",
"<",
"cookies",
".",
"length",
";",
"n",
"++",
")",
"{",
"if",
"(",
"cookies",
"[",
"n",
"]",
".",
"lastIndexOf",
"(",
"WTF_OPTIONS_COOKIE",
"+",
"'='",
")",
"==",
"0",
")",
"{",
"optionsUuid",
"=",
"cookies",
"[",
"n",
"]",
".",
"substr",
"(",
"cookies",
"[",
"n",
"]",
".",
"indexOf",
"(",
"'='",
")",
"+",
"1",
")",
";",
"}",
"if",
"(",
"cookies",
"[",
"n",
"]",
".",
"lastIndexOf",
"(",
"WTF_INSTRUMENTATION_COOKIE",
"+",
"'='",
")",
"==",
"0",
")",
"{",
"instrumentationOptions",
"=",
"cookies",
"[",
"n",
"]",
".",
"substr",
"(",
"cookies",
"[",
"n",
"]",
".",
"indexOf",
"(",
"'='",
")",
"+",
"1",
")",
";",
"}",
"}",
"if",
"(",
"!",
"optionsUuid",
"&&",
"!",
"instrumentationOptions",
")",
"{",
"return",
"null",
";",
"}",
"// If we have an instrumentation cookie we use that and go into",
"// instrumentation mode.",
"if",
"(",
"instrumentationOptions",
")",
"{",
"instrumentationOptions",
"=",
"JSON",
".",
"parse",
"(",
"instrumentationOptions",
")",
";",
"instrumentationOptions",
"[",
"'__instrumented__'",
"]",
"=",
"true",
";",
"return",
"instrumentationOptions",
";",
"}",
"// Fetch the options from the extension.",
"// This is complicated by a regression in Chrome that prevents the blob trick",
"// from working in certain versions. We try that first (as it's the best) and",
"// if it fails we fallback to a nasty HTTP header trick.",
"// https://code.google.com/p/chromium/issues/detail?id=295829",
"// blob:chrome-extension%3A//[extension id]/[options uuid]",
"var",
"blobUrl",
"=",
"'blob:'",
"+",
"chrome",
".",
"extension",
".",
"getURL",
"(",
"optionsUuid",
")",
".",
"replace",
"(",
"':'",
",",
"'%3A'",
")",
";",
"var",
"headerUrl",
"=",
"'http://tracing-framework.appspot.com/tab-options/'",
"+",
"optionsUuid",
";",
"try",
"{",
"var",
"xhr",
"=",
"new",
"XMLHttpRequest",
"(",
")",
";",
"xhr",
".",
"open",
"(",
"'GET'",
",",
"blobUrl",
",",
"false",
")",
";",
"xhr",
".",
"send",
"(",
"null",
")",
";",
"if",
"(",
"xhr",
".",
"status",
"!=",
"200",
")",
"{",
"log",
"(",
"'Failed to load WTF injection options:'",
",",
"blobUrl",
",",
"xhr",
".",
"status",
",",
"xhr",
".",
"statusText",
")",
";",
"return",
"null",
";",
"}",
"return",
"JSON",
".",
"parse",
"(",
"xhr",
".",
"responseText",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"log",
"(",
"'Failed to parse WTF injection options (falling back to headers)... '",
"+",
"'See https://code.google.com/p/chromium/issues/detail?id=295829'",
")",
";",
"// Try the headers.",
"try",
"{",
"var",
"xhr",
"=",
"new",
"XMLHttpRequest",
"(",
")",
";",
"xhr",
".",
"open",
"(",
"'GET'",
",",
"headerUrl",
",",
"false",
")",
";",
"xhr",
".",
"send",
"(",
"null",
")",
";",
"var",
"optionsData",
"=",
"xhr",
".",
"getResponseHeader",
"(",
"'X-WTF-Options'",
")",
";",
"if",
"(",
"!",
"optionsData",
")",
"{",
"log",
"(",
"'Failed to load WTF injection options from header:'",
"+",
"headerUrl",
")",
";",
"log",
"(",
"'Using defaults for settings :('",
")",
";",
"return",
"{",
"'wtf.injector'",
":",
"true",
",",
"'wtf.injector.failed'",
":",
"true",
",",
"'wtf.trace.session.bufferSize'",
":",
"6",
"*",
"1024",
"*",
"1024",
",",
"'wtf.trace.session.maximumMemoryUsage'",
":",
"512",
"*",
"1024",
"*",
"1024",
",",
"'wtf.trace.provider.chromeDebug.present'",
":",
"true",
",",
"'wtf.trace.provider.chromeDebug.tracing'",
":",
"false",
"}",
";",
"}",
"return",
"JSON",
".",
"parse",
"(",
"optionsData",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"log",
"(",
"'Really failed to fetch WTF injection options, aborting'",
",",
"e",
")",
";",
"// Try again!",
"window",
".",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"window",
".",
"location",
".",
"reload",
"(",
")",
";",
"}",
",",
"100",
")",
";",
"return",
"null",
";",
"}",
"}",
"return",
"null",
";",
"}"
] |
Fetches the options from the extension background page.
This will only return a value if the options were injected in a cookie, and
if no options are returned it means the injection is not active.
@return {!Object} Options object.
|
[
"Fetches",
"the",
"options",
"from",
"the",
"extension",
"background",
"page",
".",
"This",
"will",
"only",
"return",
"a",
"value",
"if",
"the",
"options",
"were",
"injected",
"in",
"a",
"cookie",
"and",
"if",
"no",
"options",
"are",
"returned",
"it",
"means",
"the",
"injection",
"is",
"not",
"active",
"."
] |
495ced98de99a5895e484b2e09771edb42d3c7ab
|
https://github.com/google/tracing-framework/blob/495ced98de99a5895e484b2e09771edb42d3c7ab/extensions/wtf-injector-chrome/wtf-injector.js#L141-L241
|
17,748
|
google/tracing-framework
|
extensions/wtf-injector-chrome/wtf-injector.js
|
injectAddons
|
function injectAddons(manifestUrls) {
var addons = {};
for (var n = 0; n < manifestUrls.length; n++) {
// Fetch Manifest JSON.
var url = manifestUrls[n];
var json = getUrl(url);
if (!json) {
log('Unable to fetch manifest JSON: ' + url);
continue;
}
json = JSON.parse(json);
addons[url] = json;
// If it has a tracing node, inject scripts.
var tracingInfo = json['tracing'];
if (tracingInfo && tracingInfo['scripts']) {
var tracingScripts = tracingInfo['scripts'];
for (var m = 0; m < tracingScripts.length; m++) {
var scriptUrl = resolveUrl(url, tracingScripts[m]);
if (!injectScriptFile(scriptUrl)) {
log('Error loading addon ' + url + ':');
log('Tracing script file not found: ' + scriptUrl);
}
}
}
}
return addons;
}
|
javascript
|
function injectAddons(manifestUrls) {
var addons = {};
for (var n = 0; n < manifestUrls.length; n++) {
// Fetch Manifest JSON.
var url = manifestUrls[n];
var json = getUrl(url);
if (!json) {
log('Unable to fetch manifest JSON: ' + url);
continue;
}
json = JSON.parse(json);
addons[url] = json;
// If it has a tracing node, inject scripts.
var tracingInfo = json['tracing'];
if (tracingInfo && tracingInfo['scripts']) {
var tracingScripts = tracingInfo['scripts'];
for (var m = 0; m < tracingScripts.length; m++) {
var scriptUrl = resolveUrl(url, tracingScripts[m]);
if (!injectScriptFile(scriptUrl)) {
log('Error loading addon ' + url + ':');
log('Tracing script file not found: ' + scriptUrl);
}
}
}
}
return addons;
}
|
[
"function",
"injectAddons",
"(",
"manifestUrls",
")",
"{",
"var",
"addons",
"=",
"{",
"}",
";",
"for",
"(",
"var",
"n",
"=",
"0",
";",
"n",
"<",
"manifestUrls",
".",
"length",
";",
"n",
"++",
")",
"{",
"// Fetch Manifest JSON.",
"var",
"url",
"=",
"manifestUrls",
"[",
"n",
"]",
";",
"var",
"json",
"=",
"getUrl",
"(",
"url",
")",
";",
"if",
"(",
"!",
"json",
")",
"{",
"log",
"(",
"'Unable to fetch manifest JSON: '",
"+",
"url",
")",
";",
"continue",
";",
"}",
"json",
"=",
"JSON",
".",
"parse",
"(",
"json",
")",
";",
"addons",
"[",
"url",
"]",
"=",
"json",
";",
"// If it has a tracing node, inject scripts.",
"var",
"tracingInfo",
"=",
"json",
"[",
"'tracing'",
"]",
";",
"if",
"(",
"tracingInfo",
"&&",
"tracingInfo",
"[",
"'scripts'",
"]",
")",
"{",
"var",
"tracingScripts",
"=",
"tracingInfo",
"[",
"'scripts'",
"]",
";",
"for",
"(",
"var",
"m",
"=",
"0",
";",
"m",
"<",
"tracingScripts",
".",
"length",
";",
"m",
"++",
")",
"{",
"var",
"scriptUrl",
"=",
"resolveUrl",
"(",
"url",
",",
"tracingScripts",
"[",
"m",
"]",
")",
";",
"if",
"(",
"!",
"injectScriptFile",
"(",
"scriptUrl",
")",
")",
"{",
"log",
"(",
"'Error loading addon '",
"+",
"url",
"+",
"':'",
")",
";",
"log",
"(",
"'Tracing script file not found: '",
"+",
"scriptUrl",
")",
";",
"}",
"}",
"}",
"}",
"return",
"addons",
";",
"}"
] |
Injects the given addons into the page.
@param {!Array.<string>} manifestUrls Addon manifest JSON URLs.
@return {!Object.<!Object>} Addon manifests, mapped by manifest URL.
|
[
"Injects",
"the",
"given",
"addons",
"into",
"the",
"page",
"."
] |
495ced98de99a5895e484b2e09771edb42d3c7ab
|
https://github.com/google/tracing-framework/blob/495ced98de99a5895e484b2e09771edb42d3c7ab/extensions/wtf-injector-chrome/wtf-injector.js#L249-L276
|
17,749
|
google/tracing-framework
|
extensions/wtf-injector-chrome/wtf-injector.js
|
convertUint8ArraysToArrays
|
function convertUint8ArraysToArrays(sources) {
var targets = [];
for (var n = 0; n < sources.length; n++) {
var source = sources[n];
var target = new Array(source.length);
for (var i = 0; i < source.length; i++) {
target[i] = source[i];
}
targets.push(target);
}
return targets;
}
|
javascript
|
function convertUint8ArraysToArrays(sources) {
var targets = [];
for (var n = 0; n < sources.length; n++) {
var source = sources[n];
var target = new Array(source.length);
for (var i = 0; i < source.length; i++) {
target[i] = source[i];
}
targets.push(target);
}
return targets;
}
|
[
"function",
"convertUint8ArraysToArrays",
"(",
"sources",
")",
"{",
"var",
"targets",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"n",
"=",
"0",
";",
"n",
"<",
"sources",
".",
"length",
";",
"n",
"++",
")",
"{",
"var",
"source",
"=",
"sources",
"[",
"n",
"]",
";",
"var",
"target",
"=",
"new",
"Array",
"(",
"source",
".",
"length",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"source",
".",
"length",
";",
"i",
"++",
")",
"{",
"target",
"[",
"i",
"]",
"=",
"source",
"[",
"i",
"]",
";",
"}",
"targets",
".",
"push",
"(",
"target",
")",
";",
"}",
"return",
"targets",
";",
"}"
] |
Converts a list of Uint8Arrays to regular arrays.
@param {!Array.<!Uint8Array>} sources Source arrays.
@return {!Array.<!Array.<number>>} Target arrays.
|
[
"Converts",
"a",
"list",
"of",
"Uint8Arrays",
"to",
"regular",
"arrays",
"."
] |
495ced98de99a5895e484b2e09771edb42d3c7ab
|
https://github.com/google/tracing-framework/blob/495ced98de99a5895e484b2e09771edb42d3c7ab/extensions/wtf-injector-chrome/wtf-injector.js#L314-L325
|
17,750
|
google/tracing-framework
|
extensions/wtf-injector-chrome/wtf-injector.js
|
resolveUrl
|
function resolveUrl(base, url) {
var value = '';
if (url.indexOf('://') != -1) {
// Likely absolute...
value = url;
} else {
// Combine by smashing together and letting the browser figure it out.
if (url.length && url[0] == '/') {
// URL is absolute, so strip base to just host.
var i = url.indexOf('://') + 3;
i = url.indexOf('/', i);
if (i != -1) {
value = base + url;
} else {
value = base.substr(0, i) + url;
}
} else {
// URL is relative, so combine with base.
if (base[base.length] == '/') {
value = base + '/' + url;
} else {
value = base + '/../' + url;
}
}
}
return value;
}
|
javascript
|
function resolveUrl(base, url) {
var value = '';
if (url.indexOf('://') != -1) {
// Likely absolute...
value = url;
} else {
// Combine by smashing together and letting the browser figure it out.
if (url.length && url[0] == '/') {
// URL is absolute, so strip base to just host.
var i = url.indexOf('://') + 3;
i = url.indexOf('/', i);
if (i != -1) {
value = base + url;
} else {
value = base.substr(0, i) + url;
}
} else {
// URL is relative, so combine with base.
if (base[base.length] == '/') {
value = base + '/' + url;
} else {
value = base + '/../' + url;
}
}
}
return value;
}
|
[
"function",
"resolveUrl",
"(",
"base",
",",
"url",
")",
"{",
"var",
"value",
"=",
"''",
";",
"if",
"(",
"url",
".",
"indexOf",
"(",
"'://'",
")",
"!=",
"-",
"1",
")",
"{",
"// Likely absolute...",
"value",
"=",
"url",
";",
"}",
"else",
"{",
"// Combine by smashing together and letting the browser figure it out.",
"if",
"(",
"url",
".",
"length",
"&&",
"url",
"[",
"0",
"]",
"==",
"'/'",
")",
"{",
"// URL is absolute, so strip base to just host.",
"var",
"i",
"=",
"url",
".",
"indexOf",
"(",
"'://'",
")",
"+",
"3",
";",
"i",
"=",
"url",
".",
"indexOf",
"(",
"'/'",
",",
"i",
")",
";",
"if",
"(",
"i",
"!=",
"-",
"1",
")",
"{",
"value",
"=",
"base",
"+",
"url",
";",
"}",
"else",
"{",
"value",
"=",
"base",
".",
"substr",
"(",
"0",
",",
"i",
")",
"+",
"url",
";",
"}",
"}",
"else",
"{",
"// URL is relative, so combine with base.",
"if",
"(",
"base",
"[",
"base",
".",
"length",
"]",
"==",
"'/'",
")",
"{",
"value",
"=",
"base",
"+",
"'/'",
"+",
"url",
";",
"}",
"else",
"{",
"value",
"=",
"base",
"+",
"'/../'",
"+",
"url",
";",
"}",
"}",
"}",
"return",
"value",
";",
"}"
] |
Hackily resolves a URL relative to a base.
@param {string} base Base URL.
@param {string} url Relative or absolute URL.
@return {string} Resolved URL.
|
[
"Hackily",
"resolves",
"a",
"URL",
"relative",
"to",
"a",
"base",
"."
] |
495ced98de99a5895e484b2e09771edb42d3c7ab
|
https://github.com/google/tracing-framework/blob/495ced98de99a5895e484b2e09771edb42d3c7ab/extensions/wtf-injector-chrome/wtf-injector.js#L404-L430
|
17,751
|
google/tracing-framework
|
src/wtf/trace/providers/webglprovider.js
|
wrapMethod
|
function wrapMethod(target, targetType, signature, opt_generator) {
// Parse signature.
var parsedSignature = wtf.data.Variable.parseSignature(signature);
var methodName = parsedSignature.name;
// Define a custom event type at runtime.
var customEvent = wtf.trace.events.createScope(
targetType + '#' + signature);
goog.asserts.assert(customEvent);
// Grab the original method from the target.
var rawFn = target[methodName];
if (!rawFn) {
goog.global.console.log(targetType + ' is missing ' + methodName);
return;
}
// Generate a bound function.
var instrumentedFn;
if (opt_generator) {
// Custom enter function generator.
instrumentedFn = opt_generator(rawFn, customEvent);
} else {
// Default case of simple event.
instrumentedFn = function() {
// Always call setCurrentContext first to ensure proper event order.
setCurrentContext(this);
// Enter scope with the arguments of the call.
var scope = customEvent.apply(null, arguments);
// Call the original method.
var result = rawFn.apply(this, arguments);
// Return the result and leave the scope.
return leaveScope(scope, result);
};
}
// Swap the method and save a restore function so that we can swap it back.
instrumentedFn['raw'] = rawFn;
target[methodName] = instrumentedFn;
contextRestoreFns.push(function() {
target[methodName] = rawFn;
});
}
|
javascript
|
function wrapMethod(target, targetType, signature, opt_generator) {
// Parse signature.
var parsedSignature = wtf.data.Variable.parseSignature(signature);
var methodName = parsedSignature.name;
// Define a custom event type at runtime.
var customEvent = wtf.trace.events.createScope(
targetType + '#' + signature);
goog.asserts.assert(customEvent);
// Grab the original method from the target.
var rawFn = target[methodName];
if (!rawFn) {
goog.global.console.log(targetType + ' is missing ' + methodName);
return;
}
// Generate a bound function.
var instrumentedFn;
if (opt_generator) {
// Custom enter function generator.
instrumentedFn = opt_generator(rawFn, customEvent);
} else {
// Default case of simple event.
instrumentedFn = function() {
// Always call setCurrentContext first to ensure proper event order.
setCurrentContext(this);
// Enter scope with the arguments of the call.
var scope = customEvent.apply(null, arguments);
// Call the original method.
var result = rawFn.apply(this, arguments);
// Return the result and leave the scope.
return leaveScope(scope, result);
};
}
// Swap the method and save a restore function so that we can swap it back.
instrumentedFn['raw'] = rawFn;
target[methodName] = instrumentedFn;
contextRestoreFns.push(function() {
target[methodName] = rawFn;
});
}
|
[
"function",
"wrapMethod",
"(",
"target",
",",
"targetType",
",",
"signature",
",",
"opt_generator",
")",
"{",
"// Parse signature.",
"var",
"parsedSignature",
"=",
"wtf",
".",
"data",
".",
"Variable",
".",
"parseSignature",
"(",
"signature",
")",
";",
"var",
"methodName",
"=",
"parsedSignature",
".",
"name",
";",
"// Define a custom event type at runtime.",
"var",
"customEvent",
"=",
"wtf",
".",
"trace",
".",
"events",
".",
"createScope",
"(",
"targetType",
"+",
"'#'",
"+",
"signature",
")",
";",
"goog",
".",
"asserts",
".",
"assert",
"(",
"customEvent",
")",
";",
"// Grab the original method from the target.",
"var",
"rawFn",
"=",
"target",
"[",
"methodName",
"]",
";",
"if",
"(",
"!",
"rawFn",
")",
"{",
"goog",
".",
"global",
".",
"console",
".",
"log",
"(",
"targetType",
"+",
"' is missing '",
"+",
"methodName",
")",
";",
"return",
";",
"}",
"// Generate a bound function.",
"var",
"instrumentedFn",
";",
"if",
"(",
"opt_generator",
")",
"{",
"// Custom enter function generator.",
"instrumentedFn",
"=",
"opt_generator",
"(",
"rawFn",
",",
"customEvent",
")",
";",
"}",
"else",
"{",
"// Default case of simple event.",
"instrumentedFn",
"=",
"function",
"(",
")",
"{",
"// Always call setCurrentContext first to ensure proper event order.",
"setCurrentContext",
"(",
"this",
")",
";",
"// Enter scope with the arguments of the call.",
"var",
"scope",
"=",
"customEvent",
".",
"apply",
"(",
"null",
",",
"arguments",
")",
";",
"// Call the original method.",
"var",
"result",
"=",
"rawFn",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
";",
"// Return the result and leave the scope.",
"return",
"leaveScope",
"(",
"scope",
",",
"result",
")",
";",
"}",
";",
"}",
"// Swap the method and save a restore function so that we can swap it back.",
"instrumentedFn",
"[",
"'raw'",
"]",
"=",
"rawFn",
";",
"target",
"[",
"methodName",
"]",
"=",
"instrumentedFn",
";",
"contextRestoreFns",
".",
"push",
"(",
"function",
"(",
")",
"{",
"target",
"[",
"methodName",
"]",
"=",
"rawFn",
";",
"}",
")",
";",
"}"
] |
Wraps a method on the target prototype with a scoped event.
Optionally the method can provide a custom callback routine.
@param {!Object} target Target object/prototype.
@param {string} targetType Target type name.
@param {string} signature Event signature.
@param {Function=} opt_generator Generator function.
|
[
"Wraps",
"a",
"method",
"on",
"the",
"target",
"prototype",
"with",
"a",
"scoped",
"event",
".",
"Optionally",
"the",
"method",
"can",
"provide",
"a",
"custom",
"callback",
"routine",
"."
] |
495ced98de99a5895e484b2e09771edb42d3c7ab
|
https://github.com/google/tracing-framework/blob/495ced98de99a5895e484b2e09771edb42d3c7ab/src/wtf/trace/providers/webglprovider.js#L368-L413
|
17,752
|
google/tracing-framework
|
src/wtf/trace/providers/webglprovider.js
|
wrapInstancedArraysExtension
|
function wrapInstancedArraysExtension(ctx, proto) {
/**
* @param {string} signature Event signature.
* @param {Function=} opt_generator Generator function.
*/
function wrapInstancedArraysMethod(signature, opt_generator) {
wrapMethod(
proto, 'ANGLEInstancedArrays',
signature, opt_generator);
};
wrapInstancedArraysMethod(
'drawArraysInstancedANGLE(uint32 mode, uint32 first, int32 count, ' +
'int32 primcount)',
function(fn, eventType) {
return function drawArraysInstancedANGLE() {
setCurrentContext(ctx);
var scope = eventType.apply(this, arguments);
return leaveScope(scope, fn.apply(this, arguments));
};
});
wrapInstancedArraysMethod(
'drawElementsInstancedANGLE(uint32 mode, int32 count, uint32 type, ' +
'uint32 offset, int32 primcount)',
function(fn, eventType) {
return function drawElementsInstancedANGLE() {
setCurrentContext(ctx);
var scope = eventType.apply(this, arguments);
return leaveScope(scope, fn.apply(this, arguments));
};
});
wrapInstancedArraysMethod(
'vertexAttribDivisorANGLE(uint32 index, uint32 divisor)',
function(fn, eventType) {
return function vertexAttribDivisorANGLE() {
setCurrentContext(ctx);
var scope = eventType.apply(this, arguments);
return leaveScope(scope, fn.apply(this, arguments));
};
});
}
|
javascript
|
function wrapInstancedArraysExtension(ctx, proto) {
/**
* @param {string} signature Event signature.
* @param {Function=} opt_generator Generator function.
*/
function wrapInstancedArraysMethod(signature, opt_generator) {
wrapMethod(
proto, 'ANGLEInstancedArrays',
signature, opt_generator);
};
wrapInstancedArraysMethod(
'drawArraysInstancedANGLE(uint32 mode, uint32 first, int32 count, ' +
'int32 primcount)',
function(fn, eventType) {
return function drawArraysInstancedANGLE() {
setCurrentContext(ctx);
var scope = eventType.apply(this, arguments);
return leaveScope(scope, fn.apply(this, arguments));
};
});
wrapInstancedArraysMethod(
'drawElementsInstancedANGLE(uint32 mode, int32 count, uint32 type, ' +
'uint32 offset, int32 primcount)',
function(fn, eventType) {
return function drawElementsInstancedANGLE() {
setCurrentContext(ctx);
var scope = eventType.apply(this, arguments);
return leaveScope(scope, fn.apply(this, arguments));
};
});
wrapInstancedArraysMethod(
'vertexAttribDivisorANGLE(uint32 index, uint32 divisor)',
function(fn, eventType) {
return function vertexAttribDivisorANGLE() {
setCurrentContext(ctx);
var scope = eventType.apply(this, arguments);
return leaveScope(scope, fn.apply(this, arguments));
};
});
}
|
[
"function",
"wrapInstancedArraysExtension",
"(",
"ctx",
",",
"proto",
")",
"{",
"/**\n * @param {string} signature Event signature.\n * @param {Function=} opt_generator Generator function.\n */",
"function",
"wrapInstancedArraysMethod",
"(",
"signature",
",",
"opt_generator",
")",
"{",
"wrapMethod",
"(",
"proto",
",",
"'ANGLEInstancedArrays'",
",",
"signature",
",",
"opt_generator",
")",
";",
"}",
";",
"wrapInstancedArraysMethod",
"(",
"'drawArraysInstancedANGLE(uint32 mode, uint32 first, int32 count, '",
"+",
"'int32 primcount)'",
",",
"function",
"(",
"fn",
",",
"eventType",
")",
"{",
"return",
"function",
"drawArraysInstancedANGLE",
"(",
")",
"{",
"setCurrentContext",
"(",
"ctx",
")",
";",
"var",
"scope",
"=",
"eventType",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
";",
"return",
"leaveScope",
"(",
"scope",
",",
"fn",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
")",
";",
"}",
";",
"}",
")",
";",
"wrapInstancedArraysMethod",
"(",
"'drawElementsInstancedANGLE(uint32 mode, int32 count, uint32 type, '",
"+",
"'uint32 offset, int32 primcount)'",
",",
"function",
"(",
"fn",
",",
"eventType",
")",
"{",
"return",
"function",
"drawElementsInstancedANGLE",
"(",
")",
"{",
"setCurrentContext",
"(",
"ctx",
")",
";",
"var",
"scope",
"=",
"eventType",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
";",
"return",
"leaveScope",
"(",
"scope",
",",
"fn",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
")",
";",
"}",
";",
"}",
")",
";",
"wrapInstancedArraysMethod",
"(",
"'vertexAttribDivisorANGLE(uint32 index, uint32 divisor)'",
",",
"function",
"(",
"fn",
",",
"eventType",
")",
"{",
"return",
"function",
"vertexAttribDivisorANGLE",
"(",
")",
"{",
"setCurrentContext",
"(",
"ctx",
")",
";",
"var",
"scope",
"=",
"eventType",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
";",
"return",
"leaveScope",
"(",
"scope",
",",
"fn",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
")",
";",
"}",
";",
"}",
")",
";",
"}"
] |
Wraps the ANGLEInstancedArrays extension object.
@param {!WebGLRenderingContext} ctx Target context.
@param {!Object} proto Prototype object.
|
[
"Wraps",
"the",
"ANGLEInstancedArrays",
"extension",
"object",
"."
] |
495ced98de99a5895e484b2e09771edb42d3c7ab
|
https://github.com/google/tracing-framework/blob/495ced98de99a5895e484b2e09771edb42d3c7ab/src/wtf/trace/providers/webglprovider.js#L443-L483
|
17,753
|
google/tracing-framework
|
src/wtf/trace/providers/webglprovider.js
|
wrapVertexArrayObjectExtension
|
function wrapVertexArrayObjectExtension(ctx, proto) {
/**
* @param {string} signature Event signature.
* @param {Function=} opt_generator Generator function.
*/
function wrapVertexArrayObjectMethod(signature, opt_generator) {
wrapMethod(
proto, 'OESVertexArrayObject',
signature, opt_generator);
};
// http://www.khronos.org/registry/webgl/extensions/OES_vertex_array_object/
wrapVertexArrayObjectMethod(
'createVertexArrayOES(uint32 arrayObject)',
function(fn, eventType) {
return function createVertexArrayOES() {
setCurrentContext(ctx);
var id = provider.nextObjectId_++;
leaveScope(eventType(id));
var obj = fn.apply(this, arguments);
if (obj) {
setHandle(obj, id);
}
return obj;
};
});
wrapVertexArrayObjectMethod(
'deleteVertexArrayOES(uint32 arrayObject)',
function(fn, eventType) {
return function deleteVertexArrayOES(arrayObject) {
setCurrentContext(ctx);
var scope = eventType(getHandle(arrayObject));
return leaveScope(scope, fn.apply(this, arguments));
};
});
wrapVertexArrayObjectMethod(
'isVertexArrayOES(uint32 arrayObject)',
function(fn, eventType) {
return function isVertexArrayOES(arrayObject) {
setCurrentContext(ctx);
var scope = eventType(getHandle(arrayObject));
return leaveScope(scope, fn.apply(this, arguments));
};
});
wrapVertexArrayObjectMethod(
'bindVertexArrayOES(uint32 arrayObject)',
function(fn, eventType) {
return function bindVertexArrayOES(arrayObject) {
setCurrentContext(ctx);
var scope = eventType(getHandle(arrayObject));
return leaveScope(scope, fn.apply(this, arguments));
};
});
}
|
javascript
|
function wrapVertexArrayObjectExtension(ctx, proto) {
/**
* @param {string} signature Event signature.
* @param {Function=} opt_generator Generator function.
*/
function wrapVertexArrayObjectMethod(signature, opt_generator) {
wrapMethod(
proto, 'OESVertexArrayObject',
signature, opt_generator);
};
// http://www.khronos.org/registry/webgl/extensions/OES_vertex_array_object/
wrapVertexArrayObjectMethod(
'createVertexArrayOES(uint32 arrayObject)',
function(fn, eventType) {
return function createVertexArrayOES() {
setCurrentContext(ctx);
var id = provider.nextObjectId_++;
leaveScope(eventType(id));
var obj = fn.apply(this, arguments);
if (obj) {
setHandle(obj, id);
}
return obj;
};
});
wrapVertexArrayObjectMethod(
'deleteVertexArrayOES(uint32 arrayObject)',
function(fn, eventType) {
return function deleteVertexArrayOES(arrayObject) {
setCurrentContext(ctx);
var scope = eventType(getHandle(arrayObject));
return leaveScope(scope, fn.apply(this, arguments));
};
});
wrapVertexArrayObjectMethod(
'isVertexArrayOES(uint32 arrayObject)',
function(fn, eventType) {
return function isVertexArrayOES(arrayObject) {
setCurrentContext(ctx);
var scope = eventType(getHandle(arrayObject));
return leaveScope(scope, fn.apply(this, arguments));
};
});
wrapVertexArrayObjectMethod(
'bindVertexArrayOES(uint32 arrayObject)',
function(fn, eventType) {
return function bindVertexArrayOES(arrayObject) {
setCurrentContext(ctx);
var scope = eventType(getHandle(arrayObject));
return leaveScope(scope, fn.apply(this, arguments));
};
});
}
|
[
"function",
"wrapVertexArrayObjectExtension",
"(",
"ctx",
",",
"proto",
")",
"{",
"/**\n * @param {string} signature Event signature.\n * @param {Function=} opt_generator Generator function.\n */",
"function",
"wrapVertexArrayObjectMethod",
"(",
"signature",
",",
"opt_generator",
")",
"{",
"wrapMethod",
"(",
"proto",
",",
"'OESVertexArrayObject'",
",",
"signature",
",",
"opt_generator",
")",
";",
"}",
";",
"// http://www.khronos.org/registry/webgl/extensions/OES_vertex_array_object/",
"wrapVertexArrayObjectMethod",
"(",
"'createVertexArrayOES(uint32 arrayObject)'",
",",
"function",
"(",
"fn",
",",
"eventType",
")",
"{",
"return",
"function",
"createVertexArrayOES",
"(",
")",
"{",
"setCurrentContext",
"(",
"ctx",
")",
";",
"var",
"id",
"=",
"provider",
".",
"nextObjectId_",
"++",
";",
"leaveScope",
"(",
"eventType",
"(",
"id",
")",
")",
";",
"var",
"obj",
"=",
"fn",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
";",
"if",
"(",
"obj",
")",
"{",
"setHandle",
"(",
"obj",
",",
"id",
")",
";",
"}",
"return",
"obj",
";",
"}",
";",
"}",
")",
";",
"wrapVertexArrayObjectMethod",
"(",
"'deleteVertexArrayOES(uint32 arrayObject)'",
",",
"function",
"(",
"fn",
",",
"eventType",
")",
"{",
"return",
"function",
"deleteVertexArrayOES",
"(",
"arrayObject",
")",
"{",
"setCurrentContext",
"(",
"ctx",
")",
";",
"var",
"scope",
"=",
"eventType",
"(",
"getHandle",
"(",
"arrayObject",
")",
")",
";",
"return",
"leaveScope",
"(",
"scope",
",",
"fn",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
")",
";",
"}",
";",
"}",
")",
";",
"wrapVertexArrayObjectMethod",
"(",
"'isVertexArrayOES(uint32 arrayObject)'",
",",
"function",
"(",
"fn",
",",
"eventType",
")",
"{",
"return",
"function",
"isVertexArrayOES",
"(",
"arrayObject",
")",
"{",
"setCurrentContext",
"(",
"ctx",
")",
";",
"var",
"scope",
"=",
"eventType",
"(",
"getHandle",
"(",
"arrayObject",
")",
")",
";",
"return",
"leaveScope",
"(",
"scope",
",",
"fn",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
")",
";",
"}",
";",
"}",
")",
";",
"wrapVertexArrayObjectMethod",
"(",
"'bindVertexArrayOES(uint32 arrayObject)'",
",",
"function",
"(",
"fn",
",",
"eventType",
")",
"{",
"return",
"function",
"bindVertexArrayOES",
"(",
"arrayObject",
")",
"{",
"setCurrentContext",
"(",
"ctx",
")",
";",
"var",
"scope",
"=",
"eventType",
"(",
"getHandle",
"(",
"arrayObject",
")",
")",
";",
"return",
"leaveScope",
"(",
"scope",
",",
"fn",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
")",
";",
"}",
";",
"}",
")",
";",
"}"
] |
Wraps the OESVertexArrayObject extension object.
@param {!WebGLRenderingContext} ctx Target context.
@param {!Object} proto Prototype object.
|
[
"Wraps",
"the",
"OESVertexArrayObject",
"extension",
"object",
"."
] |
495ced98de99a5895e484b2e09771edb42d3c7ab
|
https://github.com/google/tracing-framework/blob/495ced98de99a5895e484b2e09771edb42d3c7ab/src/wtf/trace/providers/webglprovider.js#L490-L544
|
17,754
|
google/tracing-framework
|
src/wtf/trace/providers/webglprovider.js
|
wrapLoseContextExtension
|
function wrapLoseContextExtension(ctx, proto) {
/**
* @param {string} signature Event signature.
* @param {Function=} opt_generator Generator function.
*/
function wrapLoseContextMethod(signature, opt_generator) {
wrapMethod(
proto, 'WebGLLoseContext',
signature, opt_generator);
};
// http://www.khronos.org/registry/webgl/extensions/WEBGL_lose_context/
wrapLoseContextMethod(
'loseContext()',
function(fn, eventType) {
return function loseContext() {
setCurrentContext(ctx);
var scope = eventType.apply(this, arguments);
return leaveScope(scope, fn.apply(this, arguments));
};
});
wrapLoseContextMethod(
'restoreContext()',
function(fn, eventType) {
return function restoreContext() {
setCurrentContext(ctx);
var scope = eventType.apply(this, arguments);
return leaveScope(scope, fn.apply(this, arguments));
};
});
}
|
javascript
|
function wrapLoseContextExtension(ctx, proto) {
/**
* @param {string} signature Event signature.
* @param {Function=} opt_generator Generator function.
*/
function wrapLoseContextMethod(signature, opt_generator) {
wrapMethod(
proto, 'WebGLLoseContext',
signature, opt_generator);
};
// http://www.khronos.org/registry/webgl/extensions/WEBGL_lose_context/
wrapLoseContextMethod(
'loseContext()',
function(fn, eventType) {
return function loseContext() {
setCurrentContext(ctx);
var scope = eventType.apply(this, arguments);
return leaveScope(scope, fn.apply(this, arguments));
};
});
wrapLoseContextMethod(
'restoreContext()',
function(fn, eventType) {
return function restoreContext() {
setCurrentContext(ctx);
var scope = eventType.apply(this, arguments);
return leaveScope(scope, fn.apply(this, arguments));
};
});
}
|
[
"function",
"wrapLoseContextExtension",
"(",
"ctx",
",",
"proto",
")",
"{",
"/**\n * @param {string} signature Event signature.\n * @param {Function=} opt_generator Generator function.\n */",
"function",
"wrapLoseContextMethod",
"(",
"signature",
",",
"opt_generator",
")",
"{",
"wrapMethod",
"(",
"proto",
",",
"'WebGLLoseContext'",
",",
"signature",
",",
"opt_generator",
")",
";",
"}",
";",
"// http://www.khronos.org/registry/webgl/extensions/WEBGL_lose_context/",
"wrapLoseContextMethod",
"(",
"'loseContext()'",
",",
"function",
"(",
"fn",
",",
"eventType",
")",
"{",
"return",
"function",
"loseContext",
"(",
")",
"{",
"setCurrentContext",
"(",
"ctx",
")",
";",
"var",
"scope",
"=",
"eventType",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
";",
"return",
"leaveScope",
"(",
"scope",
",",
"fn",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
")",
";",
"}",
";",
"}",
")",
";",
"wrapLoseContextMethod",
"(",
"'restoreContext()'",
",",
"function",
"(",
"fn",
",",
"eventType",
")",
"{",
"return",
"function",
"restoreContext",
"(",
")",
"{",
"setCurrentContext",
"(",
"ctx",
")",
";",
"var",
"scope",
"=",
"eventType",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
";",
"return",
"leaveScope",
"(",
"scope",
",",
"fn",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
")",
";",
"}",
";",
"}",
")",
";",
"}"
] |
Wraps the WebGLLoseContext extension object.
@param {!WebGLRenderingContext} ctx Target context.
@param {!Object} proto Prototype object.
|
[
"Wraps",
"the",
"WebGLLoseContext",
"extension",
"object",
"."
] |
495ced98de99a5895e484b2e09771edb42d3c7ab
|
https://github.com/google/tracing-framework/blob/495ced98de99a5895e484b2e09771edb42d3c7ab/src/wtf/trace/providers/webglprovider.js#L551-L582
|
17,755
|
google/tracing-framework
|
src/wtf/trace/providers/webglprovider.js
|
instrumentExtensionObject
|
function instrumentExtensionObject(ctx, name, object) {
var proto = object.constructor.prototype;
// We do this check only for known extensions, as Firefox will return a
// generic 'Object' for others and that will break everything.
function checkInstrumented() {
if (proto['__gl_wrapped__']) {
return false;
}
Object.defineProperty(proto, '__gl_wrapped__', {
'configurable': true,
'enumerable': false,
'value': true
});
contextRestoreFns.push(function() {
delete proto['__gl_wrapped__'];
});
return true;
};
switch (name) {
case 'ANGLE_instanced_arrays':
if (checkInstrumented()) {
wrapInstancedArraysExtension(ctx, proto);
}
return true;
case 'OES_vertex_array_object':
if (checkInstrumented()) {
wrapVertexArrayObjectExtension(ctx, proto);
}
return true;
case 'WEBGL_lose_context':
if (checkInstrumented()) {
wrapLoseContextExtension(ctx, proto);
}
return true;
case 'WEBGL_draw_buffers':
// http://www.khronos.org/registry/webgl/extensions/WEBGL_draw_buffers/
case 'WEBGL_security_sensitive_resources':
// http://www.khronos.org/registry/webgl/extensions/WEBGL_security_sensitive_resources/
case 'WEBGL_shared_resources':
// http://www.khronos.org/registry/webgl/extensions/WEBGL_shared_resources/
// Don't support these yet, so report them as not present.
return false;
default:
return true;
}
}
|
javascript
|
function instrumentExtensionObject(ctx, name, object) {
var proto = object.constructor.prototype;
// We do this check only for known extensions, as Firefox will return a
// generic 'Object' for others and that will break everything.
function checkInstrumented() {
if (proto['__gl_wrapped__']) {
return false;
}
Object.defineProperty(proto, '__gl_wrapped__', {
'configurable': true,
'enumerable': false,
'value': true
});
contextRestoreFns.push(function() {
delete proto['__gl_wrapped__'];
});
return true;
};
switch (name) {
case 'ANGLE_instanced_arrays':
if (checkInstrumented()) {
wrapInstancedArraysExtension(ctx, proto);
}
return true;
case 'OES_vertex_array_object':
if (checkInstrumented()) {
wrapVertexArrayObjectExtension(ctx, proto);
}
return true;
case 'WEBGL_lose_context':
if (checkInstrumented()) {
wrapLoseContextExtension(ctx, proto);
}
return true;
case 'WEBGL_draw_buffers':
// http://www.khronos.org/registry/webgl/extensions/WEBGL_draw_buffers/
case 'WEBGL_security_sensitive_resources':
// http://www.khronos.org/registry/webgl/extensions/WEBGL_security_sensitive_resources/
case 'WEBGL_shared_resources':
// http://www.khronos.org/registry/webgl/extensions/WEBGL_shared_resources/
// Don't support these yet, so report them as not present.
return false;
default:
return true;
}
}
|
[
"function",
"instrumentExtensionObject",
"(",
"ctx",
",",
"name",
",",
"object",
")",
"{",
"var",
"proto",
"=",
"object",
".",
"constructor",
".",
"prototype",
";",
"// We do this check only for known extensions, as Firefox will return a",
"// generic 'Object' for others and that will break everything.",
"function",
"checkInstrumented",
"(",
")",
"{",
"if",
"(",
"proto",
"[",
"'__gl_wrapped__'",
"]",
")",
"{",
"return",
"false",
";",
"}",
"Object",
".",
"defineProperty",
"(",
"proto",
",",
"'__gl_wrapped__'",
",",
"{",
"'configurable'",
":",
"true",
",",
"'enumerable'",
":",
"false",
",",
"'value'",
":",
"true",
"}",
")",
";",
"contextRestoreFns",
".",
"push",
"(",
"function",
"(",
")",
"{",
"delete",
"proto",
"[",
"'__gl_wrapped__'",
"]",
";",
"}",
")",
";",
"return",
"true",
";",
"}",
";",
"switch",
"(",
"name",
")",
"{",
"case",
"'ANGLE_instanced_arrays'",
":",
"if",
"(",
"checkInstrumented",
"(",
")",
")",
"{",
"wrapInstancedArraysExtension",
"(",
"ctx",
",",
"proto",
")",
";",
"}",
"return",
"true",
";",
"case",
"'OES_vertex_array_object'",
":",
"if",
"(",
"checkInstrumented",
"(",
")",
")",
"{",
"wrapVertexArrayObjectExtension",
"(",
"ctx",
",",
"proto",
")",
";",
"}",
"return",
"true",
";",
"case",
"'WEBGL_lose_context'",
":",
"if",
"(",
"checkInstrumented",
"(",
")",
")",
"{",
"wrapLoseContextExtension",
"(",
"ctx",
",",
"proto",
")",
";",
"}",
"return",
"true",
";",
"case",
"'WEBGL_draw_buffers'",
":",
"// http://www.khronos.org/registry/webgl/extensions/WEBGL_draw_buffers/",
"case",
"'WEBGL_security_sensitive_resources'",
":",
"// http://www.khronos.org/registry/webgl/extensions/WEBGL_security_sensitive_resources/",
"case",
"'WEBGL_shared_resources'",
":",
"// http://www.khronos.org/registry/webgl/extensions/WEBGL_shared_resources/",
"// Don't support these yet, so report them as not present.",
"return",
"false",
";",
"default",
":",
"return",
"true",
";",
"}",
"}"
] |
Wraps an extension object.
This should be called for each extension object as it is returned from
getExtension so that its prototype can be instrumented, as required.
@param {!WebGLRenderingContext} ctx Target context.
@param {string} name Extension name.
@param {!Object} object Extension object.
@return {boolean} True if the extension is supported.
|
[
"Wraps",
"an",
"extension",
"object",
".",
"This",
"should",
"be",
"called",
"for",
"each",
"extension",
"object",
"as",
"it",
"is",
"returned",
"from",
"getExtension",
"so",
"that",
"its",
"prototype",
"can",
"be",
"instrumented",
"as",
"required",
"."
] |
495ced98de99a5895e484b2e09771edb42d3c7ab
|
https://github.com/google/tracing-framework/blob/495ced98de99a5895e484b2e09771edb42d3c7ab/src/wtf/trace/providers/webglprovider.js#L593-L640
|
17,756
|
google/tracing-framework
|
src/wtf/trace/providers/webglprovider.js
|
checkInstrumented
|
function checkInstrumented() {
if (proto['__gl_wrapped__']) {
return false;
}
Object.defineProperty(proto, '__gl_wrapped__', {
'configurable': true,
'enumerable': false,
'value': true
});
contextRestoreFns.push(function() {
delete proto['__gl_wrapped__'];
});
return true;
}
|
javascript
|
function checkInstrumented() {
if (proto['__gl_wrapped__']) {
return false;
}
Object.defineProperty(proto, '__gl_wrapped__', {
'configurable': true,
'enumerable': false,
'value': true
});
contextRestoreFns.push(function() {
delete proto['__gl_wrapped__'];
});
return true;
}
|
[
"function",
"checkInstrumented",
"(",
")",
"{",
"if",
"(",
"proto",
"[",
"'__gl_wrapped__'",
"]",
")",
"{",
"return",
"false",
";",
"}",
"Object",
".",
"defineProperty",
"(",
"proto",
",",
"'__gl_wrapped__'",
",",
"{",
"'configurable'",
":",
"true",
",",
"'enumerable'",
":",
"false",
",",
"'value'",
":",
"true",
"}",
")",
";",
"contextRestoreFns",
".",
"push",
"(",
"function",
"(",
")",
"{",
"delete",
"proto",
"[",
"'__gl_wrapped__'",
"]",
";",
"}",
")",
";",
"return",
"true",
";",
"}"
] |
We do this check only for known extensions, as Firefox will return a generic 'Object' for others and that will break everything.
|
[
"We",
"do",
"this",
"check",
"only",
"for",
"known",
"extensions",
"as",
"Firefox",
"will",
"return",
"a",
"generic",
"Object",
"for",
"others",
"and",
"that",
"will",
"break",
"everything",
"."
] |
495ced98de99a5895e484b2e09771edb42d3c7ab
|
https://github.com/google/tracing-framework/blob/495ced98de99a5895e484b2e09771edb42d3c7ab/src/wtf/trace/providers/webglprovider.js#L598-L611
|
17,757
|
soyuka/pidusage
|
index.js
|
pidusage
|
function pidusage (pids, options, callback) {
if (typeof options === 'function') {
callback = options
options = {}
}
if (options === undefined) {
options = {}
}
if (typeof callback === 'function') {
stats(pids, options, callback)
return
}
return new Promise(function (resolve, reject) {
stats(pids, options, function (err, data) {
if (err) return reject(err)
resolve(data)
})
})
}
|
javascript
|
function pidusage (pids, options, callback) {
if (typeof options === 'function') {
callback = options
options = {}
}
if (options === undefined) {
options = {}
}
if (typeof callback === 'function') {
stats(pids, options, callback)
return
}
return new Promise(function (resolve, reject) {
stats(pids, options, function (err, data) {
if (err) return reject(err)
resolve(data)
})
})
}
|
[
"function",
"pidusage",
"(",
"pids",
",",
"options",
",",
"callback",
")",
"{",
"if",
"(",
"typeof",
"options",
"===",
"'function'",
")",
"{",
"callback",
"=",
"options",
"options",
"=",
"{",
"}",
"}",
"if",
"(",
"options",
"===",
"undefined",
")",
"{",
"options",
"=",
"{",
"}",
"}",
"if",
"(",
"typeof",
"callback",
"===",
"'function'",
")",
"{",
"stats",
"(",
"pids",
",",
"options",
",",
"callback",
")",
"return",
"}",
"return",
"new",
"Promise",
"(",
"function",
"(",
"resolve",
",",
"reject",
")",
"{",
"stats",
"(",
"pids",
",",
"options",
",",
"function",
"(",
"err",
",",
"data",
")",
"{",
"if",
"(",
"err",
")",
"return",
"reject",
"(",
"err",
")",
"resolve",
"(",
"data",
")",
"}",
")",
"}",
")",
"}"
] |
Get pid informations.
@public
@param {Number|Number[]|String|String[]} pids A pid or a list of pids.
@param {Object} [options={}] Options object
@param {Function} [callback=undefined] Called when the statistics are ready.
If not provided a promise is returned instead.
@returns {Promise.<Object>} Only when the callback is not provided.
|
[
"Get",
"pid",
"informations",
"."
] |
74ad6b3fed9bc865896cafb12881e05043c1b171
|
https://github.com/soyuka/pidusage/blob/74ad6b3fed9bc865896cafb12881e05043c1b171/index.js#L14-L35
|
17,758
|
soyuka/pidusage
|
lib/ps.js
|
ps
|
function ps (pids, options, done) {
var pArg = pids.join(',')
var args = ['-o', 'etime,pid,ppid,pcpu,rss,time', '-p', pArg]
if (PLATFORM === 'aix') {
args = ['-o', 'etime,pid,ppid,pcpu,rssize,time', '-p', pArg]
}
bin('ps', args, function (err, stdout, code) {
if (err) return done(err)
if (code === 1) {
return done(new Error('No maching pid found'))
}
if (code !== 0) {
return done(new Error('pidusage ps command exited with code ' + code))
}
var date = Date.now()
// Example of stdout on *nix.
// ELAPSED: format is [[dd-]hh:]mm:ss
// RSS: is counted as blocks of 1024 bytes
// TIME: format is [[dd-]hh:]mm:ss
// %CPU: goes from 0 to vcore * 100
//
// Refs: http://www.manpages.info/linux/ps.1.html
// NB: The columns are returned in the order given inside the -o option
//
// ELAPSED PID PPID %CPU RSS TIME
// 2-40:50:53 430 1 3.0 5145 1-02:03:04
// 40:50:53 432 430 0.0 2364 1-01:02:03
// 01:50:50 727 1 10.0 348932 14:27
// 00:20 7166 1 0.1 3756 0:00
// Example of stdout on Darwin
// ELAPSED: format is [[dd-]hh:]mm:ss
// RSS: is counted as blocks of 1024 bytes
// TIME: format is [[dd-]hh:]mm:ss.cc (cc are centiseconds)
// %CPU: goes from 0 to vcore * 100
//
// Refs: https://ss64.com/osx/ps.html
// NB: The columns are returned in the order given inside the -o option
//
// ELAPSED PID PPID %CPU RSS TIME
// 2-40:50:53 430 1 3.0 5145 1-02:03:04.07
// 40:50:53 432 430 0.0 2364 1-01:02:03.10
// 01:50:50 727 1 10.0 348932 14:27.26
// 00:20 7166 1 0.1 3756 0:00.02
stdout = stdout.split(os.EOL)
var statistics = {}
for (var i = 1; i < stdout.length; i++) {
var line = stdout[i].trim().split(/\s+/)
if (!line || line.length !== 6) {
continue
}
var pid = parseInt(line[1], 10)
var hst = history.get(pid, options.maxage)
if (hst === undefined) hst = {}
var ppid = parseInt(line[2], 10)
var memory = parseInt(line[4], 10) * 1024
var etime = parseTime(line[0])
var ctime = parseTime(line[5], true)
var total = (ctime - (hst.ctime || 0))
// time elapsed between calls in seconds
var seconds = Math.abs(hst.elapsed !== undefined ? etime - hst.elapsed : etime)
var cpu = seconds > 0 ? (total / seconds) * 100 : 0
statistics[pid] = {
cpu: cpu,
memory: memory,
ppid: ppid,
pid: pid,
ctime: ctime,
elapsed: etime,
timestamp: date
}
history.set(pid, statistics[pid], options.maxage)
}
done(null, statistics)
})
}
|
javascript
|
function ps (pids, options, done) {
var pArg = pids.join(',')
var args = ['-o', 'etime,pid,ppid,pcpu,rss,time', '-p', pArg]
if (PLATFORM === 'aix') {
args = ['-o', 'etime,pid,ppid,pcpu,rssize,time', '-p', pArg]
}
bin('ps', args, function (err, stdout, code) {
if (err) return done(err)
if (code === 1) {
return done(new Error('No maching pid found'))
}
if (code !== 0) {
return done(new Error('pidusage ps command exited with code ' + code))
}
var date = Date.now()
// Example of stdout on *nix.
// ELAPSED: format is [[dd-]hh:]mm:ss
// RSS: is counted as blocks of 1024 bytes
// TIME: format is [[dd-]hh:]mm:ss
// %CPU: goes from 0 to vcore * 100
//
// Refs: http://www.manpages.info/linux/ps.1.html
// NB: The columns are returned in the order given inside the -o option
//
// ELAPSED PID PPID %CPU RSS TIME
// 2-40:50:53 430 1 3.0 5145 1-02:03:04
// 40:50:53 432 430 0.0 2364 1-01:02:03
// 01:50:50 727 1 10.0 348932 14:27
// 00:20 7166 1 0.1 3756 0:00
// Example of stdout on Darwin
// ELAPSED: format is [[dd-]hh:]mm:ss
// RSS: is counted as blocks of 1024 bytes
// TIME: format is [[dd-]hh:]mm:ss.cc (cc are centiseconds)
// %CPU: goes from 0 to vcore * 100
//
// Refs: https://ss64.com/osx/ps.html
// NB: The columns are returned in the order given inside the -o option
//
// ELAPSED PID PPID %CPU RSS TIME
// 2-40:50:53 430 1 3.0 5145 1-02:03:04.07
// 40:50:53 432 430 0.0 2364 1-01:02:03.10
// 01:50:50 727 1 10.0 348932 14:27.26
// 00:20 7166 1 0.1 3756 0:00.02
stdout = stdout.split(os.EOL)
var statistics = {}
for (var i = 1; i < stdout.length; i++) {
var line = stdout[i].trim().split(/\s+/)
if (!line || line.length !== 6) {
continue
}
var pid = parseInt(line[1], 10)
var hst = history.get(pid, options.maxage)
if (hst === undefined) hst = {}
var ppid = parseInt(line[2], 10)
var memory = parseInt(line[4], 10) * 1024
var etime = parseTime(line[0])
var ctime = parseTime(line[5], true)
var total = (ctime - (hst.ctime || 0))
// time elapsed between calls in seconds
var seconds = Math.abs(hst.elapsed !== undefined ? etime - hst.elapsed : etime)
var cpu = seconds > 0 ? (total / seconds) * 100 : 0
statistics[pid] = {
cpu: cpu,
memory: memory,
ppid: ppid,
pid: pid,
ctime: ctime,
elapsed: etime,
timestamp: date
}
history.set(pid, statistics[pid], options.maxage)
}
done(null, statistics)
})
}
|
[
"function",
"ps",
"(",
"pids",
",",
"options",
",",
"done",
")",
"{",
"var",
"pArg",
"=",
"pids",
".",
"join",
"(",
"','",
")",
"var",
"args",
"=",
"[",
"'-o'",
",",
"'etime,pid,ppid,pcpu,rss,time'",
",",
"'-p'",
",",
"pArg",
"]",
"if",
"(",
"PLATFORM",
"===",
"'aix'",
")",
"{",
"args",
"=",
"[",
"'-o'",
",",
"'etime,pid,ppid,pcpu,rssize,time'",
",",
"'-p'",
",",
"pArg",
"]",
"}",
"bin",
"(",
"'ps'",
",",
"args",
",",
"function",
"(",
"err",
",",
"stdout",
",",
"code",
")",
"{",
"if",
"(",
"err",
")",
"return",
"done",
"(",
"err",
")",
"if",
"(",
"code",
"===",
"1",
")",
"{",
"return",
"done",
"(",
"new",
"Error",
"(",
"'No maching pid found'",
")",
")",
"}",
"if",
"(",
"code",
"!==",
"0",
")",
"{",
"return",
"done",
"(",
"new",
"Error",
"(",
"'pidusage ps command exited with code '",
"+",
"code",
")",
")",
"}",
"var",
"date",
"=",
"Date",
".",
"now",
"(",
")",
"// Example of stdout on *nix.",
"// ELAPSED: format is [[dd-]hh:]mm:ss",
"// RSS: is counted as blocks of 1024 bytes",
"// TIME: format is [[dd-]hh:]mm:ss",
"// %CPU: goes from 0 to vcore * 100",
"//",
"// Refs: http://www.manpages.info/linux/ps.1.html",
"// NB: The columns are returned in the order given inside the -o option",
"//",
"// ELAPSED PID PPID %CPU RSS TIME",
"// 2-40:50:53 430 1 3.0 5145 1-02:03:04",
"// 40:50:53 432 430 0.0 2364 1-01:02:03",
"// 01:50:50 727 1 10.0 348932 14:27",
"// 00:20 7166 1 0.1 3756 0:00",
"// Example of stdout on Darwin",
"// ELAPSED: format is [[dd-]hh:]mm:ss",
"// RSS: is counted as blocks of 1024 bytes",
"// TIME: format is [[dd-]hh:]mm:ss.cc (cc are centiseconds)",
"// %CPU: goes from 0 to vcore * 100",
"//",
"// Refs: https://ss64.com/osx/ps.html",
"// NB: The columns are returned in the order given inside the -o option",
"//",
"// ELAPSED PID PPID %CPU RSS TIME",
"// 2-40:50:53 430 1 3.0 5145 1-02:03:04.07",
"// 40:50:53 432 430 0.0 2364 1-01:02:03.10",
"// 01:50:50 727 1 10.0 348932 14:27.26",
"// 00:20 7166 1 0.1 3756 0:00.02",
"stdout",
"=",
"stdout",
".",
"split",
"(",
"os",
".",
"EOL",
")",
"var",
"statistics",
"=",
"{",
"}",
"for",
"(",
"var",
"i",
"=",
"1",
";",
"i",
"<",
"stdout",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"line",
"=",
"stdout",
"[",
"i",
"]",
".",
"trim",
"(",
")",
".",
"split",
"(",
"/",
"\\s+",
"/",
")",
"if",
"(",
"!",
"line",
"||",
"line",
".",
"length",
"!==",
"6",
")",
"{",
"continue",
"}",
"var",
"pid",
"=",
"parseInt",
"(",
"line",
"[",
"1",
"]",
",",
"10",
")",
"var",
"hst",
"=",
"history",
".",
"get",
"(",
"pid",
",",
"options",
".",
"maxage",
")",
"if",
"(",
"hst",
"===",
"undefined",
")",
"hst",
"=",
"{",
"}",
"var",
"ppid",
"=",
"parseInt",
"(",
"line",
"[",
"2",
"]",
",",
"10",
")",
"var",
"memory",
"=",
"parseInt",
"(",
"line",
"[",
"4",
"]",
",",
"10",
")",
"*",
"1024",
"var",
"etime",
"=",
"parseTime",
"(",
"line",
"[",
"0",
"]",
")",
"var",
"ctime",
"=",
"parseTime",
"(",
"line",
"[",
"5",
"]",
",",
"true",
")",
"var",
"total",
"=",
"(",
"ctime",
"-",
"(",
"hst",
".",
"ctime",
"||",
"0",
")",
")",
"// time elapsed between calls in seconds",
"var",
"seconds",
"=",
"Math",
".",
"abs",
"(",
"hst",
".",
"elapsed",
"!==",
"undefined",
"?",
"etime",
"-",
"hst",
".",
"elapsed",
":",
"etime",
")",
"var",
"cpu",
"=",
"seconds",
">",
"0",
"?",
"(",
"total",
"/",
"seconds",
")",
"*",
"100",
":",
"0",
"statistics",
"[",
"pid",
"]",
"=",
"{",
"cpu",
":",
"cpu",
",",
"memory",
":",
"memory",
",",
"ppid",
":",
"ppid",
",",
"pid",
":",
"pid",
",",
"ctime",
":",
"ctime",
",",
"elapsed",
":",
"etime",
",",
"timestamp",
":",
"date",
"}",
"history",
".",
"set",
"(",
"pid",
",",
"statistics",
"[",
"pid",
"]",
",",
"options",
".",
"maxage",
")",
"}",
"done",
"(",
"null",
",",
"statistics",
")",
"}",
")",
"}"
] |
Get pid informations through ps command.
@param {Number[]} pids
@param {Object} options
@param {Function} done(err, stat)
|
[
"Get",
"pid",
"informations",
"through",
"ps",
"command",
"."
] |
74ad6b3fed9bc865896cafb12881e05043c1b171
|
https://github.com/soyuka/pidusage/blob/74ad6b3fed9bc865896cafb12881e05043c1b171/lib/ps.js#L37-L124
|
17,759
|
stream-utils/raw-body
|
index.js
|
getDecoder
|
function getDecoder (encoding) {
if (!encoding) return null
try {
return iconv.getDecoder(encoding)
} catch (e) {
// error getting decoder
if (!ICONV_ENCODING_MESSAGE_REGEXP.test(e.message)) throw e
// the encoding was not found
throw createError(415, 'specified encoding unsupported', {
encoding: encoding,
type: 'encoding.unsupported'
})
}
}
|
javascript
|
function getDecoder (encoding) {
if (!encoding) return null
try {
return iconv.getDecoder(encoding)
} catch (e) {
// error getting decoder
if (!ICONV_ENCODING_MESSAGE_REGEXP.test(e.message)) throw e
// the encoding was not found
throw createError(415, 'specified encoding unsupported', {
encoding: encoding,
type: 'encoding.unsupported'
})
}
}
|
[
"function",
"getDecoder",
"(",
"encoding",
")",
"{",
"if",
"(",
"!",
"encoding",
")",
"return",
"null",
"try",
"{",
"return",
"iconv",
".",
"getDecoder",
"(",
"encoding",
")",
"}",
"catch",
"(",
"e",
")",
"{",
"// error getting decoder",
"if",
"(",
"!",
"ICONV_ENCODING_MESSAGE_REGEXP",
".",
"test",
"(",
"e",
".",
"message",
")",
")",
"throw",
"e",
"// the encoding was not found",
"throw",
"createError",
"(",
"415",
",",
"'specified encoding unsupported'",
",",
"{",
"encoding",
":",
"encoding",
",",
"type",
":",
"'encoding.unsupported'",
"}",
")",
"}",
"}"
] |
Get the decoder for a given encoding.
@param {string} encoding
@private
|
[
"Get",
"the",
"decoder",
"for",
"a",
"given",
"encoding",
"."
] |
bf4f3d1ef5d7277233f08f31d52a5ff36337d573
|
https://github.com/stream-utils/raw-body/blob/bf4f3d1ef5d7277233f08f31d52a5ff36337d573/index.js#L41-L56
|
17,760
|
brianc/node-sql
|
lib/node/index.js
|
function(query, dialect) {
var sql = query.sql || (query.table && query.table.sql);
var Dialect;
if (dialect) {
// dialect is specified
Dialect = getDialect(dialect);
} else if (sql && sql.dialect) {
// dialect is not specified, use the dialect from the sql instance
Dialect = sql.dialect;
} else {
// dialect is not specified, use the default dialect
Dialect = require('../').dialect;
}
return Dialect;
}
|
javascript
|
function(query, dialect) {
var sql = query.sql || (query.table && query.table.sql);
var Dialect;
if (dialect) {
// dialect is specified
Dialect = getDialect(dialect);
} else if (sql && sql.dialect) {
// dialect is not specified, use the dialect from the sql instance
Dialect = sql.dialect;
} else {
// dialect is not specified, use the default dialect
Dialect = require('../').dialect;
}
return Dialect;
}
|
[
"function",
"(",
"query",
",",
"dialect",
")",
"{",
"var",
"sql",
"=",
"query",
".",
"sql",
"||",
"(",
"query",
".",
"table",
"&&",
"query",
".",
"table",
".",
"sql",
")",
";",
"var",
"Dialect",
";",
"if",
"(",
"dialect",
")",
"{",
"// dialect is specified",
"Dialect",
"=",
"getDialect",
"(",
"dialect",
")",
";",
"}",
"else",
"if",
"(",
"sql",
"&&",
"sql",
".",
"dialect",
")",
"{",
"// dialect is not specified, use the dialect from the sql instance",
"Dialect",
"=",
"sql",
".",
"dialect",
";",
"}",
"else",
"{",
"// dialect is not specified, use the default dialect",
"Dialect",
"=",
"require",
"(",
"'../'",
")",
".",
"dialect",
";",
"}",
"return",
"Dialect",
";",
"}"
] |
Before the change that introduced parallel dialects, every node could be turned into a query. The parallel dialects change made it impossible to change some nodes into a query because not all nodes are constructed with the sql instance.
|
[
"Before",
"the",
"change",
"that",
"introduced",
"parallel",
"dialects",
"every",
"node",
"could",
"be",
"turned",
"into",
"a",
"query",
".",
"The",
"parallel",
"dialects",
"change",
"made",
"it",
"impossible",
"to",
"change",
"some",
"nodes",
"into",
"a",
"query",
"because",
"not",
"all",
"nodes",
"are",
"constructed",
"with",
"the",
"sql",
"instance",
"."
] |
95d775a9a10650c2de34edf23a1a859abf7744dc
|
https://github.com/brianc/node-sql/blob/95d775a9a10650c2de34edf23a1a859abf7744dc/lib/node/index.js#L35-L50
|
|
17,761
|
brianc/node-sql
|
lib/dialect/mssql.js
|
getModifierValue
|
function getModifierValue(dialect,node){
return node.count.type ? dialect.visit(node.count) : node.count;
}
|
javascript
|
function getModifierValue(dialect,node){
return node.count.type ? dialect.visit(node.count) : node.count;
}
|
[
"function",
"getModifierValue",
"(",
"dialect",
",",
"node",
")",
"{",
"return",
"node",
".",
"count",
".",
"type",
"?",
"dialect",
".",
"visit",
"(",
"node",
".",
"count",
")",
":",
"node",
".",
"count",
";",
"}"
] |
Node is either an OFFSET or LIMIT node
|
[
"Node",
"is",
"either",
"an",
"OFFSET",
"or",
"LIMIT",
"node"
] |
95d775a9a10650c2de34edf23a1a859abf7744dc
|
https://github.com/brianc/node-sql/blob/95d775a9a10650c2de34edf23a1a859abf7744dc/lib/dialect/mssql.js#L411-L413
|
17,762
|
othiym23/node-continuation-local-storage
|
context.js
|
attach
|
function attach(listener) {
if (!listener) return;
if (!listener[CONTEXTS_SYMBOL]) listener[CONTEXTS_SYMBOL] = Object.create(null);
listener[CONTEXTS_SYMBOL][thisSymbol] = {
namespace : namespace,
context : namespace.active
};
}
|
javascript
|
function attach(listener) {
if (!listener) return;
if (!listener[CONTEXTS_SYMBOL]) listener[CONTEXTS_SYMBOL] = Object.create(null);
listener[CONTEXTS_SYMBOL][thisSymbol] = {
namespace : namespace,
context : namespace.active
};
}
|
[
"function",
"attach",
"(",
"listener",
")",
"{",
"if",
"(",
"!",
"listener",
")",
"return",
";",
"if",
"(",
"!",
"listener",
"[",
"CONTEXTS_SYMBOL",
"]",
")",
"listener",
"[",
"CONTEXTS_SYMBOL",
"]",
"=",
"Object",
".",
"create",
"(",
"null",
")",
";",
"listener",
"[",
"CONTEXTS_SYMBOL",
"]",
"[",
"thisSymbol",
"]",
"=",
"{",
"namespace",
":",
"namespace",
",",
"context",
":",
"namespace",
".",
"active",
"}",
";",
"}"
] |
Capture the context active at the time the emitter is bound.
|
[
"Capture",
"the",
"context",
"active",
"at",
"the",
"time",
"the",
"emitter",
"is",
"bound",
"."
] |
fc770288979f6050e4371c1e1b44d2b76b233664
|
https://github.com/othiym23/node-continuation-local-storage/blob/fc770288979f6050e4371c1e1b44d2b76b233664/context.js#L131-L139
|
17,763
|
othiym23/node-continuation-local-storage
|
context.js
|
bind
|
function bind(unwrapped) {
if (!(unwrapped && unwrapped[CONTEXTS_SYMBOL])) return unwrapped;
var wrapped = unwrapped;
var contexts = unwrapped[CONTEXTS_SYMBOL];
Object.keys(contexts).forEach(function (name) {
var thunk = contexts[name];
wrapped = thunk.namespace.bind(wrapped, thunk.context);
});
return wrapped;
}
|
javascript
|
function bind(unwrapped) {
if (!(unwrapped && unwrapped[CONTEXTS_SYMBOL])) return unwrapped;
var wrapped = unwrapped;
var contexts = unwrapped[CONTEXTS_SYMBOL];
Object.keys(contexts).forEach(function (name) {
var thunk = contexts[name];
wrapped = thunk.namespace.bind(wrapped, thunk.context);
});
return wrapped;
}
|
[
"function",
"bind",
"(",
"unwrapped",
")",
"{",
"if",
"(",
"!",
"(",
"unwrapped",
"&&",
"unwrapped",
"[",
"CONTEXTS_SYMBOL",
"]",
")",
")",
"return",
"unwrapped",
";",
"var",
"wrapped",
"=",
"unwrapped",
";",
"var",
"contexts",
"=",
"unwrapped",
"[",
"CONTEXTS_SYMBOL",
"]",
";",
"Object",
".",
"keys",
"(",
"contexts",
")",
".",
"forEach",
"(",
"function",
"(",
"name",
")",
"{",
"var",
"thunk",
"=",
"contexts",
"[",
"name",
"]",
";",
"wrapped",
"=",
"thunk",
".",
"namespace",
".",
"bind",
"(",
"wrapped",
",",
"thunk",
".",
"context",
")",
";",
"}",
")",
";",
"return",
"wrapped",
";",
"}"
] |
At emit time, bind the listener within the correct context.
|
[
"At",
"emit",
"time",
"bind",
"the",
"listener",
"within",
"the",
"correct",
"context",
"."
] |
fc770288979f6050e4371c1e1b44d2b76b233664
|
https://github.com/othiym23/node-continuation-local-storage/blob/fc770288979f6050e4371c1e1b44d2b76b233664/context.js#L142-L152
|
17,764
|
Kong/unirest-nodejs
|
index.js
|
function (name, path, options) {
options = options || {}
options.attachment = true
return handleField(name, path, options)
}
|
javascript
|
function (name, path, options) {
options = options || {}
options.attachment = true
return handleField(name, path, options)
}
|
[
"function",
"(",
"name",
",",
"path",
",",
"options",
")",
"{",
"options",
"=",
"options",
"||",
"{",
"}",
"options",
".",
"attachment",
"=",
"true",
"return",
"handleField",
"(",
"name",
",",
"path",
",",
"options",
")",
"}"
] |
Attaches a file to the multipart-form request.
@param {String} name
@param {String|Object} path
@return {Object}
|
[
"Attaches",
"a",
"file",
"to",
"the",
"multipart",
"-",
"form",
"request",
"."
] |
a06ba4e6c58fea028d377c170cb4cbf7cf3c6049
|
https://github.com/Kong/unirest-nodejs/blob/a06ba4e6c58fea028d377c170cb4cbf7cf3c6049/index.js#L136-L140
|
|
17,765
|
Kong/unirest-nodejs
|
index.js
|
function (name, value, options) {
$this._multipart.push({
name: name,
value: value,
options: options,
attachment: options.attachment || false
})
}
|
javascript
|
function (name, value, options) {
$this._multipart.push({
name: name,
value: value,
options: options,
attachment: options.attachment || false
})
}
|
[
"function",
"(",
"name",
",",
"value",
",",
"options",
")",
"{",
"$this",
".",
"_multipart",
".",
"push",
"(",
"{",
"name",
":",
"name",
",",
"value",
":",
"value",
",",
"options",
":",
"options",
",",
"attachment",
":",
"options",
".",
"attachment",
"||",
"false",
"}",
")",
"}"
] |
Attaches field to the multipart-form request, with no pre-processing.
@param {String} name
@param {String|Object} path
@param {Object} options
@return {Object}
|
[
"Attaches",
"field",
"to",
"the",
"multipart",
"-",
"form",
"request",
"with",
"no",
"pre",
"-",
"processing",
"."
] |
a06ba4e6c58fea028d377c170cb4cbf7cf3c6049
|
https://github.com/Kong/unirest-nodejs/blob/a06ba4e6c58fea028d377c170cb4cbf7cf3c6049/index.js#L150-L157
|
|
17,766
|
Kong/unirest-nodejs
|
index.js
|
function (user, password, sendImmediately) {
$this.options.auth = (is(user).a(Object)) ? user : {
user: user,
password: password,
sendImmediately: sendImmediately
}
return $this
}
|
javascript
|
function (user, password, sendImmediately) {
$this.options.auth = (is(user).a(Object)) ? user : {
user: user,
password: password,
sendImmediately: sendImmediately
}
return $this
}
|
[
"function",
"(",
"user",
",",
"password",
",",
"sendImmediately",
")",
"{",
"$this",
".",
"options",
".",
"auth",
"=",
"(",
"is",
"(",
"user",
")",
".",
"a",
"(",
"Object",
")",
")",
"?",
"user",
":",
"{",
"user",
":",
"user",
",",
"password",
":",
"password",
",",
"sendImmediately",
":",
"sendImmediately",
"}",
"return",
"$this",
"}"
] |
Basic Header Authentication Method
Supports user being an Object to reflect Request
Supports user, password to reflect SuperAgent
@param {String|Object} user
@param {String} password
@param {Boolean} sendImmediately
@return {Object}
|
[
"Basic",
"Header",
"Authentication",
"Method"
] |
a06ba4e6c58fea028d377c170cb4cbf7cf3c6049
|
https://github.com/Kong/unirest-nodejs/blob/a06ba4e6c58fea028d377c170cb4cbf7cf3c6049/index.js#L170-L178
|
|
17,767
|
Kong/unirest-nodejs
|
index.js
|
function (field, value) {
if (is(field).a(Object)) {
for (var key in field) {
if (Object.prototype.hasOwnProperty.call(field, key)) {
$this.header(key, field[key])
}
}
return $this
}
var existingHeaderName = $this.hasHeader(field)
$this.options.headers[existingHeaderName || field] = value
return $this
}
|
javascript
|
function (field, value) {
if (is(field).a(Object)) {
for (var key in field) {
if (Object.prototype.hasOwnProperty.call(field, key)) {
$this.header(key, field[key])
}
}
return $this
}
var existingHeaderName = $this.hasHeader(field)
$this.options.headers[existingHeaderName || field] = value
return $this
}
|
[
"function",
"(",
"field",
",",
"value",
")",
"{",
"if",
"(",
"is",
"(",
"field",
")",
".",
"a",
"(",
"Object",
")",
")",
"{",
"for",
"(",
"var",
"key",
"in",
"field",
")",
"{",
"if",
"(",
"Object",
".",
"prototype",
".",
"hasOwnProperty",
".",
"call",
"(",
"field",
",",
"key",
")",
")",
"{",
"$this",
".",
"header",
"(",
"key",
",",
"field",
"[",
"key",
"]",
")",
"}",
"}",
"return",
"$this",
"}",
"var",
"existingHeaderName",
"=",
"$this",
".",
"hasHeader",
"(",
"field",
")",
"$this",
".",
"options",
".",
"headers",
"[",
"existingHeaderName",
"||",
"field",
"]",
"=",
"value",
"return",
"$this",
"}"
] |
Sets header field to value
@param {String} field Header field
@param {String} value Header field value
@return {Object}
|
[
"Sets",
"header",
"field",
"to",
"value"
] |
a06ba4e6c58fea028d377c170cb4cbf7cf3c6049
|
https://github.com/Kong/unirest-nodejs/blob/a06ba4e6c58fea028d377c170cb4cbf7cf3c6049/index.js#L187-L202
|
|
17,768
|
Kong/unirest-nodejs
|
index.js
|
function (value) {
if (is(value).a(Object)) value = Unirest.serializers.form(value)
if (!value.length) return $this
$this.options.url += (does($this.options.url).contain('?') ? '&' : '?') + value
return $this
}
|
javascript
|
function (value) {
if (is(value).a(Object)) value = Unirest.serializers.form(value)
if (!value.length) return $this
$this.options.url += (does($this.options.url).contain('?') ? '&' : '?') + value
return $this
}
|
[
"function",
"(",
"value",
")",
"{",
"if",
"(",
"is",
"(",
"value",
")",
".",
"a",
"(",
"Object",
")",
")",
"value",
"=",
"Unirest",
".",
"serializers",
".",
"form",
"(",
"value",
")",
"if",
"(",
"!",
"value",
".",
"length",
")",
"return",
"$this",
"$this",
".",
"options",
".",
"url",
"+=",
"(",
"does",
"(",
"$this",
".",
"options",
".",
"url",
")",
".",
"contain",
"(",
"'?'",
")",
"?",
"'&'",
":",
"'?'",
")",
"+",
"value",
"return",
"$this",
"}"
] |
Serialize value as querystring representation, and append or set on `Request.options.url`
@param {String|Object} value
@return {Object}
|
[
"Serialize",
"value",
"as",
"querystring",
"representation",
"and",
"append",
"or",
"set",
"on",
"Request",
".",
"options",
".",
"url"
] |
a06ba4e6c58fea028d377c170cb4cbf7cf3c6049
|
https://github.com/Kong/unirest-nodejs/blob/a06ba4e6c58fea028d377c170cb4cbf7cf3c6049/index.js#L210-L215
|
|
17,769
|
Kong/unirest-nodejs
|
index.js
|
function (data) {
var type = $this.options.headers[$this.hasHeader('content-type')]
if ((is(data).a(Object) || is(data).a(Array)) && !Buffer.isBuffer(data)) {
if (!type) {
$this.type('form')
type = $this.options.headers[$this.hasHeader('content-type')]
$this.options.body = Unirest.serializers.form(data)
} else if (~type.indexOf('json')) {
$this.options.json = true
if ($this.options.body && is($this.options.body).a(Object)) {
for (var key in data) {
if (Object.prototype.hasOwnProperty.call(data, key)) {
$this.options.body[key] = data[key]
}
}
} else {
$this.options.body = data
}
} else {
$this.options.body = Unirest.Request.serialize(data, type)
}
} else if (is(data).a(String)) {
if (!type) {
$this.type('form')
type = $this.options.headers[$this.hasHeader('content-type')]
}
if (type === 'application/x-www-form-urlencoded') {
$this.options.body = $this.options.body
? $this.options.body + '&' + data
: data
} else {
$this.options.body = ($this.options.body || '') + data
}
} else {
$this.options.body = data
}
return $this
}
|
javascript
|
function (data) {
var type = $this.options.headers[$this.hasHeader('content-type')]
if ((is(data).a(Object) || is(data).a(Array)) && !Buffer.isBuffer(data)) {
if (!type) {
$this.type('form')
type = $this.options.headers[$this.hasHeader('content-type')]
$this.options.body = Unirest.serializers.form(data)
} else if (~type.indexOf('json')) {
$this.options.json = true
if ($this.options.body && is($this.options.body).a(Object)) {
for (var key in data) {
if (Object.prototype.hasOwnProperty.call(data, key)) {
$this.options.body[key] = data[key]
}
}
} else {
$this.options.body = data
}
} else {
$this.options.body = Unirest.Request.serialize(data, type)
}
} else if (is(data).a(String)) {
if (!type) {
$this.type('form')
type = $this.options.headers[$this.hasHeader('content-type')]
}
if (type === 'application/x-www-form-urlencoded') {
$this.options.body = $this.options.body
? $this.options.body + '&' + data
: data
} else {
$this.options.body = ($this.options.body || '') + data
}
} else {
$this.options.body = data
}
return $this
}
|
[
"function",
"(",
"data",
")",
"{",
"var",
"type",
"=",
"$this",
".",
"options",
".",
"headers",
"[",
"$this",
".",
"hasHeader",
"(",
"'content-type'",
")",
"]",
"if",
"(",
"(",
"is",
"(",
"data",
")",
".",
"a",
"(",
"Object",
")",
"||",
"is",
"(",
"data",
")",
".",
"a",
"(",
"Array",
")",
")",
"&&",
"!",
"Buffer",
".",
"isBuffer",
"(",
"data",
")",
")",
"{",
"if",
"(",
"!",
"type",
")",
"{",
"$this",
".",
"type",
"(",
"'form'",
")",
"type",
"=",
"$this",
".",
"options",
".",
"headers",
"[",
"$this",
".",
"hasHeader",
"(",
"'content-type'",
")",
"]",
"$this",
".",
"options",
".",
"body",
"=",
"Unirest",
".",
"serializers",
".",
"form",
"(",
"data",
")",
"}",
"else",
"if",
"(",
"~",
"type",
".",
"indexOf",
"(",
"'json'",
")",
")",
"{",
"$this",
".",
"options",
".",
"json",
"=",
"true",
"if",
"(",
"$this",
".",
"options",
".",
"body",
"&&",
"is",
"(",
"$this",
".",
"options",
".",
"body",
")",
".",
"a",
"(",
"Object",
")",
")",
"{",
"for",
"(",
"var",
"key",
"in",
"data",
")",
"{",
"if",
"(",
"Object",
".",
"prototype",
".",
"hasOwnProperty",
".",
"call",
"(",
"data",
",",
"key",
")",
")",
"{",
"$this",
".",
"options",
".",
"body",
"[",
"key",
"]",
"=",
"data",
"[",
"key",
"]",
"}",
"}",
"}",
"else",
"{",
"$this",
".",
"options",
".",
"body",
"=",
"data",
"}",
"}",
"else",
"{",
"$this",
".",
"options",
".",
"body",
"=",
"Unirest",
".",
"Request",
".",
"serialize",
"(",
"data",
",",
"type",
")",
"}",
"}",
"else",
"if",
"(",
"is",
"(",
"data",
")",
".",
"a",
"(",
"String",
")",
")",
"{",
"if",
"(",
"!",
"type",
")",
"{",
"$this",
".",
"type",
"(",
"'form'",
")",
"type",
"=",
"$this",
".",
"options",
".",
"headers",
"[",
"$this",
".",
"hasHeader",
"(",
"'content-type'",
")",
"]",
"}",
"if",
"(",
"type",
"===",
"'application/x-www-form-urlencoded'",
")",
"{",
"$this",
".",
"options",
".",
"body",
"=",
"$this",
".",
"options",
".",
"body",
"?",
"$this",
".",
"options",
".",
"body",
"+",
"'&'",
"+",
"data",
":",
"data",
"}",
"else",
"{",
"$this",
".",
"options",
".",
"body",
"=",
"(",
"$this",
".",
"options",
".",
"body",
"||",
"''",
")",
"+",
"data",
"}",
"}",
"else",
"{",
"$this",
".",
"options",
".",
"body",
"=",
"data",
"}",
"return",
"$this",
"}"
] |
Data marshalling for HTTP request body data
Determines whether type is `form` or `json`.
For irregular mime-types the `.type()` method is used to infer the `content-type` header.
When mime-type is `application/x-www-form-urlencoded` data is appended rather than overwritten.
@param {Mixed} data
@return {Object}
|
[
"Data",
"marshalling",
"for",
"HTTP",
"request",
"body",
"data"
] |
a06ba4e6c58fea028d377c170cb4cbf7cf3c6049
|
https://github.com/Kong/unirest-nodejs/blob/a06ba4e6c58fea028d377c170cb4cbf7cf3c6049/index.js#L241-L282
|
|
17,770
|
Kong/unirest-nodejs
|
index.js
|
function (options) {
if (!$this._multipart) {
$this.options.multipart = []
}
if (is(options).a(Object)) {
if (options['content-type']) {
var type = Unirest.type(options['content-type'], true)
if (type) options.body = Unirest.Response.parse(options.body)
} else {
if (is(options.body).a(Object)) {
options.body = Unirest.serializers.json(options.body)
}
}
$this.options.multipart.push(options)
} else {
$this.options.multipart.push({
body: options
})
}
return $this
}
|
javascript
|
function (options) {
if (!$this._multipart) {
$this.options.multipart = []
}
if (is(options).a(Object)) {
if (options['content-type']) {
var type = Unirest.type(options['content-type'], true)
if (type) options.body = Unirest.Response.parse(options.body)
} else {
if (is(options.body).a(Object)) {
options.body = Unirest.serializers.json(options.body)
}
}
$this.options.multipart.push(options)
} else {
$this.options.multipart.push({
body: options
})
}
return $this
}
|
[
"function",
"(",
"options",
")",
"{",
"if",
"(",
"!",
"$this",
".",
"_multipart",
")",
"{",
"$this",
".",
"options",
".",
"multipart",
"=",
"[",
"]",
"}",
"if",
"(",
"is",
"(",
"options",
")",
".",
"a",
"(",
"Object",
")",
")",
"{",
"if",
"(",
"options",
"[",
"'content-type'",
"]",
")",
"{",
"var",
"type",
"=",
"Unirest",
".",
"type",
"(",
"options",
"[",
"'content-type'",
"]",
",",
"true",
")",
"if",
"(",
"type",
")",
"options",
".",
"body",
"=",
"Unirest",
".",
"Response",
".",
"parse",
"(",
"options",
".",
"body",
")",
"}",
"else",
"{",
"if",
"(",
"is",
"(",
"options",
".",
"body",
")",
".",
"a",
"(",
"Object",
")",
")",
"{",
"options",
".",
"body",
"=",
"Unirest",
".",
"serializers",
".",
"json",
"(",
"options",
".",
"body",
")",
"}",
"}",
"$this",
".",
"options",
".",
"multipart",
".",
"push",
"(",
"options",
")",
"}",
"else",
"{",
"$this",
".",
"options",
".",
"multipart",
".",
"push",
"(",
"{",
"body",
":",
"options",
"}",
")",
"}",
"return",
"$this",
"}"
] |
Takes multipart options and places them on `options.multipart` array.
Transforms body when an `Object` or _content-type_ is present.
Example:
Unirest.get('http://google.com').part({
'content-type': 'application/json',
body: {
phrase: 'Hello'
}
}).part({
'content-type': 'application/json',
body: {
phrase: 'World'
}
}).end(function (response) {})
@param {Object|String} options When an Object, headers should be placed directly on the object,
not under a child property.
@return {Object}
|
[
"Takes",
"multipart",
"options",
"and",
"places",
"them",
"on",
"options",
".",
"multipart",
"array",
".",
"Transforms",
"body",
"when",
"an",
"Object",
"or",
"_content",
"-",
"type_",
"is",
"present",
"."
] |
a06ba4e6c58fea028d377c170cb4cbf7cf3c6049
|
https://github.com/Kong/unirest-nodejs/blob/a06ba4e6c58fea028d377c170cb4cbf7cf3c6049/index.js#L306-L329
|
|
17,771
|
Kong/unirest-nodejs
|
index.js
|
handleField
|
function handleField (name, value, options) {
var serialized
var length
var key
var i
options = options || { attachment: false }
if (is(name).a(Object)) {
for (key in name) {
if (Object.prototype.hasOwnProperty.call(name, key)) {
handleField(key, name[key], options)
}
}
} else {
if (is(value).a(Array)) {
for (i = 0, length = value.length; i < length; i++) {
serialized = handleFieldValue(value[i])
if (serialized) {
$this.rawField(name, serialized, options)
}
}
} else if (value != null) {
$this.rawField(name, handleFieldValue(value), options)
}
}
return $this
}
|
javascript
|
function handleField (name, value, options) {
var serialized
var length
var key
var i
options = options || { attachment: false }
if (is(name).a(Object)) {
for (key in name) {
if (Object.prototype.hasOwnProperty.call(name, key)) {
handleField(key, name[key], options)
}
}
} else {
if (is(value).a(Array)) {
for (i = 0, length = value.length; i < length; i++) {
serialized = handleFieldValue(value[i])
if (serialized) {
$this.rawField(name, serialized, options)
}
}
} else if (value != null) {
$this.rawField(name, handleFieldValue(value), options)
}
}
return $this
}
|
[
"function",
"handleField",
"(",
"name",
",",
"value",
",",
"options",
")",
"{",
"var",
"serialized",
"var",
"length",
"var",
"key",
"var",
"i",
"options",
"=",
"options",
"||",
"{",
"attachment",
":",
"false",
"}",
"if",
"(",
"is",
"(",
"name",
")",
".",
"a",
"(",
"Object",
")",
")",
"{",
"for",
"(",
"key",
"in",
"name",
")",
"{",
"if",
"(",
"Object",
".",
"prototype",
".",
"hasOwnProperty",
".",
"call",
"(",
"name",
",",
"key",
")",
")",
"{",
"handleField",
"(",
"key",
",",
"name",
"[",
"key",
"]",
",",
"options",
")",
"}",
"}",
"}",
"else",
"{",
"if",
"(",
"is",
"(",
"value",
")",
".",
"a",
"(",
"Array",
")",
")",
"{",
"for",
"(",
"i",
"=",
"0",
",",
"length",
"=",
"value",
".",
"length",
";",
"i",
"<",
"length",
";",
"i",
"++",
")",
"{",
"serialized",
"=",
"handleFieldValue",
"(",
"value",
"[",
"i",
"]",
")",
"if",
"(",
"serialized",
")",
"{",
"$this",
".",
"rawField",
"(",
"name",
",",
"serialized",
",",
"options",
")",
"}",
"}",
"}",
"else",
"if",
"(",
"value",
"!=",
"null",
")",
"{",
"$this",
".",
"rawField",
"(",
"name",
",",
"handleFieldValue",
"(",
"value",
")",
",",
"options",
")",
"}",
"}",
"return",
"$this",
"}"
] |
Handles Multipart Field Processing
@param {String} name
@param {Mixed} value
@param {Object} options
|
[
"Handles",
"Multipart",
"Field",
"Processing"
] |
a06ba4e6c58fea028d377c170cb4cbf7cf3c6049
|
https://github.com/Kong/unirest-nodejs/blob/a06ba4e6c58fea028d377c170cb4cbf7cf3c6049/index.js#L734-L762
|
17,772
|
Kong/unirest-nodejs
|
index.js
|
handleFieldValue
|
function handleFieldValue (value) {
if (!(value instanceof Buffer || typeof value === 'string')) {
if (is(value).a(Object)) {
if (value instanceof fs.FileReadStream) {
return value
} else {
return Unirest.serializers.json(value)
}
} else {
return value.toString()
}
} else return value
}
|
javascript
|
function handleFieldValue (value) {
if (!(value instanceof Buffer || typeof value === 'string')) {
if (is(value).a(Object)) {
if (value instanceof fs.FileReadStream) {
return value
} else {
return Unirest.serializers.json(value)
}
} else {
return value.toString()
}
} else return value
}
|
[
"function",
"handleFieldValue",
"(",
"value",
")",
"{",
"if",
"(",
"!",
"(",
"value",
"instanceof",
"Buffer",
"||",
"typeof",
"value",
"===",
"'string'",
")",
")",
"{",
"if",
"(",
"is",
"(",
"value",
")",
".",
"a",
"(",
"Object",
")",
")",
"{",
"if",
"(",
"value",
"instanceof",
"fs",
".",
"FileReadStream",
")",
"{",
"return",
"value",
"}",
"else",
"{",
"return",
"Unirest",
".",
"serializers",
".",
"json",
"(",
"value",
")",
"}",
"}",
"else",
"{",
"return",
"value",
".",
"toString",
"(",
")",
"}",
"}",
"else",
"return",
"value",
"}"
] |
Handles Multipart Value Processing
@param {Mixed} value
|
[
"Handles",
"Multipart",
"Value",
"Processing"
] |
a06ba4e6c58fea028d377c170cb4cbf7cf3c6049
|
https://github.com/Kong/unirest-nodejs/blob/a06ba4e6c58fea028d377c170cb4cbf7cf3c6049/index.js#L769-L781
|
17,773
|
heiseonline/shariff
|
src/js/dom.js
|
dq
|
function dq(selector, context) {
var nodes = []
context = context || document
if (typeof selector === 'function') {
if (context.attachEvent ? context.readyState === 'complete' : context.readyState !== 'loading') {
selector()
} else {
context.addEventListener('DOMContentLoaded', selector)
}
} else if (selector instanceof Element) {
nodes = [ selector ]
} else if (typeof selector === 'string') {
if (selector[0] === '<') {
nodes = Array.prototype.slice.call(fragment(selector))
} else {
nodes = Array.prototype.slice.call(context.querySelectorAll(selector))
}
} else {
nodes = selector
}
return new DOMQuery(nodes, context)
}
|
javascript
|
function dq(selector, context) {
var nodes = []
context = context || document
if (typeof selector === 'function') {
if (context.attachEvent ? context.readyState === 'complete' : context.readyState !== 'loading') {
selector()
} else {
context.addEventListener('DOMContentLoaded', selector)
}
} else if (selector instanceof Element) {
nodes = [ selector ]
} else if (typeof selector === 'string') {
if (selector[0] === '<') {
nodes = Array.prototype.slice.call(fragment(selector))
} else {
nodes = Array.prototype.slice.call(context.querySelectorAll(selector))
}
} else {
nodes = selector
}
return new DOMQuery(nodes, context)
}
|
[
"function",
"dq",
"(",
"selector",
",",
"context",
")",
"{",
"var",
"nodes",
"=",
"[",
"]",
"context",
"=",
"context",
"||",
"document",
"if",
"(",
"typeof",
"selector",
"===",
"'function'",
")",
"{",
"if",
"(",
"context",
".",
"attachEvent",
"?",
"context",
".",
"readyState",
"===",
"'complete'",
":",
"context",
".",
"readyState",
"!==",
"'loading'",
")",
"{",
"selector",
"(",
")",
"}",
"else",
"{",
"context",
".",
"addEventListener",
"(",
"'DOMContentLoaded'",
",",
"selector",
")",
"}",
"}",
"else",
"if",
"(",
"selector",
"instanceof",
"Element",
")",
"{",
"nodes",
"=",
"[",
"selector",
"]",
"}",
"else",
"if",
"(",
"typeof",
"selector",
"===",
"'string'",
")",
"{",
"if",
"(",
"selector",
"[",
"0",
"]",
"===",
"'<'",
")",
"{",
"nodes",
"=",
"Array",
".",
"prototype",
".",
"slice",
".",
"call",
"(",
"fragment",
"(",
"selector",
")",
")",
"}",
"else",
"{",
"nodes",
"=",
"Array",
".",
"prototype",
".",
"slice",
".",
"call",
"(",
"context",
".",
"querySelectorAll",
"(",
"selector",
")",
")",
"}",
"}",
"else",
"{",
"nodes",
"=",
"selector",
"}",
"return",
"new",
"DOMQuery",
"(",
"nodes",
",",
"context",
")",
"}"
] |
Initialization helper. This method is this module's exported entry point.
@param {string|Array|Element} selector - css selector, one element, array of nodes or html fragment
@param {node} [context=document] - context node in which to query
@returns {DOMQuery} A DOMQuery instance containing the selected set of nodes
|
[
"Initialization",
"helper",
".",
"This",
"method",
"is",
"this",
"module",
"s",
"exported",
"entry",
"point",
"."
] |
1a4a3e2f30ccd0b16581750df3abd82b4e013566
|
https://github.com/heiseonline/shariff/blob/1a4a3e2f30ccd0b16581750df3abd82b4e013566/src/js/dom.js#L35-L56
|
17,774
|
heiseonline/shariff
|
src/js/dom.js
|
DOMQuery
|
function DOMQuery(elements, context) {
this.length = elements.length
this.context = context
var self = this
each(elements, function(i) { self[i] = this })
}
|
javascript
|
function DOMQuery(elements, context) {
this.length = elements.length
this.context = context
var self = this
each(elements, function(i) { self[i] = this })
}
|
[
"function",
"DOMQuery",
"(",
"elements",
",",
"context",
")",
"{",
"this",
".",
"length",
"=",
"elements",
".",
"length",
"this",
".",
"context",
"=",
"context",
"var",
"self",
"=",
"this",
"each",
"(",
"elements",
",",
"function",
"(",
"i",
")",
"{",
"self",
"[",
"i",
"]",
"=",
"this",
"}",
")",
"}"
] |
Contains a set of DOM nodes and provides methods to manipulate the nodes.
@constructor
|
[
"Contains",
"a",
"set",
"of",
"DOM",
"nodes",
"and",
"provides",
"methods",
"to",
"manipulate",
"the",
"nodes",
"."
] |
1a4a3e2f30ccd0b16581750df3abd82b4e013566
|
https://github.com/heiseonline/shariff/blob/1a4a3e2f30ccd0b16581750df3abd82b4e013566/src/js/dom.js#L62-L67
|
17,775
|
heiseonline/shariff
|
src/js/dom.js
|
function (parent, nodes) {
for (var i = nodes.length - 1; i >= 0; i--) {
parent.insertBefore(nodes[nodes.length - 1], parent.firstChild)
}
}
|
javascript
|
function (parent, nodes) {
for (var i = nodes.length - 1; i >= 0; i--) {
parent.insertBefore(nodes[nodes.length - 1], parent.firstChild)
}
}
|
[
"function",
"(",
"parent",
",",
"nodes",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"nodes",
".",
"length",
"-",
"1",
";",
"i",
">=",
"0",
";",
"i",
"--",
")",
"{",
"parent",
".",
"insertBefore",
"(",
"nodes",
"[",
"nodes",
".",
"length",
"-",
"1",
"]",
",",
"parent",
".",
"firstChild",
")",
"}",
"}"
] |
Prepends an array of nodes to the top of an HTML element.
@param {Element} parent - Element to prepend to
@param {Array} nodes - Collection of nodes to prepend
@private
|
[
"Prepends",
"an",
"array",
"of",
"nodes",
"to",
"the",
"top",
"of",
"an",
"HTML",
"element",
"."
] |
1a4a3e2f30ccd0b16581750df3abd82b4e013566
|
https://github.com/heiseonline/shariff/blob/1a4a3e2f30ccd0b16581750df3abd82b4e013566/src/js/dom.js#L316-L320
|
|
17,776
|
heiseonline/shariff
|
src/js/dom.js
|
function (selector, event, handler, scope) {
(scope || document).addEventListener(event, function(event) {
var listeningTarget = closest(event.target, selector)
if (listeningTarget) {
handler.call(listeningTarget, event)
}
})
}
|
javascript
|
function (selector, event, handler, scope) {
(scope || document).addEventListener(event, function(event) {
var listeningTarget = closest(event.target, selector)
if (listeningTarget) {
handler.call(listeningTarget, event)
}
})
}
|
[
"function",
"(",
"selector",
",",
"event",
",",
"handler",
",",
"scope",
")",
"{",
"(",
"scope",
"||",
"document",
")",
".",
"addEventListener",
"(",
"event",
",",
"function",
"(",
"event",
")",
"{",
"var",
"listeningTarget",
"=",
"closest",
"(",
"event",
".",
"target",
",",
"selector",
")",
"if",
"(",
"listeningTarget",
")",
"{",
"handler",
".",
"call",
"(",
"listeningTarget",
",",
"event",
")",
"}",
"}",
")",
"}"
] |
An event handler.
@callback eventHandler
@param {Event} event - The event this handler was triggered for
Delegates an event for a node matching a selector.
@param {string} selector - The CSS selector
@param {string} event - The event name
@param {eventHandler} handler - The event handler function
@param {HTMLElement} [scope=document] - Element to add the event listener to
@private
|
[
"An",
"event",
"handler",
"."
] |
1a4a3e2f30ccd0b16581750df3abd82b4e013566
|
https://github.com/heiseonline/shariff/blob/1a4a3e2f30ccd0b16581750df3abd82b4e013566/src/js/dom.js#L360-L367
|
|
17,777
|
heiseonline/shariff
|
src/js/dom.js
|
function (value) {
/* jshint maxcomplexity:7 */
// boolean
if (value === 'true') { return true }
if (value === 'false') { return false }
// null
if (value === 'null') { return null }
// number
if (+value + '' === value) { return +value }
// json
if (/^[[{]/.test(value)) {
try {
return JSON.parse(value)
} catch (e) {
return value
}
}
// everything else
return value
}
|
javascript
|
function (value) {
/* jshint maxcomplexity:7 */
// boolean
if (value === 'true') { return true }
if (value === 'false') { return false }
// null
if (value === 'null') { return null }
// number
if (+value + '' === value) { return +value }
// json
if (/^[[{]/.test(value)) {
try {
return JSON.parse(value)
} catch (e) {
return value
}
}
// everything else
return value
}
|
[
"function",
"(",
"value",
")",
"{",
"/* jshint maxcomplexity:7 */",
"// boolean",
"if",
"(",
"value",
"===",
"'true'",
")",
"{",
"return",
"true",
"}",
"if",
"(",
"value",
"===",
"'false'",
")",
"{",
"return",
"false",
"}",
"// null",
"if",
"(",
"value",
"===",
"'null'",
")",
"{",
"return",
"null",
"}",
"// number",
"if",
"(",
"+",
"value",
"+",
"''",
"===",
"value",
")",
"{",
"return",
"+",
"value",
"}",
"// json",
"if",
"(",
"/",
"^[[{]",
"/",
".",
"test",
"(",
"value",
")",
")",
"{",
"try",
"{",
"return",
"JSON",
".",
"parse",
"(",
"value",
")",
"}",
"catch",
"(",
"e",
")",
"{",
"return",
"value",
"}",
"}",
"// everything else",
"return",
"value",
"}"
] |
Deserializes JSON values from strings. Used with data attributes.
@param {string} value - String to parse
@returns {Object}
@private
|
[
"Deserializes",
"JSON",
"values",
"from",
"strings",
".",
"Used",
"with",
"data",
"attributes",
"."
] |
1a4a3e2f30ccd0b16581750df3abd82b4e013566
|
https://github.com/heiseonline/shariff/blob/1a4a3e2f30ccd0b16581750df3abd82b4e013566/src/js/dom.js#L458-L477
|
|
17,778
|
Rosey/markdown-draft-js
|
src/draft-to-markdown.js
|
draftToMarkdown
|
function draftToMarkdown(rawDraftObject, options) {
options = options || {};
var markdownString = '';
rawDraftObject.blocks.forEach(function (block, index) {
markdownString += renderBlock(block, index, rawDraftObject, options);
});
orderedListNumber = {}; // See variable definitions at the top of the page to see why we have to do this sad hack.
return markdownString;
}
|
javascript
|
function draftToMarkdown(rawDraftObject, options) {
options = options || {};
var markdownString = '';
rawDraftObject.blocks.forEach(function (block, index) {
markdownString += renderBlock(block, index, rawDraftObject, options);
});
orderedListNumber = {}; // See variable definitions at the top of the page to see why we have to do this sad hack.
return markdownString;
}
|
[
"function",
"draftToMarkdown",
"(",
"rawDraftObject",
",",
"options",
")",
"{",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"var",
"markdownString",
"=",
"''",
";",
"rawDraftObject",
".",
"blocks",
".",
"forEach",
"(",
"function",
"(",
"block",
",",
"index",
")",
"{",
"markdownString",
"+=",
"renderBlock",
"(",
"block",
",",
"index",
",",
"rawDraftObject",
",",
"options",
")",
";",
"}",
")",
";",
"orderedListNumber",
"=",
"{",
"}",
";",
"// See variable definitions at the top of the page to see why we have to do this sad hack.",
"return",
"markdownString",
";",
"}"
] |
Generate markdown for a raw draftjs object
DraftJS raw object contains an array of blocks, which is the main "structure"
of the text. Each block = a new line.
@param {Object} rawDraftObject - draftjs object to generate markdown for
@param {Object} options - optional additional data, see readme for what options can be passed in.
@return {String} markdown string
|
[
"Generate",
"markdown",
"for",
"a",
"raw",
"draftjs",
"object",
"DraftJS",
"raw",
"object",
"contains",
"an",
"array",
"of",
"blocks",
"which",
"is",
"the",
"main",
"structure",
"of",
"the",
"text",
".",
"Each",
"block",
"=",
"a",
"new",
"line",
"."
] |
8d415755fec9edad1fc9d8b531fbc7aff4436f2a
|
https://github.com/Rosey/markdown-draft-js/blob/8d415755fec9edad1fc9d8b531fbc7aff4436f2a/src/draft-to-markdown.js#L488-L497
|
17,779
|
stylus/nib
|
lib/nodes/gradient.js
|
Gradient
|
function Gradient(size, start) {
this.size = size;
this.canvas = new Canvas(1, 1);
this.setStartPosition(start);
this.ctx = this.canvas.getContext('2d');
this.grad = this.ctx.createLinearGradient(
this.from[0], this.from[1],
this.to[0], this.to[1]);
}
|
javascript
|
function Gradient(size, start) {
this.size = size;
this.canvas = new Canvas(1, 1);
this.setStartPosition(start);
this.ctx = this.canvas.getContext('2d');
this.grad = this.ctx.createLinearGradient(
this.from[0], this.from[1],
this.to[0], this.to[1]);
}
|
[
"function",
"Gradient",
"(",
"size",
",",
"start",
")",
"{",
"this",
".",
"size",
"=",
"size",
";",
"this",
".",
"canvas",
"=",
"new",
"Canvas",
"(",
"1",
",",
"1",
")",
";",
"this",
".",
"setStartPosition",
"(",
"start",
")",
";",
"this",
".",
"ctx",
"=",
"this",
".",
"canvas",
".",
"getContext",
"(",
"'2d'",
")",
";",
"this",
".",
"grad",
"=",
"this",
".",
"ctx",
".",
"createLinearGradient",
"(",
"this",
".",
"from",
"[",
"0",
"]",
",",
"this",
".",
"from",
"[",
"1",
"]",
",",
"this",
".",
"to",
"[",
"0",
"]",
",",
"this",
".",
"to",
"[",
"1",
"]",
")",
";",
"}"
] |
Initialize a new `Gradient` node with the given `size`
and `start` position.
@param {Number} size
@param {String} start
@api private
|
[
"Initialize",
"a",
"new",
"Gradient",
"node",
"with",
"the",
"given",
"size",
"and",
"start",
"position",
"."
] |
5ba7db7768e4668044c0d4d94585559d8f73a6ac
|
https://github.com/stylus/nib/blob/5ba7db7768e4668044c0d4d94585559d8f73a6ac/lib/nodes/gradient.js#L72-L80
|
17,780
|
stylus/nib
|
lib/nodes/vendor-helpers.js
|
normalize
|
function normalize(property, value, prefix){
var result = value.toString(),
args;
/* Fixing the gradients */
if (~result.indexOf('gradient(')) {
/* Normalize color stops */
result = result.replace(RE_GRADIENT_STOPS,'$1$4$3$2');
/* Normalize legacy gradients */
result = result.replace(RE_GRADIENT_VAL, function(){
args = [].slice.call(arguments, 1);
return normalizeGradient(args, prefix);
});
/* Adding prefixes to the legacy gradients */
if (prefix) result = result.replace(RE_GRADIENT_TYPE, '-' + prefix + '-$1');
}
/* Adding prefixes to the `transform` values of legacy `transition` property */
if (prefix && (property == "'transition'" || property == "'transition-property'")) {
result = result.replace(RE_TRANSFORM, '-' + prefix + '-$1');
}
/* Removing `fill` keyword from the legacy `border-image` property */
if (prefix && (property == "'border-image'" || property == "'border-image-slice'")) {
result = result.replace(RE_FILL_KEYWORD, ' ');
}
return result;
}
|
javascript
|
function normalize(property, value, prefix){
var result = value.toString(),
args;
/* Fixing the gradients */
if (~result.indexOf('gradient(')) {
/* Normalize color stops */
result = result.replace(RE_GRADIENT_STOPS,'$1$4$3$2');
/* Normalize legacy gradients */
result = result.replace(RE_GRADIENT_VAL, function(){
args = [].slice.call(arguments, 1);
return normalizeGradient(args, prefix);
});
/* Adding prefixes to the legacy gradients */
if (prefix) result = result.replace(RE_GRADIENT_TYPE, '-' + prefix + '-$1');
}
/* Adding prefixes to the `transform` values of legacy `transition` property */
if (prefix && (property == "'transition'" || property == "'transition-property'")) {
result = result.replace(RE_TRANSFORM, '-' + prefix + '-$1');
}
/* Removing `fill` keyword from the legacy `border-image` property */
if (prefix && (property == "'border-image'" || property == "'border-image-slice'")) {
result = result.replace(RE_FILL_KEYWORD, ' ');
}
return result;
}
|
[
"function",
"normalize",
"(",
"property",
",",
"value",
",",
"prefix",
")",
"{",
"var",
"result",
"=",
"value",
".",
"toString",
"(",
")",
",",
"args",
";",
"/* Fixing the gradients */",
"if",
"(",
"~",
"result",
".",
"indexOf",
"(",
"'gradient('",
")",
")",
"{",
"/* Normalize color stops */",
"result",
"=",
"result",
".",
"replace",
"(",
"RE_GRADIENT_STOPS",
",",
"'$1$4$3$2'",
")",
";",
"/* Normalize legacy gradients */",
"result",
"=",
"result",
".",
"replace",
"(",
"RE_GRADIENT_VAL",
",",
"function",
"(",
")",
"{",
"args",
"=",
"[",
"]",
".",
"slice",
".",
"call",
"(",
"arguments",
",",
"1",
")",
";",
"return",
"normalizeGradient",
"(",
"args",
",",
"prefix",
")",
";",
"}",
")",
";",
"/* Adding prefixes to the legacy gradients */",
"if",
"(",
"prefix",
")",
"result",
"=",
"result",
".",
"replace",
"(",
"RE_GRADIENT_TYPE",
",",
"'-'",
"+",
"prefix",
"+",
"'-$1'",
")",
";",
"}",
"/* Adding prefixes to the `transform` values of legacy `transition` property */",
"if",
"(",
"prefix",
"&&",
"(",
"property",
"==",
"\"'transition'\"",
"||",
"property",
"==",
"\"'transition-property'\"",
")",
")",
"{",
"result",
"=",
"result",
".",
"replace",
"(",
"RE_TRANSFORM",
",",
"'-'",
"+",
"prefix",
"+",
"'-$1'",
")",
";",
"}",
"/* Removing `fill` keyword from the legacy `border-image` property */",
"if",
"(",
"prefix",
"&&",
"(",
"property",
"==",
"\"'border-image'\"",
"||",
"property",
"==",
"\"'border-image-slice'\"",
")",
")",
"{",
"result",
"=",
"result",
".",
"replace",
"(",
"RE_FILL_KEYWORD",
",",
"' '",
")",
";",
"}",
"return",
"result",
";",
"}"
] |
Expose `normalize`.
|
[
"Expose",
"normalize",
"."
] |
5ba7db7768e4668044c0d4d94585559d8f73a6ac
|
https://github.com/stylus/nib/blob/5ba7db7768e4668044c0d4d94585559d8f73a6ac/lib/nodes/vendor-helpers.js#L13-L44
|
17,781
|
stylus/nib
|
lib/nodes/color-image.js
|
ColorImage
|
function ColorImage(color) {
this.color = color;
this.canvas = new Canvas(1, 1);
this.ctx = this.canvas.getContext('2d');
this.ctx.fillStyle = color.toString();
this.ctx.fillRect(0, 0, 1, 1);
}
|
javascript
|
function ColorImage(color) {
this.color = color;
this.canvas = new Canvas(1, 1);
this.ctx = this.canvas.getContext('2d');
this.ctx.fillStyle = color.toString();
this.ctx.fillRect(0, 0, 1, 1);
}
|
[
"function",
"ColorImage",
"(",
"color",
")",
"{",
"this",
".",
"color",
"=",
"color",
";",
"this",
".",
"canvas",
"=",
"new",
"Canvas",
"(",
"1",
",",
"1",
")",
";",
"this",
".",
"ctx",
"=",
"this",
".",
"canvas",
".",
"getContext",
"(",
"'2d'",
")",
";",
"this",
".",
"ctx",
".",
"fillStyle",
"=",
"color",
".",
"toString",
"(",
")",
";",
"this",
".",
"ctx",
".",
"fillRect",
"(",
"0",
",",
"0",
",",
"1",
",",
"1",
")",
";",
"}"
] |
Initialize a new `ColorImage` node with the given arguments.
@param {Color} color node
@api private
|
[
"Initialize",
"a",
"new",
"ColorImage",
"node",
"with",
"the",
"given",
"arguments",
"."
] |
5ba7db7768e4668044c0d4d94585559d8f73a6ac
|
https://github.com/stylus/nib/blob/5ba7db7768e4668044c0d4d94585559d8f73a6ac/lib/nodes/color-image.js#L49-L55
|
17,782
|
paypal/react-engine
|
lib/util.js
|
clearRequireCacheInDir
|
function clearRequireCacheInDir(dir, extension) {
var options = {
cwd: dir
};
// find all files with the `extension` in the express view directory
// and clean them out of require's cache.
var files = glob.sync('**/*.' + extension, options);
files.map(function(file) {
clearRequireCache(dir + path.sep + (file.split(/\\|\//g).join(path.sep)));
});
}
|
javascript
|
function clearRequireCacheInDir(dir, extension) {
var options = {
cwd: dir
};
// find all files with the `extension` in the express view directory
// and clean them out of require's cache.
var files = glob.sync('**/*.' + extension, options);
files.map(function(file) {
clearRequireCache(dir + path.sep + (file.split(/\\|\//g).join(path.sep)));
});
}
|
[
"function",
"clearRequireCacheInDir",
"(",
"dir",
",",
"extension",
")",
"{",
"var",
"options",
"=",
"{",
"cwd",
":",
"dir",
"}",
";",
"// find all files with the `extension` in the express view directory",
"// and clean them out of require's cache.",
"var",
"files",
"=",
"glob",
".",
"sync",
"(",
"'**/*.'",
"+",
"extension",
",",
"options",
")",
";",
"files",
".",
"map",
"(",
"function",
"(",
"file",
")",
"{",
"clearRequireCache",
"(",
"dir",
"+",
"path",
".",
"sep",
"+",
"(",
"file",
".",
"split",
"(",
"/",
"\\\\|\\/",
"/",
"g",
")",
".",
"join",
"(",
"path",
".",
"sep",
")",
")",
")",
";",
"}",
")",
";",
"}"
] |
clears require cache of files that have extension `extension` from a given directory `dir`.
|
[
"clears",
"require",
"cache",
"of",
"files",
"that",
"have",
"extension",
"extension",
"from",
"a",
"given",
"directory",
"dir",
"."
] |
96e371cb5e2484dbe637492f7aa218127fd0ca06
|
https://github.com/paypal/react-engine/blob/96e371cb5e2484dbe637492f7aa218127fd0ca06/lib/util.js#L30-L43
|
17,783
|
paypal/react-engine
|
lib/client.js
|
function(component) {
if (options.reduxStoreInitiator && isFunction(options.reduxStoreInitiator)) {
var initStore = options.reduxStoreInitiator;
if (initStore.default) {
initStore = initStore.default;
}
var store = initStore(props);
var Provider = require('react-redux').Provider;
return React.createElement(Provider, { store: store }, component);
} else {
return component;
}
}
|
javascript
|
function(component) {
if (options.reduxStoreInitiator && isFunction(options.reduxStoreInitiator)) {
var initStore = options.reduxStoreInitiator;
if (initStore.default) {
initStore = initStore.default;
}
var store = initStore(props);
var Provider = require('react-redux').Provider;
return React.createElement(Provider, { store: store }, component);
} else {
return component;
}
}
|
[
"function",
"(",
"component",
")",
"{",
"if",
"(",
"options",
".",
"reduxStoreInitiator",
"&&",
"isFunction",
"(",
"options",
".",
"reduxStoreInitiator",
")",
")",
"{",
"var",
"initStore",
"=",
"options",
".",
"reduxStoreInitiator",
";",
"if",
"(",
"initStore",
".",
"default",
")",
"{",
"initStore",
"=",
"initStore",
".",
"default",
";",
"}",
"var",
"store",
"=",
"initStore",
"(",
"props",
")",
";",
"var",
"Provider",
"=",
"require",
"(",
"'react-redux'",
")",
".",
"Provider",
";",
"return",
"React",
".",
"createElement",
"(",
"Provider",
",",
"{",
"store",
":",
"store",
"}",
",",
"component",
")",
";",
"}",
"else",
"{",
"return",
"component",
";",
"}",
"}"
] |
wrap component with react-redux Proivder if redux is required
|
[
"wrap",
"component",
"with",
"react",
"-",
"redux",
"Proivder",
"if",
"redux",
"is",
"required"
] |
96e371cb5e2484dbe637492f7aa218127fd0ca06
|
https://github.com/paypal/react-engine/blob/96e371cb5e2484dbe637492f7aa218127fd0ca06/lib/client.js#L76-L88
|
|
17,784
|
simonlast/node-persist
|
src/node-persist.js
|
mixin
|
function mixin (target, source, options) {
options = options || {};
options.skip = options.skip || [];
for (let key in source) {
if (typeof source[key] === 'function' && key.indexOf('_') !== 0 && options.skip.indexOf(key) === -1) {
target[key] = source[key].bind(source);
}
}
}
|
javascript
|
function mixin (target, source, options) {
options = options || {};
options.skip = options.skip || [];
for (let key in source) {
if (typeof source[key] === 'function' && key.indexOf('_') !== 0 && options.skip.indexOf(key) === -1) {
target[key] = source[key].bind(source);
}
}
}
|
[
"function",
"mixin",
"(",
"target",
",",
"source",
",",
"options",
")",
"{",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"options",
".",
"skip",
"=",
"options",
".",
"skip",
"||",
"[",
"]",
";",
"for",
"(",
"let",
"key",
"in",
"source",
")",
"{",
"if",
"(",
"typeof",
"source",
"[",
"key",
"]",
"===",
"'function'",
"&&",
"key",
".",
"indexOf",
"(",
"'_'",
")",
"!==",
"0",
"&&",
"options",
".",
"skip",
".",
"indexOf",
"(",
"key",
")",
"===",
"-",
"1",
")",
"{",
"target",
"[",
"key",
"]",
"=",
"source",
"[",
"key",
"]",
".",
"bind",
"(",
"source",
")",
";",
"}",
"}",
"}"
] |
expose all the API methods on the main module using a default instance
|
[
"expose",
"all",
"the",
"API",
"methods",
"on",
"the",
"main",
"module",
"using",
"a",
"default",
"instance"
] |
065eadd3a96f342b1d2e70f8cff5038ad657d3b7
|
https://github.com/simonlast/node-persist/blob/065eadd3a96f342b1d2e70f8cff5038ad657d3b7/src/node-persist.js#L31-L39
|
17,785
|
jaredhanson/electrolyte
|
lib/errors/interfacenotfound.js
|
InterfaceNotFoundError
|
function InterfaceNotFoundError(message, iface) {
Error.call(this);
Error.captureStackTrace(this, arguments.callee);
this.message = message;
this.code = 'INTERFACE_NOT_FOUND';
this.interface = iface;
}
|
javascript
|
function InterfaceNotFoundError(message, iface) {
Error.call(this);
Error.captureStackTrace(this, arguments.callee);
this.message = message;
this.code = 'INTERFACE_NOT_FOUND';
this.interface = iface;
}
|
[
"function",
"InterfaceNotFoundError",
"(",
"message",
",",
"iface",
")",
"{",
"Error",
".",
"call",
"(",
"this",
")",
";",
"Error",
".",
"captureStackTrace",
"(",
"this",
",",
"arguments",
".",
"callee",
")",
";",
"this",
".",
"message",
"=",
"message",
";",
"this",
".",
"code",
"=",
"'INTERFACE_NOT_FOUND'",
";",
"this",
".",
"interface",
"=",
"iface",
";",
"}"
] |
`InterfaceNotFoundError` error.
@api public
|
[
"InterfaceNotFoundError",
"error",
"."
] |
3ab5c374095eaa68366386b5734b9397aa4f8c69
|
https://github.com/jaredhanson/electrolyte/blob/3ab5c374095eaa68366386b5734b9397aa4f8c69/lib/errors/interfacenotfound.js#L6-L12
|
17,786
|
jaredhanson/electrolyte
|
lib/injectedcontainer.js
|
InjectedContainer
|
function InjectedContainer(c, parent) {
var pasm = parent ? parent._assembly : undefined;
this._c = c;
this._parent = parent;
this._ns = (pasm && pasm.namespace) || '';
}
|
javascript
|
function InjectedContainer(c, parent) {
var pasm = parent ? parent._assembly : undefined;
this._c = c;
this._parent = parent;
this._ns = (pasm && pasm.namespace) || '';
}
|
[
"function",
"InjectedContainer",
"(",
"c",
",",
"parent",
")",
"{",
"var",
"pasm",
"=",
"parent",
"?",
"parent",
".",
"_assembly",
":",
"undefined",
";",
"this",
".",
"_c",
"=",
"c",
";",
"this",
".",
"_parent",
"=",
"parent",
";",
"this",
".",
"_ns",
"=",
"(",
"pasm",
"&&",
"pasm",
".",
"namespace",
")",
"||",
"''",
";",
"}"
] |
Container wrapper used when injected into a factory.
When a factory requires that the container itself be injected, the
container is first wrapped. This wrapper provides an interface that can be
used by the factory to introspect its environment, which is useful when
loading plugins, among other functionality. The wrapper also restricts
inadvertent use of other functionality in the wrapped container.
Note that requiring an injected container makes the requiring object
dependent on the IoC runtime's existence. The need to couple the object to
the runtime should be carefully considered, and avoided if an alternative
approach is possible.
@constructor
@api private
|
[
"Container",
"wrapper",
"used",
"when",
"injected",
"into",
"a",
"factory",
"."
] |
3ab5c374095eaa68366386b5734b9397aa4f8c69
|
https://github.com/jaredhanson/electrolyte/blob/3ab5c374095eaa68366386b5734b9397aa4f8c69/lib/injectedcontainer.js#L23-L29
|
17,787
|
jaredhanson/electrolyte
|
lib/patterns/literal.js
|
LiteralComponent
|
function LiteralComponent(id, obj, asm) {
Component.call(this, id, obj, asm);
this._instance = obj;
}
|
javascript
|
function LiteralComponent(id, obj, asm) {
Component.call(this, id, obj, asm);
this._instance = obj;
}
|
[
"function",
"LiteralComponent",
"(",
"id",
",",
"obj",
",",
"asm",
")",
"{",
"Component",
".",
"call",
"(",
"this",
",",
"id",
",",
"obj",
",",
"asm",
")",
";",
"this",
".",
"_instance",
"=",
"obj",
";",
"}"
] |
A component that is an object literal.
A literal is returned directly when created by the IoC container.
Due to the nature of being a literal, no dependencies are injected and only
a single instance of the object will be created.
If a module exports a primitive type (object, string, number, etc.), the IoC
container will automatically detect it as a literal. If the module exports
a function which is to be treated as a literal, the `@literal` annotation
must be set to `true`. Otherwise, the default behavior will be to treat the
function as a factory.
@constructor
@param {string} id - The id of the component.
@param {object} obj - The module containing the literal object.
@param {number} asm - The assembly from which the component was loaded.
@protected
|
[
"A",
"component",
"that",
"is",
"an",
"object",
"literal",
"."
] |
3ab5c374095eaa68366386b5734b9397aa4f8c69
|
https://github.com/jaredhanson/electrolyte/blob/3ab5c374095eaa68366386b5734b9397aa4f8c69/lib/patterns/literal.js#L26-L29
|
17,788
|
jaredhanson/electrolyte
|
lib/patterns/factory.js
|
FactoryComponent
|
function FactoryComponent(id, fn, asm) {
Component.call(this, id, fn, asm);
this._fn = fn;
}
|
javascript
|
function FactoryComponent(id, fn, asm) {
Component.call(this, id, fn, asm);
this._fn = fn;
}
|
[
"function",
"FactoryComponent",
"(",
"id",
",",
"fn",
",",
"asm",
")",
"{",
"Component",
".",
"call",
"(",
"this",
",",
"id",
",",
"fn",
",",
"asm",
")",
";",
"this",
".",
"_fn",
"=",
"fn",
";",
"}"
] |
A component created using a factory function.
Objects will be created by calling the factory function with any required
dependencies and returning the result.
@constructor
@param {string} id - The id of the component.
@param {object} fn - The module containing the object factory.
@param {number} asm - The assembly from which the component was loaded.
@protected
|
[
"A",
"component",
"created",
"using",
"a",
"factory",
"function",
"."
] |
3ab5c374095eaa68366386b5734b9397aa4f8c69
|
https://github.com/jaredhanson/electrolyte/blob/3ab5c374095eaa68366386b5734b9397aa4f8c69/lib/patterns/factory.js#L19-L22
|
17,789
|
jaredhanson/electrolyte
|
lib/errors/componentnotfound.js
|
ComponentNotFoundError
|
function ComponentNotFoundError(message) {
Error.call(this);
Error.captureStackTrace(this, arguments.callee);
this.message = message;
this.code = 'COMPONENT_NOT_FOUND';
}
|
javascript
|
function ComponentNotFoundError(message) {
Error.call(this);
Error.captureStackTrace(this, arguments.callee);
this.message = message;
this.code = 'COMPONENT_NOT_FOUND';
}
|
[
"function",
"ComponentNotFoundError",
"(",
"message",
")",
"{",
"Error",
".",
"call",
"(",
"this",
")",
";",
"Error",
".",
"captureStackTrace",
"(",
"this",
",",
"arguments",
".",
"callee",
")",
";",
"this",
".",
"message",
"=",
"message",
";",
"this",
".",
"code",
"=",
"'COMPONENT_NOT_FOUND'",
";",
"}"
] |
`ComponentNotFoundError` error.
@api public
|
[
"ComponentNotFoundError",
"error",
"."
] |
3ab5c374095eaa68366386b5734b9397aa4f8c69
|
https://github.com/jaredhanson/electrolyte/blob/3ab5c374095eaa68366386b5734b9397aa4f8c69/lib/errors/componentnotfound.js#L6-L11
|
17,790
|
jaredhanson/electrolyte
|
lib/errors/componentcreate.js
|
ComponentCreateError
|
function ComponentCreateError(message) {
Error.call(this);
Error.captureStackTrace(this, arguments.callee);
this.message = message;
this.code = 'COMPONENT_CREATE_ERROR';
}
|
javascript
|
function ComponentCreateError(message) {
Error.call(this);
Error.captureStackTrace(this, arguments.callee);
this.message = message;
this.code = 'COMPONENT_CREATE_ERROR';
}
|
[
"function",
"ComponentCreateError",
"(",
"message",
")",
"{",
"Error",
".",
"call",
"(",
"this",
")",
";",
"Error",
".",
"captureStackTrace",
"(",
"this",
",",
"arguments",
".",
"callee",
")",
";",
"this",
".",
"message",
"=",
"message",
";",
"this",
".",
"code",
"=",
"'COMPONENT_CREATE_ERROR'",
";",
"}"
] |
`ComponentCreateError` error.
@api public
|
[
"ComponentCreateError",
"error",
"."
] |
3ab5c374095eaa68366386b5734b9397aa4f8c69
|
https://github.com/jaredhanson/electrolyte/blob/3ab5c374095eaa68366386b5734b9397aa4f8c69/lib/errors/componentcreate.js#L6-L11
|
17,791
|
jaredhanson/electrolyte
|
lib/patterns/constructor.js
|
ConstructorComponent
|
function ConstructorComponent(id, ctor, hs) {
Component.call(this, id, ctor, hs);
this._ctor = ctor;
}
|
javascript
|
function ConstructorComponent(id, ctor, hs) {
Component.call(this, id, ctor, hs);
this._ctor = ctor;
}
|
[
"function",
"ConstructorComponent",
"(",
"id",
",",
"ctor",
",",
"hs",
")",
"{",
"Component",
".",
"call",
"(",
"this",
",",
"id",
",",
"ctor",
",",
"hs",
")",
";",
"this",
".",
"_ctor",
"=",
"ctor",
";",
"}"
] |
A component created using a constructor.
Objects will be created by applying the `new` operator to the constructor
with any required dependencies and returning the result.
@constructor
@param {string} id - The id of the component.
@param {object} mod - The module containing the object constructor.
@param {number} asm - The assembly from which the component was loaded.
@protected
|
[
"A",
"component",
"created",
"using",
"a",
"constructor",
"."
] |
3ab5c374095eaa68366386b5734b9397aa4f8c69
|
https://github.com/jaredhanson/electrolyte/blob/3ab5c374095eaa68366386b5734b9397aa4f8c69/lib/patterns/constructor.js#L19-L22
|
17,792
|
jaredhanson/electrolyte
|
lib/component.js
|
Component
|
function Component(id, mod, asm) {
var keys, i, len;
this.id = id;
this.dependencies = mod['@require'] || [];
this.singleton = mod['@singleton'];
this.implements = mod['@implements'] || [];
if (typeof this.implements == 'string') {
this.implements = [ this.implements ]
}
this.a = {};
if (typeof mod === 'object' || typeof mod === 'function') {
keys = Object.keys(mod);
for (i = 0, len = keys.length; i < len; ++i) {
if (keys[i].indexOf('@') == 0) {
this.a[keys[i]] = mod[keys[i]];
}
}
}
this._assembly = asm;
}
|
javascript
|
function Component(id, mod, asm) {
var keys, i, len;
this.id = id;
this.dependencies = mod['@require'] || [];
this.singleton = mod['@singleton'];
this.implements = mod['@implements'] || [];
if (typeof this.implements == 'string') {
this.implements = [ this.implements ]
}
this.a = {};
if (typeof mod === 'object' || typeof mod === 'function') {
keys = Object.keys(mod);
for (i = 0, len = keys.length; i < len; ++i) {
if (keys[i].indexOf('@') == 0) {
this.a[keys[i]] = mod[keys[i]];
}
}
}
this._assembly = asm;
}
|
[
"function",
"Component",
"(",
"id",
",",
"mod",
",",
"asm",
")",
"{",
"var",
"keys",
",",
"i",
",",
"len",
";",
"this",
".",
"id",
"=",
"id",
";",
"this",
".",
"dependencies",
"=",
"mod",
"[",
"'@require'",
"]",
"||",
"[",
"]",
";",
"this",
".",
"singleton",
"=",
"mod",
"[",
"'@singleton'",
"]",
";",
"this",
".",
"implements",
"=",
"mod",
"[",
"'@implements'",
"]",
"||",
"[",
"]",
";",
"if",
"(",
"typeof",
"this",
".",
"implements",
"==",
"'string'",
")",
"{",
"this",
".",
"implements",
"=",
"[",
"this",
".",
"implements",
"]",
"}",
"this",
".",
"a",
"=",
"{",
"}",
";",
"if",
"(",
"typeof",
"mod",
"===",
"'object'",
"||",
"typeof",
"mod",
"===",
"'function'",
")",
"{",
"keys",
"=",
"Object",
".",
"keys",
"(",
"mod",
")",
";",
"for",
"(",
"i",
"=",
"0",
",",
"len",
"=",
"keys",
".",
"length",
";",
"i",
"<",
"len",
";",
"++",
"i",
")",
"{",
"if",
"(",
"keys",
"[",
"i",
"]",
".",
"indexOf",
"(",
"'@'",
")",
"==",
"0",
")",
"{",
"this",
".",
"a",
"[",
"keys",
"[",
"i",
"]",
"]",
"=",
"mod",
"[",
"keys",
"[",
"i",
"]",
"]",
";",
"}",
"}",
"}",
"this",
".",
"_assembly",
"=",
"asm",
";",
"}"
] |
A specification of an object.
A specification defines how an object is created. The specification includes
a "factory" which is used to create objects. A factory is typically a
function which returns the object or a constructor that is invoked with the
`new` operator. A specification also declares any objects required by the
object. Any such required objects will be injected into the object when it
is created.
A specification also contains annotations, which are used by the IoC
container when creating an object. These annotations are:
- `@require` - Declares other objects needed by this object.
- `@singleton` - Declares whether or not a single instance of this object
should be created.
- `@implements` - Declares the interfaces implemented by this object.
A specification may contain other annotations, and the complete set of
annotations is available under the `.a` hash (short for annotations). Such
annotations are typically used by higher-level frameworks for purposes such
as declaring service endpoints and loading plug-ins.
@constructor
@param {string} id - The id of the component.
@param {object} mod - The module containing the component specification.
@param {number} asm - The assembly from which the component was loaded.
@protected
|
[
"A",
"specification",
"of",
"an",
"object",
"."
] |
3ab5c374095eaa68366386b5734b9397aa4f8c69
|
https://github.com/jaredhanson/electrolyte/blob/3ab5c374095eaa68366386b5734b9397aa4f8c69/lib/component.js#L36-L57
|
17,793
|
gulpjs/vinyl-fs
|
lib/dest/write-contents/index.js
|
onWritten
|
function onWritten(writeErr) {
var flags = fo.getFlags({
overwrite: optResolver.resolve('overwrite', file),
append: optResolver.resolve('append', file),
});
if (fo.isFatalOverwriteError(writeErr, flags)) {
return callback(writeErr);
}
callback(null, file);
}
|
javascript
|
function onWritten(writeErr) {
var flags = fo.getFlags({
overwrite: optResolver.resolve('overwrite', file),
append: optResolver.resolve('append', file),
});
if (fo.isFatalOverwriteError(writeErr, flags)) {
return callback(writeErr);
}
callback(null, file);
}
|
[
"function",
"onWritten",
"(",
"writeErr",
")",
"{",
"var",
"flags",
"=",
"fo",
".",
"getFlags",
"(",
"{",
"overwrite",
":",
"optResolver",
".",
"resolve",
"(",
"'overwrite'",
",",
"file",
")",
",",
"append",
":",
"optResolver",
".",
"resolve",
"(",
"'append'",
",",
"file",
")",
",",
"}",
")",
";",
"if",
"(",
"fo",
".",
"isFatalOverwriteError",
"(",
"writeErr",
",",
"flags",
")",
")",
"{",
"return",
"callback",
"(",
"writeErr",
")",
";",
"}",
"callback",
"(",
"null",
",",
"file",
")",
";",
"}"
] |
This is invoked by the various writeXxx modules when they've finished writing the contents.
|
[
"This",
"is",
"invoked",
"by",
"the",
"various",
"writeXxx",
"modules",
"when",
"they",
"ve",
"finished",
"writing",
"the",
"contents",
"."
] |
5a5234694627276eae80d228e3b0d29e11376a89
|
https://github.com/gulpjs/vinyl-fs/blob/5a5234694627276eae80d228e3b0d29e11376a89/lib/dest/write-contents/index.js#L42-L52
|
17,794
|
sroze/ngInfiniteScroll
|
src/infinite-scroll.js
|
defaultHandler
|
function defaultHandler() {
let containerBottom;
let elementBottom;
if (container === windowElement) {
containerBottom = height(container) + pageYOffset(container[0].document.documentElement);
elementBottom = offsetTop(elem) + height(elem);
} else {
containerBottom = height(container);
let containerTopOffset = 0;
if (offsetTop(container) !== undefined) {
containerTopOffset = offsetTop(container);
}
elementBottom = (offsetTop(elem) - containerTopOffset) + height(elem);
}
if (useDocumentBottom) {
elementBottom = height((elem[0].ownerDocument || elem[0].document).documentElement);
}
const remaining = elementBottom - containerBottom;
const shouldScroll = remaining <= (height(container) * scrollDistance) + 1;
if (shouldScroll) {
checkWhenEnabled = true;
if (scrollEnabled) {
if (scope.$$phase || $rootScope.$$phase) {
scope.infiniteScroll();
} else {
scope.$apply(scope.infiniteScroll);
}
}
} else {
if (checkInterval) { $interval.cancel(checkInterval); }
checkWhenEnabled = false;
}
}
|
javascript
|
function defaultHandler() {
let containerBottom;
let elementBottom;
if (container === windowElement) {
containerBottom = height(container) + pageYOffset(container[0].document.documentElement);
elementBottom = offsetTop(elem) + height(elem);
} else {
containerBottom = height(container);
let containerTopOffset = 0;
if (offsetTop(container) !== undefined) {
containerTopOffset = offsetTop(container);
}
elementBottom = (offsetTop(elem) - containerTopOffset) + height(elem);
}
if (useDocumentBottom) {
elementBottom = height((elem[0].ownerDocument || elem[0].document).documentElement);
}
const remaining = elementBottom - containerBottom;
const shouldScroll = remaining <= (height(container) * scrollDistance) + 1;
if (shouldScroll) {
checkWhenEnabled = true;
if (scrollEnabled) {
if (scope.$$phase || $rootScope.$$phase) {
scope.infiniteScroll();
} else {
scope.$apply(scope.infiniteScroll);
}
}
} else {
if (checkInterval) { $interval.cancel(checkInterval); }
checkWhenEnabled = false;
}
}
|
[
"function",
"defaultHandler",
"(",
")",
"{",
"let",
"containerBottom",
";",
"let",
"elementBottom",
";",
"if",
"(",
"container",
"===",
"windowElement",
")",
"{",
"containerBottom",
"=",
"height",
"(",
"container",
")",
"+",
"pageYOffset",
"(",
"container",
"[",
"0",
"]",
".",
"document",
".",
"documentElement",
")",
";",
"elementBottom",
"=",
"offsetTop",
"(",
"elem",
")",
"+",
"height",
"(",
"elem",
")",
";",
"}",
"else",
"{",
"containerBottom",
"=",
"height",
"(",
"container",
")",
";",
"let",
"containerTopOffset",
"=",
"0",
";",
"if",
"(",
"offsetTop",
"(",
"container",
")",
"!==",
"undefined",
")",
"{",
"containerTopOffset",
"=",
"offsetTop",
"(",
"container",
")",
";",
"}",
"elementBottom",
"=",
"(",
"offsetTop",
"(",
"elem",
")",
"-",
"containerTopOffset",
")",
"+",
"height",
"(",
"elem",
")",
";",
"}",
"if",
"(",
"useDocumentBottom",
")",
"{",
"elementBottom",
"=",
"height",
"(",
"(",
"elem",
"[",
"0",
"]",
".",
"ownerDocument",
"||",
"elem",
"[",
"0",
"]",
".",
"document",
")",
".",
"documentElement",
")",
";",
"}",
"const",
"remaining",
"=",
"elementBottom",
"-",
"containerBottom",
";",
"const",
"shouldScroll",
"=",
"remaining",
"<=",
"(",
"height",
"(",
"container",
")",
"*",
"scrollDistance",
")",
"+",
"1",
";",
"if",
"(",
"shouldScroll",
")",
"{",
"checkWhenEnabled",
"=",
"true",
";",
"if",
"(",
"scrollEnabled",
")",
"{",
"if",
"(",
"scope",
".",
"$$phase",
"||",
"$rootScope",
".",
"$$phase",
")",
"{",
"scope",
".",
"infiniteScroll",
"(",
")",
";",
"}",
"else",
"{",
"scope",
".",
"$apply",
"(",
"scope",
".",
"infiniteScroll",
")",
";",
"}",
"}",
"}",
"else",
"{",
"if",
"(",
"checkInterval",
")",
"{",
"$interval",
".",
"cancel",
"(",
"checkInterval",
")",
";",
"}",
"checkWhenEnabled",
"=",
"false",
";",
"}",
"}"
] |
infinite-scroll specifies a function to call when the window, or some other container specified by infinite-scroll-container, is scrolled within a certain range from the bottom of the document. It is recommended to use infinite-scroll-disabled with a boolean that is set to true when the function is called in order to throttle the function call.
|
[
"infinite",
"-",
"scroll",
"specifies",
"a",
"function",
"to",
"call",
"when",
"the",
"window",
"or",
"some",
"other",
"container",
"specified",
"by",
"infinite",
"-",
"scroll",
"-",
"container",
"is",
"scrolled",
"within",
"a",
"certain",
"range",
"from",
"the",
"bottom",
"of",
"the",
"document",
".",
"It",
"is",
"recommended",
"to",
"use",
"infinite",
"-",
"scroll",
"-",
"disabled",
"with",
"a",
"boolean",
"that",
"is",
"set",
"to",
"true",
"when",
"the",
"function",
"is",
"called",
"in",
"order",
"to",
"throttle",
"the",
"function",
"call",
"."
] |
5035fd2d563eb09447bc500e5b754b21fbd3b92c
|
https://github.com/sroze/ngInfiniteScroll/blob/5035fd2d563eb09447bc500e5b754b21fbd3b92c/src/infinite-scroll.js#L63-L99
|
17,795
|
sroze/ngInfiniteScroll
|
src/infinite-scroll.js
|
throttle
|
function throttle(func, wait) {
let timeout = null;
let previous = 0;
function later() {
previous = new Date().getTime();
$interval.cancel(timeout);
timeout = null;
return func.call();
}
function throttled() {
const now = new Date().getTime();
const remaining = wait - (now - previous);
if (remaining <= 0) {
$interval.cancel(timeout);
timeout = null;
previous = now;
func.call();
} else if (!timeout) {
timeout = $interval(later, remaining, 1);
}
}
return throttled;
}
|
javascript
|
function throttle(func, wait) {
let timeout = null;
let previous = 0;
function later() {
previous = new Date().getTime();
$interval.cancel(timeout);
timeout = null;
return func.call();
}
function throttled() {
const now = new Date().getTime();
const remaining = wait - (now - previous);
if (remaining <= 0) {
$interval.cancel(timeout);
timeout = null;
previous = now;
func.call();
} else if (!timeout) {
timeout = $interval(later, remaining, 1);
}
}
return throttled;
}
|
[
"function",
"throttle",
"(",
"func",
",",
"wait",
")",
"{",
"let",
"timeout",
"=",
"null",
";",
"let",
"previous",
"=",
"0",
";",
"function",
"later",
"(",
")",
"{",
"previous",
"=",
"new",
"Date",
"(",
")",
".",
"getTime",
"(",
")",
";",
"$interval",
".",
"cancel",
"(",
"timeout",
")",
";",
"timeout",
"=",
"null",
";",
"return",
"func",
".",
"call",
"(",
")",
";",
"}",
"function",
"throttled",
"(",
")",
"{",
"const",
"now",
"=",
"new",
"Date",
"(",
")",
".",
"getTime",
"(",
")",
";",
"const",
"remaining",
"=",
"wait",
"-",
"(",
"now",
"-",
"previous",
")",
";",
"if",
"(",
"remaining",
"<=",
"0",
")",
"{",
"$interval",
".",
"cancel",
"(",
"timeout",
")",
";",
"timeout",
"=",
"null",
";",
"previous",
"=",
"now",
";",
"func",
".",
"call",
"(",
")",
";",
"}",
"else",
"if",
"(",
"!",
"timeout",
")",
"{",
"timeout",
"=",
"$interval",
"(",
"later",
",",
"remaining",
",",
"1",
")",
";",
"}",
"}",
"return",
"throttled",
";",
"}"
] |
The optional THROTTLE_MILLISECONDS configuration value specifies a minimum time that should elapse between each call to the handler. N.b. the first call the handler will be run immediately, and the final call will always result in the handler being called after the `wait` period elapses. A slimmed down version of underscore's implementation.
|
[
"The",
"optional",
"THROTTLE_MILLISECONDS",
"configuration",
"value",
"specifies",
"a",
"minimum",
"time",
"that",
"should",
"elapse",
"between",
"each",
"call",
"to",
"the",
"handler",
".",
"N",
".",
"b",
".",
"the",
"first",
"call",
"the",
"handler",
"will",
"be",
"run",
"immediately",
"and",
"the",
"final",
"call",
"will",
"always",
"result",
"in",
"the",
"handler",
"being",
"called",
"after",
"the",
"wait",
"period",
"elapses",
".",
"A",
"slimmed",
"down",
"version",
"of",
"underscore",
"s",
"implementation",
"."
] |
5035fd2d563eb09447bc500e5b754b21fbd3b92c
|
https://github.com/sroze/ngInfiniteScroll/blob/5035fd2d563eb09447bc500e5b754b21fbd3b92c/src/infinite-scroll.js#L107-L132
|
17,796
|
sroze/ngInfiniteScroll
|
src/infinite-scroll.js
|
changeContainer
|
function changeContainer(newContainer) {
if (container != null) {
container.unbind('scroll', handler);
}
container = newContainer;
if (newContainer != null) {
container.bind('scroll', handler);
}
}
|
javascript
|
function changeContainer(newContainer) {
if (container != null) {
container.unbind('scroll', handler);
}
container = newContainer;
if (newContainer != null) {
container.bind('scroll', handler);
}
}
|
[
"function",
"changeContainer",
"(",
"newContainer",
")",
"{",
"if",
"(",
"container",
"!=",
"null",
")",
"{",
"container",
".",
"unbind",
"(",
"'scroll'",
",",
"handler",
")",
";",
"}",
"container",
"=",
"newContainer",
";",
"if",
"(",
"newContainer",
"!=",
"null",
")",
"{",
"container",
".",
"bind",
"(",
"'scroll'",
",",
"handler",
")",
";",
"}",
"}"
] |
infinite-scroll-container sets the container which we want to be infinte scrolled, instead of the whole window. Must be an Angular or jQuery element, or, if jQuery is loaded, a jQuery selector as a string.
|
[
"infinite",
"-",
"scroll",
"-",
"container",
"sets",
"the",
"container",
"which",
"we",
"want",
"to",
"be",
"infinte",
"scrolled",
"instead",
"of",
"the",
"whole",
"window",
".",
"Must",
"be",
"an",
"Angular",
"or",
"jQuery",
"element",
"or",
"if",
"jQuery",
"is",
"loaded",
"a",
"jQuery",
"selector",
"as",
"a",
"string",
"."
] |
5035fd2d563eb09447bc500e5b754b21fbd3b92c
|
https://github.com/sroze/ngInfiniteScroll/blob/5035fd2d563eb09447bc500e5b754b21fbd3b92c/src/infinite-scroll.js#L196-L205
|
17,797
|
networked-aframe/networked-aframe
|
src/components/networked-scene.js
|
function () {
NAF.log.setDebug(this.data.debug);
NAF.log.write('Networked-Aframe Connecting...');
this.checkDeprecatedProperties();
this.setupNetworkAdapter();
if (this.hasOnConnectFunction()) {
this.callOnConnect();
}
return NAF.connection.connect(this.data.serverURL, this.data.app, this.data.room, this.data.audio);
}
|
javascript
|
function () {
NAF.log.setDebug(this.data.debug);
NAF.log.write('Networked-Aframe Connecting...');
this.checkDeprecatedProperties();
this.setupNetworkAdapter();
if (this.hasOnConnectFunction()) {
this.callOnConnect();
}
return NAF.connection.connect(this.data.serverURL, this.data.app, this.data.room, this.data.audio);
}
|
[
"function",
"(",
")",
"{",
"NAF",
".",
"log",
".",
"setDebug",
"(",
"this",
".",
"data",
".",
"debug",
")",
";",
"NAF",
".",
"log",
".",
"write",
"(",
"'Networked-Aframe Connecting...'",
")",
";",
"this",
".",
"checkDeprecatedProperties",
"(",
")",
";",
"this",
".",
"setupNetworkAdapter",
"(",
")",
";",
"if",
"(",
"this",
".",
"hasOnConnectFunction",
"(",
")",
")",
"{",
"this",
".",
"callOnConnect",
"(",
")",
";",
"}",
"return",
"NAF",
".",
"connection",
".",
"connect",
"(",
"this",
".",
"data",
".",
"serverURL",
",",
"this",
".",
"data",
".",
"app",
",",
"this",
".",
"data",
".",
"room",
",",
"this",
".",
"data",
".",
"audio",
")",
";",
"}"
] |
Connect to signalling server and begin connecting to other clients
|
[
"Connect",
"to",
"signalling",
"server",
"and",
"begin",
"connecting",
"to",
"other",
"clients"
] |
b0ece8ba80479fa6912969fa03bc4cf3f30c4026
|
https://github.com/networked-aframe/networked-aframe/blob/b0ece8ba80479fa6912969fa03bc4cf3f30c4026/src/components/networked-scene.js#L27-L38
|
|
17,798
|
numbers/numbers.js
|
lib/numbers/calculus.js
|
SimpsonDef
|
function SimpsonDef(func, a, b) {
var c = (a + b) / 2;
var d = Math.abs(b - a) / 6;
return d * (func(a) + 4 * func(c) + func(b));
}
|
javascript
|
function SimpsonDef(func, a, b) {
var c = (a + b) / 2;
var d = Math.abs(b - a) / 6;
return d * (func(a) + 4 * func(c) + func(b));
}
|
[
"function",
"SimpsonDef",
"(",
"func",
",",
"a",
",",
"b",
")",
"{",
"var",
"c",
"=",
"(",
"a",
"+",
"b",
")",
"/",
"2",
";",
"var",
"d",
"=",
"Math",
".",
"abs",
"(",
"b",
"-",
"a",
")",
"/",
"6",
";",
"return",
"d",
"*",
"(",
"func",
"(",
"a",
")",
"+",
"4",
"*",
"func",
"(",
"c",
")",
"+",
"func",
"(",
"b",
")",
")",
";",
"}"
] |
Helper function in calculating integral of a function
from a to b using simpson quadrature.
@param {Function} math function to be evaluated.
@param {Number} point to initiate evaluation.
@param {Number} point to complete evaluation.
@return {Number} evaluation.
|
[
"Helper",
"function",
"in",
"calculating",
"integral",
"of",
"a",
"function",
"from",
"a",
"to",
"b",
"using",
"simpson",
"quadrature",
"."
] |
ca3076a7bfc670a5c45bb18ade9c3a868363bcc3
|
https://github.com/numbers/numbers.js/blob/ca3076a7bfc670a5c45bb18ade9c3a868363bcc3/lib/numbers/calculus.js#L79-L83
|
17,799
|
numbers/numbers.js
|
lib/numbers/calculus.js
|
SimpsonRecursive
|
function SimpsonRecursive(func, a, b, whole, eps) {
var c = a + b;
var left = SimpsonDef(func, a, c);
var right = SimpsonDef(func, c, b);
if (Math.abs(left + right - whole) <= 15 * eps) {
return left + right + (left + right - whole) / 15;
} else {
return SimpsonRecursive(func, a, c, eps / 2, left) + SimpsonRecursive(func, c, b, eps / 2, right);
}
}
|
javascript
|
function SimpsonRecursive(func, a, b, whole, eps) {
var c = a + b;
var left = SimpsonDef(func, a, c);
var right = SimpsonDef(func, c, b);
if (Math.abs(left + right - whole) <= 15 * eps) {
return left + right + (left + right - whole) / 15;
} else {
return SimpsonRecursive(func, a, c, eps / 2, left) + SimpsonRecursive(func, c, b, eps / 2, right);
}
}
|
[
"function",
"SimpsonRecursive",
"(",
"func",
",",
"a",
",",
"b",
",",
"whole",
",",
"eps",
")",
"{",
"var",
"c",
"=",
"a",
"+",
"b",
";",
"var",
"left",
"=",
"SimpsonDef",
"(",
"func",
",",
"a",
",",
"c",
")",
";",
"var",
"right",
"=",
"SimpsonDef",
"(",
"func",
",",
"c",
",",
"b",
")",
";",
"if",
"(",
"Math",
".",
"abs",
"(",
"left",
"+",
"right",
"-",
"whole",
")",
"<=",
"15",
"*",
"eps",
")",
"{",
"return",
"left",
"+",
"right",
"+",
"(",
"left",
"+",
"right",
"-",
"whole",
")",
"/",
"15",
";",
"}",
"else",
"{",
"return",
"SimpsonRecursive",
"(",
"func",
",",
"a",
",",
"c",
",",
"eps",
"/",
"2",
",",
"left",
")",
"+",
"SimpsonRecursive",
"(",
"func",
",",
"c",
",",
"b",
",",
"eps",
"/",
"2",
",",
"right",
")",
";",
"}",
"}"
] |
Helper function in calculating integral of a function
from a to b using simpson quadrature. Manages recursive
investigation, handling evaluations within an error bound.
@param {Function} math function to be evaluated.
@param {Number} point to initiate evaluation.
@param {Number} point to complete evaluation.
@param {Number} total value.
@param {Number} Error bound (epsilon).
@return {Number} recursive evaluation of left and right side.
|
[
"Helper",
"function",
"in",
"calculating",
"integral",
"of",
"a",
"function",
"from",
"a",
"to",
"b",
"using",
"simpson",
"quadrature",
".",
"Manages",
"recursive",
"investigation",
"handling",
"evaluations",
"within",
"an",
"error",
"bound",
"."
] |
ca3076a7bfc670a5c45bb18ade9c3a868363bcc3
|
https://github.com/numbers/numbers.js/blob/ca3076a7bfc670a5c45bb18ade9c3a868363bcc3/lib/numbers/calculus.js#L97-L107
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.