зеркало из https://github.com/mozilla/gecko-dev.git
Add split built-in, also sort knownNatives for my own sanity (should sort builtins.tbl and jsbuiltins.cpp by function while at it, but too tired).
This commit is contained in:
Родитель
db79b8dc5b
Коммит
d5629d06d7
|
@ -60,6 +60,7 @@ BUILTIN3(String_p_concat_1int, LO, LO, LO, P, JSString*, JSContest*, JSString*
|
|||
BUILTIN4(String_p_match, LO, LO, LO, LO, P, JSObject*, JSContext*, JSString*, jsbytecode*, JSObject*, 1, 1)
|
||||
BUILTIN4(String_p_replace_str, LO, LO, LO, LO, P, JSString*, JSContext*, JSString*, JSObject*, JSString*, 1, 1)
|
||||
BUILTIN5(String_p_replace_str3, LO, LO, LO, LO, LO, P, JSString*, JSContext*, JSString*, JSString*, JSString*, JSString*, 1, 1)
|
||||
BUILTIN3(String_p_split, LO, LO, LO, P, JSString*, JSContext*, JSString*, JSString*, 1, 1)
|
||||
BUILTIN1(Math_random, LO, F, jsdouble, JSRuntime*, 1, 1)
|
||||
BUILTIN2(EqualStrings, LO, LO, LO, bool, JSString*, JSString*, 1, 1)
|
||||
BUILTIN2(CompareStrings, LO, LO, LO, bool, JSString*, JSString*, 1, 1)
|
||||
|
|
|
@ -303,6 +303,17 @@ js_String_p_replace_str3(JSContext* cx, JSString* str, JSString* patstr, JSStrin
|
|||
return JSVAL_TO_STRING(vp[0]);
|
||||
}
|
||||
|
||||
JSString* FASTCALL
|
||||
js_String_p_split(JSContext* cx, JSString* str, JSString* sepstr)
|
||||
{
|
||||
// FIXME: optimize by calling into a lower level exported from jsstr.cpp.
|
||||
jsval vp[3] = { JSVAL_NULL, STRING_TO_JSVAL(str), STRING_TO_JSVAL(sepstr) };
|
||||
if (!js_str_split(cx, 2, vp))
|
||||
return NULL;
|
||||
JS_ASSERT(JSVAL_IS_STRING(vp[0]));
|
||||
return JSVAL_TO_STRING(vp[0]);
|
||||
}
|
||||
|
||||
jsdouble FASTCALL
|
||||
js_StringToNumber(JSContext* cx, JSString* str)
|
||||
{
|
||||
|
|
|
@ -1718,10 +1718,10 @@ out:
|
|||
}
|
||||
|
||||
/*
|
||||
* Subroutine used by str_split to find the next split point in str, starting
|
||||
* at offset *ip and looking either for the separator substring given by sep,
|
||||
* or for the next re match. In the re case, return the matched separator in
|
||||
* *sep, and the possibly updated offset in *ip.
|
||||
* Subroutine used by js_str_split to find the next split point in str, starting
|
||||
* at offset *ip and looking either for the separator substring given by sep, or
|
||||
* for the next re match. In the re case, return the matched separator in *sep,
|
||||
* and the possibly updated offset in *ip.
|
||||
*
|
||||
* Return -2 on error, -1 on end of string, >= 0 for a valid index of the next
|
||||
* separator occurrence if found, or str->length if no separator is found.
|
||||
|
@ -1743,7 +1743,7 @@ find_split(JSContext *cx, JSString *str, JSRegExp *re, jsint *ip,
|
|||
*
|
||||
* 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).
|
||||
* limit argument (see js_str_split).
|
||||
*/
|
||||
i = *ip;
|
||||
length = JSSTRING_LENGTH(str);
|
||||
|
@ -1829,8 +1829,8 @@ find_split(JSContext *cx, JSString *str, JSRegExp *re, jsint *ip,
|
|||
return k;
|
||||
}
|
||||
|
||||
static JSBool
|
||||
str_split(JSContext *cx, uintN argc, jsval *vp)
|
||||
JSBool
|
||||
js_str_split(JSContext *cx, uintN argc, jsval *vp)
|
||||
{
|
||||
JSString *str, *sub;
|
||||
JSObject *arrayobj;
|
||||
|
@ -2269,7 +2269,7 @@ static JSFunctionSpec string_methods[] = {
|
|||
JS_FN("match", js_str_match, 1,GENERIC_PRIMITIVE),
|
||||
JS_FN("search", str_search, 1,GENERIC_PRIMITIVE),
|
||||
JS_FN("replace", js_str_replace, 2,GENERIC_PRIMITIVE),
|
||||
JS_FN("split", str_split, 2,GENERIC_PRIMITIVE),
|
||||
JS_FN("split", js_str_split, 2,GENERIC_PRIMITIVE),
|
||||
#if JS_HAS_PERL_SUBSTR
|
||||
JS_FN("substr", str_substr, 2,GENERIC_PRIMITIVE),
|
||||
#endif
|
||||
|
|
|
@ -626,6 +626,9 @@ extern JSBool
|
|||
js_StringReplaceHelper(JSContext *cx, uintN argc, JSObject *lambda,
|
||||
JSString *repstr, jsval *vp);
|
||||
|
||||
extern JSBool
|
||||
js_str_split(JSContext *cx, uintN argc, jsval *vp);
|
||||
|
||||
/*
|
||||
* Convert one UCS-4 char and write it into a UTF-8 buffer, which must be at
|
||||
* least 6 bytes long. Return the number of UTF-8 bytes of data written.
|
||||
|
|
|
@ -4060,28 +4060,29 @@ TraceRecorder::record_JSOP_CALL()
|
|||
ABORT_TRACE("slow native");
|
||||
|
||||
static JSTraceableNative knownNatives[] = {
|
||||
{ js_array_join, F_Array_p_join, "TC", "s", FAIL_NULL, NULL },
|
||||
{ js_math_sin, F_Math_sin, "", "d", INFALLIBLE, NULL },
|
||||
{ js_math_cos, F_Math_cos, "", "d", INFALLIBLE, NULL },
|
||||
{ js_math_pow, F_Math_pow, "", "dd", INFALLIBLE, NULL },
|
||||
{ js_math_sqrt, F_Math_sqrt, "", "d", INFALLIBLE, NULL },
|
||||
{ js_math_floor, F_Math_floor, "", "d", INFALLIBLE, NULL },
|
||||
{ js_str_substring, F_String_p_substring, "TC", "ii", FAIL_NULL, NULL },
|
||||
{ js_str_substring, F_String_p_substring_1, "TC", "i", FAIL_NULL, NULL },
|
||||
{ js_str_fromCharCode, F_String_fromCharCode, "C", "i", FAIL_NULL, NULL },
|
||||
{ js_str_charCodeAt, F_String_p_charCodeAt, "T", "i", FAIL_NEG, NULL },
|
||||
{ js_str_charAt, F_String_getelem, "TC", "i", FAIL_NULL, NULL },
|
||||
{ js_str_match, F_String_p_match, "PTC", "r", FAIL_VOID, NULL },
|
||||
{ js_str_replace, F_String_p_replace_str3,"TC","sss", FAIL_NULL, NULL },
|
||||
{ js_str_replace, F_String_p_replace_str, "TC", "sr", FAIL_NULL, NULL },
|
||||
{ js_math_random, F_Math_random, "R", "", INFALLIBLE, NULL },
|
||||
{ js_str_concat, F_String_p_concat_1int, "TC", "i", FAIL_NULL, NULL },
|
||||
{ js_array_join, F_Array_p_join, "TC", "s", FAIL_NULL, NULL },
|
||||
{ js_num_parseInt, F_ParseInt, "C", "s", INFALLIBLE, NULL },
|
||||
{ js_num_parseFloat, F_ParseFloat, "C", "s", INFALLIBLE, NULL },
|
||||
{ js_obj_hasOwnProperty, F_Object_p_hasOwnProperty,
|
||||
"TC", "s", FAIL_VOID, NULL },
|
||||
{ js_obj_propertyIsEnumerable, F_Object_p_propertyIsEnumerable,
|
||||
"TC", "s", FAIL_VOID, NULL },
|
||||
{ js_num_parseInt, F_ParseInt, "C", "s", INFALLIBLE, NULL },
|
||||
{ js_num_parseFloat, F_ParseFloat, "C", "s", INFALLIBLE, NULL },
|
||||
{ js_str_charAt, F_String_getelem, "TC", "i", FAIL_NULL, NULL },
|
||||
{ js_str_charCodeAt, F_String_p_charCodeAt, "T", "i", FAIL_NEG, NULL },
|
||||
{ js_str_concat, F_String_p_concat_1int, "TC", "i", FAIL_NULL, NULL },
|
||||
{ js_str_fromCharCode, F_String_fromCharCode, "C", "i", FAIL_NULL, NULL },
|
||||
{ js_str_match, F_String_p_match, "PTC", "r", FAIL_VOID, NULL },
|
||||
{ js_str_replace, F_String_p_replace_str, "TC", "sr", FAIL_NULL, NULL },
|
||||
{ js_str_replace, F_String_p_replace_str3,"TC","sss", FAIL_NULL, NULL },
|
||||
{ js_str_split, F_String_p_split, "TC", "s", FAIL_NULL, NULL },
|
||||
{ js_str_substring, F_String_p_substring, "TC", "ii", FAIL_NULL, NULL },
|
||||
{ js_str_substring, F_String_p_substring_1, "TC", "i", FAIL_NULL, NULL },
|
||||
};
|
||||
|
||||
for (uintN i = 0; i < JS_ARRAY_LENGTH(knownNatives); i++) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче