This commit is contained in:
brendan%mozilla.org 1999-07-28 06:48:44 +00:00
Родитель 710e7dd097
Коммит 2ac2a0d840
12 изменённых файлов: 64 добавлений и 57 удалений

Просмотреть файл

@ -147,7 +147,7 @@ js_DestroyContext(JSContext *cx, JSBool force_gc)
free(cx->lastMessage); free(cx->lastMessage);
#ifdef JS_THREADSAFE #ifdef JS_THREADSAFE
/* Destroying a context implicitly calls JS_EndRequest(). */ /* Destroying a context implicitly calls JS_EndRequest(). */
if (cx->requestDepth) if (cx->requestDepth)
JS_EndRequest(cx); JS_EndRequest(cx);
#endif #endif
@ -234,14 +234,14 @@ js_ExpandErrorArguments(JSContext *cx, JSErrorCallback callback,
if (callback) { if (callback) {
fmtData = (*callback)(userRef, "Mountain View", errorNumber); fmtData = (*callback)(userRef, "Mountain View", errorNumber);
if (fmtData != NULL) { if (fmtData != NULL) {
int totalArgsLength = 0; size_t totalArgsLength = 0;
int argLengths[10]; /* only {0} thru {9} supported */ size_t argLengths[10]; /* only {0} thru {9} supported */
argCount = fmtData->argCount; argCount = fmtData->argCount;
JS_ASSERT(argCount <= 10); JS_ASSERT(argCount <= 10);
if (argCount > 0) { if (argCount > 0) {
/* /*
* Gather the arguments into an array, and accumulate * Gather the arguments into an array, and accumulate
* their sizes. We allocate 1 more than necessary and * their sizes. We allocate 1 more than necessary and
* null it out to act as the caboose when we free the * null it out to act as the caboose when we free the
* pointers later. * pointers later.
*/ */
@ -253,7 +253,7 @@ js_ExpandErrorArguments(JSContext *cx, JSErrorCallback callback,
for (i = 0; i < argCount; i++) { for (i = 0; i < argCount; i++) {
if (charArgs) { if (charArgs) {
char *charArg = va_arg(ap, char *); char *charArg = va_arg(ap, char *);
reportp->messageArgs[i] reportp->messageArgs[i]
= js_InflateString(cx, charArg, strlen(charArg)); = js_InflateString(cx, charArg, strlen(charArg));
} }
else else
@ -262,7 +262,7 @@ js_ExpandErrorArguments(JSContext *cx, JSErrorCallback callback,
totalArgsLength += argLengths[i]; totalArgsLength += argLengths[i];
} }
/* NULL-terminate for easy copying. */ /* NULL-terminate for easy copying. */
reportp->messageArgs[i] = NULL; reportp->messageArgs[i] = NULL;
} }
/* /*
* Parse the error format, substituting the argument X * Parse the error format, substituting the argument X
@ -274,14 +274,15 @@ js_ExpandErrorArguments(JSContext *cx, JSErrorCallback callback,
const jschar *arg; const jschar *arg;
jschar *out; jschar *out;
int expandedArgs = 0; int expandedArgs = 0;
int expandedLength size_t expandedLength
= strlen(fmtData->format) = strlen(fmtData->format)
- (3 * argCount) /* exclude the {n} */ - (3 * argCount) /* exclude the {n} */
+ totalArgsLength; + totalArgsLength;
/* Note - the above calculation assumes that each argument /*
* is used once and only once in the expansion !!! * Note - the above calculation assumes that each argument
*/ * is used once and only once in the expansion !!!
reportp->ucmessage = out */
reportp->ucmessage = out
= JS_malloc(cx, (expandedLength + 1) * sizeof(jschar)); = JS_malloc(cx, (expandedLength + 1) * sizeof(jschar));
if (!out) { if (!out) {
if (reportp->messageArgs) { if (reportp->messageArgs) {
@ -311,14 +312,18 @@ js_ExpandErrorArguments(JSContext *cx, JSErrorCallback callback,
} }
JS_ASSERT(expandedArgs == argCount); JS_ASSERT(expandedArgs == argCount);
*out = 0; *out = 0;
*messagep = js_DeflateString(cx, reportp->ucmessage, *messagep =
out - reportp->ucmessage); js_DeflateString(cx, reportp->ucmessage,
(size_t)(out - reportp->ucmessage));
} }
} else { /* 0 arguments, the format string } else {
(if it exists) is the entire message */ /*
* Zero arguments: the format string (if it exists) is the
* entire message.
*/
if (fmtData->format) { if (fmtData->format) {
*messagep = JS_strdup(cx, fmtData->format); *messagep = JS_strdup(cx, fmtData->format);
reportp->ucmessage reportp->ucmessage
= js_InflateString(cx, *messagep, strlen(*messagep)); = js_InflateString(cx, *messagep, strlen(*messagep));
} }
} }
@ -396,12 +401,12 @@ js_ReportErrorNumberVA(JSContext *cx, uintN flags, JSErrorCallback callback,
*/ */
if (errorNumber == JSMSG_UNCAUGHT_EXCEPTION) if (errorNumber == JSMSG_UNCAUGHT_EXCEPTION)
report.flags |= JSREPORT_EXCEPTION; report.flags |= JSREPORT_EXCEPTION;
#if JS_HAS_ERROR_EXCEPTIONS #if JS_HAS_ERROR_EXCEPTIONS
/* /*
* Only call the error reporter if an exception wasn't raised. * Only call the error reporter if an exception wasn't raised.
* *
* If an exception was raised, then we call the debugErrorHook * If an exception was raised, then we call the debugErrorHook
* (if present) to give it a chance to see the error before it * (if present) to give it a chance to see the error before it
* propigates out of scope. This is needed for compatability with * propigates out of scope. This is needed for compatability with
* the old scheme. * the old scheme.
@ -422,11 +427,11 @@ js_ReportErrorNumberVA(JSContext *cx, uintN flags, JSErrorCallback callback,
JS_free(cx, message); JS_free(cx, message);
if (report.messageArgs) { if (report.messageArgs) {
int i = 0; int i = 0;
while (report.messageArgs[i]) while (report.messageArgs[i])
JS_free(cx, (void *)report.messageArgs[i++]); JS_free(cx, (void *)report.messageArgs[i++]);
JS_free(cx, (void *)report.messageArgs); JS_free(cx, (void *)report.messageArgs);
} }
if (report.ucmessage) if (report.ucmessage)
JS_free(cx, (void *)report.ucmessage); JS_free(cx, (void *)report.ucmessage);
} }

Просмотреть файл

@ -2530,7 +2530,7 @@ ret1:
** '+' or '-' after the 'e' in scientific notation ** '+' or '-' after the 'e' in scientific notation
*/ */
JS_FRIEND_API(void) JS_FRIEND_API(void)
JS_cnvtf(char *buf,int bufsz, int prcsn,double fval) JS_cnvtf(char *buf, size_t bufsz, int prcsn, double fval)
{ {
intN decpt,sign,numdigits; intN decpt,sign,numdigits;
char *num, *nump; char *num, *nump;

Просмотреть файл

@ -47,7 +47,7 @@ JS_strtod(const char *s00, char **se);
* point value. * point value.
*/ */
JS_FRIEND_API(void) JS_FRIEND_API(void)
JS_cnvtf(char *buf, intN bufsz, intN prcsn, double dval); JS_cnvtf(char *buf, size_t bufsz, int prcsn, double dval);
JS_END_EXTERN_C JS_END_EXTERN_C

Просмотреть файл

@ -861,7 +861,7 @@ js_EmitTree(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn)
return JS_FALSE; return JS_FALSE;
if (caseNoteIndex >= 0) { if (caseNoteIndex >= 0) {
/* off is the previous JSOP_CASE's bytecode offset. */ /* off is the previous JSOP_CASE's bytecode offset. */
if (!js_SetSrcNoteOffset(cx, cg, caseNoteIndex, 0, if (!js_SetSrcNoteOffset(cx, cg, (uintN)caseNoteIndex, 0,
CG_OFFSET(cg) - off)) { CG_OFFSET(cg) - off)) {
return JS_FALSE; return JS_FALSE;
} }
@ -877,8 +877,10 @@ js_EmitTree(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn)
pn3->pn_offset = off; pn3->pn_offset = off;
if (pn3 == pn2->pn_head) { if (pn3 == pn2->pn_head) {
/* Switch note's second offset is to first JSOP_CASE. */ /* Switch note's second offset is to first JSOP_CASE. */
if (!js_SetSrcNoteOffset(cx, cg, noteIndex, 1, off - top)) if (!js_SetSrcNoteOffset(cx, cg, (uintN)noteIndex, 1,
off - top)) {
return JS_FALSE; return JS_FALSE;
}
} }
} }
@ -927,7 +929,7 @@ js_EmitTree(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn)
/* Set the SRC_SWITCH note's offset operand to tell end of switch. */ /* Set the SRC_SWITCH note's offset operand to tell end of switch. */
off = CG_OFFSET(cg) - top; off = CG_OFFSET(cg) - top;
if (!js_SetSrcNoteOffset(cx, cg, noteIndex, 0, off)) if (!js_SetSrcNoteOffset(cx, cg, (uintN)noteIndex, 0, off))
return JS_FALSE; return JS_FALSE;
if (switchop == JSOP_TABLESWITCH) { if (switchop == JSOP_TABLESWITCH) {
@ -1138,13 +1140,13 @@ js_EmitTree(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn)
SET_STATEMENT_TOP(&stmtInfo, top); SET_STATEMENT_TOP(&stmtInfo, top);
if (!pn2->pn_kid2) { if (!pn2->pn_kid2) {
/* No loop condition: flag this fact in the source notes. */ /* No loop condition: flag this fact in the source notes. */
if (!js_SetSrcNoteOffset(cx, cg, noteIndex, 0, 0)) if (!js_SetSrcNoteOffset(cx, cg, (uintN)noteIndex, 0, 0))
return JS_FALSE; return JS_FALSE;
beq = 0; beq = 0;
} else { } else {
if (!js_EmitTree(cx, cg, pn2->pn_kid2)) if (!js_EmitTree(cx, cg, pn2->pn_kid2))
return JS_FALSE; return JS_FALSE;
if (!js_SetSrcNoteOffset(cx, cg, noteIndex, 0, if (!js_SetSrcNoteOffset(cx, cg, (uintN)noteIndex, 0,
(ptrdiff_t)(CG_OFFSET(cg) - top))) { (ptrdiff_t)(CG_OFFSET(cg) - top))) {
return JS_FALSE; return JS_FALSE;
} }
@ -1161,7 +1163,7 @@ js_EmitTree(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn)
if (pn2->pn_type != TOK_IN) { if (pn2->pn_type != TOK_IN) {
/* Set the second note offset so we can find the update part. */ /* Set the second note offset so we can find the update part. */
JS_ASSERT(noteIndex != -1); JS_ASSERT(noteIndex != -1);
if (!js_SetSrcNoteOffset(cx, cg, noteIndex, 1, if (!js_SetSrcNoteOffset(cx, cg, (uintN)noteIndex, 1,
(ptrdiff_t)(CG_OFFSET(cg) - top))) { (ptrdiff_t)(CG_OFFSET(cg) - top))) {
return JS_FALSE; return JS_FALSE;
} }
@ -1190,7 +1192,7 @@ js_EmitTree(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn)
} }
/* The third note offset helps us find the loop-closing jump. */ /* The third note offset helps us find the loop-closing jump. */
if (!js_SetSrcNoteOffset(cx, cg, noteIndex, 2, if (!js_SetSrcNoteOffset(cx, cg, (uintN)noteIndex, 2,
(ptrdiff_t)(CG_OFFSET(cg) - top))) { (ptrdiff_t)(CG_OFFSET(cg) - top))) {
return JS_FALSE; return JS_FALSE;
} }
@ -1586,7 +1588,7 @@ js_EmitTree(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn)
EMIT_ATOM_INDEX_OP(op, atomIndex); EMIT_ATOM_INDEX_OP(op, atomIndex);
tmp = CG_OFFSET(cg); tmp = CG_OFFSET(cg);
if (noteIndex >= 0) { if (noteIndex >= 0) {
if (!js_SetSrcNoteOffset(cx, cg, noteIndex, 0, tmp - off)) if (!js_SetSrcNoteOffset(cx, cg, (uintN)noteIndex, 0, tmp-off))
return JS_FALSE; return JS_FALSE;
} }
if (!pn2->pn_next) if (!pn2->pn_next)
@ -1680,7 +1682,7 @@ js_EmitTree(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn)
return JS_FALSE; return JS_FALSE;
tmp = CG_OFFSET(cg); tmp = CG_OFFSET(cg);
if (noteIndex >= 0) { if (noteIndex >= 0) {
if (!js_SetSrcNoteOffset(cx, cg, noteIndex, 0, tmp - off)) if (!js_SetSrcNoteOffset(cx, cg, (uintN)noteIndex, 0, tmp-off))
return JS_FALSE; return JS_FALSE;
} }
if (!pn2->pn_next) if (!pn2->pn_next)

Просмотреть файл

@ -1772,8 +1772,8 @@ js_ReportIsNotFunction(JSContext *cx, jsval *vp, JSBool constructing)
} }
if (str) { if (str) {
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
constructing ? JSMSG_NOT_CONSTRUCTOR (uintN)(constructing ? JSMSG_NOT_CONSTRUCTOR
: JSMSG_NOT_FUNCTION, : JSMSG_NOT_FUNCTION),
JS_GetStringBytes(str)); JS_GetStringBytes(str));
} }
} }

Просмотреть файл

@ -1916,8 +1916,8 @@ js_Interpret(JSContext *cx, jsval *result)
RESTORE_SP(fp); RESTORE_SP(fp);
if (!ok) if (!ok)
goto out; goto out;
i = ~i; d = (jsdouble) ~i;
PUSH_NUMBER(cx, i); PUSH_NUMBER(cx, d);
break; break;
case JSOP_NEG: case JSOP_NEG:

Просмотреть файл

@ -452,8 +452,8 @@ js_CleanupLocks()
JS_PUBLIC_API(void) JS_PUBLIC_API(void)
js_InitContextForLocking(JSContext *cx) js_InitContextForLocking(JSContext *cx)
{ {
cx->thread = CurrentThreadId(); cx->thread = CurrentThreadId();
JS_ASSERT(Thin_GetWait(cx->thread) == 0); JS_ASSERT(Thin_GetWait(cx->thread) == 0);
} }
/* /*

Просмотреть файл

@ -51,8 +51,8 @@ typedef struct JSFatLockTable {
#define JS_ATOMIC_ADDREF(p, i) js_AtomicAdd(p,i) #define JS_ATOMIC_ADDREF(p, i) js_AtomicAdd(p,i)
#define CurrentThreadId() (jsword)PR_GetCurrentThread() #define CurrentThreadId() (jsword)PR_GetCurrentThread()
#define JS_CurrentThreadId() js_CurrentThreadId() #define JS_CurrentThreadId() js_CurrentThreadId()
#define JS_NEW_LOCK() PR_NewLock() #define JS_NEW_LOCK() PR_NewLock()
#define JS_DESTROY_LOCK(l) PR_DestroyLock(l) #define JS_DESTROY_LOCK(l) PR_DestroyLock(l)
#define JS_ACQUIRE_LOCK(l) PR_Lock(l) #define JS_ACQUIRE_LOCK(l) PR_Lock(l)

Просмотреть файл

@ -108,11 +108,11 @@ static JSPropertySpec object_props[] = {
static JSBool static JSBool
obj_getSlot(JSContext *cx, JSObject *obj, jsval id, jsval *vp) obj_getSlot(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{ {
jsint slot; uint32 slot;
JSAccessMode mode; JSAccessMode mode;
uintN attrs; uintN attrs;
slot = JSVAL_TO_INT(id); slot = (uint32) JSVAL_TO_INT(id);
if (id == INT_TO_JSVAL(JSSLOT_PROTO)) { if (id == INT_TO_JSVAL(JSSLOT_PROTO)) {
id = (jsid)cx->runtime->atomState.protoAtom; id = (jsid)cx->runtime->atomState.protoAtom;
mode = JSACC_PROTO; mode = JSACC_PROTO;
@ -130,12 +130,12 @@ JS_STATIC_DLL_CALLBACK(JSBool)
obj_setSlot(JSContext *cx, JSObject *obj, jsval id, jsval *vp) obj_setSlot(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{ {
JSObject *obj2; JSObject *obj2;
jsint slot; uint32 slot;
if (!JSVAL_IS_OBJECT(*vp)) if (!JSVAL_IS_OBJECT(*vp))
return JS_TRUE; return JS_TRUE;
obj2 = JSVAL_TO_OBJECT(*vp); obj2 = JSVAL_TO_OBJECT(*vp);
slot = JSVAL_TO_INT(id); slot = (uint32) JSVAL_TO_INT(id);
while (obj2) { while (obj2) {
if (obj2 == obj) { if (obj2 == obj) {
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
@ -426,7 +426,7 @@ js_obj_toSource(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
/* If id is a non-identifier string, it needs to be quoted. */ /* If id is a non-identifier string, it needs to be quoted. */
if (JSVAL_IS_STRING(id) && !js_IsIdentifier(idstr)) { if (JSVAL_IS_STRING(id) && !js_IsIdentifier(idstr)) {
idstr = js_QuoteString(cx, idstr, '\''); idstr = js_QuoteString(cx, idstr, (jschar)'\'');
if (!idstr) { if (!idstr) {
ok = JS_FALSE; ok = JS_FALSE;
goto error; goto error;
@ -1724,7 +1724,7 @@ js_SetProperty(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
uintN protoattrs; uintN protoattrs;
JSClass *clasp; JSClass *clasp;
jsval pval; jsval pval;
jsint slot; uint32 slot;
JSString *str; JSString *str;
rt = cx->runtime; rt = cx->runtime;
@ -1750,7 +1750,7 @@ js_SetProperty(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
sprop = sym_property(sym); sprop = sym_property(sym);
#if JS_HAS_OBJ_WATCHPOINT #if JS_HAS_OBJ_WATCHPOINT
if (!sprop) { if (!sprop) {
uint32 slot, nslots; uint32 nslots;
jsval *slots; jsval *slots;
/* /*
@ -2644,7 +2644,7 @@ void printObj(JSObject *jsobj) {
} }
void printVal(jsval val) { void printVal(jsval val) {
fprintf(stderr, "val %d (0x%p) = ", val, (void *)val); fprintf(stderr, "val %d (0x%p) = ", (int)val, (void *)val);
if (JSVAL_IS_NULL(val)) { if (JSVAL_IS_NULL(val)) {
fprintf(stderr, "null\n"); fprintf(stderr, "null\n");
} else if (JSVAL_IS_VOID(val)) { } else if (JSVAL_IS_VOID(val)) {
@ -2666,7 +2666,7 @@ void printVal(jsval val) {
} }
void printId(jsid id) { void printId(jsid id) {
fprintf(stderr, "id %d (0x%p) is ", id, (void *)id); fprintf(stderr, "id %d (0x%p) is ", (int)id, (void *)id);
printVal(js_IdToValue(id)); printVal(js_IdToValue(id));
} }

Просмотреть файл

@ -665,7 +665,7 @@ DecompileSwitch(SprintStack *ss, TableEntry *table, uintN tableLength,
return JS_FALSE; return JS_FALSE;
jp->indent += 2; jp->indent += 2;
if (JSVAL_IS_STRING(key)) { if (JSVAL_IS_STRING(key)) {
rval = QuoteString(&ss->sprinter, str, '"'); rval = QuoteString(&ss->sprinter, str, (jschar)'"');
if (!rval) if (!rval)
return JS_FALSE; return JS_FALSE;
} else { } else {
@ -1619,7 +1619,7 @@ Decompile(SprintStack *ss, jsbytecode *pc, intN nb)
todo = Sprint(&ss->sprinter, buf); todo = Sprint(&ss->sprinter, buf);
} else if (JSVAL_IS_STRING(key)) { } else if (JSVAL_IS_STRING(key)) {
rval = QuoteString(&ss->sprinter, ATOM_TO_STRING(atom), rval = QuoteString(&ss->sprinter, ATOM_TO_STRING(atom),
'"'); (jschar)'"');
if (!rval) if (!rval)
return JS_FALSE; return JS_FALSE;
todo = Sprint(&ss->sprinter, "%s", rval); todo = Sprint(&ss->sprinter, "%s", rval);

Просмотреть файл

@ -88,7 +88,7 @@ typedef enum JSOp {
#define ARGC_HI(argc) ((jsbytecode)((argc) >> 8)) #define ARGC_HI(argc) ((jsbytecode)((argc) >> 8))
#define ARGC_LO(argc) ((jsbytecode)(argc)) #define ARGC_LO(argc) ((jsbytecode)(argc))
#define GET_ARGC(pc) (((pc)[1] << 8) | (pc)[2]) #define GET_ARGC(pc) ((uintN)(((pc)[1] << 8) | (pc)[2]))
#define ARGC_LIMIT ((uint32)1 << 16) #define ARGC_LIMIT ((uint32)1 << 16)
/* Synonyms for quick JOF_QARG and JOF_QVAR bytecodes. */ /* Synonyms for quick JOF_QARG and JOF_QVAR bytecodes. */

Просмотреть файл

@ -117,7 +117,7 @@ static int fill2(SprintfState *ss, const char *src, int srclen, int width,
} }
/* Copy out the source data */ /* Copy out the source data */
rv = (*ss->stuff)(ss, src, srclen); rv = (*ss->stuff)(ss, src, (JSUint32)srclen);
if (rv < 0) { if (rv < 0) {
return rv; return rv;
} }
@ -211,7 +211,7 @@ static int fill_n(SprintfState *ss, const char *src, int srclen, int width,
return rv; return rv;
} }
} }
rv = (*ss->stuff)(ss, src, srclen); rv = (*ss->stuff)(ss, src, (JSUint32)srclen);
if (rv < 0) { if (rv < 0) {
return rv; return rv;
} }
@ -326,7 +326,7 @@ static int cvt_f(SprintfState *ss, double d, const char *fmt0, const char *fmt1)
/* Totally bogus % command to sprintf. Just ignore it */ /* Totally bogus % command to sprintf. Just ignore it */
return 0; return 0;
} }
memcpy(fin, fmt0, amount); memcpy(fin, fmt0, (size_t)amount);
fin[amount] = 0; fin[amount] = 0;
/* Convert floating point using the native sprintf code */ /* Convert floating point using the native sprintf code */
@ -906,7 +906,7 @@ static int dosprintf(SprintfState *ss, const char *fmt, va_list ap)
i = fmt - dolPt; i = fmt - dolPt;
if( i < sizeof( pattern ) ){ if( i < sizeof( pattern ) ){
pattern[0] = '%'; pattern[0] = '%';
memcpy( &pattern[1], dolPt, i ); memcpy( &pattern[1], dolPt, (size_t)i );
rv = cvt_f(ss, u.d, pattern, &pattern[i+1] ); rv = cvt_f(ss, u.d, pattern, &pattern[i+1] );
} }
} else } else