Introduce ExceptionScope::assertNoException() and releaseAssertNoException().
https://bugs.webkit.org/show_bug.cgi?id=171776

Reviewed by Keith Miller.

Source/JavaScriptCore:

Instead of ASSERT(!scope.exception()), we can now do scope.assertNoException().
Ditto for RELEASE_ASSERT and scope.releaseAssertNoException().  

The advantage of using ExceptionScope::assertNoException() and
releaseAssertNoException() is that if the assertion fails, these utility
functions will print the stack trace for where the unexpected exception is
detected as well as where the unexpected exception was thrown from.  This makes
it much easier to debug the source of unhandled exceptions.

* debugger/Debugger.cpp:
(JSC::Debugger::pauseIfNeeded):
* dfg/DFGOperations.cpp:
* interpreter/Interpreter.cpp:
(JSC::eval):
(JSC::notifyDebuggerOfUnwinding):
(JSC::Interpreter::executeProgram):
(JSC::Interpreter::executeCall):
(JSC::Interpreter::executeConstruct):
(JSC::Interpreter::prepareForRepeatCall):
(JSC::Interpreter::execute):
(JSC::Interpreter::debug):
* interpreter/ShadowChicken.cpp:
(JSC::ShadowChicken::functionsOnStack):
* jsc.cpp:
(GlobalObject::moduleLoaderResolve):
(GlobalObject::moduleLoaderFetch):
(functionGenerateHeapSnapshot):
(functionSamplingProfilerStackTraces):
(box):
(runWithScripts):
* runtime/AbstractModuleRecord.cpp:
(JSC::AbstractModuleRecord::finishCreation):
* runtime/ArrayPrototype.cpp:
(JSC::ArrayPrototype::tryInitializeSpeciesWatchpoint):
* runtime/Completion.cpp:
(JSC::rejectPromise):
* runtime/ErrorInstance.cpp:
(JSC::ErrorInstance::sanitizedToString):
* runtime/ExceptionHelpers.cpp:
(JSC::createError):
* runtime/ExceptionScope.cpp:
(JSC::ExceptionScope::unexpectedExceptionMessage):
* runtime/ExceptionScope.h:
(JSC::ExceptionScope::assertNoException):
(JSC::ExceptionScope::releaseAssertNoException):
(JSC::ExceptionScope::unexpectedExceptionMessage):
* runtime/GenericArgumentsInlines.h:
(JSC::GenericArguments<Type>::defineOwnProperty):
* runtime/IntlCollator.cpp:
(JSC::IntlCollator::createCollator):
(JSC::IntlCollator::resolvedOptions):
* runtime/IntlDateTimeFormat.cpp:
(JSC::IntlDateTimeFormat::resolvedOptions):
(JSC::IntlDateTimeFormat::format):
* runtime/IntlNumberFormat.cpp:
(JSC::IntlNumberFormat::createNumberFormat):
(JSC::IntlNumberFormat::resolvedOptions):
* runtime/JSCJSValue.cpp:
(JSC::JSValue::putToPrimitiveByIndex):
* runtime/JSGenericTypedArrayViewPrototypeFunctions.h:
(JSC::genericTypedArrayViewProtoFuncIncludes):
(JSC::genericTypedArrayViewProtoFuncIndexOf):
(JSC::genericTypedArrayViewProtoFuncLastIndexOf):
(JSC::genericTypedArrayViewPrivateFuncSubarrayCreate):
* runtime/JSGlobalObject.cpp:
(JSC::JSGlobalObject::init):
* runtime/JSGlobalObjectFunctions.cpp:
(JSC::globalFuncHostPromiseRejectionTracker):
* runtime/JSModuleEnvironment.cpp:
(JSC::JSModuleEnvironment::getOwnPropertySlot):
* runtime/JSModuleLoader.cpp:
(JSC::JSModuleLoader::finishCreation):
* runtime/JSModuleNamespaceObject.cpp:
(JSC::JSModuleNamespaceObject::finishCreation):
* runtime/JSONObject.cpp:
(JSC::Stringifier::toJSON):
* runtime/JSObject.cpp:
(JSC::JSObject::ordinaryToPrimitive):
* runtime/JSPropertyNameEnumerator.h:
(JSC::propertyNameEnumerator):
* runtime/ObjectConstructor.cpp:
(JSC::objectConstructorGetOwnPropertyDescriptors):
(JSC::objectConstructorDefineProperty):
* runtime/ObjectPrototype.cpp:
(JSC::objectProtoFuncHasOwnProperty):
* runtime/ProgramExecutable.cpp:
(JSC::ProgramExecutable::initializeGlobalProperties):
* runtime/ReflectObject.cpp:
(JSC::reflectObjectDefineProperty):
* runtime/SamplingProfiler.cpp:
(JSC::SamplingProfiler::StackFrame::nameFromCallee):
* runtime/StringPrototype.cpp:
(JSC::stringProtoFuncRepeatCharacter):
* runtime/TemplateRegistry.cpp:
(JSC::TemplateRegistry::getTemplateObject):
* runtime/VM.cpp:
(JSC::VM::throwException):
* runtime/VM.h:
(JSC::VM::nativeStackTraceOfLastThrow):
(JSC::VM::clearException):
* wasm/WasmB3IRGenerator.cpp:
* wasm/js/JSWebAssemblyInstance.cpp:
(JSC::JSWebAssemblyInstance::create):

Source/WebCore:

No new tests because there's no behavior change in functionality.  We're only
refactoring the code to use the new assertion utility function.

* Modules/plugins/QuickTimePluginReplacement.mm:
(WebCore::QuickTimePluginReplacement::installReplacement):
* bindings/js/JSCryptoKeySerializationJWK.cpp:
(WebCore::getJSArrayFromJSON):
(WebCore::getStringFromJSON):
(WebCore::getBooleanFromJSON):
* bindings/js/JSCustomElementRegistryCustom.cpp:
(WebCore::JSCustomElementRegistry::whenDefined):
* bindings/js/JSDOMExceptionHandling.cpp:
(WebCore::propagateExceptionSlowPath):
(WebCore::throwNotSupportedError):
(WebCore::throwInvalidStateError):
(WebCore::throwSecurityError):
(WebCore::throwDOMSyntaxError):
(WebCore::throwDataCloneError):
(WebCore::throwIndexSizeError):
(WebCore::throwTypeMismatchError):
* bindings/js/JSDOMGlobalObject.cpp:
(WebCore::makeThisTypeErrorForBuiltins):
(WebCore::makeGetterTypeErrorForBuiltins):
* bindings/js/JSDOMGlobalObjectTask.cpp:
* bindings/js/JSDOMPromise.h:
(WebCore::callPromiseFunction):
* bindings/js/JSDOMWindowBase.cpp:
(WebCore::JSDOMWindowMicrotaskCallback::call):
* bindings/js/JSMainThreadExecState.h:
(WebCore::JSMainThreadExecState::~JSMainThreadExecState):
* bindings/js/ReadableStreamDefaultController.cpp:
(WebCore::ReadableStreamDefaultController::isControlledReadableStreamLocked):
* bindings/js/ReadableStreamDefaultController.h:
(WebCore::ReadableStreamDefaultController::enqueue):
* bindings/js/SerializedScriptValue.cpp:
(WebCore::CloneDeserializer::readTerminal):
* bindings/scripts/CodeGeneratorJS.pm:
(GenerateSerializerFunction):
* bindings/scripts/test/JS/JSTestNode.cpp:
(WebCore::JSTestNode::serialize):
* bindings/scripts/test/JS/JSTestObj.cpp:
(WebCore::JSTestObj::serialize):
* bindings/scripts/test/JS/JSTestSerialization.cpp:
(WebCore::JSTestSerialization::serialize):
* bindings/scripts/test/JS/JSTestSerializationInherit.cpp:
(WebCore::JSTestSerializationInherit::serialize):
* bindings/scripts/test/JS/JSTestSerializationInheritFinal.cpp:
(WebCore::JSTestSerializationInheritFinal::serialize):
* contentextensions/ContentExtensionParser.cpp:
(WebCore::ContentExtensions::getTypeFlags):
* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::didAddUserAgentShadowRoot):
(WebCore::HTMLMediaElement::updateMediaControlsAfterPresentationModeChange):
(WebCore::HTMLMediaElement::getCurrentMediaControlsStatus):
* html/HTMLPlugInImageElement.cpp:
(WebCore::HTMLPlugInImageElement::didAddUserAgentShadowRoot):

Source/WTF:

1. Add an option to skip some number of top frames when capturing the StackTrace.
2. Add an option to use an indentation string when dumping the StackTrace.

* wtf/StackTrace.cpp:
(WTF::StackTrace::captureStackTrace):
(WTF::StackTrace::dump):
* wtf/StackTrace.h:



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@216428 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/JavaScriptCore/runtime/SamplingProfiler.cpp b/Source/JavaScriptCore/runtime/SamplingProfiler.cpp
index 90ddd22..7cd873e 100644
--- a/Source/JavaScriptCore/runtime/SamplingProfiler.cpp
+++ b/Source/JavaScriptCore/runtime/SamplingProfiler.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016 Apple Inc. All rights reserved.
+ * Copyright (C) 2016-2017 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -719,7 +719,7 @@
         PropertySlot slot(callee, PropertySlot::InternalMethodType::VMInquiry);
         PropertyName propertyName(ident);
         bool hasProperty = callee->getPropertySlot(exec, propertyName, slot);
-        ASSERT_UNUSED(scope, !scope.exception());
+        scope.assertNoException();
         if (hasProperty) {
             if (slot.isValue()) {
                 JSValue nameValue = slot.getValue(exec, propertyName);