yeah, alert(logMessage); returns me the object <LDataTypeManager:
0x34fff0>
OK, so taking what you have to say literally, I could very well do in:
- (void)webView:(WebView *)sender windowScriptObjectAvailable:
(WebScriptObject *)wso
...
[wso setValue:self forKey:@"logMessage"];
...
however this seems to produce the runtime exception:
*** Exception handlers were not properly removed. Some code has
jumped or returned out of an NS_DURING...NS_HANDLER region without
using the NS_VOIDRETURN or NS_VALUERETURN macros. Clearly I'm doing
something wrong here..
I'm not sure if I totally understand the role of
invokeUndefinedMethodFromWebScript:withArguments:
It doesn't seem to get called at all whether or not [wso
setValue:self forKey:@"logMessage"]; is present(I had it just print
an NSLog() message). Is it meant to be used as such:
- (id)invokeUndefinedMethodFromWebScript:(NSString *)name
withArguments:(NSArray *)args
{
if([name isEqualToString:@"logMessage"])
return [self doTheActualLogMessage:args];
return nil;
}
Michael
--
Michael Hanna
email@hidden
iChat: michaelkhanna(AIM)
On 8-Dec-05, at 11:20 AM, Geoffrey Garen wrote:
Hi Michael. My comments are enclosed below.
I've been getting the error:
2005-12-07 16:19:18.587 DataTypeRoot01[4369] /SourceCache/
JavaScriptCore/JavaScriptCore-416.13/bindings/objc/
WebScriptObject.mm:211:[4369] JavaScript exception: Object
(result of expression logMessage) does not allow calls.
I'm not sure what this means..why would it expect an object that
does allow calls?
Because your code calls logMessage as a function, JavaScript
expects the logMessage 'object' to allow '[function] calls'. It
looks like logMessage is undefined, though. You can confirm this
by calling 'alert(logMessage)' and seeing if you get a function or
undefined.
Anyway,
on the call:
var lang = logMessage(strLang);
In the calling class(which contains these delegates:
- (void)webView:(WebView *)sender windowScriptObjectAvailable:
(WebScriptObject *)wso
+(NSString*)webScriptNameForSelector:(SEL)aSel
+(BOOL)isSelectorExcludedFromWebScript:(SEL)aSel
and
+(BOOL)isKeyExcludedFromWebScript:(const char*)k
in webScriptNameForSelector:
if (aSel == @selector(logMessage:)) {
retval = @"logMessage";
}
in isSelectorExcludedFromWebScript:
if ( aSel == @selector(logMessage:)) {
return NO;
}
Can I access a selector without a namespace(such as this case)?
webScriptNameForSelector and isSelectorExcludedFromWebScript are
appropriate methods to implement if your object exposes member
functions to JavaScript. What you've done would enable calling
plugin.logMessage() if your object were defined in the page as
'plugin'.
In this case, your object doesn't expose member functions. Rather,
you want to expose an object that itself can be called as a
function. That requires constructing an object that implements
invokeDefaultMethodWithArguments:. You can read about that in the
WebKit Objective-C docs @ <http://developer.apple.com/
documentation/Cocoa/Reference/WebKit/ObjC_classic/Protocols/
WebScripting.html>
I will say that the note there is a little tricky. It says
"Invoked when a script attempts to invoke a method on an exposed
object directly." I would say instead, "Invoked when a script
attempts to call an exposed object as a function."
Remember, to expose an object that isn't defined in the page as a
plugin, you need to call setValue:forKey: on the
windowScriptObject, passing in a valid object as the value and
@"logMessage" as the key.
You can find a good example of setValue:forKey: in the Dashboard
docs @ <http://developer.apple.com/documentation/AppleApplications/
Reference/Dashboard_Ref/Plugin/chapter_5_section_1.html>.
Cheers.
Geoff