Subj : Integration of Spider monkey with DOM To : netscape.public.mozilla.jseng From : "Pradip Singh" Date : Thu Feb 05 2004 12:25 pm This is a multi-part message in MIME format. ------=_NextPart_000_0047_01C3EBE3.31C1E4C0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi All, I am doing DOM integration with spider monkey. Below is one rapper api = which gets called when we invoke var x =3D = document.get_documentElement() from the java script. It is supposed to = return an Element object. So x will contain an element object. JSBool get_documentElement(JSContext *cx, JSObject *obj, uintN argc, = jsval *argv, jsval *rval){ Element* tElem=3D&(doc.get_documentElement());//tmDoc = *rval=3DOBJECT_TO_JSVAL(ConvertToJSObject(cx,element_methods,sEnv.elemObj= , (void*)tElem)); return JS_TRUE; } Now i invoke var y =3D x.get_nodeName(); So the corresponding wrapper = functions get invoked. Element is inherited from node. JSBool get_nodeName(JSContext *cx, JSObject *obj, uintN argc, jsval = *argv, jsval *rval){ XMLString tXtr=3DGetNodePointer(cx,obj)->get_nodeName(); JSString* = tJStr=3DJS_NewString(cx,tXtr.GetBufferPointer(),tXtr.CharLength()); *rval=3DSTRING_TO_JSVAL(tJStr); return JS_TRUE; } The problem here is that get_nodeName() does not return the proper XML = string. I am supposed to get the name of the root node. Where as if i do = the same operations i,e=20 Node *n =3D (Node *)tElem; XMLString tXtr=3D n->get_nodeName(); char * data =3D tXtr.GetBufferPointer(); in the function get_documentElement() i get the correct name. The implementation of ConvertToJSObject is given below. JSObject* ConvertToJSObject(JSContext* cx,JSFunctionSpec* obj_methods, = JSObject* jsProto, void* data){ JSObject* jsO; jsO=3DJS_NewObject(cx,JS_GetClass(jsProto),jsProto,NULL); JS_DefineFunctions(cx,jsO,obj_methods); JS_SetPrivate(cx,jsO, (void*)data); return jsO; } Thanx in advance, Regards, Pradip. ------=_NextPart_000_0047_01C3EBE3.31C1E4C0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Hi All,
 
 I am doing DOM integration with = spider=20 monkey. Below is one rapper api which gets called when we invoke var x = =3D=20 document.get_documentElement() from the java script. It is supposed to = return an=20 Element object. So x will contain an element object.
 
   JSBool = get_documentElement(JSContext=20 *cx, JSObject *obj, uintN argc, jsval *argv, jsval=20 *rval){
  Element*=20 tElem=3D&(doc.get_documentElement());//tmDoc
 *rval=3DOBJECT_= TO_JSVAL(ConvertToJSObject(cx,element_methods,sEnv.elemObj,=20 (void*)tElem));
 return JS_TRUE;
}
 
Now i invoke var y =3D = x.get_nodeName(); So the=20 corresponding wrapper functions get invoked. Element is inherited from=20 node.
 
JSBool get_nodeName(JSContext *cx, = JSObject *obj,=20 uintN argc, jsval *argv, jsval *rval){
    XMLString=20 tXtr=3DGetNodePointer(cx,obj)->get_nodeName();
 JSString*=20 tJStr=3DJS_NewString(cx,tXtr.GetBufferPointer(),tXtr.CharLength());
&n= bsp;*rval=3DSTRING_TO_JSVAL(tJStr);
 return=20 JS_TRUE;
}
 
The problem here is that get_nodeName() = does not=20 return the proper XML string. I am supposed to get the name of the root = node.=20 Where as if i do the same operations i,e
Node *n =3D (Node *)tElem;
XMLString = tXtr=3D=20 n->get_nodeName();
char * data =3D = tXtr.GetBufferPointer();
 
in the function get_documentElement() i = get the=20 correct name.
 
The implementation of ConvertToJSObject = is given=20 below.
 
JSObject* ConvertToJSObject(JSContext*=20 cx,JSFunctionSpec* obj_methods, JSObject* jsProto, void* = data){
 
 JSObject*=20 jsO;
 jsO=3DJS_NewObject(cx,JS_GetClass(jsProto),jsProto,NULL); JS_DefineFunctions(cx,jsO,obj_methods);
 JS_SetPrivate(cx= ,jsO,=20 (void*)data);
 return jsO;
}
 
Thanx in advance,
Regards,
Pradip.
------=_NextPart_000_0047_01C3EBE3.31C1E4C0-- .