Index: ossp-pkg/js/src/.cvsignore RCS File: /v/ossp/cvs/ossp-pkg/js/src/.cvsignore,v rcsdiff -q -kk '-r1.1' '-r1.2' -u '/v/ossp/cvs/ossp-pkg/js/src/.cvsignore,v' 2>/dev/null --- .cvsignore 2006/07/22 11:38:55 1.1 +++ .cvsignore 2006/07/24 18:38:26 1.2 @@ -1,2 +1,9 @@ +*.pdb +*.ncb +*.opt +*.plg +Debug +Release +Makefile +jscpucfg jsautocfg.h -*.lo Index: ossp-pkg/js/src/fdlibm/.cvsignore RCS File: /v/ossp/cvs/ossp-pkg/js/src/fdlibm/.cvsignore,v rcsdiff -q -kk '-r1.1' '-r1.2' -u '/v/ossp/cvs/ossp-pkg/js/src/fdlibm/.cvsignore,v' 2>/dev/null --- .cvsignore 2006/07/22 11:38:55 1.1 +++ .cvsignore 2006/07/24 18:38:27 1.2 @@ -1 +1,7 @@ -*.lo +*.pdb +*.ncb +*.opt +*.plg +Debug +Release +Makefile Index: ossp-pkg/js/src/fdlibm/fdlibm.h RCS File: /v/ossp/cvs/ossp-pkg/js/src/fdlibm/fdlibm.h,v rcsdiff -q -kk '-r1.2' '-r1.3' -u '/v/ossp/cvs/ossp-pkg/js/src/fdlibm/fdlibm.h,v' 2>/dev/null --- fdlibm.h 2006/07/22 13:48:03 1.2 +++ fdlibm.h 2006/07/24 18:38:28 1.3 @@ -152,7 +152,7 @@ #define __LITTLE_ENDIAN #endif -#if defined(linux) && (defined(__i386__) || defined(__x86_64__) || defined(__ia64) || (defined(__mips) && defined(__MIPSEL__))) +#if defined(linux) && (defined(__i386__) || defined(__x86_64__) || defined(__ia64)) #define __LITTLE_ENDIAN #endif Index: ossp-pkg/js/src/js.c RCS File: /v/ossp/cvs/ossp-pkg/js/src/js.c,v rcsdiff -q -kk '-r1.2' '-r1.3' -u '/v/ossp/cvs/ossp-pkg/js/src/js.c,v' 2>/dev/null --- js.c 2006/07/23 18:34:15 1.2 +++ js.c 2006/07/24 18:38:26 1.3 @@ -554,12 +554,6 @@ return JS_TRUE; } -static void -my_LoadErrorReporter(JSContext *cx, const char *message, JSErrorReport *report); - -static void -my_ErrorReporter(JSContext *cx, const char *message, JSErrorReport *report); - static JSBool Load(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { @@ -569,7 +563,6 @@ JSScript *script; JSBool ok; jsval result; - JSErrorReporter older; uint32 oldopts; for (i = 0; i < argc; i++) { @@ -579,7 +572,6 @@ argv[i] = STRING_TO_JSVAL(str); filename = JS_GetStringBytes(str); errno = 0; - older = JS_SetErrorReporter(cx, my_LoadErrorReporter); oldopts = JS_GetOptions(cx); JS_SetOptions(cx, oldopts | JSOPTION_COMPILE_N_GO); script = JS_CompileFile(cx, obj, filename); @@ -592,7 +584,6 @@ JS_DestroyScript(cx, script); } JS_SetOptions(cx, oldopts); - JS_SetErrorReporter(cx, older); if (!ok) return JS_FALSE; } @@ -1571,6 +1562,54 @@ return JS_NewNumberValue(cx, i, rval); } +static JSBool +StringsAreUtf8(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, + jsval *rval) +{ + *rval = JS_CStringsAreUTF8() ? JSVAL_TRUE : JSVAL_FALSE; + return JS_TRUE; +} + +static const char* badUtf8 = "...\xC0..."; +static const char* bigUtf8 = "...\xFB\xBF\xBF\xBF\xBF..."; +static const jschar badSurrogate[] = { 'A', 'B', 'C', 0xDEEE, 'D', 'E', 0 }; + +static JSBool +TestUtf8(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + intN mode = 1; + jschar chars[20]; + size_t charsLength = 5; + char bytes[20]; + size_t bytesLength = 20; + if (argc && !JS_ValueToInt32(cx, *argv, &mode)) + return JS_FALSE; + + /* The following throw errors if compiled with UTF-8. */ + switch (mode) { + /* mode 1: malformed UTF-8 string. */ + case 1: + JS_NewStringCopyZ(cx, badUtf8); + break; + /* mode 2: big UTF-8 character. */ + case 2: + JS_NewStringCopyZ(cx, bigUtf8); + break; + /* mode 3: bad surrogate character. */ + case 3: + JS_EncodeCharacters(cx, badSurrogate, 6, bytes, &bytesLength); + break; + /* mode 4: use a too small buffer. */ + case 4: + JS_DecodeBytes(cx, "1234567890", 10, chars, &charsLength); + break; + default: + JS_ReportError(cx, "invalid mode parameter"); + return JS_FALSE; + } + return !JS_IsExceptionPending (cx); +} + static JSFunctionSpec shell_functions[] = { {"version", Version, 0}, {"options", Options, 0}, @@ -1584,6 +1623,8 @@ {"untrap", Untrap, 2}, {"line2pc", LineToPC, 0}, {"pc2line", PCToLine, 0}, + {"stringsAreUtf8", StringsAreUtf8, 0}, + {"testUtf8", TestUtf8, 1}, #ifdef DEBUG {"dis", Disassemble, 1}, {"dissrc", DisassWithSrc, 1}, @@ -1623,6 +1664,8 @@ "untrap(fun[, pc]) Remove a trap", "line2pc([fun,] line) Map line number to PC", "pc2line(fun[, pc]) Map PC to line number", + "stringsAreUTF8() Check if strings are UTF-8 encoded", + "testUTF8(mode) Perform UTF-8 tests (modes are 1 to 4)", #ifdef DEBUG "dis([fun]) Disassemble functions into bytecodes", "dissrc([fun]) Disassemble functions with source lines", @@ -1650,14 +1693,14 @@ static void ShowHelpHeader(void) { - fprintf(gOutFile, "%-9s %-22s %s\n", "Command", "Usage", "Description"); - fprintf(gOutFile, "%-9s %-22s %s\n", "=======", "=====", "==========="); + fprintf(gOutFile, "%-14s %-22s %s\n", "Command", "Usage", "Description"); + fprintf(gOutFile, "%-14s %-22s %s\n", "=======", "=====", "==========="); } static void ShowHelpForCommand(uintN n) { - fprintf(gOutFile, "%-9.9s %s\n", shell_functions[n].name, shell_help_messages[n]); + fprintf(gOutFile, "%-14.14s %s\n", shell_functions[n].name, shell_help_messages[n]); } static JSBool @@ -1929,22 +1972,6 @@ } static void -my_LoadErrorReporter(JSContext *cx, const char *message, JSErrorReport *report) -{ - if (!report) { - fprintf(gErrFile, "%s\n", message); - return; - } - - /* Ignore any exceptions */ - if (JSREPORT_IS_EXCEPTION(report->flags)) - return; - - /* Otherwise, fall back to the ordinary error reporter. */ - my_ErrorReporter(cx, message, report); -} - -static void my_ErrorReporter(JSContext *cx, const char *message, JSErrorReport *report) { int i, j, k, n; Index: ossp-pkg/js/src/jsapi.c RCS File: /v/ossp/cvs/ossp-pkg/js/src/jsapi.c,v rcsdiff -q -kk '-r1.4' '-r1.5' -u '/v/ossp/cvs/ossp-pkg/js/src/jsapi.c,v' 2>/dev/null --- jsapi.c 2006/07/23 18:34:15 1.4 +++ jsapi.c 2006/07/24 18:38:26 1.5 @@ -896,6 +896,10 @@ /* XXXbe give the GC or another request calling it a chance to run here? Assumes FIFO scheduling */ JS_LOCK_GC(rt); + if (rt->gcThread != cx->thread) { + while (rt->gcLevel > 0) + JS_AWAIT_GC_DONE(rt); + } rt->requestCount++; JS_UNLOCK_GC(rt); } @@ -1483,7 +1487,7 @@ AddAtomToArray(JSContext *cx, JSAtom *atom, JSIdArray *ida, jsint *ip) { jsint i, length; - + i = *ip; length = ida->length; if (i >= length) { @@ -1861,7 +1865,7 @@ bytes = rt->gcBytes; lastBytes = rt->gcLastBytes; if ((bytes > 8192 && bytes > lastBytes + lastBytes / 2) || - rt->gcMallocBytes > rt->gcMaxMallocBytes) { + rt->gcMallocBytes > rt->gcMaxBytes) { /* * Run the GC if we have half again as many bytes of GC-things as * the last time we GC'd, or if we have malloc'd more bytes through @@ -1895,19 +1899,6 @@ return js_IsAboutToBeFinalized(cx, thing); } -JS_PUBLIC_API(void) -JS_SetGCParameter(JSRuntime *rt, JSGCParamKey key, uint32 value) -{ - switch (key) { - case JSGC_MAX_BYTES: - rt->gcMaxBytes = value; - break; - case JSGC_MAX_MALLOC_BYTES: - rt->gcMaxMallocBytes = value; - break; - } -} - JS_PUBLIC_API(intN) JS_AddExternalStringFinalizer(JSStringFinalizeOp finalizer) { @@ -2313,7 +2304,7 @@ scope = js_GetMutableScope(cx, obj); if (scope) SCOPE_SET_SEALED(scope); - JS_UNLOCK_SCOPE(cx, scope); + JS_UNLOCK_OBJ(cx, obj); if (!scope) return JS_FALSE; @@ -3218,7 +3209,7 @@ void *pdata; jsint index; JSIdArray *ida; - + CHECK_REQUEST(cx); iterobj = js_NewObject(cx, &prop_iter_class, NULL, obj); if (!iterobj) @@ -3294,7 +3285,7 @@ ida = (JSIdArray *) JS_GetPrivate(cx, iterobj); JS_ASSERT(i <= ida->length); if (i == 0) { - *idp = JSVAL_VOID; + *idp = JSVAL_VOID; } else { *idp = ida->vector[--i]; OBJ_SET_SLOT(cx, iterobj, JSSLOT_ITER_INDEX, INT_TO_JSVAL(i)); @@ -3459,12 +3450,6 @@ return fun->flags; } -JS_PUBLIC_API(uint16) -JS_GetFunctionArity(JSFunction *fun) -{ - return fun->nargs; -} - JS_PUBLIC_API(JSBool) JS_ObjectIsFunction(JSContext *cx, JSObject *obj) { @@ -3644,7 +3629,7 @@ JSScript *script; CHECK_REQUEST(cx); - chars = js_InflateString(cx, bytes, length); + chars = js_InflateString(cx, bytes, &length); if (!chars) return NULL; script = JS_CompileUCScript(cx, obj, chars, length, filename, lineno); @@ -3662,7 +3647,7 @@ JSScript *script; CHECK_REQUEST(cx); - chars = js_InflateString(cx, bytes, length); + chars = js_InflateString(cx, bytes, &length); if (!chars) return NULL; script = JS_CompileUCScriptForPrincipals(cx, obj, principals, @@ -3731,7 +3716,7 @@ JSErrorReporter older; CHECK_REQUEST(cx); - chars = js_InflateString(cx, bytes, length); + chars = js_InflateString(cx, bytes, &length); if (!chars) return JS_TRUE; @@ -3854,7 +3839,7 @@ JSFunction *fun; CHECK_REQUEST(cx); - chars = js_InflateString(cx, bytes, length); + chars = js_InflateString(cx, bytes, &length); if (!chars) return NULL; fun = JS_CompileUCFunction(cx, obj, name, nargs, argnames, chars, length, @@ -3874,7 +3859,7 @@ JSFunction *fun; CHECK_REQUEST(cx); - chars = js_InflateString(cx, bytes, length); + chars = js_InflateString(cx, bytes, &length); if (!chars) return NULL; fun = JS_CompileUCFunctionForPrincipals(cx, obj, principals, name, @@ -4079,7 +4064,7 @@ JSBool ok; CHECK_REQUEST(cx); - chars = js_InflateString(cx, bytes, length); + chars = js_InflateString(cx, bytes, &length); if (!chars) return JS_FALSE; ok = JS_EvaluateUCScript(cx, obj, chars, length, filename, lineno, rval); @@ -4098,7 +4083,7 @@ JSBool ok; CHECK_REQUEST(cx); - chars = js_InflateString(cx, bytes, length); + chars = js_InflateString(cx, bytes, &length); if (!chars) return JS_FALSE; ok = JS_EvaluateUCScriptForPrincipals(cx, obj, principals, chars, length, @@ -4248,15 +4233,16 @@ { jschar *chars; JSString *str; + size_t charsLength = length; CHECK_REQUEST(cx); /* Make a Unicode vector from the 8-bit char codes in bytes. */ - chars = js_InflateString(cx, bytes, length); + chars = js_InflateString(cx, bytes, &charsLength); if (!chars) return NULL; /* Free chars (but not bytes, which caller frees on error) if we fail. */ - str = js_NewString(cx, chars, length, 0); + str = js_NewString(cx, chars, charsLength, 0); if (!str) { JS_free(cx, chars); return NULL; @@ -4275,7 +4261,7 @@ JSString *str; CHECK_REQUEST(cx); - js = js_InflateString(cx, s, n); + js = js_InflateString(cx, s, &n); if (!js) return NULL; str = js_NewString(cx, js, n, 0); @@ -4295,7 +4281,7 @@ if (!s) return cx->runtime->emptyString; n = strlen(s); - js = js_InflateString(cx, s, n); + js = js_InflateString(cx, s, &n); if (!js) return NULL; str = js_NewString(cx, js, n, 0); @@ -4439,6 +4425,30 @@ return JS_TRUE; } +JS_PUBLIC_API(JSBool) +JS_EncodeCharacters(JSContext *cx, const jschar *src, size_t srclen, char *dst, + size_t *dstlenp) +{ + return js_DeflateStringToBuffer(cx, src, srclen, dst, dstlenp); +} + +JS_PUBLIC_API(JSBool) +JS_DecodeBytes(JSContext *cx, const char *src, size_t srclen, jschar *dst, + size_t *dstlenp) +{ + return js_InflateStringToBuffer(cx, src, srclen, dst, dstlenp); +} + +JS_PUBLIC_API(JSBool) +JS_CStringsAreUTF8() +{ +#ifdef JS_C_STRINGS_ARE_UTF8 + return JS_TRUE; +#else + return JS_FALSE; +#endif +} + /************************************************************************/ JS_PUBLIC_API(void) @@ -4520,7 +4530,7 @@ JS_PUBLIC_API(void) JS_ReportOutOfMemory(JSContext *cx) { - js_ReportOutOfMemory(cx, js_GetErrorMessage); + js_ReportOutOfMemory(cx); } JS_PUBLIC_API(JSErrorReporter) @@ -4546,7 +4556,7 @@ JSObject *obj; CHECK_REQUEST(cx); - chars = js_InflateString(cx, bytes, length); + chars = js_InflateString(cx, bytes, &length); if (!chars) return NULL; obj = js_NewRegExpObject(cx, NULL, chars, length, flags); Index: ossp-pkg/js/src/jscntxt.c RCS File: /v/ossp/cvs/ossp-pkg/js/src/jscntxt.c,v rcsdiff -q -kk '-r1.2' '-r1.3' -u '/v/ossp/cvs/ossp-pkg/js/src/jscntxt.c,v' 2>/dev/null --- jscntxt.c 2006/07/22 13:48:03 1.2 +++ jscntxt.c 2006/07/24 18:38:27 1.3 @@ -1,4 +1,5 @@ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sw=4 et tw=80: * * ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1/GPL 2.0/LGPL 2.1 @@ -716,14 +717,15 @@ * type message, and then hope the process ends swiftly. */ void -js_ReportOutOfMemory(JSContext *cx, JSErrorCallback callback) +js_ReportOutOfMemory(JSContext *cx) { JSStackFrame *fp; JSErrorReport report; JSErrorReporter onError = cx->errorReporter; /* Get the message for this error, but we won't expand any arguments. */ - const JSErrorFormatString *efs = callback(NULL, NULL, JSMSG_OUT_OF_MEMORY); + const JSErrorFormatString *efs = + js_GetLocalizedErrorMessage(cx, NULL, NULL, JSMSG_OUT_OF_MEMORY); const char *msg = efs ? efs->format : "Out of memory"; /* Fill out the report, but don't do anything that requires allocation. */ @@ -825,104 +827,112 @@ } *messagep = NULL; - if (callback) { + + /* Most calls supply js_GetErrorMessage; if this is so, assume NULL. */ + if (!callback || callback == js_GetErrorMessage) + efs = js_GetLocalizedErrorMessage(cx, userRef, NULL, errorNumber); + else efs = callback(userRef, NULL, errorNumber); - if (efs) { - size_t totalArgsLength = 0; - size_t argLengths[10]; /* only {0} thru {9} supported */ - argCount = efs->argCount; - JS_ASSERT(argCount <= 10); - if (argCount > 0) { - /* - * Gather the arguments into an array, and accumulate - * their sizes. We allocate 1 more than necessary and - * null it out to act as the caboose when we free the - * pointers later. - */ - reportp->messageArgs = (const jschar **) - JS_malloc(cx, sizeof(jschar *) * (argCount + 1)); - if (!reportp->messageArgs) - return JS_FALSE; - reportp->messageArgs[argCount] = NULL; - for (i = 0; i < argCount; i++) { - if (charArgs) { - char *charArg = va_arg(ap, char *); - reportp->messageArgs[i] - = js_InflateString(cx, charArg, strlen(charArg)); - if (!reportp->messageArgs[i]) - goto error; - } - else - reportp->messageArgs[i] = va_arg(ap, jschar *); - argLengths[i] = js_strlen(reportp->messageArgs[i]); - totalArgsLength += argLengths[i]; - } - /* NULL-terminate for easy copying. */ - reportp->messageArgs[i] = NULL; - } + if (efs) { + size_t totalArgsLength = 0; + size_t argLengths[10]; /* only {0} thru {9} supported */ + argCount = efs->argCount; + JS_ASSERT(argCount <= 10); + if (argCount > 0) { /* - * Parse the error format, substituting the argument X - * for {X} in the format. + * Gather the arguments into an array, and accumulate + * their sizes. We allocate 1 more than necessary and + * null it out to act as the caboose when we free the + * pointers later. */ - if (argCount > 0) { - if (efs->format) { - const char *fmt; - const jschar *arg; - jschar *out; - int expandedArgs = 0; - size_t expandedLength - = strlen(efs->format) - - (3 * argCount) /* exclude the {n} */ - + totalArgsLength; - /* - * Note - the above calculation assumes that each argument - * is used once and only once in the expansion !!! - */ - reportp->ucmessage = out = (jschar *) - JS_malloc(cx, (expandedLength + 1) * sizeof(jschar)); - if (!out) - goto error; - fmt = efs->format; - while (*fmt) { - if (*fmt == '{') { - if (isdigit(fmt[1])) { - int d = JS7_UNDEC(fmt[1]); - JS_ASSERT(d < argCount); - arg = reportp->messageArgs[d]; - js_strncpy(out, arg, argLengths[d]); - out += argLengths[d]; - fmt += 3; - expandedArgs++; - continue; - } - } - /* - * is this kosher? - */ - *out++ = (unsigned char)(*fmt++); - } - JS_ASSERT(expandedArgs == argCount); - *out = 0; - *messagep = - js_DeflateString(cx, reportp->ucmessage, - (size_t)(out - reportp->ucmessage)); - if (!*messagep) + reportp->messageArgs = (const jschar **) + JS_malloc(cx, sizeof(jschar *) * (argCount + 1)); + if (!reportp->messageArgs) + return JS_FALSE; + reportp->messageArgs[argCount] = NULL; + for (i = 0; i < argCount; i++) { + if (charArgs) { + char *charArg = va_arg(ap, char *); + size_t charArgLength = strlen(charArg); + reportp->messageArgs[i] + = js_InflateString(cx, charArg, &charArgLength); + if (!reportp->messageArgs[i]) goto error; + } else { + reportp->messageArgs[i] = va_arg(ap, jschar *); } - } else { + argLengths[i] = js_strlen(reportp->messageArgs[i]); + totalArgsLength += argLengths[i]; + } + /* NULL-terminate for easy copying. */ + reportp->messageArgs[i] = NULL; + } + /* + * Parse the error format, substituting the argument X + * for {X} in the format. + */ + if (argCount > 0) { + if (efs->format) { + jschar *buffer, *fmt, *out; + int expandedArgs = 0; + size_t expandedLength; + size_t len = strlen(efs->format); + + buffer = fmt = js_InflateString (cx, efs->format, &len); + if (!buffer) + goto error; + expandedLength = len + - (3 * argCount) /* exclude the {n} */ + + totalArgsLength; + /* - * Zero arguments: the format string (if it exists) is the - * entire message. - */ - if (efs->format) { - *messagep = JS_strdup(cx, efs->format); - if (!*messagep) - goto error; - reportp->ucmessage - = js_InflateString(cx, *messagep, strlen(*messagep)); - if (!reportp->ucmessage) - goto error; + * Note - the above calculation assumes that each argument + * is used once and only once in the expansion !!! + */ + reportp->ucmessage = out = (jschar *) + JS_malloc(cx, (expandedLength + 1) * sizeof(jschar)); + if (!out) { + JS_free (cx, buffer); + goto error; + } + while (*fmt) { + if (*fmt == '{') { + if (isdigit(fmt[1])) { + int d = JS7_UNDEC(fmt[1]); + JS_ASSERT(d < argCount); + js_strncpy(out, reportp->messageArgs[d], + argLengths[d]); + out += argLengths[d]; + fmt += 3; + expandedArgs++; + continue; + } + } + *out++ = *fmt++; } + JS_ASSERT(expandedArgs == argCount); + *out = 0; + JS_free (cx, buffer); + *messagep = + js_DeflateString(cx, reportp->ucmessage, + (size_t)(out - reportp->ucmessage)); + if (!*messagep) + goto error; + } + } else { + /* + * Zero arguments: the format string (if it exists) is the + * entire message. + */ + if (efs->format) { + size_t len; + *messagep = JS_strdup(cx, efs->format); + if (!*messagep) + goto error; + len = strlen(*messagep); + reportp->ucmessage = js_InflateString(cx, *messagep, &len); + if (!reportp->ucmessage) + goto error; } } } @@ -996,9 +1006,15 @@ if (message) JS_free(cx, message); if (report.messageArgs) { - int i = 0; - while (report.messageArgs[i]) - JS_free(cx, (void *)report.messageArgs[i++]); + /* + * js_ExpandErrorArguments owns its messageArgs only if it had to + * inflate the arguments (from regular |char *|s). + */ + if (charArgs) { + int i = 0; + while (report.messageArgs[i]) + JS_free(cx, (void *)report.messageArgs[i++]); + } JS_free(cx, (void *)report.messageArgs); } if (report.ucmessage) @@ -1053,10 +1069,10 @@ JSErrorFormatString js_ErrorFormatString[JSErr_Limit] = { #if JS_HAS_DFLT_MSG_STRINGS #define MSG_DEF(name, number, count, exception, format) \ - { format, count } , + { format, count, exception } , #else #define MSG_DEF(name, number, count, exception, format) \ - { NULL, count } , + { NULL, count, exception } , #endif #include "js.msg" #undef MSG_DEF Index: ossp-pkg/js/src/jsfile.c RCS File: /v/ossp/cvs/ossp-pkg/js/src/jsfile.c,v rcsdiff -q -kk '-r1.2' '-r1.3' -u '/v/ossp/cvs/ossp-pkg/js/src/jsfile.c,v' 2>/dev/null --- jsfile.c 2006/07/23 10:52:12 1.2 +++ jsfile.c 2006/07/24 18:38:27 1.3 @@ -2400,7 +2400,6 @@ obj = JS_NewObject(cx, &file_class, NULL, NULL); if (!obj) return JS_FALSE; - *rval = OBJECT_TO_JSVAL(obj); } str = (argc == 0) @@ -2420,6 +2419,7 @@ SECURITY_CHECK(cx, NULL, "constructor", file); + *rval = OBJECT_TO_JSVAL(obj); return JS_TRUE; } Index: ossp-pkg/js/src/jsinterp.c RCS File: /v/ossp/cvs/ossp-pkg/js/src/jsinterp.c,v rcsdiff -q -kk '-r1.3' '-r1.4' -u '/v/ossp/cvs/ossp-pkg/js/src/jsinterp.c,v' 2>/dev/null --- jsinterp.c 2006/07/22 20:31:56 1.3 +++ jsinterp.c 2006/07/24 18:38:27 1.4 @@ -1,5 +1,5 @@ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- - * vim: set ts=8 sw=4 et tw=78: + * vim: set ts=8 sw=4 et tw=80: * * ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1/GPL 2.0/LGPL 2.1 @@ -460,6 +460,8 @@ JSBool js_ComputeThis(JSContext *cx, JSObject *thisp, JSStackFrame *fp) { + JSObject *parent; + if (thisp && OBJ_GET_CLASS(cx, thisp) != &js_CallClass) { /* Some objects (e.g., With) delegate 'this' to another object. */ thisp = OBJ_THIS_OBJECT(cx, thisp); @@ -488,26 +490,13 @@ */ JS_ASSERT(!(fp->flags & JSFRAME_CONSTRUCTING)); if (JSVAL_IS_PRIMITIVE(fp->argv[-2]) || - !OBJ_GET_PARENT(cx, JSVAL_TO_OBJECT(fp->argv[-2]))) { + !(parent = OBJ_GET_PARENT(cx, JSVAL_TO_OBJECT(fp->argv[-2])))) { thisp = cx->globalObject; } else { - jsid id; - jsval v; - uintN attrs; - - /* Walk up the parent chain. */ - thisp = JSVAL_TO_OBJECT(fp->argv[-2]); - id = ATOM_TO_JSID(cx->runtime->atomState.parentAtom); - for (;;) { - if (!OBJ_CHECK_ACCESS(cx, thisp, id, JSACC_PARENT, &v, &attrs)) - return JS_FALSE; - if (JSVAL_IS_VOID(v)) - v = OBJ_GET_SLOT(cx, thisp, JSSLOT_PARENT); - JS_ASSERT(JSVAL_TO_OBJECT(v) == OBJ_GET_PARENT(cx, thisp)); - if (JSVAL_IS_NULL(v)) - break; - thisp = JSVAL_TO_OBJECT(v); - } + /* walk up to find the top-level object */ + thisp = parent; + while ((parent = OBJ_GET_PARENT(cx, thisp)) != NULL) + thisp = parent; } } fp->thisp = thisp; @@ -2009,17 +1998,6 @@ LOAD_INTERRUPT_HANDLER(rt); } } - -#if JS_HAS_CALL_OBJECT - /* - * If frame has a call object, sync values and clear the back- - * pointer. This can happen for a lightweight function if it - * calls eval unexpectedly (in a way that is hidden from the - * compiler). See bug 325540. - */ - if (fp->callobj) - ok &= js_PutCallObject(cx, fp); -#endif #if JS_HAS_ARGS_OBJECT if (fp->argsobj) ok &= js_PutArgsObject(cx, fp); @@ -2296,23 +2274,12 @@ /* Is this the first iteration ? */ if (JSVAL_IS_VOID(rval)) { - /* - * Yes, create a new JSObject to hold the iterator state. - * Use NULL as the nominal parent in js_NewObject to ensure - * that we use the correct scope chain lookup to try to find the - * PropertyIterator constructor. - */ - propobj = js_NewObject(cx, &prop_iterator_class, NULL, NULL); + /* Yes, create a new JSObject to hold the iterator state */ + propobj = js_NewObject(cx, &prop_iterator_class, NULL, obj); if (!propobj) { ok = JS_FALSE; goto out; } - - /* - * Now that we've resolved the object, use the PARENT slot to - * store the object that we're iterating over. - */ - propobj->slots[JSSLOT_PARENT] = OBJECT_TO_JSVAL(obj); propobj->slots[JSSLOT_ITER_STATE] = JSVAL_NULL; /* @@ -3410,12 +3377,17 @@ #undef FAST_GLOBAL_INCREMENT_OP do_nonint_fast_global_incop: + { + const JSCodeSpec *cs = &js_CodeSpec[op]; + vp = sp++; SAVE_SP(fp); NONINT_INCREMENT_OP_MIDDLE(); OBJ_SET_SLOT(cx, obj, slot, rval); STORE_OPND(-1, rtmp); + len = cs->length; break; + } case JSOP_GETPROP: /* Get an immediate atom naming the property. */ @@ -4572,7 +4544,8 @@ */ SAVE_SP(fp); obj2 = fp->scopeChain; - parent = js_NewObject(cx, &js_ObjectClass, NULL, obj2); + parent = js_ConstructObject(cx, &js_ObjectClass, NULL, obj2, + 0, NULL); if (!parent) { ok = JS_FALSE; goto out; @@ -4998,24 +4971,12 @@ JS_ASSERT(JSVAL_IS_OBJECT(lval)); obj = JSVAL_TO_OBJECT(lval); + /* Define obj[id] to contain rval and to be permanent. */ SAVE_SP(fp); - - /* - * It's possible for an evil script to substitute a random object - * for the new object. Check to make sure that we don't override a - * readonly property with the below OBJ_DEFINE_PROPERTY. - */ - ok = OBJ_GET_ATTRIBUTES(cx, obj, id, NULL, &attrs); + ok = OBJ_DEFINE_PROPERTY(cx, obj, id, rval, NULL, NULL, + JSPROP_PERMANENT, NULL); if (!ok) goto out; - if (!(attrs & (JSPROP_READONLY | JSPROP_PERMANENT | - JSPROP_GETTER | JSPROP_SETTER))) { - /* Define obj[id] to contain rval and to be permanent. */ - ok = OBJ_DEFINE_PROPERTY(cx, obj, id, rval, NULL, NULL, - JSPROP_PERMANENT, NULL); - if (!ok) - goto out; - } /* Now that we're done with rval, pop it. */ sp--; Index: ossp-pkg/js/src/jsprf.c RCS File: /v/ossp/cvs/ossp-pkg/js/src/jsprf.c,v rcsdiff -q -kk '-r1.2' '-r1.3' -u '/v/ossp/cvs/ossp-pkg/js/src/jsprf.c,v' 2>/dev/null --- jsprf.c 2006/07/22 17:02:34 1.2 +++ jsprf.c 2006/07/24 18:38:27 1.3 @@ -49,6 +49,8 @@ #include "jsprf.h" #include "jslong.h" #include "jsutil.h" /* Added by JSIFY */ +#include "jspubtd.h" +#include "jsstr.h" /* ** Note: on some platforms va_list is defined as an array, @@ -110,6 +112,7 @@ #define TYPE_STRING 8 #define TYPE_DOUBLE 9 #define TYPE_INTSTR 10 +#define TYPE_WSTRING 11 #define TYPE_UNKNOWN 20 #define FLAG_LEFT 0x1 @@ -400,6 +403,27 @@ return fill2(ss, s ? s : "(null)", slen, width, flags); } +static int cvt_ws(SprintfState *ss, const jschar *ws, int width, int prec, + int flags) +{ + int result; + /* + * Supply NULL as the JSContext; errors are not reported, + * and malloc() is used to allocate the buffer buffer. + */ + if (ws) { + int slen = js_strlen(ws); + char *s = js_DeflateString(NULL, ws, slen); + if (!s) + return -1; /* JSStuffFunc error indicator. */ + result = cvt_s(ss, s, width, prec, flags); + free(s); + } else { + result = cvt_s(ss, NULL, width, prec, flags); + } + return result; +} + /* ** BuildArgArray stands for Numbered Argument list Sprintf ** for example, @@ -583,7 +607,7 @@ break; case 's': - nas[ cn ].type = TYPE_STRING; + nas[ cn ].type = (nas[ cn ].type == TYPE_UINT16) ? TYPE_WSTRING : TYPE_STRING; break; case 'n': @@ -640,6 +664,8 @@ case TYPE_STRING: (void)va_arg( ap, char* ); break; + case TYPE_WSTRING: (void)va_arg( ap, jschar* ); break; + case TYPE_INTSTR: (void)va_arg( ap, JSIntn* ); break; case TYPE_DOUBLE: (void)va_arg( ap, double ); break; @@ -667,11 +693,13 @@ int flags, width, prec, radix, type; union { char ch; + jschar wch; int i; long l; JSInt64 ll; double d; const char *s; + const jschar* ws; int *ip; } u; const char *fmt0; @@ -683,7 +711,10 @@ struct NumArgState nasArray[ NAS_DEFAULT_NUM ]; char pattern[20]; const char *dolPt = NULL; /* in "%4$.2f", dolPt will poiont to . */ - +#ifdef JS_C_STRINGS_ARE_UTF8 + char utf8buf[6]; + int utf8len; +#endif /* ** build an argument array, IF the fmt is numbered argument @@ -910,7 +941,6 @@ break; case 'c': - u.ch = va_arg(ap, int); if ((flags & FLAG_LEFT) == 0) { while (width-- > 1) { rv = (*ss->stuff)(ss, " ", 1); @@ -919,7 +949,20 @@ } } } - rv = (*ss->stuff)(ss, &u.ch, 1); + switch (type) { + case TYPE_INT16: + /* Treat %hc as %c if JS_C_STRINGS_ARE_UTF8 is undefined. */ +#ifdef JS_C_STRINGS_ARE_UTF8 + u.wch = va_arg(ap, int); + utf8len = js_OneUcs4ToUtf8Char (utf8buf, u.wch); + rv = (*ss->stuff)(ss, utf8buf, utf8len); + break; +#endif + case TYPE_INTN: + u.ch = va_arg(ap, int); + rv = (*ss->stuff)(ss, &u.ch, 1); + break; + } if (rv < 0) { return rv; } @@ -958,8 +1001,17 @@ #endif case 's': - u.s = va_arg(ap, const char*); - rv = cvt_s(ss, u.s, width, prec, flags); + if(type == TYPE_INT16) { + /* + * This would do a simple string/byte conversion + * if JS_C_STRINGS_ARE_UTF8 is not defined. + */ + u.ws = va_arg(ap, const jschar*); + rv = cvt_ws(ss, u.ws, width, prec, flags); + } else { + u.s = va_arg(ap, const char*); + rv = cvt_s(ss, u.s, width, prec, flags); + } if (rv < 0) { return rv; } Index: ossp-pkg/js/src/jspubtd.h RCS File: /v/ossp/cvs/ossp-pkg/js/src/jspubtd.h,v rcsdiff -q -kk '-r1.2' '-r1.3' -u '/v/ossp/cvs/ossp-pkg/js/src/jspubtd.h,v' 2>/dev/null --- jspubtd.h 2006/07/22 20:31:56 1.2 +++ jspubtd.h 2006/07/24 18:38:27 1.3 @@ -546,9 +546,28 @@ (* JS_DLL_CALLBACK JSErrorReporter)(JSContext *cx, const char *message, JSErrorReport *report); +/* + * Possible exception types. These types are part of a JSErrorFormatString + * structure. They define which error to throw in case of a runtime error. + * JSEXN_NONE marks an unthrowable error. + */ +typedef enum JSExnType { + JSEXN_NONE = -1, + JSEXN_ERR, + JSEXN_INTERNALERR, + JSEXN_EVALERR, + JSEXN_RANGEERR, + JSEXN_REFERENCEERR, + JSEXN_SYNTAXERR, + JSEXN_TYPEERR, + JSEXN_URIERR, + JSEXN_LIMIT +} JSExnType; + typedef struct JSErrorFormatString { - const char *format; - uintN argCount; + const char *format; /* the error message (may be UTF-8 if compiled with JS_C_STRINGS_ARE_UTF8) */ + uint16 argCount; /* the number of arguments to convert in the error message */ + uint16 exnType; /* One of the JSExnType constants above */ } JSErrorFormatString; typedef const JSErrorFormatString * Index: ossp-pkg/js/src/perlconnect/.cvsignore RCS File: /v/ossp/cvs/ossp-pkg/js/src/perlconnect/.cvsignore,v rcsdiff -q -kk '-r1.1' '-r1.2' -u '/v/ossp/cvs/ossp-pkg/js/src/perlconnect/.cvsignore,v' 2>/dev/null --- .cvsignore 2006/07/22 15:09:45 1.1 +++ .cvsignore 2006/07/24 18:38:28 1.2 @@ -1,6 +1 @@ -Makefile -Makefile.PL -blib -pm_to_blib -JS.bs JS.c