Subj : Re: Spider Monkey - 200/11 works, x=200/11 core dumps To : netscape.public.mozilla.jseng From : pookiebearbottom@yahoo.com (Sally) Date : Mon Nov 10 2003 10:10 pm Brendan, the link you posted doesn't work on my end. thanks -sal Brendan Eich wrote in message news:<3FB03962.3080600@meer.net>... > Sally wrote: > > >I am using the following code. When ever I use basic math like > >"200/11" the script works. When I try to assign a variable, like > >"x=200/11" I get a core dump. Here is the code, any info would be > >helpful. I am somewhat new to spidermonkey, but been using javascript > >for years (in case you are wondering, I am calling it from C++ and > >that is why I wrote the wrappers like this). > > > > > > You're making the same mistake that was diagnosed in > news://news.mozilla.org:119/boiqeu$1ea52t$1@ID-3551.news.uni-berlin.de. > > /be > > >Thanks > >-Sal > > > >void *p=initJS(); /* set up sm MY JS_RTStruct */ > >char r[1000]; /* result string */ > >runJSScript(p,"11/2",r);/* works */ > >runJSScript(p,"x=11/2",r);/* core dumps */ > > > >typedef struct > >{ > > JSContext *cx; > > JSObject *global; > > JSRuntime *rt; > >} JS_RTStruct; > > > > > >void *initJS() > >{ > > JS_RTStruct *ptr=(JS_RTStruct *)malloc(sizeof(JS_RTStruct)); > > JSClass global_class= > > { > > "global",0, > > JS_PropertyStub,JS_PropertyStub,JS_PropertyStub,JS_PropertyStub, > > JS_EnumerateStub,JS_ResolveStub,JS_ConvertStub,JS_FinalizeStub > > }; > > > > ptr->rt = JS_NewRuntime(0x100000); > > ptr->cx = JS_NewContext(ptr->rt, 0x1000); > > ptr->global = JS_NewObject(ptr->cx, &global_class, NULL, NULL); > > JS_InitStandardClasses(ptr->cx, ptr->global); > > > > return ptr; > >} > > > >void runJSScript(void *p,char *script,char *result) > >{ > > JS_RTStruct *ptr=(JS_RTStruct *)p; > > jsval rval; > > JSString *str; > > int lineno=0; > > JSBool ok=JS_EvaluateScript(ptr->cx,ptr->global,script, > > strlen(script),NULL,lineno,&rval); > > strcpy(result,JS_GetStringBytes(JS_ValueToString(ptr->cx, rval))); > >} > > > > .