|
View:
New views
4 Messages
—
Rating Filter:
Alert me
|
|
|
Re: why , when I call a custom object's function, spidermonkey visit the propertyOn 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 propertyHello, 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 |
|
|
|
|
|
Re: why ,when I call a custom object's function, spidermonkey visit the propertyOn 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 |
| Free embeddable forum powered by Nabble | Forum Help |