Changeset 49148 in webkit


Ignore:
Timestamp:
Oct 5, 2009 9:55:14 PM (14 years ago)
Author:
abarth@webkit.org
Message:

2009-10-05 John Abd-El-Malek <jam@chromium.org>

Reviewed by Adam Barth.

Fix reliablity bot crash in DateExtension.
https://bugs.webkit.org/show_bug.cgi?id=30033

There were a few problems using the weak persistent pointers because no one else had a
handle to them. The new approach stores them as a hidden value on the Date constructor.

  • bindings/v8/DateExtension.cpp: (WebCore::DateExtension::setAllowSleep): (WebCore::DateExtension::GetNativeFunction): (WebCore::DateExtension::Setup): (WebCore::DateExtension::OnSleepDetected):
  • bindings/v8/DateExtension.h:
  • bindings/v8/V8HiddenPropertyName.cpp: (WebCore::V8HiddenPropertyName::sleepFunction):
  • bindings/v8/V8HiddenPropertyName.h:
Location:
trunk/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r49145 r49148  
     12009-10-05  John Abd-El-Malek  <jam@chromium.org>
     2
     3        Reviewed by Adam Barth.
     4
     5        Fix reliablity bot crash in DateExtension.
     6        https://bugs.webkit.org/show_bug.cgi?id=30033
     7
     8        There were a few problems using the weak persistent pointers because no one else had a
     9        handle to them.  The new approach stores them as a hidden value on the Date constructor.
     10
     11        * bindings/v8/DateExtension.cpp:
     12        (WebCore::DateExtension::setAllowSleep):
     13        (WebCore::DateExtension::GetNativeFunction):
     14        (WebCore::DateExtension::Setup):
     15        (WebCore::DateExtension::OnSleepDetected):
     16        * bindings/v8/DateExtension.h:
     17        * bindings/v8/V8HiddenPropertyName.cpp:
     18        (WebCore::V8HiddenPropertyName::sleepFunction):
     19        * bindings/v8/V8HiddenPropertyName.h:
     20
    1212009-10-05  Stephanie Lewis  <slewis@apple.com>
    222
  • trunk/WebCore/bindings/v8/DateExtension.cpp

    r48612 r49148  
    3333
    3434#include "V8Proxy.h"
     35#include "V8HiddenPropertyName.h"
    3536
    3637namespace WebCore {
     
    5758    "    }"
    5859    "  };"
     60    "  native function Setup();"
    5961    "  native function OnSleepDetected();"
    60     "  native function GiveEnableSleepDetectionFunction();"
    61     "  GiveEnableSleepDetectionFunction(enableSleepDetection);"
     62    "  Setup(Date, enableSleepDetection);"
    6263    "})()";
    6364
     
    7576void DateExtension::setAllowSleep(bool allow)
    7677{
     78    v8::Local<v8::Value> result = V8Proxy::retrieve()->context()->Global()->Get(v8::String::New("Date"));
     79    if (result.IsEmpty())
     80        return;
     81
     82    v8::Handle<v8::Object> dateObject = v8::Handle<v8::Object>::Cast(result);
     83    if (dateObject.IsEmpty())
     84        return;
     85
     86    v8::Local<v8::Value> sleepFunctionHandle = dateObject->GetHiddenValue(V8HiddenPropertyName::sleepFunction());
     87    if (sleepFunctionHandle.IsEmpty() || !sleepFunctionHandle->IsFunction())
     88        return;
     89
    7790    v8::Handle<v8::Value> argv[1];
    7891    argv[0] = v8::String::New(allow ? "false" : "true");
    79     for (size_t i = 0; i < callEnableSleepDetectionFunctionPointers.size(); ++i)
    80         callEnableSleepDetectionFunctionPointers[i]->Call(v8::Object::New(), 1, argv);
     92    v8::Handle<v8::Function>::Cast(sleepFunctionHandle)->Call(v8::Object::New(), 1, argv);
    8193}
    8294
    8395v8::Handle<v8::FunctionTemplate> DateExtension::GetNativeFunction(v8::Handle<v8::String> name)
    8496{
    85     if (name->Equals(v8::String::New("GiveEnableSleepDetectionFunction")))
    86         return v8::FunctionTemplate::New(GiveEnableSleepDetectionFunction);
     97    if (name->Equals(v8::String::New("Setup")))
     98        return v8::FunctionTemplate::New(Setup);
    8799    if (name->Equals(v8::String::New("OnSleepDetected")))
    88100        return v8::FunctionTemplate::New(OnSleepDetected);
     
    91103}
    92104
    93 void DateExtension::weakCallback(v8::Persistent<v8::Value> object, void* param)
     105v8::Handle<v8::Value> DateExtension::Setup(const v8::Arguments& args)
    94106{
    95     DateExtension* extension = get();
    96     for (size_t i = 0; i < extension->callEnableSleepDetectionFunctionPointers.size(); ++i) {
    97         if (extension->callEnableSleepDetectionFunctionPointers[i] == object) {
    98             object.Dispose();
    99             extension->callEnableSleepDetectionFunctionPointers.remove(i);
    100             return;
    101         }
    102     }
    103     ASSERT_NOT_REACHED();
    104 }
    105 
    106 v8::Handle<v8::Value> DateExtension::GiveEnableSleepDetectionFunction(const v8::Arguments& args)
    107 {
    108     if (args.Length() != 1 || !args[0]->IsFunction())
     107    if (args.Length() != 2 || !args[0]->IsObject() || !args[1]->IsFunction())
    109108        return v8::Undefined();
    110109
    111     // Ideally, we would get the Frame* here and associate it with the function pointer, so that
    112     // each time we go into an unload handler we just call that frame's function.  However there's
    113     // no way to get the Frame* at this point, so we just store all the function pointers and call
    114     // them all each time.
    115     DateExtension* extension = get();
    116     extension->callEnableSleepDetectionFunctionPointers.append(
    117         v8::Persistent<v8::Function>::New(v8::Handle<v8::Function>::Cast(args[0])));
    118     extension->callEnableSleepDetectionFunctionPointers.last().MakeWeak(NULL, weakCallback);
     110    v8::Handle<v8::Object> dateObject = v8::Handle<v8::Object>::Cast(args[0]);
     111    v8::Handle<v8::Function> enableSleepDetectionFunction = v8::Handle<v8::Function>::Cast(args[1]);
     112
     113    dateObject->SetHiddenValue(V8HiddenPropertyName::sleepFunction(), enableSleepDetectionFunction);
    119114    return v8::Undefined();
    120115}
     
    122117v8::Handle<v8::Value> DateExtension::OnSleepDetected(const v8::Arguments&)
    123118{
    124     // After we call TerminateExecution(), we can't call back into JavaScript again, so
    125     // reset all the other frames first.
    126     get()->setAllowSleep(true);
    127 
    128119    v8::V8::TerminateExecution();
    129120    return v8::Undefined();
  • trunk/WebCore/bindings/v8/DateExtension.h

    r48612 r49148  
    3434#include <v8.h>
    3535
    36 #include "Vector.h"
    37 
    3836namespace WebCore {
    3937
     
    4745    DateExtension();
    4846    virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(v8::Handle<v8::String>);
    49     static v8::Handle<v8::Value> GiveEnableSleepDetectionFunction(const v8::Arguments&);
     47    static v8::Handle<v8::Value> Setup(const v8::Arguments&);
    5048    static v8::Handle<v8::Value> OnSleepDetected(const v8::Arguments&);
    51     static void weakCallback(v8::Persistent<v8::Value> object, void* param);
    52 
    53     typedef WTF::Vector<v8::Persistent<v8::Function> > FunctionPointers;
    54     FunctionPointers callEnableSleepDetectionFunctionPointers;
    5549
    5650    static DateExtension* extension;
  • trunk/WebCore/bindings/v8/V8HiddenPropertyName.h

    r49074 r49148  
    4141    V(listener) \
    4242    V(attributeListener) \
     43    V(sleepFunction) \
    4344    V(toStringString)
    4445
Note: See TracChangeset for help on using the changeset viewer.