{"ScriptPreparationCode":"function LoopObservable() {\r\n const listeners = new Set();\r\n this.on = fn =\u003E listeners.add(fn);\r\n this.off = fn =\u003E listeners.delete(fn);\r\n this.clear = () =\u003E listeners.clear();\r\n\r\n // This has bad failure modes.\r\n this.send = function(...message) {\r\n for (let fn of listeners) {\r\n try {\r\n fn(...message);\r\n } catch (error) {\r\n console.error(error);\r\n }\r\n }\r\n };\r\n};\r\n\r\nfunction EventTargetObservable() {\r\n // Name is arbitrary because we\u0027re using a dedicated object. Use a shorter\r\n // name for shorter lookup.\r\n const NAME = \u0027.\u0027;\r\n const __ = document.createTextNode(null);\r\n\r\n this.on = function(handler) {\r\n __.addEventListener(NAME, event =\u003E {\r\n handler(event.detail);\r\n });\r\n };\r\n\r\n this.off = function(handler) {\r\n __.removeEventListener(NAME, handler);\r\n };\r\n\r\n this.send = function(detail) {\r\n __.dispatchEvent(new CustomEvent(NAME, {\r\n detail\r\n }));\r\n };\r\n}\r\n\r\nfunction run_test(observable, handlers = 5, calls = 1000) {\r\n for (let i = 0; i \u003C handlers; i\u002B\u002B)\r\n observable.on(message =\u003E console.log(i, message));\r\n\r\n for (let i = 0; i \u003C calls; i\u002B\u002B)\r\n observable.send({\r\n type: \u0022hello\u0022,\r\n i\r\n });\r\n}","TestCases":[{"Name":"loop observable","Code":"run_test(new LoopObservable());","IsDeferred":false},{"Name":"EventTarget observable","Code":"run_test(new EventTargetObservable());","IsDeferred":false}]}