Bug 1054630 - Collect telemetry on usage of SpiderMonkey's deprecated language extensions: for-each, destructuring for-in, legacy generators, and expression closures. r=till

This commit is contained in:
Chris Peterson 2014-08-24 11:56:08 -07:00
Родитель 66519af00d
Коммит 0059278e60
7 изменённых файлов: 84 добавлений и 6 удалений

Просмотреть файл

@ -2,6 +2,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
const SEARCH_ENGINES = {
"Google": {
// This is the "2x" image designed for OS X retina resolution, Windows at 192dpi, etc.;
@ -269,13 +271,13 @@ function ensureSnippetsMapThen(aCallback)
// The cache has been filled up, create the snippets map.
gSnippetsMap = Object.freeze({
get: function (aKey) cache.get(aKey),
get: (aKey) => cache.get(aKey),
set: function (aKey, aValue) {
db.transaction(SNIPPETS_OBJECTSTORE_NAME, "readwrite")
.objectStore(SNIPPETS_OBJECTSTORE_NAME).put(aValue, aKey);
return cache.set(aKey, aValue);
},
has: function (aKey) cache.has(aKey),
has: (aKey) => cache.has(aKey),
delete: function (aKey) {
db.transaction(SNIPPETS_OBJECTSTORE_NAME, "readwrite")
.objectStore(SNIPPETS_OBJECTSTORE_NAME).delete(aKey);
@ -286,7 +288,7 @@ function ensureSnippetsMapThen(aCallback)
.objectStore(SNIPPETS_OBJECTSTORE_NAME).clear();
return cache.clear();
},
get size() cache.size
get size() { return cache.size; },
});
setTimeout(invokeCallbacks, 0);

Просмотреть файл

@ -712,7 +712,7 @@
ontextreverted="return this.handleRevert();"
pageproxystate="invalid"
onfocus="document.getElementById('identity-box').style.MozUserFocus= 'normal'"
onblur="setTimeout(function() document.getElementById('identity-box').style.MozUserFocus = '', 0);">
onblur="setTimeout(() => { document.getElementById('identity-box').style.MozUserFocus = ''; }, 0);">
<box id="notification-popup-box" hidden="true" align="center">
<image id="default-notification-icon" class="notification-anchor-icon" role="button"/>
<image id="identity-notification-icon" class="notification-anchor-icon" role="button"/>

Просмотреть файл

@ -430,6 +430,10 @@ Parser<ParseHandler>::Parser(ExclusiveContext *cx, LifoAlloc *alloc,
foldConstants(foldConstants),
abortedSyntaxParse(false),
isUnexpectedEOF_(false),
sawDeprecatedForEach(false),
sawDeprecatedDestructuringForIn(false),
sawDeprecatedLegacyGenerator(false),
sawDeprecatedExpressionClosure(false),
handler(cx, *alloc, tokenStream, foldConstants, syntaxParser, lazyOuterFunction)
{
{
@ -449,6 +453,8 @@ Parser<ParseHandler>::Parser(ExclusiveContext *cx, LifoAlloc *alloc,
template <typename ParseHandler>
Parser<ParseHandler>::~Parser()
{
accumulateTelemetry();
alloc.release(tempPoolMark);
/*
@ -2259,6 +2265,10 @@ Parser<ParseHandler>::functionArgsAndBodyGeneric(Node pn, HandleFunction fun, Fu
report(ParseError, false, null(), JSMSG_CURLY_BEFORE_BODY);
return false;
}
if (kind != Arrow)
sawDeprecatedExpressionClosure = true;
tokenStream.ungetToken();
bodyType = ExpressionBody;
fun->setIsExprClosure();
@ -4083,6 +4093,7 @@ Parser<FullParseHandler>::forStatement()
if (allowsForEachIn() && tokenStream.matchContextualKeyword(context->names().each)) {
iflags = JSITER_FOREACH;
isForEach = true;
sawDeprecatedForEach = true;
}
MUST_MATCH_TOKEN(TOK_LP, JSMSG_PAREN_AFTER_FOR);
@ -4300,8 +4311,10 @@ Parser<FullParseHandler>::forStatement()
* Destructuring for-in requires [key, value] enumeration
* in JS1.7.
*/
if (!isForEach && headKind == PNK_FORIN)
if (!isForEach && headKind == PNK_FORIN) {
iflags |= JSITER_FOREACH | JSITER_KEYVALUE;
sawDeprecatedDestructuringForIn = true;
}
}
break;
@ -4803,6 +4816,7 @@ Parser<ParseHandler>::yieldExpression()
}
pc->sc->asFunctionBox()->setGeneratorKind(LegacyGenerator);
sawDeprecatedLegacyGenerator = true;
if (pc->funHasReturnExpr) {
/* As in Python (see PEP-255), disallow return v; in generators. */
@ -7573,6 +7587,47 @@ Parser<ParseHandler>::exprInParens()
return pn;
}
template <typename ParseHandler>
void
Parser<ParseHandler>::accumulateTelemetry()
{
JSContext* cx = context->maybeJSContext();
if (!cx)
return;
JSAccumulateTelemetryDataCallback cb = cx->runtime()->telemetryCallback;
if (!cb)
return;
const char* filename = getFilename();
if (!filename)
return;
bool isHTTP = strncmp(filename, "http://", 7) == 0 || strncmp(filename, "https://", 8) == 0;
// Only report telemetry for web content, not add-ons or chrome JS.
if (!isHTTP)
return;
enum DeprecatedLanguageExtensions {
DeprecatedForEach = 0, // JS 1.6+
DeprecatedDestructuringForIn = 1, // JS 1.7 only
DeprecatedLegacyGenerator = 2, // JS 1.7+
DeprecatedExpressionClosure = 3, // Added in JS 1.8, but not version-gated
};
// Hazard analysis can't tell that the telemetry callbacks don't GC.
JS::AutoSuppressGCAnalysis nogc;
// Call back into Firefox's Telemetry reporter.
if (sawDeprecatedForEach)
(*cb)(JS_TELEMETRY_DEPRECATED_LANGUAGE_EXTENSIONS_IN_CONTENT, DeprecatedForEach);
if (sawDeprecatedDestructuringForIn)
(*cb)(JS_TELEMETRY_DEPRECATED_LANGUAGE_EXTENSIONS_IN_CONTENT, DeprecatedDestructuringForIn);
if (sawDeprecatedLegacyGenerator)
(*cb)(JS_TELEMETRY_DEPRECATED_LANGUAGE_EXTENSIONS_IN_CONTENT, DeprecatedLegacyGenerator);
if (sawDeprecatedExpressionClosure)
(*cb)(JS_TELEMETRY_DEPRECATED_LANGUAGE_EXTENSIONS_IN_CONTENT, DeprecatedExpressionClosure);
}
template class Parser<FullParseHandler>;
template class Parser<SyntaxParseHandler>;

Просмотреть файл

@ -350,6 +350,12 @@ class Parser : private JS::AutoGCRooter, public StrictModeGetter
/* Unexpected end of input, i.e. TOK_EOF not at top-level. */
bool isUnexpectedEOF_:1;
/* Used for collecting telemetry on SpiderMonkey's deprecated language extensions. */
bool sawDeprecatedForEach:1;
bool sawDeprecatedDestructuringForIn:1;
bool sawDeprecatedLegacyGenerator:1;
bool sawDeprecatedExpressionClosure:1;
typedef typename ParseHandler::Node Node;
typedef typename ParseHandler::DefinitionNode DefinitionNode;
@ -658,6 +664,8 @@ class Parser : private JS::AutoGCRooter, public StrictModeGetter
bool asmJS(Node list);
void accumulateTelemetry();
friend class LegacyCompExprTransplanter;
friend struct BindData<ParseHandler>;
};

Просмотреть файл

@ -119,7 +119,8 @@ enum {
JS_TELEMETRY_GC_INCREMENTAL_DISABLED,
JS_TELEMETRY_GC_NON_INCREMENTAL,
JS_TELEMETRY_GC_SCC_SWEEP_TOTAL_MS,
JS_TELEMETRY_GC_SCC_SWEEP_MAX_PAUSE_MS
JS_TELEMETRY_GC_SCC_SWEEP_MAX_PAUSE_MS,
JS_TELEMETRY_DEPRECATED_LANGUAGE_EXTENSIONS_IN_CONTENT
};
typedef void

Просмотреть файл

@ -2929,6 +2929,12 @@ AccumulateTelemetryCallback(int id, uint32_t sample)
case JS_TELEMETRY_GC_SCC_SWEEP_MAX_PAUSE_MS:
Telemetry::Accumulate(Telemetry::GC_SCC_SWEEP_MAX_PAUSE_MS, sample);
break;
case JS_TELEMETRY_DEPRECATED_LANGUAGE_EXTENSIONS_IN_CONTENT:
MOZ_ASSERT(sample <= 3);
Telemetry::Accumulate(Telemetry::JS_DEPRECATED_LANGUAGE_EXTENSIONS_IN_CONTENT, sample);
break;
default:
MOZ_ASSERT_UNREACHABLE("Unexpected JS_TELEMETRY id");
}
}

Просмотреть файл

@ -318,6 +318,12 @@
"kind": "flag",
"description": "Has seen location error"
},
"JS_DEPRECATED_LANGUAGE_EXTENSIONS_IN_CONTENT": {
"expires_in_version": "never",
"kind": "enumerated",
"n_values": 10,
"description": "Use of SpiderMonkey's deprecated language extensions in web content: ForEach, DestructuringForIn, LegacyGenerator, ExpressionClosure"
},
"TELEMETRY_PING": {
"expires_in_version": "never",
"kind": "exponential",