Re: script object property contamination [reckon I've sussed it]
Re: script object property contamination [reckon I've sussed it]
- Subject: Re: script object property contamination [reckon I've sussed it]
- From: has <email@hidden>
- Date: Sun, 10 Feb 2002 19:00:15 +0000
Anthony Adachi wrote:
>
Sure. I've drastically reduced the size of the test script.
Mmmm, could use a bit more cleaning, but I was able to grok this one myself.
>
You can see this in the Apple Event Log when you run the script:
>
>
The Event Log output shows that the value contained in the child script
>
object's 'FirstChildProp' property is the same as it's parent's
>
'FirstParentProp' property:
>
(*9, 21, 7*)
>
Similarly, the child's SecondChildProp prop takes on the value of it's
>
parent's SecondParentProp:
>
(*missing value*)
>
The child's ThirdChildProp get's it's parent's first handler stuffed into
>
it:
>
(*parentHandlerA*)
Looks like a bug in AS.
<wild supposition>
Getting into the guts of AS for a moment, I'd guess that object names are
stored as a hash, and that pointers to the objects themselves are stored in
a simple indexed table. To get an object by name would require a three step
process: 1. look up the hash to get an index number (N), 2. get the Nth
item of the table (a pointer), 3. return whatever's being pointed to.
Now, my guess is that all the slow, tedious hash-side stuff (step 1) is
done at *compile-time* (at least for statically scoped stuff), and all that
gets stored in the resulting bytecode is an *index* to the pointer table.
That means the runtime engine only has to do a quick table lookup and
follow a pointer to retrieve an object (steps 2 and 3) instead of having to
do a full name-based lookup (steps 1 thru 3).
</wild supposition>
Here's a simple script that demonstrates this very snafu in action:
======================================================================
script scriptOne
property frank : "Frank"
property handlerStore : {}
end script
script scriptTwo
property bob : "Bob"
on getBob()
get bob
end getBob
end script
--TEST 1
tell scriptTwo to getBob()
--> "Bob" (as you'd expect)
--TEST 2
set scriptOne's handlerStore to scriptTwo's getBob
tell scriptOne to handlerStore()
--> "Frank" (note: this is wrong; it should've given an error because there
isn't a 'bob' in scriptOne)
======================================================================
If you change getBob to read:
on getBob()
get my bob
end getBob
then you now get the correct behaviour. (Whether this is because dynamic
scoping invokes a full name-based lookup or just that it pays more
attention to current context, I don't know. Though having done a quick
speed test I did note that it takes 3x longer, i.e. you never get something
for nothing.)
I guess you're just going to have to design around this one (simplify your
script's structure for starters; use 'my' keywords as appropriate, watch
whose context you're in, etc).
Meantime, can anyone tell me if this is already a known problem, or should
this go as an official bug report to the AS team?
has [man of gnarly haxor skilz and knowleg]
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.