Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Typedefs | Enumerations | Functions | Variables
jsstr.c File Reference
#include "jsstddef.h"
#include <stdlib.h>
#include <string.h>
#include "jstypes.h"
#include "jsutil.h"
#include "jshash.h"
#include "jsprf.h"
#include "jsapi.h"
#include "jsarray.h"
#include "jsatom.h"
#include "jsbool.h"
#include "jscntxt.h"
#include "jsconfig.h"
#include "jsgc.h"
#include "jsinterp.h"
#include "jslock.h"
#include "jsnum.h"
#include "jsobj.h"
#include "jsopcode.h"
#include "jsregexp.h"
#include "jsstr.h"

Go to the source code of this file.

Classes

struct  GlobData
struct  MatchData
struct  ReplaceData

Defines

#define JSSTRDEP_RECURSION_LIMIT   100
#define URL_XALPHAS   ((uint8) 1)
#define URL_XPALPHAS   ((uint8) 2)
#define URL_PATH   ((uint8) 4)
#define IS_OK(C, mask)   (urlCharType[((uint8) (C))] & (mask))
#define STRING_ELEMENT_ATTRS   (JSPROP_ENUMERATE|JSPROP_READONLY|JSPROP_PERMANENT)
#define MODE_MATCH   0x00 /* in: return match array on success */
#define MODE_REPLACE   0x01 /* in: match and replace */
#define MODE_SEARCH   0x02 /* in: search only, return match index or -1 */
#define GET_MODE(f)   ((f) & 0x03)
#define FORCE_FLAT   0x04 /* in: force flat (non-regexp) string match */
#define KEEP_REGEXP
#define GLOBAL_REGEXP   0x10 /* out: regexp had the 'g' flag */
#define PUSH_REGEXP_STATIC(sub)
#define URI_CHUNK   64U

Typedefs

typedef struct GlobData GlobData
typedef struct MatchData MatchData
typedef struct ReplaceData ReplaceData

Enumerations

enum  string_tinyid { STRING_LENGTH = -1 }

Functions

size_t js_MinimizeDependentStrings (JSString *str, int level, JSString **basep)
jscharjs_GetDependentStringChars (JSString *str)
jscharjs_GetStringChars (JSString *str)
JSStringjs_ConcatStrings (JSContext *cx, JSString *left, JSString *right)
const jscharjs_UndependString (JSContext *cx, JSString *str)
static JSBool str_decodeURI (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool str_decodeURI_Component (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool str_encodeURI (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool str_encodeURI_Component (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static uint32 Utf8ToOneUcs4Char (const uint8 *utf8Buffer, int utf8Length)
JSBool js_str_escape (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool str_unescape (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool str_uneval (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool str_getProperty (JSContext *cx, JSObject *obj, jsval id, jsval *vp)
static JSBool str_enumerate (JSContext *cx, JSObject *obj)
static JSBool str_resolve (JSContext *cx, JSObject *obj, jsval id, uintN flags, JSObject **objp)
static JSBool str_quote (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool str_toSource (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool str_toString (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool str_valueOf (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool str_substring (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool str_toLowerCase (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool str_toLocaleLowerCase (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool str_toUpperCase (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool str_toLocaleUpperCase (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool str_localeCompare (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool str_charAt (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool str_charCodeAt (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
jsint js_BoyerMooreHorspool (const jschar *text, jsint textlen, const jschar *pat, jsint patlen, jsint start)
static JSBool str_indexOf (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool str_lastIndexOf (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool match_or_replace (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, JSBool(*glob)(JSContext *cx, jsint count, GlobData *data), GlobData *data, jsval *rval)
static JSBool match_glob (JSContext *cx, jsint count, GlobData *data)
static JSBool str_match (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool str_search (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSSubStringinterpret_dollar (JSContext *cx, jschar *dp, jschar *ep, ReplaceData *rdata, size_t *skip)
static JSBool find_replen (JSContext *cx, ReplaceData *rdata, size_t *sizep)
static void do_replace (JSContext *cx, ReplaceData *rdata, jschar *chars)
static JSBool replace_glob (JSContext *cx, jsint count, GlobData *data)
static JSBool str_replace (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static jsint find_split (JSContext *cx, JSString *str, JSRegExp *re, jsint *ip, JSSubString *sep)
static JSBool str_split (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool str_substr (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool str_concat (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool str_slice (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool tagify (JSContext *cx, JSObject *obj, jsval *argv, const char *begin, JSString *param, const char *end, jsval *rval)
static JSBool tagify_value (JSContext *cx, JSObject *obj, jsval *argv, const char *begin, const char *end, jsval *rval)
static JSBool str_bold (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool str_italics (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool str_fixed (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool str_fontsize (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool str_fontcolor (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool str_link (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool str_anchor (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool str_strike (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool str_small (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool str_big (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool str_blink (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool str_sup (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool str_sub (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool String (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool str_fromCharCode (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
JSBool js_InitRuntimeStringState (JSContext *cx)
void js_FinishRuntimeStringState (JSContext *cx)
void js_FinishDeflatedStringCache (JSRuntime *rt)
JSObjectjs_InitStringClass (JSContext *cx, JSObject *obj)
JSStringjs_NewString (JSContext *cx, jschar *chars, size_t length, uintN gcflag)
JSStringjs_NewDependentString (JSContext *cx, JSString *base, size_t start, size_t length, uintN gcflag)
JSStringjs_NewStringCopyN (JSContext *cx, const jschar *s, size_t n, uintN gcflag)
JSStringjs_NewStringCopyZ (JSContext *cx, const jschar *s, uintN gcflag)
 js_hash_string_pointer (const void *key)
void js_PurgeDeflatedStringCache (JSRuntime *rt, JSString *str)
void js_FinalizeString (JSContext *cx, JSString *str)
void js_FinalizeStringRT (JSRuntime *rt, JSString *str)
JSObjectjs_StringToObject (JSContext *cx, JSString *str)
 js_ValueToPrintable (JSContext *cx, jsval v, JSValueToStringFun v2sfun)
 js_ValueToString (JSContext *cx, jsval v)
 js_ValueToSource (JSContext *cx, jsval v)
JSHashNumber js_HashString (JSString *str)
intN js_CompareStrings (JSString *str1, JSString *str2)
JSBool js_EqualStrings (JSString *str1, JSString *str2)
size_t js_strlen (const jschar *s)
jscharjs_strchr (const jschar *s, jschar c)
jscharjs_strchr_limit (const jschar *s, jschar c, const jschar *limit)
const jscharjs_SkipWhiteSpace (const jschar *s)
JSBool js_InflateStringToBuffer (JSContext *cx, const char *bytes, size_t length, jschar *chars, size_t *charsLength)
jscharjs_InflateString (JSContext *cx, const char *bytes, size_t *bytesLength)
JSBool js_DeflateStringToBuffer (JSContext *cx, const jschar *chars, size_t length, char *bytes, size_t *bytesLength)
char * js_DeflateString (JSContext *cx, const jschar *chars, size_t length)
static JSHashTableGetDeflatedStringCache (JSRuntime *rt)
JSBool js_SetStringBytes (JSRuntime *rt, JSString *str, char *bytes, size_t length)
char * js_GetStringBytes (JSRuntime *rt, JSString *str)
static JSBool AddCharsToURI (JSContext *cx, JSString *str, const jschar *chars, size_t length)
static JSBool Encode (JSContext *cx, JSString *str, const jschar *unescapedSet, const jschar *unescapedSet2, jsval *rval)
static JSBool Decode (JSContext *cx, JSString *str, const jschar *reservedSet, jsval *rval)
int js_OneUcs4ToUtf8Char (uint8 *utf8Buffer, uint32 ucs4Char)

Variables

static const uint8 urlCharType [256]
const char js_escape_str [] = "escape"
const char js_unescape_str [] = "unescape"
const char js_uneval_str [] = "uneval"
const char js_decodeURI_str [] = "decodeURI"
const char js_encodeURI_str [] = "encodeURI"
const char js_decodeURIComponent_str [] = "decodeURIComponent"
const char js_encodeURIComponent_str [] = "encodeURIComponent"
static JSFunctionSpec string_functions []
jschar js_empty_ucstr [] = {0}
JSSubString js_EmptySubString = {0, js_empty_ucstr}
static JSPropertySpec string_props []
JSClass js_StringClass
static JSFunctionSpec string_methods []
static JSFunctionSpec string_static_methods []
const uint8 js_X []
const uint8 js_Y []
const uint32 js_A []
const jschar js_uriReservedPlusPound_ucstr []
const jschar js_uriUnescaped_ucstr []

Class Documentation

struct GlobData

Definition at line 1113 of file jsstr.c.

Collaboration diagram for GlobData:
Class Members
uintN flags
uintN optarg
JSRegExp * regexp
JSString * str
struct MatchData

Definition at line 1258 of file jsstr.c.

Collaboration diagram for MatchData:
Class Members
jsval * arrayval
GlobData base
struct ReplaceData

Definition at line 1314 of file jsstr.c.

Collaboration diagram for ReplaceData:
Class Members
GlobData base
jschar * chars
jschar * dollar
jschar * dollarEnd
JSSubString dollarStr
jsint index
JSObject * lambda
jsint leftIndex
size_t length
JSString * repstr

Define Documentation

#define FORCE_FLAT   0x04 /* in: force flat (non-regexp) string match */

Definition at line 1127 of file jsstr.c.

#define GET_MODE (   f)    ((f) & 0x03)

Definition at line 1126 of file jsstr.c.

#define GLOBAL_REGEXP   0x10 /* out: regexp had the 'g' flag */

Definition at line 1129 of file jsstr.c.

#define IS_OK (   C,
  mask 
)    (urlCharType[((uint8) (C))] & (mask))

Definition at line 306 of file jsstr.c.

Definition at line 73 of file jsstr.c.

Value:
0x08    /* inout: keep GlobData.regexp alive for caller
                                          of match_or_replace; if set on input
                                          but clear on output, regexp ownership
                                          does not pass to caller */

Definition at line 1128 of file jsstr.c.

#define MODE_MATCH   0x00 /* in: return match array on success */

Definition at line 1123 of file jsstr.c.

#define MODE_REPLACE   0x01 /* in: match and replace */

Definition at line 1124 of file jsstr.c.

#define MODE_SEARCH   0x02 /* in: search only, return match index or -1 */

Definition at line 1125 of file jsstr.c.

Value:
JS_BEGIN_MACRO                                                            \
        JSString *str = js_NewStringCopyN(cx,                                 \
                                          cx->regExpStatics.sub.chars,        \
                                          cx->regExpStatics.sub.length,       \
                                          0);                                 \
        if (!str) {                                                           \
            ok = JS_FALSE;                                                    \
            goto lambda_out;                                                  \
        }                                                                     \
        *sp++ = STRING_TO_JSVAL(str);                                         \
    JS_END_MACRO

Definition at line 544 of file jsstr.c.

#define URI_CHUNK   64U

Definition at line 4495 of file jsstr.c.

#define URL_PATH   ((uint8) 4)

Definition at line 285 of file jsstr.c.

#define URL_XALPHAS   ((uint8) 1)

Definition at line 283 of file jsstr.c.

#define URL_XPALPHAS   ((uint8) 2)

Definition at line 284 of file jsstr.c.


Typedef Documentation

typedef struct GlobData GlobData
typedef struct MatchData MatchData
typedef struct ReplaceData ReplaceData

Enumeration Type Documentation

Enumerator:
STRING_LENGTH 

Definition at line 505 of file jsstr.c.

                   {
    STRING_LENGTH = -1
};

Function Documentation

static JSBool AddCharsToURI ( JSContext cx,
JSString str,
const jschar chars,
size_t  length 
) [static]

Definition at line 4499 of file jsstr.c.

{
    size_t total;

    JS_ASSERT(!JSSTRING_IS_DEPENDENT(str));
    total = str->length + length + 1;
    if (!str->chars ||
        JS_HOWMANY(total, URI_CHUNK) > JS_HOWMANY(str->length + 1, URI_CHUNK)) {
        total = JS_ROUNDUP(total, URI_CHUNK);
        str->chars = JS_realloc(cx, str->chars, total * sizeof(jschar));
        if (!str->chars)
            return JS_FALSE;
    }
    js_strncpy(str->chars + str->length, chars, length);
    str->length += length;

Here is the call graph for this function:

Here is the caller graph for this function:

static JSBool Decode ( JSContext cx,
JSString str,
const jschar reservedSet,
jsval rval 
) [static]

Definition at line 4602 of file jsstr.c.

{
    size_t length, start, k;
    jschar *chars, c, H;
    uint32 v;
    jsuint B;
    uint8 octets[6];
    JSString *R;
    intN j, n;

    length = JSSTRING_LENGTH(str);
    if (length == 0) {
        *rval = STRING_TO_JSVAL(cx->runtime->emptyString);
        return JS_TRUE;
    }

    R = js_NewString(cx, NULL, 0, 0);
    if (!R)
        return JS_FALSE;

    chars = JSSTRING_CHARS(str);
    for (k = 0; k < length; k++) {
        c = chars[k];
        if (c == '%') {
            start = k;
            if ((k + 2) >= length)
                goto bad;
            if (!JS7_ISHEX(chars[k+1]) || !JS7_ISHEX(chars[k+2]))
                goto bad;
            B = JS7_UNHEX(chars[k+1]) * 16 + JS7_UNHEX(chars[k+2]);
            k += 2;
            if (!(B & 0x80)) {
                c = (jschar)B;
            } else {
                n = 1;
                while (B & (0x80 >> n))
                    n++;
                if (n == 1 || n > 6)
                    goto bad;
                octets[0] = (uint8)B;
                if (k + 3 * (n - 1) >= length)
                    goto bad;
                for (j = 1; j < n; j++) {
                    k++;
                    if (chars[k] != '%')
                        goto bad;
                    if (!JS7_ISHEX(chars[k+1]) || !JS7_ISHEX(chars[k+2]))
                        goto bad;
                    B = JS7_UNHEX(chars[k+1]) * 16 + JS7_UNHEX(chars[k+2]);
                    if ((B & 0xC0) != 0x80)
                        goto bad;
                    k += 2;
                    octets[j] = (char)B;
                }
                v = Utf8ToOneUcs4Char(octets, n);
                if (v >= 0x10000) {
                    v -= 0x10000;
                    if (v > 0xFFFFF)
                        goto bad;
                    c = (jschar)((v & 0x3FF) + 0xDC00);
                    H = (jschar)((v >> 10) + 0xD800);
                    if (!AddCharsToURI(cx, R, &H, 1))
                        return JS_FALSE;
                } else {
                    c = (jschar)v;
                }
            }
            if (js_strchr(reservedSet, c)) {
                if (!AddCharsToURI(cx, R, &chars[start], (k - start + 1)))
                    return JS_FALSE;
            } else {
                if (!AddCharsToURI(cx, R, &c, 1))
                    return JS_FALSE;
            }
        } else {
            if (!AddCharsToURI(cx, R, &c, 1))
                return JS_FALSE;
        }
    }

    /*
     * Shrinking realloc can fail (e.g., with a BSD-style allocator), but we
     * don't worry about that case here.  Worst case, R hangs onto URI_CHUNK-1
     * more jschars than it needs.
     */
    chars = (jschar *) JS_realloc(cx, R->chars, (R->length+1) * sizeof(jschar));
    if (chars)
        R->chars = chars;
    *rval = STRING_TO_JSVAL(R);
    return JS_TRUE;

bad:

Here is the caller graph for this function:

static void do_replace ( JSContext cx,
ReplaceData rdata,
jschar chars 
) [static]

Definition at line 1518 of file jsstr.c.

{
    JSString *repstr;
    jschar *bp, *cp, *dp, *ep;
    size_t len, skip;
    JSSubString *sub;

    repstr = rdata->repstr;
    bp = cp = JSSTRING_CHARS(repstr);
    for (dp = rdata->dollar, ep = rdata->dollarEnd; dp;
         dp = js_strchr_limit(dp, '$', ep)) {
        len = dp - cp;
        js_strncpy(chars, cp, len);
        chars += len;
        cp = dp;
        sub = interpret_dollar(cx, dp, ep, rdata, &skip);
        if (sub) {
            len = sub->length;
            js_strncpy(chars, sub->chars, len);
            chars += len;
            cp += skip;
            dp += skip;
        } else {
            dp++;
        }

Here is the caller graph for this function:

static JSBool Encode ( JSContext cx,
JSString str,
const jschar unescapedSet,
const jschar unescapedSet2,
jsval rval 
) [static]

Definition at line 4526 of file jsstr.c.

{
    size_t length, j, k, L;
    jschar *chars, c, c2;
    uint32 v;
    uint8 utf8buf[6];
    jschar hexBuf[4];
    static const char HexDigits[] = "0123456789ABCDEF"; /* NB: uppercase */
    JSString *R;

    length = JSSTRING_LENGTH(str);
    if (length == 0) {
        *rval = STRING_TO_JSVAL(cx->runtime->emptyString);
        return JS_TRUE;
    }

    R = js_NewString(cx, NULL, 0, 0);
    if (!R)
        return JS_FALSE;

    hexBuf[0] = '%';
    hexBuf[3] = 0;
    chars = JSSTRING_CHARS(str);
    for (k = 0; k < length; k++) {
        c = chars[k];
        if (js_strchr(unescapedSet, c) ||
            (unescapedSet2 && js_strchr(unescapedSet2, c))) {
            if (!AddCharsToURI(cx, R, &c, 1))
                return JS_FALSE;
        } else {
            if ((c >= 0xDC00) && (c <= 0xDFFF)) {
                JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
                                 JSMSG_BAD_URI, NULL);
                return JS_FALSE;
            }
            if (c < 0xD800 || c > 0xDBFF) {
                v = c;
            } else {
                k++;
                if (k == length) {
                    JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
                                     JSMSG_BAD_URI, NULL);
                    return JS_FALSE;
                }
                c2 = chars[k];
                if ((c2 < 0xDC00) || (c2 > 0xDFFF)) {
                    JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
                                     JSMSG_BAD_URI, NULL);
                    return JS_FALSE;
                }
                v = ((c - 0xD800) << 10) + (c2 - 0xDC00) + 0x10000;
            }
            L = js_OneUcs4ToUtf8Char(utf8buf, v);
            for (j = 0; j < L; j++) {
                hexBuf[1] = HexDigits[utf8buf[j] >> 4];
                hexBuf[2] = HexDigits[utf8buf[j] & 0xf];
                if (!AddCharsToURI(cx, R, hexBuf, 3))
                    return JS_FALSE;
            }
        }
    }

    /*
     * Shrinking realloc can fail (e.g., with a BSD-style allocator), but we
     * don't worry about that case here.  Worst case, R hangs onto URI_CHUNK-1
     * more jschars than it needs.
     */
    chars = (jschar *) JS_realloc(cx, R->chars, (R->length+1) * sizeof(jschar));
    if (chars)
        R->chars = chars;

Here is the call graph for this function:

Here is the caller graph for this function:

static JSBool find_replen ( JSContext cx,
ReplaceData rdata,
size_t *  sizep 
) [static]

Definition at line 1386 of file jsstr.c.

{
    JSString *repstr;
    size_t replen, skip;
    jschar *dp, *ep;
    JSSubString *sub;
    JSObject *lambda;

    lambda = rdata->lambda;
    if (lambda) {
        uintN argc, i, j, m, n, p;
        jsval *sp, *oldsp, rval;
        void *mark;
        JSStackFrame *fp;
        JSBool ok;

        /*
         * Save the regExpStatics from the current regexp, since they may be
         * clobbered by a RegExp usage in the lambda function.  Note that all
         * members of JSRegExpStatics are JSSubStrings, so not GC roots, save
         * input, which is rooted otherwise via argv[-1] in str_replace.
         */
        JSRegExpStatics save = cx->regExpStatics;
        JSBool freeMoreParens = JS_FALSE;

        /*
         * In the lambda case, not only do we find the replacement string's
         * length, we compute repstr and return it via rdata for use within
         * do_replace.  The lambda is called with arguments ($&, $1, $2, ...,
         * index, input), i.e., all the properties of a regexp match array.
         * For $&, etc., we must create string jsvals from cx->regExpStatics.
         * We grab up stack space to keep the newborn strings GC-rooted.
         */
        p = rdata->base.regexp->parenCount;
        argc = 1 + p + 2;
        sp = js_AllocStack(cx, 2 + argc, &mark);
        if (!sp)
            return JS_FALSE;

        /* Push lambda and its 'this' parameter. */
        *sp++ = OBJECT_TO_JSVAL(lambda);
        *sp++ = OBJECT_TO_JSVAL(OBJ_GET_PARENT(cx, lambda));

#define PUSH_REGEXP_STATIC(sub)                                               \
    JS_BEGIN_MACRO                                                            \
        JSString *str = js_NewStringCopyN(cx,                                 \
                                          cx->regExpStatics.sub.chars,        \
                                          cx->regExpStatics.sub.length,       \
                                          0);                                 \
        if (!str) {                                                           \
            ok = JS_FALSE;                                                    \
            goto lambda_out;                                                  \
        }                                                                     \
        *sp++ = STRING_TO_JSVAL(str);                                         \
    JS_END_MACRO

        /* Push $&, $1, $2, ... */
        PUSH_REGEXP_STATIC(lastMatch);
        i = 0;
        m = cx->regExpStatics.parenCount;
        n = JS_MIN(m, 9);
        for (j = 0; i < n; i++, j++)
            PUSH_REGEXP_STATIC(parens[j]);
        for (j = 0; i < m; i++, j++)
            PUSH_REGEXP_STATIC(moreParens[j]);

        /*
         * We need to clear moreParens in the top-of-stack cx->regExpStatics
         * to it won't be possibly realloc'ed, leaving the bottom-of-stack
         * moreParens pointing to freed memory.
         */
        cx->regExpStatics.moreParens = NULL;
        freeMoreParens = JS_TRUE;

#undef PUSH_REGEXP_STATIC

        /* Make sure to push undefined for any unmatched parens. */
        for (; i < p; i++)
            *sp++ = JSVAL_VOID;

        /* Push match index and input string. */
        *sp++ = INT_TO_JSVAL((jsint)cx->regExpStatics.leftContext.length);
        *sp++ = STRING_TO_JSVAL(rdata->base.str);

        /* Lift current frame to include the args and do the call. */
        fp = cx->fp;
        oldsp = fp->sp;
        fp->sp = sp;
        ok = js_Invoke(cx, argc, JSINVOKE_INTERNAL);
        rval = fp->sp[-1];
        fp->sp = oldsp;

        if (ok) {
            /*
             * NB: we count on the newborn string root to hold any string
             * created by this js_ValueToString that would otherwise be GC-
             * able, until we use rdata->repstr in do_replace.
             */
            repstr = js_ValueToString(cx, rval);
            if (!repstr) {
                ok = JS_FALSE;
            } else {
                rdata->repstr = repstr;
                *sizep = JSSTRING_LENGTH(repstr);
            }
        }

      lambda_out:
        js_FreeStack(cx, mark);
        if (freeMoreParens)
            JS_free(cx, cx->regExpStatics.moreParens);
        cx->regExpStatics = save;
        return ok;
    }

    repstr = rdata->repstr;
    replen = JSSTRING_LENGTH(repstr);
    for (dp = rdata->dollar, ep = rdata->dollarEnd; dp;
         dp = js_strchr_limit(dp, '$', ep)) {
        sub = interpret_dollar(cx, dp, ep, rdata, &skip);
        if (sub) {
            replen += sub->length - skip;
            dp += skip;
        }
        else
            dp++;
    }
static jsint find_split ( JSContext cx,
JSString str,
JSRegExp re,
jsint ip,
JSSubString sep 
) [static]

Definition at line 1692 of file jsstr.c.

{
    jsint i, j, k;
    size_t length;
    jschar *chars;

    /*
     * Stop if past end of string.  If at end of string, we will compare the
     * null char stored there (by js_NewString*) to sep->chars[j] in the while
     * loop at the end of this function, so that
     *
     *  "ab,".split(',') => ["ab", ""]
     *
     * and the resulting array converts back to the string "ab," for symmetry.
     * However, we ape Perl and do this only if there is a sufficiently large
     * limit argument (see str_split).
     */
    i = *ip;
    length = JSSTRING_LENGTH(str);
    if ((size_t)i > length)
        return -1;

    chars = JSSTRING_CHARS(str);

    /*
     * Match a regular expression against the separator at or above index i.
     * Call js_ExecuteRegExp with true for the test argument.  On successful
     * match, get the separator from cx->regExpStatics.lastMatch.
     */
    if (re) {
        size_t index;
        jsval rval;

      again:
        /* JS1.2 deviated from Perl by never matching at end of string. */
        index = (size_t)i;
        if (!js_ExecuteRegExp(cx, re, str, &index, JS_TRUE, &rval))
            return -2;
        if (rval != JSVAL_TRUE) {
            /* Mismatch: ensure our caller advances i past end of string. */
            sep->length = 1;
            return length;
        }
        i = (jsint)index;
        *sep = cx->regExpStatics.lastMatch;
        if (sep->length == 0) {
            /*
             * Empty string match: never split on an empty match at the start
             * of a find_split cycle.  Same rule as for an empty global match
             * in match_or_replace.
             */
            if (i == *ip) {
                /*
                 * "Bump-along" to avoid sticking at an empty match, but don't
                 * bump past end of string -- our caller must do that by adding
                 * sep->length to our return value.
                 */
                if ((size_t)i == length)
                    return -1;
                i++;
                goto again;
            }
            if ((size_t)i == length) {
                /*
                 * If there was a trivial zero-length match at the end of the
                 * split, then we shouldn't output the matched string at the end
                 * of the split array. See ECMA-262 Ed. 3, 15.5.4.14, Step 15.
                 */
                sep->chars = NULL;
            }
        }
        JS_ASSERT((size_t)i >= sep->length);
        return i - sep->length;
    }

    /*
     * Deviate from ECMA by never splitting an empty string by any separator
     * string into a non-empty array (an array of length 1 that contains the
     * empty string).
     */
    if (!JS_VERSION_IS_ECMA(cx) && length == 0)
        return -1;

    /*
     * Special case: if sep is the empty string, split str into one character
     * substrings.  Let our caller worry about whether to split once at end of
     * string into an empty substring.
     */
    if (sep->length == 0)
        return ((size_t)i == length) ? -1 : i + 1;

    /*
     * Now that we know sep is non-empty, search starting at i in str for an
     * occurrence of all of sep's chars.  If we find them, return the index of
     * the first separator char.  Otherwise, return length.
     */
    j = 0;
    while ((size_t)(k = i + j) < length) {
        if (chars[k] == sep->chars[j]) {
            if ((size_t)++j == sep->length)
                return i;
        } else {
            i++;
            j = 0;
        }

Here is the call graph for this function:

static JSHashTable* GetDeflatedStringCache ( JSRuntime rt) [static]

Definition at line 3112 of file jsstr.c.

Here is the call graph for this function:

static JSSubString* interpret_dollar ( JSContext cx,
jschar dp,
jschar ep,
ReplaceData rdata,
size_t *  skip 
) [static]

Definition at line 1328 of file jsstr.c.

{
    JSRegExpStatics *res;
    jschar dc, *cp;
    uintN num, tmp;

    JS_ASSERT(*dp == '$');

    /* If there is only a dollar, bail now */
    if (dp + 1 >= ep)
        return NULL;

    /* Interpret all Perl match-induced dollar variables. */
    res = &cx->regExpStatics;
    dc = dp[1];
    if (JS7_ISDEC(dc)) {
        /* ECMA-262 Edition 3: 1-9 or 01-99 */
        num = JS7_UNDEC(dc);
        if (num > res->parenCount)
            return NULL;

        cp = dp + 2;
        if (cp < ep && (dc = *cp, JS7_ISDEC(dc))) {
            tmp = 10 * num + JS7_UNDEC(dc);
            if (tmp <= res->parenCount) {
                cp++;
                num = tmp;
            }
        }
        if (num == 0)
            return NULL;

        /* Adjust num from 1 $n-origin to 0 array-index-origin. */
        num--;
        *skip = cp - dp;
        return REGEXP_PAREN_SUBSTRING(res, num);
    }

    *skip = 2;
    switch (dc) {
      case '$':
        rdata->dollarStr.chars = dp;
        rdata->dollarStr.length = 1;
        return &rdata->dollarStr;
      case '&':
        return &res->lastMatch;
      case '+':
        return &res->lastParen;
      case '`':
        return &res->leftContext;
      case '\'':
        return &res->rightContext;
jsint js_BoyerMooreHorspool ( const jschar text,
jsint  textlen,
const jschar pat,
jsint  patlen,
jsint  start 
)

Definition at line 952 of file jsstr.c.

{
    jsint i, j, k, m;
    uint8 skip[BMH_CHARSET_SIZE];
    jschar c;

    JS_ASSERT(0 < patlen && patlen <= BMH_PATLEN_MAX);
    for (i = 0; i < BMH_CHARSET_SIZE; i++)
        skip[i] = (uint8)patlen;
    m = patlen - 1;
    for (i = 0; i < m; i++) {
        c = pat[i];
        if (c >= BMH_CHARSET_SIZE)
            return BMH_BAD_PATTERN;
        skip[c] = (uint8)(m - i);
    }
    for (k = start + m;
         k < textlen;
         k += ((c = text[k]) >= BMH_CHARSET_SIZE) ? patlen : skip[c]) {
        for (i = k, j = m; ; i--, j--) {
            if (j < 0)
                return i + 1;
            if (text[i] != pat[j])
                break;
        }
    }
    return -1;
}

Here is the caller graph for this function:

intN js_CompareStrings ( JSString str1,
JSString str2 
)

Definition at line 2740 of file jsstr.c.

{
    size_t l1, l2, n, i;
    const jschar *s1, *s2;
    intN cmp;

    JS_ASSERT(str1);
    JS_ASSERT(str2);

    /* Fast case: pointer equality could be a quick win. */
    if (str1 == str2)
        return 0;

    l1 = JSSTRING_LENGTH(str1), l2 = JSSTRING_LENGTH(str2);
    s1 = JSSTRING_CHARS(str1),  s2 = JSSTRING_CHARS(str2);
    n = JS_MIN(l1, l2);
    for (i = 0; i < n; i++) {
        cmp = s1[i] - s2[i];
        if (cmp != 0)
            return cmp;

Here is the caller graph for this function:

JSString* js_ConcatStrings ( JSContext cx,
JSString left,
JSString right 
)

Definition at line 129 of file jsstr.c.

{
    size_t rn, ln, lrdist, n;
    jschar *rs, *ls, *s;
    JSDependentString *ldep;    /* non-null if left should become dependent */
    JSString *str;

    if (JSSTRING_IS_DEPENDENT(right)) {
        rn = JSSTRDEP_LENGTH(right);
        rs = JSSTRDEP_CHARS(right);
    } else {
        rn = right->length;
        rs = right->chars;
    }
    if (rn == 0)
        return left;

    if (JSSTRING_IS_DEPENDENT(left) ||
        !(*js_GetGCThingFlags(left) & GCF_MUTABLE)) {
        /* We must copy if left does not own a buffer to realloc. */
        ln = JSSTRING_LENGTH(left);
        if (ln == 0)
            return right;
        ls = JSSTRING_CHARS(left);
        s = (jschar *) JS_malloc(cx, (ln + rn + 1) * sizeof(jschar));
        if (!s)
            return NULL;
        js_strncpy(s, ls, ln);
        ldep = NULL;
    } else {
        /* We can realloc left's space and make it depend on our result. */
        ln = left->length;
        if (ln == 0)
            return right;
        ls = left->chars;
        s = (jschar *) JS_realloc(cx, ls, (ln + rn + 1) * sizeof(jschar));
        if (!s)
            return NULL;

        /* Take care: right could depend on left! */
        lrdist = (size_t)(rs - ls);
        if (lrdist < ln)
            rs = s + lrdist;
        left->chars = ls = s;
        ldep = JSSTRDEP(left);
    }

    js_strncpy(s + ln, rs, rn);
    n = ln + rn;
    s[n] = 0;
    str = js_NewString(cx, s, n, GCF_MUTABLE);
    if (!str) {
        /* Out of memory: clean up any space we (re-)allocated. */
        if (!ldep) {
            JS_free(cx, s);
        } else {
            s = JS_realloc(cx, ls, (ln + 1) * sizeof(jschar));
            if (s)
                left->chars = s;
        }
    } else {
        /* Morph left into a dependent prefix if we realloc'd its buffer. */
        if (ldep) {
            JSPREFIX_SET_LENGTH(ldep, ln);
            JSPREFIX_SET_BASE(ldep, str);
#ifdef DEBUG
          {
            JSRuntime *rt = cx->runtime;
            JS_RUNTIME_METER(rt, liveDependentStrings);
            JS_RUNTIME_METER(rt, totalDependentStrings);
            JS_LOCK_RUNTIME_VOID(rt,
                (rt->strdepLengthSum += (double)ln,
                 rt->strdepLengthSquaredSum += (double)ln * (double)ln));
          }
#endif
        }
    }

    return str;
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* js_DeflateString ( JSContext cx,
const jschar chars,
size_t  length 
)

Definition at line 3092 of file jsstr.c.

{
    size_t i, size;
    char *bytes;

    size = (length + 1) * sizeof(char);
    bytes = (char *) (cx ? JS_malloc(cx, size) : malloc(size));
    if (!bytes)
        return NULL;

    for (i = 0; i < length; i++)
        bytes[i] = (char) chars[i];

Here is the call graph for this function:

Here is the caller graph for this function:

JSBool js_DeflateStringToBuffer ( JSContext cx,
const jschar chars,
size_t  length,
char *  bytes,
size_t *  bytesLength 
)

Definition at line 3068 of file jsstr.c.

{
    size_t i;

    if (length > *bytesLength) {
        for (i = 0; i < *bytesLength; i++)
            bytes[i] = (char) chars[i];
        if (cx) {
            JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
                                 JSMSG_BUFFER_TOO_SMALL);
        }
        return JS_FALSE;
    }
    for (i = 0; i < length; i++)
        bytes[i] = (char) chars[i];

Here is the caller graph for this function:

JSBool js_EqualStrings ( JSString str1,
JSString str2 
)

Definition at line 2765 of file jsstr.c.

{
    size_t n;
    const jschar *s1, *s2;

    JS_ASSERT(str1);
    JS_ASSERT(str2);

    /* Fast case: pointer equality could be a quick win. */
    if (str1 == str2)
        return JS_TRUE;

    n = JSSTRING_LENGTH(str1);
    if (n != JSSTRING_LENGTH(str2))
        return JS_FALSE;

    if (n == 0)
        return JS_TRUE;

    s1 = JSSTRING_CHARS(str1), s2 = JSSTRING_CHARS(str2);
    do {
        if (*s1 != *s2)
            return JS_FALSE;
        ++s1, ++s2;
    } while (--n != 0);

Here is the caller graph for this function:

void js_FinalizeString ( JSContext cx,
JSString str 
)

Definition at line 2609 of file jsstr.c.

{
void js_FinalizeStringRT ( JSRuntime rt,
JSString str 
)

Definition at line 2615 of file jsstr.c.

{
    JSBool valid;

    JS_RUNTIME_UNMETER(rt, liveStrings);
    if (JSSTRING_IS_DEPENDENT(str)) {
        /* If JSSTRFLAG_DEPENDENT is set, this string must be valid. */
        JS_ASSERT(JSSTRDEP_BASE(str));
        JS_RUNTIME_UNMETER(rt, liveDependentStrings);
        valid = JS_TRUE;
    } else {
        /* A stillborn string has null chars, so is not valid. */
        valid = (str->chars != NULL);
        if (valid)
            free(str->chars);
    }
    if (valid) {
        js_PurgeDeflatedStringCache(rt, str);
        str->chars = NULL;

Here is the caller graph for this function:

Definition at line 2396 of file jsstr.c.

{
    if (rt->deflatedStringCache) {
        JS_HashTableDestroy(rt->deflatedStringCache);
        rt->deflatedStringCache = NULL;
    }
#ifdef JS_THREADSAFE
    if (rt->deflatedStringCacheLock) {
        JS_DESTROY_LOCK(rt->deflatedStringCacheLock);
        rt->deflatedStringCacheLock = NULL;

Here is the caller graph for this function:

Definition at line 2387 of file jsstr.c.

{
    JSRuntime *rt = cx->runtime;

Here is the caller graph for this function:

Definition at line 107 of file jsstr.c.

{
    size_t start;
    JSString *base;

    start = js_MinimizeDependentStrings(str, 0, &base);
    JS_ASSERT(!JSSTRING_IS_DEPENDENT(base));
    JS_ASSERT(start < base->length);
    return base->chars + start;
}

Here is the call graph for this function:

char* js_GetStringBytes ( JSRuntime rt,
JSString str 
)

Definition at line 3155 of file jsstr.c.

{
    JSHashTable *cache;
    char *bytes;
    JSHashNumber hash;
    JSHashEntry *he, **hep;

    JS_ACQUIRE_LOCK(rt->deflatedStringCacheLock);

    cache = GetDeflatedStringCache(rt);
    if (!cache) {
        bytes = NULL;
    } else {
        hash = js_hash_string_pointer(str);
        hep = JS_HashTableRawLookup(cache, hash, str);
        he = *hep;
        if (he) {
            bytes = (char *) he->value;

            /* Try to catch failure to JS_ShutDown between runtime epochs. */
            JS_ASSERT((*bytes == '\0' && JSSTRING_LENGTH(str) == 0) ||
                      *bytes == (char) JSSTRING_CHARS(str)[0]);
        } else {
            bytes = js_DeflateString(NULL, JSSTRING_CHARS(str),
                                           JSSTRING_LENGTH(str));
            if (bytes) {
                if (JS_HashTableRawAdd(cache, hep, hash, str, bytes)) {
#ifdef DEBUG
                    rt->deflatedStringCacheBytes += JSSTRING_LENGTH(str);
#endif
                } else {
                    free(bytes);
                    bytes = NULL;
                }
            }
        }
    }

Here is the caller graph for this function:

Definition at line 119 of file jsstr.c.

{
    if (JSSTRING_IS_DEPENDENT(str) && !js_UndependString(NULL, str))
        return NULL;

    *js_GetGCThingFlags(str) &= ~GCF_MUTABLE;
    return str->chars;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2580 of file jsstr.c.

{

Here is the caller graph for this function:

Definition at line 2727 of file jsstr.c.

{
    JSHashNumber h;
    const jschar *s;
    size_t n;

    h = 0;
    for (s = JSSTRING_CHARS(str), n = JSSTRING_LENGTH(str); n; s++, n--)

Here is the caller graph for this function:

jschar* js_InflateString ( JSContext cx,
const char *  bytes,
size_t *  bytesLength 
)

Definition at line 3050 of file jsstr.c.

{
    jschar *chars;
    size_t i, length = *bytesLength;

    chars = (jschar *) JS_malloc(cx, (length + 1) * sizeof(jschar));
    if (!chars) {
        *bytesLength = 0;
        return NULL;
    }
    for (i = 0; i < length; i++)
        chars[i] = (unsigned char) bytes[i];
    chars[length] = 0;

Here is the caller graph for this function:

JSBool js_InflateStringToBuffer ( JSContext cx,
const char *  bytes,
size_t  length,
jschar chars,
size_t *  charsLength 
)

Definition at line 3029 of file jsstr.c.

{
    size_t i;

    if (length > *charsLength) {
        for (i = 0; i < *charsLength; i++)
            chars[i] = (unsigned char) bytes[i];
        if (cx) {
            JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
                                 JSMSG_BUFFER_TOO_SMALL);
        }
        return JS_FALSE;
    }
    for (i = 0; i < length; i++)
        chars[i] = (unsigned char) bytes[i];

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2345 of file jsstr.c.

{
    JSRuntime *rt;
    JSString *empty;
    JSAtom *atom;

    rt = cx->runtime;

    /* Initialize string cache */
#ifdef JS_THREADSAFE
    JS_ASSERT(!rt->deflatedStringCacheLock);
    rt->deflatedStringCacheLock = JS_NEW_LOCK();
    if (!rt->deflatedStringCacheLock)
        return JS_FALSE;
#endif

    /* Make a permanently locked empty string. */
    JS_ASSERT(!rt->emptyString);
    empty = js_NewStringCopyN(cx, js_empty_ucstr, 0, GCF_LOCK);
    if (!empty)
        goto bad;

    /* Atomize it for scripts that use '' + x to convert x to string. */
    atom = js_AtomizeString(cx, empty, ATOM_PINNED);
    if (!atom)
        goto bad;

    rt->emptyString = empty;
    rt->atomState.emptyAtom = atom;

    return JS_TRUE;

  bad:
#ifdef JS_THREADSAFE
    JS_DESTROY_LOCK(rt->deflatedStringCacheLock);
    rt->deflatedStringCacheLock = NULL;
#endif

Here is the caller graph for this function:

Definition at line 2411 of file jsstr.c.

{
    JSObject *proto;

    /* Define the escape, unescape functions in the global object. */
    if (!JS_DefineFunctions(cx, obj, string_functions))
        return NULL;

    proto = JS_InitClass(cx, obj, NULL, &js_StringClass, String, 1,
                         string_props, string_methods,
                         NULL, string_static_methods);
    if (!proto)
        return NULL;
    OBJ_SET_SLOT(cx, proto, JSSLOT_PRIVATE,

Here is the caller graph for this function:

size_t js_MinimizeDependentStrings ( JSString str,
int  level,
JSString **  basep 
)

Definition at line 76 of file jsstr.c.

{
    JSString *base;
    size_t start, length;

    JS_ASSERT(JSSTRING_IS_DEPENDENT(str));
    base = JSSTRDEP_BASE(str);
    start = JSSTRDEP_START(str);
    if (JSSTRING_IS_DEPENDENT(base)) {
        if (level < JSSTRDEP_RECURSION_LIMIT) {
            start += js_MinimizeDependentStrings(base, level + 1, &base);
        } else {
            do {
                start += JSSTRDEP_START(base);
                base = JSSTRDEP_BASE(base);
            } while (JSSTRING_IS_DEPENDENT(base));
        }
        if (start == 0) {
            JS_ASSERT(JSSTRING_IS_PREFIX(str));
            JSPREFIX_SET_BASE(str, base);
        } else if (start <= JSSTRDEP_START_MASK) {
            length = JSSTRDEP_LENGTH(str);
            JSSTRDEP_SET_START_AND_LENGTH(str, start, length);
            JSSTRDEP_SET_BASE(str, base);
        }
    }
    *basep = base;
    return start;
}

Here is the call graph for this function:

Here is the caller graph for this function:

JSString* js_NewDependentString ( JSContext cx,
JSString base,
size_t  start,
size_t  length,
uintN  gcflag 
)

Definition at line 2458 of file jsstr.c.

{
    JSDependentString *ds;

    if (length == 0)
        return cx->runtime->emptyString;

    if (start == 0 && length == JSSTRING_LENGTH(base))
        return base;

    if (start > JSSTRDEP_START_MASK ||
        (start != 0 && length > JSSTRDEP_LENGTH_MASK)) {
        return js_NewStringCopyN(cx, JSSTRING_CHARS(base) + start, length,
                                 gcflag);
    }

    ds = (JSDependentString *)
         js_NewGCThing(cx, gcflag | GCX_MUTABLE_STRING, sizeof(JSString));
    if (!ds)
        return NULL;
    if (start == 0) {
        JSPREFIX_SET_LENGTH(ds, length);
        JSPREFIX_SET_BASE(ds, base);
    } else {
        JSSTRDEP_SET_START_AND_LENGTH(ds, start, length);
        JSSTRDEP_SET_BASE(ds, base);
    }
#ifdef DEBUG
  {
    JSRuntime *rt = cx->runtime;
    JS_RUNTIME_METER(rt, liveDependentStrings);
    JS_RUNTIME_METER(rt, totalDependentStrings);
    JS_RUNTIME_METER(rt, liveStrings);
    JS_RUNTIME_METER(rt, totalStrings);
    JS_LOCK_RUNTIME_VOID(rt,
        (rt->strdepLengthSum += (double)length,
         rt->strdepLengthSquaredSum += (double)length * (double)length));
    JS_LOCK_RUNTIME_VOID(rt,
        (rt->lengthSum += (double)length,
         rt->lengthSquaredSum += (double)length * (double)length));
  }

Here is the caller graph for this function:

JSString* js_NewString ( JSContext cx,
jschar chars,
size_t  length,
uintN  gcflag 
)

Definition at line 2430 of file jsstr.c.

{
    JSString *str;

    if (length > JSSTRING_LENGTH_MASK) {
        JS_ReportOutOfMemory(cx);
        return NULL;
    }

    str = (JSString *) js_NewGCThing(cx, gcflag | GCX_STRING, sizeof(JSString));
    if (!str)
        return NULL;
    str->length = length;
    str->chars = chars;
#ifdef DEBUG
  {
    JSRuntime *rt = cx->runtime;
    JS_RUNTIME_METER(rt, liveStrings);
    JS_RUNTIME_METER(rt, totalStrings);
    JS_LOCK_RUNTIME_VOID(rt,
        (rt->lengthSum += (double)length,
         rt->lengthSquaredSum += (double)length * (double)length));
  }

Here is the caller graph for this function:

JSString* js_NewStringCopyN ( JSContext cx,
const jschar s,
size_t  n,
uintN  gcflag 
)

Definition at line 2544 of file jsstr.c.

{
    jschar *news;
    JSString *str;

    news = (jschar *)JS_malloc(cx, (n + 1) * sizeof(jschar));
    if (!news)
        return NULL;
    js_strncpy(news, s, n);
    news[n] = 0;
    str = js_NewString(cx, news, n, gcflag);
    if (!str)

Here is the call graph for this function:

Here is the caller graph for this function:

JSString* js_NewStringCopyZ ( JSContext cx,
const jschar s,
uintN  gcflag 
)

Definition at line 2561 of file jsstr.c.

{
    size_t n, m;
    jschar *news;
    JSString *str;

    n = js_strlen(s);
    m = (n + 1) * sizeof(jschar);
    news = (jschar *) JS_malloc(cx, m);
    if (!news)
        return NULL;
    memcpy(news, s, m);
    str = js_NewString(cx, news, n, gcflag);
    if (!str)

Here is the caller graph for this function:

int js_OneUcs4ToUtf8Char ( uint8 utf8Buffer,
uint32  ucs4Char 
)

Definition at line 4756 of file jsstr.c.

{
    int utf8Length = 1;

    JS_ASSERT(ucs4Char <= 0x7FFFFFFF);
    if (ucs4Char < 0x80) {
        *utf8Buffer = (uint8)ucs4Char;
    } else {
        int i;
        uint32 a = ucs4Char >> 11;
        utf8Length = 2;
        while (a) {
            a >>= 5;
            utf8Length++;
        }
        i = utf8Length;
        while (--i) {
            utf8Buffer[i] = (uint8)((ucs4Char & 0x3F) | 0x80);
            ucs4Char >>= 6;
        }
        *utf8Buffer = (uint8)(0x100 - (1 << (8-utf8Length)) + ucs4Char);

Here is the caller graph for this function:

Definition at line 2586 of file jsstr.c.

{
    JSHashNumber hash;
    JSHashEntry *he, **hep;

    if (!rt->deflatedStringCache)
        return;

    hash = js_hash_string_pointer(str);
    JS_ACQUIRE_LOCK(rt->deflatedStringCacheLock);
    hep = JS_HashTableRawLookup(rt->deflatedStringCache, hash, str);
    he = *hep;
    if (he) {
#ifdef DEBUG
        rt->deflatedStringCacheBytes -= JSSTRING_LENGTH(str);
#endif
        free(he->value);
        JS_HashTableRawRemove(rt->deflatedStringCache, hep, he);

Here is the caller graph for this function:

JSBool js_SetStringBytes ( JSRuntime rt,
JSString str,
char *  bytes,
size_t  length 
)

Definition at line 3127 of file jsstr.c.

{
    JSHashTable *cache;
    JSBool ok;
    JSHashNumber hash;
    JSHashEntry **hep;

    JS_ACQUIRE_LOCK(rt->deflatedStringCacheLock);

    cache = GetDeflatedStringCache(rt);
    if (!cache) {
        ok = JS_FALSE;
    } else {
        hash = js_hash_string_pointer(str);
        hep = JS_HashTableRawLookup(cache, hash, str);
        JS_ASSERT(*hep == NULL);
        ok = JS_HashTableRawAdd(cache, hep, hash, str, bytes) != NULL;
#ifdef DEBUG
        if (ok)
            rt->deflatedStringCacheBytes += length;
#endif
    }

Here is the caller graph for this function:

Definition at line 2827 of file jsstr.c.

{
    /* JS_ISSPACE is false on a null. */
    while (JS_ISSPACE(*s))

Here is the caller graph for this function:

JSBool js_str_escape ( JSContext cx,
JSObject obj,
uintN  argc,
jsval argv,
jsval rval 
)

Definition at line 310 of file jsstr.c.

{
    JSString *str;
    size_t i, ni, length, newlength;
    const jschar *chars;
    jschar *newchars;
    jschar ch;
    jsint mask;
    jsdouble d;
    const char digits[] = {'0', '1', '2', '3', '4', '5', '6', '7',
                           '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };

    mask = URL_XALPHAS | URL_XPALPHAS | URL_PATH;
    if (argc > 1) {
        if (!js_ValueToNumber(cx, argv[1], &d))
            return JS_FALSE;
        if (!JSDOUBLE_IS_FINITE(d) ||
            (mask = (jsint)d) != d ||
            mask & ~(URL_XALPHAS | URL_XPALPHAS | URL_PATH))
        {
            char numBuf[12];
            JS_snprintf(numBuf, sizeof numBuf, "%lx", (unsigned long) mask);
            JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
                                 JSMSG_BAD_STRING_MASK, numBuf);
            return JS_FALSE;
        }
    }

    str = js_ValueToString(cx, argv[0]);
    if (!str)
        return JS_FALSE;
    argv[0] = STRING_TO_JSVAL(str);

    chars = JSSTRING_CHARS(str);
    length = newlength = JSSTRING_LENGTH(str);

    /* Take a first pass and see how big the result string will need to be. */
    for (i = 0; i < length; i++) {
        if ((ch = chars[i]) < 128 && IS_OK(ch, mask))
            continue;
        if (ch < 256) {
            if (mask == URL_XPALPHAS && ch == ' ')
                continue;   /* The character will be encoded as '+' */
            newlength += 2; /* The character will be encoded as %XX */
        } else {
            newlength += 5; /* The character will be encoded as %uXXXX */
        }

        /*
         * This overflow test works because newlength is incremented by at
         * most 5 on each iteration.
         */
        if (newlength < length) {
            JS_ReportOutOfMemory(cx);
            return JS_FALSE;
        }
    }

    if (newlength >= ~(size_t)0 / sizeof(jschar)) {
        JS_ReportOutOfMemory(cx);
        return JS_FALSE;
    }

    newchars = (jschar *) JS_malloc(cx, (newlength + 1) * sizeof(jschar));
    if (!newchars)
        return JS_FALSE;
    for (i = 0, ni = 0; i < length; i++) {
        if ((ch = chars[i]) < 128 && IS_OK(ch, mask)) {
            newchars[ni++] = ch;
        } else if (ch < 256) {
            if (mask == URL_XPALPHAS && ch == ' ') {
                newchars[ni++] = '+'; /* convert spaces to pluses */
            } else {
                newchars[ni++] = '%';
                newchars[ni++] = digits[ch >> 4];
                newchars[ni++] = digits[ch & 0xF];
            }
        } else {
            newchars[ni++] = '%';
            newchars[ni++] = 'u';
            newchars[ni++] = digits[ch >> 12];
            newchars[ni++] = digits[(ch & 0xF00) >> 8];
            newchars[ni++] = digits[(ch & 0xF0) >> 4];
            newchars[ni++] = digits[ch & 0xF];
        }
    }
    JS_ASSERT(ni == newlength);
    newchars[newlength] = 0;

    str = js_NewString(cx, newchars, newlength, 0);
    if (!str) {
        JS_free(cx, newchars);
        return JS_FALSE;
    }
    *rval = STRING_TO_JSVAL(str);
    return JS_TRUE;
}

Here is the call graph for this function:

jschar* js_strchr ( const jschar s,
jschar  c 
)

Definition at line 2805 of file jsstr.c.

{
    while (*s != 0) {
        if (*s == c)
            return (jschar *)s;
        s++;

Here is the caller graph for this function:

jschar* js_strchr_limit ( const jschar s,
jschar  c,
const jschar limit 
)

Definition at line 2816 of file jsstr.c.

{
    while (s < limit) {
        if (*s == c)
            return (jschar *)s;
        s++;

Here is the caller graph for this function:

JSObject* js_StringToObject ( JSContext cx,
JSString str 
)

Definition at line 2639 of file jsstr.c.

{
    JSObject *obj;

    obj = js_NewObject(cx, &js_StringClass, NULL, NULL);
    if (!obj)
        return NULL;

Here is the caller graph for this function:

size_t js_strlen ( const jschar s)

Definition at line 2795 of file jsstr.c.

{
    const jschar *t;

    for (t = s; *t != 0; t++)

Here is the caller graph for this function:

Definition at line 215 of file jsstr.c.

{
    size_t n, size;
    jschar *s;

    if (JSSTRING_IS_DEPENDENT(str)) {
        n = JSSTRDEP_LENGTH(str);
        size = (n + 1) * sizeof(jschar);
        s = (jschar *) (cx ? JS_malloc(cx, size) : malloc(size));
        if (!s)
            return NULL;

        js_strncpy(s, JSSTRDEP_CHARS(str), n);
        s[n] = 0;
        str->length = n;
        str->chars = s;

#ifdef DEBUG
        if (cx) {
            JSRuntime *rt = cx->runtime;
            JS_RUNTIME_UNMETER(rt, liveDependentStrings);
            JS_RUNTIME_UNMETER(rt, totalDependentStrings);
            JS_LOCK_RUNTIME_VOID(rt,
                (rt->strdepLengthSum -= (double)n,
                 rt->strdepLengthSquaredSum -= (double)n * (double)n));
        }
#endif
    }

    return str->chars;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2651 of file jsstr.c.

{
    JSString *str;
    const char *bytes;

    str = v2sfun(cx, v);
    if (!str)
        return NULL;
    str = js_QuoteString(cx, str, 0);
    if (!str)
        return NULL;
    bytes = js_GetStringBytes(cx->runtime, str);
    if (!bytes)
js_ValueToSource ( JSContext cx,
jsval  v 
)

Definition at line 2696 of file jsstr.c.

{
    JSTempValueRooter tvr;
    JSString *str;

    if (JSVAL_IS_STRING(v))
        return js_QuoteString(cx, JSVAL_TO_STRING(v), '"');
    if (JSVAL_IS_PRIMITIVE(v)) {
        /* Special case to preserve negative zero, _contra_ toString. */
        if (JSVAL_IS_DOUBLE(v) && JSDOUBLE_IS_NEGZERO(*JSVAL_TO_DOUBLE(v))) {
            /* NB: _ucNstr rather than _ucstr to indicate non-terminated. */
            static const jschar js_negzero_ucNstr[] = {'-', '0'};

            return js_NewStringCopyN(cx, js_negzero_ucNstr, 2, 0);
        }
        return js_ValueToString(cx, v);
    }

    JS_PUSH_SINGLE_TEMP_ROOT(cx, JSVAL_NULL, &tvr);
    if (!js_TryMethod(cx, JSVAL_TO_OBJECT(v),
                      cx->runtime->atomState.toSourceAtom,
                      0, NULL, &tvr.u.value)) {
        str = NULL;
    } else {
        str = js_ValueToString(cx, tvr.u.value);
    }

Here is the caller graph for this function:

js_ValueToString ( JSContext cx,
jsval  v 
)

Definition at line 2669 of file jsstr.c.

{
    JSObject *obj;
    JSString *str;

    if (JSVAL_IS_OBJECT(v)) {
        obj = JSVAL_TO_OBJECT(v);
        if (!obj)
            return ATOM_TO_STRING(cx->runtime->atomState.nullAtom);
        if (!OBJ_DEFAULT_VALUE(cx, obj, JSTYPE_STRING, &v))
            return NULL;
    }
    if (JSVAL_IS_STRING(v)) {
        str = JSVAL_TO_STRING(v);
    } else if (JSVAL_IS_INT(v)) {
        str = js_NumberToString(cx, JSVAL_TO_INT(v));
    } else if (JSVAL_IS_DOUBLE(v)) {
        str = js_NumberToString(cx, *JSVAL_TO_DOUBLE(v));
    } else if (JSVAL_IS_BOOLEAN(v)) {
        str = js_BooleanToString(cx, JSVAL_TO_BOOLEAN(v));
    } else {
        str = ATOM_TO_STRING(cx->runtime->atomState.typeAtoms[JSTYPE_VOID]);
static JSBool match_glob ( JSContext cx,
jsint  count,
GlobData data 
) [static]

Definition at line 1264 of file jsstr.c.

{
    MatchData *mdata;
    JSObject *arrayobj;
    JSSubString *matchsub;
    JSString *matchstr;
    jsval v;

    mdata = (MatchData *)data;
    arrayobj = JSVAL_TO_OBJECT(*mdata->arrayval);
    if (!arrayobj) {
        arrayobj = js_ConstructObject(cx, &js_ArrayClass, NULL, NULL, 0, NULL);
        if (!arrayobj)
            return JS_FALSE;
        *mdata->arrayval = OBJECT_TO_JSVAL(arrayobj);
    }
    matchsub = &cx->regExpStatics.lastMatch;
    matchstr = js_NewStringCopyN(cx, matchsub->chars, matchsub->length, 0);
    if (!matchstr)
        return JS_FALSE;
static JSBool match_or_replace ( JSContext cx,
JSObject obj,
uintN  argc,
jsval argv,
JSBool(*)(JSContext *cx, jsint count, GlobData *data glob,
GlobData data,
jsval rval 
) [static]

Definition at line 1132 of file jsstr.c.

{
    JSString *str, *src, *opt;
    JSObject *reobj;
    JSRegExp *re;
    size_t index, length;
    JSBool ok, test;
    jsint count;

    str = js_ValueToString(cx, OBJECT_TO_JSVAL(obj));
    if (!str)
        return JS_FALSE;
    argv[-1] = STRING_TO_JSVAL(str);
    data->str = str;

    if (JSVAL_IS_REGEXP(cx, argv[0])) {
        reobj = JSVAL_TO_OBJECT(argv[0]);
        re = (JSRegExp *) JS_GetPrivate(cx, reobj);
    } else {
        src = js_ValueToString(cx, argv[0]);
        if (!src)
            return JS_FALSE;
        if (data->optarg < argc) {
            argv[0] = STRING_TO_JSVAL(src);
            opt = js_ValueToString(cx, argv[data->optarg]);
            if (!opt)
                return JS_FALSE;
        } else {
            opt = NULL;
        }
        re = js_NewRegExpOpt(cx, NULL, src, opt,
                             (data->flags & FORCE_FLAT) != 0);
        if (!re)
            return JS_FALSE;
        reobj = NULL;
    }
    /* From here on, all control flow must reach the matching DROP. */
    data->regexp = re;
    HOLD_REGEXP(cx, re);

    if (re->flags & JSREG_GLOB)
        data->flags |= GLOBAL_REGEXP;
    index = 0;
    if (GET_MODE(data->flags) == MODE_SEARCH) {
        ok = js_ExecuteRegExp(cx, re, str, &index, JS_TRUE, rval);
        if (ok) {
            *rval = (*rval == JSVAL_TRUE)
                    ? INT_TO_JSVAL(cx->regExpStatics.leftContext.length)
                    : INT_TO_JSVAL(-1);
        }
    } else if (data->flags & GLOBAL_REGEXP) {
        if (reobj) {
            /* Set the lastIndex property's reserved slot to 0. */
            ok = js_SetLastIndex(cx, reobj, 0);
        } else {
            ok = JS_TRUE;
        }
        if (ok) {
            length = JSSTRING_LENGTH(str);
            for (count = 0; index <= length; count++) {
                ok = js_ExecuteRegExp(cx, re, str, &index, JS_TRUE, rval);
                if (!ok || *rval != JSVAL_TRUE)
                    break;
                ok = glob(cx, count, data);
                if (!ok)
                    break;
                if (cx->regExpStatics.lastMatch.length == 0) {
                    if (index == length)
                        break;
                    index++;
                }
            }
        }
    } else {
        if (GET_MODE(data->flags) == MODE_REPLACE) {
            test = JS_TRUE;
        } else {
            /*
             * MODE_MATCH implies str_match is being called from a script or a
             * scripted function.  If the caller cares only about testing null
             * vs. non-null return value, optimize away the array object that
             * would normally be returned in *rval.
             */
            JSStackFrame *fp = cx->fp->down;

            /* Skip Function.prototype.call and .apply frames. */
            while (fp && !fp->pc) {
                JS_ASSERT(!fp->script);
                fp = fp->down;
            }

            /* Assume a full array result is required, then prove otherwise. */
            test = JS_FALSE;
            if (fp) {
                JS_ASSERT(*fp->pc == JSOP_CALL || *fp->pc == JSOP_NEW);
                JS_ASSERT(js_CodeSpec[*fp->pc].length == 3);
                switch (fp->pc[3]) {
                  case JSOP_POP:
                  case JSOP_IFEQ:
                  case JSOP_IFNE:
                  case JSOP_IFEQX:
                  case JSOP_IFNEX:
                    test = JS_TRUE;
                    break;
                  default:;
                }
            }
        }
        ok = js_ExecuteRegExp(cx, re, str, &index, test, rval);
    }

    DROP_REGEXP(cx, re);
    if (reobj) {
        /* Tell our caller that it doesn't need to destroy data->regexp. */
        data->flags &= ~KEEP_REGEXP;
    } else if (!(data->flags & KEEP_REGEXP)) {
        /* Caller didn't want to keep data->regexp, so null and destroy it.  */
        data->regexp = NULL;
        js_DestroyRegExp(cx, re);
    }

Here is the call graph for this function:

static JSBool replace_glob ( JSContext cx,
jsint  count,
GlobData data 
) [static]

Definition at line 1548 of file jsstr.c.

{
    ReplaceData *rdata;
    JSString *str;
    size_t leftoff, leftlen, replen, growth;
    const jschar *left;
    jschar *chars;

    rdata = (ReplaceData *)data;
    str = data->str;
    leftoff = rdata->leftIndex;
    left = JSSTRING_CHARS(str) + leftoff;
    leftlen = cx->regExpStatics.lastMatch.chars - left;
    rdata->leftIndex = cx->regExpStatics.lastMatch.chars - JSSTRING_CHARS(str);
    rdata->leftIndex += cx->regExpStatics.lastMatch.length;
    if (!find_replen(cx, rdata, &replen))
        return JS_FALSE;
    growth = leftlen + replen;
    chars = (jschar *)
        (rdata->chars
         ? JS_realloc(cx, rdata->chars, (rdata->length + growth + 1)
                                        * sizeof(jschar))
         : JS_malloc(cx, (growth + 1) * sizeof(jschar)));
    if (!chars) {
        JS_free(cx, rdata->chars);
        rdata->chars = NULL;
        return JS_FALSE;
    }
    rdata->chars = chars;
    rdata->length += growth;
    chars += rdata->index;
    rdata->index += growth;
    js_strncpy(chars, left, leftlen);
    chars += leftlen;
static JSBool str_anchor ( JSContext cx,
JSObject obj,
uintN  argc,
jsval argv,
jsval rval 
) [static]

Definition at line 2175 of file jsstr.c.

{
static JSBool str_big ( JSContext cx,
JSObject obj,
uintN  argc,
jsval argv,
jsval rval 
) [static]

Definition at line 2193 of file jsstr.c.

{
static JSBool str_blink ( JSContext cx,
JSObject obj,
uintN  argc,
jsval argv,
jsval rval 
) [static]

Definition at line 2199 of file jsstr.c.

{
static JSBool str_bold ( JSContext cx,
JSObject obj,
uintN  argc,
jsval argv,
jsval rval 
) [static]

Definition at line 2138 of file jsstr.c.

{
static JSBool str_charAt ( JSContext cx,
JSObject obj,
uintN  argc,
jsval argv,
jsval rval 
) [static]

Definition at line 890 of file jsstr.c.

{
    JSString *str;
    jsdouble d;
    size_t index;

    str = js_ValueToString(cx, OBJECT_TO_JSVAL(obj));
    if (!str)
        return JS_FALSE;
    argv[-1] = STRING_TO_JSVAL(str);

    if (argc == 0) {
        d = 0.0;
    } else {
        if (!js_ValueToNumber(cx, argv[0], &d))
            return JS_FALSE;
        d = js_DoubleToInteger(d);
    }

    if (d < 0 || JSSTRING_LENGTH(str) <= d) {
        *rval = JS_GetEmptyStringValue(cx);
    } else {
        index = (size_t)d;
        str = js_NewDependentString(cx, str, index, 1, 0);
        if (!str)
            return JS_FALSE;
        *rval = STRING_TO_JSVAL(str);
    }
    return JS_TRUE;
}

Here is the call graph for this function:

static JSBool str_charCodeAt ( JSContext cx,
JSObject obj,
uintN  argc,
jsval argv,
jsval rval 
) [static]

Definition at line 922 of file jsstr.c.

{
    JSString *str;
    jsdouble d;
    size_t index;

    str = js_ValueToString(cx, OBJECT_TO_JSVAL(obj));
    if (!str)
        return JS_FALSE;
    argv[-1] = STRING_TO_JSVAL(str);

    if (argc == 0) {
        d = 0.0;
    } else {
        if (!js_ValueToNumber(cx, argv[0], &d))
            return JS_FALSE;
        d = js_DoubleToInteger(d);
    }

    if (d < 0 || JSSTRING_LENGTH(str) <= d) {
        *rval = JS_GetNaNValue(cx);
    } else {
        index = (size_t)d;
        *rval = INT_TO_JSVAL((jsint) JSSTRING_CHARS(str)[index]);
    }
    return JS_TRUE;
}

Here is the call graph for this function:

static JSBool str_concat ( JSContext cx,
JSObject obj,
uintN  argc,
jsval argv,
jsval rval 
) [static]

Definition at line 1971 of file jsstr.c.

{
    JSString *str, *str2;
    uintN i;

    str = js_ValueToString(cx, OBJECT_TO_JSVAL(obj));
    if (!str)
        return JS_FALSE;
    argv[-1] = STRING_TO_JSVAL(str);

    for (i = 0; i < argc; i++) {
        str2 = js_ValueToString(cx, argv[i]);
        if (!str2)
            return JS_FALSE;
        argv[i] = STRING_TO_JSVAL(str2);

        str = js_ConcatStrings(cx, str, str2);
        if (!str)
            return JS_FALSE;
    }

Here is the call graph for this function:

static JSBool str_decodeURI ( JSContext cx,
JSObject obj,
uintN  argc,
jsval argv,
jsval rval 
) [static]

Definition at line 4699 of file jsstr.c.

{
    JSString *str;

    str = js_ValueToString(cx, argv[0]);
    if (!str)
        return JS_FALSE;
static JSBool str_decodeURI_Component ( JSContext cx,
JSObject obj,
uintN  argc,
jsval argv,
jsval rval 
) [static]

Definition at line 4712 of file jsstr.c.

{
    JSString *str;

    str = js_ValueToString(cx, argv[0]);
    if (!str)
        return JS_FALSE;
static JSBool str_encodeURI ( JSContext cx,
JSObject obj,
uintN  argc,
jsval argv,
jsval rval 
) [static]

Definition at line 4725 of file jsstr.c.

{
    JSString *str;

    str = js_ValueToString(cx, argv[0]);
    if (!str)
        return JS_FALSE;
    argv[0] = STRING_TO_JSVAL(str);
static JSBool str_encodeURI_Component ( JSContext cx,
JSObject obj,
uintN  argc,
jsval argv,
jsval rval 
) [static]

Definition at line 4739 of file jsstr.c.

{
    JSString *str;

    str = js_ValueToString(cx, argv[0]);
    if (!str)
        return JS_FALSE;
static JSBool str_enumerate ( JSContext cx,
JSObject obj 
) [static]

Definition at line 547 of file jsstr.c.

{
    jsval v;
    JSString *str, *str1;
    size_t i, length;

    v = OBJ_GET_SLOT(cx, obj, JSSLOT_PRIVATE);
    JS_ASSERT(JSVAL_IS_STRING(v));
    str = JSVAL_TO_STRING(v);

    length = JSSTRING_LENGTH(str);
    for (i = 0; i < length; i++) {
        str1 = js_NewDependentString(cx, str, i, 1, 0);
        if (!str1)
            return JS_FALSE;
        if (!OBJ_DEFINE_PROPERTY(cx, obj, INT_TO_JSID(i),
                                 STRING_TO_JSVAL(str1), NULL, NULL,
                                 STRING_ELEMENT_ATTRS, NULL)) {
            return JS_FALSE;
        }
    }
    return JS_TRUE;
}

Here is the call graph for this function:

static JSBool str_fixed ( JSContext cx,
JSObject obj,
uintN  argc,
jsval argv,
jsval rval 
) [static]

Definition at line 2150 of file jsstr.c.

{
static JSBool str_fontcolor ( JSContext cx,
JSObject obj,
uintN  argc,
jsval argv,
jsval rval 
) [static]

Definition at line 2162 of file jsstr.c.

{
static JSBool str_fontsize ( JSContext cx,
JSObject obj,
uintN  argc,
jsval argv,
jsval rval 
) [static]

Definition at line 2156 of file jsstr.c.

{
static JSBool str_fromCharCode ( JSContext cx,
JSObject obj,
uintN  argc,
jsval argv,
jsval rval 
) [static]

Definition at line 2310 of file jsstr.c.

{
    jschar *chars;
    uintN i;
    uint16 code;
    JSString *str;

    JS_ASSERT(argc < ARRAY_INIT_LIMIT);
    chars = (jschar *) JS_malloc(cx, (argc + 1) * sizeof(jschar));
    if (!chars)
        return JS_FALSE;
    for (i = 0; i < argc; i++) {
        if (!js_ValueToUint16(cx, argv[i], &code)) {
            JS_free(cx, chars);
            return JS_FALSE;
        }
        chars[i] = (jschar)code;
    }
    chars[i] = 0;
    str = js_NewString(cx, chars, argc, 0);
    if (!str) {
        JS_free(cx, chars);
        return JS_FALSE;
    }
static JSBool str_getProperty ( JSContext cx,
JSObject obj,
jsval  id,
jsval vp 
) [static]

Definition at line 516 of file jsstr.c.

{
    jsval v;
    JSString *str;
    jsint slot;

    if (!JSVAL_IS_INT(id))
        return JS_TRUE;

    slot = JSVAL_TO_INT(id);
    if (slot == STRING_LENGTH) {
        if (OBJ_GET_CLASS(cx, obj) == &js_StringClass) {
            /* Follow ECMA-262 by fetching intrinsic length of our string. */
            v = OBJ_GET_SLOT(cx, obj, JSSLOT_PRIVATE);
            JS_ASSERT(JSVAL_IS_STRING(v));
            str = JSVAL_TO_STRING(v);
        } else {
            /* Preserve compatibility: convert obj to a string primitive. */
            str = js_ValueToString(cx, OBJECT_TO_JSVAL(obj));
            if (!str)
                return JS_FALSE;
        }

        *vp = INT_TO_JSVAL((jsint) JSSTRING_LENGTH(str));
    }
    return JS_TRUE;
}

Here is the call graph for this function:

static JSBool str_indexOf ( JSContext cx,
JSObject obj,
uintN  argc,
jsval argv,
jsval rval 
) [static]

Definition at line 984 of file jsstr.c.

{
    JSString *str, *str2;
    jsint i, j, index, textlen, patlen;
    const jschar *text, *pat;
    jsdouble d;

    str = js_ValueToString(cx, OBJECT_TO_JSVAL(obj));
    if (!str)
        return JS_FALSE;
    argv[-1] = STRING_TO_JSVAL(str);
    text = JSSTRING_CHARS(str);
    textlen = (jsint) JSSTRING_LENGTH(str);

    str2 = js_ValueToString(cx, argv[0]);
    if (!str2)
        return JS_FALSE;
    argv[0] = STRING_TO_JSVAL(str2);
    pat = JSSTRING_CHARS(str2);
    patlen = (jsint) JSSTRING_LENGTH(str2);

    if (argc > 1) {
        if (!js_ValueToNumber(cx, argv[1], &d))
            return JS_FALSE;
        d = js_DoubleToInteger(d);
        if (d < 0)
            i = 0;
        else if (d > textlen)
            i = textlen;
        else
            i = (jsint)d;
    } else {
        i = 0;
    }
    if (patlen == 0) {
        *rval = INT_TO_JSVAL(i);
        return JS_TRUE;
    }

    /* XXX tune the BMH threshold (512) */
    if ((jsuint)(patlen - 2) <= BMH_PATLEN_MAX - 2 && textlen >= 512) {
        index = js_BoyerMooreHorspool(text, textlen, pat, patlen, i);
        if (index != BMH_BAD_PATTERN)
            goto out;
    }

    index = -1;
    j = 0;
    while (i + j < textlen) {
        if (text[i + j] == pat[j]) {
            if (++j == patlen) {
                index = i;
                break;
            }
        } else {
            i++;
            j = 0;
        }
    }

out:
    *rval = INT_TO_JSVAL(index);
    return JS_TRUE;
}

Here is the call graph for this function:

static JSBool str_italics ( JSContext cx,
JSObject obj,
uintN  argc,
jsval argv,
jsval rval 
) [static]

Definition at line 2144 of file jsstr.c.

{
static JSBool str_lastIndexOf ( JSContext cx,
JSObject obj,
uintN  argc,
jsval argv,
jsval rval 
) [static]

Definition at line 1050 of file jsstr.c.

{
    JSString *str, *str2;
    const jschar *text, *pat;
    jsint i, j, textlen, patlen;
    jsdouble d;

    str = js_ValueToString(cx, OBJECT_TO_JSVAL(obj));
    if (!str)
        return JS_FALSE;
    argv[-1] = STRING_TO_JSVAL(str);
    text = JSSTRING_CHARS(str);
    textlen = (jsint) JSSTRING_LENGTH(str);

    str2 = js_ValueToString(cx, argv[0]);
    if (!str2)
        return JS_FALSE;
    argv[0] = STRING_TO_JSVAL(str2);
    pat = JSSTRING_CHARS(str2);
    patlen = (jsint) JSSTRING_LENGTH(str2);

    if (argc > 1) {
        if (!js_ValueToNumber(cx, argv[1], &d))
            return JS_FALSE;
        if (JSDOUBLE_IS_NaN(d)) {
            i = textlen;
        } else {
            d = js_DoubleToInteger(d);
            if (d < 0)
                i = 0;
            else if (d > textlen)
                i = textlen;
            else
                i = (jsint)d;
        }
    } else {
        i = textlen;
    }

    if (patlen == 0) {
        *rval = INT_TO_JSVAL(i);
        return JS_TRUE;
    }

    j = 0;
    while (i >= 0) {
        /* Don't assume that text is NUL-terminated: it could be dependent. */
        if (i + j < textlen && text[i + j] == pat[j]) {
            if (++j == patlen)
                break;
        } else {
            i--;
            j = 0;
        }
    }
    *rval = INT_TO_JSVAL(i);
    return JS_TRUE;
}

Here is the call graph for this function:

static JSBool str_link ( JSContext cx,
JSObject obj,
uintN  argc,
jsval argv,
jsval rval 
) [static]

Definition at line 2169 of file jsstr.c.

{
static JSBool str_localeCompare ( JSContext cx,
JSObject obj,
uintN  argc,
jsval argv,
jsval rval 
) [static]

Definition at line 864 of file jsstr.c.

{
    JSString *str, *thatStr;

    str = js_ValueToString(cx, OBJECT_TO_JSVAL(obj));
    if (!str)
        return JS_FALSE;
    argv[-1] = STRING_TO_JSVAL(str);

    if (argc == 0) {
        *rval = JSVAL_ZERO;
    } else {
        thatStr = js_ValueToString(cx, argv[0]);
        if (!thatStr)
            return JS_FALSE;
        if (cx->localeCallbacks && cx->localeCallbacks->localeCompare) {
            argv[0] = STRING_TO_JSVAL(thatStr);
            return cx->localeCallbacks->localeCompare(cx, str, thatStr, rval);
        }
        *rval = INT_TO_JSVAL(js_CompareStrings(str, thatStr));
    }
    return JS_TRUE;
}

Here is the call graph for this function:

static JSBool str_match ( JSContext cx,
JSObject obj,
uintN  argc,
jsval argv,
jsval rval 
) [static]

Definition at line 1289 of file jsstr.c.

{
    MatchData mdata;
    JSBool ok;

    mdata.base.flags = MODE_MATCH;
    mdata.base.optarg = 1;
    mdata.arrayval = &argv[2];
    *mdata.arrayval = JSVAL_NULL;
    ok = match_or_replace(cx, obj, argc, argv, match_glob, &mdata.base, rval);
    if (ok && !JSVAL_IS_NULL(*mdata.arrayval))
static JSBool str_quote ( JSContext cx,
JSObject obj,
uintN  argc,
jsval argv,
jsval rval 
) [static]

Definition at line 617 of file jsstr.c.

{
    JSString *str;

    str = js_ValueToString(cx, OBJECT_TO_JSVAL(obj));
    if (!str)
        return JS_FALSE;
    argv[-1] = STRING_TO_JSVAL(str);

    str = js_QuoteString(cx, str, '"');
    if (!str)
        return JS_FALSE;
    *rval = STRING_TO_JSVAL(str);
    return JS_TRUE;
}

Here is the call graph for this function:

static JSBool str_replace ( JSContext cx,
JSObject obj,
uintN  argc,
jsval argv,
jsval rval 
) [static]

Definition at line 1587 of file jsstr.c.

{
    JSObject *lambda;
    JSString *repstr, *str;
    ReplaceData rdata;
    JSBool ok;
    jschar *chars;
    size_t leftlen, rightlen, length;

    if (JS_TypeOfValue(cx, argv[1]) == JSTYPE_FUNCTION) {
        lambda = JSVAL_TO_OBJECT(argv[1]);
        repstr = NULL;
    } else {
        if (!JS_ConvertValue(cx, argv[1], JSTYPE_STRING, &argv[1]))
            return JS_FALSE;
        repstr = JSVAL_TO_STRING(argv[1]);
        lambda = NULL;
    }

    /*
     * For ECMA Edition 3, the first argument is to be converted to a string
     * to match in a "flat" sense (without regular expression metachars having
     * special meanings) UNLESS the first arg is a RegExp object.
     */
    rdata.base.flags = MODE_REPLACE | KEEP_REGEXP | FORCE_FLAT;
    rdata.base.optarg = 2;

    rdata.lambda = lambda;
    rdata.repstr = repstr;
    if (repstr) {
        rdata.dollarEnd = JSSTRING_CHARS(repstr) + JSSTRING_LENGTH(repstr);
        rdata.dollar = js_strchr_limit(JSSTRING_CHARS(repstr), '$',
                                       rdata.dollarEnd);
    } else {
        rdata.dollar = rdata.dollarEnd = NULL;
    }
    rdata.chars = NULL;
    rdata.length = 0;
    rdata.index = 0;
    rdata.leftIndex = 0;

    ok = match_or_replace(cx, obj, argc, argv, replace_glob, &rdata.base, rval);
    if (!ok)
        return JS_FALSE;

    if (!rdata.chars) {
        if ((rdata.base.flags & GLOBAL_REGEXP) || *rval != JSVAL_TRUE) {
            /* Didn't match even once. */
            *rval = STRING_TO_JSVAL(rdata.base.str);
            goto out;
        }
        leftlen = cx->regExpStatics.leftContext.length;
        ok = find_replen(cx, &rdata, &length);
        if (!ok)
            goto out;
        length += leftlen;
        chars = (jschar *) JS_malloc(cx, (length + 1) * sizeof(jschar));
        if (!chars) {
            ok = JS_FALSE;
            goto out;
        }
        js_strncpy(chars, cx->regExpStatics.leftContext.chars, leftlen);
        do_replace(cx, &rdata, chars + leftlen);
        rdata.chars = chars;
        rdata.length = length;
    }

    rightlen = cx->regExpStatics.rightContext.length;
    length = rdata.length + rightlen;
    chars = (jschar *)
        JS_realloc(cx, rdata.chars, (length + 1) * sizeof(jschar));
    if (!chars) {
        JS_free(cx, rdata.chars);
        ok = JS_FALSE;
        goto out;
    }
    js_strncpy(chars + rdata.length, cx->regExpStatics.rightContext.chars,
               rightlen);
    chars[length] = 0;

    str = js_NewString(cx, chars, length, 0);
    if (!str) {
        JS_free(cx, chars);
        ok = JS_FALSE;
        goto out;
    }
    *rval = STRING_TO_JSVAL(str);

out:
    /* If KEEP_REGEXP is still set, it's our job to destroy regexp now. */
    if (rdata.base.flags & KEEP_REGEXP)
static JSBool str_resolve ( JSContext cx,
JSObject obj,
jsval  id,
uintN  flags,
JSObject **  objp 
) [static]

Definition at line 572 of file jsstr.c.

{
    jsval v;
    JSString *str, *str1;
    jsint slot;

    if (!JSVAL_IS_INT(id) || (flags & JSRESOLVE_ASSIGNING))
        return JS_TRUE;

    v = OBJ_GET_SLOT(cx, obj, JSSLOT_PRIVATE);
    JS_ASSERT(JSVAL_IS_STRING(v));
    str = JSVAL_TO_STRING(v);

    slot = JSVAL_TO_INT(id);
    if ((size_t)slot < JSSTRING_LENGTH(str)) {
        str1 = js_NewDependentString(cx, str, (size_t)slot, 1, 0);
        if (!str1)
            return JS_FALSE;
        if (!OBJ_DEFINE_PROPERTY(cx, obj, INT_TO_JSID(slot),
                                 STRING_TO_JSVAL(str1), NULL, NULL,
                                 STRING_ELEMENT_ATTRS, NULL)) {
            return JS_FALSE;
        }
        *objp = obj;
    }
    return JS_TRUE;
}

Here is the call graph for this function:

static JSBool str_search ( JSContext cx,
JSObject obj,
uintN  argc,
jsval argv,
jsval rval 
) [static]

Definition at line 1305 of file jsstr.c.

static JSBool str_slice ( JSContext cx,
JSObject obj,
uintN  argc,
jsval argv,
jsval rval 
) [static]

Definition at line 1997 of file jsstr.c.

{
    JSString *str;
    jsdouble d;
    jsdouble length, begin, end;

    str = js_ValueToString(cx, OBJECT_TO_JSVAL(obj));
    if (!str)
        return JS_FALSE;
    argv[-1] = STRING_TO_JSVAL(str);

    if (argc != 0) {
        if (!js_ValueToNumber(cx, argv[0], &d))
            return JS_FALSE;
        length = JSSTRING_LENGTH(str);
        begin = js_DoubleToInteger(d);
        if (begin < 0) {
            begin += length;
            if (begin < 0)
                begin = 0;
        } else if (begin > length) {
            begin = length;
        }

        if (argc == 1) {
            end = length;
        } else {
            if (!js_ValueToNumber(cx, argv[1], &d))
                return JS_FALSE;
            end = js_DoubleToInteger(d);
            if (end < 0) {
                end += length;
                if (end < 0)
                    end = 0;
            } else if (end > length) {
                end = length;
            }
            if (end < begin)
                end = begin;
        }

        str = js_NewDependentString(cx, str, (size_t)begin,
                                    (size_t)(end - begin), 0);
        if (!str)
            return JS_FALSE;
    }
static JSBool str_small ( JSContext cx,
JSObject obj,
uintN  argc,
jsval argv,
jsval rval 
) [static]

Definition at line 2187 of file jsstr.c.

{
static JSBool str_split ( JSContext cx,
JSObject obj,
uintN  argc,
jsval argv,
jsval rval 
) [static]

Definition at line 1803 of file jsstr.c.

{
    JSString *str, *sub;
    JSObject *arrayobj;
    jsval v;
    JSBool ok, limited;
    JSRegExp *re;
    JSSubString *sep, tmp;
    jsdouble d;
    jsint i, j;
    uint32 len, limit;

    str = js_ValueToString(cx, OBJECT_TO_JSVAL(obj));
    if (!str)
        return JS_FALSE;
    argv[-1] = STRING_TO_JSVAL(str);

    arrayobj = js_ConstructObject(cx, &js_ArrayClass, NULL, NULL, 0, NULL);
    if (!arrayobj)
        return JS_FALSE;
    *rval = OBJECT_TO_JSVAL(arrayobj);

    if (argc == 0) {
        v = STRING_TO_JSVAL(str);
        ok = JS_SetElement(cx, arrayobj, 0, &v);
    } else {
        if (JSVAL_IS_REGEXP(cx, argv[0])) {
            re = (JSRegExp *) JS_GetPrivate(cx, JSVAL_TO_OBJECT(argv[0]));
            sep = &tmp;

            /* Set a magic value so we can detect a successful re match. */
            sep->chars = NULL;
            sep->length = 0;
        } else {
            JSString *str2 = js_ValueToString(cx, argv[0]);
            if (!str2)
                return JS_FALSE;
            argv[0] = STRING_TO_JSVAL(str2);

            /*
             * Point sep at a local copy of str2's header because find_split
             * will modify sep->length.
             */
            tmp.length = JSSTRING_LENGTH(str2);
            tmp.chars = JSSTRING_CHARS(str2);
            sep = &tmp;
            re = NULL;
        }

        /* Use the second argument as the split limit, if given. */
        limited = (argc > 1) && !JSVAL_IS_VOID(argv[1]);
        limit = 0; /* Avoid warning. */
        if (limited) {
            if (!js_ValueToNumber(cx, argv[1], &d))
                return JS_FALSE;

            /* Clamp limit between 0 and 1 + string length. */
            if (!js_DoubleToECMAUint32(cx, d, &limit))
                return JS_FALSE;
            if (limit > JSSTRING_LENGTH(str))
                limit = 1 + JSSTRING_LENGTH(str);
        }

        len = i = 0;
        while ((j = find_split(cx, str, re, &i, sep)) >= 0) {
            if (limited && len >= limit)
                break;
            sub = js_NewDependentString(cx, str, i, (size_t)(j - i), 0);
            if (!sub)
                return JS_FALSE;
            v = STRING_TO_JSVAL(sub);
            if (!JS_SetElement(cx, arrayobj, len, &v))
                return JS_FALSE;
            len++;

            /*
             * Imitate perl's feature of including parenthesized substrings
             * that matched part of the delimiter in the new array, after the
             * split substring that was delimited.
             */
            if (re && sep->chars) {
                uintN num;
                JSSubString *parsub;

                for (num = 0; num < cx->regExpStatics.parenCount; num++) {
                    if (limited && len >= limit)
                        break;
                    parsub = REGEXP_PAREN_SUBSTRING(&cx->regExpStatics, num);
                    sub = js_NewStringCopyN(cx, parsub->chars, parsub->length,
                                            0);
                    if (!sub)
                        return JS_FALSE;
                    v = STRING_TO_JSVAL(sub);
                    if (!JS_SetElement(cx, arrayobj, len, &v))
                        return JS_FALSE;
                    len++;
                }
                sep->chars = NULL;
            }

            i = j + sep->length;
            if (!JS_VERSION_IS_ECMA(cx)) {
                /*
                 * Deviate from ECMA to imitate Perl, which omits a final
                 * split unless a limit argument is given and big enough.
                 */
                if (!limited && (size_t)i == JSSTRING_LENGTH(str))
                    break;
            }
        }
        ok = (j != -2);
static JSBool str_strike ( JSContext cx,
JSObject obj,
uintN  argc,
jsval argv,
jsval rval 
) [static]

Definition at line 2181 of file jsstr.c.

{
static JSBool str_sub ( JSContext cx,
JSObject obj,
uintN  argc,
jsval argv,
jsval rval 
) [static]

Definition at line 2211 of file jsstr.c.

{
static JSBool str_substr ( JSContext cx,
JSObject obj,
uintN  argc,
jsval argv,
jsval rval 
) [static]

Definition at line 1920 of file jsstr.c.

{
    JSString *str;
    jsdouble d;
    jsdouble length, begin, end;

    str = js_ValueToString(cx, OBJECT_TO_JSVAL(obj));
    if (!str)
        return JS_FALSE;
    argv[-1] = STRING_TO_JSVAL(str);

    if (argc != 0) {
        if (!js_ValueToNumber(cx, argv[0], &d))
            return JS_FALSE;
        length = JSSTRING_LENGTH(str);
        begin = js_DoubleToInteger(d);
        if (begin < 0) {
            begin += length;
            if (begin < 0)
                begin = 0;
        } else if (begin > length) {
            begin = length;
        }

        if (argc == 1) {
            end = length;
        } else {
            if (!js_ValueToNumber(cx, argv[1], &d))
                return JS_FALSE;
            end = js_DoubleToInteger(d);
            if (end < 0)
                end = 0;
            end += begin;
            if (end > length)
                end = length;
        }

        str = js_NewDependentString(cx, str, (size_t)begin,
                                    (size_t)(end - begin), 0);
        if (!str)
            return JS_FALSE;
    }

Here is the call graph for this function:

static JSBool str_substring ( JSContext cx,
JSObject obj,
uintN  argc,
jsval argv,
jsval rval 
) [static]

Definition at line 714 of file jsstr.c.

{
    JSString *str;
    jsdouble d;
    jsdouble length, begin, end;

    str = js_ValueToString(cx, OBJECT_TO_JSVAL(obj));
    if (!str)
        return JS_FALSE;
    argv[-1] = STRING_TO_JSVAL(str);

    if (argc != 0) {
        if (!js_ValueToNumber(cx, argv[0], &d))
            return JS_FALSE;
        length = JSSTRING_LENGTH(str);
        begin = js_DoubleToInteger(d);
        if (begin < 0)
            begin = 0;
        else if (begin > length)
            begin = length;

        if (argc == 1) {
            end = length;
        } else {
            if (!js_ValueToNumber(cx, argv[1], &d))
                return JS_FALSE;
            end = js_DoubleToInteger(d);
            if (end < 0)
                end = 0;
            else if (end > length)
                end = length;
            if (end < begin) {
                /* ECMA emulates old JDK1.0 java.lang.String.substring. */
                jsdouble tmp = begin;
                begin = end;
                end = tmp;
            }
        }

        str = js_NewDependentString(cx, str, (size_t)begin,
                                    (size_t)(end - begin), 0);
        if (!str)
            return JS_FALSE;
    }
    *rval = STRING_TO_JSVAL(str);
    return JS_TRUE;
}

Here is the call graph for this function:

static JSBool str_sup ( JSContext cx,
JSObject obj,
uintN  argc,
jsval argv,
jsval rval 
) [static]

Definition at line 2205 of file jsstr.c.

{
static JSBool str_toLocaleLowerCase ( JSContext cx,
JSObject obj,
uintN  argc,
jsval argv,
jsval rval 
) [static]

Definition at line 794 of file jsstr.c.

{
    JSString *str;

    /*
     * Forcefully ignore the first (or any) argument and return toLowerCase(),
     * ECMA has reserved that argument, presumably for defining the locale.
     */
    if (cx->localeCallbacks && cx->localeCallbacks->localeToLowerCase) {
        str = js_ValueToString(cx, OBJECT_TO_JSVAL(obj));
        if (!str)
            return JS_FALSE;
        argv[-1] = STRING_TO_JSVAL(str);
        return cx->localeCallbacks->localeToLowerCase(cx, str, rval);
    }
    return str_toLowerCase(cx, obj, 0, argv, rval);
}

Here is the call graph for this function:

static JSBool str_toLocaleUpperCase ( JSContext cx,
JSObject obj,
uintN  argc,
jsval argv,
jsval rval 
) [static]

Definition at line 844 of file jsstr.c.

{
    JSString *str;

    /*
     * Forcefully ignore the first (or any) argument and return toUpperCase(),
     * ECMA has reserved that argument, presumbaly for defining the locale.
     */
    if (cx->localeCallbacks && cx->localeCallbacks->localeToUpperCase) {
        str = js_ValueToString(cx, OBJECT_TO_JSVAL(obj));
        if (!str)
            return JS_FALSE;
        argv[-1] = STRING_TO_JSVAL(str);
        return cx->localeCallbacks->localeToUpperCase(cx, str, rval);
    }
    return str_toUpperCase(cx, obj, 0, argv, rval);
}

Here is the call graph for this function:

static JSBool str_toLowerCase ( JSContext cx,
JSObject obj,
uintN  argc,
jsval argv,
jsval rval 
) [static]

Definition at line 764 of file jsstr.c.

{
    JSString *str;
    size_t i, n;
    jschar *s, *news;

    str = js_ValueToString(cx, OBJECT_TO_JSVAL(obj));
    if (!str)
        return JS_FALSE;
    argv[-1] = STRING_TO_JSVAL(str);

    n = JSSTRING_LENGTH(str);
    news = (jschar *) JS_malloc(cx, (n + 1) * sizeof(jschar));
    if (!news)
        return JS_FALSE;
    s = JSSTRING_CHARS(str);
    for (i = 0; i < n; i++)
        news[i] = JS_TOLOWER(s[i]);
    news[n] = 0;
    str = js_NewString(cx, news, n, 0);
    if (!str) {
        JS_free(cx, news);
        return JS_FALSE;
    }
    *rval = STRING_TO_JSVAL(str);
    return JS_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static JSBool str_toSource ( JSContext cx,
JSObject obj,
uintN  argc,
jsval argv,
jsval rval 
) [static]

Definition at line 634 of file jsstr.c.

{
    jsval v;
    JSString *str;
    size_t i, j, k, n;
    char buf[16];
    jschar *s, *t;

    if (JSVAL_IS_STRING((jsval)obj)) {
        v = (jsval)obj;
    } else {
        if (!JS_InstanceOf(cx, obj, &js_StringClass, argv))
            return JS_FALSE;
        v = OBJ_GET_SLOT(cx, obj, JSSLOT_PRIVATE);
        if (!JSVAL_IS_STRING(v))
            return js_obj_toSource(cx, obj, argc, argv, rval);
    }
    str = js_QuoteString(cx, JSVAL_TO_STRING(v), '"');
    if (!str)
        return JS_FALSE;
    j = JS_snprintf(buf, sizeof buf, "(new %s(", js_StringClass.name);
    s = JSSTRING_CHARS(str);
    k = JSSTRING_LENGTH(str);
    n = j + k + 2;
    t = (jschar *) JS_malloc(cx, (n + 1) * sizeof(jschar));
    if (!t)
        return JS_FALSE;
    for (i = 0; i < j; i++)
        t[i] = buf[i];
    for (j = 0; j < k; i++, j++)
        t[i] = s[j];
    t[i++] = ')';
    t[i++] = ')';
    t[i] = 0;
    str = js_NewString(cx, t, n, 0);
    if (!str) {
        JS_free(cx, t);
        return JS_FALSE;
    }
    *rval = STRING_TO_JSVAL(str);
    return JS_TRUE;
}

Here is the call graph for this function:

static JSBool str_toString ( JSContext cx,
JSObject obj,
uintN  argc,
jsval argv,
jsval rval 
) [static]

Definition at line 680 of file jsstr.c.

{
    jsval v;

    if (JSVAL_IS_STRING((jsval)obj)) {
        *rval = (jsval)obj;
        return JS_TRUE;
    }
    if (!JS_InstanceOf(cx, obj, &js_StringClass, argv))
        return JS_FALSE;
    v = OBJ_GET_SLOT(cx, obj, JSSLOT_PRIVATE);
    if (!JSVAL_IS_STRING(v))
        return js_obj_toString(cx, obj, argc, argv, rval);
    *rval = v;
    return JS_TRUE;
}

Here is the call graph for this function:

static JSBool str_toUpperCase ( JSContext cx,
JSObject obj,
uintN  argc,
jsval argv,
jsval rval 
) [static]

Definition at line 814 of file jsstr.c.

{
    JSString *str;
    size_t i, n;
    jschar *s, *news;

    str = js_ValueToString(cx, OBJECT_TO_JSVAL(obj));
    if (!str)
        return JS_FALSE;
    argv[-1] = STRING_TO_JSVAL(str);

    n = JSSTRING_LENGTH(str);
    news = (jschar *) JS_malloc(cx, (n + 1) * sizeof(jschar));
    if (!news)
        return JS_FALSE;
    s = JSSTRING_CHARS(str);
    for (i = 0; i < n; i++)
        news[i] = JS_TOUPPER(s[i]);
    news[n] = 0;
    str = js_NewString(cx, news, n, 0);
    if (!str) {
        JS_free(cx, news);
        return JS_FALSE;
    }
    *rval = STRING_TO_JSVAL(str);
    return JS_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static JSBool str_unescape ( JSContext cx,
JSObject obj,
uintN  argc,
jsval argv,
jsval rval 
) [static]

Definition at line 411 of file jsstr.c.

{
    JSString *str;
    size_t i, ni, length;
    const jschar *chars;
    jschar *newchars;
    jschar ch;

    str = js_ValueToString(cx, argv[0]);
    if (!str)
        return JS_FALSE;
    argv[0] = STRING_TO_JSVAL(str);

    chars = JSSTRING_CHARS(str);
    length = JSSTRING_LENGTH(str);

    /* Don't bother allocating less space for the new string. */
    newchars = (jschar *) JS_malloc(cx, (length + 1) * sizeof(jschar));
    if (!newchars)
        return JS_FALSE;
    ni = i = 0;
    while (i < length) {
        ch = chars[i++];
        if (ch == '%') {
            if (i + 1 < length &&
                JS7_ISHEX(chars[i]) && JS7_ISHEX(chars[i + 1]))
            {
                ch = JS7_UNHEX(chars[i]) * 16 + JS7_UNHEX(chars[i + 1]);
                i += 2;
            } else if (i + 4 < length && chars[i] == 'u' &&
                       JS7_ISHEX(chars[i + 1]) && JS7_ISHEX(chars[i + 2]) &&
                       JS7_ISHEX(chars[i + 3]) && JS7_ISHEX(chars[i + 4]))
            {
                ch = (((((JS7_UNHEX(chars[i + 1]) << 4)
                        + JS7_UNHEX(chars[i + 2])) << 4)
                      + JS7_UNHEX(chars[i + 3])) << 4)
                    + JS7_UNHEX(chars[i + 4]);
                i += 5;
            }
        }
        newchars[ni++] = ch;
    }
    newchars[ni] = 0;

    str = js_NewString(cx, newchars, ni, 0);
    if (!str) {
        JS_free(cx, newchars);
        return JS_FALSE;
    }
    *rval = STRING_TO_JSVAL(str);
    return JS_TRUE;
}

Here is the call graph for this function:

static JSBool str_uneval ( JSContext cx,
JSObject obj,
uintN  argc,
jsval argv,
jsval rval 
) [static]

Definition at line 466 of file jsstr.c.

{
    JSString *str;

    str = js_ValueToSource(cx, argv[0]);
    if (!str)
        return JS_FALSE;
    *rval = STRING_TO_JSVAL(str);
    return JS_TRUE;
}

Here is the call graph for this function:

static JSBool str_valueOf ( JSContext cx,
JSObject obj,
uintN  argc,
jsval argv,
jsval rval 
) [static]

Definition at line 698 of file jsstr.c.

{
    if (JSVAL_IS_STRING((jsval)obj)) {
        *rval = (jsval)obj;
        return JS_TRUE;
    }
    if (!JS_InstanceOf(cx, obj, &js_StringClass, argv))
        return JS_FALSE;
    *rval = OBJ_GET_SLOT(cx, obj, JSSLOT_PRIVATE);
    return JS_TRUE;
}

Here is the call graph for this function:

static JSBool String ( JSContext cx,
JSObject obj,
uintN  argc,
jsval argv,
jsval rval 
) [static]

Definition at line 2289 of file jsstr.c.

{
    JSString *str;

    if (argc > 0) {
        str = js_ValueToString(cx, argv[0]);
        if (!str)
            return JS_FALSE;
        argv[0] = STRING_TO_JSVAL(str);
    } else {
        str = cx->runtime->emptyString;
    }
    if (!(cx->fp->flags & JSFRAME_CONSTRUCTING)) {
        *rval = STRING_TO_JSVAL(str);
        return JS_TRUE;
    }
static JSBool tagify ( JSContext cx,
JSObject obj,
jsval argv,
const char *  begin,
JSString param,
const char *  end,
jsval rval 
) [static]

Definition at line 2052 of file jsstr.c.

{
    JSString *str;
    jschar *tagbuf;
    size_t beglen, endlen, parlen, taglen;
    size_t i, j;

    if (JSVAL_IS_STRING((jsval)obj)) {
        str = JSVAL_TO_STRING((jsval)obj);
    } else {
        str = js_ValueToString(cx, OBJECT_TO_JSVAL(obj));
        if (!str)
            return JS_FALSE;
        argv[-1] = STRING_TO_JSVAL(str);
    }

    if (!end)
        end = begin;

    beglen = strlen(begin);
    taglen = 1 + beglen + 1;                            /* '<begin' + '>' */
    parlen = 0; /* Avoid warning. */
    if (param) {
        parlen = JSSTRING_LENGTH(param);
        taglen += 2 + parlen + 1;                       /* '="param"' */
    }
    endlen = strlen(end);
    taglen += JSSTRING_LENGTH(str) + 2 + endlen + 1;    /* 'str</end>' */

    if (taglen >= ~(size_t)0 / sizeof(jschar)) {
        JS_ReportOutOfMemory(cx);
        return JS_FALSE;
    }

    tagbuf = (jschar *) JS_malloc(cx, (taglen + 1) * sizeof(jschar));
    if (!tagbuf)
        return JS_FALSE;

    j = 0;
    tagbuf[j++] = '<';
    for (i = 0; i < beglen; i++)
        tagbuf[j++] = (jschar)begin[i];
    if (param) {
        tagbuf[j++] = '=';
        tagbuf[j++] = '"';
        js_strncpy(&tagbuf[j], JSSTRING_CHARS(param), parlen);
        j += parlen;
        tagbuf[j++] = '"';
    }
    tagbuf[j++] = '>';
    js_strncpy(&tagbuf[j], JSSTRING_CHARS(str), JSSTRING_LENGTH(str));
    j += JSSTRING_LENGTH(str);
    tagbuf[j++] = '<';
    tagbuf[j++] = '/';
    for (i = 0; i < endlen; i++)
        tagbuf[j++] = (jschar)end[i];
    tagbuf[j++] = '>';
    JS_ASSERT(j == taglen);
    tagbuf[j] = 0;

    str = js_NewString(cx, tagbuf, taglen, 0);
    if (!str) {
        free((char *)tagbuf);
        return JS_FALSE;
    }

Here is the call graph for this function:

static JSBool tagify_value ( JSContext cx,
JSObject obj,
jsval argv,
const char *  begin,
const char *  end,
jsval rval 
) [static]

Definition at line 2124 of file jsstr.c.

{
    JSString *param;

    param = js_ValueToString(cx, argv[0]);
    if (!param)
        return JS_FALSE;
static uint32 Utf8ToOneUcs4Char ( const uint8 utf8Buffer,
int  utf8Length 
) [static]

Definition at line 4787 of file jsstr.c.

{
    uint32 ucs4Char;
    uint32 minucs4Char;
    /* from Unicode 3.1, non-shortest form is illegal */
    static const uint32 minucs4Table[] = {
        0x00000080, 0x00000800, 0x0001000, 0x0020000, 0x0400000
    };

    JS_ASSERT(utf8Length >= 1 && utf8Length <= 6);
    if (utf8Length == 1) {
        ucs4Char = *utf8Buffer;
        JS_ASSERT(!(ucs4Char & 0x80));
    } else {
        JS_ASSERT((*utf8Buffer & (0x100 - (1 << (7-utf8Length)))) ==
                  (0x100 - (1 << (8-utf8Length))));
        ucs4Char = *utf8Buffer++ & ((1<<(7-utf8Length))-1);
        minucs4Char = minucs4Table[utf8Length-2];
        while (--utf8Length) {
            JS_ASSERT((*utf8Buffer & 0xC0) == 0x80);
            ucs4Char = ucs4Char<<6 | (*utf8Buffer++ & 0x3F);
        }
        if (ucs4Char < minucs4Char ||
            ucs4Char == 0xFFFE || ucs4Char == 0xFFFF) {
            ucs4Char = 0xFFFD;
        }

Variable Documentation

Definition at line 4358 of file jsstr.c.

const char js_decodeURI_str[] = "decodeURI"

Definition at line 483 of file jsstr.c.

const char js_decodeURIComponent_str[] = "decodeURIComponent"

Definition at line 485 of file jsstr.c.

Definition at line 502 of file jsstr.c.

Definition at line 503 of file jsstr.c.

const char js_encodeURI_str[] = "encodeURI"

Definition at line 484 of file jsstr.c.

const char js_encodeURIComponent_str[] = "encodeURIComponent"

Definition at line 486 of file jsstr.c.

const char js_escape_str[] = "escape"

Definition at line 478 of file jsstr.c.

const char js_unescape_str[] = "unescape"

Definition at line 479 of file jsstr.c.

const char js_uneval_str[] = "uneval"

Definition at line 481 of file jsstr.c.

Initial value:
    {';', '/', '?', ':', '@', '&', '=', '+', '$', ',', '#', 0}

Definition at line 4485 of file jsstr.c.

Initial value:
    {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
     'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
     'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
     'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
     'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
     '-', '_', '.', '!', '~', '*', '\'', '(', ')', 0}

Definition at line 4487 of file jsstr.c.

Definition at line 3244 of file jsstr.c.

Definition at line 3377 of file jsstr.c.

Definition at line 2217 of file jsstr.c.

Initial value:

Definition at line 509 of file jsstr.c.

Initial value:
 {
    {"fromCharCode",    str_fromCharCode,       1,0,0},
    {0,0,0,0,0}
}

Definition at line 2339 of file jsstr.c.

const uint8 urlCharType[256] [static]
Initial value:

    
    {    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,       
         0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,       
         0,0,0,0,0,0,0,0,0,0,7,4,0,7,7,4,       
         7,7,7,7,7,7,7,7,7,7,0,0,0,0,0,0,       
         7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,       
         7,7,7,7,7,7,7,7,7,7,7,0,0,0,0,7,       
         0,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,       
         7,7,7,7,7,7,7,7,7,7,7,0,0,0,0,0,       
         0, }

Definition at line 287 of file jsstr.c.