From 76813139a06f8a37a8b1c0c9db1c0e226429d951 Mon Sep 17 00:00:00 2001 From: fur Date: Mon, 1 Jun 1998 00:31:59 +0000 Subject: [PATCH] Merge several bug fixes from client 4.1 branch git-svn-id: svn://10.0.0.236/trunk@2791 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/js/ref/js.c | 1 + mozilla/js/ref/jsapi.c | 8 +++- mozilla/js/ref/jsarray.c | 17 ++++---- mozilla/js/ref/jsatom.c | 2 +- mozilla/js/ref/jsbool.c | 1 + mozilla/js/ref/jscntxt.c | 1 + mozilla/js/ref/jsdate.c | 1 + mozilla/js/ref/jsdbgapi.c | 1 + mozilla/js/ref/jsemit.c | 8 ++-- mozilla/js/ref/jsemit.h | 5 ++- mozilla/js/ref/jsfun.c | 1 + mozilla/js/ref/jsgc.c | 1 + mozilla/js/ref/jsinterp.c | 83 +++++++++++++++++++++++++++------------ mozilla/js/ref/jslock.c | 1 + mozilla/js/ref/jsmath.c | 1 + mozilla/js/ref/jsnum.c | 1 + mozilla/js/ref/jsobj.c | 75 +++++++++++++++++++++++++++++++---- mozilla/js/ref/jsopcode.c | 13 +++--- mozilla/js/ref/jsparse.c | 4 ++ mozilla/js/ref/jsregexp.c | 13 +++--- mozilla/js/ref/jsscan.c | 15 +++---- mozilla/js/ref/jsscope.c | 1 + mozilla/js/ref/jsscript.c | 5 ++- mozilla/js/ref/jsstddef.h | 41 +++++++++++++++++++ mozilla/js/ref/jsstr.c | 3 +- mozilla/js/ref/jsxdrapi.c | 37 ++++++++--------- mozilla/js/ref/prarena.c | 1 + mozilla/js/ref/prdtoa.c | 1 + 28 files changed, 253 insertions(+), 89 deletions(-) create mode 100644 mozilla/js/ref/jsstddef.h diff --git a/mozilla/js/ref/js.c b/mozilla/js/ref/js.c index 1461fd0b4e2..c2fdf53acca 100644 --- a/mozilla/js/ref/js.c +++ b/mozilla/js/ref/js.c @@ -19,6 +19,7 @@ /* * JS shell. */ +#include "jsstddef.h" #include #include #include diff --git a/mozilla/js/ref/jsapi.c b/mozilla/js/ref/jsapi.c index 29c93f0333e..82de69353d2 100644 --- a/mozilla/js/ref/jsapi.c +++ b/mozilla/js/ref/jsapi.c @@ -19,6 +19,7 @@ /* * JavaScript API. */ +#include "jsstddef.h" #include #include #include @@ -935,7 +936,10 @@ JS_InitClass(JSContext *cx, JSObject *obj, JSObject *parent_proto, /* Bootstrap Function.prototype (see also JS_InitStandardClasses). */ if (OBJ_GET_CLASS(cx, ctor) == clasp) { - PR_ASSERT(!OBJ_GET_PROTO(cx, ctor)); + /* XXXMLM - this fails in framesets that are writing over + * themselves! + * PR_ASSERT(!OBJ_GET_PROTO(cx, ctor)); + */ OBJ_SET_PROTO(cx, ctor, proto); } } @@ -1720,7 +1724,7 @@ JS_Enumerate(JSContext *cx, JSObject *obj) goto error; /* No more jsid's to enumerate ? */ - if (!iter_state) + if (iter_state == JSVAL_NULL) break; vector[i++] = id; } diff --git a/mozilla/js/ref/jsarray.c b/mozilla/js/ref/jsarray.c index 66ff1d9bab7..892662f9cd8 100644 --- a/mozilla/js/ref/jsarray.c +++ b/mozilla/js/ref/jsarray.c @@ -19,6 +19,7 @@ /* * JS array class. */ +#include "jsstddef.h" #include #include #include "prtypes.h" @@ -69,6 +70,7 @@ static JSBool ValueIsLength(JSContext *cx, jsval v, jsuint *lengthp) { jsint i; + JSBool res = JS_FALSE; /* It's only an array length if it's an int or a double. Some relevant * ECMA language is 15.4.2.2 - 'If the argument len is a number, then the @@ -79,18 +81,18 @@ ValueIsLength(JSContext *cx, jsval v, jsuint *lengthp) if (JSVAL_IS_INT(v)) { i = JSVAL_TO_INT(v); /* jsuint cast does ToUint32 */ - *lengthp = (jsuint)i; - return JS_TRUE; + if (lengthp) + *lengthp = (jsuint) i; + res = JS_TRUE; } else if (JSVAL_IS_DOUBLE(v)) { /* XXXmccabe I'd love to add another check here, against * js_DoubleToInteger(d) != d), so that ValueIsLength matches * IdIsIndex, but it doesn't seem to follow from ECMA. * (seems to be appropriate for IdIsIndex, though). - */ - return js_ValueToECMAUint32(cx, v, (uint32 *)lengthp); - } else { - return JS_FALSE; + */ + res = js_ValueToECMAUint32(cx, v, (uint32 *)lengthp); } + return res; } @@ -102,7 +104,8 @@ ValueToIndex(JSContext *cx, jsval v, jsuint *lengthp) if (JSVAL_IS_INT(v)) { i = JSVAL_TO_INT(v); /* jsuint cast does ToUint32. */ - *lengthp = (jsuint)i; + if (lengthp) + *lengthp = (jsuint)i; return JS_TRUE; } return js_ValueToECMAUint32(cx, v, (uint32 *)lengthp); diff --git a/mozilla/js/ref/jsatom.c b/mozilla/js/ref/jsatom.c index 37123d8b572..410ac6871f8 100644 --- a/mozilla/js/ref/jsatom.c +++ b/mozilla/js/ref/jsatom.c @@ -19,7 +19,7 @@ /* * JS atom table. */ -#include +#include "jsstddef.h" #include #include #include "prtypes.h" diff --git a/mozilla/js/ref/jsbool.c b/mozilla/js/ref/jsbool.c index a6c6ea436a8..3546e0aa9b3 100644 --- a/mozilla/js/ref/jsbool.c +++ b/mozilla/js/ref/jsbool.c @@ -19,6 +19,7 @@ /* * JS boolean implementation. */ +#include "jsstddef.h" #include "prtypes.h" #include "prassert.h" #include "jsapi.h" diff --git a/mozilla/js/ref/jscntxt.c b/mozilla/js/ref/jscntxt.c index 5db637e70ef..6328f2ef0fa 100644 --- a/mozilla/js/ref/jscntxt.c +++ b/mozilla/js/ref/jscntxt.c @@ -19,6 +19,7 @@ /* * JS execution context. */ +#include "jsstddef.h" #include #include #include diff --git a/mozilla/js/ref/jsdate.c b/mozilla/js/ref/jsdate.c index e2b0973f3bb..3a704bb0c4e 100644 --- a/mozilla/js/ref/jsdate.c +++ b/mozilla/js/ref/jsdate.c @@ -19,6 +19,7 @@ /* * JS date methods. */ +#include "jsstddef.h" #include #include #include diff --git a/mozilla/js/ref/jsdbgapi.c b/mozilla/js/ref/jsdbgapi.c index 00e2830cc46..efe1dc57f42 100644 --- a/mozilla/js/ref/jsdbgapi.c +++ b/mozilla/js/ref/jsdbgapi.c @@ -19,6 +19,7 @@ /* * JS debugging API. */ +#include "jsstddef.h" #include #include "prtypes.h" #include "prassert.h" diff --git a/mozilla/js/ref/jsemit.c b/mozilla/js/ref/jsemit.c index f5563f53703..b341d6640ff 100644 --- a/mozilla/js/ref/jsemit.c +++ b/mozilla/js/ref/jsemit.c @@ -19,8 +19,10 @@ /* * JS bytecode generation. */ +#include "jsstddef.h" #include -#include + + #include #include "prtypes.h" #include "prarena.h" @@ -78,7 +80,7 @@ EmitCheck(JSContext *cx, JSCodeGenerator *cg, JSOp op, ptrdiff_t delta) if (op != JSOP_NOP) cg->lastCodeOffset = offset; if ((pruword)cg->next + delta >= (pruword)cg->limit) { - length = cg->limit - cg->base; + length = PTRDIFF(cg->limit, cg->base, jsbytecode); cgsize = length * sizeof(jsbytecode); PR_ARENA_GROW(cg->base, &cx->codePool, cgsize, CGINCR); if (!cg->base) { @@ -280,7 +282,7 @@ PatchGotos(JSContext *cx, JSCodeGenerator *cg, JSStmtInfo *stmt, while (pc > top) { PR_ASSERT(*pc == JSOP_GOTO); delta = GET_JUMP_OFFSET(pc); - jumpOffset = target - pc; + jumpOffset = PTRDIFF(target, pc, jsbytecode); CHECK_AND_SET_JUMP_OFFSET(cx, cg, pc, jumpOffset); pc -= delta; } diff --git a/mozilla/js/ref/jsemit.h b/mozilla/js/ref/jsemit.h index 0f020b514a2..12d08ced3a7 100644 --- a/mozilla/js/ref/jsemit.h +++ b/mozilla/js/ref/jsemit.h @@ -21,7 +21,8 @@ /* * JS bytecode generation. */ -#include + +#include "jsstddef.h" #include "prtypes.h" #include "jsatom.h" #include "jsopcode.h" @@ -100,7 +101,7 @@ struct JSCodeGenerator { }; #define CG_CODE(cg,offset) ((cg)->base + (offset)) -#define CG_OFFSET(cg) ((cg)->next - (cg)->base) +#define CG_OFFSET(cg) PTRDIFF((cg)->next, (cg)->base, jsbytecode) #define CG_RESET(cg) ((cg)->next = (cg)->base, \ ATOM_LIST_INIT(&(cg)->atomList), \ (cg)->lastCodeOffset = 0, \ diff --git a/mozilla/js/ref/jsfun.c b/mozilla/js/ref/jsfun.c index e71a241d6bb..4ad41665547 100644 --- a/mozilla/js/ref/jsfun.c +++ b/mozilla/js/ref/jsfun.c @@ -19,6 +19,7 @@ /* * JS function support. */ +#include "jsstddef.h" #include #include "prtypes.h" #include "prassert.h" diff --git a/mozilla/js/ref/jsgc.c b/mozilla/js/ref/jsgc.c index d4d8c03adba..c437212230c 100644 --- a/mozilla/js/ref/jsgc.c +++ b/mozilla/js/ref/jsgc.c @@ -26,6 +26,7 @@ * * XXX swizzle page to freelist for better locality of reference */ +#include "jsstddef.h" #include /* for free, called by PR_ARENA_DESTROY */ #include /* for memset, called by prarena.h macros if DEBUG */ #include "prtypes.h" diff --git a/mozilla/js/ref/jsinterp.c b/mozilla/js/ref/jsinterp.c index f6d65a371c4..8f96f17f916 100644 --- a/mozilla/js/ref/jsinterp.c +++ b/mozilla/js/ref/jsinterp.c @@ -19,6 +19,7 @@ /* * JavaScript bytecode interpreter. */ +#include "jsstddef.h" #include #include #include @@ -97,7 +98,7 @@ prop_iterator_finalize(JSContext *cx, JSObject *obj) /* Protect against stillborn iterators. */ iter_state = obj->slots[JSSLOT_ITR_STATE]; - if (iter_state) + if (iter_state != JSVAL_NULL) OBJ_ENUMERATE(cx, obj, JSENUMERATE_DESTROY, &iter_state, NULL); } @@ -386,6 +387,7 @@ js_SetLocalVariable(JSContext *cx, JSObject *obj, jsval id, jsval *vp) } } return JS_TRUE; + } /* @@ -438,29 +440,29 @@ js_Invoke(JSContext *cx, uintN argc, JSBool constructing) if (!ok) goto out2; if (!JSVAL_IS_FUNCTION(cx, v)) { - fun = NULL; + fun = NULL; + script = NULL; + minargs = nvars = 0; } else { funobj = JSVAL_TO_OBJECT(v); + fun = JS_GetPrivate(cx, funobj); + if (clasp != &js_ClosureClass) { + /* Make vp refer to funobj to keep it available as argv[-2]. */ + *vp = v; + goto have_fun; + } + + /* Closure invocation may need extra arg and local var slots. */ + script = fun->script; + minargs = fun->nargs + fun->extra; + nvars = fun->nvars; } /* Try a call or construct native object op, using fun as fallback. */ native = constructing ? ops->construct : ops->call; - if (!native) { - if (fun) - goto have_fun; + if (!native) goto bad; - } - - /* The callable may be a function with a script (e.g., a closure). */ - if (fun) { - script = fun->script; - minargs = fun->nargs + fun->extra; - nvars = fun->nvars; - } else { - script = NULL; - minargs = nvars = 0; - } } else { /* Get private data and set derived locals from it. */ fun = JS_GetPrivate(cx, funobj); @@ -833,13 +835,42 @@ ImportProperty(JSContext *cx, JSObject *obj, jsid id) ok = JS_FALSE; goto out; } + /* + * The Closure() constructor resets the closure object's parent to be + * the current scope chain. Set it to the object that the imported + * function is being defined in. + */ + OBJ_SET_PARENT(cx, closure, obj); value = OBJECT_TO_JSVAL(closure); } - ok = OBJ_DEFINE_PROPERTY(cx, target, id, value, NULL, NULL, - attrs & ~JSPROP_EXPORTED, - NULL); - if (!ok) - goto out; + + /* + * Handle the case of importing a property that refers to a local + * variable or formal parameter of a function activation. Those + * properties are accessed by opcodes using stack slot numbers + * generated by the compiler rather than runtime name-lookup. These + * local references, therefore, bypass the normal scope chain lookup. + * So, instead of defining a new property in the activation object, + * modify the existing value in the stack slot. + */ + if (OBJ_GET_CLASS(cx, target) == &js_CallClass) { + ok = OBJ_LOOKUP_PROPERTY(cx, target, id, &obj2, &prop); + if (!ok) + goto out; + } else { + prop = NULL; + } + if (prop && (target == obj2)) { + ok = OBJ_SET_PROPERTY(cx, target, id, &value); + } else { + ok = OBJ_DEFINE_PROPERTY(cx, target, id, value, NULL, NULL, + attrs & ~JSPROP_EXPORTED, + NULL); + } + if (prop) + OBJ_DROP_PROPERTY(cx, obj2, prop); + if (!ok) + goto out; } while (ida && ++i < ida->length); out: @@ -1205,6 +1236,7 @@ js_Interpret(JSContext *cx, jsval *result) *vp = OBJECT_TO_JSVAL(propobj); ok = OBJ_ENUMERATE(cx, obj, JSENUMERATE_INIT, &iter_state, 0); + propobj->slots[JSSLOT_ITR_STATE] = iter_state; if (!ok) goto out; @@ -1214,7 +1246,6 @@ js_Interpret(JSContext *cx, jsval *result) */ PR_ASSERT(JS_INITIAL_NSLOTS >= 5); propobj->slots[JSSLOT_PARENT] = OBJECT_TO_JSVAL(obj); - propobj->slots[JSSLOT_ITR_STATE] = iter_state; } else { /* This is not the first iteration. Recover iterator state. */ @@ -1227,10 +1258,10 @@ js_Interpret(JSContext *cx, jsval *result) /* Get the next jsid to be enumerated and store it in rval */ OBJ_ENUMERATE(cx, obj, JSENUMERATE_NEXT, &iter_state, &rval); - propobj->slots[JSSLOT_ITR_STATE] = PRIVATE_TO_JSVAL(iter_state); + propobj->slots[JSSLOT_ITR_STATE] = iter_state; /* No more jsids to iterate in obj ? */ - if (!iter_state) { + if (iter_state == JSVAL_NULL) { /* Enumerate the properties on obj's prototype chain */ obj = OBJ_GET_PROTO(cx, obj); @@ -1241,12 +1272,12 @@ js_Interpret(JSContext *cx, jsval *result) } ok = OBJ_ENUMERATE(cx, obj, JSENUMERATE_INIT, &iter_state, 0); + propobj->slots[JSSLOT_ITR_STATE] = iter_state; if (!ok) goto out; /* Stash private iteration state into iterator JSObject. */ propobj->slots[JSSLOT_PARENT] = OBJECT_TO_JSVAL(obj); - propobj->slots[JSSLOT_ITR_STATE] = iter_state; goto enum_next_property; } @@ -2505,7 +2536,7 @@ js_Interpret(JSContext *cx, jsval *result) PR_ASSERT(!fp->exceptPending); throw: tn = script->trynotes; - offset = pc - script->code; + offset = PTRDIFF(pc, script->code, jsbytecode); if (tn) { for (; tn->start && tn->end && (tn->start > offset || tn->end < offset); diff --git a/mozilla/js/ref/jslock.c b/mozilla/js/ref/jslock.c index 2251f811b90..dc83a8f20c9 100644 --- a/mozilla/js/ref/jslock.c +++ b/mozilla/js/ref/jslock.c @@ -21,6 +21,7 @@ /* * JS locking stubs. */ +#include "jsstddef.h" #include #include "jspubtd.h" #include "prthread.h" diff --git a/mozilla/js/ref/jsmath.c b/mozilla/js/ref/jsmath.c index cf2d54e12ea..40a76a9a49d 100644 --- a/mozilla/js/ref/jsmath.c +++ b/mozilla/js/ref/jsmath.c @@ -19,6 +19,7 @@ /* * JS math package. */ +#include "jsstddef.h" #include #include #include "prtypes.h" diff --git a/mozilla/js/ref/jsnum.c b/mozilla/js/ref/jsnum.c index 990a3282ecb..ddec4779c7f 100644 --- a/mozilla/js/ref/jsnum.c +++ b/mozilla/js/ref/jsnum.c @@ -19,6 +19,7 @@ /* * JS number type and wrapper class. */ +#include "jsstddef.h" #include #ifdef XP_PC #include diff --git a/mozilla/js/ref/jsobj.c b/mozilla/js/ref/jsobj.c index ceacd1d4163..493eb9664cf 100644 --- a/mozilla/js/ref/jsobj.c +++ b/mozilla/js/ref/jsobj.c @@ -19,6 +19,7 @@ /* * JS object implementation. */ +#include "jsstddef.h" #include #include #include "prtypes.h" @@ -238,7 +239,7 @@ js_EnterSharpObject(JSContext *cx, JSObject *obj, JSIdArray **idap, PRHashTable *table; JSIdArray *ida; prhashcode hash; - PRHashEntry *he; + PRHashEntry *he, **hep; jsatomid sharpid; char buf[20]; size_t len; @@ -266,9 +267,24 @@ js_EnterSharpObject(JSContext *cx, JSObject *obj, JSIdArray **idap, ida = NULL; } } else { - hash = js_hash_object(obj); - he = *PR_HashTableRawLookup(table, hash, obj); - PR_ASSERT(he); + hash = js_hash_object(obj); + hep = PR_HashTableRawLookup(table, hash, obj); + he = *hep; + + /* + * It's possible that the value of a property has changed from the + * first time the object's properties are traversed (when the property + * ids are entered into the hash table) to the second (when they are + * converted to strings), i.e. the getProperty() call is not + * idempotent. + */ + if (!he) { + he = PR_HashTableRawAdd(table, hep, hash, obj, (void *)0); + if (!he) + JS_ReportOutOfMemory(cx); + *sp = NULL; + goto out; + } } sharpid = (jsatomid) he->value; @@ -285,6 +301,7 @@ js_EnterSharpObject(JSContext *cx, JSObject *obj, JSIdArray **idap, } } +out: if ((sharpid & SHARP_BIT) == 0) { if (idap && !ida) { ida = JS_Enumerate(cx, obj); @@ -298,6 +315,7 @@ js_EnterSharpObject(JSContext *cx, JSObject *obj, JSIdArray **idap, } map->depth++; } + if (idap) *idap = ida; return he; @@ -1034,6 +1052,8 @@ FindConstructor(JSContext *cx, const char *name, jsval *vp) { JSAtom *atom; JSObject *obj, *tmp; + JSObject *pobj; + JSScopeProperty *sprop; atom = js_Atomize(cx, name, strlen(name), 0); if (!atom) @@ -1053,7 +1073,19 @@ FindConstructor(JSContext *cx, const char *name, jsval *vp) } } - return OBJ_GET_PROPERTY(cx, obj, (jsid)atom, vp); + if(!OBJ_LOOKUP_PROPERTY(cx, obj, (jsid)atom, &pobj, (JSProperty **) &sprop)) + { + return JS_FALSE; + } + if(!sprop) { + *vp = JSVAL_VOID; + return JS_TRUE; + } + + PR_ASSERT(OBJ_IS_NATIVE(pobj)); + *vp = OBJ_GET_SLOT(cx, pobj, sprop->slot); + OBJ_DROP_PROPERTY(cx, pobj, (JSProperty *)sprop); + return JS_TRUE; } JSObject * @@ -1934,6 +1966,25 @@ js_DefaultValue(JSContext *cx, JSObject *obj, JSType hint, jsval *vp) if (!JSVAL_IS_PRIMITIVE(v)) { if (!OBJ_GET_CLASS(cx, obj)->convert(cx, obj, hint, &v)) return JS_FALSE; + + /* + * JS1.2 never failed (except for malloc failure) to convert an + * object to a string. ECMA requires an error if both toString + * and valueOf fail to produce a primitive value. + */ + if (!JSVAL_IS_PRIMITIVE(v) && cx->version == JSVERSION_1_2) { + char *bytes = PR_smprintf("[object %s]", + OBJ_GET_CLASS(cx, obj)->name); + if (!bytes) + return JS_FALSE; + str = JS_NewString(cx, bytes, strlen(bytes)); + if (!str) { + free(bytes); + return JS_FALSE; + } + v = STRING_TO_JSVAL(str); + goto out; + } } break; @@ -1943,6 +1994,9 @@ js_DefaultValue(JSContext *cx, JSObject *obj, JSType hint, jsval *vp) if (!JSVAL_IS_PRIMITIVE(v)) { if (JS_TypeOfValue(cx, v) == hint) goto out; + /* Don't convert to string (source object literal) for JS1.2. */ + if (cx->version == JSVERSION_1_2 && hint == JSTYPE_BOOLEAN) + goto out; js_TryMethod(cx, obj, cx->runtime->atomState.toStringAtom, 0, NULL, &v); } @@ -2016,7 +2070,7 @@ js_Enumerate(JSContext *cx, JSObject *obj, JSIterateOp enum_op, case JSENUMERATE_INIT: if (!enumerate(cx, obj)) - return JS_FALSE; + goto init_error; length = 0; /* @@ -2033,7 +2087,7 @@ js_Enumerate(JSContext *cx, JSObject *obj, JSIterateOp enum_op, ida = js_NewIdArray(cx, length); if (!ida) { JS_UNLOCK_OBJ(cx, obj); - return JS_FALSE; + goto init_error; } i = 0; for (sprop = scope->props; sprop; sprop = sprop->next) { @@ -2047,7 +2101,7 @@ js_Enumerate(JSContext *cx, JSObject *obj, JSIterateOp enum_op, state = JS_malloc(cx, sizeof(JSNativeIteratorState)); if (!state) { JS_DestroyIdArray(cx, ida); - return JS_FALSE; + goto init_error; } state->ida = ida; state->next_index = 0; @@ -2069,6 +2123,7 @@ js_Enumerate(JSContext *cx, JSObject *obj, JSIterateOp enum_op, case JSENUMERATE_DESTROY: state = JSVAL_TO_PRIVATE(*statep); + JS_DestroyIdArray(cx, state->ida); JS_free(cx, state); *statep = JSVAL_NULL; return JS_TRUE; @@ -2077,6 +2132,10 @@ js_Enumerate(JSContext *cx, JSObject *obj, JSIterateOp enum_op, PR_ASSERT(0); return JS_FALSE; } + +init_error: + *statep = JSVAL_NULL; + return JS_FALSE; } JSBool diff --git a/mozilla/js/ref/jsopcode.c b/mozilla/js/ref/jsopcode.c index f37a628d900..4626b4a3ef7 100644 --- a/mozilla/js/ref/jsopcode.c +++ b/mozilla/js/ref/jsopcode.c @@ -19,6 +19,7 @@ /* * JS bytecode descriptors, disassemblers, and decompilers. */ +#include "jsstddef.h" #include #include #include @@ -334,7 +335,7 @@ QuoteString(Sprinter *sp, JSString *str, jschar quote) do { while (JS_ISPRINT(c) && c != quote && !(c >> 8)) c = *++t; - len = t - s; + len = PTRDIFF(t, s, jschar); /* Allocate space for s, including the '\0' at the end. */ nb = (sp->offset + len + 1) - sp->size; @@ -1071,7 +1072,7 @@ Decompile(SprintStack *ss, jsbytecode *pc, intN nb) rval = POP_STR(); todo = Sprint(&ss->sprinter, "%s || %s", lval, rval); JS_free(cx, (void *)lval); - len = done - pc; + len = PTRDIFF(done, pc, jsbytecode); } #endif /* JS_BUG_SHORT_CIRCUIT */ break; @@ -1110,7 +1111,7 @@ Decompile(SprintStack *ss, jsbytecode *pc, intN nb) rval = POP_STR(); todo = Sprint(&ss->sprinter, "%s && %s", lval, rval); JS_free(cx, (void *)lval); - len = done - pc; + len = PTRDIFF(done, pc, jsbytecode); } #endif /* JS_BUG_SHORT_CIRCUIT */ break; @@ -1123,7 +1124,7 @@ Decompile(SprintStack *ss, jsbytecode *pc, intN nb) return JS_FALSE; done = pc + GET_JUMP_OFFSET(pc); pc += len; - len = done - pc; + len = PTRDIFF(done, pc, jsbytecode); DECOMPILE_CODE(pc, len); rval = POP_STR(); todo = Sprint(&ss->sprinter, "%s || %s", lval, rval); @@ -1137,7 +1138,7 @@ Decompile(SprintStack *ss, jsbytecode *pc, intN nb) return JS_FALSE; done = pc + GET_JUMP_OFFSET(pc); pc += len; - len = done - pc; + len = PTRDIFF(done, pc, jsbytecode); DECOMPILE_CODE(pc, len); rval = POP_STR(); todo = Sprint(&ss->sprinter, "%s && %s", lval, rval); @@ -1974,7 +1975,7 @@ js_DecompileValueGenerator(JSContext *cx, jsval v, JSString *fallback) begin = pc - js_GetSrcNoteOffset(sn, 0); } end = pc + cs->length; - len = end - begin; + len =PTRDIFF(end, begin, jsbytecode); if (format & (JOF_SET | JOF_DEL | JOF_INCDEC | JOF_IMPORT)) { /* These formats require bytecode source extension. */ diff --git a/mozilla/js/ref/jsparse.c b/mozilla/js/ref/jsparse.c index 4d4c31ea948..53dffd62cab 100644 --- a/mozilla/js/ref/jsparse.c +++ b/mozilla/js/ref/jsparse.c @@ -31,6 +31,7 @@ * was designed with error recovery built on 64-bit first and follow bitsets * in mind, however. */ +#include "jsstddef.h" #include #include #include @@ -61,6 +62,7 @@ * Each parser takes a context and a token stream, and emits bytecode using * a code generator. */ + typedef JSParseNode * JSParser(JSContext *cx, JSTokenStream *ts, JSTreeContext *tc); @@ -569,9 +571,11 @@ Condition(JSContext *cx, JSTokenStream *ts, JSTreeContext *tc) * XXX not ECMA, but documented in several books -- need a compile option */ if (pn->pn_type == TOK_ASSIGN && pn->pn_op == JSOP_NOP) { +#ifdef CHECK_EQUALITY_ASSIGNMENT js_ReportCompileError(cx, ts, "test for equality (==) mistyped as assignment (=)?\n" "Assuming equality test"); +#endif pn->pn_type = TOK_EQOP; pn->pn_op = cx->jsop_eq; pn2 = pn->pn_left; diff --git a/mozilla/js/ref/jsregexp.c b/mozilla/js/ref/jsregexp.c index 1b411ebc1f8..6b6c770d5a3 100644 --- a/mozilla/js/ref/jsregexp.c +++ b/mozilla/js/ref/jsregexp.c @@ -19,6 +19,7 @@ /* * JS regular expressions, after Perl. */ +#include "jsstddef.h" #include #include #include "prtypes.h" @@ -1410,13 +1411,13 @@ OptimizeRegExp(CompilerState *state, RENode *ren) (REOP(next) == REOP_FLAT || REOP(next) == REOP_FLAT1)) { if (REOP(next) == REOP_FLAT) { cp2 = next->kid; - len2 = (jschar *)next->u.kid2 - cp2; + len2 = PTRDIFF((jschar *)next->u.kid2, cp2, jschar); } else { cp2 = &next->u.chr; len2 = 1; } cp = ren->kid; - len = (jschar *)ren->u.kid2 - cp; + len = PTRDIFF((jschar *)ren->u.kid2, cp, jschar); if (len + len2 > REOP_FLATLEN_MAX) break; cx = state->context; @@ -1464,7 +1465,7 @@ OptimizeRegExp(CompilerState *state, RENode *ren) (REOP(next) == REOP_FLAT || REOP(next) == REOP_FLAT1)) { if (REOP(next) == REOP_FLAT) { cp2 = next->kid; - len = (jschar *)next->u.kid2 - cp2; + len = PTRDIFF((jschar *)next->u.kid2, cp2, jschar); } else { cp2 = &next->u.chr; len = 1; @@ -1514,7 +1515,7 @@ OptimizeRegExp(CompilerState *state, RENode *ren) */ cp = ren->kid; cp2 = ren->u.kid2; - len = cp2 - cp; + len = PTRDIFF(cp2, cp, jschar); maxc = 0; while (cp < cp2) { c = *cp++; @@ -1568,7 +1569,7 @@ OptimizeRegExp(CompilerState *state, RENode *ren) */ cp = ren->kid; cp2 = ren->u.kid2; - len = cp2 - cp; + len = PTRDIFF(cp2, cp, jschar); while (cp < cp2) { c = *cp++; if (c >> 8) { @@ -2613,7 +2614,7 @@ js_ExecuteRegExp(JSContext *cx, JSRegExp *re, JSString *str, size_t *indexp, *rval = JSVAL_NULL; goto out; } - i = cp - state.cpbegin; + i = PTRDIFF(cp, state.cpbegin, jschar); *indexp = i; matchlen = i - (start + state.skipped); ep = cp; diff --git a/mozilla/js/ref/jsscan.c b/mozilla/js/ref/jsscan.c index 1c6ddef107b..04c9005a458 100644 --- a/mozilla/js/ref/jsscan.c +++ b/mozilla/js/ref/jsscan.c @@ -19,13 +19,14 @@ /* * JS lexical scanner. */ +#include "jsstddef.h" #include /* first to avoid trouble on some systems */ #include #include #include #include #include -#include + #include #include #include "prtypes.h" @@ -282,12 +283,12 @@ GetChar(JSTokenStream *ts) int32 c; ptrdiff_t len, olen; jschar *nl; - + if (ts->ungetpos != 0) { c = ts->ungetbuf[--ts->ungetpos]; } else { - if (ts->linebuf.ptr == ts->linebuf.limit) { - len = ts->userbuf.limit - ts->userbuf.ptr; + if (ts->linebuf.ptr == ts->linebuf.limit) { + len = PTRDIFF(ts->userbuf.limit, ts->userbuf.ptr, jschar); if (len <= 0) { #ifdef JSFILE /* Fill ts->userbuf so that \r and \r\n convert to \n. */ @@ -349,7 +350,7 @@ GetChar(JSTokenStream *ts) * Else copy JS_LINE_LIMIT-1 bytes into linebuf. */ if (nl < ts->userbuf.limit) - len = nl - ts->userbuf.ptr + 1; + len = PTRDIFF(nl, ts->userbuf.ptr, jschar) + 1; if (len >= JS_LINE_LIMIT) len = JS_LINE_LIMIT - 1; js_strncpy(ts->linebuf.base, ts->userbuf.ptr, len); @@ -564,8 +565,8 @@ GrowTokenBuf(JSContext *cx, JSTokenBuf *tb) PRArenaPool *pool; base = tb->base; - offset = tb->ptr - base; - length = tb->limit - base; + offset = PTRDIFF(tb->ptr, base, jschar); + length = PTRDIFF(tb->limit, base, jschar); tbincr = TBINCR * sizeof(jschar); pool = &cx->tempPool; if (!base) { diff --git a/mozilla/js/ref/jsscope.c b/mozilla/js/ref/jsscope.c index 22c55850afd..382d28bb854 100644 --- a/mozilla/js/ref/jsscope.c +++ b/mozilla/js/ref/jsscope.c @@ -19,6 +19,7 @@ /* * JS symbol tables. */ +#include "jsstddef.h" #include #include "prtypes.h" #include "prassert.h" diff --git a/mozilla/js/ref/jsscript.c b/mozilla/js/ref/jsscript.c index 74282821724..fcb07a5c064 100644 --- a/mozilla/js/ref/jsscript.c +++ b/mozilla/js/ref/jsscript.c @@ -19,6 +19,7 @@ /* * JS script operations. */ +#include "jsstddef.h" #include #include "prtypes.h" #include "prassert.h" @@ -695,7 +696,7 @@ js_GetSrcNote(JSScript *script, jsbytecode *pc) sn = script->notes; if (!sn) return NULL; - target = pc - script->code; + target = PTRDIFF(pc, script->code, jsbytecode); if ((uintN)target >= script->length) return NULL; for (offset = 0; !SN_IS_TERMINATOR(sn); sn = SN_NEXT(sn)) { @@ -717,7 +718,7 @@ js_PCToLineNumber(JSScript *script, jsbytecode *pc) sn = script->notes; if (!sn) return 0; - target = pc - script->code; + target = PTRDIFF(pc, script->code, jsbytecode); lineno = script->lineno; for (offset = 0; !SN_IS_TERMINATOR(sn); sn = SN_NEXT(sn)) { offset += SN_DELTA(sn); diff --git a/mozilla/js/ref/jsstddef.h b/mozilla/js/ref/jsstddef.h new file mode 100644 index 00000000000..698ba9353b9 --- /dev/null +++ b/mozilla/js/ref/jsstddef.h @@ -0,0 +1,41 @@ +/*stddef inclusion here to first declare ptrdif as a signed long instead of a signed int*/ + +#ifdef _WINDOWS +# ifndef XP_WIN +# define XP_WIN +# endif +#if defined(_WIN32) || defined(WIN32) +# ifndef XP_WIN32 +# define XP_WIN32 +# endif +#else +# ifndef XP_WIN16 +# define XP_WIN16 +# endif +#endif +#endif + +#ifdef XP_WIN16 +#ifndef _PTRDIFF_T_DEFINED +typedef long ptrdiff_t; + +/* + * The Win16 compiler treats pointer differences as 16-bit signed values. + * This macro allows us to treat them as 17-bit signed values, stored in + * a 32-bit type. + */ +#define PTRDIFF(p1, p2, type) \ + ((((unsigned long)(p1)) - ((unsigned long)(p2))) / sizeof(type)) + +#define _PTRDIFF_T_DEFINED +#endif /*_PTRDIFF_T_DEFINED*/ +#else /*WIN16*/ + +#define PTRDIFF(p1, p2, type) \ + ((p1) - (p2)) + +#endif + +#include + + diff --git a/mozilla/js/ref/jsstr.c b/mozilla/js/ref/jsstr.c index 0544fa25480..50cf3d1bac4 100644 --- a/mozilla/js/ref/jsstr.c +++ b/mozilla/js/ref/jsstr.c @@ -26,6 +26,7 @@ * of rooting things that might lose their newborn root due to subsequent GC * allocations in the same native method. */ +#include "jsstddef.h" #include #include #include "prtypes.h" @@ -2257,7 +2258,7 @@ js_InflateString(JSContext *cx, const char *bytes, size_t length) if (!chars) return NULL; for (i = 0; i < length; i++) - chars[i] = (jschar) bytes[i]; + chars[i] = (jschar) (unsigned char) bytes[i]; chars[i] = 0; return chars; } diff --git a/mozilla/js/ref/jsxdrapi.c b/mozilla/js/ref/jsxdrapi.c index 3d2f6ad1cef..7fe319fa01a 100644 --- a/mozilla/js/ref/jsxdrapi.c +++ b/mozilla/js/ref/jsxdrapi.c @@ -15,6 +15,7 @@ * Copyright (C) 1998 Netscape Communications Corporation. All Rights * Reserved. */ +#include "jsstddef.h" #include #include "prtypes.h" @@ -191,7 +192,7 @@ static JSXDROps xdrmem_ops = { mem_raw, mem_seek, mem_tell, mem_finalize }; -void +JS_PUBLIC_API(void) JS_XDRNewBase(JSContext *cx, JSXDRState *xdr, JSXDRMode mode) { xdr->cx = cx; @@ -200,7 +201,7 @@ JS_XDRNewBase(JSContext *cx, JSXDRState *xdr, JSXDRMode mode) xdr->nclasses = 0; } -JSXDRState * +JS_PUBLIC_API(JSXDRState *) JS_XDRNewMem(JSContext *cx, JSXDRMode mode) { JSXDRState *xdr = JS_malloc(cx, sizeof(JSXDRMemState)); @@ -222,7 +223,7 @@ JS_XDRNewMem(JSContext *cx, JSXDRMode mode) return xdr; } -void * +JS_PUBLIC_API(void *) JS_XDRMemGetData(JSXDRState *xdr, uint32 *lp) { if (xdr->ops != &xdrmem_ops) @@ -231,7 +232,7 @@ JS_XDRMemGetData(JSXDRState *xdr, uint32 *lp) return xdr->data; } -void +JS_PUBLIC_API(void) JS_XDRMemSetData(JSXDRState *xdr, void *data, uint32 len) { if (xdr->ops != &xdrmem_ops) @@ -241,7 +242,7 @@ JS_XDRMemSetData(JSXDRState *xdr, void *data, uint32 len) MEM_PRIV(xdr)->count = 0; } -JSBool +JS_PUBLIC_API(JSBool) JS_XDRUint8(JSXDRState *xdr, uint8 *b) { uint32 l = *b; @@ -251,7 +252,7 @@ JS_XDRUint8(JSXDRState *xdr, uint8 *b) return JS_TRUE; } -JSBool +JS_PUBLIC_API(JSBool) JS_XDRUint16(JSXDRState *xdr, uint16 *s) { uint32 l = *s; @@ -261,7 +262,7 @@ JS_XDRUint16(JSXDRState *xdr, uint16 *s) return JS_TRUE; } -JSBool +JS_PUBLIC_API(JSBool) JS_XDRUint32(JSXDRState *xdr, uint32 *lp) { JSBool ok; @@ -275,7 +276,7 @@ JS_XDRUint32(JSXDRState *xdr, uint32 *lp) return ok; } -JSBool +JS_PUBLIC_API(JSBool) JS_XDRBytes(JSXDRState *xdr, char **bytesp, uint32 len) { if (xdr->mode == JSXDR_ENCODE) { @@ -300,7 +301,7 @@ JS_XDRBytes(JSXDRState *xdr, char **bytesp, uint32 len) * leading 32-bit count, then counted vector of chars, * then possibly \0 padding to multiple of 4. */ -JSBool +JS_PUBLIC_API(JSBool) JS_XDRCString(JSXDRState *xdr, char **sp) { uint32 len; @@ -326,7 +327,7 @@ JS_XDRCString(JSXDRState *xdr, char **sp) return JS_TRUE; } -JSBool +JS_PUBLIC_API(JSBool) JS_XDRCStringOrNull(JSXDRState *xdr, char **sp) { uint32 null = (*sp == NULL); @@ -342,7 +343,7 @@ JS_XDRCStringOrNull(JSXDRState *xdr, char **sp) /* * Convert between a JS (Unicode) string and the XDR representation. */ -JSBool +JS_PUBLIC_API(JSBool) JS_XDRString(JSXDRState *xdr, JSString **strp) { uint32 i, len, nbytes; @@ -382,7 +383,7 @@ bad: return JS_FALSE; } -JSBool +JS_PUBLIC_API(JSBool) JS_XDRStringOrNull(JSXDRState *xdr, JSString **strp) { uint32 null = (*strp == NULL); @@ -395,7 +396,7 @@ JS_XDRStringOrNull(JSXDRState *xdr, JSString **strp) return JS_XDRString(xdr, strp); } -JSBool +JS_PUBLIC_API(JSBool) JS_XDRDouble(JSXDRState *xdr, jsdouble **dp) { jsdouble d; @@ -417,7 +418,7 @@ JS_XDRDouble(JSXDRState *xdr, jsdouble **dp) return JS_TRUE; } -JSBool +JS_PUBLIC_API(JSBool) JS_XDRValue(JSXDRState *xdr, jsval *vp) { uint32 type = JSVAL_TAG(*vp); @@ -475,7 +476,7 @@ JS_XDRValue(JSXDRState *xdr, jsval *vp) } -void +JS_PUBLIC_API(void) JS_XDRDestroy(JSXDRState *xdr) { JSContext *cx = xdr->cx; @@ -487,7 +488,7 @@ JS_XDRDestroy(JSXDRState *xdr) #define REGISTRY_CHUNK 4 -JSBool +JS_PUBLIC_API(JSBool) JS_RegisterClass(JSXDRState *xdr, JSClass *clasp, uint32 *idp) { uintN nclasses; @@ -510,7 +511,7 @@ JS_RegisterClass(JSXDRState *xdr, JSClass *clasp, uint32 *idp) return JS_TRUE; } -uint32 +JS_PUBLIC_API(uint32) JS_FindClassIdByName(JSXDRState *xdr, const char *name) { uintN i; @@ -522,7 +523,7 @@ JS_FindClassIdByName(JSXDRState *xdr, const char *name) return 0; } -JSClass * +JS_PUBLIC_API(JSClass *) JS_FindClassById(JSXDRState *xdr, uint32 id) { if (id > xdr->nclasses) diff --git a/mozilla/js/ref/prarena.c b/mozilla/js/ref/prarena.c index d2228f48f01..1b2fe0fa251 100644 --- a/mozilla/js/ref/prarena.c +++ b/mozilla/js/ref/prarena.c @@ -21,6 +21,7 @@ * "Fast Allocation and Deallocation of Memory Based on Object Lifetimes" * David R. Hanson, Software -- Practice and Experience, Vol. 20(1). */ +#include "jsstddef.h" #include #include #include "prtypes.h" diff --git a/mozilla/js/ref/prdtoa.c b/mozilla/js/ref/prdtoa.c index df8288895aa..d967f266cdf 100644 --- a/mozilla/js/ref/prdtoa.c +++ b/mozilla/js/ref/prdtoa.c @@ -19,6 +19,7 @@ /* * Portable double to alphanumeric string and back converters. */ +#include "jsstddef.h" #include "prtypes.h" #include "prdtoa.h" #include "prprintf.h"