mozjs78/CodeCoverage.patch
František Zatloukal 0fa6e64112 gjs build fixes
2020-08-17 20:24:51 +02:00

108 lines
3.8 KiB
Diff

From e5a2eb99f653ae03c67e536df1d55d265a0a1605 Mon Sep 17 00:00:00 2001
From: Evan Welsh <contact@evanwelsh.com>
Date: Mon, 10 Aug 2020 13:17:36 -0500
Subject: [PATCH] Bug 1654696 - Implement code coverage JSAPI.
r=nbp,ptomato,jwalden
---
js/public/experimental/CodeCoverage.h | 25 +++++++++++++++++++++++++
js/src/jsfriendapi.cpp | 3 +++
js/src/moz.build | 1 +
js/src/shell/js.cpp | 11 ++++++-----
4 files changed, 35 insertions(+), 5 deletions(-)
create mode 100644 js/public/experimental/CodeCoverage.h
diff --git a/js/public/experimental/CodeCoverage.h b/js/public/experimental/CodeCoverage.h
new file mode 100644
index 000000000..06cc0c9ca
--- /dev/null
+++ b/js/public/experimental/CodeCoverage.h
@@ -0,0 +1,25 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ * vim: set ts=8 sts=2 et sw=2 tw=80:
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef js_experimental_CodeCoverage_h
+#define js_experimental_CodeCoverage_h
+
+#include "jstypes.h" // JS_FRIEND_API
+
+struct JS_PUBLIC_API JSContext;
+
+namespace js {
+
+/**
+ * Enable the collection of lcov code coverage metrics.
+ * Must be called before a runtime is created and before any calls to
+ * GetCodeCoverageSummary.
+ */
+extern JS_FRIEND_API void EnableCodeCoverage();
+
+} // namespace js
+
+#endif // js_experimental_CodeCoverage_h
diff --git a/js/src/jsfriendapi.cpp b/js/src/jsfriendapi.cpp
index af7a03bd4..5f20c6576 100644
--- a/js/src/jsfriendapi.cpp
+++ b/js/src/jsfriendapi.cpp
@@ -20,6 +20,7 @@
#include "gc/PublicIterators.h"
#include "gc/WeakMap.h"
#include "js/CharacterEncoding.h"
+#include "js/experimental/CodeCoverage.h" // js::EnableCodeCoverage
#include "js/Printf.h"
#include "js/Proxy.h"
#include "js/Wrapper.h"
@@ -1465,6 +1466,8 @@ JS_FRIEND_API void js::EnableAccessValidation(JSContext* cx, bool enabled) {
cx->enableAccessValidation = enabled;
}
+JS_FRIEND_API void js::EnableCodeCoverage() { js::coverage::EnableLCov(); }
+
JS_FRIEND_API void js::SetRealmValidAccessPtr(JSContext* cx,
JS::HandleObject global,
bool* accessp) {
diff --git a/js/src/moz.build b/js/src/moz.build
index deb15d83a..b4e9e2b02 100755
--- a/js/src/moz.build
+++ b/js/src/moz.build
@@ -210,6 +210,7 @@ EXPORTS.js += [
]
EXPORTS.js.experimental += [
+ '../public/experimental/CodeCoverage.h',
'../public/experimental/SourceHook.h',
]
diff --git a/js/src/shell/js.cpp b/js/src/shell/js.cpp
index 4b3f545e6..252dd24f0 100644
--- a/js/src/shell/js.cpp
+++ b/js/src/shell/js.cpp
@@ -104,10 +104,11 @@
#include "js/CompileOptions.h"
#include "js/ContextOptions.h" // JS::ContextOptions{,Ref}
#include "js/Debug.h"
-#include "js/Equality.h" // JS::SameValue
-#include "js/ErrorReport.h" // JS::PrintError
-#include "js/Exception.h" // JS::StealPendingExceptionStack
-#include "js/experimental/SourceHook.h" // js::{Set,Forget,}SourceHook
+#include "js/Equality.h" // JS::SameValue
+#include "js/ErrorReport.h" // JS::PrintError
+#include "js/Exception.h" // JS::StealPendingExceptionStack
+#include "js/experimental/CodeCoverage.h" // js::EnableCodeCoverage
+#include "js/experimental/SourceHook.h" // js::{Set,Forget,}SourceHook
#include "js/GCVector.h"
#include "js/Initialization.h"
#include "js/JSON.h"
@@ -11416,7 +11417,7 @@ int main(int argc, char** argv, char** envp) {
enableCodeCoverage = op.getBoolOption("code-coverage");
if (enableCodeCoverage) {
- coverage::EnableLCov();
+ js::EnableCodeCoverage();
}
#ifdef JS_WITHOUT_NSPR