Commit 11baa827 authored by rswindell's avatar rswindell
Browse files

Fix more JS suspend/resume request bugs, optimize some others, and add

some requests for clarification from Deuce.
parent cf63f2a6
......@@ -680,6 +680,7 @@ BOOL js_generate_index(JSContext* js_cx, JSObject* parent,
strcat(spath,".js");
if(!fexist(spath)) {
JS_RESUMEREQUEST(js_cx, rc);
lprintf(LOG_ERR,"%04d !HTML JavaScript (%s) doesn't exist",sock,spath);
break;
}
......
......@@ -1755,6 +1755,7 @@ js_recvfile(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
char* p;
char* cstr;
jsrefcount rc;
/* Deuce: please explain the next 2 lines: */
rc=JS_SUSPENDREQUEST(cx);
JS_RESUMEREQUEST(cx, rc);
......
......@@ -403,9 +403,9 @@ js_readln(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
JS_RESUMEREQUEST(cx, rc);
if((js_str=JS_NewStringCopyZ(cx,buf))!=NULL) /* exception here Feb-12-2005 */
*rval = STRING_TO_JSVAL(js_str); /* _CrtDbgBreak from _heap_alloc_dbg */
rc=JS_SUSPENDREQUEST(cx);
} else {
JS_RESUMEREQUEST(cx, rc);
}
JS_RESUMEREQUEST(cx, rc);
return(JS_TRUE);
}
......@@ -1174,6 +1174,7 @@ js_write(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
if(tlen>len) {
len=tlen-len;
if((cp=malloc(len))==NULL) {
JS_RESUMEREQUEST(cx, rc);
FREE_AND_NULL(uubuf);
dbprintf(TRUE, p, "malloc failure of %u bytes", len);
return(JS_TRUE);
......
......@@ -499,6 +499,7 @@ js_crc32(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
size_t len;
uint32_t cs;
jsrefcount rc;
/* Deuce: please explain the next 2 lines: */
rc=JS_SUSPENDREQUEST(cx);
JS_RESUMEREQUEST(cx, rc);
......@@ -529,7 +530,7 @@ js_chksum(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
if((p=js_ValueToStringBytes(cx, argv[0], &len))==NULL)
return(JS_FALSE);
rc=JS_SUSPENDREQUEST(cx);
rc=JS_SUSPENDREQUEST(cx); /* Deuce: Is this really necessary? */
while(len--) sum+=*(p++);
JS_RESUMEREQUEST(cx, rc);
......@@ -2567,6 +2568,7 @@ js_cfgfname(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
char result[MAX_PATH+1];
char* cstr;
jsrefcount rc;
/* Deuce: please explain next 2 lines: */
rc=JS_SUSPENDREQUEST(cx);
JS_RESUMEREQUEST(cx, rc);
......
......@@ -710,6 +710,8 @@ js_recvfrom(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
break;
}
JS_RESUMEREQUEST(cx, rc);
if(rd!=len) {
p->last_error=ERROR_VALUE;
return(JS_TRUE);
......@@ -724,12 +726,11 @@ js_recvfrom(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
rc=JS_SUSPENDREQUEST(cx);
len = recvfrom(p->sock,buf,len,0,(SOCKADDR*)&addr,&addrlen);
JS_RESUMEREQUEST(cx, rc);
if(len<0) {
p->last_error=ERROR_VALUE;
JS_RESUMEREQUEST(cx, rc);
return(JS_TRUE);
}
JS_RESUMEREQUEST(cx, rc);
buf[len]=0;
str = JS_NewStringCopyN(cx, buf, len);
......
......@@ -818,11 +818,10 @@ js_matchuserdata(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *r
JS_ValueToInt32(cx,argv[0],&offset);
rc=JS_SUSPENDREQUEST(cx);
if((len=user_rec_len(offset))<0) {
JS_RESUMEREQUEST(cx, rc);
return(JS_FALSE);
}
len=user_rec_len(offset);
JS_RESUMEREQUEST(cx, rc);
if(len<0)
return(JS_FALSE);
if((js_str=JS_ValueToString(cx, argv[1]))==NULL) {
*rval = INT_TO_JSVAL(0);
......@@ -1183,11 +1182,10 @@ js_get_node_message(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval
node_num=1;
rc=JS_SUSPENDREQUEST(cx);
if((buf=getnmsg(cfg,node_num))==NULL) {
JS_RESUMEREQUEST(cx, rc);
return(JS_TRUE);
}
buf=getnmsg(cfg,node_num);
JS_RESUMEREQUEST(cx, rc);
if(buf==NULL)
return(JS_TRUE);
js_str=JS_NewStringCopyZ(cx, buf);
free(buf);
......@@ -1247,11 +1245,10 @@ js_get_telegram(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rv
usernumber=1;
rc=JS_SUSPENDREQUEST(cx);
if((buf=getsmsg(cfg,usernumber))==NULL) {
JS_RESUMEREQUEST(cx, rc);
return(JS_TRUE);
}
buf=getsmsg(cfg,usernumber);
JS_RESUMEREQUEST(cx, rc);
if(buf==NULL)
return(JS_TRUE);
js_str=JS_NewStringCopyZ(cx, buf);
free(buf);
......
......@@ -8,7 +8,7 @@
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
* *
* Copyright 2007 Rob Swindell - http://www.synchro.net/copyright.html *
* Copyright 2008 Rob Swindell - http://www.synchro.net/copyright.html *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
......@@ -473,8 +473,10 @@ js_prompt(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
instr[0]=0;
rc=JS_SUSPENDREQUEST(cx);
if(!fgets(instr,sizeof(instr),stdin))
if(!fgets(instr,sizeof(instr),stdin)) {
JS_RESUMEREQUEST(cx, rc);
return(JS_TRUE);
}
JS_RESUMEREQUEST(cx, rc);
if((str=JS_NewStringCopyZ(cx, truncnl(instr)))==NULL)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment