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 <Foundation/Foundation.h> 30 31 #if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_4 32 #define WebNSUInteger unsigned int 33 #else 34 #define WebNSUInteger NSUInteger 35 #endif 36 37 #if defined(BUILDING_ON_TIGER) || defined(BUILDING_ON_LEOPARD) 38 typedef int WebSourceId; 39 #else 40 typedef intptr_t WebSourceId; 41 #endif 42 43 @class WebView; 44 @class WebFrame; 45 @class WebScriptCallFrame; 46 @class WebScriptCallFramePrivate; 47 @class WebScriptObject; 48 49 extern NSString * const WebScriptErrorDomain; 50 extern NSString * const WebScriptErrorDescriptionKey; 51 extern NSString * const WebScriptErrorLineNumberKey; 52 53 enum { 54 WebScriptGeneralErrorCode = -100 55 }; 56 57 // WebScriptDebugDelegate messages 58 59 @interface NSObject (WebScriptDebugDelegate) 60 61 // some source was parsed, establishing a "source ID" (>= 0) for future reference 62 // this delegate method is deprecated, please switch to the new version below 63 - (void)webView:(WebView *)webView didParseSource:(NSString *)source 64 fromURL:(NSString *)url 65 sourceId:(WebSourceId)sid 66 forWebFrame:(WebFrame *)webFrame; 67 68 // some source was parsed, establishing a "source ID" (>= 0) for future reference 69 - (void)webView:(WebView *)webView didParseSource:(NSString *)source 70 baseLineNumber:(WebNSUInteger)lineNumber 71 fromURL:(NSURL *)url 72 sourceId:(WebSourceId)sid 73 forWebFrame:(WebFrame *)webFrame; 74 75 // some source failed to parse 76 - (void)webView:(WebView *)webView failedToParseSource:(NSString *)source 77 baseLineNumber:(WebNSUInteger)lineNumber 78 fromURL:(NSURL *)url 79 withError:(NSError *)error 80 forWebFrame:(WebFrame *)webFrame; 81 82 // just entered a stack frame (i.e. called a function, or started global scope) 83 - (void)webView:(WebView *)webView didEnterCallFrame:(WebScriptCallFrame *)frame 84 sourceId:(WebSourceId)sid 85 line:(int)lineno 86 forWebFrame:(WebFrame *)webFrame; 87 88 // about to execute some code 89 - (void)webView:(WebView *)webView willExecuteStatement:(WebScriptCallFrame *)frame 90 sourceId:(WebSourceId)sid 91 line:(int)lineno 92 forWebFrame:(WebFrame *)webFrame; 93 94 // about to leave a stack frame (i.e. return from a function) 95 - (void)webView:(WebView *)webView willLeaveCallFrame:(WebScriptCallFrame *)frame 96 sourceId:(WebSourceId)sid 97 line:(int)lineno 98 forWebFrame:(WebFrame *)webFrame; 99 100 // exception is being thrown 101 - (void)webView:(WebView *)webView exceptionWasRaised:(WebScriptCallFrame *)frame 102 hasHandler:(BOOL)hasHandler 103 sourceId:(WebSourceId)sid 104 line:(int)lineno 105 forWebFrame:(WebFrame *)webFrame; 106 107 // exception is being thrown (deprecated old version; called only if new version is not implemented) 108 - (void)webView:(WebView *)webView exceptionWasRaised:(WebScriptCallFrame *)frame 109 sourceId:(WebSourceId)sid 110 line:(int)lineno 111 forWebFrame:(WebFrame *)webFrame; 112 113 @end 114 115 116 117 // WebScriptCallFrame interface 118 // 119 // These objects are passed as arguments to the debug delegate. 120 121 @interface WebScriptCallFrame : NSObject 122 { 123 @private 124 WebScriptCallFramePrivate* _private; 125 id _userInfo; 126 } 127 128 // associate user info with frame 129 - (void)setUserInfo:(id)userInfo; 130 131 // retrieve user info 132 - (id)userInfo; 133 134 // get next frame on call stack (or nil if this is already the "global" frame) 135 - (WebScriptCallFrame *)caller; 136 137 // get array of WebScriptObjects for each scope (innermost first, last is always global object) 138 - (NSArray *)scopeChain; 139 140 // get name of function (if available) or nil 141 - (NSString *)functionName; 142 143 // get pending exception (if any) or nil 144 - (id)exception; 145 146 // evaluate a script (as if by "eval") in the context of this frame 147 - (id)evaluateWebScript:(NSString *)script; 148 149 @end 150 151 #undef WebNSUInteger 152 153