Mozilla

NAVIGATION
CATEGORIES
REFERRENCE
LINKS
  • npruntime: accessing javascript arrays

    3 answers - 796 bytes - related search similar search Add To My Delicious Add To My Stumble Upon Add To My Google Mark Add To My Facebook Add To My Digg Add To My Reddit

    Hi,
    How can I access javascript array elements from inside npruntime?
    I have javascript array passed to my plugin's function: like
    plugin.MyFunction( new Array(1,2,3) );
    The array argument is an variant (as expected). I can get the length
    of the array by querying "length" property or by doing NPN_Evaluate on the
    object with a "length" script. I get back an Int32 variant with the correct
    value.
    However, I did not find a way to query the contents of the array yet. Doing
    something like "[0]" produces null result in NPN_Evaluate and
    NPN_HasProperty returns false for that (even if the docs near
    NPN_GetStringIdentifier seem to imply that indexing should work).
    Any suggestions?
    (everything's happening on Firefox 1.5.0.6)
  • No.1 | | 1134 bytes | |

    Hi Aras,

    There's a NPN_GetIntIdentifier() that you can use to get an integer
    identifier and with that you can access properties by index off of any
    JS object, including Array's.

    Aras Pranckevicius wrote:
    Hi,

    How can I access javascript array elements from inside npruntime?

    I have javascript array passed to my plugin's function: like
    plugin.MyFunction( new Array(1,2,3) );

    The array argument is an variant (as expected). I can get the
    length of the array by querying "length" property or by doing
    NPN_Evaluate on the object with a "length" script. I get back an Int32
    variant with the correct value.

    However, I did not find a way to query the contents of the array yet.
    Doing something like "[0]" produces null result in NPN_Evaluate and
    NPN_HasProperty returns false for that (even if the docs near
    NPN_GetStringIdentifier seem to imply that indexing should work).

    Any suggestions?

    (everything's happening on Firefox 1.5.0.6)

    dev-tech-plugins mailing list
    dev-tech-plugins (AT) lists (DOT) mozilla.org
  • No.2 | | 646 bytes | |

    There's a NPN_GetIntIdentifier() that you can use to get an integer
    identifier and with that you can access properties by index off of any JS
    object, including Array's.

    Thanks a lot, that works perfectly!

    The docs here could
    mention these use cases - right now they only say "returns identifier for a
    string" or "returns identifier for an int". Could add that the first you use
    to access regular properties, and the other one to access indexed objects.

    How would one access an associative array? Esp. if it has an entry at index
    ["length"] (there's a reglar property named like that already)?
  • No.3 | | 902 bytes | |

    Aras Pranckevicius wrote:
    >There's a NPN_GetIntIdentifier() that you can use to get an integer
    >identifier and with that you can access properties by index off of any
    >JS object, including Array's.


    Thanks a lot, that works perfectly!

    The docs here
    could mention these use cases - right now they only say "returns
    identifier for a string" or "returns identifier for an int". Could add
    that the first you use to access regular properties, and the other one
    to access indexed objects.

    How would one access an associative array? Esp. if it has an entry at
    index ["length"] (there's a reglar property named like that already)?

    AFAIK there is no such concept in JS, array.length is the same as
    accessing array["length"] in all cases. And thus you differentiate
    between the two using NPRuntime either.

Re: npruntime: accessing javascript arrays


max 4000 letters.
Your nickname that display:
In order to stop the spam: 7 + 6 =
QUESTION ON "Mozilla"

EMSDN.COM