Changeset 206405 in webkit


Ignore:
Timestamp:
Sep 26, 2016 4:56:37 PM (8 years ago)
Author:
mark.lam@apple.com
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.
Location:
trunk/Source/JavaScriptCore
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/API/JSObjectRef.cpp

    r206267 r206405  
    310310    }
    311311    ExecState* exec = toJS(ctx);
    312     JSLockHolder locker(exec);
     312    VM& vm = exec->vm();
     313    JSLockHolder locker(vm);
     314    auto scope = DECLARE_CATCH_SCOPE(vm);
    313315
    314316    JSObject* jsObject = toJS(object);
     
    316318    JSValue jsValue = toJS(exec, value);
    317319
    318     if (attributes && !jsObject->hasProperty(exec, name)) {
    319         PropertyDescriptor desc(jsValue, attributes);
    320         jsObject->methodTable()->defineOwnProperty(jsObject, exec, name, desc, false);
    321     } else {
    322         PutPropertySlot slot(jsObject);
    323         jsObject->methodTable()->put(jsObject, exec, name, jsValue, slot);
    324     }
    325 
     320    bool doesNotHaveProperty = attributes && !jsObject->hasProperty(exec, name);
     321    if (LIKELY(!scope.exception())) {
     322        if (doesNotHaveProperty) {
     323            PropertyDescriptor desc(jsValue, attributes);
     324            jsObject->methodTable()->defineOwnProperty(jsObject, exec, name, desc, false);
     325        } else {
     326            PutPropertySlot slot(jsObject);
     327            jsObject->methodTable()->put(jsObject, exec, name, jsValue, slot);
     328        }
     329    }
    326330    handleExceptionIfNeeded(exec, exception);
    327331}
  • trunk/Source/JavaScriptCore/ChangeLog

    r206401 r206405  
     12016-09-26  Mark Lam  <mark.lam@apple.com>
     2
     3        Add some needed CatchScopes in code that should not throw.
     4        https://bugs.webkit.org/show_bug.cgi?id=162584
     5
     6        Reviewed by Keith Miller.
     7
     8        * API/JSObjectRef.cpp:
     9        (JSObjectSetProperty):
     10        - This function already handles exceptions in its own way.  We're honoring this
     11          contract and catching exceptions and passing it to the handler.
     12
     13        * interpreter/Interpreter.cpp:
     14        (JSC::notifyDebuggerOfUnwinding):
     15        - The debugger should not be throwing any exceptions.
     16
     17        * jsc.cpp:
     18        (runJSC):
     19        - the buck stops here.  There's no reason an exception should propagate past here.
     20
     21        * profiler/ProfilerDatabase.cpp:
     22        (JSC::Profiler::Database::save):
     23        - If an exception was thrown while saving the database, there's nothing we can
     24          really do about it anyway.  Just fail nicely and return false.  This is in line
     25          with existing error checking code in Database::save() that returns false if
     26          it's not able to open the file to save to.
     27
     28        * runtime/ExceptionHelpers.cpp:
     29        (JSC::createError):
     30        - If we're not able to stringify the error value, then we'll just use the
     31          provided message as the error string.  It doesn't make sense to have the
     32          Error factory throw an exception that shadows the intended exception that the
     33          client probably wants to throw (assuming that that's why the client is creating
     34          this Error object).
     35
     36        * runtime/JSModuleLoader.cpp:
     37        (JSC::JSModuleLoader::finishCreation):
     38        - The existing code already RELEASE_ASSERT that no exception was thrown.
     39          Hence, it's appropriate to use a CatchScope here.
     40
     41        * runtime/SamplingProfiler.cpp:
     42        (JSC::SamplingProfiler::StackFrame::nameFromCallee):
     43        - The sampling profiler is doing a VMInquiry get here.  It should never throw an
     44          exception.  Hence, we'll just use a CatchScope and assert accordingly.
     45
    1462016-09-26  Mark Lam  <mark.lam@apple.com>
    247
  • trunk/Source/JavaScriptCore/interpreter/Interpreter.cpp

    r206401 r206405  
    584584{
    585585    VM& vm = callFrame->vm();
    586     auto throwScope = DECLARE_THROW_SCOPE(vm);
     586    auto catchScope = DECLARE_CATCH_SCOPE(vm);
    587587    if (Debugger* debugger = callFrame->vmEntryGlobalObject()->debugger()) {
    588588        SuspendExceptionScope scope(&vm);
     
    591591        else
    592592            debugger->didExecuteProgram(callFrame);
    593         ASSERT_UNUSED(throwScope, !throwScope.exception());
     593        ASSERT_UNUSED(catchScope, !catchScope.exception());
    594594    }
    595595}
  • trunk/Source/JavaScriptCore/jsc.cpp

    r206386 r206405  
    25402540{
    25412541    JSLockHolder locker(vm);
     2542    auto scope = DECLARE_CATCH_SCOPE(*vm);
    25422543
    25432544    int result;
     
    25462547
    25472548    GlobalObject* globalObject = GlobalObject::create(*vm, GlobalObject::createStructure(*vm, jsNull()), options.m_arguments);
     2549    RETURN_IF_EXCEPTION(scope, 3);
     2550
    25482551    bool success = runWithScripts(globalObject, options.m_scripts, options.m_uncaughtExceptionName, options.m_alwaysDumpUncaughtException, options.m_dump, options.m_module);
    25492552    if (options.m_interactive && success)
  • trunk/Source/JavaScriptCore/profiler/ProfilerDatabase.cpp

    r206386 r206405  
    135135bool Database::save(const char* filename) const
    136136{
     137    auto scope = DECLARE_CATCH_SCOPE(m_vm);
    137138    auto out = FilePrintStream::open(filename, "w");
    138139    if (!out)
    139140        return false;
    140141   
    141     out->print(toJSON());
     142    String data = toJSON();
     143    if (UNLIKELY(scope.exception())) {
     144        scope.clearException();
     145        return false;
     146    }
     147    out->print(data);
    142148    return true;
    143149}
  • trunk/Source/JavaScriptCore/runtime/ExceptionHelpers.cpp

    r205198 r206405  
    237237JSObject* createError(ExecState* exec, JSValue value, const String& message, ErrorInstance::SourceAppender appender)
    238238{
     239    VM& vm = exec->vm();
     240    auto scope = DECLARE_CATCH_SCOPE(vm);
     241
    239242    String errorMessage = makeString(errorDescriptionForValue(exec, value)->value(exec), ' ', message);
     243    if (UNLIKELY(scope.exception())) {
     244        scope.clearException();
     245        errorMessage = message;
     246    }
    240247    JSObject* exception = createTypeError(exec, errorMessage, appender, runtimeTypeForValue(value));
    241248    ASSERT(exception->isErrorInstance());
  • trunk/Source/JavaScriptCore/runtime/JSModuleLoader.cpp

    r205569 r206405  
    5858void JSModuleLoader::finishCreation(ExecState* exec, VM& vm, JSGlobalObject* globalObject)
    5959{
     60    auto scope = DECLARE_CATCH_SCOPE(vm);
     61
    6062    Base::finishCreation(vm);
    6163    ASSERT(inherits(info()));
    62     auto scope = DECLARE_THROW_SCOPE(vm);
    6364    JSMap* map = JSMap::create(exec, vm, globalObject->mapStructure());
    6465    RELEASE_ASSERT(!scope.exception());
  • trunk/Source/JavaScriptCore/runtime/SamplingProfiler.cpp

    r206267 r206405  
    592592        return String();
    593593
     594    auto scope = DECLARE_CATCH_SCOPE(vm);
    594595    ExecState* exec = callee->globalObject()->globalExec();
    595596    auto getPropertyIfPureOperation = [&] (const Identifier& ident) -> String {
    596597        PropertySlot slot(callee, PropertySlot::InternalMethodType::VMInquiry);
    597598        PropertyName propertyName(ident);
    598         if (callee->getPropertySlot(exec, propertyName, slot)) {
     599        bool hasProperty = callee->getPropertySlot(exec, propertyName, slot);
     600        ASSERT_UNUSED(scope, !scope.exception());
     601        if (hasProperty) {
    599602            if (slot.isValue()) {
    600603                JSValue nameValue = slot.getValue(exec, propertyName);
Note: See TracChangeset for help on using the changeset viewer.