Commit e89032a9 authored by kmccullo's avatar kmccullo

Reviewed by Adam.

        - Implemented cross-platform code for functions calling into the JavaScript.

        * Drosera/DebuggerDocument.cpp:
        (DebuggerDocument::callAsFunction):
        (DebuggerDocument::pauseJS):
        (DebuggerDocument::resumeJS):
        (DebuggerDocument::stepIntoJS):
        (DebuggerDocument::stepOverJS):
        (DebuggerDocument::stepOutJS):
        (DebuggerDocument::showConsoleJS):
        (DebuggerDocument::closeCurrentFileJS):
        (DebuggerDocument::updateFileSource):
        (DebuggerDocument::didParseScript):
        (DebuggerDocument::willExecuteStatement):
        (DebuggerDocument::didEnterCallFrame):
        (DebuggerDocument::willLeaveCallFrame):
        (DebuggerDocument::exceptionWasRaised):
        * Drosera/DebuggerDocument.h:
        * Drosera/mac/DebuggerDocumentMac.mm:
        (-[DebuggerDocumentMac pause:]):
        (-[DebuggerDocumentMac resume:]):
        (-[DebuggerDocumentMac stepInto:]):
        (-[DebuggerDocumentMac stepOver:]):
        (-[DebuggerDocumentMac stepOut:]):
        (-[DebuggerDocumentMac showConsole:]):
        (-[DebuggerDocumentMac closeCurrentFile:]):
        (-[DebuggerDocumentMac webView:didLoadMainResourceForDataSource:]):
        (-[DebuggerDocumentMac webView:didParseSource:baseLineNumber:fromURL:sourceId:forWebFrame:]):
        (-[DebuggerDocumentMac webView:didEnterCallFrame:sourceId:line:forWebFrame:]):
        (-[DebuggerDocumentMac webView:willExecuteStatement:sourceId:line:forWebFrame:]):
        (-[DebuggerDocumentMac webView:willLeaveCallFrame:sourceId:line:forWebFrame:]):
        (-[DebuggerDocumentMac webView:exceptionWasRaised:sourceId:line:forWebFrame:]):



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@24374 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent be8ba793
2007-07-17 Kevin McCullough <kmccullough@apple.com>
Reviewed by Adam.
- Implemented cross-platform code for functions calling into the JavaScript.
* Drosera/DebuggerDocument.cpp:
(DebuggerDocument::callAsFunction):
(DebuggerDocument::pauseJS):
(DebuggerDocument::resumeJS):
(DebuggerDocument::stepIntoJS):
(DebuggerDocument::stepOverJS):
(DebuggerDocument::stepOutJS):
(DebuggerDocument::showConsoleJS):
(DebuggerDocument::closeCurrentFileJS):
(DebuggerDocument::updateFileSource):
(DebuggerDocument::didParseScript):
(DebuggerDocument::willExecuteStatement):
(DebuggerDocument::didEnterCallFrame):
(DebuggerDocument::willLeaveCallFrame):
(DebuggerDocument::exceptionWasRaised):
* Drosera/DebuggerDocument.h:
* Drosera/mac/DebuggerDocumentMac.mm:
(-[DebuggerDocumentMac pause:]):
(-[DebuggerDocumentMac resume:]):
(-[DebuggerDocumentMac stepInto:]):
(-[DebuggerDocumentMac stepOver:]):
(-[DebuggerDocumentMac stepOut:]):
(-[DebuggerDocumentMac showConsole:]):
(-[DebuggerDocumentMac closeCurrentFile:]):
(-[DebuggerDocumentMac webView:didLoadMainResourceForDataSource:]):
(-[DebuggerDocumentMac webView:didParseSource:baseLineNumber:fromURL:sourceId:forWebFrame:]):
(-[DebuggerDocumentMac webView:didEnterCallFrame:sourceId:line:forWebFrame:]):
(-[DebuggerDocumentMac webView:willExecuteStatement:sourceId:line:forWebFrame:]):
(-[DebuggerDocumentMac webView:willLeaveCallFrame:sourceId:line:forWebFrame:]):
(-[DebuggerDocumentMac webView:exceptionWasRaised:sourceId:line:forWebFrame:]):
2007-07-16 Kevin McCullough <kmccullough@apple.com>
Reviewed by Darin.
......
......@@ -120,3 +120,103 @@ JSStringRef DebuggerDocument::valueForScopeVariableNamed(CallFrame /*frame*/, JS
{
return key;
}
//-- These are the calls into the JS. --//
void DebuggerDocument::callGlobalFunction(JSContextRef context, const char* functionName, int argumentCount, JSValueRef arguments[])
{
JSObjectRef globalObject = JSContextGetGlobalObject(context);
JSStringRef string = JSStringCreateWithUTF8CString(functionName);
JSObjectRef function = JSValueToObject(context, JSObjectGetProperty(context, globalObject, string, 0), 0);
JSStringRelease(string);
JSObjectCallAsFunction(context, function, 0, argumentCount, arguments, 0);
}
void DebuggerDocument::pause(JSContextRef context)
{
DebuggerDocument::callGlobalFunction(context, "pause", 0, 0);
}
void DebuggerDocument::resume(JSContextRef context)
{
DebuggerDocument::callGlobalFunction(context, "resume", 0, 0);
}
void DebuggerDocument::stepInto(JSContextRef context)
{
DebuggerDocument::callGlobalFunction(context, "stepInto", 0, 0);
}
void DebuggerDocument::stepOver(JSContextRef context)
{
DebuggerDocument::callGlobalFunction(context, "stepOver", 0, 0);
}
void DebuggerDocument::stepOut(JSContextRef context)
{
DebuggerDocument::callGlobalFunction(context, "stepOut", 0, 0);
}
void DebuggerDocument::showConsole(JSContextRef context)
{
DebuggerDocument::callGlobalFunction(context, "showConsole", 0, 0);
}
void DebuggerDocument::closeCurrentFile(JSContextRef context)
{
DebuggerDocument::callGlobalFunction(context, "closeCurrentFile", 0, 0);
}
void DebuggerDocument::updateFileSource(JSContextRef context, JSStringRef documentSource, JSStringRef url)
{
JSValueRef documentSourceValue = JSValueMakeString(context, documentSource);
JSValueRef urlValue = JSValueMakeString(context, url);
JSValueRef forceValue = JSValueMakeBoolean(context, false);
JSValueRef arguments[] = { documentSourceValue, urlValue, forceValue };
int argumentsSize = sizeof(arguments)/sizeof(arguments[0]);
DebuggerDocument::callGlobalFunction(context, "updateFileSource", argumentsSize, arguments);
}
void DebuggerDocument::didParseScript(JSContextRef context, JSStringRef source, JSStringRef documentSource, JSStringRef url, JSValueRef sourceId, JSValueRef baseLine)
{
JSValueRef sourceValue = JSValueMakeString(context, source);
JSValueRef documentSourceValue = JSValueMakeString(context, documentSource);
JSValueRef urlValue = JSValueMakeString(context, url);
JSValueRef arguments[] = { sourceValue, documentSourceValue, urlValue, sourceId, baseLine };
int argumentsSize = sizeof(arguments)/sizeof(arguments[0]);
DebuggerDocument::callGlobalFunction(context, "didParseScript", argumentsSize, arguments);
}
void DebuggerDocument::willExecuteStatement(JSContextRef context, JSValueRef sourceId, JSValueRef lineno)
{
JSValueRef arguments[] = { sourceId, lineno };
int argumentsSize = sizeof(arguments)/sizeof(arguments[0]);
DebuggerDocument::callGlobalFunction(context, "willExecuteStatement", argumentsSize, arguments);
}
void DebuggerDocument::didEnterCallFrame(JSContextRef context, JSValueRef sourceId, JSValueRef lineno)
{
JSValueRef arguments[] = { sourceId, lineno };
int argumentsSize = sizeof(arguments)/sizeof(arguments[0]);
DebuggerDocument::callGlobalFunction(context, "didEnterCallFrame", argumentsSize, arguments);
}
void DebuggerDocument::willLeaveCallFrame(JSContextRef context, JSValueRef sourceId, JSValueRef lineno)
{
JSValueRef arguments[] = { sourceId, lineno };
int argumentsSize = sizeof(arguments)/sizeof(arguments[0]);
DebuggerDocument::callGlobalFunction(context, "willLeaveCallFrame", argumentsSize, arguments);
}
void DebuggerDocument::exceptionWasRaised(JSContextRef context, JSValueRef sourceId, JSValueRef lineno)
{
JSValueRef arguments[] = { sourceId, lineno };
int argumentsSize = sizeof(arguments)/sizeof(arguments[0]);
DebuggerDocument::callGlobalFunction(context, "exceptionWasRaised", argumentsSize, arguments);
}
......@@ -46,6 +46,9 @@ public:
{
}
//-- Not sure of a good naming scheme here. --//
//-- These are the calls out of the JS. --//
bool isPaused();
void pause();
void resume();
......@@ -56,9 +59,28 @@ public:
JSStringRef valueForScopeVariableNamed(CallFrame frame, JSStringRef key);
static JSValueRef breakpointEditorHTML(JSContextRef context);
//-- Not sure of a good naming scheme here. --//
//-- These are the calls into the JS. --//
static void pause(JSContextRef);
static void resume(JSContextRef);
static void stepInto(JSContextRef);
static void stepOver(JSContextRef);
static void stepOut(JSContextRef);
static void showConsole(JSContextRef);
static void closeCurrentFile(JSContextRef);
static void updateFileSource(JSContextRef, JSStringRef documentSource, JSStringRef url);
static void didParseScript(JSContextRef, JSStringRef source, JSStringRef documentSource, JSStringRef url, JSValueRef sourceId, JSValueRef baseLine);
static void willExecuteStatement(JSContextRef, JSValueRef sourceId, JSValueRef lineno);
static void didEnterCallFrame(JSContextRef, JSValueRef sourceId, JSValueRef lineno);
static void willLeaveCallFrame(JSContextRef, JSValueRef sourceId, JSValueRef lineno);
static void exceptionWasRaised(JSContextRef, JSValueRef sourceId, JSValueRef lineno);
private:
static void callGlobalFunction(JSContextRef, const char* functionName, int argumentCount, JSValueRef arguments[]); // Implementation for calls into JS
bool m_paused;
};
#endif //DebuggerDocumentImpl_H
#endif //DebuggerDocument_H
......@@ -228,37 +228,37 @@ static NSString *DebuggerStepOutToolbarItem = @"DebuggerStepOutToolbarItem";
- (IBAction)pause:(id)sender
{
[[webView windowScriptObject] callWebScriptMethod:@"pause" withArguments:nil];
DebuggerDocument::pause([[webView mainFrame] globalContext]);
}
- (IBAction)resume:(id)sender
{
[[webView windowScriptObject] callWebScriptMethod:@"resume" withArguments:nil];
DebuggerDocument::resume([[webView mainFrame] globalContext]);
}
- (IBAction)stepInto:(id)sender
{
[[webView windowScriptObject] callWebScriptMethod:@"stepInto" withArguments:nil];
DebuggerDocument::stepInto([[webView mainFrame] globalContext]);
}
- (IBAction)stepOver:(id)sender
{
[[webView windowScriptObject] callWebScriptMethod:@"stepOver" withArguments:nil];
DebuggerDocument::stepOver([[webView mainFrame] globalContext]);
}
- (IBAction)stepOut:(id)sender
{
[[webView windowScriptObject] callWebScriptMethod:@"stepOut" withArguments:nil];
DebuggerDocument::stepOut([[webView mainFrame] globalContext]);
}
- (IBAction)showConsole:(id)sender
{
[[webView windowScriptObject] callWebScriptMethod:@"showConsoleWindow" withArguments:nil];
DebuggerDocument::showConsole([[webView mainFrame] globalContext]);
}
- (IBAction)closeCurrentFile:(id)sender
{
[[webView windowScriptObject] callWebScriptMethod:@"closeCurrentFile" withArguments:nil];
callbacks->closeCurrentFile([[webView mainFrame] globalContext]);
}
#pragma mark -
......@@ -581,22 +581,23 @@ static NSString *DebuggerStepOutToolbarItem = @"DebuggerStepOutToolbarItem";
#pragma mark Debug Listener Callbacks
- (void)webView:(WebView *)view didLoadMainResourceForDataSource:(WebDataSource *)dataSource
{
NSString *documentSourceCopy = nil;
{
NSString *documentSource = nil;
id <WebDocumentRepresentation> rep = [dataSource representation];
if ([rep canProvideDocumentSource])
documentSourceCopy = [[rep documentSource] copy];
documentSource = [rep documentSource];
if (!documentSourceCopy)
if (!documentSource)
return;
NSString *urlCopy = [[[[dataSource response] URL] absoluteString] copy];
NSArray *args = [[NSArray alloc] initWithObjects:(documentSourceCopy ? documentSourceCopy : @""), (urlCopy ? urlCopy : @""), [NSNumber numberWithBool:NO], nil];
[[webView windowScriptObject] callWebScriptMethod:@"updateFileSource" withArguments:args];
JSStringRef documentSourceJS = JSStringCreateWithCFString((CFStringRef)documentSource); // We already checked for NULL
NSString *url = [[[dataSource response] URL] absoluteString];
JSStringRef urlJS = JSStringCreateWithCFString(url ? (CFStringRef)url : CFSTR(""));
[args release];
[documentSourceCopy release];
[urlCopy release];
DebuggerDocument::updateFileSource([[webView mainFrame] globalContext], documentSourceJS, urlJS);
JSStringRelease(documentSourceJS);
JSStringRelease(urlJS);
}
- (void)webView:(WebView *)view didParseSource:(NSString *)source baseLineNumber:(unsigned)baseLine fromURL:(NSURL *)url sourceId:(int)sid forWebFrame:(WebFrame *)webFrame
......@@ -620,10 +621,19 @@ static NSString *DebuggerStepOutToolbarItem = @"DebuggerStepOutToolbarItem";
urlCopy = [[[[dataSource response] URL] absoluteString] copy];
}
NSArray *args = [[NSArray alloc] initWithObjects:sourceCopy, (documentSourceCopy ? documentSourceCopy : @""), (urlCopy ? urlCopy : @""), [NSNumber numberWithInt:sid], [NSNumber numberWithUnsignedInt:baseLine], nil];
[[webView windowScriptObject] callWebScriptMethod:@"didParseScript" withArguments:args];
JSStringRef sourceCopyJS = JSStringCreateWithCFString((CFStringRef)sourceCopy); // We checked for NULL earlier.
JSStringRef documentSourceCopyJS = JSStringCreateWithCFString(documentSourceCopy ? (CFStringRef)documentSourceCopy : (CFStringRef)@"");
JSStringRef urlCopyJS = JSStringCreateWithCFString(urlCopy ? (CFStringRef)urlCopy : (CFStringRef)@"");
JSContextRef context = [[webView mainFrame] globalContext];
JSValueRef sidJS = JSValueMakeNumber(context, sid); // JSValueRefs are garbage collected
JSValueRef baseLineJS = JSValueMakeNumber(context, baseLine);
DebuggerDocument::didParseScript(context, sourceCopyJS, documentSourceCopyJS, urlCopyJS, sidJS, baseLineJS);
JSStringRelease(sourceCopyJS);
JSStringRelease(documentSourceCopyJS);
JSStringRelease(urlCopyJS);
[args release];
[sourceCopy release];
[documentSourceCopy release];
[urlCopy release];
......@@ -642,10 +652,11 @@ static NSString *DebuggerStepOutToolbarItem = @"DebuggerStepOutToolbarItem";
currentFrame = [frame retain];
[old release];
//webView->mainframe->JSObejctRef->
NSArray *args = [[NSArray alloc] initWithObjects:[NSNumber numberWithInt:sid], [NSNumber numberWithInt:lineno], nil];
[[webView windowScriptObject] callWebScriptMethod:@"didEnterCallFrame" withArguments:args];
[args release];
JSContextRef context = [[webView mainFrame] globalContext];
JSValueRef sidJS = JSValueMakeNumber(context, sid);
JSValueRef linenoJS = JSValueMakeNumber(context, lineno);
DebuggerDocument::didEnterCallFrame(context, sidJS, linenoJS);
}
- (void)webView:(WebView *)view willExecuteStatement:(WebScriptCallFrame *)frame sourceId:(int)sid line:(int)lineno forWebFrame:(WebFrame *)webFrame
......@@ -653,9 +664,11 @@ static NSString *DebuggerStepOutToolbarItem = @"DebuggerStepOutToolbarItem";
if (!webViewLoaded)
return;
NSArray *args = [[NSArray alloc] initWithObjects:[NSNumber numberWithInt:sid], [NSNumber numberWithInt:lineno], nil];
[[webView windowScriptObject] callWebScriptMethod:@"willExecuteStatement" withArguments:args];
[args release];
JSContextRef context = [[webView mainFrame] globalContext];
JSValueRef sidJS = JSValueMakeNumber(context, sid);
JSValueRef linenoJS = JSValueMakeNumber(context, lineno);
DebuggerDocument::willExecuteStatement(context, sidJS, linenoJS);
}
- (void)webView:(WebView *)view willLeaveCallFrame:(WebScriptCallFrame *)frame sourceId:(int)sid line:(int)lineno forWebFrame:(WebFrame *)webFrame
......@@ -663,9 +676,11 @@ static NSString *DebuggerStepOutToolbarItem = @"DebuggerStepOutToolbarItem";
if (!webViewLoaded)
return;
NSArray *args = [[NSArray alloc] initWithObjects:[NSNumber numberWithInt:sid], [NSNumber numberWithInt:lineno], nil];
[[webView windowScriptObject] callWebScriptMethod:@"willLeaveCallFrame" withArguments:args];
[args release];
JSContextRef context = [[webView mainFrame] globalContext];
JSValueRef sidJS = JSValueMakeNumber(context, sid);
JSValueRef linenoJS = JSValueMakeNumber(context, lineno);
DebuggerDocument::willLeaveCallFrame(context, sidJS, linenoJS);
id old = currentFrame;
currentFrame = [[frame caller] retain];
......@@ -677,8 +692,11 @@ static NSString *DebuggerStepOutToolbarItem = @"DebuggerStepOutToolbarItem";
if (!webViewLoaded)
return;
NSArray *args = [[NSArray alloc] initWithObjects:[NSNumber numberWithInt:sid], [NSNumber numberWithInt:lineno], nil];
[[webView windowScriptObject] callWebScriptMethod:@"exceptionWasRaised" withArguments:args];
[args release];
JSContextRef context = [[webView mainFrame] globalContext];
JSValueRef sidJS = JSValueMakeNumber(context, sid);
JSValueRef linenoJS = JSValueMakeNumber(context, lineno);
DebuggerDocument::exceptionWasRaised(context, sidJS, linenoJS);
}
@end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment