/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * 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/. */
void PerformanceObserver::Notify() { if (mQueuedEntries.IsEmpty()) { return;
}
RefPtr<PerformanceObserverEntryList> list = new PerformanceObserverEntryList(this, mQueuedEntries);
if (!mPerformance || !mOwner) {
aRv.Throw(NS_ERROR_FAILURE); return;
}
if (!maybeEntryTypes.WasPassed() && !maybeType.WasPassed()) { /* Per spec (3.3.1.2), this should be a syntax error. */
aRv.ThrowTypeError("Can't call observe without `type` or `entryTypes`"); return;
}
if (maybeEntryTypes.WasPassed() && maybeType.WasPassed()) { /* Per spec (3.3.1.3), this, too, should be a syntax error. */ /* * As per the spec we also need to throw a type error if there are both * `entryTypes` and `buffered` options, but either Blink or WebKit doesn't * throw the error so we don't throw to align the behavior with them. * https://github.com/w3c/performance-timeline/issues/215
*/
aRv.ThrowTypeError("Can't call observe with both `type` and `entryTypes`"); return;
}
if (StaticPrefs::dom_enable_event_timing()) { for (const nsLiteralString& name : kValidEventTimingNames) { if (entryTypes.Contains(name) && !validEntryTypes.Contains(name)) {
validEntryTypes.AppendElement(name);
}
}
} if (StaticPrefs::dom_enable_largest_contentful_paint()) { if (entryTypes.Contains(kLargestContentfulPaintName) &&
!validEntryTypes.Contains(kLargestContentfulPaintName)) {
validEntryTypes.AppendElement(kLargestContentfulPaintName);
}
} for (const nsLiteralString& name : kValidTypeNames) { if (entryTypes.Contains(name) && !validEntryTypes.Contains(name)) {
validEntryTypes.AppendElement(name);
}
}
nsAutoString invalidTypesJoined; bool addComma = false; for (constauto& type : entryTypes) { if (!validEntryTypes.Contains<nsString>(type)) { if (addComma) {
invalidTypesJoined.AppendLiteral(", ");
}
addComma = true;
invalidTypesJoined.Append(type);
}
}
if (!invalidTypesJoined.IsEmpty()) {
AutoTArray<nsString, 1> params = {invalidTypesJoined};
mOwner->ReportToConsole(nsIScriptError::warningFlag, "DOM"_ns,
nsContentUtils::eDOM_PROPERTIES, "UnsupportedEntryTypesIgnored"_ns, params); // (we don't return because we're ignoring and we keep going)
}
/* * Registered or not, we clear out the list of options, and start fresh * with the one that we are using here. (3.3.1.5.4,5)
*/
mOptions.Clear();
mOptions.AppendElement(aOptions);
if (StaticPrefs::dom_enable_event_timing()) { for (const nsLiteralString& name : kValidEventTimingNames) {
validTypes.AppendElement(name);
}
}
if (StaticPrefs::dom_enable_largest_contentful_paint()) {
validTypes.AppendElement(u"largest-contentful-paint"_ns);
} for (const nsLiteralString& name : kValidTypeNames) {
validTypes.AppendElement(name);
}
if (!ToJSValue(aGlobal.Context(), validTypes, &val)) { /* * If this conversion fails, we don't set a result. * The spec does not allow us to throw an exception.
*/ return;
}
aObject.set(&val.toObject());
}
bool PerformanceObserver::ObservesTypeOfEntry(PerformanceEntry* aEntry) { for (auto& option : mOptions) { if (aEntry->ShouldAddEntryToObserverBuffer(option)) { returntrue;
}
} returnfalse;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.