mirror of
https://github.com/lexmount/moli.git
synced 2026-11-21 08:02:59 +00:00
fix(performance): support User Timing in workers
This commit is contained in:
@@ -503,154 +503,6 @@ fn performance_mark_constructor_creates_detached_structured_entries() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn performance_user_timing_enforces_mark_and_measure_boundaries() {
|
||||
let mut vm = new_storage_test_vm("https://performance-user-timing-boundaries.test/");
|
||||
|
||||
let result = vm
|
||||
.eval(
|
||||
r#"
|
||||
(() => {
|
||||
const capture = callback => {
|
||||
try {
|
||||
callback();
|
||||
return "none";
|
||||
} catch (error) {
|
||||
return `${error.name}:${error.code}`;
|
||||
}
|
||||
};
|
||||
performance.mark("later", { startTime: 5 });
|
||||
const sourceDetail = { value: 1 };
|
||||
const cloned = performance.measure("cloned", {
|
||||
start: 1,
|
||||
duration: 2,
|
||||
detail: sourceDetail
|
||||
});
|
||||
sourceDetail.value = 9;
|
||||
const negative = performance.measure(
|
||||
"negative-duration",
|
||||
"later",
|
||||
"navigationStart"
|
||||
);
|
||||
const legacyPendingNames = [
|
||||
"unloadEventStart",
|
||||
"unloadEventEnd",
|
||||
"redirectStart",
|
||||
"redirectEnd",
|
||||
"secureConnectionStart",
|
||||
"domInteractive",
|
||||
"domContentLoadedEventStart",
|
||||
"domContentLoadedEventEnd",
|
||||
"domComplete",
|
||||
"loadEventStart",
|
||||
"loadEventEnd"
|
||||
];
|
||||
return JSON.stringify({
|
||||
reservedMark: capture(() => performance.mark("navigationStart")),
|
||||
missingMark: capture(() => performance.measure("missing", "does-not-exist")),
|
||||
numericLegacyMark: capture(() => performance.measure("number", 51.15, "later")),
|
||||
unavailableTiming: capture(() => performance.measure("pending", "redirectStart")),
|
||||
detailOnlyOptions: capture(() => performance.measure("detail-only", { detail: 1 })),
|
||||
overSpecifiedOptions: capture(() => performance.measure("all", {
|
||||
start: 1,
|
||||
duration: 2,
|
||||
end: 3
|
||||
})),
|
||||
negativeMark: capture(() => performance.mark("bad-mark", { startTime: -1 })),
|
||||
infiniteMark: capture(() => performance.mark("bad-infinite", { startTime: Infinity })),
|
||||
negativeBoundary: capture(() => performance.measure("bad-boundary", { start: -1 })),
|
||||
negativeDuration: negative.duration,
|
||||
navigationStartTime: performance.measure("from-navigation", "navigationStart").startTime,
|
||||
pendingTimingStartsAtZero: legacyPendingNames.every(name => performance.timing[name] === 0),
|
||||
clonedDetail: `${cloned.detail.value}:${cloned.detail === sourceDetail}`,
|
||||
navigationEntryIsNotMark: capture(() => performance.measure("entry-name", location.href))
|
||||
});
|
||||
})()
|
||||
"#,
|
||||
)
|
||||
.expect("User Timing boundary probe should evaluate");
|
||||
|
||||
assert_eq!(
|
||||
result,
|
||||
r#"{"reservedMark":"SyntaxError:12","missingMark":"SyntaxError:12","numericLegacyMark":"SyntaxError:12","unavailableTiming":"InvalidAccessError:15","detailOnlyOptions":"TypeError:undefined","overSpecifiedOptions":"TypeError:undefined","negativeMark":"TypeError:undefined","infiniteMark":"TypeError:undefined","negativeBoundary":"TypeError:undefined","negativeDuration":-5,"navigationStartTime":0,"pendingTimingStartsAtZero":true,"clonedDetail":"1:false","navigationEntryIsNotMark":"SyntaxError:12"}"#
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn performance_mark_constructor_creates_detached_structured_entries() {
|
||||
let mut vm = new_storage_test_vm("https://performance-mark-constructor.test/");
|
||||
|
||||
let result = vm
|
||||
.eval(
|
||||
r#"
|
||||
(() => {
|
||||
const capture = callback => {
|
||||
try {
|
||||
callback();
|
||||
return "none";
|
||||
} catch (error) {
|
||||
return `${error.name}:${error.code}`;
|
||||
}
|
||||
};
|
||||
const sourceDetail = { state: "before" };
|
||||
const entry = new PerformanceMark("detached", {
|
||||
startTime: 2,
|
||||
detail: sourceDetail
|
||||
});
|
||||
sourceDetail.state = "after";
|
||||
class DerivedPerformanceMark extends PerformanceMark {}
|
||||
const derived = new DerivedPerformanceMark("derived", { startTime: 3 });
|
||||
return JSON.stringify({
|
||||
shape: [
|
||||
entry instanceof PerformanceEntry,
|
||||
entry instanceof PerformanceMark,
|
||||
Object.prototype.toString.call(entry),
|
||||
entry.name,
|
||||
entry.entryType,
|
||||
entry.startTime,
|
||||
entry.duration
|
||||
].join(":"),
|
||||
detail: `${entry.detail.state}:${entry.detail === entry.detail}:${entry.detail === sourceDetail}`,
|
||||
timelineEntries: performance.getEntriesByName("detached", "mark").length,
|
||||
derived: [
|
||||
derived instanceof DerivedPerformanceMark,
|
||||
derived instanceof PerformanceMark,
|
||||
Object.getPrototypeOf(derived) === DerivedPerformanceMark.prototype,
|
||||
derived.name,
|
||||
derived.startTime
|
||||
].join(":"),
|
||||
constructorInheritance:
|
||||
Object.getPrototypeOf(PerformanceMark) === PerformanceEntry
|
||||
&& Object.getPrototypeOf(PerformanceMeasure) === PerformanceEntry,
|
||||
detailBrand: capture(() =>
|
||||
Object.getOwnPropertyDescriptor(PerformanceMark.prototype, "detail")
|
||||
.get.call(PerformanceMark.prototype)),
|
||||
methodBrands: [
|
||||
performance.mark,
|
||||
performance.clearMarks,
|
||||
performance.measure,
|
||||
performance.clearMeasures
|
||||
].map(method => capture(() => method.call(null, "unbound"))).join("|"),
|
||||
withoutNew: capture(() => PerformanceMark("call")),
|
||||
missingName: capture(() => new PerformanceMark()),
|
||||
negativeStart: capture(() => new PerformanceMark("negative", { startTime: -1 })),
|
||||
infiniteStart: capture(() => new PerformanceMark("infinite", { startTime: Infinity })),
|
||||
reservedName: capture(() => new PerformanceMark("navigationStart")),
|
||||
cloneError: capture(() => new PerformanceMark("clone", {
|
||||
detail: { value: Symbol() }
|
||||
}))
|
||||
});
|
||||
})()
|
||||
"#,
|
||||
)
|
||||
.expect("PerformanceMark constructor probe should evaluate");
|
||||
|
||||
assert_eq!(
|
||||
result,
|
||||
r#"{"shape":"true:true:[object PerformanceMark]:detached:mark:2:0","detail":"before:true:false","timelineEntries":0,"derived":"true:true:true:derived:3","constructorInheritance":true,"detailBrand":"TypeError:undefined","methodBrands":"TypeError:undefined|TypeError:undefined|TypeError:undefined|TypeError:undefined","withoutNew":"TypeError:undefined","missingName":"TypeError:undefined","negativeStart":"TypeError:undefined","infiniteStart":"TypeError:undefined","reservedName":"SyntaxError:12","cloneError":"DataCloneError:25"}"#
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn performance_entry_to_json_returns_native_base_snapshot() {
|
||||
let mut vm = new_storage_test_vm("https://performance-entry-json.test/");
|
||||
@@ -855,6 +707,13 @@ fn performance_root_slots_ignore_reflection_and_spoofing() {
|
||||
&& descriptor.configurable === true
|
||||
&& !Object.prototype.hasOwnProperty.call(receiver, name);
|
||||
};
|
||||
const capture = callback => {
|
||||
try {
|
||||
return String(callback());
|
||||
} catch (error) {
|
||||
return error.name;
|
||||
}
|
||||
};
|
||||
const timing = performance.timing;
|
||||
const navigation = performance.navigation;
|
||||
const eventCounts = performance.eventCounts;
|
||||
|
||||
Reference in New Issue
Block a user