- Revision
- 206405
- Author
- [email protected]
- Date
- 2016-09-26 16:56:37 -0700 (Mon, 26 Sep 2016)
Log Message
Add some needed CatchScopes in code that should not throw.
https://bugs.webkit.org/show_bug.cgi?id=162584
Reviewed by Keith Miller.
* API/JSObjectRef.cpp:
(JSObjectSetProperty):
- This function already handles exceptions in its own way. We're honoring this
contract and catching exceptions and passing it to the handler.
* interpreter/Interpreter.cpp:
(JSC::notifyDebuggerOfUnwinding):
- The debugger should not be throwing any exceptions.
* jsc.cpp:
(runJSC):
- the buck stops here. There's no reason an exception should propagate past here.
* profiler/ProfilerDatabase.cpp:
(JSC::Profiler::Database::save):
- If an exception was thrown while saving the database, there's nothing we can
really do about it anyway. Just fail nicely and return false. This is in line
with existing error checking code in Database::save() that returns false if
it's not able to open the file to save to.
* runtime/ExceptionHelpers.cpp:
(JSC::createError):
- If we're not able to stringify the error value, then we'll just use the
provided message as the error string. It doesn't make sense to have the
Error factory throw an exception that shadows the intended exception that the
client probably wants to throw (assuming that that's why the client is creating
this Error object).
* runtime/JSModuleLoader.cpp:
(JSC::JSModuleLoader::finishCreation):
- The existing code already RELEASE_ASSERT that no exception was thrown.
Hence, it's appropriate to use a CatchScope here.
* runtime/SamplingProfiler.cpp:
(JSC::SamplingProfiler::StackFrame::nameFromCallee):
- The sampling profiler is doing a VMInquiry get here. It should never throw an
exception. Hence, we'll just use a CatchScope and assert accordingly.
Modified Paths
Diff
Modified: trunk/Source/_javascript_Core/API/JSObjectRef.cpp (206404 => 206405)
--- trunk/Source/_javascript_Core/API/JSObjectRef.cpp 2016-09-26 23:51:17 UTC (rev 206404)
+++ trunk/Source/_javascript_Core/API/JSObjectRef.cpp 2016-09-26 23:56:37 UTC (rev 206405)
@@ -309,20 +309,24 @@
return;
}
ExecState* exec = toJS(ctx);
- JSLockHolder locker(exec);
+ VM& vm = exec->vm();
+ JSLockHolder locker(vm);
+ auto scope = DECLARE_CATCH_SCOPE(vm);
JSObject* jsObject = toJS(object);
Identifier name(propertyName->identifier(&exec->vm()));
JSValue jsValue = toJS(exec, value);
- if (attributes && !jsObject->hasProperty(exec, name)) {
- PropertyDescriptor desc(jsValue, attributes);
- jsObject->methodTable()->defineOwnProperty(jsObject, exec, name, desc, false);
- } else {
- PutPropertySlot slot(jsObject);
- jsObject->methodTable()->put(jsObject, exec, name, jsValue, slot);
+ bool doesNotHaveProperty = attributes && !jsObject->hasProperty(exec, name);
+ if (LIKELY(!scope.exception())) {
+ if (doesNotHaveProperty) {
+ PropertyDescriptor desc(jsValue, attributes);
+ jsObject->methodTable()->defineOwnProperty(jsObject, exec, name, desc, false);
+ } else {
+ PutPropertySlot slot(jsObject);
+ jsObject->methodTable()->put(jsObject, exec, name, jsValue, slot);
+ }
}
-
handleExceptionIfNeeded(exec, exception);
}
Modified: trunk/Source/_javascript_Core/ChangeLog (206404 => 206405)
--- trunk/Source/_javascript_Core/ChangeLog 2016-09-26 23:51:17 UTC (rev 206404)
+++ trunk/Source/_javascript_Core/ChangeLog 2016-09-26 23:56:37 UTC (rev 206405)
@@ -1,5 +1,50 @@
2016-09-26 Mark Lam <[email protected]>
+ Add some needed CatchScopes in code that should not throw.
+ https://bugs.webkit.org/show_bug.cgi?id=162584
+
+ Reviewed by Keith Miller.
+
+ * API/JSObjectRef.cpp:
+ (JSObjectSetProperty):
+ - This function already handles exceptions in its own way. We're honoring this
+ contract and catching exceptions and passing it to the handler.
+
+ * interpreter/Interpreter.cpp:
+ (JSC::notifyDebuggerOfUnwinding):
+ - The debugger should not be throwing any exceptions.
+
+ * jsc.cpp:
+ (runJSC):
+ - the buck stops here. There's no reason an exception should propagate past here.
+
+ * profiler/ProfilerDatabase.cpp:
+ (JSC::Profiler::Database::save):
+ - If an exception was thrown while saving the database, there's nothing we can
+ really do about it anyway. Just fail nicely and return false. This is in line
+ with existing error checking code in Database::save() that returns false if
+ it's not able to open the file to save to.
+
+ * runtime/ExceptionHelpers.cpp:
+ (JSC::createError):
+ - If we're not able to stringify the error value, then we'll just use the
+ provided message as the error string. It doesn't make sense to have the
+ Error factory throw an exception that shadows the intended exception that the
+ client probably wants to throw (assuming that that's why the client is creating
+ this Error object).
+
+ * runtime/JSModuleLoader.cpp:
+ (JSC::JSModuleLoader::finishCreation):
+ - The existing code already RELEASE_ASSERT that no exception was thrown.
+ Hence, it's appropriate to use a CatchScope here.
+
+ * runtime/SamplingProfiler.cpp:
+ (JSC::SamplingProfiler::StackFrame::nameFromCallee):
+ - The sampling profiler is doing a VMInquiry get here. It should never throw an
+ exception. Hence, we'll just use a CatchScope and assert accordingly.
+
+2016-09-26 Mark Lam <[email protected]>
+
Exception unwinding code should use a CatchScope instead of a ThrowScope.
https://bugs.webkit.org/show_bug.cgi?id=162583
Modified: trunk/Source/_javascript_Core/interpreter/Interpreter.cpp (206404 => 206405)
--- trunk/Source/_javascript_Core/interpreter/Interpreter.cpp 2016-09-26 23:51:17 UTC (rev 206404)
+++ trunk/Source/_javascript_Core/interpreter/Interpreter.cpp 2016-09-26 23:56:37 UTC (rev 206405)
@@ -583,7 +583,7 @@
ALWAYS_INLINE static void notifyDebuggerOfUnwinding(CallFrame* callFrame)
{
VM& vm = callFrame->vm();
- auto throwScope = DECLARE_THROW_SCOPE(vm);
+ auto catchScope = DECLARE_CATCH_SCOPE(vm);
if (Debugger* debugger = callFrame->vmEntryGlobalObject()->debugger()) {
SuspendExceptionScope scope(&vm);
if (jsDynamicCast<JSFunction*>(callFrame->callee()))
@@ -590,7 +590,7 @@
debugger->returnEvent(callFrame);
else
debugger->didExecuteProgram(callFrame);
- ASSERT_UNUSED(throwScope, !throwScope.exception());
+ ASSERT_UNUSED(catchScope, !catchScope.exception());
}
}
Modified: trunk/Source/_javascript_Core/jsc.cpp (206404 => 206405)
--- trunk/Source/_javascript_Core/jsc.cpp 2016-09-26 23:51:17 UTC (rev 206404)
+++ trunk/Source/_javascript_Core/jsc.cpp 2016-09-26 23:56:37 UTC (rev 206405)
@@ -2539,6 +2539,7 @@
static int NEVER_INLINE runJSC(VM* vm, CommandLine options)
{
JSLockHolder locker(vm);
+ auto scope = DECLARE_CATCH_SCOPE(*vm);
int result;
if (options.m_profile && !vm->m_perBytecodeProfiler)
@@ -2545,6 +2546,8 @@
vm->m_perBytecodeProfiler = std::make_unique<Profiler::Database>(*vm);
GlobalObject* globalObject = GlobalObject::create(*vm, GlobalObject::createStructure(*vm, jsNull()), options.m_arguments);
+ RETURN_IF_EXCEPTION(scope, 3);
+
bool success = runWithScripts(globalObject, options.m_scripts, options.m_uncaughtExceptionName, options.m_alwaysDumpUncaughtException, options.m_dump, options.m_module);
if (options.m_interactive && success)
runInteractive(globalObject);
Modified: trunk/Source/_javascript_Core/profiler/ProfilerDatabase.cpp (206404 => 206405)
--- trunk/Source/_javascript_Core/profiler/ProfilerDatabase.cpp 2016-09-26 23:51:17 UTC (rev 206404)
+++ trunk/Source/_javascript_Core/profiler/ProfilerDatabase.cpp 2016-09-26 23:56:37 UTC (rev 206405)
@@ -134,11 +134,17 @@
bool Database::save(const char* filename) const
{
+ auto scope = DECLARE_CATCH_SCOPE(m_vm);
auto out = FilePrintStream::open(filename, "w");
if (!out)
return false;
- out->print(toJSON());
+ String data = ""
+ if (UNLIKELY(scope.exception())) {
+ scope.clearException();
+ return false;
+ }
+ out->print(data);
return true;
}
Modified: trunk/Source/_javascript_Core/runtime/ExceptionHelpers.cpp (206404 => 206405)
--- trunk/Source/_javascript_Core/runtime/ExceptionHelpers.cpp 2016-09-26 23:51:17 UTC (rev 206404)
+++ trunk/Source/_javascript_Core/runtime/ExceptionHelpers.cpp 2016-09-26 23:56:37 UTC (rev 206405)
@@ -236,7 +236,14 @@
JSObject* createError(ExecState* exec, JSValue value, const String& message, ErrorInstance::SourceAppender appender)
{
+ VM& vm = exec->vm();
+ auto scope = DECLARE_CATCH_SCOPE(vm);
+
String errorMessage = makeString(errorDescriptionForValue(exec, value)->value(exec), ' ', message);
+ if (UNLIKELY(scope.exception())) {
+ scope.clearException();
+ errorMessage = message;
+ }
JSObject* exception = createTypeError(exec, errorMessage, appender, runtimeTypeForValue(value));
ASSERT(exception->isErrorInstance());
return exception;
Modified: trunk/Source/_javascript_Core/runtime/JSModuleLoader.cpp (206404 => 206405)
--- trunk/Source/_javascript_Core/runtime/JSModuleLoader.cpp 2016-09-26 23:51:17 UTC (rev 206404)
+++ trunk/Source/_javascript_Core/runtime/JSModuleLoader.cpp 2016-09-26 23:56:37 UTC (rev 206405)
@@ -57,9 +57,10 @@
void JSModuleLoader::finishCreation(ExecState* exec, VM& vm, JSGlobalObject* globalObject)
{
+ auto scope = DECLARE_CATCH_SCOPE(vm);
+
Base::finishCreation(vm);
ASSERT(inherits(info()));
- auto scope = DECLARE_THROW_SCOPE(vm);
JSMap* map = JSMap::create(exec, vm, globalObject->mapStructure());
RELEASE_ASSERT(!scope.exception());
putDirect(vm, Identifier::fromString(&vm, "registry"), map);
Modified: trunk/Source/_javascript_Core/runtime/SamplingProfiler.cpp (206404 => 206405)
--- trunk/Source/_javascript_Core/runtime/SamplingProfiler.cpp 2016-09-26 23:51:17 UTC (rev 206404)
+++ trunk/Source/_javascript_Core/runtime/SamplingProfiler.cpp 2016-09-26 23:56:37 UTC (rev 206405)
@@ -591,11 +591,14 @@
if (!callee)
return String();
+ auto scope = DECLARE_CATCH_SCOPE(vm);
ExecState* exec = callee->globalObject()->globalExec();
auto getPropertyIfPureOperation = [&] (const Identifier& ident) -> String {
PropertySlot slot(callee, PropertySlot::InternalMethodType::VMInquiry);
PropertyName propertyName(ident);
- if (callee->getPropertySlot(exec, propertyName, slot)) {
+ bool hasProperty = callee->getPropertySlot(exec, propertyName, slot);
+ ASSERT_UNUSED(scope, !scope.exception());
+ if (hasProperty) {
if (slot.isValue()) {
JSValue nameValue = slot.getValue(exec, propertyName);
if (isJSString(nameValue))