[Swfdec] problems to lookup AS object properties using SWFDEC API functions - cause found

Benjamin Otte otte at gnome.org
Thu Jul 9 05:22:49 PDT 2009


Ah, d'oh, I should have spotted that when glancing the mail.
Yeah, there is a reason why Swfdec uses a direct lookup: performance.
As getting a variable is one of the most-used things when running
scripts it must be very fast. In fact, a large chunk of recent
Javascript performance improvements in Webkit and Firefox comes from
making this lookup even faster.

There's an easy way to solve your problem, and that is
swfdec_as_context_get_string(), which will hand you an internal unique
string that properly compares with direct hashes.

Cheers,
Benjamin


On Thu, Jul 9, 2009 at 1:13 PM, Bernd Kischnick<kisch at ki.sch-co.de> wrote:
> Replying to my own mail:
>
>> Neither
>> swfdec_as_object_has_variable() nor swfdec_as_object_get_variable() nor
>> swfdec_as_object_get_variable_and_flags() are able to find a property
>> which definitely exists.
>
> ...whereas enumerating the properties shows them to exist.
>
> This strange behaviour is caused by the properties-hash of AS objects
> being a DIRECT hash as opposed to a STRING hash.
>
> swfdec_as_object.c has this:
>
> static void
> swfdec_as_object_init (SwfdecAsObject *object)
> {
>  object->properties = g_hash_table_new (g_direct_hash, g_direct_equal);
> }
>
> It should probably have g_str_hash and g_str_equal.
>
> Direct hashing only works as long as the property names are guaranteed to
> be the identical string constants (same address) as used when populating
> the hash.
> In my case I'm trying to look up a property using a fresh string constant
> as the key; this will never be address-equal to any existing key in the
> hash.
>
> Changing swfdec_as_object_init() to use g_str_hash and g_str_euqal seems
> to solve the lookup problem. Now I'm struggling to get AS function calls
> to work.
>
> Is there a reason why a direct hash was used in the first place?
> I hope the change doesn't have bad side effects.
>
> The lookup problem is probably masked by a backwards-compatibility mode
> for ActionScript < v7. In swfdec_as_object_hash_lookup(), there's a
> fallback to sequential case-insensitive property lookup when the direct
> lookup fails --- but my test SWF are v7, so the fallback wasn't effective.
>
> - kisch
>
> _______________________________________________
> Swfdec mailing list
> Swfdec at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/swfdec
>


More information about the Swfdec mailing list