commit 6fc34fde9274a13bf47cc616e6d1072e6084f8be
parent bd3d5efbfd1d2957dbe4c822c77d5a036ef669fb
Author: Lorenz A <me@lorenzackermann.xyz>
Date: Tue, 9 Dec 2025 06:41:54 +0000
Bug 2004215 - [devtools] Turn devtools/shared/heapsnapshot/tests/xpcshell/Match.sys.mjs into an ES class. r=devtools-reviewers,nchevobbe
Differential Revision: https://phabricator.services.mozilla.com/D275477
Diffstat:
2 files changed, 23 insertions(+), 27 deletions(-)
diff --git a/devtools/shared/heapsnapshot/tests/xpcshell/Match.sys.mjs b/devtools/shared/heapsnapshot/tests/xpcshell/Match.sys.mjs
@@ -4,19 +4,14 @@
// server xpcshell tests.
export const Match = (function () {
- function Pattern(template) {
- // act like a constructor even as a function
- if (!(this instanceof Pattern)) {
- return new Pattern(template);
+ class Pattern {
+ constructor(template) {
+ this.template = template;
}
- this.template = template;
- }
-
- Pattern.prototype = {
match(act) {
return match(act, this.template);
- },
+ }
matches(act) {
try {
@@ -27,7 +22,7 @@ export const Match = (function () {
}
}
return false;
- },
+ }
assert(act, message) {
try {
@@ -38,10 +33,12 @@ export const Match = (function () {
}
}
return false;
- },
+ }
- toString: () => "[object Pattern]",
- };
+ toString() {
+ return "[object Pattern]";
+ }
+ }
Pattern.ANY = new Pattern();
Pattern.ANY.template = Pattern.ANY;
@@ -62,15 +59,14 @@ export const Match = (function () {
const quote = uneval;
- function MatchError(msg) {
- this.message = msg;
- }
-
- MatchError.prototype = {
+ class MatchError {
+ constructor(msg) {
+ this.message = msg;
+ }
toString() {
return "match error: " + this.message;
- },
- };
+ }
+ }
function isAtom(x) {
return (
diff --git a/devtools/shared/heapsnapshot/tests/xpcshell/test_HeapSnapshot_takeCensus_06.js b/devtools/shared/heapsnapshot/tests/xpcshell/test_HeapSnapshot_takeCensus_06.js
@@ -12,7 +12,7 @@ function run_test() {
const g = newGlobal();
const dbg = new Debugger(g);
- Pattern({ count: Pattern.NATURAL, bytes: Pattern.NATURAL }).assert(
+ new Pattern({ count: Pattern.NATURAL, bytes: Pattern.NATURAL }).assert(
saveHeapSnapshotAndTakeCensus(dbg, { breakdown: { by: "count" } })
);
@@ -43,7 +43,7 @@ function run_test() {
// Pattern doesn't mind objects with extra properties, so we'll restrict this
// list to the object classes we're pretty sure are going to stick around for
// the forseeable future.
- Pattern({
+ new Pattern({
Function: { count: Pattern.NATURAL },
Object: { count: Pattern.NATURAL },
DebuggerPrototype: { count: Pattern.NATURAL },
@@ -52,7 +52,7 @@ function run_test() {
saveHeapSnapshotAndTakeCensus(dbg, { breakdown: { by: "objectClass" } })
);
- Pattern({
+ new Pattern({
objects: { count: Pattern.NATURAL },
scripts: { count: Pattern.NATURAL },
strings: { count: Pattern.NATURAL },
@@ -63,7 +63,7 @@ function run_test() {
// As for { by: 'objectClass' }, restrict our pattern to the types
// we predict will stick around for a long time.
- Pattern({
+ new Pattern({
JSString: { count: Pattern.NATURAL },
"js::Shape": { count: Pattern.NATURAL },
JSObject: { count: Pattern.NATURAL },
@@ -80,7 +80,7 @@ function run_test() {
other: { count: Pattern.NATURAL },
};
- Pattern({
+ new Pattern({
JSString: coarseTypePattern,
"js::Shape": coarseTypePattern,
JSObject: coarseTypePattern,
@@ -90,7 +90,7 @@ function run_test() {
})
);
- Pattern({
+ new Pattern({
Function: { count: Pattern.NATURAL },
Object: { count: Pattern.NATURAL },
DebuggerPrototype: { count: Pattern.NATURAL },
@@ -106,7 +106,7 @@ function run_test() {
})
);
- Pattern({
+ new Pattern({
objects: { count: Pattern.NATURAL, label: "object" },
scripts: { count: Pattern.NATURAL, label: "scripts" },
strings: { count: Pattern.NATURAL, label: "strings" },