why , when I call a custom object's function, spidermonkey visit the property

View: New views
4 Messages — Rating Filter:   Alert me  

Re: why , when I call a custom object's function, spidermonkey visit the property

by Donny Viszneki :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Thu, Sep 24, 2009 at 4:49 PM, stdan <stdanley@...> wrote:

> JSPropertySpec JsBusiCom::props[] = {
>    {"condition",          ID_COND,      JSPROP_ENUMERATE,       NULL,NULL},
>    {"field",           ID_FIELD,      JSPROP_ENUMERATE,       NULL, NULL},
>    {"rows",         ID_ROW,    JSPROP_ENUMERATE|JSPROP_READONLY,NULL,NULL},
>    {NULL,0,0,NULL,NULL}
> };
> ============code end==
> then implement property getter ,construct ,and so on
> when I run test prgram in jsshell
> for example :
> var bc= new busiComp('test');
> bc.select('aaa');
> spidermonkey has not call my native function, but JSGetProperty is called,
> why ?

You have supplied NULL for the native getter/setter functions on your
instance properties.

--
http://codebad.com/
_______________________________________________
dev-tech-js-engine mailing list
dev-tech-js-engine@...
https://lists.mozilla.org/listinfo/dev-tech-js-engine

why , when I call a custom object's function, spidermonkey visit the property

by Tom Stanley :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello, all
I have implement an custom object:BusiComp,which has some properties and
methods: as follows:
====code============
JSClass JsBusiCom::BusiCom_class={
        "busiComp", JSCLASS_HAS_PRIVATE,
    JS_PropertyStub,  JS_PropertyStub,
    JsBusiCom::JSGetProperty,  JsBusiCom::JSSetProperty,
    JS_EnumerateStub, JS_ResolveStub,
    JS_ConvertStub,   JsBusiCom::JSDestructor
};
JSFunctionSpec JsBusiCom::methods[]= {
        { "select", JsBusiCom::select, 1, 0, 0 },
        {0,0,0,0,0}
};
JSPropertySpec JsBusiCom::props[] = {
    {"condition",          ID_COND,      JSPROP_ENUMERATE,       NULL,NULL},
    {"field",           ID_FIELD,      JSPROP_ENUMERATE,       NULL, NULL},
    {"rows",         ID_ROW,    JSPROP_ENUMERATE|JSPROP_READONLY,NULL,NULL},
    {NULL,0,0,NULL,NULL}
};
============code end==
then implement property getter ,construct ,and so on
when I run test prgram in jsshell
for example :
var bc= new busiComp('test');
bc.select('aaa');
spidermonkey has not call my native function, but JSGetProperty is called,
why ?
======code====
JSBool JsBusiCom::JSGetProperty(JSContext *cx, JSObject *obj, jsval idval,
jsval *vp){
        BusiComp* p=(BusiComp*) JS_GetPrivate(cx,obj);
        if (p==NULL) {
                simLog(DEBUG_LEVEL,"BusiComp private is null");
                *vp=JSVAL_VOID;
                return JS_FALSE;
        }
        AISTD string key=JS_GetStringBytes(JS_ValueToString(cx, idval));
        simLog(DEBUG_LEVEL,"get prop:%s",key.c_str());
...
}
JSBool JsBusiCom::JSConstructor(JSContext *cx, JSObject *obj, uintN argc,
jsval *argv, jsval *rval){
        ...
        BusiComp*  comp= new BusiComp(assignName,*p);
        if ( ! JS_SetPrivate(cx, obj, comp) )
                return JS_FALSE;
        *rval = OBJECT_TO_JSVAL(obj);
        return true;

}
JSObject* JsBusiCom::JSInit(JSContext *cx, JSObject *obj, JSObject *proto ){
        JSObject *newObj = JS_InitClass(cx, obj, proto,
&JsBusiCom::BusiCom_class,
                                     JsBusiCom::JSConstructor, 1,
                                     NULL, JsBusiCom::methods,
                                     NULL, NULL);
     return newObj;
};

==========code end==========
thx



_______________________________________________
dev-tech-js-engine mailing list
dev-tech-js-engine@...
https://lists.mozilla.org/listinfo/dev-tech-js-engine

Parent Message unknown Re: why , when I call a custom object's function, spidermonkey visit the property

by Tom Stanley :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Donny Viszneki wrote:

> On Thu, Sep 24, 2009 at 4:49 PM, stdan <stdanley@...> wrote:
>> JSPropertySpec JsBusiCom::props[] = {
>> {"condition",          ID_COND,      JSPROP_ENUMERATE,       NULL,NULL},
>> {"field",           ID_FIELD,      JSPROP_ENUMERATE,       NULL, NULL},
>> {"rows",         ID_ROW,    JSPROP_ENUMERATE|JSPROP_READONLY,NULL,NULL},
>> {NULL,0,0,NULL,NULL}
>> };
>> ============code end==
>> then implement property getter ,construct ,and so on
>> when I run test prgram in jsshell
>> for example :
>> var bc= new busiComp('test');
>> bc.select('aaa');
>> spidermonkey has not call my native function, but JSGetProperty is
>> called, why ?
>
> You have supplied NULL for the native getter/setter functions on your
> instance properties.
>
hi Donny,
Did you mean   NULL in JS_InitClass?
> JSObject *newObj = JS_InitClass(cx, obj, proto,
>&JsBusiCom::BusiCom_class,
>                                     JsBusiCom::JSConstructor, 1,
>                                     NULL, JsBusiCom::methods,
>                                     NULL, NULL);
I can fix this when change "NULL, JsBusiCom::methods," to
JsBusiCom::props,JsBusiCom::methods,"
and return true in JSGetProperty ,
but can you explain how spidermonkey resolve properties and functions?
_______________________________________________
dev-tech-js-engine mailing list
dev-tech-js-engine@...
https://lists.mozilla.org/listinfo/dev-tech-js-engine

Re: why ,when I call a custom object's function, spidermonkey visit the property

by Jason Orendorff-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 09/24/2009 03:49 PM, stdan wrote:

> JSClass JsBusiCom::BusiCom_class={
>          "busiComp", JSCLASS_HAS_PRIVATE,
>      JS_PropertyStub,  JS_PropertyStub,
>      JsBusiCom::JSGetProperty,  JsBusiCom::JSSetProperty,
>      JS_EnumerateStub, JS_ResolveStub,
>      JS_ConvertStub,   JsBusiCom::JSDestructor
> };
> JSFunctionSpec JsBusiCom::methods[]= {
>          { "select", JsBusiCom::select, 1, 0, 0 },
>          {0,0,0,0,0}
> };
 > [...]
> when I run test prgram in jsshell
> for example :
> var bc= new busiComp('test');
> bc.select('aaa');
> spidermonkey has not call my native function, but JSGetProperty is called,
> why ?

It is calling JSGetProperty to get the select property of bc.
The JSClass.getProperty and JSClass.setProperty hooks are the default
getter and setter for all properties on objects of that class.

You want your methods to behave like ordinary properties of ordinary
Objects. To do this, add the JSFUN_STUB_GSOPS flag to all JSFunctionSpecs:

   JSFunctionSpec JsBusiCom::methods[]= {
            { "select", JsBusiCom::select, 1, JSFUN_STUB_GSOPS, 0 },
            ...

-j
_______________________________________________
dev-tech-js-engine mailing list
dev-tech-js-engine@...
https://lists.mozilla.org/listinfo/dev-tech-js-engine