+2007-09-13 Sam Weinig <sam@webkit.org>
+
+ Rubber stamped by Darin.
+
+ Make DumpRenderTree more cross platform ready.
+ - Convert GCController to use the JSCore API instead of the WebScriptObject.
+ - Use CF types instead of NS objects.
+ - General cleanup.
+
+ * DumpRenderTree/DumpRenderTree.h:
+ * DumpRenderTree/DumpRenderTree.mm:
+ (dumpRenderTree):
+ (dump):
+ (runTest):
+ * DumpRenderTree/DumpRenderTree.xcodeproj/project.pbxproj:
+ * DumpRenderTree/EditingDelegate.m:
+ * DumpRenderTree/FrameLoadDelegate.h:
+ * DumpRenderTree/FrameLoadDelegate.mm:
+ (-[FrameLoadDelegate init]):
+ (-[FrameLoadDelegate dealloc]):
+ (-[FrameLoadDelegate webView:didClearWindowObject:forFrame:]):
+ * DumpRenderTree/GCController.cpp: Added.
+ (GCController::GCController):
+ (GCController::~GCController):
+ (collectCallback):
+ (collectOnAlternateThreadCallback):
+ (getJSObjectCountCallback):
+ (GCController::makeWindowObject):
+ (GCController::getJSClass):
+ (GCController::staticFunctions):
+ * DumpRenderTree/GCController.h:
+ * DumpRenderTree/GCController.mm:
+ (GCController::collect):
+ (GCController::collectOnAlternateThread):
+ (GCController::getJSObjectCount):
+ * DumpRenderTree/LayoutTestController.cpp:
+ (LayoutTestController::makeWindowObject):
+ (LayoutTestController::getJSClass):
+ * DumpRenderTree/LayoutTestController.h:
+ * DumpRenderTree/LayoutTestControllerMac.mm:
+ (LayoutTestController::addDisallowedURL):
+ (waitUntilDoneWatchdogFired):
+ (LayoutTestController::waitUntilDone):
+ * DumpRenderTree/ResourceLoadDelegate.m:
+ (-[ResourceLoadDelegate webView:resource:willSendRequest:redirectResponse:fromDataSource:]):
+
2007-09-12 Sam Weinig <sam@webkit.org>
Reviewed by Stephanie.
/*
- * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
+ * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#ifndef DumpRenderTree_h
+#define DumpRenderTree_h
@class DumpRenderTreeDraggingInfo;
@class EditingDelegate;
@class ResourceLoadDelegate;
@class UIDelegate;
@class WebFrame;
-@class WebScriptObject;
@class WebView;
+extern volatile bool done;
-extern BOOL dumpAsText;
-extern BOOL dumpDOMAsWebArchive;
-extern BOOL dumpSourceAsWebArchive;
-extern BOOL dumpSelectionRect;
-extern BOOL dumpTitleChanges;
-extern BOOL dumpBackForwardList;
-extern BOOL dumpChildFrameScrollPositions;
-extern BOOL dumpChildFramesAsText;
-extern BOOL testRepaint;
-extern BOOL repaintSweepHorizontally;
-extern BOOL windowIsKey;
-extern BOOL shouldDumpEditingCallbacks;
-extern BOOL shouldDumpResourceLoadCallbacks;
-extern BOOL shouldDumpFrameLoadCallbacks;
-extern BOOL shouldDumpResourceLoadCallbacks;
-extern BOOL shouldDumpFrameLoadCallbacks;
-extern BOOL waitToDump;
-extern BOOL canOpenWindows;
-extern BOOL closeWebViews;
-extern BOOL closeRemainingWindowsWhenComplete;
-extern BOOL addFileToPasteboardOnDrag;
+extern bool dumpAsText;
+extern bool dumpSelectionRect;
+extern bool dumpTitleChanges;
+extern bool dumpBackForwardList;
+extern bool dumpChildFrameScrollPositions;
+extern bool dumpChildFramesAsText;
+extern bool dumpDOMAsWebArchive;
+extern bool dumpSourceAsWebArchive;
+extern bool shouldDumpEditingCallbacks;
+extern bool shouldDumpResourceLoadCallbacks;
+extern bool shouldDumpFrameLoadCallbacks;
+extern bool shouldDumpResourceLoadCallbacks;
+extern bool shouldDumpFrameLoadCallbacks;
+extern bool addFileToPasteboardOnDrag;
+extern bool canOpenWindows;
+extern bool closeRemainingWindowsWhenComplete;
+extern bool closeWebViews;
+extern bool repaintSweepHorizontally;
+extern bool testRepaint;
+extern bool waitToDump;
+extern bool windowIsKey;
-extern volatile BOOL done;
+extern CFMutableArrayRef allWindowsRef;
+extern CFMutableSetRef disallowedURLs;
+extern CFRunLoopTimerRef waitToDumpWatchdog;
+extern CFTimeInterval waitToDumpWatchdogInterval;
+
+extern WebFrame* mainFrame;
+extern WebFrame* topLoadingFrame;
-extern WebFrame *mainFrame;
extern DumpRenderTreeDraggingInfo *draggingInfo;
-extern WebFrame *topLoadingFrame;
-extern NavigationController *navigationController;
-extern NSTimer *waitToDumpWatchdog;
-extern NSTimeInterval waitToDumpWatchdogInterval;
-extern CFMutableArrayRef allWindowsRef;
-extern NSMutableSet *disallowedURLs;
+
+// Global Controllers
+extern NavigationController* navigationController;
// Delegates
-extern FrameLoadDelegate *frameLoadDelegate;
-extern UIDelegate *uiDelegate;
-extern EditingDelegate *editingDelegate;
-extern ResourceLoadDelegate *resourceLoadDelegate;
-extern PolicyDelegate *policyDelegate;
+extern FrameLoadDelegate* frameLoadDelegate;
+extern UIDelegate* uiDelegate;
+extern EditingDelegate* editingDelegate;
+extern ResourceLoadDelegate* resourceLoadDelegate;
+extern PolicyDelegate* policyDelegate;
-WebView *createWebView();
+WebView* createWebView();
void displayWebView();
void dump(void);
+
+#endif DumpRenderTree_h
}
@end
-LayoutTestController* layoutTestController = 0;
-
-BOOL windowIsKey = YES;
-WebFrame *mainFrame = 0;
-BOOL shouldDumpEditingCallbacks;
-BOOL shouldDumpResourceLoadCallbacks;
-BOOL shouldDumpFrameLoadCallbacks;
-NSMutableSet *disallowedURLs = 0;
-BOOL waitToDump; // TRUE if waitUntilDone() has been called, but notifyDone() has not yet been called
-BOOL canOpenWindows;
-BOOL closeWebViews;
-BOOL closeRemainingWindowsWhenComplete = YES;
-BOOL addFileToPasteboardOnDrag = NO;
-
static void runTest(const char *pathOrURL);
static NSString *md5HashStringForBitmap(CGImageRef bitmap);
-volatile BOOL done;
-NavigationController *navigationController = nil;
-
-NSTimer *waitToDumpWatchdog;
-NSTimeInterval waitToDumpWatchdogInterval = 10; // seconds
-
-// Delegates
-FrameLoadDelegate *frameLoadDelegate;
-UIDelegate *uiDelegate;
-EditingDelegate *editingDelegate;
-ResourceLoadDelegate *resourceLoadDelegate;
-PolicyDelegate *policyDelegate;
-
// Deciding when it's OK to dump out the state is a bit tricky. All these must be true:
// - There is no load in progress
// - There is no work queued up (see workQueue var, below)
// and notifyDone was called subsequently.
// Note that the call to notifyDone and the end of the load can happen in either order.
+volatile bool done;
+
+LayoutTestController* layoutTestController = 0;
+NavigationController* navigationController = 0;
+
+WebFrame *mainFrame = 0;
// This is the topmost frame that is loading, during a given load, or nil when no load is
// in progress. Usually this is the same as the main frame, but not always. In the case
// where a frameset is loaded, and then new content is loaded into one of the child frames,
// that child frame is the "topmost frame that is loading".
WebFrame *topLoadingFrame = nil; // !nil iff a load is in progress
-BOOL dumpAsText;
-BOOL dumpDOMAsWebArchive;
-BOOL dumpSourceAsWebArchive;
-BOOL dumpSelectionRect;
-BOOL dumpTitleChanges = NO;
-BOOL dumpBackForwardList;
-BOOL dumpChildFrameScrollPositions;
-BOOL dumpChildFramesAsText;
-BOOL testRepaint;
-BOOL repaintSweepHorizontally;
+bool addFileToPasteboardOnDrag = NO;
+bool canOpenWindows;
+bool closeRemainingWindowsWhenComplete = YES;
+bool closeWebViews;
+bool dumpAsText;
+bool dumpBackForwardList;
+bool dumpChildFramesAsText;
+bool dumpChildFrameScrollPositions;
+bool dumpDOMAsWebArchive;
+bool dumpSelectionRect;
+bool dumpSourceAsWebArchive;
+bool dumpTitleChanges = NO;
+bool repaintSweepHorizontally;
+bool shouldDumpEditingCallbacks;
+bool shouldDumpFrameLoadCallbacks;
+bool shouldDumpResourceLoadCallbacks;
+bool testRepaint;
+bool waitToDump; // TRUE if waitUntilDone() has been called, but notifyDone() has not yet been called
+bool windowIsKey = YES;
+
+CFMutableArrayRef allWindowsRef = 0;
+CFMutableSetRef disallowedURLs = 0;
+CFRunLoopTimerRef waitToDumpWatchdog = 0;
+CFTimeInterval waitToDumpWatchdogInterval = 10.0; // seconds
+
+// Delegates
+FrameLoadDelegate *frameLoadDelegate;
+UIDelegate *uiDelegate;
+EditingDelegate *editingDelegate;
+ResourceLoadDelegate *resourceLoadDelegate;
+PolicyDelegate *policyDelegate;
static int dumpPixels;
static int paint;
const unsigned maxViewHeight = 600;
const unsigned maxViewWidth = 800;
-CFMutableArrayRef allWindowsRef;
-
static pthread_mutex_t javaScriptThreadsMutex = PTHREAD_MUTEX_INITIALIZER;
static BOOL javaScriptThreadsShouldTerminate;
[navigationController release];
navigationController = nil;
-
- [disallowedURLs release];
- disallowedURLs = nil;
-
+
+ if (disallowedURLs) {
+ CFRelease(disallowedURLs);
+ disallowedURLs = 0;
+ }
+
if (dumpPixels)
restoreColorSpace(0);
}
void dump(void)
{
- [waitToDumpWatchdog invalidate];
- [waitToDumpWatchdog release];
- waitToDumpWatchdog = nil;
-
+ if (waitToDumpWatchdog) {
+ CFRunLoopTimerInvalidate(waitToDumpWatchdog);
+ CFRelease(waitToDumpWatchdog);
+ waitToDumpWatchdog = 0;
+ }
+
if (dumpTree) {
NSString *result = nil;
}
if (dumpBackForwardList) {
- unsigned count = [(NSArray *)allWindowsRef count];
+ unsigned count = CFArrayGetCount(allWindowsRef);
for (unsigned i = 0; i < count; i++) {
- NSWindow *window = [(NSArray *)allWindowsRef objectAtIndex:i];
+ NSWindow *window = (NSWindow *)CFArrayGetValueAtIndex(allWindowsRef, i);
WebView *webView = [[[window contentView] subviews] objectAtIndex:0];
dumpBackForwardListForWebView(webView);
}
if ([WebHistory optionalSharedHistory])
[WebHistory setOptionalSharedHistory:nil];
lastMousePosition = NSMakePoint(0, 0);
- [disallowedURLs removeAllObjects];
-
+ if (disallowedURLs)
+ CFSetRemoveAllValues(disallowedURLs);
+
if (currentTest != nil)
CFRelease(currentTest);
currentTest = (NSString *)pathOrURLString;
BCA51F970C960CFC0076A81A /* LayoutTestControllerMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = BCA51F960C960CFC0076A81A /* LayoutTestControllerMac.mm */; };
BCA876B70C921FA100946E9C /* ObjCController.h in Headers */ = {isa = PBXBuildFile; fileRef = BCA876B50C921FA100946E9C /* ObjCController.h */; };
BCA876B80C921FA100946E9C /* ObjCController.m in Sources */ = {isa = PBXBuildFile; fileRef = BCA876B60C921FA100946E9C /* ObjCController.m */; };
+ BCF6C6500C98E9C000AC063E /* GCController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BCF6C64F0C98E9C000AC063E /* GCController.cpp */; };
D23AE9660C56BB2100C47236 /* PolicyDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = D23AE8EA0C56B2FF00C47236 /* PolicyDelegate.m */; };
D23AE9690C56BB2900C47236 /* PolicyDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = D23AE8E00C56B29E00C47236 /* PolicyDelegate.h */; };
E1330800099624DA00AC0A91 /* AppleScriptController.h in Headers */ = {isa = PBXBuildFile; fileRef = E13307FE099624DA00AC0A91 /* AppleScriptController.h */; };
9340995408540CAF007F3BC8 /* DumpRenderTree */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = DumpRenderTree; sourceTree = BUILT_PRODUCTS_DIR; };
93442CF408F8BA4900BFE8CA /* TextInputController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextInputController.h; sourceTree = "<group>"; };
93442CF508F8BA4900BFE8CA /* TextInputController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TextInputController.m; sourceTree = "<group>"; };
- 9345229C0BD12B710086EDA0 /* AHEM____.TTF */ = {isa = PBXFileReference; explicitFileType = file; name = "AHEM____.TTF"; path = "DumpRenderTree.qtproj/fonts/AHEM____.TTF"; sourceTree = "<group>"; };
+ 9345229C0BD12B710086EDA0 /* AHEM____.TTF */ = {isa = PBXFileReference; explicitFileType = file; name = AHEM____.TTF; path = DumpRenderTree.qtproj/fonts/AHEM____.TTF; sourceTree = "<group>"; };
A803FCB709CAAAB0009B2A37 /* EventSendingController.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = EventSendingController.h; sourceTree = "<group>"; };
A803FCB809CAAAB1009B2A37 /* EventSendingController.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = EventSendingController.m; sourceTree = "<group>"; };
A803FF7409CAAD08009B2A37 /* DumpRenderTree.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DumpRenderTree.h; sourceTree = "<group>"; };
BCA51F960C960CFC0076A81A /* LayoutTestControllerMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = LayoutTestControllerMac.mm; sourceTree = "<group>"; };
BCA876B50C921FA100946E9C /* ObjCController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ObjCController.h; sourceTree = "<group>"; };
BCA876B60C921FA100946E9C /* ObjCController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ObjCController.m; sourceTree = "<group>"; };
+ BCF6C64F0C98E9C000AC063E /* GCController.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = GCController.cpp; sourceTree = "<group>"; };
D23AE8E00C56B29E00C47236 /* PolicyDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PolicyDelegate.h; sourceTree = "<group>"; };
D23AE8EA0C56B2FF00C47236 /* PolicyDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PolicyDelegate.m; sourceTree = "<group>"; };
E13307FE099624DA00AC0A91 /* AppleScriptController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppleScriptController.h; sourceTree = "<group>"; };
E13307FF099624DA00AC0A91 /* AppleScriptController.m */,
A803FCB709CAAAB0009B2A37 /* EventSendingController.h */,
A803FCB809CAAAB1009B2A37 /* EventSendingController.m */,
+ BCF6C64F0C98E9C000AC063E /* GCController.cpp */,
14770FE00A22ADF7009342EE /* GCController.h */,
14770FE10A22ADF7009342EE /* GCController.mm */,
+ BC0131D80C9772010087317D /* LayoutTestController.cpp */,
+ BC0131D90C9772010087317D /* LayoutTestController.h */,
+ BCA51F960C960CFC0076A81A /* LayoutTestControllerMac.mm */,
14A6FB880971CAE5008B014F /* NavigationController.h */,
14A6FB890971CAE5008B014F /* NavigationController.m */,
- 93442CF408F8BA4900BFE8CA /* TextInputController.h */,
- 93442CF508F8BA4900BFE8CA /* TextInputController.m */,
BCA876B50C921FA100946E9C /* ObjCController.h */,
BCA876B60C921FA100946E9C /* ObjCController.m */,
- BC0131D80C9772010087317D /* LayoutTestController.cpp */,
- BC0131D90C9772010087317D /* LayoutTestController.h */,
- BCA51F960C960CFC0076A81A /* LayoutTestControllerMac.mm */,
+ 93442CF408F8BA4900BFE8CA /* TextInputController.h */,
+ 93442CF508F8BA4900BFE8CA /* TextInputController.m */,
);
name = Controllers;
sourceTree = "<group>";
08FB7793FE84155DC02AAC07 /* Project object */ = {
isa = PBXProject;
buildConfigurationList = 149C29C308902C6D008A9EFC /* Build configuration list for PBXProject "DumpRenderTree" */;
- compatibilityVersion = "Xcode 2.4";
hasScannedForEncodings = 1;
mainGroup = 08FB7794FE84155DC02AAC07 /* DumpRenderTree */;
productRefGroup = 9340995508540CAF007F3BC8 /* Products */;
BC9D90240C97472E0099A4A3 /* WorkQueue.cpp in Sources */,
BC0131DA0C9772010087317D /* LayoutTestController.cpp in Sources */,
BC0131EF0C9774700087317D /* WorkQueueItemMac.mm in Sources */,
+ BCF6C6500C98E9C000AC063E /* GCController.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
"-sectcreate",
__DATA,
Ahem,
- "DumpRenderTree.qtproj/fonts/AHEM____.TTF",
+ DumpRenderTree.qtproj/fonts/AHEM____.TTF,
);
PRODUCT_NAME = DumpRenderTree;
VALID_ARCHS = "ppc7400 ppc970 i386 ppc";
"-sectcreate",
__DATA,
Ahem,
- "DumpRenderTree.qtproj/fonts/AHEM____.TTF",
+ DumpRenderTree.qtproj/fonts/AHEM____.TTF,
);
PRODUCT_NAME = DumpRenderTree;
VALID_ARCHS = "ppc7400 ppc970 i386 ppc";
#import <WebKit/WebKit.h>
-extern BOOL shouldDumpEditingCallbacks;
+extern bool shouldDumpEditingCallbacks;
@interface DOMNode (dumpPath)
- (NSString *)dumpPath;
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#import <Cocoa/Cocoa.h>
+#import <Foundation/Foundation.h>
-class LayoutTestController;
+class LayoutTestController;
+class GCController;
@interface FrameLoadDelegate : NSObject
{
LayoutTestController* layoutTestContoller;
+ GCController* gcController;
}
@end
- (id)init
{
- if ((self = [super init]))
+ if ((self = [super init])) {
layoutTestContoller = new LayoutTestController;
+ gcController = new GCController;
+ }
return self;
}
- (void)dealloc
{
delete layoutTestContoller;
+ delete gcController;
[super dealloc];
}
JSContextRef context = [frame globalContext];
JSObjectRef globalObject = JSContextGetGlobalObject(context);
JSValueRef exception = 0;
+
layoutTestContoller->makeWindowObject(context, globalObject, &exception);
ASSERT(!exception);
+ gcController->makeWindowObject(context, globalObject, &exception);
+ ASSERT(!exception);
+
// Make Old-Style controllers
EventSendingController *esc = [[EventSendingController alloc] init];
[obj setValue:esc forKey:@"eventSender"];
AppleScriptController *asc = [[AppleScriptController alloc] initWithWebView:sender];
[obj setValue:asc forKey:@"appleScriptController"];
[asc release];
-
- GCController *gcc = [[GCController alloc] init];
- [obj setValue:gcc forKey:@"GCController"];
- [gcc release];
ObjCController *occ = [[ObjCController alloc] init];
[obj setValue:occ forKey:@"objCController"];
--- /dev/null
+/*
+ * Copyright (C) 2007 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "GCController.h"
+
+#include <JavaScriptCore/JSObjectRef.h>
+#include <JavaScriptCore/JSRetainPtr.h>
+
+GCController::GCController()
+{
+}
+
+GCController::~GCController()
+{
+}
+
+#pragma mark -
+#pragma mark Static Functions
+
+static JSValueRef collectCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+ GCController* controller = reinterpret_cast<GCController*>(JSObjectGetPrivate(thisObject));
+ controller->collect();
+ return JSValueMakeUndefined(context);
+}
+
+static JSValueRef collectOnAlternateThreadCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+ bool waitUntilDone = false;
+ if (argumentCount > 0)
+ waitUntilDone = JSValueToBoolean(context, arguments[0]);
+
+ GCController* controller = reinterpret_cast<GCController*>(JSObjectGetPrivate(thisObject));
+ controller->collectOnAlternateThread(waitUntilDone);
+
+ return JSValueMakeUndefined(context);
+}
+
+static JSValueRef getJSObjectCountCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+ GCController* controller = reinterpret_cast<GCController*>(JSObjectGetPrivate(thisObject));
+ size_t jsObjectCount = controller->getJSObjectCount();
+
+ return JSValueMakeNumber(context, jsObjectCount);
+}
+
+#pragma mark -
+#pragma mark Object Creation
+
+void GCController::makeWindowObject(JSContextRef context, JSObjectRef windowObject, JSValueRef* exception)
+{
+ JSRetainPtr<JSStringRef> gcControllerStr(Adopt, JSStringCreateWithUTF8CString("GCController"));
+ JSValueRef gcControllerObject = JSObjectMake(context, getJSClass(), this);
+ JSObjectSetProperty(context, windowObject, gcControllerStr.get(), gcControllerObject, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, exception);
+}
+
+JSClassRef GCController::getJSClass()
+{
+ static JSClassRef gcControllerClass = 0;
+
+ if (!gcControllerClass) {
+ JSStaticFunction* staticFunctions = GCController::staticFunctions();
+ JSClassDefinition classDefinition = {
+ 0, kJSClassAttributeNone, "GCController", 0, 0, staticFunctions,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+ };
+
+ gcControllerClass = JSClassCreate(&classDefinition);
+ }
+
+ return gcControllerClass;
+}
+
+JSStaticFunction* GCController::staticFunctions()
+{
+ static JSStaticFunction staticFunctions[] = {
+ { "collect", collectCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
+ { "collectOnAlternateThread", collectOnAlternateThreadCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
+ { "getJSObjectCount", getJSObjectCountCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
+ { 0, 0, 0 }
+ };
+
+ return staticFunctions;
+}
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#import <WebKit/WebView.h>
+#ifndef GCController_h
+#define GCController_h
-@interface GCController : NSObject {
-}
-+ (BOOL)isSelectorExcludedFromWebScript:(SEL)aSelector;
-+ (NSString *)webScriptNameForSelector:(SEL)aSelector;
-- (void)collect;
-- (void)collectOnAlternateThread:(BOOL)waitUntilDone;
-- (size_t)getJSObjectCount;
-@end
+#include <JavaScriptCore/JSObjectRef.h>
+
+class GCController {
+public:
+ GCController();
+ ~GCController();
+
+ void makeWindowObject(JSContextRef context, JSObjectRef windowObject, JSValueRef* exception);
+
+ // Controller Methods - platfrom independant implementations
+ void collect() const;
+ void collectOnAlternateThread(bool waitUntilDone) const;
+ size_t getJSObjectCount() const;
+
+private:
+ static JSClassRef getJSClass();
+ static JSStaticFunction* staticFunctions();
+};
+
+#endif // GCController_h
#import "GCController.h"
#import <WebKit/WebCoreStatistics.h>
-@implementation GCController
-+ (BOOL)isSelectorExcludedFromWebScript:(SEL)aSelector
-{
- if (aSelector == @selector(collect))
- return NO;
- if (aSelector == @selector(collectOnAlternateThread:))
- return NO;
- if (aSelector == @selector(getJSObjectCount))
- return NO;
-
- return YES;
-}
-
-+ (NSString *)webScriptNameForSelector:(SEL)aSelector
-{
- if (aSelector == @selector(collectOnAlternateThread:))
- return @"collectOnAlternateThread";
-
- return nil;
-}
-- (void)collect
+void GCController::collect() const
{
[WebCoreStatistics garbageCollectJavaScriptObjects];
}
-- (void)collectOnAlternateThread:(BOOL)waitUntilDone
+void GCController::collectOnAlternateThread(bool waitUntilDone) const
{
[WebCoreStatistics garbageCollectJavaScriptObjectsOnAlternateThread:waitUntilDone];
}
-- (size_t)getJSObjectCount
+size_t GCController::getJSObjectCount() const
{
return [WebCoreStatistics javaScriptObjectsCount];
}
-@end
void LayoutTestController::makeWindowObject(JSContextRef context, JSObjectRef windowObject, JSValueRef* exception)
{
JSRetainPtr<JSStringRef> layoutTestContollerStr(Adopt, JSStringCreateWithUTF8CString("layoutTestController"));
- JSValueRef layoutTestContollerObject = JSObjectMake(context, getLayoutTestControllerJSClass(), this);
- JSObjectSetProperty(context, windowObject, layoutTestContollerStr.get(), layoutTestContollerObject, kJSPropertyAttributeNone, exception);
+ JSValueRef layoutTestContollerObject = JSObjectMake(context, getJSClass(), this);
+ JSObjectSetProperty(context, windowObject, layoutTestContollerStr.get(), layoutTestContollerObject, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, exception);
}
-JSClassRef LayoutTestController::getLayoutTestControllerJSClass()
+JSClassRef LayoutTestController::getJSClass()
{
static JSClassRef layoutTestControllerClass = 0;
private:
- static JSClassRef getLayoutTestControllerJSClass();
+ static JSClassRef getJSClass();
static JSStaticFunction* staticFunctions();
};
RetainPtr<CFStringRef> urlCF(AdoptCF, JSStringCopyCFString(kCFAllocatorDefault, url));
if (!disallowedURLs)
- disallowedURLs = [[NSMutableSet alloc] init];
+ disallowedURLs = CFSetCreateMutable(kCFAllocatorDefault, 0, NULL);
// Canonicalize the URL
NSURLRequest* request = [NSURLRequest requestWithURL:[NSURL URLWithString:(NSString *)urlCF.get()]];
request = [NSURLProtocol canonicalRequestForRequest:request];
- [disallowedURLs addObject:[request URL]];
+ CFSetAddValue(disallowedURLs, [request URL]);
}
void LayoutTestController::clearBackForwardList()
[(WebHTMLView *)documentView _updateActiveState];
}
-@interface WaitToDumpWatchdog : NSObject
-+ (void)waitUntilDoneWatchdogFired;
-@end
-
-@implementation WaitToDumpWatchdog
-+ (void)waitUntilDoneWatchdogFired
+static void waitUntilDoneWatchdogFired(CFRunLoopTimerRef timer, void* info)
{
const char* message = "FAIL: Timed out waiting for notifyDone to be called\n";
fprintf(stderr, message);
fprintf(stdout, message);
dump();
}
-@end
void LayoutTestController::waitUntilDone()
{
waitToDump = true;
if (!waitToDumpWatchdog)
- waitToDumpWatchdog = [[NSTimer scheduledTimerWithTimeInterval:waitToDumpWatchdogInterval target:[WaitToDumpWatchdog class] selector:@selector(waitUntilDoneWatchdogFired) userInfo:nil repeats:NO] retain];
+ waitToDumpWatchdog = CFRunLoopTimerCreate(kCFAllocatorDefault, 0, waitToDumpWatchdogInterval, 0, 0, waitUntilDoneWatchdogFired, NULL);
}
int LayoutTestController::windowCount()
printf ("%s\n", [string UTF8String]);
}
- if ([disallowedURLs containsObject:[newRequest URL]])
+ if (disallowedURLs && CFSetContainsValue(disallowedURLs, [newRequest URL]))
return nil;
return newRequest;