Spidermonkey embedding: How can I set Class Properties?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Blake McBride

    #1

    Spidermonkey embedding: How can I set Class Properties?


    Greetings,

    I am embedding Spidermonkey in a C app. and I'm having trouble setting
    class (not instance) property values. For example, I am setting up
    the class as follows:


    static JSBool constructor(JSC ontext *cx, JSObject *obj, uintN argc, jsval
    *argv, jsval *rval)
    {
    printf("constru ctor argc = %d\n", argc);
    *rval = OBJECT_TO_JSVAL (obj);
    return JS_TRUE;
    }

    main()
    {
    ....
    static JSClass my_class = {
    "MyClass", JSCLASS_HAS_PRI VATE,
    JS_PropertyStub ,JS_PropertyStu b,JS_PropertySt ub,JS_PropertyS tub,
    JS_EnumerateStu b,JS_ResolveStu b,JS_ConvertStu b,JS_FinalizeSt ub
    };
    static JSPropertySpec class_props[] = {
    {"Prop1", 0, JSPROP_ENUMERAT E},
    {0}
    };
    JSObject *proto;

    proto = JS_InitClass(cx , JS_GetGlobalObj ect(cx), 0, &my_class,
    constructor, 1, NULL, NULL, class_props, NULL);

    The above code correctly (verified through a JavaScript program)
    creates a new class with the Prop1 class property.

    The following code correctly adds an _instance_ property:

    jsval val = INT_TO_JSVAL(42 );
    JS_SetProperty( cx, proto, "MyProp2", &val);

    After three days I still can't figure out how to set the value of the class
    property,
    or, for that matter, create a new class property with a particular value. I
    am looking to
    do something like this:


    jsval val = INT_TO_JSVAL(88 );
    JS_SetProperty( cx, ???, "Prop1", &val);

    Any help would really be appreciated.

    Blake McBride
    blake@integra-online.com





  • RobG

    #2
    Re: Spidermonkey embedding: How can I set Class Properties?

    Blake McBride wrote:[color=blue]
    > Greetings,
    >
    > I am embedding Spidermonkey in a C app. and I'm having trouble setting
    > class (not instance) property values. For example, I am setting up
    > the class as follows:
    >[/color]

    I think you're lost - what has this got to do with JavaScript?

    See ya! :-)

    [...]

    --
    Rob

    Comment

    • Richard Cornford

      #3
      Re: Spidermonkey embedding: How can I set Class Properties?

      RobG wrote:[color=blue]
      > Blake McBride wrote:[color=green]
      >> I am embedding Spidermonkey in a C app. and I'm having trouble
      >> setting class (not instance) property values. For example,
      >> I am setting up the class as follows:
      >>[/color]
      >
      > I think you're lost - what has this got to do with JavaScript?[/color]

      Lost maybe, but this sort of has something to do with javascript. But
      this group is more about the use of the language then its
      implementations . A good group to ask questions about the Spidermonkey
      and/or Rhino implementations is - netscape.public .mozilla.jseng -, as
      there they may get the attention of the authors of those
      implementations .

      Richard.


      Comment

      • Blake McBride

        #4
        Re: Spidermonkey embedding: How can I set Class Properties?

        Spidermonkey is Mozilla's JavaScript engine. I'm trying to embed it in a C
        application.

        "RobG" <rgqld@iinet.ne t.auau> wrote in message
        news:NP0we.2323 $Zn.106493@news .optus.net.au.. .[color=blue]
        > Blake McBride wrote:[color=green]
        > > Greetings,
        > >
        > > I am embedding Spidermonkey in a C app. and I'm having trouble setting
        > > class (not instance) property values. For example, I am setting up
        > > the class as follows:
        > >[/color]
        >
        > I think you're lost - what has this got to do with JavaScript?
        >
        > See ya! :-)
        >
        > [...]
        >
        > --
        > Rob[/color]


        Comment

        Working...