Changeset 185608 in webkit


Ignore:
Timestamp:
Jun 16, 2015, 1:51:04 PM (10 years ago)
Author:
mark.lam@apple.com
Message:

Use NakedPtr<Exception>& to return exception results.
https://bugs.webkit.org/show_bug.cgi?id=145870

Reviewed by Anders Carlsson and Filip Pizlo.

Source/JavaScriptCore:

Before r185259, calls into the VM takes a JSValue* exception result argument for
returning any uncaught exception that may have been thrown while executing JS code.
As a result, clients of the VM functions will declare a local JSValue exception
result which is automatically initialized to a null value (i.e. the empty value,
not the JS null value).

With r185259, the VM functions were changed to take an Exception*& exception result
instead, and the VM functions are responsible for initializing the exception result
to null if no exception is thrown.

This introduces 2 issues:

  1. the VM functions are vulnerable to modifications that may add early returns before the exception result is nullified. This can result in the exception result being used without initialization.
  1. Previously, a client could technically use the same exception result for more than one calls into the VM functions. If an earlier call sets it to a thrown value, the thrown value will stick unless a subsequent call throws a different exception.

With the new Exception*& exception result, the VM functions will always clear
the exception result before proceeding. As a result, the client's exception
result will be null after the second call even though the first call saw an
exception thrown. This is a change in the expected behavior.

To fix these issues, we'll introduce a NakedPtr smart pointer whose sole purpose
is to guarantee that the pointer is initialized. The VM functions will now take
a NakedPtr<Exception>& instead of the Exception*&. This ensures that the
exception result is initialized.

The VM functions be also reverted to only set the exception result if a new
exception is thrown.

  • API/JSBase.cpp:

(JSEvaluateScript):

  • API/JSScriptRef.cpp:
  • bindings/ScriptFunctionCall.cpp:

(Deprecated::ScriptFunctionCall::call):

  • bindings/ScriptFunctionCall.h:
  • debugger/Debugger.cpp:

(JSC::Debugger::hasBreakpoint):

  • debugger/Debugger.h:
  • debugger/DebuggerCallFrame.cpp:

(JSC::DebuggerCallFrame::thisValue):
(JSC::DebuggerCallFrame::evaluate):

  • debugger/DebuggerCallFrame.h:

(JSC::DebuggerCallFrame::isValid):

  • inspector/InjectedScriptManager.cpp:

(Inspector::InjectedScriptManager::createInjectedScript):

  • inspector/InspectorEnvironment.h:
  • inspector/JSJavaScriptCallFrame.cpp:

(Inspector::JSJavaScriptCallFrame::evaluate):

  • inspector/JavaScriptCallFrame.h:

(Inspector::JavaScriptCallFrame::vmEntryGlobalObject):
(Inspector::JavaScriptCallFrame::thisValue):
(Inspector::JavaScriptCallFrame::evaluate):

  • inspector/ScriptDebugServer.cpp:

(Inspector::ScriptDebugServer::evaluateBreakpointAction):

  • jsc.cpp:

(functionRun):
(functionLoad):
(runWithScripts):
(runInteractive):

  • runtime/CallData.cpp:

(JSC::call):

  • runtime/CallData.h:
  • runtime/Completion.cpp:

(JSC::checkSyntax):
(JSC::evaluate):

  • runtime/Completion.h:

(JSC::evaluate):

Source/WebCore:

No new WebCore tests because this functionality is already covered by existing tests.
API tests added for WTF::NakedPtr.

  • bindings/js/JSCallbackData.cpp:

(WebCore::JSCallbackData::invokeCallback):

  • bindings/js/JSCustomXPathNSResolver.cpp:

(WebCore::JSCustomXPathNSResolver::lookupNamespaceURI):

  • bindings/js/JSErrorHandler.cpp:

(WebCore::JSErrorHandler::handleEvent):

  • bindings/js/JSEventListener.cpp:

(WebCore::JSEventListener::handleEvent):

  • bindings/js/JSMainThreadExecState.cpp:

(WebCore::JSMainThreadExecState::didLeaveScriptContext):
(WebCore::functionCallHandlerFromAnyThread):
(WebCore::evaluateHandlerFromAnyThread):

  • bindings/js/JSMainThreadExecState.h:

(WebCore::JSMainThreadExecState::currentState):
(WebCore::JSMainThreadExecState::call):
(WebCore::JSMainThreadExecState::evaluate):

  • bindings/js/JSMutationCallback.cpp:

(WebCore::JSMutationCallback::call):

  • bindings/js/ScheduledAction.cpp:

(WebCore::ScheduledAction::executeFunctionInContext):

  • bindings/js/ScriptController.cpp:

(WebCore::ScriptController::evaluateInWorld):

  • bindings/js/WorkerScriptController.cpp:

(WebCore::WorkerScriptController::evaluate):
(WebCore::WorkerScriptController::setException):

  • bindings/js/WorkerScriptController.h:

(WebCore::WorkerScriptController::workerGlobalScopeWrapper):

  • bindings/objc/WebScriptObject.mm:

(-[WebScriptObject callWebScriptMethod:withArguments:]):

  • workers/WorkerGlobalScope.cpp:

(WebCore::WorkerGlobalScope::importScripts):

Source/WTF:

Introducing the NakedPtr class.

  • WTF.xcodeproj/project.pbxproj:
  • wtf/NakedPtr.h: Added.

(WTF::NakedPtr::NakedPtr):
(WTF::NakedPtr::get):
(WTF::NakedPtr::clear):
(WTF::NakedPtr::operator*):
(WTF::NakedPtr::operator->):
(WTF::NakedPtr::operator T*):
(WTF::NakedPtr::operator!):
(WTF::NakedPtr::operator bool):
(WTF::=):
(WTF::NakedPtr<T>::swap):
(WTF::swap):

Tools:

  • TestWebKitAPI/CMakeLists.txt:
  • TestWebKitAPI/TestWebKitAPI.vcxproj/TestWebKitAPI.vcxproj:
  • TestWebKitAPI/TestWebKitAPI.vcxproj/TestWebKitAPI.vcxproj.filters:
  • TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
  • TestWebKitAPI/Tests/WTF/NakedPtr.cpp: Added.

(TestWebKitAPI::TEST):
(TestWebKitAPI::nakedPtrFoo):

Location:
trunk
Files:
2 added
40 edited

Legend:

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

    r185259 r185608  
    6565    SourceCode source = makeSource(script->string(), sourceURL ? sourceURL->string() : String(), TextPosition(OrdinalNumber::fromOneBasedInt(startingLineNumber), OrdinalNumber::first()));
    6666
    67     Exception* evaluationException;
     67    NakedPtr<Exception> evaluationException;
    6868    JSValue returnValue = evaluate(globalObject->globalExec(), source, jsThisObject, evaluationException);
    6969
  • trunk/Source/JavaScriptCore/API/JSScriptRef.cpp

    r185346 r185608  
    144144        return 0;
    145145    }
    146     Exception* internalException;
     146    NakedPtr<Exception> internalException;
    147147    JSValue thisValue = thisValueRef ? toJS(exec, thisValueRef) : jsUndefined();
    148148    JSValue result = evaluate(exec, SourceCode(script), thisValue, internalException);
  • trunk/Source/JavaScriptCore/ChangeLog

    r185600 r185608  
     12015-06-16  Mark Lam  <mark.lam@apple.com>
     2
     3        Use NakedPtr<Exception>& to return exception results.
     4        https://bugs.webkit.org/show_bug.cgi?id=145870
     5
     6        Reviewed by Anders Carlsson and Filip Pizlo.
     7
     8        Before r185259, calls into the VM takes a JSValue* exception result argument for
     9        returning any uncaught exception that may have been thrown while executing JS code.
     10        As a result, clients of the VM functions will declare a local JSValue exception
     11        result which is automatically initialized to a null value (i.e. the empty value,
     12        not the JS null value).
     13
     14        With r185259, the VM functions were changed to take an Exception*& exception result
     15        instead, and the VM functions are responsible for initializing the exception result
     16        to null if no exception is thrown.
     17
     18        This introduces 2 issues:
     19
     20        1. the VM functions are vulnerable to modifications that may add early returns
     21           before the exception result is nullified.  This can result in the exception
     22           result being used without initialization.
     23
     24        2. Previously, a client could technically use the same exception result for more
     25           than one calls into the VM functions.  If an earlier call sets it to a thrown
     26           value, the thrown value will stick unless a subsequent call throws a different
     27           exception.
     28
     29           With the new Exception*& exception result, the VM functions will always clear
     30           the exception result before proceeding.  As a result, the client's exception
     31           result will be null after the second call even though the first call saw an
     32           exception thrown.  This is a change in the expected behavior.
     33
     34        To fix these issues, we'll introduce a NakedPtr smart pointer whose sole purpose
     35        is to guarantee that the pointer is initialized.  The VM functions will now take
     36        a NakedPtr<Exception>& instead of the Exception*&.  This ensures that the
     37        exception result is initialized.
     38
     39        The VM functions be also reverted to only set the exception result if a new
     40        exception is thrown.
     41
     42        * API/JSBase.cpp:
     43        (JSEvaluateScript):
     44        * API/JSScriptRef.cpp:
     45        * bindings/ScriptFunctionCall.cpp:
     46        (Deprecated::ScriptFunctionCall::call):
     47        * bindings/ScriptFunctionCall.h:
     48        * debugger/Debugger.cpp:
     49        (JSC::Debugger::hasBreakpoint):
     50        * debugger/Debugger.h:
     51        * debugger/DebuggerCallFrame.cpp:
     52        (JSC::DebuggerCallFrame::thisValue):
     53        (JSC::DebuggerCallFrame::evaluate):
     54        * debugger/DebuggerCallFrame.h:
     55        (JSC::DebuggerCallFrame::isValid):
     56        * inspector/InjectedScriptManager.cpp:
     57        (Inspector::InjectedScriptManager::createInjectedScript):
     58        * inspector/InspectorEnvironment.h:
     59        * inspector/JSJavaScriptCallFrame.cpp:
     60        (Inspector::JSJavaScriptCallFrame::evaluate):
     61        * inspector/JavaScriptCallFrame.h:
     62        (Inspector::JavaScriptCallFrame::vmEntryGlobalObject):
     63        (Inspector::JavaScriptCallFrame::thisValue):
     64        (Inspector::JavaScriptCallFrame::evaluate):
     65        * inspector/ScriptDebugServer.cpp:
     66        (Inspector::ScriptDebugServer::evaluateBreakpointAction):
     67        * jsc.cpp:
     68        (functionRun):
     69        (functionLoad):
     70        (runWithScripts):
     71        (runInteractive):
     72        * runtime/CallData.cpp:
     73        (JSC::call):
     74        * runtime/CallData.h:
     75        * runtime/Completion.cpp:
     76        (JSC::checkSyntax):
     77        (JSC::evaluate):
     78        * runtime/Completion.h:
     79        (JSC::evaluate):
     80
    1812015-06-15  Filip Pizlo  <fpizlo@apple.com>
    282
  • trunk/Source/JavaScriptCore/bindings/ScriptFunctionCall.cpp

    r185259 r185608  
    134134
    135135    JSValue result;
    136     Exception* exception;
     136    NakedPtr<Exception> exception;
    137137    if (m_callHandler)
    138138        result = m_callHandler(m_exec, function, callType, callData, thisObject, m_arguments, exception);
  • trunk/Source/JavaScriptCore/bindings/ScriptFunctionCall.h

    r185259 r185608  
    7272class JS_EXPORT_PRIVATE ScriptFunctionCall : public ScriptCallArgumentHandler {
    7373public:
    74     typedef JSC::JSValue (*ScriptFunctionCallHandler)(JSC::ExecState* exec, JSC::JSValue functionObject, JSC::CallType callType, const JSC::CallData& callData, JSC::JSValue thisValue, const JSC::ArgList& args, JSC::Exception*& exception);
     74    typedef JSC::JSValue (*ScriptFunctionCallHandler)(JSC::ExecState* exec, JSC::JSValue functionObject, JSC::CallType callType, const JSC::CallData& callData, JSC::JSValue thisValue, const JSC::ArgList& args, NakedPtr<JSC::Exception>&);
    7575    ScriptFunctionCall(const ScriptObject& thisObject, const String& name, ScriptFunctionCallHandler handler = nullptr);
    7676    ScriptValue call(bool& hadException);
  • trunk/Source/JavaScriptCore/debugger/Debugger.cpp

    r185379 r185608  
    2626#include "DebuggerCallFrame.h"
    2727#include "Error.h"
    28 
    2928#include "HeapIterationScope.h"
    3029#include "Interpreter.h"
     
    488487    TemporaryPausedState pausedState(*this);
    489488
    490     Exception* exception;
     489    NakedPtr<Exception> exception;
    491490    DebuggerCallFrame* debuggerCallFrame = currentDebuggerCallFrame();
    492491    JSValue result = debuggerCallFrame->evaluate(breakpoint->condition, exception);
  • trunk/Source/JavaScriptCore/debugger/Debugger.h

    r185259 r185608  
    3535
    3636class CodeBlock;
     37class Exception;
    3738class ExecState;
    3839class JSGlobalObject;
  • trunk/Source/JavaScriptCore/debugger/DebuggerCallFrame.cpp

    r185532 r185608  
    3333#include "DebuggerEvalEnabler.h"
    3434#include "DebuggerScope.h"
    35 #include "Exception.h"
    3635#include "Interpreter.h"
    3736#include "JSFunction.h"
     
    178177
    179178// Evaluate some JavaScript code in the scope of this frame.
    180 JSValue DebuggerCallFrame::evaluate(const String& script, Exception*& exception)
    181 {
    182     ASSERT(isValid());
    183     exception = nullptr;
     179JSValue DebuggerCallFrame::evaluate(const String& script, NakedPtr<Exception>& exception)
     180{
     181    ASSERT(isValid());
    184182    CallFrame* callFrame = m_callFrame;
    185183    if (!callFrame)
  • trunk/Source/JavaScriptCore/debugger/DebuggerCallFrame.h

    r185532 r185608  
    3232#include "DebuggerPrimitives.h"
    3333#include "Strong.h"
     34#include <wtf/NakedPtr.h>
    3435#include <wtf/PassRefPtr.h>
    3536#include <wtf/RefCounted.h>
     
    6869    JS_EXPORT_PRIVATE Type type() const;
    6970    JS_EXPORT_PRIVATE JSValue thisValue() const;
    70     JSValue evaluate(const String&, Exception*&);
     71    JSValue evaluate(const String&, NakedPtr<Exception>&);
    7172
    7273    bool isValid() const { return !!m_callFrame; }
  • trunk/Source/JavaScriptCore/inspector/InjectedScriptManager.cpp

    r185259 r185608  
    140140    JSValue globalThisValue = scriptState->globalThisValue();
    141141
    142     Exception* evaluationException;
     142    NakedPtr<Exception> evaluationException;
    143143    InspectorEvaluateHandler evaluateHandler = m_environment.evaluateHandler();
    144144    JSValue functionValue = evaluateHandler(scriptState, sourceCode, globalThisValue, evaluationException);
  • trunk/Source/JavaScriptCore/inspector/InspectorEnvironment.h

    r185259 r185608  
    4040namespace Inspector {
    4141
    42 typedef JSC::JSValue (*InspectorFunctionCallHandler)(JSC::ExecState* exec, JSC::JSValue functionObject, JSC::CallType callType, const JSC::CallData& callData, JSC::JSValue thisValue, const JSC::ArgList& args, JSC::Exception*& returnedException);
    43 typedef JSC::JSValue (*InspectorEvaluateHandler)(JSC::ExecState*, const JSC::SourceCode&, JSC::JSValue thisValue, JSC::Exception*& returnedException);
     42typedef JSC::JSValue (*InspectorFunctionCallHandler)(JSC::ExecState* exec, JSC::JSValue functionObject, JSC::CallType callType, const JSC::CallData& callData, JSC::JSValue thisValue, const JSC::ArgList& args, NakedPtr<JSC::Exception>& returnedException);
     43typedef JSC::JSValue (*InspectorEvaluateHandler)(JSC::ExecState*, const JSC::SourceCode&, JSC::JSValue thisValue, NakedPtr<JSC::Exception>& returnedException);
    4444
    4545class InspectorEnvironment {
  • trunk/Source/JavaScriptCore/inspector/JSJavaScriptCallFrame.cpp

    r185259 r185608  
    2929#include "DebuggerScope.h"
    3030#include "Error.h"
    31 #include "Exception.h"
    3231#include "JSCJSValue.h"
    3332#include "JSCellInlines.h"
     
    7776JSValue JSJavaScriptCallFrame::evaluate(ExecState* exec)
    7877{
    79     Exception* exception;
     78    NakedPtr<Exception> exception;
    8079    JSValue result = impl().evaluate(exec->argument(0).toString(exec)->value(exec), exception);
    8180    if (exception)
  • trunk/Source/JavaScriptCore/inspector/JavaScriptCallFrame.h

    r185346 r185608  
    5656
    5757    JSC::JSValue thisValue() const { return m_debuggerCallFrame->thisValue(); }
    58     JSC::JSValue evaluate(const String& script, JSC::Exception*& exception) const  { return m_debuggerCallFrame->evaluate(script, exception); }
     58    JSC::JSValue evaluate(const String& script, NakedPtr<JSC::Exception>& exception) const  { return m_debuggerCallFrame->evaluate(script, exception); }
    5959
    6060private:
  • trunk/Source/JavaScriptCore/inspector/ScriptDebugServer.cpp

    r185259 r185608  
    9595    }
    9696    case ScriptBreakpointActionTypeEvaluate: {
    97         Exception* exception;
     97        NakedPtr<Exception> exception;
    9898        debuggerCallFrame->evaluate(breakpointAction.data, exception);
    9999        if (exception)
     
    105105        break;
    106106    case ScriptBreakpointActionTypeProbe: {
    107         Exception* exception;
     107        NakedPtr<Exception> exception;
    108108        JSValue result = debuggerCallFrame->evaluate(breakpointAction.data, exception);
    109109        if (exception)
  • trunk/Source/JavaScriptCore/jsc.cpp

    r185346 r185608  
    909909        exec->vm(), Identifier::fromString(globalObject->globalExec(), "arguments"), array);
    910910
    911     Exception* exception;
     911    NakedPtr<Exception> exception;
    912912    StopWatch stopWatch;
    913913    stopWatch.start();
     
    932932    JSGlobalObject* globalObject = exec->lexicalGlobalObject();
    933933   
    934     Exception* evaluationException;
     934    NakedPtr<Exception> evaluationException;
    935935    JSValue result = evaluate(globalObject->globalExec(), jscSource(script.data(), fileName), JSValue(), evaluationException);
    936936    if (evaluationException)
     
    12951295        vm.startSampling();
    12961296
    1297         Exception* evaluationException;
     1297        NakedPtr<Exception> evaluationException;
    12981298        JSValue returnValue = evaluate(globalObject->globalExec(), jscSource(script, fileName), JSValue(), evaluationException);
    12991299        success = success && !evaluationException;
     
    13591359       
    13601360       
    1361         Exception* evaluationException;
     1361        NakedPtr<Exception> evaluationException;
    13621362        JSValue returnValue = evaluate(globalObject->globalExec(), makeSource(source, interpreterName), JSValue(), evaluationException);
    13631363#else
     
    13751375        line.append('\0');
    13761376
    1377         Exception* evaluationException;
     1377        NakedPtr<Exception> evaluationException;
    13781378        JSValue returnValue = evaluate(globalObject->globalExec(), jscSource(line.data(), interpreterName), JSValue(), evaluationException);
    13791379#endif
  • trunk/Source/JavaScriptCore/runtime/CallData.cpp

    r185259 r185608  
    2727#include "CallData.h"
    2828
    29 #include "Exception.h"
    3029#include "Executable.h"
    3130#include "Interpreter.h"
     
    4140}
    4241
    43 JSValue call(ExecState* exec, JSValue functionObject, CallType callType, const CallData& callData, JSValue thisValue, const ArgList& args, Exception*& returnedException)
     42JSValue call(ExecState* exec, JSValue functionObject, CallType callType, const CallData& callData, JSValue thisValue, const ArgList& args, NakedPtr<Exception>& returnedException)
    4443{
    4544    JSValue result = call(exec, functionObject, callType, callData, thisValue, args);
     
    4847        exec->clearException();
    4948        return jsUndefined();
    50     } else
    51         returnedException = nullptr;
     49    }
    5250    RELEASE_ASSERT(result);
    5351    return result;
  • trunk/Source/JavaScriptCore/runtime/CallData.h

    r185259 r185608  
    3131
    3232#include "JSCJSValue.h"
     33#include <wtf/NakedPtr.h>
    3334
    3435namespace JSC {
     
    6061
    6162JS_EXPORT_PRIVATE JSValue call(ExecState*, JSValue functionObject, CallType, const CallData&, JSValue thisValue, const ArgList&);
    62 JS_EXPORT_PRIVATE JSValue call(ExecState*, JSValue functionObject, CallType, const CallData&, JSValue thisValue, const ArgList&, Exception*& returnedException);
     63JS_EXPORT_PRIVATE JSValue call(ExecState*, JSValue functionObject, CallType, const CallData&, JSValue thisValue, const ArgList&, NakedPtr<Exception>& returnedException);
    6364
    6465} // namespace JSC
  • trunk/Source/JavaScriptCore/runtime/Completion.cpp

    r185259 r185608  
    6262}
    6363
    64 JSValue evaluate(ExecState* exec, const SourceCode& source, JSValue thisValue, Exception*& returnedException)
     64JSValue evaluate(ExecState* exec, const SourceCode& source, JSValue thisValue, NakedPtr<Exception>& returnedException)
    6565{
    6666    JSLockHolder lock(exec);
    6767    RELEASE_ASSERT(exec->vm().atomicStringTable() == wtfThreadData().atomicStringTable());
    6868    RELEASE_ASSERT(!exec->vm().isCollectorBusy());
    69     returnedException = nullptr;
    7069
    7170    CodeProfiling profile(source);
  • trunk/Source/JavaScriptCore/runtime/Completion.h

    r185259 r185608  
    2525
    2626#include "JSCJSValue.h"
     27#include <wtf/NakedPtr.h>
    2728
    2829namespace JSC {
     
    3738JS_EXPORT_PRIVATE bool checkSyntax(VM&, const SourceCode&, ParserError&);
    3839JS_EXPORT_PRIVATE bool checkSyntax(ExecState*, const SourceCode&, JSValue* exception = 0);
    39 JS_EXPORT_PRIVATE JSValue evaluate(ExecState*, const SourceCode&, JSValue thisValue, Exception*& returnedException);
     40JS_EXPORT_PRIVATE JSValue evaluate(ExecState*, const SourceCode&, JSValue thisValue, NakedPtr<Exception>& returnedException);
    4041inline JSValue evaluate(ExecState* exec, const SourceCode& sourceCode, JSValue thisValue = JSValue())
    4142{
    42     Exception* unused;
     43    NakedPtr<Exception> unused;
    4344    return evaluate(exec, sourceCode, thisValue, unused);
    4445}
  • trunk/Source/WTF/ChangeLog

    r185502 r185608  
     12015-06-16  Mark Lam  <mark.lam@apple.com>
     2
     3        Use NakedPtr<Exception>& to return exception results.
     4        https://bugs.webkit.org/show_bug.cgi?id=145870
     5
     6        Reviewed by Anders Carlsson and Filip Pizlo.
     7
     8        Introducing the NakedPtr class.
     9
     10        * WTF.xcodeproj/project.pbxproj:
     11        * wtf/NakedPtr.h: Added.
     12        (WTF::NakedPtr::NakedPtr):
     13        (WTF::NakedPtr::get):
     14        (WTF::NakedPtr::clear):
     15        (WTF::NakedPtr::operator*):
     16        (WTF::NakedPtr::operator->):
     17        (WTF::NakedPtr::operator T*):
     18        (WTF::NakedPtr::operator!):
     19        (WTF::NakedPtr::operator bool):
     20        (WTF::=):
     21        (WTF::NakedPtr<T>::swap):
     22        (WTF::swap):
     23
    1242015-06-12  Zan Dobersek  <zdobersek@igalia.com>
    225
  • trunk/Source/WTF/WTF.xcodeproj/project.pbxproj

    r185324 r185608  
    278278                E4A0AD3D1A96253C00536DF6 /* WorkQueueCocoa.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4A0AD3C1A96253C00536DF6 /* WorkQueueCocoa.cpp */; };
    279279                EB95E1F0161A72410089A2F5 /* ByteOrder.h in Headers */ = {isa = PBXBuildFile; fileRef = EB95E1EF161A72410089A2F5 /* ByteOrder.h */; };
     280                FE8225311B2A1E5B00BA68FD /* NakedPtr.h in Headers */ = {isa = PBXBuildFile; fileRef = FE8225301B2A1E5B00BA68FD /* NakedPtr.h */; };
    280281                FE91E8811AB2A0200099895F /* SpinLock.h in Headers */ = {isa = PBXBuildFile; fileRef = FE91E8801AB2A0200099895F /* SpinLock.h */; };
    281282                FEDACD3D1630F83F00C69634 /* StackStats.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FEDACD3B1630F83F00C69634 /* StackStats.cpp */; };
     
    569570                E4A0AD3C1A96253C00536DF6 /* WorkQueueCocoa.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WorkQueueCocoa.cpp; sourceTree = "<group>"; };
    570571                EB95E1EF161A72410089A2F5 /* ByteOrder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ByteOrder.h; sourceTree = "<group>"; };
     572                FE8225301B2A1E5B00BA68FD /* NakedPtr.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NakedPtr.h; sourceTree = "<group>"; };
    571573                FE91E8801AB2A0200099895F /* SpinLock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SpinLock.h; sourceTree = "<group>"; };
    572574                FEDACD3B1630F83F00C69634 /* StackStats.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StackStats.cpp; sourceTree = "<group>"; };
     
    783785                                A8A472CE151A825B004123FF /* MetaAllocator.h */,
    784786                                A8A472CF151A825B004123FF /* MetaAllocatorHandle.h */,
     787                                FE8225301B2A1E5B00BA68FD /* NakedPtr.h */,
    785788                                1A3F6BE6174ADA2100B2EEA7 /* NeverDestroyed.h */,
    786789                                0F0D85B317234CB100338210 /* NoLock.h */,
     
    11791182                                A8A4742C151A825B004123FF /* StringExtras.h in Headers */,
    11801183                                A8A4743F151A825B004123FF /* StringHash.h in Headers */,
     1184                                FE8225311B2A1E5B00BA68FD /* NakedPtr.h in Headers */,
    11811185                                A748745417A0BDAE00FA04CB /* StringHashDumpContext.h in Headers */,
    11821186                                A8A4742D151A825B004123FF /* StringHasher.h in Headers */,
  • trunk/Source/WebCore/ChangeLog

    r185606 r185608  
     12015-06-16  Mark Lam  <mark.lam@apple.com>
     2
     3        Use NakedPtr<Exception>& to return exception results.
     4        https://bugs.webkit.org/show_bug.cgi?id=145870
     5
     6        Reviewed by Anders Carlsson and Filip Pizlo.
     7
     8        No new WebCore tests because this functionality is already covered by existing tests.
     9        API tests added for WTF::NakedPtr.
     10
     11        * bindings/js/JSCallbackData.cpp:
     12        (WebCore::JSCallbackData::invokeCallback):
     13        * bindings/js/JSCustomXPathNSResolver.cpp:
     14        (WebCore::JSCustomXPathNSResolver::lookupNamespaceURI):
     15        * bindings/js/JSErrorHandler.cpp:
     16        (WebCore::JSErrorHandler::handleEvent):
     17        * bindings/js/JSEventListener.cpp:
     18        (WebCore::JSEventListener::handleEvent):
     19        * bindings/js/JSMainThreadExecState.cpp:
     20        (WebCore::JSMainThreadExecState::didLeaveScriptContext):
     21        (WebCore::functionCallHandlerFromAnyThread):
     22        (WebCore::evaluateHandlerFromAnyThread):
     23        * bindings/js/JSMainThreadExecState.h:
     24        (WebCore::JSMainThreadExecState::currentState):
     25        (WebCore::JSMainThreadExecState::call):
     26        (WebCore::JSMainThreadExecState::evaluate):
     27        * bindings/js/JSMutationCallback.cpp:
     28        (WebCore::JSMutationCallback::call):
     29        * bindings/js/ScheduledAction.cpp:
     30        (WebCore::ScheduledAction::executeFunctionInContext):
     31        * bindings/js/ScriptController.cpp:
     32        (WebCore::ScriptController::evaluateInWorld):
     33        * bindings/js/WorkerScriptController.cpp:
     34        (WebCore::WorkerScriptController::evaluate):
     35        (WebCore::WorkerScriptController::setException):
     36        * bindings/js/WorkerScriptController.h:
     37        (WebCore::WorkerScriptController::workerGlobalScopeWrapper):
     38        * bindings/objc/WebScriptObject.mm:
     39        (-[WebScriptObject callWebScriptMethod:withArguments:]):
     40        * workers/WorkerGlobalScope.cpp:
     41        (WebCore::WorkerGlobalScope::importScripts):
     42
    1432015-06-16  Brent Fulgham  <bfulgham@apple.com>
    244
  • trunk/Source/WebCore/bindings/js/JSCallbackData.cpp

    r185259 r185608  
    7474    InspectorInstrumentationCookie cookie = JSMainThreadExecState::instrumentFunctionCall(context, callType, callData);
    7575
    76     Exception* exception;
     76    NakedPtr<Exception> exception;
    7777    JSValue result = context->isDocument()
    7878        ? JSMainThreadExecState::call(exec, function, callType, callData, thisValue, args, exception)
  • trunk/Source/WebCore/bindings/js/JSCustomXPathNSResolver.cpp

    r185259 r185608  
    9494    args.append(jsStringWithCache(exec, prefix));
    9595
    96     Exception* exception;
     96    NakedPtr<Exception> exception;
    9797    JSValue retval = JSMainThreadExecState::call(exec, function, callType, callData, m_customResolver.get(), args, exception);
    9898
  • trunk/Source/WebCore/bindings/js/JSErrorHandler.cpp

    r185259 r185608  
    9999        VMEntryScope entryScope(vm, vm.entryScope ? vm.entryScope->globalObject() : globalObject);
    100100
    101         Exception* exception;
     101        NakedPtr<Exception> exception;
    102102        JSValue returnValue = scriptExecutionContext->isDocument()
    103103            ? JSMainThreadExecState::call(exec, jsFunction, callType, callData, globalObject, args, exception)
  • trunk/Source/WebCore/bindings/js/JSEventListener.cpp

    r185259 r185608  
    125125
    126126        JSValue thisValue = handleEventFunction == jsFunction ? toJS(exec, globalObject, event->currentTarget()) : jsFunction;
    127         Exception* exception;
     127        NakedPtr<Exception> exception;
    128128        JSValue retval = scriptExecutionContext->isDocument()
    129129            ? JSMainThreadExecState::call(exec, handleEventFunction, callType, callData, thisValue, args, exception)
  • trunk/Source/WebCore/bindings/js/JSMainThreadExecState.cpp

    r185259 r185608  
    4747}
    4848
    49 JSC::JSValue functionCallHandlerFromAnyThread(JSC::ExecState* exec, JSC::JSValue functionObject, JSC::CallType callType, const JSC::CallData& callData, JSC::JSValue thisValue, const JSC::ArgList& args, JSC::Exception*& returnedException)
     49JSC::JSValue functionCallHandlerFromAnyThread(JSC::ExecState* exec, JSC::JSValue functionObject, JSC::CallType callType, const JSC::CallData& callData, JSC::JSValue thisValue, const JSC::ArgList& args, NakedPtr<JSC::Exception>& returnedException)
    5050{
    5151    if (isMainThread())
     
    5454}
    5555
    56 JSC::JSValue evaluateHandlerFromAnyThread(JSC::ExecState* exec, const JSC::SourceCode& source, JSC::JSValue thisValue, JSC::Exception*& returnedException)
     56JSC::JSValue evaluateHandlerFromAnyThread(JSC::ExecState* exec, const JSC::SourceCode& source, JSC::JSValue thisValue, NakedPtr<JSC::Exception>& returnedException)
    5757{
    5858    if (isMainThread())
  • trunk/Source/WebCore/bindings/js/JSMainThreadExecState.h

    r185259 r185608  
    5151    };
    5252   
    53     static JSC::JSValue call(JSC::ExecState* exec, JSC::JSValue functionObject, JSC::CallType callType, const JSC::CallData& callData, JSC::JSValue thisValue, const JSC::ArgList& args, JSC::Exception*& returnedException)
     53    static JSC::JSValue call(JSC::ExecState* exec, JSC::JSValue functionObject, JSC::CallType callType, const JSC::CallData& callData, JSC::JSValue thisValue, const JSC::ArgList& args, NakedPtr<JSC::Exception>& returnedException)
    5454    {
    5555        JSMainThreadExecState currentState(exec);
     
    5757    };
    5858
    59     static JSC::JSValue evaluate(JSC::ExecState* exec, const JSC::SourceCode& source, JSC::JSValue thisValue, JSC::Exception*& returnedException)
     59    static JSC::JSValue evaluate(JSC::ExecState* exec, const JSC::SourceCode& source, JSC::JSValue thisValue, NakedPtr<JSC::Exception>& returnedException)
    6060    {
    6161        JSMainThreadExecState currentState(exec);
     
    6565    static JSC::JSValue evaluate(JSC::ExecState* exec, const JSC::SourceCode& source, JSC::JSValue thisValue = JSC::JSValue())
    6666    {
    67         JSC::Exception* unused;
     67        NakedPtr<JSC::Exception> unused;
    6868        return evaluate(exec, source, thisValue, unused);
    6969    };
     
    128128};
    129129
    130 JSC::JSValue functionCallHandlerFromAnyThread(JSC::ExecState*, JSC::JSValue functionObject, JSC::CallType, const JSC::CallData&, JSC::JSValue thisValue, const JSC::ArgList& args, JSC::Exception*& returnedException);
    131 JSC::JSValue evaluateHandlerFromAnyThread(JSC::ExecState*, const JSC::SourceCode&, JSC::JSValue thisValue, JSC::Exception*& returnedException);
     130JSC::JSValue functionCallHandlerFromAnyThread(JSC::ExecState*, JSC::JSValue functionObject, JSC::CallType, const JSC::CallData&, JSC::JSValue thisValue, const JSC::ArgList& args, NakedPtr<JSC::Exception>& returnedException);
     131JSC::JSValue evaluateHandlerFromAnyThread(JSC::ExecState*, const JSC::SourceCode&, JSC::JSValue thisValue, NakedPtr<JSC::Exception>& returnedException);
    132132
    133133} // namespace WebCore
  • trunk/Source/WebCore/bindings/js/JSMutationCallback.cpp

    r185259 r185608  
    8888    InspectorInstrumentationCookie cookie = JSMainThreadExecState::instrumentFunctionCall(context, callType, callData);
    8989
    90     Exception* exception;
     90    NakedPtr<Exception> exception;
    9191    JSMainThreadExecState::call(exec, callback, callType, callData, jsObserver, args, exception);
    9292
  • trunk/Source/WebCore/bindings/js/ScheduledAction.cpp

    r185259 r185608  
    100100    InspectorInstrumentationCookie cookie = JSMainThreadExecState::instrumentFunctionCall(&context, callType, callData);
    101101
    102     Exception* exception;
     102    NakedPtr<Exception> exception;
    103103    if (is<Document>(context))
    104104        JSMainThreadExecState::call(exec, m_function.get(), callType, callData, thisValue, args, exception);
  • trunk/Source/WebCore/bindings/js/ScriptController.cpp

    r185342 r185608  
    161161    InspectorInstrumentationCookie cookie = InspectorInstrumentation::willEvaluateScript(m_frame, sourceURL, sourceCode.startLine());
    162162
    163     Exception* evaluationException;
     163    NakedPtr<Exception> evaluationException;
    164164    JSValue returnValue = JSMainThreadExecState::evaluate(exec, jsSourceCode, shell, evaluationException);
    165165
  • trunk/Source/WebCore/bindings/js/WorkerScriptController.cpp

    r185286 r185608  
    100100        return;
    101101
    102     Exception* exception;
     102    NakedPtr<Exception> exception;
    103103    evaluate(sourceCode, exception);
    104104    if (exception) {
     
    108108}
    109109
    110 void WorkerScriptController::evaluate(const ScriptSourceCode& sourceCode, JSC::Exception*& returnedException)
     110void WorkerScriptController::evaluate(const ScriptSourceCode& sourceCode, NakedPtr<JSC::Exception>& returnedException)
    111111{
    112     returnedException = nullptr;
    113112    if (isExecutionForbidden())
    114113        return;
     
    119118    JSLockHolder lock(exec);
    120119
    121     JSC::Exception* evaluationException;
    122     JSC::evaluate(exec, sourceCode.jsSourceCode(), m_workerGlobalScopeWrapper->globalThis(), evaluationException);
     120    JSC::evaluate(exec, sourceCode.jsSourceCode(), m_workerGlobalScopeWrapper->globalThis(), returnedException);
    123121
    124122    VM& vm = exec->vm();
    125     if ((evaluationException && isTerminatedExecutionException(evaluationException))
     123    if ((returnedException && isTerminatedExecutionException(returnedException))
    126124        || (vm.watchdog && vm.watchdog->didFire())) {
    127125        forbidExecution();
     
    129127    }
    130128
    131     if (evaluationException) {
     129    if (returnedException) {
    132130        String errorMessage;
    133131        int lineNumber = 0;
     
    136134        if (m_workerGlobalScope->sanitizeScriptError(errorMessage, lineNumber, columnNumber, sourceURL, sourceCode.cachedScript())) {
    137135            vm.throwException(exec, createError(exec, errorMessage.impl()));
    138             evaluationException = vm.exception();
     136            returnedException = vm.exception();
    139137            vm.clearException();
    140138        }
    141139    }
    142     returnedException = evaluationException;
    143140}
    144141
  • trunk/Source/WebCore/bindings/js/WorkerScriptController.h

    r185259 r185608  
    3232#include <heap/Strong.h>
    3333#include <wtf/Forward.h>
     34#include <wtf/NakedPtr.h>
    3435#include <wtf/Threading.h>
    3536
     
    6162
    6263        void evaluate(const ScriptSourceCode&);
    63         void evaluate(const ScriptSourceCode&, JSC::Exception*& returnedException);
     64        void evaluate(const ScriptSourceCode&, NakedPtr<JSC::Exception>& returnedException);
    6465
    6566        void setException(JSC::Exception*);
  • trunk/Source/WebCore/bindings/objc/WebScriptObject.mm

    r185259 r185608  
    343343        return nil;
    344344
    345     JSC::Exception* exception;
     345    NakedPtr<JSC::Exception> exception;
    346346    JSC::JSValue result = JSMainThreadExecState::call(exec, function, callType, callData, [self _imp], argList, exception);
    347347
  • trunk/Source/WebCore/workers/WorkerGlobalScope.cpp

    r185259 r185608  
    198198        InspectorInstrumentation::scriptImported(scriptExecutionContext(), scriptLoader->identifier(), scriptLoader->script());
    199199
    200         JSC::Exception* exception;
     200        NakedPtr<JSC::Exception> exception;
    201201        m_script->evaluate(ScriptSourceCode(scriptLoader->script(), scriptLoader->responseURL()), exception);
    202202        if (exception) {
  • trunk/Tools/ChangeLog

    r185587 r185608  
     12015-06-16  Mark Lam  <mark.lam@apple.com>
     2
     3        Use NakedPtr<Exception>& to return exception results.
     4        https://bugs.webkit.org/show_bug.cgi?id=145870
     5
     6        Reviewed by Anders Carlsson and Filip Pizlo.
     7
     8        * TestWebKitAPI/CMakeLists.txt:
     9        * TestWebKitAPI/TestWebKitAPI.vcxproj/TestWebKitAPI.vcxproj:
     10        * TestWebKitAPI/TestWebKitAPI.vcxproj/TestWebKitAPI.vcxproj.filters:
     11        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     12        * TestWebKitAPI/Tests/WTF/NakedPtr.cpp: Added.
     13        (TestWebKitAPI::TEST):
     14        (TestWebKitAPI::nakedPtrFoo):
     15
    1162015-06-16  Tobias Reiss  <tobi+webkit@basecode.de>
    217
  • trunk/Tools/TestWebKitAPI/CMakeLists.txt

    r185358 r185608  
    8080    ${TESTWEBKITAPI_DIR}/Tests/WTF/MediaTime.cpp
    8181    ${TESTWEBKITAPI_DIR}/Tests/WTF/MetaAllocator.cpp
     82    ${TESTWEBKITAPI_DIR}/Tests/WTF/NakedPtr.cpp
    8283    ${TESTWEBKITAPI_DIR}/Tests/WTF/RedBlackTree.cpp
    8384    ${TESTWEBKITAPI_DIR}/Tests/WTF/Ref.cpp
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.vcxproj/TestWebKitAPI.vcxproj

    r184137 r185608  
    324324    <ClCompile Include="..\Tests\WTF\MediaTime.cpp" />
    325325    <ClCompile Include="..\Tests\WTF\MetaAllocator.cpp" />
     326    <ClCompile Include="..\Tests\WTF\NakedPtr.cpp" />
    326327    <ClCompile Include="..\Tests\WTF\Optional.cpp" />
    327328    <ClCompile Include="..\Tests\WTF\RedBlackTree.cpp" />
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.vcxproj/TestWebKitAPI.vcxproj.filters

    r182871 r185608  
    7474    </ClCompile>
    7575    <ClCompile Include="..\Tests\WTF\MediaTime.cpp">
     76      <Filter>Tests\WTF</Filter>
     77    </ClCompile>
     78    <ClCompile Include="..\Tests\WTF\NakedPtr.cpp">
    7679      <Filter>Tests\WTF</Filter>
    7780    </ClCompile>
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r185230 r185608  
    301301                F6F49C6B15545CA70007F39D /* DOMWindowExtensionNoCache_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F6F49C6615545C8D0007F39D /* DOMWindowExtensionNoCache_Bundle.cpp */; };
    302302                F6FDDDD614241C6F004F1729 /* push-state.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F6FDDDD514241C48004F1729 /* push-state.html */; };
     303                FEB6F7511B2BA464009E4922 /* NakedPtr.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FEB6F74E1B2BA44E009E4922 /* NakedPtr.cpp */; };
    303304/* End PBXBuildFile section */
    304305
     
    729730                F6FDDDD214241AD4004F1729 /* PrivateBrowsingPushStateNoHistoryCallback.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PrivateBrowsingPushStateNoHistoryCallback.cpp; sourceTree = "<group>"; };
    730731                F6FDDDD514241C48004F1729 /* push-state.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "push-state.html"; sourceTree = "<group>"; };
     732                FEB6F74E1B2BA44E009E4922 /* NakedPtr.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NakedPtr.cpp; sourceTree = "<group>"; };
    731733/* End PBXFileReference section */
    732734
     
    10741076                                0FC6C4CE141034AD005B7F0C /* MetaAllocator.cpp */,
    10751077                                93A427AC180DA60F00CD24D7 /* MoveOnly.h */,
     1078                                FEB6F74E1B2BA44E009E4922 /* NakedPtr.cpp */,
    10761079                                1AFDE6541953B2C000C48FFA /* Optional.cpp */,
    10771080                                0FC6C4CB141027E0005B7F0C /* RedBlackTree.cpp */,
     
    15011504                                7CCE7F031A411AE600447C4C /* NewFirstVisuallyNonEmptyLayoutFails.cpp in Sources */,
    15021505                                7CCE7F041A411AE600447C4C /* NewFirstVisuallyNonEmptyLayoutForImages.cpp in Sources */,
     1506                                FEB6F7511B2BA464009E4922 /* NakedPtr.cpp in Sources */,
    15031507                                7CCE7F051A411AE600447C4C /* NewFirstVisuallyNonEmptyLayoutFrames.cpp in Sources */,
    15041508                                7CCE7F251A411AF600447C4C /* OpenAndCloseWindow.mm in Sources */,
Note: See TracChangeset for help on using the changeset viewer.