Merge several bug fixes from client 4.1 branch

This commit is contained in:
fur 1998-06-01 00:31:59 +00:00
Родитель c78e8a48c2
Коммит e8261717d2
28 изменённых файлов: 252 добавлений и 2694 удалений

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

@ -19,6 +19,7 @@
/*
* JS shell.
*/
#include "jsstddef.h"
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>

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

@ -19,6 +19,7 @@
/*
* JavaScript API.
*/
#include "jsstddef.h"
#include <ctype.h>
#include <stdarg.h>
#include <stdlib.h>
@ -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;
}

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

@ -19,6 +19,7 @@
/*
* JS array class.
*/
#include "jsstddef.h"
#include <stdlib.h>
#include <string.h>
#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);

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

@ -19,7 +19,7 @@
/*
* JS atom table.
*/
#include <stddef.h>
#include "jsstddef.h"
#include <stdlib.h>
#include <string.h>
#include "prtypes.h"

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

@ -19,6 +19,7 @@
/*
* JS boolean implementation.
*/
#include "jsstddef.h"
#include "prtypes.h"
#include "prassert.h"
#include "jsapi.h"

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

@ -19,6 +19,7 @@
/*
* JS execution context.
*/
#include "jsstddef.h"
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>

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

@ -19,6 +19,7 @@
/*
* JS date methods.
*/
#include "jsstddef.h"
#include <math.h>
#include <stdlib.h>
#include <string.h>

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

@ -19,6 +19,7 @@
/*
* JS debugging API.
*/
#include "jsstddef.h"
#include <string.h>
#include "prtypes.h"
#include "prassert.h"

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

@ -19,8 +19,10 @@
/*
* JS bytecode generation.
*/
#include "jsstddef.h"
#include <memory.h>
#include <stddef.h>
#include <string.h>
#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;
}

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

@ -21,7 +21,8 @@
/*
* JS bytecode generation.
*/
#include <stddef.h>
#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, \

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

@ -19,6 +19,7 @@
/*
* JS function support.
*/
#include "jsstddef.h"
#include <string.h>
#include "prtypes.h"
#include "prassert.h"

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

@ -26,6 +26,7 @@
*
* XXX swizzle page to freelist for better locality of reference
*/
#include "jsstddef.h"
#include <stdlib.h> /* for free, called by PR_ARENA_DESTROY */
#include <string.h> /* for memset, called by prarena.h macros if DEBUG */
#include "prtypes.h"

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

@ -19,6 +19,7 @@
/*
* JavaScript bytecode interpreter.
*/
#include "jsstddef.h"
#include <stdio.h>
#include <string.h>
#include <math.h>
@ -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);

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

@ -21,6 +21,7 @@
/*
* JS locking stubs.
*/
#include "jsstddef.h"
#include <stdlib.h>
#include "jspubtd.h"
#include "prthread.h"

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

@ -19,6 +19,7 @@
/*
* JS math package.
*/
#include "jsstddef.h"
#include <math.h>
#include <stdlib.h>
#include "prtypes.h"

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

@ -19,6 +19,7 @@
/*
* JS number type and wrapper class.
*/
#include "jsstddef.h"
#include <errno.h>
#ifdef XP_PC
#include <float.h>

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

@ -19,6 +19,7 @@
/*
* JS object implementation.
*/
#include "jsstddef.h"
#include <stdlib.h>
#include <string.h>
#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

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

@ -19,6 +19,7 @@
/*
* JS bytecode descriptors, disassemblers, and decompilers.
*/
#include "jsstddef.h"
#include <memory.h>
#include <stdarg.h>
#include <stdio.h>
@ -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. */

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

@ -31,6 +31,7 @@
* was designed with error recovery built on 64-bit first and follow bitsets
* in mind, however.
*/
#include "jsstddef.h"
#include <stdlib.h>
#include <string.h>
#include <math.h>
@ -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;

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

@ -19,6 +19,7 @@
/*
* JS regular expressions, after Perl.
*/
#include "jsstddef.h"
#include <stdlib.h>
#include <string.h>
#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;

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

@ -19,13 +19,14 @@
/*
* JS lexical scanner.
*/
#include "jsstddef.h"
#include <stdio.h> /* first to avoid trouble on some systems */
#include <errno.h>
#include <limits.h>
#include <math.h>
#include <memory.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#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) {

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

@ -19,6 +19,7 @@
/*
* JS symbol tables.
*/
#include "jsstddef.h"
#include <string.h>
#include "prtypes.h"
#include "prassert.h"

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

@ -19,6 +19,7 @@
/*
* JS script operations.
*/
#include "jsstddef.h"
#include <string.h>
#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);

41
js/ref/jsstddef.h Normal file
Просмотреть файл

@ -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 <stddef.h>

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

@ -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 <stdlib.h>
#include <string.h>
#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;
}

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

@ -15,6 +15,7 @@
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "jsstddef.h"
#include <string.h>
#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)

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

@ -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 <stdlib.h>
#include <string.h>
#include "prtypes.h"

Разница между файлами не показана из-за своего большого размера Загрузить разницу