Changeset 49148 in webkit
- Timestamp:
- Oct 5, 2009 9:55:14 PM (14 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r49145 r49148 1 2009-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 1 21 2009-10-05 Stephanie Lewis <slewis@apple.com> 2 22 -
trunk/WebCore/bindings/v8/DateExtension.cpp
r48612 r49148 33 33 34 34 #include "V8Proxy.h" 35 #include "V8HiddenPropertyName.h" 35 36 36 37 namespace WebCore { … … 57 58 " }" 58 59 " };" 60 " native function Setup();" 59 61 " native function OnSleepDetected();" 60 " native function GiveEnableSleepDetectionFunction();" 61 " GiveEnableSleepDetectionFunction(enableSleepDetection);" 62 " Setup(Date, enableSleepDetection);" 62 63 "})()"; 63 64 … … 75 76 void DateExtension::setAllowSleep(bool allow) 76 77 { 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 77 90 v8::Handle<v8::Value> argv[1]; 78 91 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); 81 93 } 82 94 83 95 v8::Handle<v8::FunctionTemplate> DateExtension::GetNativeFunction(v8::Handle<v8::String> name) 84 96 { 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); 87 99 if (name->Equals(v8::String::New("OnSleepDetected"))) 88 100 return v8::FunctionTemplate::New(OnSleepDetected); … … 91 103 } 92 104 93 v oid DateExtension::weakCallback(v8::Persistent<v8::Value> object, void* param)105 v8::Handle<v8::Value> DateExtension::Setup(const v8::Arguments& args) 94 106 { 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()) 109 108 return v8::Undefined(); 110 109 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); 119 114 return v8::Undefined(); 120 115 } … … 122 117 v8::Handle<v8::Value> DateExtension::OnSleepDetected(const v8::Arguments&) 123 118 { 124 // After we call TerminateExecution(), we can't call back into JavaScript again, so125 // reset all the other frames first.126 get()->setAllowSleep(true);127 128 119 v8::V8::TerminateExecution(); 129 120 return v8::Undefined(); -
trunk/WebCore/bindings/v8/DateExtension.h
r48612 r49148 34 34 #include <v8.h> 35 35 36 #include "Vector.h"37 38 36 namespace WebCore { 39 37 … … 47 45 DateExtension(); 48 46 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&); 50 48 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;55 49 56 50 static DateExtension* extension; -
trunk/WebCore/bindings/v8/V8HiddenPropertyName.h
r49074 r49148 41 41 V(listener) \ 42 42 V(attributeListener) \ 43 V(sleepFunction) \ 43 44 V(toStringString) 44 45
Note: See TracChangeset
for help on using the changeset viewer.