Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Object does not allow calls



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
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webkitsdk-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webkitsdk-dev/email@hidden

This email sent to email@hidden
References: 
 >Object does not allow calls (From: Michael Hanna <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.