Changeset 128139 in webkit


Ignore:
Timestamp:
Sep 10, 2012 6:25:03 PM (12 years ago)
Author:
commit-queue@webkit.org
Message:

[V8] Code assumes that getScriptExecutionContext can return 0
https://bugs.webkit.org/show_bug.cgi?id=96340

Patch by Adam Barth <abarth@chromium.org> on 2012-09-10
Reviewed by Eric Seidel.

This function can never return 0 (as long as V8 is on the stack).
There's no reason to try to handle a 0 return as an error.

  • bindings/scripts/CodeGeneratorV8.pm:

(GenerateCallWith):
(GenerateConstructorCallback):

  • bindings/scripts/test/V8/V8TestInterface.cpp:

(WebCore::TestInterfaceV8Internal::supplementalMethod2Callback):
(WebCore::V8TestInterface::constructorCallback):

  • bindings/scripts/test/V8/V8TestObj.cpp:

(WebCore::TestObjV8Internal::withScriptExecutionContextAttributeAttrGetter):
(WebCore::TestObjV8Internal::withScriptExecutionContextAttributeAttrSetter):
(WebCore::TestObjV8Internal::withScriptExecutionContextAttributeRaisesAttrGetter):
(WebCore::TestObjV8Internal::withScriptExecutionContextAttributeRaisesAttrSetter):
(WebCore::TestObjV8Internal::withScriptExecutionContextAndScriptStateAttributeAttrGetter):
(WebCore::TestObjV8Internal::withScriptExecutionContextAndScriptStateAttributeAttrSetter):
(WebCore::TestObjV8Internal::withScriptExecutionContextAndScriptStateAttributeRaisesAttrGetter):
(WebCore::TestObjV8Internal::withScriptExecutionContextAndScriptStateAttributeRaisesAttrSetter):
(WebCore::TestObjV8Internal::withScriptExecutionContextAndScriptStateWithSpacesAttributeAttrGetter):
(WebCore::TestObjV8Internal::withScriptExecutionContextAndScriptStateWithSpacesAttributeAttrSetter):
(WebCore::TestObjV8Internal::withScriptExecutionContextCallback):
(WebCore::TestObjV8Internal::withScriptExecutionContextAndScriptStateCallback):
(WebCore::TestObjV8Internal::withScriptExecutionContextAndScriptStateObjExceptionCallback):
(WebCore::TestObjV8Internal::withScriptExecutionContextAndScriptStateWithSpacesCallback):

  • bindings/v8/custom/V8BlobCustom.cpp:

(WebCore::V8Blob::constructorCallback):

  • bindings/v8/custom/V8CustomXPathNSResolver.cpp:

(WebCore::V8CustomXPathNSResolver::lookupNamespaceURI):

  • bindings/v8/custom/V8MessageChannelConstructor.cpp:

(WebCore::V8MessageChannel::constructorCallback):

  • bindings/v8/custom/V8MutationObserverCustom.cpp:

(WebCore::V8MutationObserver::constructorCallback):

  • bindings/v8/custom/V8SQLTransactionCustom.cpp:

(WebCore::V8SQLTransaction::executeSqlCallback):

  • bindings/v8/custom/V8WebSocketCustom.cpp:

(WebCore::V8WebSocket::constructorCallback):

  • bindings/v8/custom/V8XMLHttpRequestConstructor.cpp:

(WebCore::V8XMLHttpRequest::constructorCallback):

  • bindings/v8/custom/V8XMLHttpRequestCustom.cpp:

(WebCore::V8XMLHttpRequest::openCallback):

Location:
trunk/Source/WebCore
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r128138 r128139  
     12012-09-10  Adam Barth  <abarth@chromium.org>
     2
     3        [V8] Code assumes that getScriptExecutionContext can return 0
     4        https://bugs.webkit.org/show_bug.cgi?id=96340
     5
     6        Reviewed by Eric Seidel.
     7
     8        This function can never return 0 (as long as V8 is on the stack).
     9        There's no reason to try to handle a 0 return as an error.
     10
     11        * bindings/scripts/CodeGeneratorV8.pm:
     12        (GenerateCallWith):
     13        (GenerateConstructorCallback):
     14        * bindings/scripts/test/V8/V8TestInterface.cpp:
     15        (WebCore::TestInterfaceV8Internal::supplementalMethod2Callback):
     16        (WebCore::V8TestInterface::constructorCallback):
     17        * bindings/scripts/test/V8/V8TestObj.cpp:
     18        (WebCore::TestObjV8Internal::withScriptExecutionContextAttributeAttrGetter):
     19        (WebCore::TestObjV8Internal::withScriptExecutionContextAttributeAttrSetter):
     20        (WebCore::TestObjV8Internal::withScriptExecutionContextAttributeRaisesAttrGetter):
     21        (WebCore::TestObjV8Internal::withScriptExecutionContextAttributeRaisesAttrSetter):
     22        (WebCore::TestObjV8Internal::withScriptExecutionContextAndScriptStateAttributeAttrGetter):
     23        (WebCore::TestObjV8Internal::withScriptExecutionContextAndScriptStateAttributeAttrSetter):
     24        (WebCore::TestObjV8Internal::withScriptExecutionContextAndScriptStateAttributeRaisesAttrGetter):
     25        (WebCore::TestObjV8Internal::withScriptExecutionContextAndScriptStateAttributeRaisesAttrSetter):
     26        (WebCore::TestObjV8Internal::withScriptExecutionContextAndScriptStateWithSpacesAttributeAttrGetter):
     27        (WebCore::TestObjV8Internal::withScriptExecutionContextAndScriptStateWithSpacesAttributeAttrSetter):
     28        (WebCore::TestObjV8Internal::withScriptExecutionContextCallback):
     29        (WebCore::TestObjV8Internal::withScriptExecutionContextAndScriptStateCallback):
     30        (WebCore::TestObjV8Internal::withScriptExecutionContextAndScriptStateObjExceptionCallback):
     31        (WebCore::TestObjV8Internal::withScriptExecutionContextAndScriptStateWithSpacesCallback):
     32        * bindings/v8/custom/V8BlobCustom.cpp:
     33        (WebCore::V8Blob::constructorCallback):
     34        * bindings/v8/custom/V8CustomXPathNSResolver.cpp:
     35        (WebCore::V8CustomXPathNSResolver::lookupNamespaceURI):
     36        * bindings/v8/custom/V8MessageChannelConstructor.cpp:
     37        (WebCore::V8MessageChannel::constructorCallback):
     38        * bindings/v8/custom/V8MutationObserverCustom.cpp:
     39        (WebCore::V8MutationObserver::constructorCallback):
     40        * bindings/v8/custom/V8SQLTransactionCustom.cpp:
     41        (WebCore::V8SQLTransaction::executeSqlCallback):
     42        * bindings/v8/custom/V8WebSocketCustom.cpp:
     43        (WebCore::V8WebSocket::constructorCallback):
     44        * bindings/v8/custom/V8XMLHttpRequestConstructor.cpp:
     45        (WebCore::V8XMLHttpRequest::constructorCallback):
     46        * bindings/v8/custom/V8XMLHttpRequestCustom.cpp:
     47        (WebCore::V8XMLHttpRequest::openCallback):
     48
    1492012-09-10  Adam Barth  <abarth@chromium.org>
    250
  • trunk/Source/WebCore/bindings/scripts/CodeGeneratorV8.pm

    r128102 r128139  
    15991599    if ($codeGenerator->ExtendedAttributeContains($callWith, "ScriptExecutionContext")) {
    16001600        push(@$outputArray, $indent . "ScriptExecutionContext* scriptContext = getScriptExecutionContext();\n");
    1601         push(@$outputArray, $indent . "if (!scriptContext)\n");
    1602         push(@$outputArray, $indent . "    return" . ($returnVoid ? "" : " v8Undefined()") . ";\n");
    16031601        push(@callWithArgs, "scriptContext");
    16041602    }
     
    18491847
    18501848    ScriptExecutionContext* context = getScriptExecutionContext();
    1851     if (!context)
    1852         return throwError(ReferenceError, "${implClassName} constructor's associated context is not available", args.GetIsolate());
    18531849END
    18541850    }
  • trunk/Source/WebCore/bindings/scripts/test/V8/V8TestInterface.cpp

    r127972 r128139  
    164164    EXCEPTION_BLOCK(TestObj*, objArg, V8TestObj::HasInstance(MAYBE_MISSING_PARAMETER(args, 1, DefaultIsUndefined)) ? V8TestObj::toNative(v8::Handle<v8::Object>::Cast(MAYBE_MISSING_PARAMETER(args, 1, DefaultIsUndefined))) : 0);
    165165    ScriptExecutionContext* scriptContext = getScriptExecutionContext();
    166     if (!scriptContext)
    167         return v8Undefined();
    168166    RefPtr<TestObj> result = TestSupplemental::supplementalMethod2(scriptContext, imp, strArg, objArg, ec);
    169167    if (UNLIKELY(ec))
     
    260258
    261259    ScriptExecutionContext* context = getScriptExecutionContext();
    262     if (!context)
    263         return throwError(ReferenceError, "TestInterface constructor's associated context is not available", args.GetIsolate());
    264260
    265261    RefPtr<TestInterface> impl = TestInterface::create(context, str1, str2, ec);
  • trunk/Source/WebCore/bindings/scripts/test/V8/V8TestObj.cpp

    r127972 r128139  
    547547    TestObj* imp = V8TestObj::toNative(info.Holder());
    548548    ScriptExecutionContext* scriptContext = getScriptExecutionContext();
    549     if (!scriptContext)
    550         return v8Undefined();
    551549    return toV8(imp->withScriptExecutionContextAttribute(scriptContext), info.Holder(), info.GetIsolate());
    552550}
     
    558556    TestObj* v = V8TestObj::HasInstance(value) ? V8TestObj::toNative(v8::Handle<v8::Object>::Cast(value)) : 0;
    559557    ScriptExecutionContext* scriptContext = getScriptExecutionContext();
    560     if (!scriptContext)
    561         return;
    562558    imp->setWithScriptExecutionContextAttribute(scriptContext, WTF::getPtr(v));
    563559    return;
     
    603599    ExceptionCode ec = 0;
    604600    ScriptExecutionContext* scriptContext = getScriptExecutionContext();
    605     if (!scriptContext)
    606         return v8Undefined();
    607601    RefPtr<TestObj> v = imp->withScriptExecutionContextAttributeRaises(scriptContext, ec);
    608602    if (UNLIKELY(ec))
     
    618612    ExceptionCode ec = 0;
    619613    ScriptExecutionContext* scriptContext = getScriptExecutionContext();
    620     if (!scriptContext)
    621         return;
    622614    imp->setWithScriptExecutionContextAttributeRaises(scriptContext, WTF::getPtr(v), ec);
    623615    if (UNLIKELY(ec))
     
    634626        return v8Undefined();
    635627    ScriptExecutionContext* scriptContext = getScriptExecutionContext();
    636     if (!scriptContext)
    637         return v8Undefined();
    638628    return toV8(imp->withScriptExecutionContextAndScriptStateAttribute(state, scriptContext), info.Holder(), info.GetIsolate());
    639629}
     
    648638        return;
    649639    ScriptExecutionContext* scriptContext = getScriptExecutionContext();
    650     if (!scriptContext)
    651         return;
    652640    imp->setWithScriptExecutionContextAndScriptStateAttribute(state, scriptContext, WTF::getPtr(v));
    653641    if (state.hadException())
     
    665653        return v8Undefined();
    666654    ScriptExecutionContext* scriptContext = getScriptExecutionContext();
    667     if (!scriptContext)
    668         return v8Undefined();
    669655    RefPtr<TestObj> v = imp->withScriptExecutionContextAndScriptStateAttributeRaises(state, scriptContext, ec);
    670656    if (UNLIKELY(ec))
     
    685671        return;
    686672    ScriptExecutionContext* scriptContext = getScriptExecutionContext();
    687     if (!scriptContext)
    688         return;
    689673    imp->setWithScriptExecutionContextAndScriptStateAttributeRaises(state, scriptContext, WTF::getPtr(v), ec);
    690674    if (UNLIKELY(ec))
     
    703687        return v8Undefined();
    704688    ScriptExecutionContext* scriptContext = getScriptExecutionContext();
    705     if (!scriptContext)
    706         return v8Undefined();
    707689    return toV8(imp->withScriptExecutionContextAndScriptStateWithSpacesAttribute(state, scriptContext), info.Holder(), info.GetIsolate());
    708690}
     
    717699        return;
    718700    ScriptExecutionContext* scriptContext = getScriptExecutionContext();
    719     if (!scriptContext)
    720         return;
    721701    imp->setWithScriptExecutionContextAndScriptStateWithSpacesAttribute(state, scriptContext, WTF::getPtr(v));
    722702    if (state.hadException())
     
    13121292    TestObj* imp = V8TestObj::toNative(args.Holder());
    13131293    ScriptExecutionContext* scriptContext = getScriptExecutionContext();
    1314     if (!scriptContext)
    1315         return v8Undefined();
    13161294    imp->withScriptExecutionContext(scriptContext);
    13171295    return v8Undefined();
     
    13241302    EmptyScriptState state;
    13251303    ScriptExecutionContext* scriptContext = getScriptExecutionContext();
    1326     if (!scriptContext)
    1327         return v8Undefined();
    13281304    imp->withScriptExecutionContextAndScriptState(&state, scriptContext);
    13291305    if (state.hadException())
     
    13401316    EmptyScriptState state;
    13411317    ScriptExecutionContext* scriptContext = getScriptExecutionContext();
    1342     if (!scriptContext)
    1343         return v8Undefined();
    13441318    RefPtr<TestObj> result = imp->withScriptExecutionContextAndScriptStateObjException(&state, scriptContext, ec);
    13451319    if (UNLIKELY(ec))
     
    13591333    EmptyScriptState state;
    13601334    ScriptExecutionContext* scriptContext = getScriptExecutionContext();
    1361     if (!scriptContext)
    1362         return v8Undefined();
    13631335    RefPtr<TestObj> result = imp->withScriptExecutionContextAndScriptStateWithSpaces(&state, scriptContext);
    13641336    if (state.hadException())
  • trunk/Source/WebCore/bindings/v8/custom/V8BlobCustom.cpp

    r127946 r128139  
    6565        return args.Holder();
    6666
    67     // Get the script execution context.
    6867    ScriptExecutionContext* context = getScriptExecutionContext();
    69     if (!context)
    70         return throwError(ReferenceError, "Blob constructor associated document is unavailable", args.GetIsolate());
    7168
    7269    if (!args.Length()) {
  • trunk/Source/WebCore/bindings/v8/custom/V8CustomXPathNSResolver.cpp

    r126109 r128139  
    3131#include "V8CustomXPathNSResolver.h"
    3232
     33#include "Console.h"
     34#include "DOMWindow.h"
    3335#include "ScriptCallStack.h"
    3436#include "ScriptController.h"
     
    6769
    6870    if (lookupNamespaceURIFunc.IsEmpty() && !m_resolver->IsFunction()) {
    69         if (ScriptExecutionContext* context = getScriptExecutionContext())
    70             context->addConsoleMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "XPathNSResolver does not have a lookupNamespaceURI method.");
     71        activeDOMWindow(BindingState::instance())->console()->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "XPathNSResolver does not have a lookupNamespaceURI method.");
    7172        return String();
    7273    }
    7374
    7475    // Catch exceptions from calling the namespace resolver.
    75     v8::TryCatch try_catch;
    76     try_catch.SetVerbose(true); // Print exceptions to console.
     76    v8::TryCatch tryCatch;
     77    tryCatch.SetVerbose(true); // Print exceptions to console.
    7778
    7879    const int argc = 1;
     
    8384
    8485    // Eat exceptions from namespace resolver and return an empty string. This will most likely cause NAMESPACE_ERR.
    85     if (try_catch.HasCaught())
     86    if (tryCatch.HasCaught())
    8687        return String();
    8788
  • trunk/Source/WebCore/bindings/v8/custom/V8MessageChannelConstructor.cpp

    r127946 r128139  
    4848{
    4949    INC_STATS("DOM.MessageChannel.Constructor");
    50     // FIXME: The logic here is almost exact duplicate of V8::constructDOMObject.
    51     // Consider refactoring to reduce duplication.
     50
    5251    if (!args.IsConstructCall())
    5352        return throwTypeError("DOM object constructor cannot be called as a function.", args.GetIsolate());
     
    5655        return args.Holder();
    5756
    58     // Get the ScriptExecutionContext (WorkerContext or Document)
    5957    ScriptExecutionContext* context = getScriptExecutionContext();
    60     if (!context)
    61         return v8::Undefined();
    6258
    63     // Note: it's OK to let this RefPtr go out of scope because we also call
    64     // SetDOMWrapper(), which effectively holds a reference to obj.
    6559    RefPtr<MessageChannel> obj = MessageChannel::create(context);
    6660
    67     v8::Local<v8::Object> messageChannel = args.Holder();
     61    v8::Local<v8::Object> wrapper = args.Holder();
    6862
    6963    // Create references from the MessageChannel wrapper to the two
    7064    // MessagePort wrappers to make sure that the MessagePort wrappers
    7165    // stay alive as long as the MessageChannel wrapper is around.
    72     V8DOMWrapper::setNamedHiddenReference(messageChannel, "port1", toV8(obj->port1(), args.Holder(), args.GetIsolate()));
    73     V8DOMWrapper::setNamedHiddenReference(messageChannel, "port2", toV8(obj->port2(), args.Holder(), args.GetIsolate()));
     66    V8DOMWrapper::setNamedHiddenReference(wrapper, "port1", toV8(obj->port1(), args.Holder(), args.GetIsolate()));
     67    V8DOMWrapper::setNamedHiddenReference(wrapper, "port2", toV8(obj->port2(), args.Holder(), args.GetIsolate()));
    7468
    75     // Setup the standard wrapper object internal fields.
    76     V8DOMWrapper::setDOMWrapper(messageChannel, &info, obj.get());
    77     V8DOMWrapper::setJSWrapperForDOMObject(obj.release(), messageChannel);
    78     return messageChannel;
     69    V8DOMWrapper::setDOMWrapper(wrapper, &info, obj.get());
     70    V8DOMWrapper::setJSWrapperForDOMObject(obj.release(), wrapper);
     71    return wrapper;
    7972}
    8073
    81 
    8274} // namespace WebCore
  • trunk/Source/WebCore/bindings/v8/custom/V8MutationObserverCustom.cpp

    r126399 r128139  
    6262
    6363    ScriptExecutionContext* context = getScriptExecutionContext();
    64     if (!context)
    65         return throwError(ReferenceError, "MutationObserver constructor's associated frame unavailable", args.GetIsolate());
    6664
    6765    RefPtr<MutationCallback> callback = V8MutationCallback::create(arg, context);
  • trunk/Source/WebCore/bindings/v8/custom/V8SQLTransactionCustom.cpp

    r126399 r128139  
    9090
    9191    ScriptExecutionContext* scriptExecutionContext = getScriptExecutionContext();
    92     if (!scriptExecutionContext)
    93         return v8::Undefined();
    9492
    9593    RefPtr<SQLStatementCallback> callback;
  • trunk/Source/WebCore/bindings/v8/custom/V8WebSocketCustom.cpp

    r126399 r128139  
    7272        return throwError(SyntaxError, "Empty URL", args.GetIsolate());
    7373
    74     // Get the script execution context.
    7574    ScriptExecutionContext* context = getScriptExecutionContext();
    76     if (!context)
    77         return throwError(ReferenceError, "WebSocket constructor's associated frame is not available", args.GetIsolate());
    78 
    7975    const KURL& url = context->completeURL(toWebCoreString(urlstring));
    8076
  • trunk/Source/WebCore/bindings/v8/custom/V8XMLHttpRequestConstructor.cpp

    r126399 r128139  
    5353        return args.Holder();
    5454
    55     // Expect no parameters.
    56     // Allocate a XMLHttpRequest object as its internal field.
    5755    ScriptExecutionContext* context = getScriptExecutionContext();
    58     if (!context)
    59         return throwError(ReferenceError, "XMLHttpRequest constructor's associated context is not available", args.GetIsolate());
    6056
    6157    RefPtr<SecurityOrigin> securityOrigin;
    6258    if (V8IsolatedContext* isolatedContext = V8IsolatedContext::getEntered())
    6359        securityOrigin = isolatedContext->securityOrigin();
     60
    6461    RefPtr<XMLHttpRequest> xmlHttpRequest = XMLHttpRequest::create(context, securityOrigin);
     62
    6563    v8::Handle<v8::Object> wrapper = args.Holder();
    6664    V8DOMWrapper::setDOMWrapper(wrapper, &info, xmlHttpRequest.get());
  • trunk/Source/WebCore/bindings/v8/custom/V8XMLHttpRequestCustom.cpp

    r127946 r128139  
    118118    String method = toWebCoreString(args[0]);
    119119    String urlstring = toWebCoreString(args[1]);
     120
    120121    ScriptExecutionContext* context = getScriptExecutionContext();
    121     if (!context)
    122         return v8::Undefined();
    123 
    124122    KURL url = context->completeURL(urlstring);
    125123
Note: See TracChangeset for help on using the changeset viewer.