Skip to content

Commit

Permalink
Avoid classical for when looping through all items of an Array-like o…
Browse files Browse the repository at this point in the history
…bject (part #2) (mdn#19405)

* Avoid classical for if for...of when looping all object of an Array-like object

* Remove addictions from MDN

* Add checkPerformanceEntry

* Use same example

* Use same example

* Fix naming

* Fix names

* Fix name

* Fix name

* Fix name

* Fix name

* Rename function

* Rename function

* Fix name

* Fix name

* Remove useless const

* Remove useless variable

* fix name

* Fix name

* Fix name

* Fix name

* Fix name

* Fix name

* Fix name

* Remove useless variable

* Remove useless variable

* Remove useless variable

* Remove useless varaible

* Rename function

* fix function name

* Fix function name

* Fix function name

* Fix function name

* Add empty line

* Fix function names

* Update files/en-us/web/api/performanceresourcetiming/decodedbodysize/index.md

Co-authored-by: Joshua Chen <[email protected]>

* Fix function names

* Fix function name

* Fix function names

* Fix function names

* Fix function names

* Fix function names

* fix function names

* Fix function names

* Fix function names

* Fix function names

* Fix function names

* Fix function names

* Use ternary operator

* Fix function names

* Use method

* Update files/en-us/web/api/texttrack/mode/index.md

Co-authored-by: Joshua Chen <[email protected]>

* Update files/en-us/web/api/performance/getentriesbytype/index.md

Co-authored-by: rubiesonthesky <[email protected]>

* Update files/en-us/web/api/performance/getentriesbytype/index.md

Co-authored-by: rubiesonthesky <[email protected]>

* Update files/en-us/web/api/performance_timeline/using_performance_timeline/index.md

Co-authored-by: rubiesonthesky <[email protected]>

* Update files/en-us/web/api/performance/getentriesbytype/index.md

Co-authored-by: rubiesonthesky <[email protected]>

* Update files/en-us/web/api/performance_timeline/using_performance_timeline/index.md

Co-authored-by: rubiesonthesky <[email protected]>

* Update files/en-us/web/api/performance_timeline/using_performance_timeline/index.md

Co-authored-by: rubiesonthesky <[email protected]>

* Update files/en-us/web/api/performance_timeline/using_performance_timeline/index.md

Co-authored-by: rubiesonthesky <[email protected]>

* Update files/en-us/web/api/speechsynthesisvoice/name/index.md

Co-authored-by: rubiesonthesky <[email protected]>

* Readd example

* readd example

* Add workerStart to the list

* Replace for…in

* Use findIndex()

* Use findIndex()

* Fix function names (no _)

* Fix alignement + for…in

* Alignment

* Update files/en-us/web/api/performanceresourcetiming/transfersize/index.md

Co-authored-by: Joshua Chen <[email protected]>

* Use ??

* Use ??

* Use ??

* Use ??

* Use ??

* Use ??

* Update files/en-us/web/api/performanceresourcetiming/connectstart/index.md

* Use ??

* Use ??

* Remove empty space

* Remove space

* Use ??

* Use ??

* Use ??

* Use ??

* Use ??

* Use ??

* Use ??

* Use ??

* Use ??

* Apply suggestions from code review

* Use console.log

* Use console.log

* Use console.log

* Use console.log

* Use console.log

* console.log

* console.log

* Apply suggestions from code review

* Update index.md

* Update index.md

* Update index.md

* Remove useless variable

* Fix typo

* Use findLastIndex()

* Update index.md

* Update index.md

Co-authored-by: Joshua Chen <[email protected]>
Co-authored-by: rubiesonthesky <[email protected]>
  • Loading branch information
3 people authored Sep 2, 2022
1 parent 0182d6f commit 24f9f75
Show file tree
Hide file tree
Showing 48 changed files with 821 additions and 932 deletions.
53 changes: 33 additions & 20 deletions files/en-us/web/api/performance/getentries/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ None.
## Examples

```js
function use_PerformanceEntry_methods() {
function usePerformanceEntryMethods() {
console.log("PerformanceEntry tests…");

if (performance.mark === undefined) {
Expand All @@ -61,29 +61,42 @@ function use_PerformanceEntry_methods() {
performance.mark("End");

// Use getEntries() to iterate through the each entry
let p = performance.getEntries();
for (let i = 0; i < p.length; i++) {
console.log(`Entry[${i}]`);
check_PerformanceEntry(p[i]);
}
performance.getEntries()
.forEach((entry, i) => {
console.log(`Entry[${i}]`);
checkPerformanceEntry(entry);
});

// Use getEntriesByType() to get all "mark" entries
p = performance.getEntriesByType("mark");
for (let i=0; i < p.length; i++) {
console.log(`Mark only entry[${i}]:`);
console.log(` name = ${p[i].name}`);
console.log(` startTime = ${p[i].startTime}`);
console.log(` duration = ${p[i].duration}`);
}
performance.getEntriesByType("mark")
.forEach((entry, i) => {
console.log(`Mark only entry[${i}]:`);
checkPerformanceEntry(entry);
});

// Use getEntriesByName() to get all "mark" entries named "Begin"
p = performance.getEntriesByName("Begin", "mark");
for (let i=0; i < p.length; i++) {
console.log(`Mark and Begin entry[${i}]:`);
console.log(` name = ${p[i].name}`);
console.log(` startTime = ${p[i].startTime}`);
console.log(` duration = ${p[i].duration}`);
}
performance.getEntriesByName("Begin", "mark")
.forEach((entry, i) => {
console.log(`Mark and Begin entry[${i}]:`);
checkPerformanceEntry(entry);
});
}

function checkPerformanceEntry(obj) {
const properties = ["name", "entryType", "startTime", "duration"];
const methods = ["toJSON"];

// Check each property
properties.forEach((property) => {
const supported = property in obj;
console.log(`${property} = ${supported ? obj[property] : "Not supported"}`);
});

// Check each method
methods.forEach((method) => {
const supported = typeof obj[method] === "function";
console.log(`${method} = ${supported ? JSON.stringify(obj[method]()) : "Not supported"}`);
});
}
```

Expand Down
67 changes: 40 additions & 27 deletions files/en-us/web/api/performance/getentriesbyname/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ A list of {{domxref("PerformanceEntry")}} objects that have the specified
## Examples

```js
function use_PerformanceEntry_methods() {
function usePerformanceEntryMethods() {
console.log("PerformanceEntry tests…");

if (performance.mark === undefined) {
console.error("The property performance.mark is not supported.");
console.error("The property performance.mark is not supported");
return;
}

Expand All @@ -65,36 +65,49 @@ function use_PerformanceEntry_methods() {
performance.mark("End");

// Use getEntries() to iterate through the each entry
let p = performance.getEntries();
for (let i=0; i < p.length; i++) {
log(`Entry[${i}]`);
check_PerformanceEntry(p[i]);
}

performance.getEntries()
.forEach((entry, i) => {
console.log(`Entry[${i}]`);
checkPerformanceEntry(entry);
});
// Use getEntries(name, entryType) to get specific entries
p = performance.getEntries({name : "Begin", entryType: "mark"});
for (let i=0; i < p.length; i++) {
log(`Begin[${i}]`);
check_PerformanceEntry(p[i]);
}
performance.getEntries({ name: "Begin", entryType: "mark" })
.forEach((entry, i) => {
console.log(`Begin[${i}]`);
checkPerformanceEntry(entry);
});

// Use getEntriesByType() to get all "mark" entries
p = performance.getEntriesByType("mark");
for (let i=0; i < p.length; i++) {
log(`Mark only entry[${i}]:`);
log(` name = ${p[i].name}`);
log(` startTime = ${p[i].startTime}`);
log(` duration = ${p[i].duration}`);
}
performance.getEntriesByType("mark")
.forEach((entry, i) => {
console.log(`Mark only entry[${i}]:`);
checkPerformanceEntry(entry);
});

// Use getEntriesByName() to get all "mark" entries named "Begin"
p = performance.getEntriesByName("Begin", "mark");
for (let i=0; i < p.length; i++) {
log(`Mark and Begin entry[${i}]:`);
log(` name = ${p[i].name}`);
log(` startTime = ${p[i].startTime}`);
log(` duration = ${p[i].duration}`);
}
performance.getEntriesByName("Begin", "mark")
.forEach((entry, i) => {
console.log(`Mark and Begin entry[${i}]:`);
checkPerformanceEntry(entry);
});
}

function checkPerformanceEntry(obj) {
const properties = ["name", "entryType", "startTime", "duration"];
const methods = ["toJSON"];

// Check each property
properties.forEach((property) => {
const supported = property in obj;
console.log(`${property} = ${supported ? obj[property] : "Not supported"}`);
});

// Check each method
methods.forEach((method) => {
const supported = typeof obj[method] === "function";
console.log(`${method} = ${supported ? obj[method] : "Not supported"}`);
});
}
```

Expand Down
65 changes: 39 additions & 26 deletions files/en-us/web/api/performance/getentriesbytype/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function usePerformanceEntryMethods() {
console.log("PerformanceEntry tests…");

if (performance.mark === undefined) {
console.error("The property performance.mark is not supported.");
console.error("The property performance.mark is not supported");
return;
}

Expand All @@ -60,36 +60,49 @@ function usePerformanceEntryMethods() {
performance.mark("End");

// Use getEntries() to iterate through the each entry
let p = performance.getEntries();
for (let i=0; i < p.length; i++) {
log(`Entry[${i}]`);
checkPerformanceEntry(p[i]);
}

performance.getEntries()
.forEach((entry, i) => {
console.log(`Entry[${i}]`);
checkPerformanceEntry(entry);
});
// Use getEntries(name, entryType) to get specific entries
p = performance.getEntries({name : "Begin", entryType: "mark"});
for (let i=0; i < p.length; i++) {
log(`Begin[${i}]`);
checkPerformanceEntry(p[i]);
}
performance.getEntries({ name: "Begin", entryType: "mark" })
.forEach((entry, i) => {
console.log(`Begin[${i}]`);
checkPerformanceEntry(entry);
});

// Use getEntriesByType() to get all "mark" entries
p = performance.getEntriesByType("mark");
for (let i=0; i < p.length; i++) {
log(`Mark only entry[${i}]:`);
log(` name = ${p[i].name}`);
log(` startTime = ${p[i].startTime}`);
log(` duration = ${p[i].duration}`);
}
performance.getEntriesByType("mark")
.forEach((entry, i) => {
console.log(`Mark only entry[${i}]:`);
checkPerformanceEntry(entry);
});

// Use getEntriesByName() to get all "mark" entries named "Begin"
p = performance.getEntriesByName("Begin", "mark");
for (let i=0; i < p.length; i++) {
log(`Mark and Begin entry[${i}]:`);
log(` name = ${p[i].name}`);
log(` startTime = ${p[i].startTime}`);
log(` duration = ${p[i].duration}`);
}
performance.getEntriesByName("Begin", "mark")
.forEach((entry, i) => {
console.log(`Mark and Begin entry[${i}]:`);
checkPerformanceEntry(entry);
});
}

function checkPerformanceEntry(obj) {
const properties = ["name", "entryType", "startTime", "duration"];
const methods = ["toJSON"];

// Check each property
properties.forEach((property) => {
const supported = property in obj;
console.log(`${property} = ${supported ? obj[property] : "Not supported"}`);
});

// Check each method
methods.forEach((method) => {
const supported = typeof obj[method] === "function";
console.log(`${method} = ${supported ? JSON.stringify(obj[method]()) : "Not supported"}`);
});
}
```

Expand Down
Loading

0 comments on commit 24f9f75

Please sign in to comment.