From c8a3e25062ab1413ec319602140a0233ae69e971 Mon Sep 17 00:00:00 2001 From: "shaver%mozilla.org" Date: Wed, 4 Apr 2001 04:30:41 +0000 Subject: [PATCH] 73645: use JSDHashTable for JSRuntime.gcRootsHash and .gcLocksHash. r=waterson-the-dhash-fiend, sr=brendan-the-other-dhash-fiend --- js/src/jsapi.c | 1329 +++++++++++++++++++++++----------------------- js/src/jsapi.h | 2 +- js/src/jscntxt.h | 4 +- js/src/jsgc.c | 151 +++--- js/src/jsgc.h | 13 + js/src/jsprvtd.h | 2 + 6 files changed, 757 insertions(+), 744 deletions(-) diff --git a/js/src/jsapi.c b/js/src/jsapi.c index d8bf32d95eb..4f9a98c2a96 100644 --- a/js/src/jsapi.c +++ b/js/src/jsapi.c @@ -81,9 +81,9 @@ #endif #if defined(JS_PARANOID_REQUEST) && defined(JS_THREADSAFE) -#define CHECK_REQUEST(cx) JS_ASSERT(cx->requestDepth) +#define CHECK_REQUEST(cx) JS_ASSERT(cx->requestDepth) #else -#define CHECK_REQUEST(cx) ((void)0) +#define CHECK_REQUEST(cx) ((void)0) #endif JS_PUBLIC_API(jsval) @@ -112,17 +112,17 @@ JS_GetEmptyStringValue(JSContext *cx) static JSBool TryArgumentFormatter(JSContext *cx, const char **formatp, JSBool fromJS, - jsval **vpp, va_list *app) + jsval **vpp, va_list *app) { const char *format; JSArgumentFormatMap *map; format = *formatp; for (map = cx->argumentFormatMap; map; map = map->next) { - if (!strncmp(format, map->format, map->length)) { - *formatp = format + map->length; - return map->formatter(cx, format, fromJS, vpp, app); - } + if (!strncmp(format, map->format, map->length)) { + *formatp = format + map->length; + return map->formatter(cx, format, fromJS, vpp, app); + } } JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_BAD_CHAR, format); return JS_FALSE; @@ -130,7 +130,7 @@ TryArgumentFormatter(JSContext *cx, const char **formatp, JSBool fromJS, JS_PUBLIC_API(JSBool) JS_ConvertArguments(JSContext *cx, uintN argc, jsval *argv, const char *format, - ...) + ...) { va_list ap; JSBool ok; @@ -143,7 +143,7 @@ JS_ConvertArguments(JSContext *cx, uintN argc, jsval *argv, const char *format, JS_PUBLIC_API(JSBool) JS_ConvertArgumentsVA(JSContext *cx, uintN argc, jsval *argv, - const char *format, va_list ap) + const char *format, va_list ap) { jsval *sp; JSBool required; @@ -157,99 +157,99 @@ JS_ConvertArgumentsVA(JSContext *cx, uintN argc, jsval *argv, sp = argv; required = JS_TRUE; while ((c = *format++) != '\0') { - if (isspace(c)) - continue; - if (c == '/') { - required = JS_FALSE; - continue; - } - if (sp == argv + argc) { - if (required) { - fun = js_ValueToFunction(cx, &argv[-2], JS_FALSE); - if (fun) { - char numBuf[12]; - JS_snprintf(numBuf, sizeof numBuf, "%u", argc); - JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, - JSMSG_MORE_ARGS_NEEDED, - JS_GetFunctionName(fun), numBuf, - (argc == 1) ? "" : "s"); - } - return JS_FALSE; - } - break; - } - switch (c) { - case 'b': - if (!js_ValueToBoolean(cx, *sp, va_arg(ap, JSBool *))) - return JS_FALSE; - break; - case 'c': - if (!js_ValueToUint16(cx, *sp, va_arg(ap, uint16 *))) - return JS_FALSE; - break; - case 'i': - if (!js_ValueToECMAInt32(cx, *sp, va_arg(ap, int32 *))) - return JS_FALSE; - break; - case 'u': - if (!js_ValueToECMAUint32(cx, *sp, va_arg(ap, uint32 *))) - return JS_FALSE; - break; - case 'j': - if (!js_ValueToInt32(cx, *sp, va_arg(ap, int32 *))) - return JS_FALSE; - break; - case 'd': - if (!js_ValueToNumber(cx, *sp, va_arg(ap, jsdouble *))) - return JS_FALSE; - break; - case 'I': - if (!js_ValueToNumber(cx, *sp, &d)) - return JS_FALSE; - *va_arg(ap, jsdouble *) = js_DoubleToInteger(d); - break; - case 's': - case 'S': - case 'W': - str = js_ValueToString(cx, *sp); - if (!str) - return JS_FALSE; - *sp = STRING_TO_JSVAL(str); - if (c == 's') - *va_arg(ap, char **) = JS_GetStringBytes(str); - else if (c == 'W') - *va_arg(ap, jschar **) = str->chars; - else - *va_arg(ap, JSString **) = str; - break; - case 'o': - if (!js_ValueToObject(cx, *sp, &obj)) - return JS_FALSE; - *sp = OBJECT_TO_JSVAL(obj); - *va_arg(ap, JSObject **) = obj; - break; - case 'f': - fun = js_ValueToFunction(cx, sp, JS_FALSE); - if (!fun) - return JS_FALSE; - *sp = OBJECT_TO_JSVAL(fun->object); - *va_arg(ap, JSFunction **) = fun; - break; - case 'v': - *va_arg(ap, jsval *) = *sp; - break; - case '*': - break; - default: - format--; - if (!TryArgumentFormatter(cx, &format, JS_TRUE, &sp, - JS_ADDRESSOF_VA_LIST(ap))) { - return JS_FALSE; + if (isspace(c)) + continue; + if (c == '/') { + required = JS_FALSE; + continue; + } + if (sp == argv + argc) { + if (required) { + fun = js_ValueToFunction(cx, &argv[-2], JS_FALSE); + if (fun) { + char numBuf[12]; + JS_snprintf(numBuf, sizeof numBuf, "%u", argc); + JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, + JSMSG_MORE_ARGS_NEEDED, + JS_GetFunctionName(fun), numBuf, + (argc == 1) ? "" : "s"); + } + return JS_FALSE; } - /* NB: the formatter already updated sp, so we continue here. */ - continue; - } - sp++; + break; + } + switch (c) { + case 'b': + if (!js_ValueToBoolean(cx, *sp, va_arg(ap, JSBool *))) + return JS_FALSE; + break; + case 'c': + if (!js_ValueToUint16(cx, *sp, va_arg(ap, uint16 *))) + return JS_FALSE; + break; + case 'i': + if (!js_ValueToECMAInt32(cx, *sp, va_arg(ap, int32 *))) + return JS_FALSE; + break; + case 'u': + if (!js_ValueToECMAUint32(cx, *sp, va_arg(ap, uint32 *))) + return JS_FALSE; + break; + case 'j': + if (!js_ValueToInt32(cx, *sp, va_arg(ap, int32 *))) + return JS_FALSE; + break; + case 'd': + if (!js_ValueToNumber(cx, *sp, va_arg(ap, jsdouble *))) + return JS_FALSE; + break; + case 'I': + if (!js_ValueToNumber(cx, *sp, &d)) + return JS_FALSE; + *va_arg(ap, jsdouble *) = js_DoubleToInteger(d); + break; + case 's': + case 'S': + case 'W': + str = js_ValueToString(cx, *sp); + if (!str) + return JS_FALSE; + *sp = STRING_TO_JSVAL(str); + if (c == 's') + *va_arg(ap, char **) = JS_GetStringBytes(str); + else if (c == 'W') + *va_arg(ap, jschar **) = str->chars; + else + *va_arg(ap, JSString **) = str; + break; + case 'o': + if (!js_ValueToObject(cx, *sp, &obj)) + return JS_FALSE; + *sp = OBJECT_TO_JSVAL(obj); + *va_arg(ap, JSObject **) = obj; + break; + case 'f': + fun = js_ValueToFunction(cx, sp, JS_FALSE); + if (!fun) + return JS_FALSE; + *sp = OBJECT_TO_JSVAL(fun->object); + *va_arg(ap, JSFunction **) = fun; + break; + case 'v': + *va_arg(ap, jsval *) = *sp; + break; + case '*': + break; + default: + format--; + if (!TryArgumentFormatter(cx, &format, JS_TRUE, &sp, + JS_ADDRESSOF_VA_LIST(ap))) { + return JS_FALSE; + } + /* NB: the formatter already updated sp, so we continue here. */ + continue; + } + sp++; } return JS_TRUE; } @@ -281,78 +281,78 @@ JS_PushArgumentsVA(JSContext *cx, void **markp, const char *format, va_list ap) *markp = NULL; argc = 0; for (cp = format; (c = *cp) != '\0'; cp++) { - /* - * Count non-space non-star characters as individual jsval arguments. - * This may over-allocate stack, but we'll fix below. - */ - if (isspace(c) || c == '*') - continue; - argc++; + /* + * Count non-space non-star characters as individual jsval arguments. + * This may over-allocate stack, but we'll fix below. + */ + if (isspace(c) || c == '*') + continue; + argc++; } sp = js_AllocStack(cx, argc, markp); if (!sp) - return NULL; + return NULL; argv = sp; while ((c = *format++) != '\0') { - if (isspace(c) || c == '*') - continue; - switch (c) { - case 'b': - *sp = BOOLEAN_TO_JSVAL((JSBool) va_arg(ap, int)); - break; - case 'c': - *sp = INT_TO_JSVAL((uint16) va_arg(ap, unsigned int)); - break; - case 'i': - case 'j': - if (!js_NewNumberValue(cx, (jsdouble) va_arg(ap, int32), sp)) - goto bad; - break; - case 'u': - if (!js_NewNumberValue(cx, (jsdouble) va_arg(ap, uint32), sp)) - goto bad; - break; - case 'd': - case 'I': - if (!js_NewDoubleValue(cx, va_arg(ap, jsdouble), sp)) - goto bad; - break; - case 's': - str = JS_NewStringCopyZ(cx, va_arg(ap, char *)); - if (!str) - goto bad; - *sp = STRING_TO_JSVAL(str); - break; - case 'W': - str = JS_NewUCStringCopyZ(cx, va_arg(ap, jschar *)); - if (!str) - goto bad; - *sp = STRING_TO_JSVAL(str); - break; - case 'S': - str = va_arg(ap, JSString *); - *sp = STRING_TO_JSVAL(str); - break; - case 'o': - *sp = OBJECT_TO_JSVAL(va_arg(ap, JSObject *)); - break; - case 'f': - fun = va_arg(ap, JSFunction *); - *sp = fun ? OBJECT_TO_JSVAL(fun->object) : JSVAL_NULL; - break; - case 'v': - *sp = va_arg(ap, jsval); - break; - default: - format--; - if (!TryArgumentFormatter(cx, &format, JS_FALSE, &sp, + if (isspace(c) || c == '*') + continue; + switch (c) { + case 'b': + *sp = BOOLEAN_TO_JSVAL((JSBool) va_arg(ap, int)); + break; + case 'c': + *sp = INT_TO_JSVAL((uint16) va_arg(ap, unsigned int)); + break; + case 'i': + case 'j': + if (!js_NewNumberValue(cx, (jsdouble) va_arg(ap, int32), sp)) + goto bad; + break; + case 'u': + if (!js_NewNumberValue(cx, (jsdouble) va_arg(ap, uint32), sp)) + goto bad; + break; + case 'd': + case 'I': + if (!js_NewDoubleValue(cx, va_arg(ap, jsdouble), sp)) + goto bad; + break; + case 's': + str = JS_NewStringCopyZ(cx, va_arg(ap, char *)); + if (!str) + goto bad; + *sp = STRING_TO_JSVAL(str); + break; + case 'W': + str = JS_NewUCStringCopyZ(cx, va_arg(ap, jschar *)); + if (!str) + goto bad; + *sp = STRING_TO_JSVAL(str); + break; + case 'S': + str = va_arg(ap, JSString *); + *sp = STRING_TO_JSVAL(str); + break; + case 'o': + *sp = OBJECT_TO_JSVAL(va_arg(ap, JSObject *)); + break; + case 'f': + fun = va_arg(ap, JSFunction *); + *sp = fun ? OBJECT_TO_JSVAL(fun->object) : JSVAL_NULL; + break; + case 'v': + *sp = va_arg(ap, jsval); + break; + default: + format--; + if (!TryArgumentFormatter(cx, &format, JS_FALSE, &sp, JS_ADDRESSOF_VA_LIST(ap))) { - goto bad; + goto bad; } - /* NB: the formatter already updated sp, so we continue here. */ - continue; - } - sp++; + /* NB: the formatter already updated sp, so we continue here. */ + continue; + } + sp++; } /* @@ -362,7 +362,7 @@ JS_PushArgumentsVA(JSContext *cx, void **markp, const char *format, va_list ap) JS_ASSERT(sp <= argv + argc); if (sp < argv + argc) { /* Return slots not pushed to the current stack arena. */ - cx->stackPool.current->avail = (jsuword)sp; + cx->stackPool.current->avail = (jsuword)sp; /* Reduce the count of slots the GC will scan in this stack segment. */ sh = cx->stackHeaders; @@ -385,7 +385,7 @@ JS_PopArguments(JSContext *cx, void *mark) JS_PUBLIC_API(JSBool) JS_AddArgumentFormatter(JSContext *cx, const char *format, - JSArgumentFormatter formatter) + JSArgumentFormatter formatter) { size_t length; JSArgumentFormatMap **mpp, *map; @@ -393,16 +393,16 @@ JS_AddArgumentFormatter(JSContext *cx, const char *format, length = strlen(format); mpp = &cx->argumentFormatMap; while ((map = *mpp) != NULL) { - /* Insert before any shorter string to match before prefixes. */ - if (map->length < length) - break; - if (map->length == length && !strcmp(map->format, format)) - goto out; - mpp = &map->next; + /* Insert before any shorter string to match before prefixes. */ + if (map->length < length) + break; + if (map->length == length && !strcmp(map->format, format)) + goto out; + mpp = &map->next; } map = (JSArgumentFormatMap *) JS_malloc(cx, sizeof *map); if (!map) - return JS_FALSE; + return JS_FALSE; map->format = format; map->length = length; map->next = *mpp; @@ -421,12 +421,12 @@ JS_RemoveArgumentFormatter(JSContext *cx, const char *format) length = strlen(format); mpp = &cx->argumentFormatMap; while ((map = *mpp) != NULL) { - if (map->length == length && !strcmp(map->format, format)) { - *mpp = map->next; - JS_free(cx, map); - return; - } - mpp = &map->next; + if (map->length == length && !strcmp(map->format, format)) { + *mpp = map->next; + JS_free(cx, map); + return; + } + mpp = &map->next; } } @@ -442,47 +442,47 @@ JS_ConvertValue(JSContext *cx, jsval v, JSType type, jsval *vp) CHECK_REQUEST(cx); switch (type) { case JSTYPE_VOID: - *vp = JSVAL_VOID; + *vp = JSVAL_VOID; ok = JS_TRUE; - break; + break; case JSTYPE_OBJECT: - ok = js_ValueToObject(cx, v, &obj); - if (ok) - *vp = OBJECT_TO_JSVAL(obj); - break; + ok = js_ValueToObject(cx, v, &obj); + if (ok) + *vp = OBJECT_TO_JSVAL(obj); + break; case JSTYPE_FUNCTION: - fun = js_ValueToFunction(cx, &v, JS_FALSE); - ok = (fun != NULL); - if (ok) - *vp = OBJECT_TO_JSVAL(fun->object); - break; + fun = js_ValueToFunction(cx, &v, JS_FALSE); + ok = (fun != NULL); + if (ok) + *vp = OBJECT_TO_JSVAL(fun->object); + break; case JSTYPE_STRING: - str = js_ValueToString(cx, v); - ok = (str != NULL); - if (ok) - *vp = STRING_TO_JSVAL(str); - break; + str = js_ValueToString(cx, v); + ok = (str != NULL); + if (ok) + *vp = STRING_TO_JSVAL(str); + break; case JSTYPE_NUMBER: - ok = js_ValueToNumber(cx, v, &d); - if (ok) { - dp = js_NewDouble(cx, d); - ok = (dp != NULL); - if (ok) - *vp = DOUBLE_TO_JSVAL(dp); - } - break; + ok = js_ValueToNumber(cx, v, &d); + if (ok) { + dp = js_NewDouble(cx, d); + ok = (dp != NULL); + if (ok) + *vp = DOUBLE_TO_JSVAL(dp); + } + break; case JSTYPE_BOOLEAN: - ok = js_ValueToBoolean(cx, v, &b); - if (ok) - *vp = BOOLEAN_TO_JSVAL(b); - break; + ok = js_ValueToBoolean(cx, v, &b); + if (ok) + *vp = BOOLEAN_TO_JSVAL(b); + break; default: { - char numBuf[12]; - JS_snprintf(numBuf, sizeof numBuf, "%d", (int)type); - JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_BAD_TYPE, - numBuf); - ok = JS_FALSE; - break; + char numBuf[12]; + JS_snprintf(numBuf, sizeof numBuf, "%d", (int)type); + JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_BAD_TYPE, + numBuf); + ok = JS_FALSE; + break; } } return ok; @@ -569,25 +569,25 @@ JS_TypeOfValue(JSContext *cx, jsval v) CHECK_REQUEST(cx); if (JSVAL_IS_OBJECT(v)) { /* XXX JSVAL_IS_OBJECT(v) is true for null too! Can we change ECMA? */ - obj = JSVAL_TO_OBJECT(v); - if (obj && - (ops = obj->map->ops, - ops == &js_ObjectOps - ? (clasp = OBJ_GET_CLASS(cx, obj), - clasp->call || clasp == &js_FunctionClass) - : ops->call != 0)) { - type = JSTYPE_FUNCTION; - } else { - type = JSTYPE_OBJECT; - } + obj = JSVAL_TO_OBJECT(v); + if (obj && + (ops = obj->map->ops, + ops == &js_ObjectOps + ? (clasp = OBJ_GET_CLASS(cx, obj), + clasp->call || clasp == &js_FunctionClass) + : ops->call != 0)) { + type = JSTYPE_FUNCTION; + } else { + type = JSTYPE_OBJECT; + } } else if (JSVAL_IS_NUMBER(v)) { - type = JSTYPE_NUMBER; + type = JSTYPE_NUMBER; } else if (JSVAL_IS_STRING(v)) { - type = JSTYPE_STRING; + type = JSTYPE_STRING; } else if (JSVAL_IS_BOOLEAN(v)) { - type = JSTYPE_BOOLEAN; + type = JSTYPE_BOOLEAN; } else { - type = JSTYPE_VOID; + type = JSTYPE_VOID; } return type; } @@ -596,7 +596,7 @@ JS_PUBLIC_API(const char *) JS_GetTypeName(JSContext *cx, JSType type) { if ((uintN)type >= (uintN)JSTYPE_LIMIT) - return NULL; + return NULL; return js_type_str[type]; } @@ -624,36 +624,36 @@ JS_NewRuntime(uint32 maxbytes) #endif /* DEBUG */ if (!js_InitStringGlobals()) - return NULL; + return NULL; rt = (JSRuntime *) malloc(sizeof(JSRuntime)); if (!rt) - return NULL; + return NULL; memset(rt, 0, sizeof(JSRuntime)); if (!js_InitGC(rt, maxbytes)) - goto bad; + goto bad; #ifdef JS_THREADSAFE rt->gcLock = JS_NEW_LOCK(); if (!rt->gcLock) - goto bad; + goto bad; rt->gcDone = JS_NEW_CONDVAR(rt->gcLock); if (!rt->gcDone) - goto bad; + goto bad; rt->requestDone = JS_NEW_CONDVAR(rt->gcLock); if (!rt->requestDone) - goto bad; + goto bad; js_SetupLocks(20, 32); /* this is asymmetric with JS_ShutDown. */ rt->rtLock = JS_NEW_LOCK(); if (!rt->rtLock) - goto bad; + goto bad; rt->stateChange = JS_NEW_CONDVAR(rt->rtLock); if (!rt->stateChange) - goto bad; + goto bad; rt->setSlotLock = JS_NEW_LOCK(); if (!rt->setSlotLock) - goto bad; + goto bad; rt->scopeSharingDone = JS_NEW_CONDVAR(rt->gcLock); if (!rt->scopeSharingDone) - goto bad; + goto bad; rt->scopeSharingTodo = NO_SCOPE_SHARING_TODO; #endif rt->propertyCache.empty = JS_TRUE; @@ -687,11 +687,11 @@ JS_DestroyRuntime(JSRuntime *rt) js_FinishGC(rt); #ifdef JS_THREADSAFE if (rt->gcLock) - JS_DESTROY_LOCK(rt->gcLock); + JS_DESTROY_LOCK(rt->gcLock); if (rt->gcDone) - JS_DESTROY_CONDVAR(rt->gcDone); + JS_DESTROY_CONDVAR(rt->gcDone); if (rt->requestDone) - JS_DESTROY_CONDVAR(rt->requestDone); + JS_DESTROY_CONDVAR(rt->requestDone); if (rt->rtLock) JS_DESTROY_LOCK(rt->rtLock); if (rt->stateChange) @@ -735,9 +735,9 @@ JS_BeginRequest(JSContext *cx) JS_ASSERT(cx->thread); if (!cx->requestDepth) { - /* Wait until the GC is finished. */ - rt = cx->runtime; - JS_LOCK_GC(rt); + /* Wait until the GC is finished. */ + rt = cx->runtime; + JS_LOCK_GC(rt); /* NB: we use cx->thread here, not js_CurrentThreadId(). */ if (rt->gcThread != cx->thread) { @@ -745,10 +745,10 @@ JS_BeginRequest(JSContext *cx) JS_AWAIT_GC_DONE(rt); } - /* Indicate that a request is running. */ - rt->requestCount++; + /* Indicate that a request is running. */ + rt->requestCount++; cx->requestDepth = 1; - JS_UNLOCK_GC(rt); + JS_UNLOCK_GC(rt); return; } cx->requestDepth++; @@ -933,11 +933,11 @@ JS_SetVersion(JSContext *cx, JSVersion version) #if !JS_BUG_FALLIBLE_EQOPS if (cx->version == JSVERSION_1_2) { - cx->jsop_eq = JSOP_NEW_EQ; - cx->jsop_ne = JSOP_NEW_NE; + cx->jsop_eq = JSOP_NEW_EQ; + cx->jsop_ne = JSOP_NEW_NE; } else { - cx->jsop_eq = JSOP_EQ; - cx->jsop_ne = JSOP_NE; + cx->jsop_eq = JSOP_EQ; + cx->jsop_ne = JSOP_NE; } #endif /* !JS_BUG_FALLIBLE_EQOPS */ @@ -1427,11 +1427,11 @@ JS_malloc(JSContext *cx, size_t nbytes) JS_ASSERT(nbytes != 0); if (nbytes == 0) - nbytes = 1; + nbytes = 1; cx->runtime->gcMallocBytes += nbytes; p = malloc(nbytes); if (!p) - JS_ReportOutOfMemory(cx); + JS_ReportOutOfMemory(cx); return p; } @@ -1440,7 +1440,7 @@ JS_realloc(JSContext *cx, void *p, size_t nbytes) { p = realloc(p, nbytes); if (!p) - JS_ReportOutOfMemory(cx); + JS_ReportOutOfMemory(cx); return p; } @@ -1448,7 +1448,7 @@ JS_PUBLIC_API(void) JS_free(JSContext *cx, void *p) { if (p) - free(p); + free(p); } JS_PUBLIC_API(char *) @@ -1456,7 +1456,7 @@ JS_strdup(JSContext *cx, const char *s) { char *p = (char *) JS_malloc(cx, strlen(s) + 1); if (!p) - return NULL; + return NULL; return strcpy(p, s); } @@ -1523,26 +1523,28 @@ typedef struct NamedRootDumpArgs { void *data; } NamedRootDumpArgs; -JS_STATIC_DLL_CALLBACK(intN) -js_named_root_dumper(JSHashEntry *he, intN i, void *arg) +JS_STATIC_DLL_CALLBACK(JSDHashOperator) +js_named_root_dumper(JSDHashTable *table, JSDHashEntryHdr *hdr, uint32 number, + void *arg) { NamedRootDumpArgs *args = (NamedRootDumpArgs *) arg; + JSGCRootHashEntry *rhe = (JSGCRootHashEntry *)hdr; - if (he->value) - args->dump((char *)he->value, (void *)he->key, args->data); - return HT_ENUMERATE_NEXT; + if (rhe->name) + args->dump(rhe->name, rhe->root, args->data); + return JS_DHASH_NEXT; } JS_PUBLIC_API(void) JS_DumpNamedRoots(JSRuntime *rt, - void (*dump)(const char *name, void *rp, void *data), - void *data) + void (*dump)(const char *name, void *rp, void *data), + void *data) { NamedRootDumpArgs args; args.dump = dump; args.data = data; - JS_HashTableEnumerateEntries(rt->gcRootsHash, js_named_root_dumper, &args); + JS_DHashTableEnumerate(&rt->gcRootsHash, js_named_root_dumper, &args); } #endif /* DEBUG */ @@ -1552,39 +1554,42 @@ typedef struct GCRootMapArgs { void *data; } GCRootMapArgs; -JS_STATIC_DLL_CALLBACK(intN) -js_gcroot_mapper(JSHashEntry *he, intN i, void *arg) +JS_STATIC_DLL_CALLBACK(JSDHashOperator) +js_gcroot_mapper(JSDHashTable *table, JSDHashEntryHdr *hdr, uint32 number, + void *arg) { GCRootMapArgs *args = (GCRootMapArgs *) arg; - intN mapflags, htflags; + JSGCRootHashEntry *rhe = (JSGCRootHashEntry *)hdr; + intN mapflags; + JSDHashOperator op; - mapflags = args->map((void *)he->key, (char *)he->value, args->data); + mapflags = args->map(rhe->root, rhe->name, args->data); -#if JS_MAP_GCROOT_NEXT == HT_ENUMERATE_NEXT && \ - JS_MAP_GCROOT_STOP == HT_ENUMERATE_STOP && \ - JS_MAP_GCROOT_REMOVE == HT_ENUMERATE_REMOVE - htflags = mapflags; +#if JS_MAP_GCROOT_NEXT == JS_DHASH_NEXT && \ + JS_MAP_GCROOT_STOP == JS_DHASH_STOP && \ + JS_MAP_GCROOT_REMOVE == JS_DHASH_REMOVE + op = (JSDHashOperator)mapflags; #else - htflags = HT_ENUMERATE_NEXT; + op = JS_DHASH_NEXT; if (mapflags & JS_MAP_GCROOT_STOP) - htflags |= HT_ENUMERATE_STOP; + op |= JS_DHASH_STOP; if (mapflags & JS_MAP_GCROOT_REMOVE) - htflags |= HT_ENUMERATE_REMOVE; + op |= JS_DHASH_REMOVE; #endif - return htflags; + return op; } -JS_PUBLIC_API(intN) +JS_PUBLIC_API(uint32) JS_MapGCRoots(JSRuntime *rt, JSGCRootMapFun map, void *data) { GCRootMapArgs args; - intN rv; + uint32 rv; args.map = map; args.data = data; JS_LOCK_GC(rt); - rv = JS_HashTableEnumerateEntries(rt->gcRootsHash, js_gcroot_mapper, &args); + rv = JS_DHashTableEnumerate(&rt->gcRootsHash, js_gcroot_mapper, &args); JS_UNLOCK_GC(rt); return rv; } @@ -1597,7 +1602,7 @@ JS_LockGCThing(JSContext *cx, void *thing) CHECK_REQUEST(cx); ok = js_LockGCThing(cx, thing); if (!ok) - JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_CANT_LOCK); + JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_CANT_LOCK); return ok; } @@ -1609,7 +1614,7 @@ JS_UnlockGCThing(JSContext *cx, void *thing) CHECK_REQUEST(cx); ok = js_UnlockGCThing(cx, thing); if (!ok) - JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_CANT_UNLOCK); + JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_CANT_UNLOCK); return ok; } @@ -1628,7 +1633,7 @@ JS_PUBLIC_API(void) JS_GC(JSContext *cx) { if (cx->stackPool.current == &cx->stackPool.first) - JS_FinishArenaPool(&cx->stackPool); + JS_FinishArenaPool(&cx->stackPool); JS_FinishArenaPool(&cx->codePool); JS_FinishArenaPool(&cx->tempPool); js_ForceGC(cx); @@ -1650,7 +1655,7 @@ JS_MaybeGC(JSContext *cx) * the last time we GC'd, or if we have malloc'd more bytes through * JS_malloc than we were told to allocate by JS_NewRuntime. */ - JS_GC(cx); + JS_GC(cx); } } @@ -1720,12 +1725,12 @@ JS_ValueToId(JSContext *cx, jsval v, jsid *idp) CHECK_REQUEST(cx); if (JSVAL_IS_INT(v)) { - *idp = v; + *idp = v; } else { - atom = js_ValueToStringAtom(cx, v); - if (!atom) - return JS_FALSE; - *idp = (jsid)atom; + atom = js_ValueToStringAtom(cx, v); + if (!atom) + return JS_FALSE; + *idp = (jsid)atom; } return JS_TRUE; } @@ -1761,7 +1766,7 @@ JS_ConvertStub(JSContext *cx, JSObject *obj, JSType type, jsval *vp) { #if JS_BUG_EAGER_TOSTRING if (type == JSTYPE_STRING) - return JS_TRUE; + return JS_TRUE; #endif return js_TryValueOf(cx, obj, type, vp); } @@ -1773,9 +1778,9 @@ JS_FinalizeStub(JSContext *cx, JSObject *obj) JS_PUBLIC_API(JSObject *) JS_InitClass(JSContext *cx, JSObject *obj, JSObject *parent_proto, - JSClass *clasp, JSNative constructor, uintN nargs, - JSPropertySpec *ps, JSFunctionSpec *fs, - JSPropertySpec *static_ps, JSFunctionSpec *static_fs) + JSClass *clasp, JSNative constructor, uintN nargs, + JSPropertySpec *ps, JSFunctionSpec *fs, + JSPropertySpec *static_ps, JSFunctionSpec *static_fs) { JSAtom *atom; JSObject *proto, *ctor; @@ -1786,26 +1791,26 @@ JS_InitClass(JSContext *cx, JSObject *obj, JSObject *parent_proto, CHECK_REQUEST(cx); atom = js_Atomize(cx, clasp->name, strlen(clasp->name), 0); if (!atom) - return NULL; + return NULL; /* Create a prototype object for this class. */ proto = js_NewObject(cx, clasp, parent_proto, obj); if (!proto) - return NULL; + return NULL; if (!constructor) { - /* Lacking a constructor, name the prototype (e.g., Math). */ - named = OBJ_DEFINE_PROPERTY(cx, obj, (jsid)atom, OBJECT_TO_JSVAL(proto), - NULL, NULL, 0, NULL); - if (!named) - goto bad; - ctor = proto; + /* Lacking a constructor, name the prototype (e.g., Math). */ + named = OBJ_DEFINE_PROPERTY(cx, obj, (jsid)atom, OBJECT_TO_JSVAL(proto), + NULL, NULL, 0, NULL); + if (!named) + goto bad; + ctor = proto; } else { - /* Define the constructor function in obj's scope. */ - fun = js_DefineFunction(cx, obj, atom, constructor, nargs, 0); - named = (fun != NULL); - if (!fun) - goto bad; + /* Define the constructor function in obj's scope. */ + fun = js_DefineFunction(cx, obj, atom, constructor, nargs, 0); + named = (fun != NULL); + if (!fun) + goto bad; /* * Remember the class this function is a constructor for so that @@ -1814,35 +1819,35 @@ JS_InitClass(JSContext *cx, JSObject *obj, JSObject *parent_proto, */ fun->clasp = clasp; - /* Connect constructor and prototype by named properties. */ - ctor = fun->object; - if (!js_SetClassPrototype(cx, ctor, proto, - JSPROP_READONLY | JSPROP_PERMANENT)) { - goto bad; - } + /* Connect constructor and prototype by named properties. */ + ctor = fun->object; + if (!js_SetClassPrototype(cx, ctor, proto, + JSPROP_READONLY | JSPROP_PERMANENT)) { + goto bad; + } - /* Bootstrap Function.prototype (see also JS_InitStandardClasses). */ - if (OBJ_GET_CLASS(cx, ctor) == clasp) { - /* XXXMLM - this fails in framesets that are writing over - * themselves! - * JS_ASSERT(!OBJ_GET_PROTO(cx, ctor)); - */ - OBJ_SET_PROTO(cx, ctor, proto); - } + /* Bootstrap Function.prototype (see also JS_InitStandardClasses). */ + if (OBJ_GET_CLASS(cx, ctor) == clasp) { + /* XXXMLM - this fails in framesets that are writing over + * themselves! + * JS_ASSERT(!OBJ_GET_PROTO(cx, ctor)); + */ + OBJ_SET_PROTO(cx, ctor, proto); + } } /* Add properties and methods to the prototype and the constructor. */ if ((ps && !JS_DefineProperties(cx, proto, ps)) || - (fs && !JS_DefineFunctions(cx, proto, fs)) || - (static_ps && !JS_DefineProperties(cx, ctor, static_ps)) || - (static_fs && !JS_DefineFunctions(cx, ctor, static_fs))) { - goto bad; + (fs && !JS_DefineFunctions(cx, proto, fs)) || + (static_ps && !JS_DefineProperties(cx, ctor, static_ps)) || + (static_fs && !JS_DefineFunctions(cx, ctor, static_fs))) { + goto bad; } return proto; bad: if (named) - (void) OBJ_DELETE_PROPERTY(cx, obj, (jsid)atom, &junk); + (void) OBJ_DELETE_PROPERTY(cx, obj, (jsid)atom, &junk); cx->newborn[GCX_OBJECT] = NULL; return NULL; } @@ -1868,15 +1873,15 @@ JS_InstanceOf(JSContext *cx, JSObject *obj, JSClass *clasp, jsval *argv) CHECK_REQUEST(cx); if (OBJ_GET_CLASS(cx, obj) == clasp) - return JS_TRUE; + return JS_TRUE; if (argv) { - fun = js_ValueToFunction(cx, &argv[-2], JS_FALSE); - if (fun) { - JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, - JSMSG_INCOMPATIBLE_PROTO, - clasp->name, JS_GetFunctionName(fun), - OBJ_GET_CLASS(cx, obj)->name); - } + fun = js_ValueToFunction(cx, &argv[-2], JS_FALSE); + if (fun) { + JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, + JSMSG_INCOMPATIBLE_PROTO, + clasp->name, JS_GetFunctionName(fun), + OBJ_GET_CLASS(cx, obj)->name); + } } return JS_FALSE; } @@ -1889,7 +1894,7 @@ JS_GetPrivate(JSContext *cx, JSObject *obj) JS_ASSERT(OBJ_GET_CLASS(cx, obj)->flags & JSCLASS_HAS_PRIVATE); v = OBJ_GET_SLOT(cx, obj, JSSLOT_PRIVATE); if (!JSVAL_IS_INT(v)) - return NULL; + return NULL; return JSVAL_TO_PRIVATE(v); } @@ -1903,10 +1908,10 @@ JS_SetPrivate(JSContext *cx, JSObject *obj, void *data) JS_PUBLIC_API(void *) JS_GetInstancePrivate(JSContext *cx, JSObject *obj, JSClass *clasp, - jsval *argv) + jsval *argv) { if (!JS_InstanceOf(cx, obj, clasp, argv)) - return NULL; + return NULL; return JS_GetPrivate(cx, obj); } @@ -1960,14 +1965,14 @@ JS_GetConstructor(JSContext *cx, JSObject *proto) CHECK_REQUEST(cx); if (!OBJ_GET_PROPERTY(cx, proto, - (jsid)cx->runtime->atomState.constructorAtom, - &cval)) { - return NULL; + (jsid)cx->runtime->atomState.constructorAtom, + &cval)) { + return NULL; } if (!JSVAL_IS_FUNCTION(cx, cval)) { - JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_NO_CONSTRUCTOR, - OBJ_GET_CLASS(cx, proto)->name); - return NULL; + JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_NO_CONSTRUCTOR, + OBJ_GET_CLASS(cx, proto)->name); + return NULL; } return JSVAL_TO_OBJECT(cval); } @@ -1983,7 +1988,7 @@ JS_NewObject(JSContext *cx, JSClass *clasp, JSObject *proto, JSObject *parent) JS_PUBLIC_API(JSObject *) JS_ConstructObject(JSContext *cx, JSClass *clasp, JSObject *proto, - JSObject *parent) + JSObject *parent) { CHECK_REQUEST(cx); if (!clasp) @@ -1993,46 +1998,46 @@ JS_ConstructObject(JSContext *cx, JSClass *clasp, JSObject *proto, static JSBool DefineProperty(JSContext *cx, JSObject *obj, const char *name, jsval value, - JSPropertyOp getter, JSPropertyOp setter, uintN attrs, - JSProperty **propp) + JSPropertyOp getter, JSPropertyOp setter, uintN attrs, + JSProperty **propp) { jsid id; JSAtom *atom; if (attrs & JSPROP_INDEX) { - id = INT_TO_JSVAL((jsint)name); - atom = NULL; + id = INT_TO_JSVAL((jsint)name); + atom = NULL; attrs &= ~JSPROP_INDEX; } else { - atom = js_Atomize(cx, name, strlen(name), 0); - if (!atom) - return JS_FALSE; - id = (jsid)atom; + atom = js_Atomize(cx, name, strlen(name), 0); + if (!atom) + return JS_FALSE; + id = (jsid)atom; } return OBJ_DEFINE_PROPERTY(cx, obj, id, value, getter, setter, attrs, - propp); + propp); } #define AUTO_NAMELEN(s,n) (((n) == (size_t)-1) ? js_strlen(s) : (n)) static JSBool DefineUCProperty(JSContext *cx, JSObject *obj, - const jschar *name, size_t namelen, jsval value, - JSPropertyOp getter, JSPropertyOp setter, uintN attrs, - JSProperty **propp) + const jschar *name, size_t namelen, jsval value, + JSPropertyOp getter, JSPropertyOp setter, uintN attrs, + JSProperty **propp) { JSAtom *atom; atom = js_AtomizeChars(cx, name, AUTO_NAMELEN(name,namelen), 0); if (!atom) - return JS_FALSE; + return JS_FALSE; return OBJ_DEFINE_PROPERTY(cx, obj, (jsid)atom, value, getter, setter, - attrs, propp); + attrs, propp); } JS_PUBLIC_API(JSObject *) JS_DefineObject(JSContext *cx, JSObject *obj, const char *name, JSClass *clasp, - JSObject *proto, uintN attrs) + JSObject *proto, uintN attrs) { JSObject *nobj; @@ -2041,11 +2046,11 @@ JS_DefineObject(JSContext *cx, JSObject *obj, const char *name, JSClass *clasp, clasp = &js_ObjectClass; /* default class is Object */ nobj = js_NewObject(cx, clasp, proto, obj); if (!nobj) - return NULL; + return NULL; if (!DefineProperty(cx, obj, name, OBJECT_TO_JSVAL(nobj), NULL, NULL, attrs, - NULL)) { - cx->newborn[GCX_OBJECT] = NULL; - return NULL; + NULL)) { + cx->newborn[GCX_OBJECT] = NULL; + return NULL; } return nobj; } @@ -2059,15 +2064,15 @@ JS_DefineConstDoubles(JSContext *cx, JSObject *obj, JSConstDoubleSpec *cds) CHECK_REQUEST(cx); for (ok = JS_TRUE; cds->name; cds++) { - ok = js_NewNumberValue(cx, cds->dval, &value); - if (!ok) - break; - flags = cds->flags; - if (!flags) - flags = JSPROP_READONLY | JSPROP_PERMANENT; - ok = DefineProperty(cx, obj, cds->name, value, NULL, NULL, flags, NULL); - if (!ok) - break; + ok = js_NewNumberValue(cx, cds->dval, &value); + if (!ok) + break; + flags = cds->flags; + if (!flags) + flags = JSPROP_READONLY | JSPROP_PERMANENT; + ok = DefineProperty(cx, obj, cds->name, value, NULL, NULL, flags, NULL); + if (!ok) + break; } return ok; } @@ -2081,30 +2086,30 @@ JS_DefineProperties(JSContext *cx, JSObject *obj, JSPropertySpec *ps) CHECK_REQUEST(cx); for (ok = JS_TRUE; ps->name; ps++) { - ok = DefineProperty(cx, obj, ps->name, JSVAL_VOID, - ps->getter, ps->setter, ps->flags, - &prop); - if (!ok) - break; - if (prop) { - if (OBJ_IS_NATIVE(obj)) { - sprop = (JSScopeProperty *)prop; + ok = DefineProperty(cx, obj, ps->name, JSVAL_VOID, + ps->getter, ps->setter, ps->flags, + &prop); + if (!ok) + break; + if (prop) { + if (OBJ_IS_NATIVE(obj)) { + sprop = (JSScopeProperty *)prop; #ifdef JS_DOUBLE_HASHING sprop->attrs |= JSPROP_INDEX; sprop->tinyid = ps->tinyid; #else - sprop->id = INT_TO_JSVAL(ps->tinyid); + sprop->id = INT_TO_JSVAL(ps->tinyid); #endif - } - OBJ_DROP_PROPERTY(cx, obj, prop); - } + } + OBJ_DROP_PROPERTY(cx, obj, prop); + } } return ok; } JS_PUBLIC_API(JSBool) JS_DefineProperty(JSContext *cx, JSObject *obj, const char *name, jsval value, - JSPropertyOp getter, JSPropertyOp setter, uintN attrs) + JSPropertyOp getter, JSPropertyOp setter, uintN attrs) { CHECK_REQUEST(cx); return DefineProperty(cx, obj, name, value, getter, setter, attrs, NULL); @@ -2112,9 +2117,9 @@ JS_DefineProperty(JSContext *cx, JSObject *obj, const char *name, jsval value, JS_PUBLIC_API(JSBool) JS_DefinePropertyWithTinyId(JSContext *cx, JSObject *obj, const char *name, - int8 tinyid, jsval value, - JSPropertyOp getter, JSPropertyOp setter, - uintN attrs) + int8 tinyid, jsval value, + JSPropertyOp getter, JSPropertyOp setter, + uintN attrs) { JSBool ok; JSProperty *prop; @@ -2123,48 +2128,48 @@ JS_DefinePropertyWithTinyId(JSContext *cx, JSObject *obj, const char *name, CHECK_REQUEST(cx); ok = DefineProperty(cx, obj, name, value, getter, setter, attrs, &prop); if (ok && prop) { - if (OBJ_IS_NATIVE(obj)) { - sprop = (JSScopeProperty *)prop; + if (OBJ_IS_NATIVE(obj)) { + sprop = (JSScopeProperty *)prop; #ifdef JS_DOUBLE_HASHING sprop->attrs |= JSPROP_INDEX; sprop->tinyid = tinyid; #else - sprop->id = INT_TO_JSVAL(tinyid); + sprop->id = INT_TO_JSVAL(tinyid); #endif - } - OBJ_DROP_PROPERTY(cx, obj, prop); + } + OBJ_DROP_PROPERTY(cx, obj, prop); } return ok; } static JSBool LookupProperty(JSContext *cx, JSObject *obj, const char *name, JSObject **objp, - JSProperty **propp) + JSProperty **propp) { JSAtom *atom; atom = js_Atomize(cx, name, strlen(name), 0); if (!atom) - return JS_FALSE; + return JS_FALSE; return OBJ_LOOKUP_PROPERTY(cx, obj, (jsid)atom, objp, propp); } static JSBool LookupUCProperty(JSContext *cx, JSObject *obj, - const jschar *name, size_t namelen, - JSObject **objp, JSProperty **propp) + const jschar *name, size_t namelen, + JSObject **objp, JSProperty **propp) { JSAtom *atom; atom = js_AtomizeChars(cx, name, AUTO_NAMELEN(name,namelen), 0); if (!atom) - return JS_FALSE; + return JS_FALSE; return OBJ_LOOKUP_PROPERTY(cx, obj, (jsid)atom, objp, propp); } JS_PUBLIC_API(JSBool) JS_AliasProperty(JSContext *cx, JSObject *obj, const char *name, - const char *alias) + const char *alias) { JSObject *obj2; JSProperty *prop; @@ -2175,24 +2180,24 @@ JS_AliasProperty(JSContext *cx, JSObject *obj, const char *name, CHECK_REQUEST(cx); /* XXXbe push this into jsobj.c or jsscope.c */ if (!LookupProperty(cx, obj, name, &obj2, &prop)) - return JS_FALSE; + return JS_FALSE; if (!prop) { - js_ReportIsNotDefined(cx, name); - return JS_FALSE; + js_ReportIsNotDefined(cx, name); + return JS_FALSE; } if (obj2 != obj || !OBJ_IS_NATIVE(obj2)) { - OBJ_DROP_PROPERTY(cx, obj2, prop); - JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_CANT_ALIAS, - alias, name, OBJ_GET_CLASS(cx, obj2)->name); - return JS_FALSE; + OBJ_DROP_PROPERTY(cx, obj2, prop); + JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_CANT_ALIAS, + alias, name, OBJ_GET_CLASS(cx, obj2)->name); + return JS_FALSE; } atom = js_Atomize(cx, alias, strlen(alias), 0); if (!atom) { - ok = JS_FALSE; + ok = JS_FALSE; } else { - scope = OBJ_SCOPE(obj); - ok = (scope->ops->add(cx, scope, (jsid)atom, (JSScopeProperty *)prop) - != NULL); + scope = OBJ_SCOPE(obj); + ok = (scope->ops->add(cx, scope, (jsid)atom, (JSScopeProperty *)prop) + != NULL); } OBJ_DROP_PROPERTY(cx, obj, prop); return ok; @@ -2205,18 +2210,18 @@ LookupResult(JSContext *cx, JSObject *obj, JSObject *obj2, JSProperty *prop) jsval rval; if (!prop) { - /* XXX bad API: no way to tell "not defined" from "void value" */ - return JSVAL_VOID; + /* XXX bad API: no way to tell "not defined" from "void value" */ + return JSVAL_VOID; } if (OBJ_IS_NATIVE(obj2)) { - /* Peek at the native property's slot value, without doing a Get. */ - sprop = (JSScopeProperty *)prop; + /* Peek at the native property's slot value, without doing a Get. */ + sprop = (JSScopeProperty *)prop; rval = (SPROP_HAS_VALID_SLOT(sprop)) ? LOCKED_OBJ_GET_SLOT(obj2, sprop->slot) : JSVAL_TRUE; } else { - /* XXX bad API: no way to return "defined but value unknown" */ - rval = JSVAL_TRUE; + /* XXX bad API: no way to return "defined but value unknown" */ + rval = JSVAL_TRUE; } OBJ_DROP_PROPERTY(cx, obj2, prop); return rval; @@ -2224,21 +2229,21 @@ LookupResult(JSContext *cx, JSObject *obj, JSObject *obj2, JSProperty *prop) static JSBool GetPropertyAttributes(JSContext *cx, JSObject *obj, JSAtom *atom, - uintN *attrsp, JSBool *foundp) + uintN *attrsp, JSBool *foundp) { JSObject *obj2; JSProperty *prop; JSBool ok; if (!atom) - return JS_FALSE; + return JS_FALSE; if (!OBJ_LOOKUP_PROPERTY(cx, obj, (jsid)atom, &obj2, &prop)) - return JS_FALSE; + return JS_FALSE; if (!prop || obj != obj2) { - *foundp = JS_FALSE; - if (prop) - OBJ_DROP_PROPERTY(cx, obj2, prop); - return JS_TRUE; + *foundp = JS_FALSE; + if (prop) + OBJ_DROP_PROPERTY(cx, obj2, prop); + return JS_TRUE; } *foundp = JS_TRUE; @@ -2249,21 +2254,21 @@ GetPropertyAttributes(JSContext *cx, JSObject *obj, JSAtom *atom, static JSBool SetPropertyAttributes(JSContext *cx, JSObject *obj, JSAtom *atom, - uintN attrs, JSBool *foundp) + uintN attrs, JSBool *foundp) { JSObject *obj2; JSProperty *prop; JSBool ok; if (!atom) - return JS_FALSE; + return JS_FALSE; if (!OBJ_LOOKUP_PROPERTY(cx, obj, (jsid)atom, &obj2, &prop)) - return JS_FALSE; + return JS_FALSE; if (!prop || obj != obj2) { - *foundp = JS_FALSE; - if (prop) - OBJ_DROP_PROPERTY(cx, obj2, prop); - return JS_TRUE; + *foundp = JS_FALSE; + if (prop) + OBJ_DROP_PROPERTY(cx, obj2, prop); + return JS_TRUE; } *foundp = JS_TRUE; @@ -2275,22 +2280,22 @@ SetPropertyAttributes(JSContext *cx, JSObject *obj, JSAtom *atom, JS_PUBLIC_API(JSBool) JS_GetPropertyAttributes(JSContext *cx, JSObject *obj, const char *name, - uintN *attrsp, JSBool *foundp) + uintN *attrsp, JSBool *foundp) { CHECK_REQUEST(cx); return GetPropertyAttributes(cx, obj, - js_Atomize(cx, name, strlen(name), 0), - attrsp, foundp); + js_Atomize(cx, name, strlen(name), 0), + attrsp, foundp); } JS_PUBLIC_API(JSBool) JS_SetPropertyAttributes(JSContext *cx, JSObject *obj, const char *name, - uintN attrs, JSBool *foundp) + uintN attrs, JSBool *foundp) { CHECK_REQUEST(cx); return SetPropertyAttributes(cx, obj, - js_Atomize(cx, name, strlen(name), 0), - attrs, foundp); + js_Atomize(cx, name, strlen(name), 0), + attrs, foundp); } JS_PUBLIC_API(JSBool) @@ -2303,7 +2308,7 @@ JS_LookupProperty(JSContext *cx, JSObject *obj, const char *name, jsval *vp) CHECK_REQUEST(cx); ok = LookupProperty(cx, obj, name, &obj2, &prop); if (ok) - *vp = LookupResult(cx, obj, obj2, prop); + *vp = LookupResult(cx, obj, obj2, prop); return ok; } @@ -2315,7 +2320,7 @@ JS_GetProperty(JSContext *cx, JSObject *obj, const char *name, jsval *vp) CHECK_REQUEST(cx); atom = js_Atomize(cx, name, strlen(name), 0); if (!atom) - return JS_FALSE; + return JS_FALSE; return OBJ_GET_PROPERTY(cx, obj, (jsid)atom, vp); } @@ -2327,7 +2332,7 @@ JS_SetProperty(JSContext *cx, JSObject *obj, const char *name, jsval *vp) CHECK_REQUEST(cx); atom = js_Atomize(cx, name, strlen(name), 0); if (!atom) - return JS_FALSE; + return JS_FALSE; return OBJ_SET_PROPERTY(cx, obj, (jsid)atom, vp); } @@ -2342,56 +2347,56 @@ JS_DeleteProperty(JSContext *cx, JSObject *obj, const char *name) JS_PUBLIC_API(JSBool) JS_DeleteProperty2(JSContext *cx, JSObject *obj, const char *name, - jsval *rval) + jsval *rval) { JSAtom *atom; CHECK_REQUEST(cx); atom = js_Atomize(cx, name, strlen(name), 0); if (!atom) - return JS_FALSE; + return JS_FALSE; return OBJ_DELETE_PROPERTY(cx, obj, (jsid)atom, rval); } JS_PUBLIC_API(JSBool) JS_DefineUCProperty(JSContext *cx, JSObject *obj, - const jschar *name, size_t namelen, jsval value, - JSPropertyOp getter, JSPropertyOp setter, - uintN attrs) + const jschar *name, size_t namelen, jsval value, + JSPropertyOp getter, JSPropertyOp setter, + uintN attrs) { CHECK_REQUEST(cx); return DefineUCProperty(cx, obj, name, namelen, value, getter, setter, - attrs, NULL); + attrs, NULL); } JS_PUBLIC_API(JSBool) JS_GetUCPropertyAttributes(JSContext *cx, JSObject *obj, - const jschar *name, size_t namelen, - uintN *attrsp, JSBool *foundp) + const jschar *name, size_t namelen, + uintN *attrsp, JSBool *foundp) { CHECK_REQUEST(cx); return GetPropertyAttributes(cx, obj, - js_AtomizeChars(cx, name, AUTO_NAMELEN(name,namelen), 0), - attrsp, foundp); + js_AtomizeChars(cx, name, AUTO_NAMELEN(name,namelen), 0), + attrsp, foundp); } JS_PUBLIC_API(JSBool) JS_SetUCPropertyAttributes(JSContext *cx, JSObject *obj, - const jschar *name, size_t namelen, - uintN attrs, JSBool *foundp) + const jschar *name, size_t namelen, + uintN attrs, JSBool *foundp) { CHECK_REQUEST(cx); return SetPropertyAttributes(cx, obj, - js_AtomizeChars(cx, name, AUTO_NAMELEN(name,namelen), 0), - attrs, foundp); + js_AtomizeChars(cx, name, AUTO_NAMELEN(name,namelen), 0), + attrs, foundp); } JS_PUBLIC_API(JSBool) JS_DefineUCPropertyWithTinyId(JSContext *cx, JSObject *obj, - const jschar *name, size_t namelen, - int8 tinyid, jsval value, - JSPropertyOp getter, JSPropertyOp setter, - uintN attrs) + const jschar *name, size_t namelen, + int8 tinyid, jsval value, + JSPropertyOp getter, JSPropertyOp setter, + uintN attrs) { JSBool ok; JSProperty *prop; @@ -2399,26 +2404,26 @@ JS_DefineUCPropertyWithTinyId(JSContext *cx, JSObject *obj, CHECK_REQUEST(cx); ok = DefineUCProperty(cx, obj, name, namelen, value, getter, setter, attrs, - &prop); + &prop); if (ok && prop) { - if (OBJ_IS_NATIVE(obj)) { - sprop = (JSScopeProperty *)prop; + if (OBJ_IS_NATIVE(obj)) { + sprop = (JSScopeProperty *)prop; #ifdef JS_DOUBLE_HASHING sprop->attrs |= JSPROP_INDEX; sprop->tinyid = tinyid; #else - sprop->id = INT_TO_JSVAL(tinyid); + sprop->id = INT_TO_JSVAL(tinyid); #endif - } - OBJ_DROP_PROPERTY(cx, obj, prop); + } + OBJ_DROP_PROPERTY(cx, obj, prop); } return ok; } JS_PUBLIC_API(JSBool) JS_LookupUCProperty(JSContext *cx, JSObject *obj, - const jschar *name, size_t namelen, - jsval *vp) + const jschar *name, size_t namelen, + jsval *vp) { JSBool ok; JSObject *obj2; @@ -2427,49 +2432,49 @@ JS_LookupUCProperty(JSContext *cx, JSObject *obj, CHECK_REQUEST(cx); ok = LookupUCProperty(cx, obj, name, namelen, &obj2, &prop); if (ok) - *vp = LookupResult(cx, obj, obj2, prop); + *vp = LookupResult(cx, obj, obj2, prop); return ok; } JS_PUBLIC_API(JSBool) JS_GetUCProperty(JSContext *cx, JSObject *obj, - const jschar *name, size_t namelen, - jsval *vp) + const jschar *name, size_t namelen, + jsval *vp) { JSAtom *atom; CHECK_REQUEST(cx); atom = js_AtomizeChars(cx, name, AUTO_NAMELEN(name,namelen), 0); if (!atom) - return JS_FALSE; + return JS_FALSE; return OBJ_GET_PROPERTY(cx, obj, (jsid)atom, vp); } JS_PUBLIC_API(JSBool) JS_SetUCProperty(JSContext *cx, JSObject *obj, - const jschar *name, size_t namelen, - jsval *vp) + const jschar *name, size_t namelen, + jsval *vp) { JSAtom *atom; CHECK_REQUEST(cx); atom = js_AtomizeChars(cx, name, AUTO_NAMELEN(name,namelen), 0); if (!atom) - return JS_FALSE; + return JS_FALSE; return OBJ_SET_PROPERTY(cx, obj, (jsid)atom, vp); } JS_PUBLIC_API(JSBool) JS_DeleteUCProperty2(JSContext *cx, JSObject *obj, - const jschar *name, size_t namelen, - jsval *rval) + const jschar *name, size_t namelen, + jsval *rval) { JSAtom *atom; CHECK_REQUEST(cx); atom = js_AtomizeChars(cx, name, AUTO_NAMELEN(name,namelen), 0); if (!atom) - return JS_FALSE; + return JS_FALSE; return OBJ_DELETE_PROPERTY(cx, obj, (jsid)atom, rval); } @@ -2510,11 +2515,11 @@ JS_HasArrayLength(JSContext *cx, JSObject *obj, jsuint *lengthp) JS_PUBLIC_API(JSBool) JS_DefineElement(JSContext *cx, JSObject *obj, jsint index, jsval value, - JSPropertyOp getter, JSPropertyOp setter, uintN attrs) + JSPropertyOp getter, JSPropertyOp setter, uintN attrs) { CHECK_REQUEST(cx); return OBJ_DEFINE_PROPERTY(cx, obj, INT_TO_JSVAL(index), value, - getter, setter, attrs, NULL); + getter, setter, attrs, NULL); } JS_PUBLIC_API(JSBool) @@ -2528,23 +2533,23 @@ JS_AliasElement(JSContext *cx, JSObject *obj, const char *name, jsint alias) CHECK_REQUEST(cx); /* XXXbe push this into jsobj.c or jsscope.c */ if (!LookupProperty(cx, obj, name, &obj2, &prop)) - return JS_FALSE; + return JS_FALSE; if (!prop) { - js_ReportIsNotDefined(cx, name); - return JS_FALSE; + js_ReportIsNotDefined(cx, name); + return JS_FALSE; } if (obj2 != obj || !OBJ_IS_NATIVE(obj2)) { - char numBuf[12]; - OBJ_DROP_PROPERTY(cx, obj2, prop); - JS_snprintf(numBuf, sizeof numBuf, "%ld", (long)alias); - JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_CANT_ALIAS, - numBuf, name, OBJ_GET_CLASS(cx, obj2)->name); - return JS_FALSE; + char numBuf[12]; + OBJ_DROP_PROPERTY(cx, obj2, prop); + JS_snprintf(numBuf, sizeof numBuf, "%ld", (long)alias); + JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_CANT_ALIAS, + numBuf, name, OBJ_GET_CLASS(cx, obj2)->name); + return JS_FALSE; } scope = OBJ_SCOPE(obj); ok = (scope->ops->add(cx, scope, INT_TO_JSVAL(alias), - (JSScopeProperty *)prop) - != NULL); + (JSScopeProperty *)prop) + != NULL); OBJ_DROP_PROPERTY(cx, obj, prop); return ok; } @@ -2559,7 +2564,7 @@ JS_LookupElement(JSContext *cx, JSObject *obj, jsint index, jsval *vp) CHECK_REQUEST(cx); ok = OBJ_LOOKUP_PROPERTY(cx, obj, INT_TO_JSVAL(index), &obj2, &prop); if (ok) - *vp = LookupResult(cx, obj, obj2, prop); + *vp = LookupResult(cx, obj, obj2, prop); return ok; } @@ -2618,10 +2623,10 @@ JS_Enumerate(JSContext *cx, JSObject *obj) /* Get the number of properties to enumerate. */ if (!OBJ_ENUMERATE(cx, obj, JSENUMERATE_INIT, &iter_state, &num_properties)) - goto error; + goto error; if (!JSVAL_IS_INT(num_properties)) { - JS_ASSERT(0); - goto error; + JS_ASSERT(0); + goto error; } /* Grow as needed if we don't know the exact amount ahead of time. */ @@ -2632,42 +2637,42 @@ JS_Enumerate(JSContext *cx, JSObject *obj) /* Create an array of jsids large enough to hold all the properties */ ida = js_NewIdArray(cx, n); if (!ida) - goto error; + goto error; i = 0; vector = &ida->vector[0]; while (1) { - if (i == ida->length) { - /* Grow length by factor of 1.5 instead of doubling. */ - jsint newlen = ida->length + (((jsuint)ida->length + 1) >> 1); - ida = js_GrowIdArray(cx, ida, newlen); - if (!ida) - goto error; - vector = &ida->vector[0]; - } + if (i == ida->length) { + /* Grow length by factor of 1.5 instead of doubling. */ + jsint newlen = ida->length + (((jsuint)ida->length + 1) >> 1); + ida = js_GrowIdArray(cx, ida, newlen); + if (!ida) + goto error; + vector = &ida->vector[0]; + } - if (!OBJ_ENUMERATE(cx, obj, JSENUMERATE_NEXT, &iter_state, &id)) - goto error; + if (!OBJ_ENUMERATE(cx, obj, JSENUMERATE_NEXT, &iter_state, &id)) + goto error; - /* No more jsid's to enumerate ? */ - if (iter_state == JSVAL_NULL) - break; - vector[i++] = id; + /* No more jsid's to enumerate ? */ + if (iter_state == JSVAL_NULL) + break; + vector[i++] = id; } ida->length = i; return ida; error: if (iter_state != JSVAL_NULL) - OBJ_ENUMERATE(cx, obj, JSENUMERATE_DESTROY, &iter_state, 0); + OBJ_ENUMERATE(cx, obj, JSENUMERATE_DESTROY, &iter_state, 0); if (ida) - JS_DestroyIdArray(cx, ida); + JS_DestroyIdArray(cx, ida); return NULL; } JS_PUBLIC_API(JSBool) JS_CheckAccess(JSContext *cx, JSObject *obj, jsid id, JSAccessMode mode, - jsval *vp, uintN *attrsp) + jsval *vp, uintN *attrsp) { CHECK_REQUEST(cx); return OBJ_CHECK_ACCESS(cx, obj, id, mode, vp, attrsp); @@ -2675,18 +2680,18 @@ JS_CheckAccess(JSContext *cx, JSObject *obj, jsid id, JSAccessMode mode, JS_PUBLIC_API(JSFunction *) JS_NewFunction(JSContext *cx, JSNative native, uintN nargs, uintN flags, - JSObject *parent, const char *name) + JSObject *parent, const char *name) { JSAtom *atom; CHECK_REQUEST(cx); if (!name) { - atom = NULL; + atom = NULL; } else { - atom = js_Atomize(cx, name, strlen(name), 0); - if (!atom) - return NULL; + atom = js_Atomize(cx, name, strlen(name), 0); + if (!atom) + return NULL; } return js_NewFunction(cx, NULL, native, nargs, flags, parent, atom); } @@ -2697,7 +2702,7 @@ JS_CloneFunctionObject(JSContext *cx, JSObject *funobj, JSObject *parent) CHECK_REQUEST(cx); if (OBJ_GET_CLASS(cx, funobj) != &js_FunctionClass) { /* Indicate we cannot clone this object. */ - return funobj; + return funobj; } return js_CloneFunctionObject(cx, funobj, parent); } @@ -2712,8 +2717,8 @@ JS_PUBLIC_API(const char *) JS_GetFunctionName(JSFunction *fun) { return fun->atom - ? JS_GetStringBytes(ATOM_TO_STRING(fun->atom)) - : js_anonymous_str; + ? JS_GetStringBytes(ATOM_TO_STRING(fun->atom)) + : js_anonymous_str; } JS_PUBLIC_API(JSBool) @@ -2723,31 +2728,31 @@ JS_DefineFunctions(JSContext *cx, JSObject *obj, JSFunctionSpec *fs) CHECK_REQUEST(cx); for (; fs->name; fs++) { - fun = JS_DefineFunction(cx, obj, fs->name, fs->call, fs->nargs, - fs->flags); - if (!fun) - return JS_FALSE; - fun->extra = fs->extra; + fun = JS_DefineFunction(cx, obj, fs->name, fs->call, fs->nargs, + fs->flags); + if (!fun) + return JS_FALSE; + fun->extra = fs->extra; } return JS_TRUE; } JS_PUBLIC_API(JSFunction *) JS_DefineFunction(JSContext *cx, JSObject *obj, const char *name, JSNative call, - uintN nargs, uintN attrs) + uintN nargs, uintN attrs) { JSAtom *atom; CHECK_REQUEST(cx); atom = js_Atomize(cx, name, strlen(name), 0); if (!atom) - return NULL; + return NULL; return js_DefineFunction(cx, obj, atom, call, nargs, attrs); } static JSScript * CompileTokenStream(JSContext *cx, JSObject *obj, JSTokenStream *ts, - void *tempMark, JSBool *eofp) + void *tempMark, JSBool *eofp) { JSBool eof; JSCodeGenerator cg; @@ -2756,14 +2761,14 @@ CompileTokenStream(JSContext *cx, JSObject *obj, JSTokenStream *ts, CHECK_REQUEST(cx); eof = JS_FALSE; if (!js_InitCodeGenerator(cx, &cg, ts->filename, ts->lineno, - ts->principals)) { - script = NULL; - goto out; + ts->principals)) { + script = NULL; + goto out; } if (!js_CompileTokenStream(cx, obj, ts, &cg)) { - script = NULL; + script = NULL; eof = (ts->flags & TSF_EOF) != 0; - goto out; + goto out; } script = js_NewScriptFromCG(cx, &cg, NULL); out: @@ -2771,8 +2776,8 @@ out: *eofp = eof; if (!js_CloseTokenStream(cx, ts)) { if (script) - js_DestroyScript(cx, script); - script = NULL; + js_DestroyScript(cx, script); + script = NULL; } cg.tempMark = tempMark; js_FinishCodeGenerator(cx, &cg); @@ -2781,8 +2786,8 @@ out: JS_PUBLIC_API(JSScript *) JS_CompileScript(JSContext *cx, JSObject *obj, - const char *bytes, size_t length, - const char *filename, uintN lineno) + const char *bytes, size_t length, + const char *filename, uintN lineno) { jschar *chars; JSScript *script; @@ -2790,7 +2795,7 @@ JS_CompileScript(JSContext *cx, JSObject *obj, CHECK_REQUEST(cx); chars = js_InflateString(cx, bytes, length); if (!chars) - return NULL; + return NULL; script = JS_CompileUCScript(cx, obj, chars, length, filename, lineno); JS_free(cx, chars); return script; @@ -2798,9 +2803,9 @@ JS_CompileScript(JSContext *cx, JSObject *obj, JS_PUBLIC_API(JSScript *) JS_CompileScriptForPrincipals(JSContext *cx, JSObject *obj, - JSPrincipals *principals, - const char *bytes, size_t length, - const char *filename, uintN lineno) + JSPrincipals *principals, + const char *bytes, size_t length, + const char *filename, uintN lineno) { jschar *chars; JSScript *script; @@ -2808,28 +2813,28 @@ JS_CompileScriptForPrincipals(JSContext *cx, JSObject *obj, CHECK_REQUEST(cx); chars = js_InflateString(cx, bytes, length); if (!chars) - return NULL; + return NULL; script = JS_CompileUCScriptForPrincipals(cx, obj, principals, - chars, length, filename, lineno); + chars, length, filename, lineno); JS_free(cx, chars); return script; } JS_PUBLIC_API(JSScript *) JS_CompileUCScript(JSContext *cx, JSObject *obj, - const jschar *chars, size_t length, - const char *filename, uintN lineno) + const jschar *chars, size_t length, + const char *filename, uintN lineno) { CHECK_REQUEST(cx); return JS_CompileUCScriptForPrincipals(cx, obj, NULL, chars, length, - filename, lineno); + filename, lineno); } JS_PUBLIC_API(JSScript *) JS_CompileUCScriptForPrincipals(JSContext *cx, JSObject *obj, - JSPrincipals *principals, - const jschar *chars, size_t length, - const char *filename, uintN lineno) + JSPrincipals *principals, + const jschar *chars, size_t length, + const char *filename, uintN lineno) { void *mark; JSTokenStream *ts; @@ -2838,7 +2843,7 @@ JS_CompileUCScriptForPrincipals(JSContext *cx, JSObject *obj, mark = JS_ARENA_MARK(&cx->tempPool); ts = js_NewTokenStream(cx, chars, length, filename, lineno, principals); if (!ts) - return NULL; + return NULL; return CompileTokenStream(cx, obj, ts, mark, NULL); } @@ -2858,7 +2863,7 @@ JS_BufferIsCompilableUnit(JSContext *cx, JSObject *obj, mark = JS_ARENA_MARK(&cx->tempPool); chars = js_InflateString(cx, bytes, length); if (!chars) - return JS_TRUE; + return JS_TRUE; exnState = JS_SaveExceptionState(cx); ts = js_NewTokenStream(cx, chars, length, NULL, 0, NULL); if (!ts) { @@ -2899,7 +2904,7 @@ JS_CompileFile(JSContext *cx, JSObject *obj, const char *filename) mark = JS_ARENA_MARK(&cx->tempPool); ts = js_NewFileTokenStream(cx, filename, stdin); if (!ts) - return NULL; + return NULL; return CompileTokenStream(cx, obj, ts, mark, NULL); } @@ -2922,7 +2927,7 @@ JS_CompileFileHandleForPrincipals(JSContext *cx, JSObject *obj, mark = JS_ARENA_MARK(&cx->tempPool); ts = js_NewFileTokenStream(cx, NULL, fh); if (!ts) - return NULL; + return NULL; ts->filename = filename; /* XXXshaver js_NewFileTokenStream should do this, because it drops */ if (principals) { @@ -2940,11 +2945,11 @@ JS_NewScriptObject(JSContext *cx, JSScript *script) CHECK_REQUEST(cx); obj = js_NewObject(cx, &js_ScriptClass, NULL, NULL); if (!obj) - return NULL; + return NULL; if (script) { - if (!JS_SetPrivate(cx, obj, script)) - return NULL; - script->object = obj; + if (!JS_SetPrivate(cx, obj, script)) + return NULL; + script->object = obj; } return obj; } @@ -2958,9 +2963,9 @@ JS_DestroyScript(JSContext *cx, JSScript *script) JS_PUBLIC_API(JSFunction *) JS_CompileFunction(JSContext *cx, JSObject *obj, const char *name, - uintN nargs, const char **argnames, - const char *bytes, size_t length, - const char *filename, uintN lineno) + uintN nargs, const char **argnames, + const char *bytes, size_t length, + const char *filename, uintN lineno) { jschar *chars; JSFunction *fun; @@ -2968,19 +2973,19 @@ JS_CompileFunction(JSContext *cx, JSObject *obj, const char *name, CHECK_REQUEST(cx); chars = js_InflateString(cx, bytes, length); if (!chars) - return NULL; + return NULL; fun = JS_CompileUCFunction(cx, obj, name, nargs, argnames, chars, length, - filename, lineno); + filename, lineno); JS_free(cx, chars); return fun; } JS_PUBLIC_API(JSFunction *) JS_CompileFunctionForPrincipals(JSContext *cx, JSObject *obj, - JSPrincipals *principals, const char *name, - uintN nargs, const char **argnames, - const char *bytes, size_t length, - const char *filename, uintN lineno) + JSPrincipals *principals, const char *name, + uintN nargs, const char **argnames, + const char *bytes, size_t length, + const char *filename, uintN lineno) { jschar *chars; JSFunction *fun; @@ -2988,33 +2993,33 @@ JS_CompileFunctionForPrincipals(JSContext *cx, JSObject *obj, CHECK_REQUEST(cx); chars = js_InflateString(cx, bytes, length); if (!chars) - return NULL; + return NULL; fun = JS_CompileUCFunctionForPrincipals(cx, obj, principals, name, - nargs, argnames, chars, length, - filename, lineno); + nargs, argnames, chars, length, + filename, lineno); JS_free(cx, chars); return fun; } JS_PUBLIC_API(JSFunction *) JS_CompileUCFunction(JSContext *cx, JSObject *obj, const char *name, - uintN nargs, const char **argnames, - const jschar *chars, size_t length, - const char *filename, uintN lineno) + uintN nargs, const char **argnames, + const jschar *chars, size_t length, + const char *filename, uintN lineno) { CHECK_REQUEST(cx); return JS_CompileUCFunctionForPrincipals(cx, obj, NULL, name, - nargs, argnames, - chars, length, - filename, lineno); + nargs, argnames, + chars, length, + filename, lineno); } JS_PUBLIC_API(JSFunction *) JS_CompileUCFunctionForPrincipals(JSContext *cx, JSObject *obj, - JSPrincipals *principals, const char *name, - uintN nargs, const char **argnames, - const jschar *chars, size_t length, - const char *filename, uintN lineno) + JSPrincipals *principals, const char *name, + uintN nargs, const char **argnames, + const jschar *chars, size_t length, + const char *filename, uintN lineno) { void *mark; JSTokenStream *ts; @@ -3027,43 +3032,43 @@ JS_CompileUCFunctionForPrincipals(JSContext *cx, JSObject *obj, mark = JS_ARENA_MARK(&cx->tempPool); ts = js_NewTokenStream(cx, chars, length, filename, lineno, principals); if (!ts) { - fun = NULL; - goto out; + fun = NULL; + goto out; } if (!name) { - funAtom = NULL; + funAtom = NULL; } else { - funAtom = js_Atomize(cx, name, strlen(name), 0); - if (!funAtom) { - fun = NULL; - goto out; - } + funAtom = js_Atomize(cx, name, strlen(name), 0); + if (!funAtom) { + fun = NULL; + goto out; + } } fun = js_NewFunction(cx, NULL, NULL, nargs, 0, obj, funAtom); if (!fun) - goto out; + goto out; if (nargs) { - for (i = 0; i < nargs; i++) { - argAtom = js_Atomize(cx, argnames[i], strlen(argnames[i]), 0); - if (!argAtom) - break; - if (!js_DefineProperty(cx, fun->object, (jsid)argAtom, - JSVAL_VOID, js_GetArgument, js_SetArgument, - JSPROP_ENUMERATE|JSPROP_PERMANENT, - (JSProperty **)&sprop)) { - break; - } - JS_ASSERT(sprop); - sprop->id = INT_TO_JSVAL(i); - OBJ_DROP_PROPERTY(cx, fun->object, (JSProperty *)sprop); - } - if (i < nargs) { - fun = NULL; - goto out; - } + for (i = 0; i < nargs; i++) { + argAtom = js_Atomize(cx, argnames[i], strlen(argnames[i]), 0); + if (!argAtom) + break; + if (!js_DefineProperty(cx, fun->object, (jsid)argAtom, + JSVAL_VOID, js_GetArgument, js_SetArgument, + JSPROP_ENUMERATE|JSPROP_PERMANENT, + (JSProperty **)&sprop)) { + break; + } + JS_ASSERT(sprop); + sprop->id = INT_TO_JSVAL(i); + OBJ_DROP_PROPERTY(cx, fun->object, (JSProperty *)sprop); + } + if (i < nargs) { + fun = NULL; + goto out; + } } if (!js_CompileFunctionBody(cx, ts, fun)) { - fun = NULL; + fun = NULL; goto out; } if (funAtom) { @@ -3075,14 +3080,14 @@ JS_CompileUCFunctionForPrincipals(JSContext *cx, JSObject *obj, } out: if (ts) - js_CloseTokenStream(cx, ts); + js_CloseTokenStream(cx, ts); JS_ARENA_RELEASE(&cx->tempPool, mark); return fun; } JS_PUBLIC_API(JSString *) JS_DecompileScript(JSContext *cx, JSScript *script, const char *name, - uintN indent) + uintN indent) { JSPrinter *jp; JSString *str; @@ -3092,11 +3097,11 @@ JS_DecompileScript(JSContext *cx, JSScript *script, const char *name, indent & ~JS_DONT_PRETTY_PRINT, !(indent & JS_DONT_PRETTY_PRINT)); if (!jp) - return NULL; + return NULL; if (js_DecompileScript(jp, script)) - str = js_GetPrinterOutput(jp); + str = js_GetPrinterOutput(jp); else - str = NULL; + str = NULL; js_DestroyPrinter(jp); return str; } @@ -3112,11 +3117,11 @@ JS_DecompileFunction(JSContext *cx, JSFunction *fun, uintN indent) indent & ~JS_DONT_PRETTY_PRINT, !(indent & JS_DONT_PRETTY_PRINT)); if (!jp) - return NULL; + return NULL; if (js_DecompileFunction(jp, fun)) - str = js_GetPrinterOutput(jp); + str = js_GetPrinterOutput(jp); else - str = NULL; + str = NULL; js_DestroyPrinter(jp); return str; } @@ -3132,11 +3137,11 @@ JS_DecompileFunctionBody(JSContext *cx, JSFunction *fun, uintN indent) indent & ~JS_DONT_PRETTY_PRINT, !(indent & JS_DONT_PRETTY_PRINT)); if (!jp) - return NULL; + return NULL; if (js_DecompileFunctionBody(jp, fun)) - str = js_GetPrinterOutput(jp); + str = js_GetPrinterOutput(jp); else - str = NULL; + str = NULL; js_DestroyPrinter(jp); return str; } @@ -3187,9 +3192,9 @@ JS_ExecuteScriptPart(JSContext *cx, JSObject *obj, JSScript *script, JS_PUBLIC_API(JSBool) JS_EvaluateScript(JSContext *cx, JSObject *obj, - const char *bytes, uintN length, - const char *filename, uintN lineno, - jsval *rval) + const char *bytes, uintN length, + const char *filename, uintN lineno, + jsval *rval) { jschar *chars; JSBool ok; @@ -3197,7 +3202,7 @@ JS_EvaluateScript(JSContext *cx, JSObject *obj, CHECK_REQUEST(cx); chars = js_InflateString(cx, bytes, length); if (!chars) - return JS_FALSE; + return JS_FALSE; ok = JS_EvaluateUCScript(cx, obj, chars, length, filename, lineno, rval); JS_free(cx, chars); return ok; @@ -3205,10 +3210,10 @@ JS_EvaluateScript(JSContext *cx, JSObject *obj, JS_PUBLIC_API(JSBool) JS_EvaluateScriptForPrincipals(JSContext *cx, JSObject *obj, - JSPrincipals *principals, - const char *bytes, uintN length, - const char *filename, uintN lineno, - jsval *rval) + JSPrincipals *principals, + const char *bytes, uintN length, + const char *filename, uintN lineno, + jsval *rval) { jschar *chars; JSBool ok; @@ -3216,39 +3221,39 @@ JS_EvaluateScriptForPrincipals(JSContext *cx, JSObject *obj, CHECK_REQUEST(cx); chars = js_InflateString(cx, bytes, length); if (!chars) - return JS_FALSE; + return JS_FALSE; ok = JS_EvaluateUCScriptForPrincipals(cx, obj, principals, chars, length, - filename, lineno, rval); + filename, lineno, rval); JS_free(cx, chars); return ok; } JS_PUBLIC_API(JSBool) JS_EvaluateUCScript(JSContext *cx, JSObject *obj, - const jschar *chars, uintN length, - const char *filename, uintN lineno, - jsval *rval) + const jschar *chars, uintN length, + const char *filename, uintN lineno, + jsval *rval) { CHECK_REQUEST(cx); return JS_EvaluateUCScriptForPrincipals(cx, obj, NULL, chars, length, - filename, lineno, rval); + filename, lineno, rval); } JS_PUBLIC_API(JSBool) JS_EvaluateUCScriptForPrincipals(JSContext *cx, JSObject *obj, - JSPrincipals *principals, - const jschar *chars, uintN length, - const char *filename, uintN lineno, - jsval *rval) + JSPrincipals *principals, + const jschar *chars, uintN length, + const char *filename, uintN lineno, + jsval *rval) { JSScript *script; JSBool ok; CHECK_REQUEST(cx); script = JS_CompileUCScriptForPrincipals(cx, obj, principals, chars, length, - filename, lineno); + filename, lineno); if (!script) - return JS_FALSE; + return JS_FALSE; ok = js_Execute(cx, obj, script, NULL, 0, rval); #if JS_HAS_EXCEPTIONS if (!ok) @@ -3260,11 +3265,11 @@ JS_EvaluateUCScriptForPrincipals(JSContext *cx, JSObject *obj, JS_PUBLIC_API(JSBool) JS_CallFunction(JSContext *cx, JSObject *obj, JSFunction *fun, uintN argc, - jsval *argv, jsval *rval) + jsval *argv, jsval *rval) { CHECK_REQUEST(cx); if (!js_InternalCall(cx, obj, OBJECT_TO_JSVAL(fun->object), argc, argv, - rval)) { + rval)) { #if JS_HAS_EXCEPTIONS js_ReportUncaughtException(cx); #endif @@ -3275,13 +3280,13 @@ JS_CallFunction(JSContext *cx, JSObject *obj, JSFunction *fun, uintN argc, JS_PUBLIC_API(JSBool) JS_CallFunctionName(JSContext *cx, JSObject *obj, const char *name, uintN argc, - jsval *argv, jsval *rval) + jsval *argv, jsval *rval) { jsval fval; CHECK_REQUEST(cx); if (!JS_GetProperty(cx, obj, name, &fval)) - return JS_FALSE; + return JS_FALSE; if (!js_InternalCall(cx, obj, fval, argc, argv, rval)) { #if JS_HAS_EXCEPTIONS js_ReportUncaughtException(cx); @@ -3293,7 +3298,7 @@ JS_CallFunctionName(JSContext *cx, JSObject *obj, const char *name, uintN argc, JS_PUBLIC_API(JSBool) JS_CallFunctionValue(JSContext *cx, JSObject *obj, jsval fval, uintN argc, - jsval *argv, jsval *rval) + jsval *argv, jsval *rval) { CHECK_REQUEST(cx); if (!js_InternalCall(cx, obj, fval, argc, argv, rval)) { @@ -3336,7 +3341,7 @@ JS_IsAssigning(JSContext *cx) for (fp = cx->fp; fp && !fp->script; fp = fp->down) ; if (!fp || !(pc = fp->pc)) - return JS_FALSE; + return JS_FALSE; return (js_CodeSpec[*pc].format & JOF_SET) != 0; } @@ -3361,18 +3366,18 @@ JS_NewString(JSContext *cx, char *bytes, size_t length) /* Make a Unicode vector from the 8-bit char codes in bytes. */ chars = js_InflateString(cx, bytes, length); if (!chars) - return NULL; + return NULL; /* Free chars (but not bytes, which caller frees on error) if we fail. */ str = js_NewString(cx, chars, length, 0); if (!str) { - JS_free(cx, chars); - return NULL; + JS_free(cx, chars); + return NULL; } /* Hand off bytes to the deflated string cache, if possible. */ if (!js_SetStringBytes(str, bytes, length)) - JS_free(cx, bytes); + JS_free(cx, bytes); return str; } @@ -3385,10 +3390,10 @@ JS_NewStringCopyN(JSContext *cx, const char *s, size_t n) CHECK_REQUEST(cx); js = js_InflateString(cx, s, n); if (!js) - return NULL; + return NULL; str = js_NewString(cx, js, n, 0); if (!str) - JS_free(cx, js); + JS_free(cx, js); return str; } @@ -3401,14 +3406,14 @@ JS_NewStringCopyZ(JSContext *cx, const char *s) CHECK_REQUEST(cx); if (!s) - return cx->runtime->emptyString; + return cx->runtime->emptyString; n = strlen(s); js = js_InflateString(cx, s, n); if (!js) - return NULL; + return NULL; str = js_NewString(cx, js, n, 0); if (!str) - JS_free(cx, js); + JS_free(cx, js); return str; } @@ -3420,7 +3425,7 @@ JS_InternString(JSContext *cx, const char *s) CHECK_REQUEST(cx); atom = js_Atomize(cx, s, strlen(s), ATOM_INTERNED); if (!atom) - return NULL; + return NULL; return ATOM_TO_STRING(atom); } @@ -3443,7 +3448,7 @@ JS_NewUCStringCopyZ(JSContext *cx, const jschar *s) { CHECK_REQUEST(cx); if (!s) - return cx->runtime->emptyString; + return cx->runtime->emptyString; return js_NewStringCopyZ(cx, s, 0); } @@ -3455,7 +3460,7 @@ JS_InternUCStringN(JSContext *cx, const jschar *s, size_t length) CHECK_REQUEST(cx); atom = js_AtomizeChars(cx, s, length, ATOM_INTERNED); if (!atom) - return NULL; + return NULL; return ATOM_TO_STRING(atom); } @@ -3504,25 +3509,25 @@ JS_ReportError(JSContext *cx, const char *format, ...) JS_PUBLIC_API(void) JS_ReportErrorNumber(JSContext *cx, JSErrorCallback errorCallback, - void *userRef, const uintN errorNumber, ...) + void *userRef, const uintN errorNumber, ...) { va_list ap; va_start(ap, errorNumber); js_ReportErrorNumberVA(cx, JSREPORT_ERROR, errorCallback, userRef, - errorNumber, JS_TRUE, ap); + errorNumber, JS_TRUE, ap); va_end(ap); } JS_PUBLIC_API(void) JS_ReportErrorNumberUC(JSContext *cx, JSErrorCallback errorCallback, - void *userRef, const uintN errorNumber, ...) + void *userRef, const uintN errorNumber, ...) { va_list ap; va_start(ap, errorNumber); js_ReportErrorNumberVA(cx, JSREPORT_ERROR, errorCallback, userRef, - errorNumber, JS_FALSE, ap); + errorNumber, JS_FALSE, ap); va_end(ap); } @@ -3599,7 +3604,7 @@ JS_NewRegExpObject(JSContext *cx, char *bytes, size_t length, uintN flags) CHECK_REQUEST(cx); chars = js_InflateString(cx, bytes, length); if (!chars) - return NULL; + return NULL; obj = js_NewRegExpObject(cx, NULL, chars, length, flags); JS_free(cx, chars); return obj; @@ -3694,7 +3699,7 @@ JS_GetPendingException(JSContext *cx, jsval *vp) #if JS_HAS_EXCEPTIONS CHECK_REQUEST(cx); if (!cx->throwing) - return JS_FALSE; + return JS_FALSE; *vp = cx->exception; return JS_TRUE; #else @@ -3837,7 +3842,7 @@ BOOL WINAPI DllMain (HINSTANCE hDLL, DWORD dwReason, LPVOID lpReserved) #else /* !_WIN32 */ int CALLBACK LibMain( HINSTANCE hInst, WORD wDataSeg, - WORD cbHeapSize, LPSTR lpszCmdLine ) + WORD cbHeapSize, LPSTR lpszCmdLine ) { return TRUE; } diff --git a/js/src/jsapi.h b/js/src/jsapi.h index 4e675d77078..71bd10caf62 100644 --- a/js/src/jsapi.h +++ b/js/src/jsapi.h @@ -556,7 +556,7 @@ JS_DumpNamedRoots(JSRuntime *rt, typedef intN (* JS_DLL_CALLBACK JSGCRootMapFun)(void *rp, const char *name, void *data); -extern JS_PUBLIC_API(intN) +extern JS_PUBLIC_API(uint32) JS_MapGCRoots(JSRuntime *rt, JSGCRootMapFun map, void *data); extern JS_PUBLIC_API(JSBool) diff --git a/js/src/jscntxt.h b/js/src/jscntxt.h index 54db0ff6b81..fafc3b8cc21 100644 --- a/js/src/jscntxt.h +++ b/js/src/jscntxt.h @@ -66,8 +66,8 @@ struct JSRuntime { /* Garbage collector state, used by jsgc.c. */ JSArenaPool gcArenaPool; - JSHashTable *gcRootsHash; - JSHashTable *gcLocksHash; + JSDHashTable gcRootsHash; + JSDHashTable *gcLocksHash; JSGCThing *gcFreeList; jsrefcount gcDisabled; uint32 gcBytes; diff --git a/js/src/jsgc.c b/js/src/jsgc.c index 36ec0b2a91d..a5caac61250 100644 --- a/js/src/jsgc.c +++ b/js/src/jsgc.c @@ -249,8 +249,6 @@ js_ChangeExternalStringFinalizer(JSStringFinalizeOp oldop, #define GC_ROOTS_SIZE 256 #define GC_FINALIZE_LEN 1024 -static JSHashNumber gc_hash_root(const void *key); - JSBool js_InitGC(JSRuntime *rt, uint32 maxbytes) { @@ -271,11 +269,10 @@ js_InitGC(JSRuntime *rt, uint32 maxbytes) JS_InitArenaPool(&rt->gcArenaPool, "gc-arena", GC_ARENA_SIZE, sizeof(JSGCThing)); - rt->gcRootsHash = JS_NewHashTable(GC_ROOTS_SIZE, gc_hash_root, - JS_CompareValues, JS_CompareValues, - NULL, NULL); - if (!rt->gcRootsHash) - return JS_FALSE; + if (!JS_DHashTableInit(&rt->gcRootsHash, JS_DHashGetStubOps(), NULL, + sizeof(JSGCRootHashEntry), GC_ROOTS_SIZE)) { + return JS_FALSE; + } rt->gcLocksHash = NULL; /* create lazily */ rt->gcMaxBytes = maxbytes; return JS_TRUE; @@ -311,17 +308,18 @@ js_DumpGCStats(JSRuntime *rt, FILE *fp) #endif #if DEBUG -JS_STATIC_DLL_CALLBACK(intN) -js_root_printer(JSHashEntry *he, intN i, void *arg) +JS_STATIC_DLL_CALLBACK(JSDHashOperator) +js_root_printer(JSDHashTable *table, JSDHashEntryHdr *hdr, uint32 i, void *arg) { uint32 *leakedroots = (uint32 *)arg; + JSGCRootHashEntry *rhe = (JSGCRootHashEntry *)hdr; - *leakedroots += 1; + (*leakedroots)++; fprintf(stderr, "JS engine warning: leaking GC root \'%s\' at %p\n", - he->value ? (char *)he->value : "", he->key); + rhe->name ? (char *)rhe->name : "", rhe->root); - return HT_ENUMERATE_NEXT; + return JS_DHASH_NEXT; } #endif @@ -342,8 +340,8 @@ js_FinishGC(JSRuntime *rt) uint32 leakedroots = 0; /* Warn (but don't assert) debug builds of any remaining roots. */ - JS_HashTableEnumerateEntries(rt->gcRootsHash, js_root_printer, - &leakedroots); + JS_DHashTableEnumerate(&rt->gcRootsHash, js_root_printer, + &leakedroots); if (leakedroots > 0) { if (leakedroots == 1) { fprintf(stderr, @@ -361,10 +359,9 @@ js_FinishGC(JSRuntime *rt) } #endif - JS_HashTableDestroy(rt->gcRootsHash); - rt->gcRootsHash = NULL; + JS_DHashTableFinish(&rt->gcRootsHash); if (rt->gcLocksHash) { - JS_HashTableDestroy(rt->gcLocksHash); + JS_DHashTableDestroy(rt->gcLocksHash); rt->gcLocksHash = NULL; } rt->gcFreeList = NULL; @@ -383,6 +380,7 @@ JSBool js_AddRootRT(JSRuntime *rt, void *rp, const char *name) { JSBool ok; + JSGCRootHashEntry *rhe; /* * Due to the long-standing, but now removed, use of rt->gcLock across the @@ -406,7 +404,15 @@ js_AddRootRT(JSRuntime *rt, void *rp, const char *name) } while (rt->gcLevel > 0); } #endif - ok = (JS_HashTableAdd(rt->gcRootsHash, rp, (void *)name) != NULL); + rhe = (JSGCRootHashEntry *) JS_DHashTableOperate(&rt->gcRootsHash, rp, + JS_DHASH_ADD); + if (rhe) { + rhe->root = rp; + rhe->name = name; + ok = JS_TRUE; + } else { + ok = JS_FALSE; + } JS_UNLOCK_GC(rt); return ok; } @@ -427,7 +433,7 @@ js_RemoveRoot(JSRuntime *rt, void *rp) } while (rt->gcLevel > 0); } #endif - JS_HashTableRemove(rt->gcRootsHash, rp); + (void) JS_DHashTableOperate(&rt->gcRootsHash, rp, JS_DHASH_REMOVE); rt->gcPoke = JS_TRUE; JS_UNLOCK_GC(rt); return JS_TRUE; @@ -528,26 +534,13 @@ retry: return thing; } -static JSHashNumber -gc_hash_thing(const void *key) -{ - JSHashNumber num = (JSHashNumber) key; /* help lame MSVC1.5 on Win16 */ - - return num >> JSVAL_TAGBITS; -} - -#define gc_lock_get_count(he) ((jsrefcount)(he)->value) -#define gc_lock_set_count(he,n) ((jsrefcount)((he)->value = (void *)(n))) -#define gc_lock_increment(he) gc_lock_set_count(he, gc_lock_get_count(he)+1) -#define gc_lock_decrement(he) gc_lock_set_count(he, gc_lock_get_count(he)-1) - JSBool js_LockGCThing(JSContext *cx, void *thing) { JSRuntime *rt; uint8 *flagp, flags, lockbits; JSBool ok; - JSHashEntry **hep, *he; + JSGCLockHashEntry *lhe; if (!thing) return JS_TRUE; @@ -564,31 +557,36 @@ js_LockGCThing(JSContext *cx, void *thing) /* Objects may require "deep locking", i.e., rooting by value. */ if (lockbits == 0) { if (!rt->gcLocksHash) { - rt->gcLocksHash = JS_NewHashTable(GC_ROOTS_SIZE, - gc_hash_thing, - JS_CompareValues, - JS_CompareValues, - NULL, NULL); + rt->gcLocksHash = + JS_NewDHashTable(JS_DHashGetStubOps(), NULL, + sizeof(JSGCLockHashEntry), + GC_ROOTS_SIZE); if (!rt->gcLocksHash) goto outofmem; } else { - JS_ASSERT(!JS_HashTableLookup(rt->gcLocksHash, thing)); +#ifdef DEBUG + JSDHashEntryHdr *hdr = + JS_DHashTableOperate(rt->gcLocksHash, thing, + JS_DHASH_LOOKUP); + JS_ASSERT(JS_DHASH_ENTRY_IS_FREE(hdr)); +#endif } - he = JS_HashTableAdd(rt->gcLocksHash, thing, NULL); - if (!he) + lhe = (JSGCLockHashEntry *) + JS_DHashTableOperate(rt->gcLocksHash, thing, JS_DHASH_ADD); + if (!lhe) goto outofmem; - gc_lock_set_count(he, 1); + lhe->thing = thing; + lhe->count = 1; *flagp = (uint8)(flags + GCF_LOCK); } else { JS_ASSERT(lockbits == GCF_LOCK); - hep = JS_HashTableRawLookup(rt->gcLocksHash, - gc_hash_thing(thing), - thing); - he = *hep; - JS_ASSERT(he); - if (he) { - JS_ASSERT(gc_lock_get_count(he) >= 1); - gc_lock_increment(he); + lhe = (JSGCLockHashEntry *) + JS_DHashTableOperate(rt->gcLocksHash, thing, + JS_DHASH_LOOKUP); + JS_ASSERT(JS_DHASH_ENTRY_IS_BUSY(&lhe->hdr)); + if (JS_DHASH_ENTRY_IS_BUSY(&lhe->hdr) { + JS_ASSERT(lhe->count >= 1); + lhe->count++; } } } else { @@ -614,7 +612,7 @@ js_UnlockGCThing(JSContext *cx, void *thing) { JSRuntime *rt; uint8 *flagp, flags, lockbits; - JSHashEntry **hep, *he; + JSGCLockHashEntry *lhe; if (!thing) return JS_TRUE; @@ -630,13 +628,14 @@ js_UnlockGCThing(JSContext *cx, void *thing) /* Defend against a call on an unlocked object. */ if (lockbits != 0) { JS_ASSERT(lockbits == GCF_LOCK); - hep = JS_HashTableRawLookup(rt->gcLocksHash, - gc_hash_thing(thing), - thing); - he = *hep; - JS_ASSERT(he); - if (he && gc_lock_decrement(he) == 0) { - JS_HashTableRawRemove(rt->gcLocksHash, hep, he); + lhe = (JSGCLockHashEntry *) + JS_DHashTableOperate(rt->gcLocksHash, thing, + JS_DHASH_LOOKUP); + JS_ASSERT(JS_DHASH_ENTRY_IS_BUSY(&lhe->hdr)); + if (JS_DHASH_ENTRY_IS_BUSY(&lhe->hdr) && + --lhe->count == 0) { + (void) JS_DHashTableOperate(rt->gcLocksHash, thing, + JS_DHASH_REMOVE); *flagp = (uint8)(flags & ~GCF_LOCKMASK); } } @@ -884,18 +883,11 @@ out: METER(rt->gcStats.depth--); } -static JSHashNumber -gc_hash_root(const void *key) +JS_STATIC_DLL_CALLBACK(JSDHashOperator) +gc_root_marker(JSDHashTable *table, JSDHashEntryHdr *hdr, uint32 num, void *arg) { - JSHashNumber num = (JSHashNumber) key; /* help lame MSVC1.5 on Win16 */ - - return num >> 2; -} - -JS_STATIC_DLL_CALLBACK(intN) -gc_root_marker(JSHashEntry *he, intN i, void *arg) -{ - jsval *rp = (jsval *)he->key; + JSGCRootHashEntry *rhe = (JSGCRootHashEntry *)hdr; + jsval *rp = (jsval *)rhe->root; jsval v = *rp; /* Ignore null object and scalar values. */ @@ -914,29 +906,30 @@ gc_root_marker(JSHashEntry *he, intN i, void *arg) break; } } - if (!root_points_to_gcArenaPool && he->value) { + if (!root_points_to_gcArenaPool && rhe->name) { fprintf(stderr, "JS API usage error: the address passed to JS_AddNamedRoot currently holds an\n" "invalid jsval. This is usually caused by a missing call to JS_RemoveRoot.\n" "The root's name is \"%s\".\n", - (const char *) he->value); + rhe->name); } JS_ASSERT(root_points_to_gcArenaPool); #endif - GC_MARK(cx, JSVAL_TO_GCTHING(v), he->value ? he->value : "root", NULL); + GC_MARK(cx, JSVAL_TO_GCTHING(v), rhe->name ? rhe->name : "root", NULL); } - return HT_ENUMERATE_NEXT; + return JS_DHASH_NEXT; } -JS_STATIC_DLL_CALLBACK(intN) -gc_lock_marker(JSHashEntry *he, intN i, void *arg) +JS_STATIC_DLL_CALLBACK(JSDHashOperator) +gc_lock_marker(JSDHashTable *table, JSDHashEntryHdr *hdr, uint32 num, void *arg) { - void *thing = (void *)he->key; + JSGCLockHashEntry *lhe = (JSGCLockHashEntry *)hdr; + void *thing = (void *)lhe->thing; JSContext *cx = (JSContext *)arg; GC_MARK(cx, thing, "locked object", NULL); - return HT_ENUMERATE_NEXT; + return JS_DHASH_NEXT; } JS_FRIEND_API(void) @@ -1116,9 +1109,9 @@ restart: /* * Mark phase. */ - JS_HashTableEnumerateEntries(rt->gcRootsHash, gc_root_marker, cx); + JS_DHashTableEnumerate(&rt->gcRootsHash, gc_root_marker, cx); if (rt->gcLocksHash) - JS_HashTableEnumerateEntries(rt->gcLocksHash, gc_lock_marker, cx); + JS_DHashTableEnumerate(rt->gcLocksHash, gc_lock_marker, cx); js_MarkAtomState(&rt->atomState, gcflags, gc_mark_atom_key_thing, cx); iter = NULL; while ((acx = js_ContextIterator(rt, &iter)) != NULL) { diff --git a/js/src/jsgc.h b/js/src/jsgc.h index 3044278f646..0c874aeb994 100644 --- a/js/src/jsgc.h +++ b/js/src/jsgc.h @@ -58,6 +58,19 @@ JS_BEGIN_EXTERN_C #define GCF_LOCKMASK (JS_BITMASK(8 - GCF_LOCKSHIFT) << GCF_LOCKSHIFT) #define GCF_LOCK JS_BIT(GCF_LOCKSHIFT) /* lock request bit in API */ +/* These are compatible with JSDHashEntryStub. */ +struct JSGCRootHashEntry { + JSDHashEntryHdr hdr; + void *root; + const char *name; +}; + +struct JSGCLockHashEntry { + JSDHashEntryHdr hdr; + const JSGCThing *thing; + uint32 count; +}; + #if 1 /* * Since we're forcing a GC from JS_GC anyway, don't bother wasting cycles diff --git a/js/src/jsprvtd.h b/js/src/jsprvtd.h index 13c33efe937..2aeac2f1aae 100644 --- a/js/src/jsprvtd.h +++ b/js/src/jsprvtd.h @@ -59,6 +59,8 @@ typedef uint32 jsatomid; /* Struct typedefs. */ typedef struct JSArgumentFormatMap JSArgumentFormatMap; typedef struct JSCodeGenerator JSCodeGenerator; +typedef struct JSGCLockHashEntry JSGCLockHashEntry; +typedef struct JSGCRootHashEntry JSGCRootHashEntry; typedef struct JSGCThing JSGCThing; typedef struct JSParseNode JSParseNode; typedef struct JSSharpObjectMap JSSharpObjectMap;