function checkFast(value, expectWhySlow) {
let whySlow;
let json; try {
json = JSONStringify(value, "FastOnly");
} catch (e) { const m = e.message.match(/failed mandatory fast path: (\S+)/); if (!m) {
report("Expected fast path fail, got " + e); return1;
}
whySlow = m[1];
}
if (expectWhySlow) { if (!whySlow) {
report("Expected to bail out of fast path but unexpectedly succeeded");
report((new Error).stack);
report(json); return1;
} elseif (whySlow != expectWhySlow) {
report(`Expected to bail out of fast path because ${expectWhySlow} but bailed because ${whySlow}`); return1;
}
} else { if (whySlow) {
report("Expected fast path to succeed, bailed because: " + whySlow); return1; // Fail
}
}
// This is probably redundant with one of the above, but it was // found by a fuzzer at one point. const accessorProto = Object.create(Array.prototype);
Object.defineProperty(accessorProto, "0", {
get() { return2; }, set() { }
}); const child = [];
Object.setPrototypeOf(child, accessorProto);
child.push(1);
failures += checkFast(child, "INELIGIBLE_OBJECT");
failures += checkFast({ get x() { return1; } }, "NON_DATA_PROPERTY");
const self = {};
self.self = self;
failures += checkFast(self, "DEEP_RECURSION"); const ouroboros = ['head', 'middle', []];
let p = ouroboros[2];
let middle; for (let i = 0; i < 1000; i++) {
p.push('middle', 'middle');
p = p[2] = []; if (i == 10) {
middle = p;
}
}
failures += checkFast(ouroboros, "DEEP_RECURSION"); // Acyclic but deep
p[2] = ouroboros;
failures += checkFast(ouroboros, "DEEP_RECURSION"); // Cyclic and deep
middle[2] = ouroboros;
failures += checkFast(ouroboros, "DEEP_RECURSION"); // Cyclic after 10 recursions
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.