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: 'do JavaScript' still broken in Safari 3 beta



jj wrote:

> tell application "Safari"
>      do JavaScript "document.title = 'hello'; return 1" in tab 1 of
> window 1
> end tell
>
> Window title changes as expected; still no return value though, so
> 'do JavaScript' is definitely broken. Feel free to file your own bug
> report on it; this is something that should've been caught by basic
> unit testing well before public beta.

I think this use of "return" is "invalid". "return" must be used inside a
function (?)

You may be on to something. I tried running:

tell application "Safari"
	do JavaScript "42" in document 1
end tell
--> 42

As you can see, it gives a result. Looks like something in the JavaScript interpreter has changed from previous versions, as "return 1" works fine in the version of JS used by Safari 2. Unfortunately, I'm not a JS expert (as you can tell) so I've no idea if this is by design or accident - anyone know?


Seems that 3b now coerces results (if possible).

I don't know about coercing results, but it does seem to have improved the mapping between JS and AS types, e.g. JS numbers now return as AS numbers instead of strings.


Anyway, after all that there is absolutely definitely a bug in 'do JavaScript', although it's not the one I initially thought. The bug is that 'do JavaScript' should always return a result, even if that result is only 'missing value', but sometimes fails to do so. It's not the first application to do this, e.g. older versions of Address Book were notorious for this, and I suspect it's really something that should be addressed at the Cocoa Scripting framework level when mapping Cocoa objects to their AEDesc equivalents.


It shouldn't, I think. And
if it does, it should also throw AS-errors when the do JavaScript call does
so... (for example, appart from the DOM and appart from lots of missing
functions in Safari and, more generally, in most of browsers).

I've never understood JS's approach to exceptions and exception handling, so ain't going there myself. :p


Anyways, many thanks for helping to get to the bottom of the problem, and I'll be sure to pass the info on.

Cheers,

has
--
http://appscript.sourceforge.net
http://rb-appscript.rubyforge.org
http://appscript.sourceforge.net/objc-appscript.html

_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/applescript-users/email@hidden
Archives: http://lists.apple.com/archives/applescript-users

This email sent to 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.