Changeset 126004 in webkit


Ignore:
Timestamp:
Aug 20, 2012 12:47:27 AM (12 years ago)
Author:
haraken@chromium.org
Message:

[V8] Move V8Proxy::newInstance() to V8ObjectConstructor
https://bugs.webkit.org/show_bug.cgi?id=94443

Reviewed by Adam Barth.

To kill V8Proxy, this patch moves V8Proxy::newInstance() to
V8ObjectConstructor::newInstanceInFrame().
In addition, this patch does the following things:

  • For consistency with V8ObjectConstructor::newInstanceInFrame(),

this patch inserts an if(v8::V8::IsDead()) check to just after
Function::NewInstance(). The check is done by V8Binding::assertIfV8IsDead().

  • To avoid #include circular dependency, this patch de-inline

V8ObjectConstructor::newInstance()s. I didn't observe any perf regression.
I don't think these methods are worth being inlined, because
these methods call Function::NewInstance(), which is not inlined
and calls a bunch of heavy mehtods in V8.

No tests. No change in behavior.

  • bindings/v8/NPV8Object.cpp:

(_NPN_Construct):

  • bindings/v8/V8Binding.cpp:

(WebCore::assertIfV8IsDead):
(WebCore):

  • bindings/v8/V8Binding.h:

(WebCore):

  • bindings/v8/V8ObjectConstructor.cpp:

(WebCore::V8ObjectConstructor::newInstance):
(WebCore):
(WebCore::V8ObjectConstructor::newInstanceInFrame):

  • bindings/v8/V8ObjectConstructor.h:

(WebCore):
(V8ObjectConstructor):

  • bindings/v8/V8Proxy.cpp:

(WebCore::V8Proxy::runScript):
(WebCore::V8Proxy::instrumentedCallFunction):

Location:
trunk/Source/WebCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r126002 r126004  
     12012-08-20  Kentaro Hara  <haraken@chromium.org>
     2
     3        [V8] Move V8Proxy::newInstance() to V8ObjectConstructor
     4        https://bugs.webkit.org/show_bug.cgi?id=94443
     5
     6        Reviewed by Adam Barth.
     7
     8        To kill V8Proxy, this patch moves V8Proxy::newInstance() to
     9        V8ObjectConstructor::newInstanceInFrame().
     10        In addition, this patch does the following things:
     11
     12        - For consistency with V8ObjectConstructor::newInstanceInFrame(),
     13        this patch inserts an if(v8::V8::IsDead()) check to just after
     14        Function::NewInstance(). The check is done by V8Binding::assertIfV8IsDead().
     15
     16        - To avoid #include circular dependency, this patch de-inline
     17        V8ObjectConstructor::newInstance()s. I didn't observe any perf regression.
     18        I don't think these methods are worth being inlined, because
     19        these methods call Function::NewInstance(), which is not inlined
     20        and calls a bunch of heavy mehtods in V8.
     21
     22        No tests. No change in behavior.
     23
     24        * bindings/v8/NPV8Object.cpp:
     25        (_NPN_Construct):
     26        * bindings/v8/V8Binding.cpp:
     27        (WebCore::assertIfV8IsDead):
     28        (WebCore):
     29        * bindings/v8/V8Binding.h:
     30        (WebCore):
     31        * bindings/v8/V8ObjectConstructor.cpp:
     32        (WebCore::V8ObjectConstructor::newInstance):
     33        (WebCore):
     34        (WebCore::V8ObjectConstructor::newInstanceInFrame):
     35        * bindings/v8/V8ObjectConstructor.h:
     36        (WebCore):
     37        (V8ObjectConstructor):
     38        * bindings/v8/V8Proxy.cpp:
     39        (WebCore::V8Proxy::runScript):
     40        (WebCore::V8Proxy::instrumentedCallFunction):
     41
    1422012-08-20  Kentaro Hara  <haraken@chromium.org>
    243
  • trunk/Source/WebCore/bindings/v8/NPV8Object.cpp

    r125998 r126004  
    592592        v8::Handle<v8::Function> ctor(v8::Function::Cast(*ctorObj));
    593593        if (!ctor->IsNull()) {
    594             V8Proxy* proxy = toV8Proxy(npObject);
    595             ASSERT(proxy);
    596 
     594            Frame* frame = object->rootObject->frame();
     595            ASSERT(frame);
    597596            OwnArrayPtr<v8::Handle<v8::Value> > argv = createValueListFromVariantArgs(arguments, argumentCount, npObject);
    598             resultObject = proxy->newInstance(ctor, argumentCount, argv.get());
     597            resultObject = V8ObjectConstructor::newInstanceInDocument(ctor, argumentCount, argv.get(), frame ? frame->document() : 0);
    599598        }
    600599
  • trunk/Source/WebCore/bindings/v8/V8Binding.cpp

    r125995 r126004  
    382382}
    383383
     384void crashIfV8IsDead()
     385{
     386    if (v8::V8::IsDead()) {
     387        // FIXME: We temporarily deal with V8 internal error situations
     388        // such as out-of-memory by crashing the renderer.
     389        CRASH();
     390    }
     391}
     392
    384393} // namespace WebCore
  • trunk/Source/WebCore/bindings/v8/V8Binding.h

    r125995 r126004  
    369369    PassRefPtr<DOMStringList> toDOMStringList(v8::Handle<v8::Value>);
    370370
     371    void crashIfV8IsDead();
     372
    371373    class V8ParameterBase {
    372374    public:
  • trunk/Source/WebCore/bindings/v8/V8ObjectConstructor.cpp

    r125995 r126004  
    2626#include "V8ObjectConstructor.h"
    2727
     28#include "Frame.h"
    2829#include "V8Binding.h"
     30#include "V8RecursionScope.h"
     31
     32#if PLATFORM(CHROMIUM)
     33#include "TraceEvent.h"
     34#endif
    2935
    3036namespace WebCore {
     37
     38v8::Local<v8::Object> V8ObjectConstructor::newInstance(v8::Handle<v8::Function> function)
     39{
     40    if (function.IsEmpty())
     41        return v8::Local<v8::Object>();
     42    ConstructorMode constructorMode;
     43    V8RecursionScope::MicrotaskSuppression scope;
     44    v8::Local<v8::Object> result = function->NewInstance();
     45    crashIfV8IsDead();
     46    return result;
     47}
     48
     49v8::Local<v8::Object> V8ObjectConstructor::newInstance(v8::Handle<v8::ObjectTemplate> objectTemplate)
     50{
     51    if (objectTemplate.IsEmpty())
     52        return v8::Local<v8::Object>();
     53    ConstructorMode constructorMode;
     54    V8RecursionScope::MicrotaskSuppression scope;
     55    v8::Local<v8::Object> result = objectTemplate->NewInstance();
     56    crashIfV8IsDead();
     57    return result;
     58}
     59
     60v8::Local<v8::Object> V8ObjectConstructor::newInstance(v8::Handle<v8::Function> function, int argc, v8::Handle<v8::Value> argv[])
     61{
     62    if (function.IsEmpty())
     63        return v8::Local<v8::Object>();
     64    ConstructorMode constructorMode;
     65    V8RecursionScope::MicrotaskSuppression scope;
     66    v8::Local<v8::Object> result = function->NewInstance(argc, argv);
     67    crashIfV8IsDead();
     68    return result;
     69}
     70
     71v8::Local<v8::Object> V8ObjectConstructor::newInstanceInDocument(v8::Handle<v8::Function> function, int argc, v8::Handle<v8::Value> argv[], Document* document)
     72{
     73#if PLATFORM(CHROMIUM)
     74    TRACE_EVENT0("v8", "v8.newInstance");
     75#endif
     76
     77    // No artificial limitations on the depth of recursion, see comment in
     78    // V8Proxy::callFunction.
     79    V8RecursionScope recursionScope(document);
     80    v8::Local<v8::Object> result = function->NewInstance(argc, argv);
     81    crashIfV8IsDead();
     82    return result;
     83}
    3184
    3285v8::Handle<v8::Value> V8ObjectConstructor::isValidConstructorMode(const v8::Arguments& args)
  • trunk/Source/WebCore/bindings/v8/V8ObjectConstructor.h

    r125995 r126004  
    3333
    3434#include "V8PerIsolateData.h"
    35 #include "V8RecursionScope.h"
    3635
    3736#include <v8.h>
    3837
    3938namespace WebCore {
     39
     40class Document;
    4041
    4142class ConstructorMode {
     
    6768class V8ObjectConstructor {
    6869public:
    69     static inline v8::Local<v8::Object> newInstance(v8::Handle<v8::Function>);
    70     static inline v8::Local<v8::Object> newInstance(v8::Handle<v8::ObjectTemplate>);
    71     static inline v8::Local<v8::Object> newInstance(v8::Handle<v8::Function>, int argc, v8::Handle<v8::Value> argv[]);
     70    static v8::Local<v8::Object> newInstance(v8::Handle<v8::Function>);
     71    static v8::Local<v8::Object> newInstance(v8::Handle<v8::ObjectTemplate>);
     72    static v8::Local<v8::Object> newInstance(v8::Handle<v8::Function>, int, v8::Handle<v8::Value> argv[]);
     73    static v8::Local<v8::Object> newInstanceInDocument(v8::Handle<v8::Function>, int, v8::Handle<v8::Value> argv[], Document*);
    7274
    7375    static v8::Handle<v8::Value> isValidConstructorMode(const v8::Arguments&);
    7476};
    7577
    76 v8::Local<v8::Object> V8ObjectConstructor::newInstance(v8::Handle<v8::Function> function)
    77 {
    78     if (function.IsEmpty())
    79         return v8::Local<v8::Object>();
    80     ConstructorMode constructorMode;
    81     V8RecursionScope::MicrotaskSuppression scope;
    82     return function->NewInstance();
    83 }
    84 
    85 v8::Local<v8::Object> V8ObjectConstructor::newInstance(v8::Handle<v8::ObjectTemplate> objectTemplate)
    86 {
    87     if (objectTemplate.IsEmpty())
    88         return v8::Local<v8::Object>();
    89     ConstructorMode constructorMode;
    90     V8RecursionScope::MicrotaskSuppression scope;
    91     return objectTemplate->NewInstance();
    92 }
    93 
    94 v8::Local<v8::Object> V8ObjectConstructor::newInstance(v8::Handle<v8::Function> function, int argc, v8::Handle<v8::Value> argv[])
    95 {
    96     if (function.IsEmpty())
    97         return v8::Local<v8::Object>();
    98     ConstructorMode constructorMode;
    99     V8RecursionScope::MicrotaskSuppression scope;
    100     return function->NewInstance(argc, argv);
    101 }
    102 
    10378} // namespace WebCore
    10479
  • trunk/Source/WebCore/bindings/v8/V8Proxy.cpp

    r126002 r126004  
    106106}
    107107
    108 static void handleFatalErrorInV8()
    109 {
    110     // FIXME: We temporarily deal with V8 internal error situations
    111     // such as out-of-memory by crashing the renderer.
    112     CRASH();
    113 }
    114 
    115108static v8::Local<v8::Value> handleMaxRecursionDepthExceeded()
    116109{
     
    263256        return v8::Local<v8::Value>();
    264257
    265     if (v8::V8::IsDead())
    266         handleFatalErrorInV8();
    267 
     258    crashIfV8IsDead();
    268259    return result;
    269260}
     
    321312
    322313    InspectorInstrumentation::didCallFunction(cookie);
    323 
    324     if (v8::V8::IsDead())
    325         handleFatalErrorInV8();
    326 
    327     return result;
    328 }
    329 
    330 v8::Local<v8::Value> V8Proxy::newInstance(v8::Handle<v8::Function> constructor, int argc, v8::Handle<v8::Value> args[])
    331 {
    332 #if PLATFORM(CHROMIUM)
    333     TRACE_EVENT0("v8", "v8.newInstance");
    334 #endif
    335 
    336     // No artificial limitations on the depth of recursion, see comment in
    337     // V8Proxy::callFunction.
    338     v8::Local<v8::Value> result;
    339     {
    340         V8RecursionScope recursionScope(frame() ? frame()->document() : 0);
    341         result = constructor->NewInstance(argc, args);
    342     }
    343 
    344     if (v8::V8::IsDead())
    345         handleFatalErrorInV8();
    346 
     314    crashIfV8IsDead();
    347315    return result;
    348316}
Note: See TracChangeset for help on using the changeset viewer.