|
1 /* |
|
2 * Copyright (C) 2005 Apple Computer, Inc. All rights reserved. |
|
3 * |
|
4 * Redistribution and use in source and binary forms, with or without |
|
5 * modification, are permitted provided that the following conditions |
|
6 * are met: |
|
7 * |
|
8 * 1. Redistributions of source code must retain the above copyright |
|
9 * notice, this list of conditions and the following disclaimer. |
|
10 * 2. Redistributions in binary form must reproduce the above copyright |
|
11 * notice, this list of conditions and the following disclaimer in the |
|
12 * documentation and/or other materials provided with the distribution. |
|
13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of |
|
14 * its contributors may be used to endorse or promote products derived |
|
15 * from this software without specific prior written permission. |
|
16 * |
|
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY |
|
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
|
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
|
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
|
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
|
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
|
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
|
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
27 */ |
|
28 |
|
29 #import "WebScriptDebugDelegatePrivate.h" |
|
30 |
|
31 #import "WebDataSource.h" |
|
32 #import "WebDataSourceInternal.h" |
|
33 #import "WebFrameBridge.h" |
|
34 #import "WebFrameInternal.h" |
|
35 #import "WebScriptDebugServerPrivate.h" |
|
36 #import "WebViewInternal.h" |
|
37 #import <WebCore/Frame.h> |
|
38 #import <WebCore/WebCoreScriptDebugger.h> |
|
39 |
|
40 using namespace WebCore; |
|
41 |
|
42 // FIXME: these error strings should be public for future use by WebScriptObject and in WebScriptObject.h |
|
43 NSString * const WebScriptErrorDomain = @"WebScriptErrorDomain"; |
|
44 NSString * const WebScriptErrorDescriptionKey = @"WebScriptErrorDescription"; |
|
45 NSString * const WebScriptErrorLineNumberKey = @"WebScriptErrorLineNumber"; |
|
46 |
|
47 @interface WebScriptCallFrame (WebScriptDebugDelegateInternal) |
|
48 |
|
49 - (WebScriptCallFrame *)_initWithFrame:(WebCoreScriptCallFrame *)frame; |
|
50 |
|
51 @end |
|
52 |
|
53 @implementation WebScriptDebugger |
|
54 |
|
55 - (WebScriptDebugger *)initWithWebFrame:(WebFrame *)webFrame |
|
56 { |
|
57 if ((self = [super init])) { |
|
58 _webFrame = webFrame; |
|
59 _debugger = [[WebCoreScriptDebugger alloc] initWithDelegate:self]; |
|
60 } |
|
61 return self; |
|
62 } |
|
63 |
|
64 - (void)dealloc |
|
65 { |
|
66 [_debugger release]; |
|
67 [super dealloc]; |
|
68 } |
|
69 |
|
70 - (WebScriptObject *)globalObject |
|
71 { |
|
72 return core(_webFrame)->windowScriptObject(); |
|
73 } |
|
74 |
|
75 - (id)newWrapperForFrame:(WebCoreScriptCallFrame *)frame |
|
76 { |
|
77 return [[WebScriptCallFrame alloc] _initWithFrame:frame]; |
|
78 } |
|
79 |
|
80 - (void)parsedSource:(NSString *)source fromURL:(NSURL *)url sourceId:(int)sid startLine:(int)startLine errorLine:(int)errorLine errorMessage:(NSString *)errorMessage |
|
81 { |
|
82 WebView *webView = [_webFrame webView]; |
|
83 if (errorLine == -1) { |
|
84 [[webView _scriptDebugDelegateForwarder] webView:webView didParseSource:source baseLineNumber:startLine fromURL:url sourceId:sid forWebFrame:_webFrame]; |
|
85 [[webView _scriptDebugDelegateForwarder] webView:webView didParseSource:source fromURL:[url absoluteString] sourceId:sid forWebFrame:_webFrame]; // deprecated delegate method |
|
86 if ([WebScriptDebugServer listenerCount]) |
|
87 [[WebScriptDebugServer sharedScriptDebugServer] webView:webView didParseSource:source baseLineNumber:startLine fromURL:url sourceId:sid forWebFrame:_webFrame]; |
|
88 } else { |
|
89 NSDictionary *info = [[NSDictionary alloc] initWithObjectsAndKeys:errorMessage, WebScriptErrorDescriptionKey, [NSNumber numberWithUnsignedInt:errorLine], WebScriptErrorLineNumberKey, nil]; |
|
90 NSError *error = [[NSError alloc] initWithDomain:WebScriptErrorDomain code:WebScriptGeneralErrorCode userInfo:info]; |
|
91 [[webView _scriptDebugDelegateForwarder] webView:webView failedToParseSource:source baseLineNumber:startLine fromURL:url withError:error forWebFrame:_webFrame]; |
|
92 if ([WebScriptDebugServer listenerCount]) |
|
93 [[WebScriptDebugServer sharedScriptDebugServer] webView:webView failedToParseSource:source baseLineNumber:startLine fromURL:url withError:error forWebFrame:_webFrame]; |
|
94 [error release]; |
|
95 [info release]; |
|
96 } |
|
97 } |
|
98 |
|
99 - (void)enteredFrame:(WebCoreScriptCallFrame *)frame sourceId:(int)sid line:(int)lineno |
|
100 { |
|
101 WebView *webView = [_webFrame webView]; |
|
102 [[webView _scriptDebugDelegateForwarder] webView:webView didEnterCallFrame:[frame wrapper] sourceId:sid line:lineno forWebFrame:_webFrame]; |
|
103 if ([WebScriptDebugServer listenerCount]) |
|
104 [[WebScriptDebugServer sharedScriptDebugServer] webView:webView didEnterCallFrame:[frame wrapper] sourceId:sid line:lineno forWebFrame:_webFrame]; |
|
105 } |
|
106 |
|
107 - (void)hitStatement:(WebCoreScriptCallFrame *)frame sourceId:(int)sid line:(int)lineno |
|
108 { |
|
109 WebView *webView = [_webFrame webView]; |
|
110 [[webView _scriptDebugDelegateForwarder] webView:webView willExecuteStatement:[frame wrapper] sourceId:sid line:lineno forWebFrame:_webFrame]; |
|
111 if ([WebScriptDebugServer listenerCount]) |
|
112 [[WebScriptDebugServer sharedScriptDebugServer] webView:webView willExecuteStatement:[frame wrapper] sourceId:sid line:lineno forWebFrame:_webFrame]; |
|
113 } |
|
114 |
|
115 - (void)leavingFrame:(WebCoreScriptCallFrame *)frame sourceId:(int)sid line:(int)lineno |
|
116 { |
|
117 WebView *webView = [_webFrame webView]; |
|
118 [[webView _scriptDebugDelegateForwarder] webView:webView willLeaveCallFrame:[frame wrapper] sourceId:sid line:lineno forWebFrame:_webFrame]; |
|
119 if ([WebScriptDebugServer listenerCount]) |
|
120 [[WebScriptDebugServer sharedScriptDebugServer] webView:webView willLeaveCallFrame:[frame wrapper] sourceId:sid line:lineno forWebFrame:_webFrame]; |
|
121 } |
|
122 |
|
123 - (void)exceptionRaised:(WebCoreScriptCallFrame *)frame sourceId:(int)sid line:(int)lineno |
|
124 { |
|
125 WebView *webView = [_webFrame webView]; |
|
126 [[webView _scriptDebugDelegateForwarder] webView:webView exceptionWasRaised:[frame wrapper] sourceId:sid line:lineno forWebFrame:_webFrame]; |
|
127 if ([WebScriptDebugServer listenerCount]) |
|
128 [[WebScriptDebugServer sharedScriptDebugServer] webView:webView exceptionWasRaised:[frame wrapper] sourceId:sid line:lineno forWebFrame:_webFrame]; |
|
129 } |
|
130 |
|
131 @end |
|
132 |
|
133 |
|
134 |
|
135 @implementation WebScriptCallFrame (WebScriptDebugDelegateInternal) |
|
136 |
|
137 - (WebScriptCallFrame *)_initWithFrame:(WebCoreScriptCallFrame *)frame |
|
138 { |
|
139 if ((self = [super init])) { |
|
140 _private = frame; |
|
141 } |
|
142 return self; |
|
143 } |
|
144 |
|
145 @end |
|
146 |
|
147 |
|
148 |
|
149 @implementation WebScriptCallFrame |
|
150 |
|
151 - (void) dealloc |
|
152 { |
|
153 [_userInfo release]; |
|
154 [super dealloc]; |
|
155 } |
|
156 |
|
157 - (void)setUserInfo:(id)userInfo |
|
158 { |
|
159 if (userInfo != _userInfo) { |
|
160 [_userInfo release]; |
|
161 _userInfo = [userInfo retain]; |
|
162 } |
|
163 } |
|
164 |
|
165 - (id)userInfo |
|
166 { |
|
167 return _userInfo; |
|
168 } |
|
169 |
|
170 - (WebScriptCallFrame *)caller |
|
171 { |
|
172 return [[_private caller] wrapper]; |
|
173 } |
|
174 |
|
175 - (NSArray *)scopeChain |
|
176 { |
|
177 return [_private scopeChain]; |
|
178 } |
|
179 |
|
180 - (NSString *)functionName |
|
181 { |
|
182 return [_private functionName]; |
|
183 } |
|
184 |
|
185 - (id)exception |
|
186 { |
|
187 return [_private exception]; |
|
188 } |
|
189 |
|
190 - (id)evaluateWebScript:(NSString *)script |
|
191 { |
|
192 return [_private evaluateWebScript:script]; |
|
193 } |
|
194 |
|
195 @end |