Skip to content

Performance api improvements #709

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions api-reports/2_12.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15763,9 +15763,9 @@ Pbkdf2Params[SO] val salt = salt0
Performance[JC] def clearMarks(markName: String?): Unit
Performance[JC] def clearMeasures(measureName: String?): Unit
Performance[JC] def clearResourceTimings(): Unit
Performance[JC] def getEntries(): js.Dynamic
Performance[JC] def getEntriesByName(name: String, entryType: String?): js.Dynamic
Performance[JC] def getEntriesByType(entryType: String): js.Dynamic
Performance[JC] def getEntries(): js.Array[PerformanceEntry]
Performance[JC] def getEntriesByName(name: String, entryType: String?): js.Array[PerformanceEntry]
Performance[JC] def getEntriesByType(entryType: String): js.Array[PerformanceEntry]
Performance[JC] def getMarks(markName: String?): js.Dynamic
Performance[JC] def getMeasures(measureName: String?): js.Dynamic
Performance[JC] def mark(markName: String): Unit
Expand All @@ -15775,15 +15775,15 @@ Performance[JC] def now(): Double
Performance[JC] def setResourceTimingBufferSize(maxSize: Int): Unit
Performance[JC] def timing: PerformanceTiming
Performance[JC] def toJSON(): js.Dynamic
PerformanceEntry[JC] def duration: Int
PerformanceEntry[JC] def duration: Double
PerformanceEntry[JC] def entryType: String
PerformanceEntry[JC] def name: String
PerformanceEntry[JC] def startTime: Double
PerformanceMark[JC] def duration: Int
PerformanceMark[JC] def duration: Double
PerformanceMark[JC] def entryType: String
PerformanceMark[JC] def name: String
PerformanceMark[JC] def startTime: Double
PerformanceMeasure[JC] def duration: Int
PerformanceMeasure[JC] def duration: Double
PerformanceMeasure[JC] def entryType: String
PerformanceMeasure[JC] def name: String
PerformanceMeasure[JC] def startTime: Double
Expand All @@ -15798,7 +15798,7 @@ PerformanceResourceTiming[JC] def connectEnd: Int
PerformanceResourceTiming[JC] def connectStart: Int
PerformanceResourceTiming[JC] def domainLookupEnd: Int
PerformanceResourceTiming[JC] def domainLookupStart: Int
PerformanceResourceTiming[JC] def duration: Int
PerformanceResourceTiming[JC] def duration: Double
PerformanceResourceTiming[JC] def entryType: String
PerformanceResourceTiming[JC] def fetchStart: Int
PerformanceResourceTiming[JC] def initiatorType: String
Expand Down
14 changes: 7 additions & 7 deletions api-reports/2_13.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15763,9 +15763,9 @@ Pbkdf2Params[SO] val salt = salt0
Performance[JC] def clearMarks(markName: String?): Unit
Performance[JC] def clearMeasures(measureName: String?): Unit
Performance[JC] def clearResourceTimings(): Unit
Performance[JC] def getEntries(): js.Dynamic
Performance[JC] def getEntriesByName(name: String, entryType: String?): js.Dynamic
Performance[JC] def getEntriesByType(entryType: String): js.Dynamic
Performance[JC] def getEntries(): js.Array[PerformanceEntry]
Performance[JC] def getEntriesByName(name: String, entryType: String?): js.Array[PerformanceEntry]
Performance[JC] def getEntriesByType(entryType: String): js.Array[PerformanceEntry]
Performance[JC] def getMarks(markName: String?): js.Dynamic
Performance[JC] def getMeasures(measureName: String?): js.Dynamic
Performance[JC] def mark(markName: String): Unit
Expand All @@ -15775,15 +15775,15 @@ Performance[JC] def now(): Double
Performance[JC] def setResourceTimingBufferSize(maxSize: Int): Unit
Performance[JC] def timing: PerformanceTiming
Performance[JC] def toJSON(): js.Dynamic
PerformanceEntry[JC] def duration: Int
PerformanceEntry[JC] def duration: Double
PerformanceEntry[JC] def entryType: String
PerformanceEntry[JC] def name: String
PerformanceEntry[JC] def startTime: Double
PerformanceMark[JC] def duration: Int
PerformanceMark[JC] def duration: Double
PerformanceMark[JC] def entryType: String
PerformanceMark[JC] def name: String
PerformanceMark[JC] def startTime: Double
PerformanceMeasure[JC] def duration: Int
PerformanceMeasure[JC] def duration: Double
PerformanceMeasure[JC] def entryType: String
PerformanceMeasure[JC] def name: String
PerformanceMeasure[JC] def startTime: Double
Expand All @@ -15798,7 +15798,7 @@ PerformanceResourceTiming[JC] def connectEnd: Int
PerformanceResourceTiming[JC] def connectStart: Int
PerformanceResourceTiming[JC] def domainLookupEnd: Int
PerformanceResourceTiming[JC] def domainLookupStart: Int
PerformanceResourceTiming[JC] def duration: Int
PerformanceResourceTiming[JC] def duration: Double
PerformanceResourceTiming[JC] def entryType: String
PerformanceResourceTiming[JC] def fetchStart: Int
PerformanceResourceTiming[JC] def initiatorType: String
Expand Down
8 changes: 4 additions & 4 deletions dom/src/main/scala/org/scalajs/dom/Performance.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import scala.scalajs.js.annotation._
*/
@js.native
@JSGlobal
class Performance extends js.Object {
class Performance private[this] () extends js.Object {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You cannot create objects of type Performance. Is this the correct way to forbid it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I think we do this in other places as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is correct.


/** The Performance.navigation read-only property returns a PerformanceNavigation object representing the type of
* navigation that occurs in the given browsing context, like the amount of redirections needed to fetch the
Expand All @@ -28,7 +28,7 @@ class Performance extends js.Object {
*/
def timing: PerformanceTiming = js.native

def getEntriesByType(entryType: String): js.Dynamic = js.native
def getEntriesByType(entryType: String): js.Array[PerformanceEntry] = js.native
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since there are only a limited set of values that can be passed as an entryType I wonder if we should create a specific type for it.
https://developer.mozilla.org/en-US/docs/Web/API/PerformanceEntry/entryType

E.g. like InputType.
https://github.com/scala-js/scala-js-dom/blob/1a944e4863aaf52694e29e38fb2a174f351f2ceb/dom/src/main/scala-3/org/scalajs/dom/InputType.scala

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, maybe I was wrong 😅

As the list of supported entries varies per browser and is evolving, this property allows web developers to check which are available.

https://developer.mozilla.org/en-US/docs/Web/API/PerformanceObserver/supportedEntryTypes


/** Is a jsonizer returning a json object representing the Performance object. */
def toJSON(): js.Dynamic = js.native
Expand All @@ -45,9 +45,9 @@ class Performance extends js.Object {

def measure(measureName: String, startMarkName: String = js.native, endMarkName: String = js.native): Unit = js.native

def getEntriesByName(name: String, entryType: String = js.native): js.Dynamic = js.native
def getEntriesByName(name: String, entryType: String = js.native): js.Array[PerformanceEntry] = js.native

def getEntries(): js.Dynamic = js.native
def getEntries(): js.Array[PerformanceEntry] = js.native

def clearMeasures(measureName: String = js.native): Unit = js.native

Expand Down
2 changes: 1 addition & 1 deletion dom/src/main/scala/org/scalajs/dom/PerformanceEntry.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class PerformanceEntry extends js.Object {

def startTime: Double = js.native

def duration: Int = js.native
def duration: Double = js.native

def entryType: String = js.native
}