/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/** *ThisescapesallcharactersthathaveaspecialmeaninginRegExps. *Thiswasstolenfromhttps://github.com/sindresorhus/escape-string-regexp and *soitislicenceMITand: *Copyright(c)SindreSorhus<sindresorhus@gmail.com>(https://sindresorhus.com). *Seethefulllicenseinhttps://raw.githubusercontent.com/sindresorhus/escape-string-regexp/main/license. * *@param{string}stringThestringtobeescaped *@returns{string}Theresult
*/ function escapeStringRegexp(string) { if (typeof string !== "string") { thrownew TypeError("Expected a string");
}
// Escape characters with special meaning either inside or outside character // sets. Use a simple backslash escape when it’s always valid, and a `\xnn` // escape when the simpler form would be disallowed by Unicode patterns’ // stricter grammar. return string.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&").replace(/-/g, "\\x2d");
}
/** ------ Utility functions and definitions for raising POSIX signals ------ */
// Find the path for a profile written to disk because of signals
async function getFullProfilePath(pid) { // Initially look for "MOZ_UPLOAD_DIR". If this exists, firefox will write the // profile file here, so this is where we need to look.
let path = Services.env.get("MOZ_UPLOAD_DIR"); if (!path) {
path = await Downloads.getSystemDownloadsDirectory();
} return PathUtils.join(path, `profile_0_${pid}.json`);
}
// Hardcode the constants SIGUSR1 and SIGUSR2. // This is an absolutely terrible idea, as they are implementation defined! // However, it turns out that for 99% of the platforms we care about, and for // 99.999% of the platforms we test, these constants are, well, constant. // Additionally, these constants are only for _testing_ the signal handling // feature - the actual feature relies on platform specific definitions. This // may cause a mismatch if we test on on, say, a gnu hurd kernel, or on a // linux kernel running on sparc, but the feature will not break - only // the testing. const SIGUSR1 = Services.appinfo.OS === "Darwin" ? 30 : 10; const SIGUSR2 = Services.appinfo.OS === "Darwin" ? 31 : 12;
// Derived from functionality in js/src/devtools/rootAnalysis/utility.js function openLibrary(names) { for (const name of names) { try { return ctypes.open(name);
} catch (e) {}
} return undefined;
}
try { const libc = openLibrary([ "libc.so.6", "libc.so", "libc.dylib", "libSystem.B.dylib",
]); if (!libc) {
info("Failed to open any libc shared object"); return { ok: false };
}
// c.f. https://man7.org/linux/man-pages/man2/kill.2.html // This choice of typing for `pid` is complex, and brittle, as it's platform // dependent. Getting it wrong can result in incoreect generation/calling of // the `kill` function. Unfortunately, as it's defined as `pid_t` in a // header, we can't easily get access to it. For now, we just use an // integer, and hope that the system int size aligns with the `pid_t` size. const kill = libc.declare( "kill",
ctypes.default_abi,
ctypes.int, // return value
ctypes.int32_t, // pid
ctypes.int// sig
);
let kres = kill(pid, sig); if (kres != 0) {
info(`Kill returned a non-zero result ${kres}.`); return { ok: false };
}
libc.close();
} catch (e) {
info(`Exception ${e} thrown while trying to call kill`); return { ok: false };
}
return { ok: true };
}
/** ------ Assertions helper ------ */ /** *Thisasserthelperfunctionmakesiteasytocheckalotofpropertiesinan *object.WeaugmentAssert.sys.mjstomakeiteasiertouse.
*/
Object.assign(Assert, { /* *Itchecksifthepropertiesontherightareallpresentintheobjecton *theleft.Notethattheobjectmightstillhaveotherproperties(see *objectContainsOnlybelowifyouwantthestricterform). * *Thebasicformdoesbasicequalityoneachexpectedproperty: * *Assert.objectContains(fixture,{ *foo:"foo", *bar:1, *baz:true, *}); * *Butitalsohasamorepowerfulformwithexpectations.Theavailable *expectationsare: *-any():thisonlychecksfortheexistenceoftheproperty,notitsvalue *-number(),string(),boolean(),bigint(),function(),symbol(),object(): *thischecksifthevalueisofthistype *-objectContains(expected):thisappliesAssert.objectContains() *recursivelyonthisproperty. *-stringContains(needle):thischecksiftheexpectedvalueisincludedin *thepropertyvalue. *-stringMatches(regexp):thischecksifthepropertyvaluematchesthis *regexp.Theregexpcanbepassedasastring,tobedynamicallybuilt. * *example: * *Assert.objectContains(fixture,{ *name:Expect.stringMatches(`Load\\d+:.*${url}`), *data:Expect.objectContains({ *status:"STATUS_STOP", *URI:Expect.stringContains("https://"), *requestMethod:"GET", *contentType:Expect.string(), *startTime:Expect.number(), *cached:Expect.boolean(), *}), *}); * *EachexpectationwilltranslateintooneormoreAssertcall.Thereforeif *oneexpectationfails,thiswillbeclearlyvisibleinthetestoutput. * *Expectationscanalsobenormalfunctions,forexample: * *Assert.objectContains(fixture,{ *number:value=>Assert.greater(value,5) *}); * *Notethatyou'llneedtouseAssertinsidethisfunction.
*/
objectContains(object, expectedProperties) { // Basic tests: we don't want to run other assertions if these tests fail. if (typeof object !== "object") { this.ok( false,
`The first parameter should be an object, but found: ${object}.`
); return;
}
if (typeof expectedProperties !== "object") { this.ok( false,
`The second parameter should be an object, but found: ${expectedProperties}.`
); return;
}
for (const key of Object.keys(expectedProperties)) { const expected = expectedProperties[key]; if (!(key in object)) { this.report( true,
object,
expectedProperties,
`The object should contain the property "${key}", but it's missing.`
); continue;
}
if (typeof expected === "function") { // This is a function, so let's call it.
expected(
object[key],
`The object should contain the property "${key}" with an expected value and type.`
);
} else { // Otherwise, we check for equality. this.equal(
object[key],
expectedProperties[key],
`The object should contain the property "${key}" with an expected value.`
);
}
}
},
/** *Thisisverysimilartotheprevious`objectContains`,butthisalsolooks *atthenumberoftheobjects'properties.Thusthiswillfailifthe *objectsdon'thavethesamepropertiesexactly.
*/
objectContainsOnly(object, expectedProperties) { // Basic tests: we don't want to run other assertions if these tests fail. if (typeof object !== "object") { this.ok( false,
`The first parameter should be an object but found: ${object}.`
); return;
}
if (typeof expectedProperties !== "object") { this.ok( false,
`The second parameter should be an object but found: ${expectedProperties}.`
); return;
}
// In objectContainsOnly, we specifically want to check if all properties // from the fixture object are expected. // We'll be failing a test only for the specific properties that weren't // expected, and only fail with one message, so that the test outputs aren't // spammed. const extraProperties = []; for (const fixtureKey of Object.keys(object)) { if (!(fixtureKey in expectedProperties)) {
extraProperties.push(fixtureKey);
}
}
if (extraProperties.length) { // Some extra properties have been found. this.report( true,
object,
expectedProperties,
`These properties are present, but shouldn't: "${extraProperties.join( '", "'
)}".`
);
}
// Now, let's carry on the rest of our work. this.objectContains(object, expectedProperties);
},
});
const Expect = {
any:
() =>
() => {} /* We don't check anything more than the presence of this property. */,
};
/* These functions are part of the Assert object, and we want to reuse them. */
[ "stringContains", "stringMatches", "objectContains", "objectContainsOnly",
].forEach(
assertChecker =>
(Expect[assertChecker] =
expected =>
(actual, ...moreArgs) => Assert[assertChecker](actual, expected, ...moreArgs))
);
/* These functions will only check for the type. */
[ "number", "string", "boolean", "bigint", "symbol", "object", "function",
].forEach(type => (Expect[type] = makeTypeChecker(type)));
function makeTypeChecker(type) { return (...unexpectedArgs) => { if (unexpectedArgs.length) { thrownew Error( "Type checkers expectations aren't expecting any argument."
);
} return (actual, message) => { const isCorrect = typeof actual === type; Assert.report(!isCorrect, actual, type, message, "has type");
};
};
} /* ------ End of assertion helper ------ */
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.19 Sekunden
(vorverarbeitet am 2026-08-25)
¤
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 und die Messung sind noch experimentell.