DOMEventDispatch.h (2336B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- 2 * vim: set ts=8 sts=2 et sw=2 tw=80: 3 * This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef js_DOMEventDispatch_h 8 #define js_DOMEventDispatch_h 9 10 #include "js/TypeDecls.h" 11 12 namespace JS { 13 14 /** 15 * Callback type for DOM event dispatching from SpiderMonkey. 16 * 17 * Current events dispatched include JIT compilation steps during instantiation: 18 * - "omt_eager_baseline_function" when functions are queued for compilation 19 * - "omt_eager_baseline_dispatch" when compilation batches are sent 20 * 21 * Function names are appended when available (e.g., 22 * "omt_eager_baseline_function: myFunc"). 23 * Anonymous functions appear without names. 24 */ 25 typedef void (*DispatchDOMEventCallback)(JSContext* cx, const char* eventType); 26 27 /** 28 * Set the DOM event dispatch callback for embedders. 29 * Allows embedders to observe internal SpiderMonkey operations for 30 * testing/debugging. Pass nullptr to clear the callback. 31 */ 32 extern JS_PUBLIC_API void SetDispatchDOMEventCallback( 33 JSContext* cx, DispatchDOMEventCallback callback); 34 35 } /* namespace JS */ 36 37 namespace js { 38 39 /** 40 * Internal function to dispatch DOM events for testing. 41 * Calls the registered DispatchDOMEventCallback if available. 42 */ 43 extern void TestingDispatchDOMEvent(JSContext* cx, const char* eventType); 44 45 /** 46 * Internal function to dispatch DOM events with optional function information. 47 * 48 * Behavior: 49 * - If script is nullptr or lacks function: dispatches basic eventType 50 * - If function name extraction succeeds: dispatches "eventType: functionName" 51 * - If function name extraction fails: does nothing and returns. 52 */ 53 extern void TestingDispatchDOMEvent(JSContext* cx, const char* eventType, 54 JSScript* script); 55 56 } /* namespace js */ 57 58 /** 59 * Convenience macro for internal testing event dispatch. 60 * Supports both basic form and optional script parameter for function names. 61 */ 62 #define TRACE_FOR_TEST_DOM(cx, str, ...) \ 63 do { \ 64 js::TestingDispatchDOMEvent(cx, str, ##__VA_ARGS__); \ 65 } while (0) 66 67 #endif /* js_DOMEventDispatch_h */