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 int WebSourceId; // FIXME <rdar://problem/6263293>: Turn this int into an intptr_t once <rdar://problem/6263297> is fixed. 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 sourceId:(WebSourceId)sid 103 line:(int)lineno 104 forWebFrame:(WebFrame *)webFrame; 105 @end 106 107 108 109 // WebScriptCallFrame interface 110 // 111 // These objects are passed as arguments to the debug delegate. 112 113 @interface WebScriptCallFrame : NSObject 114 { 115 @private 116 WebScriptCallFramePrivate* _private; 117 id _userInfo; 118 } 119 120 // associate user info with frame 121 - (void)setUserInfo:(id)userInfo; 122 123 // retrieve user info 124 - (id)userInfo; 125 126 // get next frame on call stack (or nil if this is already the "global" frame) 127 - (WebScriptCallFrame *)caller; 128 129 // get array of WebScriptObjects for each scope (innermost first, last is always global object) 130 - (NSArray *)scopeChain; 131 132 // get name of function (if available) or nil 133 - (NSString *)functionName; 134 135 // get pending exception (if any) or nil 136 - (id)exception; 137 138 // evaluate a script (as if by "eval") in the context of this frame 139 - (id)evaluateWebScript:(NSString *)script; 140 141 @end 142 143 #undef WebNSUInteger 144 145