Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
Backed out changeset e04ef5171459 (bug 1539006) for permafailing test…
Browse files Browse the repository at this point in the history
…_worker_observer.html CLOSED TREE
  • Loading branch information
SV-ACiure committed Apr 9, 2019
1 parent ded477a commit 80e7286
Show file tree
Hide file tree
Showing 14 changed files with 136 additions and 242 deletions.
2 changes: 0 additions & 2 deletions dom/locales/en-US/chrome/dom/dom.properties
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,6 @@ AmbientLightEventWarning=Use of the ambient light sensor is deprecated.
IDBOpenDBOptions_StorageTypeWarning=The ‘storage’ attribute in options passed to indexedDB.open is deprecated and will soon be removed. To get persistent storage, please use navigator.storage.persist() instead.
DOMQuadBoundsAttrWarning=DOMQuad.bounds is deprecated in favor of DOMQuad.getBounds()
UnsupportedEntryTypesIgnored=Ignoring unsupported entryTypes: %S.
# LOCALIZATION NOTE: Do not use a period at the end of the sentence. It is embedded in a string that already contains a period.
NoValidEntryTypes=No valid entry types; aborting registration

#LOCALIZATION NOTE(DeprecatedTestingInterfaceWarning): Do not translate this message. It's just testing only.
DeprecatedTestingInterfaceWarning=TestingDeprecatedInterface is a testing-only interface and this is its testing deprecation message.
Expand Down
19 changes: 2 additions & 17 deletions dom/performance/Performance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -596,23 +596,8 @@ void Performance::QueueEntry(PerformanceEntry* aEntry) {
if (mObservers.IsEmpty()) {
return;
}

nsTObserverArray<PerformanceObserver*> interestedObservers;
nsTObserverArray<PerformanceObserver*>::ForwardIterator observerIt(
mObservers);
while (observerIt.HasMore()) {
PerformanceObserver* observer = observerIt.GetNext();
if (observer->ObservesTypeOfEntry(aEntry)) {
interestedObservers.AppendElement(observer);
}
}

if (interestedObservers.IsEmpty()) {
return;
}

NS_OBSERVER_ARRAY_NOTIFY_XPCOM_OBSERVERS(
interestedObservers, PerformanceObserver, QueueEntry, (aEntry));
NS_OBSERVER_ARRAY_NOTIFY_XPCOM_OBSERVERS(mObservers, PerformanceObserver,
QueueEntry, (aEntry));

if (!mPendingNotificationObserversTask) {
RunNotificationObserversTask();
Expand Down
228 changes: 47 additions & 181 deletions dom/performance/PerformanceObserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,14 @@ NS_INTERFACE_MAP_END

PerformanceObserver::PerformanceObserver(nsPIDOMWindowInner* aOwner,
PerformanceObserverCallback& aCb)
: mOwner(aOwner),
mCallback(&aCb),
mObserverType(ObserverTypeUndefined),
mConnected(false) {
: mOwner(aOwner), mCallback(&aCb), mConnected(false) {
MOZ_ASSERT(mOwner);
mPerformance = aOwner->GetPerformance();
}

PerformanceObserver::PerformanceObserver(WorkerPrivate* aWorkerPrivate,
PerformanceObserverCallback& aCb)
: mCallback(&aCb), mObserverType(ObserverTypeUndefined), mConnected(false) {
: mCallback(&aCb), mConnected(false) {
MOZ_ASSERT(aWorkerPrivate);
mPerformance = aWorkerPrivate->GlobalScope()->GetPerformance();
}
Expand Down Expand Up @@ -119,216 +116,85 @@ void PerformanceObserver::Notify() {
void PerformanceObserver::QueueEntry(PerformanceEntry* aEntry) {
MOZ_ASSERT(aEntry);

if (!ObservesTypeOfEntry(aEntry)) {
nsAutoString entryType;
aEntry->GetEntryType(entryType);
if (!mEntryTypes.Contains<nsString>(entryType)) {
return;
}

mQueuedEntries.AppendElement(aEntry);
}

/*
* Keep this list in alphabetical order.
* https://w3c.github.io/performance-timeline/#supportedentrytypes-attribute
*/
static const char16_t* const sValidTypeNames[4] = {
u"navigation",
u"mark",
u"measure",
u"navigation",
u"resource",
};

void PerformanceObserver::ReportUnsupportedTypesErrorToConsole(
bool aIsMainThread, const nsString& aInvalidTypes) {
if (aIsMainThread) {
nsTArray<nsString> params;
params.AppendElement(aInvalidTypes);
WorkerPrivate::ReportErrorToConsole("UnsupportedEntryTypesIgnored", params);
} else {
nsCOMPtr<nsPIDOMWindowInner> ownerWindow = do_QueryInterface(mOwner);
Document* document = ownerWindow->GetExtantDoc();
const char16_t* params[] = {aInvalidTypes.get()};
nsContentUtils::ReportToConsole(nsIScriptError::warningFlag,
NS_LITERAL_CSTRING("DOM"), document,
nsContentUtils::eDOM_PROPERTIES,
"UnsupportedEntryTypesIgnored", params, 1);
void PerformanceObserver::Observe(const PerformanceObserverInit& aOptions) {
if (aOptions.mEntryTypes.IsEmpty()) {
return;
}
return;
}

void PerformanceObserver::Observe(const PerformanceObserverInit& aOptions,
ErrorResult& aRv) {
const Optional<Sequence<nsString>>& maybeEntryTypes = aOptions.mEntryTypes;
const Optional<nsString>& maybeType = aOptions.mType;
const Optional<bool>& maybeBuffered = aOptions.mBuffered;
nsTArray<nsString> validEntryTypes;

if (!maybeEntryTypes.WasPassed() && !maybeType.WasPassed()) {
/* Per spec (3.3.1.2), this should be a syntax error. */
aRv.Throw(NS_ERROR_DOM_SYNTAX_ERR);
return;
for (const char16_t* name : sValidTypeNames) {
nsDependentString validTypeName(name);
if (aOptions.mEntryTypes.Contains<nsString>(validTypeName) &&
!validEntryTypes.Contains<nsString>(validTypeName)) {
validEntryTypes.AppendElement(validTypeName);
}
}

if (maybeEntryTypes.WasPassed() &&
(maybeType.WasPassed() || maybeBuffered.WasPassed())) {
/* Per spec (3.3.1.3), this, too, should be a syntax error. */
aRv.Throw(NS_ERROR_DOM_SYNTAX_ERR);
return;
nsAutoString invalidTypesJoined;
bool addComma = false;
for (const auto& type : aOptions.mEntryTypes) {
if (!validEntryTypes.Contains<nsString>(type)) {
if (addComma) {
invalidTypesJoined.AppendLiteral(", ");
}
addComma = true;
invalidTypesJoined.Append(type);
}
}

/* 3.3.1.4.1 */
if (mObserverType == ObserverTypeUndefined) {
if (maybeEntryTypes.WasPassed()) {
mObserverType = ObserverTypeMultiple;
if (!invalidTypesJoined.IsEmpty()) {
if (!NS_IsMainThread()) {
nsTArray<nsString> params;
params.AppendElement(invalidTypesJoined);
WorkerPrivate::ReportErrorToConsole("UnsupportedEntryTypesIgnored",
params);
} else {
mObserverType = ObserverTypeSingle;
nsCOMPtr<nsPIDOMWindowInner> ownerWindow = do_QueryInterface(mOwner);
Document* document = ownerWindow->GetExtantDoc();
const char16_t* params[] = {invalidTypesJoined.get()};
nsContentUtils::ReportToConsole(
nsIScriptError::warningFlag, NS_LITERAL_CSTRING("DOM"), document,
nsContentUtils::eDOM_PROPERTIES, "UnsupportedEntryTypesIgnored",
params, 1);
}
}

/* 3.3.1.4.2 */
if (mObserverType == ObserverTypeSingle && maybeEntryTypes.WasPassed()) {
aRv.Throw(NS_ERROR_DOM_INVALID_MODIFICATION_ERR);
return;
}
/* 3.3.1.4.3 */
if (mObserverType == ObserverTypeMultiple && maybeType.WasPassed()) {
aRv.Throw(NS_ERROR_DOM_INVALID_MODIFICATION_ERR);
if (validEntryTypes.IsEmpty()) {
return;
}

/* 3.3.1.5 */
if (mObserverType == ObserverTypeMultiple) {
const Sequence<nsString>& entryTypes = maybeEntryTypes.Value();
mEntryTypes.SwapElements(validEntryTypes);

if (entryTypes.IsEmpty()) {
return;
}

/* 3.3.1.5.2 */
nsTArray<nsString> validEntryTypes;
for (const char16_t* name : sValidTypeNames) {
nsDependentString validTypeName(name);
if (entryTypes.Contains<nsString>(validTypeName) &&
!validEntryTypes.Contains<nsString>(validTypeName)) {
validEntryTypes.AppendElement(validTypeName);
}
}

nsAutoString invalidTypesJoined;
bool addComma = false;
for (const auto& type : entryTypes) {
if (!validEntryTypes.Contains<nsString>(type)) {
if (addComma) {
invalidTypesJoined.AppendLiteral(", ");
}
addComma = true;
invalidTypesJoined.Append(type);
}
}

if (!invalidTypesJoined.IsEmpty()) {
ReportUnsupportedTypesErrorToConsole(NS_IsMainThread(),
invalidTypesJoined);
}

/* 3.3.1.5.3 */
if (validEntryTypes.IsEmpty()) {
nsString errorString;
nsresult rv = nsContentUtils::GetLocalizedString(
nsContentUtils::eDOM_PROPERTIES, "NoValidEntryTypes", errorString);
NS_ENSURE_SUCCESS(rv, );
ReportUnsupportedTypesErrorToConsole(NS_IsMainThread(), errorString);
return;
}

/*
* 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);

} else {
MOZ_ASSERT(mObserverType == ObserverTypeSingle);
bool typeValid = false;
nsString type = maybeType.Value();

/* 3.3.1.6.2 */
for (const char16_t* name : sValidTypeNames) {
nsDependentString validTypeName(name);
if (type == validTypeName) {
typeValid = true;
break;
}
}

if (!typeValid) {
ReportUnsupportedTypesErrorToConsole(NS_IsMainThread(), type);
return;
}

/* 3.3.1.6.4, 3.3.1.6.4 */
bool didUpdateOptionsList = false;
nsTArray<PerformanceObserverInit> updatedOptionsList;
for (auto& option : mOptions) {
if (option.mType.WasPassed() && option.mType.Value() == type) {
updatedOptionsList.AppendElement(aOptions);
didUpdateOptionsList = true;
} else {
updatedOptionsList.AppendElement(option);
}
}
if (!didUpdateOptionsList) {
updatedOptionsList.AppendElement(aOptions);
}
mOptions.SwapElements(updatedOptionsList);
mPerformance->AddObserver(this);

/* 3.3.1.6.5 */
if (maybeBuffered.WasPassed() && maybeBuffered.Value()) {
if (aOptions.mBuffered) {
for (auto entryType : mEntryTypes) {
nsTArray<RefPtr<PerformanceEntry>> existingEntries;
mPerformance->GetEntriesByType(type, existingEntries);
mPerformance->GetEntriesByType(entryType, existingEntries);
if (!existingEntries.IsEmpty()) {
mQueuedEntries.AppendElements(existingEntries);
}
}
}
/* Add ourselves to the list of registered performance
* observers, if necessary. (3.3.1.5.4,5; 3.3.1.6.4)
*/
mPerformance->AddObserver(this);
mConnected = true;
}

void PerformanceObserver::GetSupportedEntryTypes(
const GlobalObject& aGlobal, JS::MutableHandle<JSObject*> aObject) {
nsTArray<nsString> validTypes;
JS::Rooted<JS::Value> val(aGlobal.Context());

for (const char16_t* name : sValidTypeNames) {
nsString validTypeName(name);
validTypes.AppendElement(validTypeName);
}

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 (option.mType.WasPassed()) {
if (option.mType.Value() == aEntry->GetEntryType()) {
return true;
}
} else {
if (option.mEntryTypes.Value().Contains(aEntry->GetEntryType())) {
return true;
}
}
}
return false;
mConnected = true;
}

void PerformanceObserver::Disconnect() {
Expand Down
17 changes: 1 addition & 16 deletions dom/performance/PerformanceObserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ class PerformanceObserver final : public nsISupports, public nsWrapperCache {

nsISupports* GetParentObject() const { return mOwner; }

void Observe(const PerformanceObserverInit& aOptions, ErrorResult& aRv);
static void GetSupportedEntryTypes(const GlobalObject& aGlobal,
JS::MutableHandle<JSObject*> aObject);
void Observe(const PerformanceObserverInit& aOptions);

void Disconnect();

Expand All @@ -60,26 +58,13 @@ class PerformanceObserver final : public nsISupports, public nsWrapperCache {
MOZ_CAN_RUN_SCRIPT void Notify();
void QueueEntry(PerformanceEntry* aEntry);

bool ObservesTypeOfEntry(PerformanceEntry* aEntry);

private:
void ReportUnsupportedTypesErrorToConsole(bool aIsMainThread,
const nsString& aInvalidTypes);
~PerformanceObserver();

nsCOMPtr<nsISupports> mOwner;
RefPtr<PerformanceObserverCallback> mCallback;
RefPtr<Performance> mPerformance;
nsTArray<nsString> mEntryTypes;
nsTArray<PerformanceObserverInit> mOptions;
enum {
ObserverTypeUndefined,
ObserverTypeSingle,
ObserverTypeMultiple,
} mObserverType;
/*
* This is also known as registered, in the spec.
*/
bool mConnected;
nsTArray<RefPtr<PerformanceEntry>> mQueuedEntries;
};
Expand Down
4 changes: 2 additions & 2 deletions dom/performance/tests/test_performance_observer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ test(t => {
var observer = new PerformanceObserver(() => {
});

assert_throws({name: "SyntaxError"}, function() {
assert_throws({name: "TypeError"}, function() {
observer.observe();
}, "observe() should throw TypeError exception if no option specified.");

assert_throws({name: "SyntaxError"}, function() {
assert_throws({name: "TypeError"}, function() {
observer.observe({ unsupportedAttribute: "unsupported" });
}, "obsrve() should throw TypeError exception if the option has no 'entryTypes' attribute.");

Expand Down
8 changes: 3 additions & 5 deletions dom/webidl/PerformanceObserver.webidl
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
*/

dictionary PerformanceObserverInit {
sequence<DOMString> entryTypes;
DOMString type;
boolean buffered;
required sequence<DOMString> entryTypes;
boolean buffered = false;
};

callback PerformanceObserverCallback = void (PerformanceObserverEntryList entries,
Expand All @@ -20,8 +19,7 @@ callback PerformanceObserverCallback = void (PerformanceObserverEntryList entrie
Constructor(PerformanceObserverCallback callback),
Exposed=(Window,Worker)]
interface PerformanceObserver {
[Throws] void observe(optional PerformanceObserverInit options);
void observe(PerformanceObserverInit options);
void disconnect();
PerformanceEntryList takeRecords();
static readonly attribute object supportedEntryTypes;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[supported_navigation_type.window.html]
[supportedEntryTypes contains 'navigation'.]
expected: FAIL

Loading

0 comments on commit 80e7286

Please sign in to comment.