char/avril
(wip) why'd you have to go and make things so complicaaaaated?
git clone https://git.t4t.associates/char/avril
44fe2c6
main
1import { 2ObjectCreate , 3TypeError , 4WeakMap , 5WeakMapPrototypeSet as set , 6} from "ext:core/primordials" ; 7import { onRuntimeStart } from "ext:core/bootstrap" ; 8import { 9op_timer_now as timerNow , 10op_timer_time_origin as timerTimeOrigin , 11} from "ext:core/ops" ; 12import { EventTarget } from "./events.js" ; 13import { state } from "./idl.js" ; 14 15const secret = ObjectCreate ( null ) as { 16readonly performanceToken :unique symbol ; 17}; 18const performances = new WeakMap < object , number >(); 19const floor = Math . floor ; 20 21class Performance extends EventTarget { 22constructor ( key :typeof secret ); 23constructor () { 24if ( arguments [ 0 ] !== secret ) throw new TypeError ( "Illegal constructor" ); 25super (); 26} 27now () :number { 28state ( performances , this ); 29return floor ( timerNow ( null ) * 10 ) / 10 ; 30} 31get timeOrigin () :number { 32return state ( performances , this ); 33} 34toJSON () :{ timeOrigin :number } { 35return { timeOrigin :state ( performances , this ) }; 36} 37} 38 39const performance = new Performance ( secret ); 40onRuntimeStart (() => { 41set ( performances , performance , floor ( timerTimeOrigin ( null ) * 10 ) / 10 ); 42}); 43export { Performance , performance };