Changeset 117926 in webkit


Ignore:
Timestamp:
May 22, 2012 12:42:10 AM (12 years ago)
Author:
haraken@chromium.org
Message:

[V8] setDOMException() should return v8::Handle<v8::Value>()
https://bugs.webkit.org/show_bug.cgi?id=87083

Reviewed by Adam Barth.

The following patterns are used here and there in V8 bindings:

setDOMException();
return v8::Handle<v8::Value>();

and

setDOMException();
return v8::Undefined();

By returning v8::Handle<v8::Value>() from setDOMException(), we can simplify the above patterns into this:

return setDOMException();

This patch just replaces the code in CodeGeneratorV8.pm. I'll replace
all other custom bindings in a follow-up patch.

No tests. No change in behavior.

  • bindings/scripts/CodeGeneratorV8.pm:

(GenerateSetDOMException):
(GenerateFunctionCallback):
(GenerateFunctionCallString):

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

(WebCore::TestEventTargetV8Internal::itemCallback):
(WebCore::TestEventTargetV8Internal::dispatchEventCallback):

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

(WebCore::TestInterfaceV8Internal::supplementalMethod2Callback):

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

(WebCore::TestObjV8Internal::attrWithGetterExceptionAttrGetter):
(WebCore::TestObjV8Internal::stringAttrWithGetterExceptionAttrGetter):
(WebCore::TestObjV8Internal::withScriptStateAttributeRaisesAttrGetter):
(WebCore::TestObjV8Internal::withScriptExecutionContextAttributeRaisesAttrGetter):
(WebCore::TestObjV8Internal::withScriptExecutionContextAndScriptStateAttributeRaisesAttrGetter):
(WebCore::TestObjV8Internal::methodThatRequiresAllArgsAndThrowsCallback):
(WebCore::TestObjV8Internal::methodWithExceptionCallback):
(WebCore::TestObjV8Internal::withScriptStateVoidExceptionCallback):
(WebCore::TestObjV8Internal::withScriptStateObjExceptionCallback):
(WebCore::TestObjV8Internal::withScriptExecutionContextAndScriptStateObjExceptionCallback):
(WebCore::TestObjV8Internal::getSVGDocumentCallback):
(WebCore::TestObjV8Internal::strictFunctionCallback):

  • bindings/v8/V8Proxy.cpp:

(WebCore::V8Proxy::setDOMException):

  • bindings/v8/V8Proxy.h:

(V8Proxy):

Location:
trunk/Source/WebCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r117925 r117926  
     12012-05-22  Kentaro Hara  <haraken@chromium.org>
     2
     3        [V8] setDOMException() should return v8::Handle<v8::Value>()
     4        https://bugs.webkit.org/show_bug.cgi?id=87083
     5
     6        Reviewed by Adam Barth.
     7
     8        The following patterns are used here and there in V8 bindings:
     9
     10            setDOMException();
     11            return v8::Handle<v8::Value>();
     12
     13        and
     14
     15            setDOMException();
     16            return v8::Undefined();
     17
     18        By returning v8::Handle<v8::Value>() from setDOMException(), we can simplify the above patterns into this:
     19
     20            return setDOMException();
     21
     22        This patch just replaces the code in CodeGeneratorV8.pm. I'll replace
     23        all other custom bindings in a follow-up patch.
     24
     25        No tests. No change in behavior.
     26
     27        * bindings/scripts/CodeGeneratorV8.pm:
     28        (GenerateSetDOMException):
     29        (GenerateFunctionCallback):
     30        (GenerateFunctionCallString):
     31        * bindings/scripts/test/V8/V8TestEventTarget.cpp:
     32        (WebCore::TestEventTargetV8Internal::itemCallback):
     33        (WebCore::TestEventTargetV8Internal::dispatchEventCallback):
     34        * bindings/scripts/test/V8/V8TestInterface.cpp:
     35        (WebCore::TestInterfaceV8Internal::supplementalMethod2Callback):
     36        * bindings/scripts/test/V8/V8TestObj.cpp:
     37        (WebCore::TestObjV8Internal::attrWithGetterExceptionAttrGetter):
     38        (WebCore::TestObjV8Internal::stringAttrWithGetterExceptionAttrGetter):
     39        (WebCore::TestObjV8Internal::withScriptStateAttributeRaisesAttrGetter):
     40        (WebCore::TestObjV8Internal::withScriptExecutionContextAttributeRaisesAttrGetter):
     41        (WebCore::TestObjV8Internal::withScriptExecutionContextAndScriptStateAttributeRaisesAttrGetter):
     42        (WebCore::TestObjV8Internal::methodThatRequiresAllArgsAndThrowsCallback):
     43        (WebCore::TestObjV8Internal::methodWithExceptionCallback):
     44        (WebCore::TestObjV8Internal::withScriptStateVoidExceptionCallback):
     45        (WebCore::TestObjV8Internal::withScriptStateObjExceptionCallback):
     46        (WebCore::TestObjV8Internal::withScriptExecutionContextAndScriptStateObjExceptionCallback):
     47        (WebCore::TestObjV8Internal::getSVGDocumentCallback):
     48        (WebCore::TestObjV8Internal::strictFunctionCallback):
     49        * bindings/v8/V8Proxy.cpp:
     50        (WebCore::V8Proxy::setDOMException):
     51        * bindings/v8/V8Proxy.h:
     52        (V8Proxy):
     53
    1542012-05-22  MORITA Hajime  <morrita@google.com>
    255
  • trunk/Source/WebCore/bindings/scripts/CodeGeneratorV8.pm

    r117898 r117926  
    651651    my $result = "";
    652652
    653     $result .= $indent . "if (UNLIKELY(ec)) {\n";
    654     $result .= $indent . "    V8Proxy::setDOMException(ec, $getIsolate);\n";
    655     $result .= $indent . "    return v8::Handle<v8::Value>();\n";
    656     $result .= $indent . "}\n";
    657 
     653    $result .= $indent . "if (UNLIKELY(ec))\n";
     654    $result .= $indent . "    return V8Proxy::setDOMException(ec, $getIsolate);\n";
    658655    return $result;
    659656}
     
    14091406            AddToImplIncludes("ExceptionCode.h");
    14101407            push(@implContentDecls, "    $nativeClassName wrapper = V8${implClassName}::toNative(args.Holder());\n");
    1411             push(@implContentDecls, "    if (wrapper->role() == AnimValRole) {\n");
    1412             push(@implContentDecls, "        V8Proxy::setDOMException(NO_MODIFICATION_ALLOWED_ERR, args.GetIsolate());\n");
    1413             push(@implContentDecls, "        return v8::Handle<v8::Value>();\n");
    1414             push(@implContentDecls, "    }\n");
     1408            push(@implContentDecls, "    if (wrapper->role() == AnimValRole)\n");
     1409            push(@implContentDecls, "        return V8Proxy::setDOMException(NO_MODIFICATION_ALLOWED_ERR, args.GetIsolate());\n");
    14151410            my $svgWrappedNativeType = $codeGenerator->GetSVGWrappedTypeNeedingTearOff($implClassName);
    14161411            push(@implContentDecls, "    $svgWrappedNativeType& impInstance = wrapper->propertyReference();\n");
     
    14671462        push(@implContentDecls, "    }\n");
    14681463        push(@implContentDecls, "    fail:\n");
    1469         push(@implContentDecls, "    V8Proxy::setDOMException(ec, args.GetIsolate());\n");
    1470         push(@implContentDecls, "    return v8::Handle<v8::Value>();\n");
     1464        push(@implContentDecls, "    return V8Proxy::setDOMException(ec, args.GetIsolate());\n");
    14711465    }
    14721466
     
    33343328        } elsif ($codeGenerator->IsSVGTypeNeedingTearOff($parameter->type) and not $implClassName =~ /List$/) {
    33353329            push @arguments, "$paramName->propertyReference()";
    3336             $result .= $indent . "if (!$paramName) {\n";
    3337             $result .= $indent . "    V8Proxy::setDOMException(WebCore::TYPE_MISMATCH_ERR, args.GetIsolate());\n";
    3338             $result .= $indent . "    return v8::Handle<v8::Value>();\n";
    3339             $result .= $indent . "}\n";
     3330            $result .= $indent . "if (!$paramName)\n";
     3331            $result .= $indent . "    return V8Proxy::setDOMException(WebCore::TYPE_MISMATCH_ERR, args.GetIsolate());\n";
    33403332        } elsif ($parameter->type eq "SVGMatrix" and $implClassName eq "SVGTransformList") {
    33413333            push @arguments, "$paramName.get()";
  • trunk/Source/WebCore/bindings/scripts/test/V8/V8TestEventTarget.cpp

    r117925 r117926  
    6060    }
    6161    fail:
    62     V8Proxy::setDOMException(ec, args.GetIsolate());
    63     return v8::Handle<v8::Value>();
     62    return V8Proxy::setDOMException(ec, args.GetIsolate());
    6463}
    6564
     
    101100    }
    102101    fail:
    103     V8Proxy::setDOMException(ec, args.GetIsolate());
    104     return v8::Handle<v8::Value>();
     102    return V8Proxy::setDOMException(ec, args.GetIsolate());
    105103}
    106104
  • trunk/Source/WebCore/bindings/scripts/test/V8/V8TestInterface.cpp

    r117925 r117926  
    141141    }
    142142    fail:
    143     V8Proxy::setDOMException(ec, args.GetIsolate());
    144     return v8::Handle<v8::Value>();
     143    return V8Proxy::setDOMException(ec, args.GetIsolate());
    145144}
    146145
  • trunk/Source/WebCore/bindings/scripts/test/V8/V8TestObj.cpp

    r117925 r117926  
    627627    ExceptionCode ec = 0;
    628628    int v = imp->attrWithGetterException(ec);
    629     if (UNLIKELY(ec)) {
    630         V8Proxy::setDOMException(ec, info.GetIsolate());
    631         return v8::Handle<v8::Value>();
    632     }
     629    if (UNLIKELY(ec))
     630        return V8Proxy::setDOMException(ec, info.GetIsolate());
    633631    return v8::Integer::New(v);
    634632}
     
    671669    ExceptionCode ec = 0;
    672670    String v = imp->stringAttrWithGetterException(ec);
    673     if (UNLIKELY(ec)) {
    674         V8Proxy::setDOMException(ec, info.GetIsolate());
    675         return v8::Handle<v8::Value>();
    676     }
     671    if (UNLIKELY(ec))
     672        return V8Proxy::setDOMException(ec, info.GetIsolate());
    677673    return v8String(v, info.GetIsolate());
    678674}
     
    764760        return v8::Undefined();
    765761    RefPtr<TestObj> v = imp->withScriptStateAttributeRaises(state, ec);
    766     if (UNLIKELY(ec)) {
    767         V8Proxy::setDOMException(ec, info.GetIsolate());
    768         return v8::Handle<v8::Value>();
    769     }
     762    if (UNLIKELY(ec))
     763        return V8Proxy::setDOMException(ec, info.GetIsolate());
    770764    if (state.hadException())
    771765        return throwError(state.exception(), info.GetIsolate());
     
    799793        return v8::Undefined();
    800794    RefPtr<TestObj> v = imp->withScriptExecutionContextAttributeRaises(scriptContext, ec);
    801     if (UNLIKELY(ec)) {
    802         V8Proxy::setDOMException(ec, info.GetIsolate());
    803         return v8::Handle<v8::Value>();
    804     }
     795    if (UNLIKELY(ec))
     796        return V8Proxy::setDOMException(ec, info.GetIsolate());
    805797    return toV8(v.release(), info.GetIsolate());
    806798}
     
    863855        return v8::Undefined();
    864856    RefPtr<TestObj> v = imp->withScriptExecutionContextAndScriptStateAttributeRaises(state, scriptContext, ec);
    865     if (UNLIKELY(ec)) {
    866         V8Proxy::setDOMException(ec, info.GetIsolate());
    867         return v8::Handle<v8::Value>();
    868     }
     857    if (UNLIKELY(ec))
     858        return V8Proxy::setDOMException(ec, info.GetIsolate());
    869859    if (state.hadException())
    870860        return throwError(state.exception(), info.GetIsolate());
     
    13481338    }
    13491339    fail:
    1350     V8Proxy::setDOMException(ec, args.GetIsolate());
    1351     return v8::Handle<v8::Value>();
     1340    return V8Proxy::setDOMException(ec, args.GetIsolate());
    13521341}
    13531342
     
    14111400    }
    14121401    fail:
    1413     V8Proxy::setDOMException(ec, args.GetIsolate());
    1414     return v8::Handle<v8::Value>();
     1402    return V8Proxy::setDOMException(ec, args.GetIsolate());
    14151403}
    14161404
     
    14741462    }
    14751463    fail:
    1476     V8Proxy::setDOMException(ec, args.GetIsolate());
    1477     return v8::Handle<v8::Value>();
     1464    return V8Proxy::setDOMException(ec, args.GetIsolate());
    14781465}
    14791466
     
    14931480    }
    14941481    fail:
    1495     V8Proxy::setDOMException(ec, args.GetIsolate());
    1496     return v8::Handle<v8::Value>();
     1482    return V8Proxy::setDOMException(ec, args.GetIsolate());
    14971483}
    14981484
     
    15401526    }
    15411527    fail:
    1542     V8Proxy::setDOMException(ec, args.GetIsolate());
    1543     return v8::Handle<v8::Value>();
     1528    return V8Proxy::setDOMException(ec, args.GetIsolate());
    15441529}
    15451530
     
    19291914    }
    19301915    fail:
    1931     V8Proxy::setDOMException(ec, args.GetIsolate());
    1932     return v8::Handle<v8::Value>();
     1916    return V8Proxy::setDOMException(ec, args.GetIsolate());
    19331917}
    19341918
     
    20272011    }
    20282012    fail:
    2029     V8Proxy::setDOMException(ec, args.GetIsolate());
    2030     return v8::Handle<v8::Value>();
     2013    return V8Proxy::setDOMException(ec, args.GetIsolate());
    20312014}
    20322015
  • trunk/Source/WebCore/bindings/v8/V8Proxy.cpp

    r117873 r117926  
    587587        break;
    588588
    589 void V8Proxy::setDOMException(int ec, v8::Isolate* isolate)
     589v8::Handle<v8::Value> V8Proxy::setDOMException(int ec, v8::Isolate* isolate)
    590590{
    591591    if (ec <= 0)
    592         return;
     592        return v8::Handle<v8::Value>();
    593593
    594594    ExceptionCodeDescription description(ec);
     
    600600
    601601    if (exception.IsEmpty())
    602         return;
     602        return v8::Handle<v8::Value>();
    603603
    604604    // Attach an Error object to the DOMException. This is then lazily used to get the stack value.
     
    608608    exception->ToObject()->SetAccessor(v8String("stack", isolate), DOMExceptionStackGetter, DOMExceptionStackSetter, error);
    609609
    610     v8::ThrowException(exception);
     610    return v8::ThrowException(exception);
    611611}
    612612
  • trunk/Source/WebCore/bindings/v8/V8Proxy.h

    r117898 r117926  
    235235        // If the exception code is different from zero, a DOM exception is
    236236        // schedule to be thrown.
    237         static void setDOMException(int exceptionCode, v8::Isolate*);
     237        static v8::Handle<v8::Value> setDOMException(int exceptionCode, v8::Isolate*);
    238238
    239239        // Schedule an error object to be thrown.
Note: See TracChangeset for help on using the changeset viewer.