Skip to content

Commit 8054931

Browse files
JosephPecorarowebkit-commit-queue
authored andcommitted
Web Inspector: JSContext inspection provide a way to opt-out of including Native Call Stacks in Exception traces reported to Web Inspector
https://bugs.webkit.org/show_bug.cgi?id=131186 Patch by Joseph Pecoraro <pecoraro@apple.com> on 2014-04-03 Reviewed by Geoffrey Garen. * API/JSContextPrivate.h: * API/JSContext.mm: (-[JSContext _includesNativeCallStackWhenReportingExceptions]): (-[JSContext _setIncludesNativeCallStackWhenReportingExceptions:]): JSContext ObjC SPI to opt-out of including native call stacks in exceptions. * API/JSContextRefPrivate.h: * API/JSContextRef.cpp: (JSGlobalContextGetIncludesNativeCallStackWhenReportingExceptions): (JSGlobalContextSetIncludesNativeCallStackWhenReportingExceptions): JSContext C SPI to opt-out of including native call stacks in exceptions. * inspector/JSGlobalObjectInspectorController.h: * inspector/JSGlobalObjectInspectorController.cpp: (Inspector::JSGlobalObjectInspectorController::JSGlobalObjectInspectorController): (Inspector::JSGlobalObjectInspectorController::reportAPIException): Only include the native call stack if the setting is enabled. It is enabled by default. Canonical link: https://commits.webkit.org/149254@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@166756 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent 074464c commit 8054931

7 files changed

Lines changed: 108 additions & 1 deletion

File tree

‎Source/JavaScriptCore/API/JSContext.mm‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,16 @@ - (void)_setRemoteInspectionEnabled:(BOOL)enabled
213213
JSGlobalContextSetRemoteInspectionEnabled(m_context, enabled);
214214
}
215215

216+
- (BOOL)_includesNativeCallStackWhenReportingExceptions
217+
{
218+
return JSGlobalContextGetIncludesNativeCallStackWhenReportingExceptions(m_context);
219+
}
220+
221+
- (void)_setIncludesNativeCallStackWhenReportingExceptions:(BOOL)includeNativeCallStack
222+
{
223+
JSGlobalContextSetIncludesNativeCallStackWhenReportingExceptions(m_context, includeNativeCallStack);
224+
}
225+
216226
@end
217227

218228
@implementation JSContext(SubscriptSupport)

‎Source/JavaScriptCore/API/JSContextPrivate.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@
3838
*/
3939
@property (setter=_setRemoteInspectionEnabled:) BOOL _remoteInspectionEnabled NS_AVAILABLE(10_10, 8_0);
4040

41+
/*!
42+
@property
43+
@discussion Set whether or not the native call stack is included when reporting exceptions. Default value is YES.
44+
*/
45+
@property (setter=_setIncludesNativeCallStackWhenReportingExceptions:) BOOL _includesNativeCallStackWhenReportingExceptions NS_AVAILABLE(10_10, 8_0);
46+
4147
@end
4248

4349
#endif

‎Source/JavaScriptCore/API/JSContextRef.cpp‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@
4040
#include <wtf/text/StringBuilder.h>
4141
#include <wtf/text/StringHash.h>
4242

43+
#if ENABLE(REMOTE_INSPECTOR)
44+
#include "JSGlobalObjectInspectorController.h"
45+
#endif
46+
4347
#if OS(DARWIN)
4448
#include <mach-o/dyld.h>
4549

@@ -320,3 +324,42 @@ void JSGlobalContextSetRemoteInspectionEnabled(JSGlobalContextRef ctx, bool enab
320324

321325
exec->vmEntryGlobalObject()->setRemoteDebuggingEnabled(enabled);
322326
}
327+
328+
bool JSGlobalContextGetIncludesNativeCallStackWhenReportingExceptions(JSGlobalContextRef ctx)
329+
{
330+
#if ENABLE(REMOTE_INSPECTOR)
331+
if (!ctx) {
332+
ASSERT_NOT_REACHED();
333+
return false;
334+
}
335+
336+
ExecState* exec = toJS(ctx);
337+
JSLockHolder lock(exec);
338+
339+
JSGlobalObject* globalObject = exec->vmEntryGlobalObject();
340+
return globalObject->inspectorController().includesNativeCallStackWhenReportingExceptions();
341+
#else
342+
UNUSED_PARAM(ctx);
343+
return false;
344+
#endif
345+
}
346+
347+
void JSGlobalContextSetIncludesNativeCallStackWhenReportingExceptions(JSGlobalContextRef ctx, bool includesNativeCallStack)
348+
{
349+
#if ENABLE(REMOTE_INSPECTOR)
350+
if (!ctx) {
351+
ASSERT_NOT_REACHED();
352+
return;
353+
}
354+
355+
ExecState* exec = toJS(ctx);
356+
JSLockHolder lock(exec);
357+
358+
JSGlobalObject* globalObject = exec->vmEntryGlobalObject();
359+
globalObject->inspectorController().setIncludesNativeCallStackWhenReportingExceptions(includesNativeCallStack);
360+
#else
361+
UNUSED_PARAM(ctx);
362+
UNUSED_PARAM(includesNativeCallStack);
363+
#endif
364+
}
365+

‎Source/JavaScriptCore/API/JSContextRefPrivate.h‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,23 @@ JS_EXPORT bool JSGlobalContextGetRemoteInspectionEnabled(JSGlobalContextRef ctx)
111111
*/
112112
JS_EXPORT void JSGlobalContextSetRemoteInspectionEnabled(JSGlobalContextRef ctx, bool enabled) CF_AVAILABLE(10_10, 8_0);
113113

114+
/*!
115+
@function
116+
@abstract Gets the include native call stack when reporting exceptions setting for a context.
117+
@param ctx The JSGlobalContext whose setting you want to get.
118+
@result The value of the setting, true if remote inspection is enabled, otherwise false.
119+
@discussion This setting is true by default.
120+
*/
121+
JS_EXPORT bool JSGlobalContextGetIncludesNativeCallStackWhenReportingExceptions(JSGlobalContextRef ctx) CF_AVAILABLE(10_10, 8_0);
122+
123+
/*!
124+
@function
125+
@abstract Sets the include native call stack when reporting exceptions setting for a context.
126+
@param ctx The JSGlobalContext that you want to change.
127+
@param includeNativeCallStack The new value of the setting for the context.
128+
*/
129+
JS_EXPORT void JSGlobalContextSetIncludesNativeCallStackWhenReportingExceptions(JSGlobalContextRef ctx, bool includesNativeCallStack) CF_AVAILABLE(10_10, 8_0);
130+
114131
#ifdef __cplusplus
115132
}
116133
#endif

‎Source/JavaScriptCore/ChangeLog‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,28 @@
1+
2014-04-03 Joseph Pecoraro <pecoraro@apple.com>
2+
3+
Web Inspector: JSContext inspection provide a way to opt-out of including Native Call Stacks in Exception traces reported to Web Inspector
4+
https://bugs.webkit.org/show_bug.cgi?id=131186
5+
6+
Reviewed by Geoffrey Garen.
7+
8+
* API/JSContextPrivate.h:
9+
* API/JSContext.mm:
10+
(-[JSContext _includesNativeCallStackWhenReportingExceptions]):
11+
(-[JSContext _setIncludesNativeCallStackWhenReportingExceptions:]):
12+
JSContext ObjC SPI to opt-out of including native call stacks in exceptions.
13+
14+
* API/JSContextRefPrivate.h:
15+
* API/JSContextRef.cpp:
16+
(JSGlobalContextGetIncludesNativeCallStackWhenReportingExceptions):
17+
(JSGlobalContextSetIncludesNativeCallStackWhenReportingExceptions):
18+
JSContext C SPI to opt-out of including native call stacks in exceptions.
19+
20+
* inspector/JSGlobalObjectInspectorController.h:
21+
* inspector/JSGlobalObjectInspectorController.cpp:
22+
(Inspector::JSGlobalObjectInspectorController::JSGlobalObjectInspectorController):
23+
(Inspector::JSGlobalObjectInspectorController::reportAPIException):
24+
Only include the native call stack if the setting is enabled. It is enabled by default.
25+
126
2014-04-03 Mark Lam <mark.lam@apple.com>
227

328
Fix bit rot in ARMv7 JIT probe mechanism.

‎Source/JavaScriptCore/inspector/JSGlobalObjectInspectorController.cpp‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ JSGlobalObjectInspectorController::JSGlobalObjectInspectorController(JSGlobalObj
5555
: m_globalObject(globalObject)
5656
, m_injectedScriptManager(std::make_unique<InjectedScriptManager>(*this, InjectedScriptHost::create()))
5757
, m_inspectorFrontendChannel(nullptr)
58+
, m_includeNativeCallStackWithExceptions(true)
5859
{
5960
auto runtimeAgent = std::make_unique<JSGlobalObjectRuntimeAgent>(m_injectedScriptManager.get(), m_globalObject);
6061
auto consoleAgent = std::make_unique<JSGlobalObjectConsoleAgent>(m_injectedScriptManager.get());
@@ -147,7 +148,8 @@ void JSGlobalObjectInspectorController::reportAPIException(ExecState* exec, JSVa
147148
ErrorHandlingScope errorScope(exec->vm());
148149

149150
RefPtr<ScriptCallStack> callStack = createScriptCallStackFromException(exec, exception, ScriptCallStack::maxCallStackSizeToCapture);
150-
appendAPIBacktrace(callStack.get());
151+
if (includesNativeCallStackWhenReportingExceptions())
152+
appendAPIBacktrace(callStack.get());
151153

152154
// FIXME: <http://webkit.org/b/115087> Web Inspector: Should not evaluate JavaScript handling exceptions
153155
// If this is a custom exception object, call toString on it to try and get a nice string representation for the exception.

‎Source/JavaScriptCore/inspector/JSGlobalObjectInspectorController.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ class JSGlobalObjectInspectorController final : public InspectorEnvironment {
6464

6565
void globalObjectDestroyed();
6666

67+
bool includesNativeCallStackWhenReportingExceptions() const { return m_includeNativeCallStackWithExceptions; }
68+
void setIncludesNativeCallStackWhenReportingExceptions(bool includesNativeCallStack) { m_includeNativeCallStackWithExceptions = includesNativeCallStack; }
69+
6770
void reportAPIException(JSC::ExecState*, JSC::JSValue exception);
6871

6972
JSC::ConsoleClient* consoleClient() const;
@@ -85,6 +88,7 @@ class JSGlobalObjectInspectorController final : public InspectorEnvironment {
8588
InspectorAgentRegistry m_agents;
8689
InspectorFrontendChannel* m_inspectorFrontendChannel;
8790
RefPtr<InspectorBackendDispatcher> m_inspectorBackendDispatcher;
91+
bool m_includeNativeCallStackWithExceptions;
8892
};
8993

9094
} // namespace Inspector

0 commit comments

Comments
 (0)