// Takes an array of dictionaries mapping keys to value arrays, e.g.: // [ {Shape: ["Square", "Circle", undefined]}, {Count: [1, 2]} ] // Returns an array of dictionaries with all value combinations, i.e.: // [ {Shape: "Square", Count: 1}, {Shape: "Square", Count: 2}, // {Shape: "Circle", Count: 1}, {Shape: "Circle", Count: 2}, // {Shape: undefined, Count: 1}, {Shape: undefined, Count: 2} ] // Omits dictionary members when the value is undefined; supports array values. function generateOptionCombinations(optionsSpec) { // 1. Extract keys from the input specification. const keys = optionsSpec.map(o => Object.keys(o)[0]); // 2. Extract the arrays of possible values for each key. const valueArrays = optionsSpec.map(o => Object.values(o)[0]); // 3. Compute the Cartesian product of the value arrays using reduce. const valueCombinations = valueArrays.reduce((accumulator, currentValues) => { // Init the empty accumulator (first iteration), with single-element // arrays. if (accumulator.length === 0) { return currentValues.map(value => [value]);
} // Otherwise, expand existing combinations with current values. return accumulator.flatMap(
existingCombo => currentValues.map(
currentValue => [...existingCombo, currentValue]));
}, []);
// 4. Map each value combination to a result dictionary, skipping // undefined. return valueCombinations.map(combination => { const result = {};
keys.forEach((key, index) => { if (combination[index] !== undefined) {
result[key] = combination[index];
}
}); return result;
});
}
// The method should take the AbortSignal as an option and return a promise.
async function testAbortPromise(t, method) { // Test abort signal without custom error.
{ const controller = new AbortController(); const promise = method(controller.signal);
controller.abort();
await promise_rejects_dom(t, 'AbortError', promise);
// Using the same aborted controller will get the `AbortError` as well. const anotherPromise = method(controller.signal);
await promise_rejects_dom(t, 'AbortError', anotherPromise);
}
// Test abort signal with custom error.
{ const err = new Error('test'); const controller = new AbortController(); const promise = method(controller.signal);
controller.abort(err);
await promise_rejects_exactly(t, err, promise);
// Using the same aborted controller will get the same error as well. const anotherPromise = method(controller.signal);
await promise_rejects_exactly(t, err, anotherPromise);
}
};
async function testCreateMonitorWithAbortAt(
t, loadedToAbortAt, method, options = {}) { const {promise: eventPromise, resolve} = Promise.withResolvers();
let hadEvent = false; function monitor(m) {
m.addEventListener('downloadprogress', e => { if (e.loaded != loadedToAbortAt) { return;
}
if (hadEvent) {
assert_unreached( 'This should never be reached since the create() operation was aborted.'); return;
}
// The method should take the AbortSignal as an option and return a // ReadableStream.
async function testAbortReadableStream(t, method) { // Test abort signal without custom error.
{ const controller = new AbortController(); const stream = method(controller.signal);
controller.abort();
let writableStream = new WritableStream();
await promise_rejects_dom(t, 'AbortError', stream.pipeTo(writableStream));
// Using the same aborted controller will get the `AbortError` as well.
await promise_rejects_dom(t, 'AbortError', new Promise(() => {
method(controller.signal);
}));
}
// Test abort signal with custom error.
{ const error = new DOMException('test', 'VersionError'); const controller = new AbortController(); const stream = method(controller.signal);
controller.abort(error);
let writableStream = new WritableStream();
await promise_rejects_exactly(t, error, stream.pipeTo(writableStream));
// Using the same aborted controller will get the same error.
await promise_rejects_exactly(t, error, new Promise(() => {
method(controller.signal);
}));
}
};
async function testMonitor(createFunc, options = {}) {
let created = false; const progressEvents = []; function monitor(m) {
m.addEventListener('downloadprogress', e => { // No progress events should be fired after `createFunc` resolves.
assert_false(created);
progressEvents.push(e);
});
}
result = await createFunc({...options, monitor});
created = true;
let lastProgressEventLoaded = -1; for (const progressEvent of progressEvents) {
assert_equals(progressEvent.lengthComputable, true);
assert_equals(progressEvent.total, 1);
assert_less_than_equal(progressEvent.loaded, progressEvent.total);
// `loaded` must be rounded to the nearest 0x10000th.
assert_equals(progressEvent.loaded % (1 / 0x10000), 0);
// Progress events should have monotonically increasing `loaded` values.
assert_greater_than(progressEvent.loaded, lastProgressEventLoaded);
lastProgressEventLoaded = progressEvent.loaded;
} return result;
}
async function testCreateMonitorCallbackThrowsError(
t, createFunc, options = {}) { const error = new Error('CreateMonitorCallback threw an error'); function monitor(m) {
m.addEventListener('downloadprogress', e => {
assert_unreached( 'This should never be reached since monitor throws an error.');
}); throw error;
}
async function ensureLanguageModel(options = {}) {
assert_true(!!LanguageModel); const availability = await LanguageModel.availability(options);
assert_in_array(availability, kValidAvailabilities); // Yield PRECONDITION_FAILED if the API is unavailable on this device.
assert_implements_optional(availability != 'unavailable', 'API unavailable');
};
for (const promise of promises) {
await promise_rejects_exactly(t, error, promise);
}
}
function consumeTransientUserActivation() { const win = window.open('about:blank', '_blank'); if (win)
win.close();
}
// Helper function to create a regex from some keywords. function matchKeywordsRegex(keywords) { const keywordsPattern = keywords.join('|'); returnnew RegExp(`(${keywordsPattern})`, 'i');
}
function testResponseJsonSchema(response, t) {
let jsonResponse; try {
jsonResponse = JSON.parse(response);
} catch (e) {
assert_unreached(
`Response is not valid JSON: "${response}". Error: ${e.message}`); return;
}
assert_equals(typeof jsonResponse, 'object', 'Response should be an object');
assert_own_property(
jsonResponse, 'Rating', 'JSON response should have a "Rating" property.');
assert_equals( typeof jsonResponse.Rating, 'number', 'Rating should be a number');
assert_greater_than_equal(jsonResponse.Rating, 0, 'Rating should be >= 0');
assert_less_than_equal(jsonResponse.Rating, 5, 'Rating should be <= 5');
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.13 Sekunden
(vorverarbeitet am 2026-08-26)
¤
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.