ScriptTrace.h (2210B)
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 mozilla_dom_ScriptTrace_h 8 #define mozilla_dom_ScriptTrace_h 9 10 #include "js/loader/LoadedScript.h" // JS::loader::LoadedScript 11 #include "js/loader/ScriptLoadRequest.h" // JS::loader::ScriptLoadRequest 12 #include "mozilla/StaticPrefs_dom.h" 13 14 // This macro is used to wrap a tracing mechanism which is scheduling events 15 // which are then used by the JavaScript code of test cases to track the code 16 // path to verify the optimizations are working as expected. 17 #define TRACE_FOR_TEST(requestOrScript, str) \ 18 PR_BEGIN_MACRO \ 19 mozilla::dom::script::TestingNotifyObserver(requestOrScript, str); \ 20 PR_END_MACRO 21 22 #define TRACE_FOR_TEST_0(str) \ 23 PR_BEGIN_MACRO \ 24 mozilla::dom::script::TestingNotifyObserver(str); \ 25 PR_END_MACRO 26 27 namespace mozilla::dom::script { 28 29 void TestingNotifyObserver(JS::loader::ScriptLoadRequest* aRequest, 30 JS::loader::LoadedScript* aLoadedScript, 31 const char* aEvent); 32 33 inline void TestingNotifyObserver(JS::loader::LoadedScript* aLoadedScript, 34 const char* aEvent) { 35 if (!StaticPrefs::dom_expose_test_interfaces()) { 36 return; 37 } 38 39 TestingNotifyObserver(nullptr, aLoadedScript, aEvent); 40 } 41 42 inline void TestingNotifyObserver(JS::loader::ScriptLoadRequest* aRequest, 43 const char* aEvent) { 44 if (!StaticPrefs::dom_expose_test_interfaces()) { 45 return; 46 } 47 48 TestingNotifyObserver(aRequest, aRequest->getLoadedScript(), aEvent); 49 } 50 51 inline void TestingNotifyObserver(const char* aEvent) { 52 if (!StaticPrefs::dom_expose_test_interfaces()) { 53 return; 54 } 55 56 TestingNotifyObserver(nullptr, nullptr, aEvent); 57 } 58 59 } // namespace mozilla::dom::script 60 61 #endif // mozilla_dom_ScriptTrace_h