/[jscoverage]/trunk/js/jsstr.cpp
ViewVC logotype

Diff of /trunk/js/jsstr.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 332 by siliconforks, Thu Oct 23 19:03:33 2008 UTC revision 399 by siliconforks, Tue Dec 9 03:37:47 2008 UTC
# Line 1  Line 1 
1  /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-  /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2   * vim: set ts=8 sw=4 et tw=80:   * vim: set ts=8 sw=4 et tw=99:
3   *   *
4   * ***** BEGIN LICENSE BLOCK *****   * ***** BEGIN LICENSE BLOCK *****
5   * Version: MPL 1.1/GPL 2.0/LGPL 2.1   * Version: MPL 1.1/GPL 2.0/LGPL 2.1
# Line 59  Line 59 
59  #include "jsarray.h"  #include "jsarray.h"
60  #include "jsatom.h"  #include "jsatom.h"
61  #include "jsbool.h"  #include "jsbool.h"
62    #include "jsbuiltins.h"
63  #include "jscntxt.h"  #include "jscntxt.h"
64  #include "jsversion.h"  #include "jsversion.h"
65  #include "jsgc.h"  #include "jsgc.h"
# Line 732  Line 733 
733  /*  /*
734   * Java-like string native methods.   * Java-like string native methods.
735   */   */
736  JSBool  
737  js_str_substring(JSContext *cx, uintN argc, jsval *vp)  static JSString *
738    SubstringTail(JSContext *cx, JSString *str, jsdouble length, jsdouble begin, jsdouble end)
739    {
740        if (begin < 0)
741            begin = 0;
742        else if (begin > length)
743            begin = length;
744    
745        if (end < 0)
746            end = 0;
747        else if (end > length)
748            end = length;
749        if (end < begin) {
750            /* ECMA emulates old JDK1.0 java.lang.String.substring. */
751            jsdouble tmp = begin;
752            begin = end;
753            end = tmp;
754        }
755    
756        return js_NewDependentString(cx, str, (size_t)begin, (size_t)(end - begin));
757    }
758    
759    static JSBool
760    str_substring(JSContext *cx, uintN argc, jsval *vp)
761  {  {
762      JSString *str;      JSString *str;
763      jsdouble d;      jsdouble d;
# Line 746  Line 770 
770              return JS_FALSE;              return JS_FALSE;
771          length = JSSTRING_LENGTH(str);          length = JSSTRING_LENGTH(str);
772          begin = js_DoubleToInteger(d);          begin = js_DoubleToInteger(d);
         if (begin < 0)  
             begin = 0;  
         else if (begin > length)  
             begin = length;  
   
773          if (argc == 1) {          if (argc == 1) {
774              end = length;              end = length;
775          } else {          } else {
# Line 758  Line 777 
777              if (JSVAL_IS_NULL(vp[3]))              if (JSVAL_IS_NULL(vp[3]))
778                  return JS_FALSE;                  return JS_FALSE;
779              end = js_DoubleToInteger(d);              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;  
             }  
780          }          }
781    
782          str = js_NewDependentString(cx, str, (size_t)begin,          str = SubstringTail(cx, str, length, begin, end);
                                     (size_t)(end - begin));  
783          if (!str)          if (!str)
784              return JS_FALSE;              return JS_FALSE;
785      }      }
# Line 779  Line 787 
787      return JS_TRUE;      return JS_TRUE;
788  }  }
789    
790    #ifdef JS_TRACER
791    static JSString* FASTCALL
792    String_p_toString(JSContext* cx, JSObject* obj)
793    {
794        if (!JS_InstanceOf(cx, obj, &js_StringClass, NULL))
795            return NULL;
796        jsval v = OBJ_GET_SLOT(cx, obj, JSSLOT_PRIVATE);
797        JS_ASSERT(JSVAL_IS_STRING(v));
798        return JSVAL_TO_STRING(v);
799    }
800    
801    static JSString* FASTCALL
802    String_p_substring(JSContext* cx, JSString* str, int32 begin, int32 end)
803    {
804        JS_ASSERT(JS_ON_TRACE(cx));
805    
806        size_t length = JSSTRING_LENGTH(str);
807        return SubstringTail(cx, str, length, begin, end);
808    }
809    
810    static JSString* FASTCALL
811    String_p_substring_1(JSContext* cx, JSString* str, int32 begin)
812    {
813        JS_ASSERT(JS_ON_TRACE(cx));
814    
815        size_t length = JSSTRING_LENGTH(str);
816        return SubstringTail(cx, str, length, begin, length);
817    }
818    #endif
819    
820  JSString* JS_FASTCALL  JSString* JS_FASTCALL
821  js_toLowerCase(JSContext *cx, JSString *str)  js_toLowerCase(JSContext *cx, JSString *str)
822  {  {
# Line 800  Line 838 
838      return str;      return str;
839  }  }
840    
841  JSBool  static JSBool
842  js_str_toLowerCase(JSContext *cx, uintN argc, jsval *vp)  str_toLowerCase(JSContext *cx, uintN argc, jsval *vp)
843  {  {
844      JSString *str;      JSString *str;
845    
# Line 826  Line 864 
864          NORMALIZE_THIS(cx, vp, str);          NORMALIZE_THIS(cx, vp, str);
865          return cx->localeCallbacks->localeToLowerCase(cx, str, vp);          return cx->localeCallbacks->localeToLowerCase(cx, str, vp);
866      }      }
867      return js_str_toLowerCase(cx, 0, vp);      return str_toLowerCase(cx, 0, vp);
868  }  }
869    
870  JSString* JS_FASTCALL  JSString* JS_FASTCALL
# Line 850  Line 888 
888      return str;      return str;
889  }  }
890    
891  JSBool  static JSBool
892  js_str_toUpperCase(JSContext *cx, uintN argc, jsval *vp)  str_toUpperCase(JSContext *cx, uintN argc, jsval *vp)
893  {  {
894      JSString *str;      JSString *str;
895    
# Line 876  Line 914 
914          NORMALIZE_THIS(cx, vp, str);          NORMALIZE_THIS(cx, vp, str);
915          return cx->localeCallbacks->localeToUpperCase(cx, str, vp);          return cx->localeCallbacks->localeToUpperCase(cx, str, vp);
916      }      }
917      return js_str_toUpperCase(cx, 0, vp);      return str_toUpperCase(cx, 0, vp);
918  }  }
919    
920  static JSBool  static JSBool
# Line 900  Line 938 
938      return JS_TRUE;      return JS_TRUE;
939  }  }
940    
941  JSBool  static JSBool
942  js_str_charAt(JSContext *cx, uintN argc, jsval *vp)  str_charAt(JSContext *cx, uintN argc, jsval *vp)
943  {  {
944      jsval t;      jsval t;
945      JSString *str;      JSString *str;
# Line 944  Line 982 
982      return JS_TRUE;      return JS_TRUE;
983  }  }
984    
985  JSBool  static JSBool
986  js_str_charCodeAt(JSContext *cx, uintN argc, jsval *vp)  str_charCodeAt(JSContext *cx, uintN argc, jsval *vp)
987  {  {
988      jsval t;      jsval t;
989      JSString *str;      JSString *str;
# Line 985  Line 1023 
1023      return JS_TRUE;      return JS_TRUE;
1024  }  }
1025    
1026    #ifdef JS_TRACER
1027    int32 FASTCALL
1028    js_String_p_charCodeAt(JSString* str, int32 i)
1029    {
1030        if (i < 0 || (int32)JSSTRING_LENGTH(str) <= i)
1031            return -1;
1032        return JSSTRING_CHARS(str)[i];
1033    }
1034    #endif
1035    
1036  jsint  jsint
1037  js_BoyerMooreHorspool(const jschar *text, jsint textlen,  js_BoyerMooreHorspool(const jschar *text, jsint textlen,
1038                        const jschar *pat, jsint patlen,                        const jschar *pat, jsint patlen,
# Line 1299  Line 1347 
1347              test = JS_TRUE;              test = JS_TRUE;
1348          } else {          } else {
1349              /*              /*
1350               * MODE_MATCH implies js_str_match is being called from a script or               * MODE_MATCH implies str_match is being called from a script or a
1351               * a scripted function.  If the caller cares only about testing null               * scripted function.  If the caller cares only about testing null
1352               * vs. non-null return value, optimize away the array object that               * vs. non-null return value, optimize away the array object that
1353               * would normally be returned in *vp.               * would normally be returned in *vp.
1354               *               *
# Line 1365  Line 1413 
1413          return JS_FALSE;          return JS_FALSE;
1414      v = STRING_TO_JSVAL(matchstr);      v = STRING_TO_JSVAL(matchstr);
1415      JS_ASSERT(count <= JSVAL_INT_MAX);      JS_ASSERT(count <= JSVAL_INT_MAX);
1416    
1417        JSAutoResolveFlags rf(cx, JSRESOLVE_QUALIFIED | JSRESOLVE_ASSIGNING);
1418      return OBJ_SET_PROPERTY(cx, arrayobj, INT_TO_JSID(count), &v);      return OBJ_SET_PROPERTY(cx, arrayobj, INT_TO_JSID(count), &v);
1419  }  }
1420    
# Line 1387  Line 1437 
1437      return ok;      return ok;
1438  }  }
1439    
1440  JSBool  static JSBool
1441  js_str_match(JSContext *cx, uintN argc, jsval *vp)  str_match(JSContext *cx, uintN argc, jsval *vp)
1442  {  {
1443      JSStackFrame *fp;      JSStackFrame *fp;
1444    
# Line 1397  Line 1447 
1447      return js_StringMatchHelper(cx, argc, vp, fp ? fp->regs->pc : NULL);      return js_StringMatchHelper(cx, argc, vp, fp ? fp->regs->pc : NULL);
1448  }  }
1449    
1450    #ifdef JS_TRACER
1451    static JSObject* FASTCALL
1452    String_p_match(JSContext* cx, JSString* str, jsbytecode *pc, JSObject* regexp)
1453    {
1454        jsval vp[3] = { JSVAL_NULL, STRING_TO_JSVAL(str), OBJECT_TO_JSVAL(regexp) };
1455        if (!js_StringMatchHelper(cx, 1, vp, pc))
1456            return (JSObject*) JSVAL_TO_BOOLEAN(JSVAL_VOID);
1457        JS_ASSERT(JSVAL_IS_NULL(vp[0]) ||
1458                  (!JSVAL_IS_PRIMITIVE(vp[0]) && OBJ_IS_ARRAY(cx, JSVAL_TO_OBJECT(vp[0]))));
1459        return JSVAL_TO_OBJECT(vp[0]);
1460    }
1461    
1462    static JSObject* FASTCALL
1463    String_p_match_obj(JSContext* cx, JSObject* str, jsbytecode *pc, JSObject* regexp)
1464    {
1465        jsval vp[3] = { JSVAL_NULL, OBJECT_TO_JSVAL(str), OBJECT_TO_JSVAL(regexp) };
1466        if (!js_StringMatchHelper(cx, 1, vp, pc))
1467            return (JSObject*) JSVAL_TO_BOOLEAN(JSVAL_VOID);
1468        JS_ASSERT(JSVAL_IS_NULL(vp[0]) ||
1469                  (!JSVAL_IS_PRIMITIVE(vp[0]) && OBJ_IS_ARRAY(cx, JSVAL_TO_OBJECT(vp[0]))));
1470        return JSVAL_TO_OBJECT(vp[0]);
1471    }
1472    #endif
1473    
1474  static JSBool  static JSBool
1475  str_search(JSContext *cx, uintN argc, jsval *vp)  str_search(JSContext *cx, uintN argc, jsval *vp)
1476  {  {
# Line 1498  Line 1572 
1572           * Save the regExpStatics from the current regexp, since they may be           * Save the regExpStatics from the current regexp, since they may be
1573           * clobbered by a RegExp usage in the lambda function.  Note that all           * clobbered by a RegExp usage in the lambda function.  Note that all
1574           * members of JSRegExpStatics are JSSubStrings, so not GC roots, save           * members of JSRegExpStatics are JSSubStrings, so not GC roots, save
1575           * input, which is rooted otherwise via vp[1] in js_str_replace.           * input, which is rooted otherwise via vp[1] in str_replace.
1576           */           */
1577          JSRegExpStatics save = cx->regExpStatics;          JSRegExpStatics save = cx->regExpStatics;
1578          JSBool freeMoreParens = JS_FALSE;          JSBool freeMoreParens = JS_FALSE;
# Line 1678  Line 1752 
1752      return JS_TRUE;      return JS_TRUE;
1753  }  }
1754    
1755  JSBool  static JSBool
1756  js_str_replace(JSContext *cx, uintN argc, jsval *vp)  str_replace(JSContext *cx, uintN argc, jsval *vp)
1757  {  {
1758      JSObject *lambda;      JSObject *lambda;
1759      JSString *repstr;      JSString *repstr;
# Line 1697  Line 1771 
1771      return js_StringReplaceHelper(cx, argc, lambda, repstr, vp);      return js_StringReplaceHelper(cx, argc, lambda, repstr, vp);
1772  }  }
1773    
1774    #ifdef JS_TRACER
1775    static JSString* FASTCALL
1776    String_p_replace_str(JSContext* cx, JSString* str, JSObject* regexp, JSString* repstr)
1777    {
1778        jsval vp[4] = {
1779            JSVAL_NULL, STRING_TO_JSVAL(str), OBJECT_TO_JSVAL(regexp), STRING_TO_JSVAL(repstr)
1780        };
1781        if (!js_StringReplaceHelper(cx, 2, NULL, repstr, vp))
1782            return NULL;
1783        JS_ASSERT(JSVAL_IS_STRING(vp[0]));
1784        return JSVAL_TO_STRING(vp[0]);
1785    }
1786    
1787    static JSString* FASTCALL
1788    String_p_replace_str2(JSContext* cx, JSString* str, JSString* patstr, JSString* repstr)
1789    {
1790        jsval vp[4] = {
1791            JSVAL_NULL, STRING_TO_JSVAL(str), STRING_TO_JSVAL(patstr), STRING_TO_JSVAL(repstr)
1792        };
1793        if (!js_StringReplaceHelper(cx, 2, NULL, repstr, vp))
1794            return NULL;
1795        JS_ASSERT(JSVAL_IS_STRING(vp[0]));
1796        return JSVAL_TO_STRING(vp[0]);
1797    }
1798    
1799    static JSString* FASTCALL
1800    String_p_replace_str3(JSContext* cx, JSString* str, JSString* patstr, JSString* repstr,
1801                          JSString* flagstr)
1802    {
1803        jsval vp[5] = {
1804            JSVAL_NULL, STRING_TO_JSVAL(str), STRING_TO_JSVAL(patstr), STRING_TO_JSVAL(repstr),
1805            STRING_TO_JSVAL(flagstr)
1806        };
1807        if (!js_StringReplaceHelper(cx, 3, NULL, repstr, vp))
1808            return NULL;
1809        JS_ASSERT(JSVAL_IS_STRING(vp[0]));
1810        return JSVAL_TO_STRING(vp[0]);
1811    }
1812    #endif
1813    
1814  JSBool  JSBool
1815  js_StringReplaceHelper(JSContext *cx, uintN argc, JSObject *lambda,  js_StringReplaceHelper(JSContext *cx, uintN argc, JSObject *lambda,
1816                         JSString *repstr, jsval *vp)                         JSString *repstr, jsval *vp)
# Line 1785  Line 1899 
1899  }  }
1900    
1901  /*  /*
1902   * Subroutine used by js_str_split to find the next split point in str, starting   * Subroutine used by str_split to find the next split point in str, starting
1903   * at offset *ip and looking either for the separator substring given by sep, or   * at offset *ip and looking either for the separator substring given by sep, or
1904   * for the next re match.  In the re case, return the matched separator in *sep,   * for the next re match.  In the re case, return the matched separator in *sep,
1905   * and the possibly updated offset in *ip.   * and the possibly updated offset in *ip.
# Line 1810  Line 1924 
1924       *       *
1925       * and the resulting array converts back to the string "ab," for symmetry.       * and the resulting array converts back to the string "ab," for symmetry.
1926       * However, we ape Perl and do this only if there is a sufficiently large       * However, we ape Perl and do this only if there is a sufficiently large
1927       * limit argument (see js_str_split).       * limit argument (see str_split).
1928       */       */
1929      i = *ip;      i = *ip;
1930      length = JSSTRING_LENGTH(str);      length = JSSTRING_LENGTH(str);
# Line 1896  Line 2010 
2010      return k;      return k;
2011  }  }
2012    
2013  JSBool  static JSBool
2014  js_str_split(JSContext *cx, uintN argc, jsval *vp)  str_split(JSContext *cx, uintN argc, jsval *vp)
2015  {  {
2016      JSString *str, *sub;      JSString *str, *sub;
2017      JSObject *arrayobj;      JSObject *arrayobj;
# Line 1998  Line 2112 
2112      return ok;      return ok;
2113  }  }
2114    
2115    #ifdef JS_TRACER
2116    static JSObject* FASTCALL
2117    String_p_split(JSContext* cx, JSString* str, JSString* sepstr)
2118    {
2119        // FIXME: Avoid building and then parsing this array.
2120        jsval vp[4] = { JSVAL_NULL, STRING_TO_JSVAL(str), STRING_TO_JSVAL(sepstr), JSVAL_VOID };
2121        if (!str_split(cx, 2, vp))
2122            return NULL;
2123        JS_ASSERT(JSVAL_IS_OBJECT(vp[0]));
2124        return JSVAL_TO_OBJECT(vp[0]);
2125    }
2126    #endif
2127    
2128  #if JS_HAS_PERL_SUBSTR  #if JS_HAS_PERL_SUBSTR
2129  static JSBool  static JSBool
2130  str_substr(JSContext *cx, uintN argc, jsval *vp)  str_substr(JSContext *cx, uintN argc, jsval *vp)
# Line 2049  Line 2176 
2176  /*  /*
2177   * Python-esque sequence operations.   * Python-esque sequence operations.
2178   */   */
2179  JSBool  static JSBool
2180  js_str_concat(JSContext *cx, uintN argc, jsval *vp)  str_concat(JSContext *cx, uintN argc, jsval *vp)
2181  {  {
2182      JSString *str, *str2;      JSString *str, *str2;
2183      jsval *argv;      jsval *argv;
# Line 2073  Line 2200 
2200      return JS_TRUE;      return JS_TRUE;
2201  }  }
2202    
2203    #ifdef JS_TRACER
2204    static JSString* FASTCALL
2205    String_p_concat_1int(JSContext* cx, JSString* str, int32 i)
2206    {
2207        // FIXME: should be able to use stack buffer and avoid istr...
2208        JSString* istr = js_NumberToString(cx, i);
2209        if (!istr)
2210            return NULL;
2211        return js_ConcatStrings(cx, str, istr);
2212    }
2213    
2214    static JSString* FASTCALL
2215    String_p_concat_2str(JSContext* cx, JSString* str, JSString* a, JSString* b)
2216    {
2217        str = js_ConcatStrings(cx, str, a);
2218        if (str)
2219            return js_ConcatStrings(cx, str, b);
2220        return NULL;
2221    }
2222    
2223    static JSString* FASTCALL
2224    String_p_concat_3str(JSContext* cx, JSString* str, JSString* a, JSString* b, JSString* c)
2225    {
2226        str = js_ConcatStrings(cx, str, a);
2227        if (str) {
2228            str = js_ConcatStrings(cx, str, b);
2229            if (str)
2230                return js_ConcatStrings(cx, str, c);
2231        }
2232        return NULL;
2233    }
2234    #endif
2235    
2236  static JSBool  static JSBool
2237  str_slice(JSContext *cx, uintN argc, jsval *vp)  str_slice(JSContext *cx, uintN argc, jsval *vp)
2238  {  {
# Line 2308  Line 2468 
2468  }  }
2469  #endif /* JS_HAS_STR_HTML_HELPERS */  #endif /* JS_HAS_STR_HTML_HELPERS */
2470    
2471    #ifdef JS_TRACER
2472    JSString* FASTCALL
2473    js_String_getelem(JSContext* cx, JSString* str, int32 i)
2474    {
2475        if ((size_t)i >= JSSTRING_LENGTH(str))
2476            return NULL;
2477        return js_GetUnitString(cx, str, (size_t)i);
2478    }
2479    #endif
2480    
2481    JS_DEFINE_CALLINFO_2(extern, BOOL,   js_EqualStrings, STRING, STRING,                       1, 1)
2482    JS_DEFINE_CALLINFO_2(extern, INT32,  js_CompareStrings, STRING, STRING,                     1, 1)
2483    
2484    JS_DEFINE_TRCINFO_1(str_toString,
2485        (2, (extern, STRING_FAIL,      String_p_toString, CONTEXT, THIS,                        1, 1)))
2486    JS_DEFINE_TRCINFO_2(str_substring,
2487        (4, (static, STRING_FAIL,      String_p_substring, CONTEXT, THIS_STRING, INT32, INT32,   1, 1)),
2488        (3, (static, STRING_FAIL,      String_p_substring_1, CONTEXT, THIS_STRING, INT32,        1, 1)))
2489    JS_DEFINE_TRCINFO_1(str_charAt,
2490        (3, (extern, STRING_FAIL,      js_String_getelem, CONTEXT, THIS_STRING, INT32,           1, 1)))
2491    JS_DEFINE_TRCINFO_1(str_charCodeAt,
2492        (2, (extern, INT32_FAIL,       js_String_p_charCodeAt, THIS_STRING, INT32,               1, 1)))
2493    JS_DEFINE_TRCINFO_4(str_concat,
2494        (3, (static, STRING_FAIL,      String_p_concat_1int, CONTEXT, THIS_STRING, INT32,        1, 1)),
2495        (3, (extern, STRING_FAIL,      js_ConcatStrings, CONTEXT, THIS_STRING, STRING,           1, 1)),
2496        (4, (static, STRING_FAIL,      String_p_concat_2str, CONTEXT, THIS_STRING, STRING, STRING, 1, 1)),
2497        (5, (static, STRING_FAIL,      String_p_concat_3str, CONTEXT, THIS_STRING, STRING, STRING, STRING, 1, 1)))
2498    JS_DEFINE_TRCINFO_2(str_match,
2499        (4, (static, OBJECT_FAIL_VOID, String_p_match, CONTEXT, THIS_STRING, PC, REGEXP,         1, 1)),
2500        (4, (static, OBJECT_FAIL_VOID, String_p_match_obj, CONTEXT, THIS, PC, REGEXP,            1, 1)))
2501    JS_DEFINE_TRCINFO_3(str_replace,
2502        (4, (static, STRING_FAIL,      String_p_replace_str, CONTEXT, THIS_STRING, REGEXP, STRING, 1, 1)),
2503        (4, (static, STRING_FAIL,      String_p_replace_str2, CONTEXT, THIS_STRING, STRING, STRING, 1, 1)),
2504        (5, (static, STRING_FAIL,      String_p_replace_str3, CONTEXT, THIS_STRING, STRING, STRING, STRING, 1, 1)))
2505    JS_DEFINE_TRCINFO_1(str_split,
2506        (3, (static, OBJECT_FAIL_NULL, String_p_split, CONTEXT, THIS_STRING, STRING,             0, 0)))
2507    JS_DEFINE_TRCINFO_1(str_toLowerCase,
2508        (2, (extern, STRING_FAIL,      js_toLowerCase, CONTEXT, THIS_STRING,                     1, 1)))
2509    JS_DEFINE_TRCINFO_1(str_toUpperCase,
2510        (2, (extern, STRING_FAIL,      js_toUpperCase, CONTEXT, THIS_STRING,                     1, 1)))
2511    
2512  #define GENERIC           JSFUN_GENERIC_NATIVE  #define GENERIC           JSFUN_GENERIC_NATIVE
2513  #define PRIMITIVE         JSFUN_THISP_PRIMITIVE  #define PRIMITIVE         JSFUN_THISP_PRIMITIVE
2514  #define GENERIC_PRIMITIVE (GENERIC | PRIMITIVE)  #define GENERIC_PRIMITIVE (GENERIC | PRIMITIVE)
# Line 2319  Line 2520 
2520  #endif  #endif
2521    
2522      /* Java-like methods. */      /* Java-like methods. */
2523      JS_FN(js_toString_str,     str_toString,          0,JSFUN_THISP_STRING),      JS_TN(js_toString_str,     str_toString,          0,JSFUN_THISP_STRING, str_toString_trcinfo),
2524      JS_FN(js_valueOf_str,      str_toString,          0,JSFUN_THISP_STRING),      JS_FN(js_valueOf_str,      str_toString,          0,JSFUN_THISP_STRING),
2525      JS_FN("substring",         js_str_substring,      2,GENERIC_PRIMITIVE),      JS_FN(js_toJSON_str,       str_toString,          0,JSFUN_THISP_STRING),
2526      JS_FN("toLowerCase",       js_str_toLowerCase,    0,GENERIC_PRIMITIVE),      JS_TN("substring",         str_substring,         2,GENERIC_PRIMITIVE, str_substring_trcinfo),
2527      JS_FN("toUpperCase",       js_str_toUpperCase,    0,GENERIC_PRIMITIVE),      JS_TN("toLowerCase",       str_toLowerCase,       0,GENERIC_PRIMITIVE, str_toLowerCase_trcinfo),
2528      JS_FN("charAt",            js_str_charAt,         1,GENERIC_PRIMITIVE),      JS_TN("toUpperCase",       str_toUpperCase,       0,GENERIC_PRIMITIVE, str_toUpperCase_trcinfo),
2529      JS_FN("charCodeAt",        js_str_charCodeAt,     1,GENERIC_PRIMITIVE),      JS_TN("charAt",            str_charAt,            1,GENERIC_PRIMITIVE, str_charAt_trcinfo),
2530        JS_TN("charCodeAt",        str_charCodeAt,        1,GENERIC_PRIMITIVE, str_charCodeAt_trcinfo),
2531      JS_FN("indexOf",           str_indexOf,           1,GENERIC_PRIMITIVE),      JS_FN("indexOf",           str_indexOf,           1,GENERIC_PRIMITIVE),
2532      JS_FN("lastIndexOf",       str_lastIndexOf,       1,GENERIC_PRIMITIVE),      JS_FN("lastIndexOf",       str_lastIndexOf,       1,GENERIC_PRIMITIVE),
2533      JS_FN("trim",              str_trim,              0,GENERIC_PRIMITIVE),      JS_FN("trim",              str_trim,              0,GENERIC_PRIMITIVE),
# Line 2336  Line 2538 
2538      JS_FN("localeCompare",     str_localeCompare,     1,GENERIC_PRIMITIVE),      JS_FN("localeCompare",     str_localeCompare,     1,GENERIC_PRIMITIVE),
2539    
2540      /* Perl-ish methods (search is actually Python-esque). */      /* Perl-ish methods (search is actually Python-esque). */
2541      JS_FN("match",             js_str_match,          1,GENERIC_PRIMITIVE),      JS_TN("match",             str_match,             1,GENERIC_PRIMITIVE, str_match_trcinfo),
2542      JS_FN("search",            str_search,            1,GENERIC_PRIMITIVE),      JS_FN("search",            str_search,            1,GENERIC_PRIMITIVE),
2543      JS_FN("replace",           js_str_replace,        2,GENERIC_PRIMITIVE),      JS_TN("replace",           str_replace,           2,GENERIC_PRIMITIVE, str_replace_trcinfo),
2544      JS_FN("split",             js_str_split,          2,GENERIC_PRIMITIVE),      JS_TN("split",             str_split,             2,GENERIC_PRIMITIVE, str_split_trcinfo),
2545  #if JS_HAS_PERL_SUBSTR  #if JS_HAS_PERL_SUBSTR
2546      JS_FN("substr",            str_substr,            2,GENERIC_PRIMITIVE),      JS_FN("substr",            str_substr,            2,GENERIC_PRIMITIVE),
2547  #endif  #endif
2548    
2549      /* Python-esque sequence methods. */      /* Python-esque sequence methods. */
2550      JS_FN("concat",            js_str_concat,         1,GENERIC_PRIMITIVE),      JS_TN("concat",            str_concat,            1,GENERIC_PRIMITIVE, str_concat_trcinfo),
2551      JS_FN("slice",             str_slice,             2,GENERIC_PRIMITIVE),      JS_FN("slice",             str_slice,             2,GENERIC_PRIMITIVE),
2552    
2553      /* HTML string methods. */      /* HTML string methods. */
# Line 2389  Line 2591 
2591      return JS_TRUE;      return JS_TRUE;
2592  }  }
2593    
2594  JSBool  static JSBool
2595  js_str_fromCharCode(JSContext *cx, uintN argc, jsval *vp)  str_fromCharCode(JSContext *cx, uintN argc, jsval *vp)
2596  {  {
2597      jsval *argv;      jsval *argv;
2598      uintN i;      uintN i;
# Line 2429  Line 2631 
2631      return JS_TRUE;      return JS_TRUE;
2632  }  }
2633    
2634    #ifdef JS_TRACER
2635    static JSString* FASTCALL
2636    String_fromCharCode(JSContext* cx, int32 i)
2637    {
2638        JS_ASSERT(JS_ON_TRACE(cx));
2639        jschar c = (jschar)i;
2640        if (c < UNIT_STRING_LIMIT)
2641            return js_GetUnitStringForChar(cx, c);
2642        return js_NewStringCopyN(cx, &c, 1);
2643    }
2644    #endif
2645    
2646    JS_DEFINE_TRCINFO_1(str_fromCharCode,
2647        (2, (static, STRING_FAIL, String_fromCharCode, CONTEXT, INT32, 1, 1)))
2648    
2649  static JSFunctionSpec string_static_methods[] = {  static JSFunctionSpec string_static_methods[] = {
2650      JS_FN("fromCharCode",    js_str_fromCharCode,    1,0),      JS_TN("fromCharCode", str_fromCharCode, 1, 0, str_fromCharCode_trcinfo),
2651      JS_FS_END      JS_FS_END
2652  };  };
2653    
# Line 2920  Line 3137 
3137      return JS_TRUE;      return JS_TRUE;
3138  }  }
3139    
3140  jsint JS_FASTCALL  int32 JS_FASTCALL
3141  js_CompareStrings(JSString *str1, JSString *str2)  js_CompareStrings(JSString *str1, JSString *str2)
3142  {  {
3143      size_t l1, l2, n, i;      size_t l1, l2, n, i;

Legend:
Removed from v.332  
changed lines
  Added in v.399

  ViewVC Help
Powered by ViewVC 1.1.24