Backed out 4 changesets (bug 1263558) for jit OOM crashes a=backout

Backed out changeset 7fcc62dda4e3 (bug 1263558)
Backed out changeset faa055e3ace8 (bug 1263558)
Backed out changeset 94805cd19c15 (bug 1263558)
Backed out changeset ad22cb06de5d (bug 1263558)

MozReview-Commit-ID: JkWyfHDBf1E
This commit is contained in:
Wes Kocher 2016-04-15 10:21:35 -07:00
Родитель c4445ccd33
Коммит 59d9a1b8ae
13 изменённых файлов: 123 добавлений и 877 удалений

Просмотреть файл

@ -1027,60 +1027,3 @@ function ArrayStaticConcat(arr, arg1) {
var args = callFunction(std_Array_slice, arguments, 1);
return callFunction(std_Function_apply, ArrayConcat, arr, args);
}
function ArrayStaticJoin(arr, separator) {
if (arguments.length < 1)
ThrowTypeError(JSMSG_MISSING_FUN_ARG, 0, 'Array.join');
return callFunction(std_Array_join, arr, separator);
}
function ArrayStaticReverse(arr) {
if (arguments.length < 1)
ThrowTypeError(JSMSG_MISSING_FUN_ARG, 0, 'Array.reverse');
return callFunction(std_Array_reverse, arr);
}
function ArrayStaticSort(arr, comparefn) {
if (arguments.length < 1)
ThrowTypeError(JSMSG_MISSING_FUN_ARG, 0, 'Array.sort');
return callFunction(std_Array_sort, arr, comparefn);
}
function ArrayStaticPush(arr, arg1) {
if (arguments.length < 1)
ThrowTypeError(JSMSG_MISSING_FUN_ARG, 0, 'Array.push');
var args = callFunction(std_Array_slice, arguments, 1);
return callFunction(std_Function_apply, std_Array_push, arr, args);
}
function ArrayStaticPop(arr) {
if (arguments.length < 1)
ThrowTypeError(JSMSG_MISSING_FUN_ARG, 0, 'Array.pop');
return callFunction(std_Array_pop, arr);
}
function ArrayStaticShift(arr) {
if (arguments.length < 1)
ThrowTypeError(JSMSG_MISSING_FUN_ARG, 0, 'Array.shift');
return callFunction(std_Array_shift, arr);
}
function ArrayStaticUnshift(arr, arg1) {
if (arguments.length < 1)
ThrowTypeError(JSMSG_MISSING_FUN_ARG, 0, 'Array.unshift');
var args = callFunction(std_Array_slice, arguments, 1);
return callFunction(std_Function_apply, std_Array_unshift, arr, args);
}
function ArrayStaticSplice(arr, start, deleteCount) {
if (arguments.length < 1)
ThrowTypeError(JSMSG_MISSING_FUN_ARG, 0, 'Array.splice');
var args = callFunction(std_Array_slice, arguments, 1);
return callFunction(std_Function_apply, std_Array_splice, arr, args);
}
function ArrayStaticSlice(arr, start, end) {
if (arguments.length < 1)
ThrowTypeError(JSMSG_MISSING_FUN_ARG, 0, 'Array.slice');
return callFunction(std_Array_slice, arr, start, end);
}

Просмотреть файл

@ -722,11 +722,7 @@ function String_static_localeCompare(str1, str2) {
ThrowTypeError(JSMSG_MISSING_FUN_ARG, 0, "String.localeCompare");
var locales = arguments.length > 2 ? arguments[2] : undefined;
var options = arguments.length > 3 ? arguments[3] : undefined;
#if EXPOSE_INTL_API
return callFunction(String_localeCompare, str1, str2, locales, options);
#else
return callFunction(std_String_localeCompare, str1, str2, locales, options);
#endif
}
// ES6 draft 2014-04-27 B.2.3.3
@ -828,108 +824,3 @@ function String_link(url) {
var S = ToString(this);
return '<a href="' + EscapeAttributeValue(url) + '">' + S + "</a>";
}
function String_static_toLowerCase(string) {
if (arguments.length < 1)
ThrowTypeError(JSMSG_MISSING_FUN_ARG, 0, 'String.toLowerCase');
return callFunction(std_String_toLowerCase, string);
}
function String_static_toUpperCase(string) {
if (arguments.length < 1)
ThrowTypeError(JSMSG_MISSING_FUN_ARG, 0, 'String.toUpperCase');
return callFunction(std_String_toUpperCase, string);
}
function String_static_charAt(string, pos) {
if (arguments.length < 1)
ThrowTypeError(JSMSG_MISSING_FUN_ARG, 0, 'String.charAt');
return callFunction(std_String_charAt, string, pos);
}
function String_static_charCodeAt(string, pos) {
if (arguments.length < 1)
ThrowTypeError(JSMSG_MISSING_FUN_ARG, 0, 'String.charCodeAt');
return callFunction(std_String_charCodeAt, string, pos);
}
function String_static_includes(string, searchString) {
if (arguments.length < 1)
ThrowTypeError(JSMSG_MISSING_FUN_ARG, 0, 'String.includes');
var position = arguments.length > 2 ? arguments[2] : undefined;
return callFunction(std_String_includes, string, searchString, position);
}
function String_static_indexOf(string, searchString) {
if (arguments.length < 1)
ThrowTypeError(JSMSG_MISSING_FUN_ARG, 0, 'String.indexOf');
var position = arguments.length > 2 ? arguments[2] : undefined;
return callFunction(std_String_indexOf, string, searchString, position);
}
function String_static_lastIndexOf(string, searchString) {
if (arguments.length < 1)
ThrowTypeError(JSMSG_MISSING_FUN_ARG, 0, 'String.lastIndexOf');
var position = arguments.length > 2 ? arguments[2] : undefined;
return callFunction(std_String_lastIndexOf, string, searchString, position);
}
function String_static_startsWith(string, searchString) {
if (arguments.length < 1)
ThrowTypeError(JSMSG_MISSING_FUN_ARG, 0, 'String.startsWith');
var position = arguments.length > 2 ? arguments[2] : undefined;
return callFunction(std_String_startsWith, string, searchString, position);
}
function String_static_endsWith(string, searchString) {
if (arguments.length < 1)
ThrowTypeError(JSMSG_MISSING_FUN_ARG, 0, 'String.endsWith');
var endPosition = arguments.length > 2 ? arguments[2] : undefined;
return callFunction(std_String_endsWith, string, searchString, endPosition);
}
function String_static_trim(string) {
if (arguments.length < 1)
ThrowTypeError(JSMSG_MISSING_FUN_ARG, 0, 'String.trim');
return callFunction(std_String_trim, string);
}
function String_static_trimLeft(string) {
if (arguments.length < 1)
ThrowTypeError(JSMSG_MISSING_FUN_ARG, 0, 'String.trimLeft');
return callFunction(std_String_trimLeft, string);
}
function String_static_trimRight(string) {
if (arguments.length < 1)
ThrowTypeError(JSMSG_MISSING_FUN_ARG, 0, 'String.trimRight');
return callFunction(std_String_trimRight, string);
}
function String_static_toLocaleLowerCase(string) {
if (arguments.length < 1)
ThrowTypeError(JSMSG_MISSING_FUN_ARG, 0, 'String.toLocaleLowerCase');
return callFunction(std_String_toLocaleLowerCase, string);
}
function String_static_toLocaleUpperCase(string) {
if (arguments.length < 1)
ThrowTypeError(JSMSG_MISSING_FUN_ARG, 0, 'String.toLocaleUpperCase');
return callFunction(std_String_toLocaleUpperCase, string);
}
#if EXPOSE_INTL_API
function String_static_normalize(string) {
if (arguments.length < 1)
ThrowTypeError(JSMSG_MISSING_FUN_ARG, 0, 'String.normalize');
var form = arguments.length > 1 ? arguments[1] : undefined;
return callFunction(std_String_normalize, string, form);
}
#endif
function String_static_concat(string, arg1) {
if (arguments.length < 1)
ThrowTypeError(JSMSG_MISSING_FUN_ARG, 0, 'String.concat');
var args = callFunction(std_Array_slice, arguments, 1);
return callFunction(std_Function_apply, std_String_concat, string, args);
}

Просмотреть файл

@ -1,16 +0,0 @@
if (!('oomTest' in this))
quit();
evalcx(`
eval('\
var appendToActual = function(s) {};\
gczeal = function() {};\
gcslice = function() {};\
selectforgc = function() {};\
if (!("verifyprebarriers" in this)) {\
verifyprebarriers = function() {};\
}\
');
oomTest(() => eval('Array(..."")'));
Intl.NumberFormat.prototype.format(0);
`, newGlobal());

Просмотреть файл

@ -837,7 +837,17 @@ class MOZ_STACK_CLASS SourceBufferHolder final
#define JSFUN_CONSTRUCTOR 0x400 /* native that can be called as a ctor */
// 0x800 /* Unused */
/*
* Specify a generic native prototype methods, i.e., methods of a class
* prototype that are exposed as static methods taking an extra leading
* argument: the generic |this| parameter.
*
* If you set this flag in a JSFunctionSpec struct's flags initializer, then
* that struct must live at least as long as the native static method object
* created due to this flag by JS_DefineFunctions or JS_InitClass. Typically
* JSFunctionSpec structs are allocated in static arrays.
*/
#define JSFUN_GENERIC_NATIVE 0x800
#define JSFUN_HAS_REST 0x1000 /* function has ...rest parameter. */

Просмотреть файл

@ -1390,8 +1390,8 @@ ArrayReverseDenseKernel(JSContext* cx, HandleObject obj, uint32_t length)
DefineBoxedOrUnboxedFunctor3(ArrayReverseDenseKernel,
JSContext*, HandleObject, uint32_t);
bool
js::array_reverse(JSContext* cx, unsigned argc, Value* vp)
static bool
array_reverse(JSContext* cx, unsigned argc, Value* vp)
{
AutoSPSEntry pseudoFrame(cx->runtime(), "Array.prototype.reverse");
CallArgs args = CallArgsFromVp(argc, vp);
@ -2381,8 +2381,8 @@ CanOptimizeForDenseStorage(HandleObject arr, uint32_t startingIndex, uint32_t co
}
/* ES 2016 draft Mar 25, 2016 22.1.3.26. */
bool
js::array_splice(JSContext* cx, unsigned argc, Value* vp)
static bool
array_splice(JSContext* cx, unsigned argc, Value* vp)
{
return array_splice_impl(cx, argc, vp, true);
}
@ -3082,6 +3082,8 @@ array_of(JSContext* cx, unsigned argc, Value* vp)
return true;
}
#define GENERIC JSFUN_GENERIC_NATIVE
static const JSFunctionSpec array_methods[] = {
#if JS_HAS_TOSOURCE
JS_FN(js_toSource_str, array_toSource, 0,0),
@ -3090,18 +3092,18 @@ static const JSFunctionSpec array_methods[] = {
JS_FN(js_toLocaleString_str, array_toLocaleString, 0,0),
/* Perl-ish methods. */
JS_INLINABLE_FN("join", array_join, 1,0, ArrayJoin),
JS_FN("reverse", array_reverse, 0,0),
JS_FN("sort", array_sort, 1,0),
JS_INLINABLE_FN("push", array_push, 1,0, ArrayPush),
JS_INLINABLE_FN("pop", array_pop, 0,0, ArrayPop),
JS_INLINABLE_FN("shift", array_shift, 0,0, ArrayShift),
JS_FN("unshift", array_unshift, 1,0),
JS_INLINABLE_FN("splice", array_splice, 2,0, ArraySplice),
JS_INLINABLE_FN("join", array_join, 1,JSFUN_GENERIC_NATIVE, ArrayJoin),
JS_FN("reverse", array_reverse, 0,JSFUN_GENERIC_NATIVE),
JS_FN("sort", array_sort, 1,JSFUN_GENERIC_NATIVE),
JS_INLINABLE_FN("push", array_push, 1,JSFUN_GENERIC_NATIVE, ArrayPush),
JS_INLINABLE_FN("pop", array_pop, 0,JSFUN_GENERIC_NATIVE, ArrayPop),
JS_INLINABLE_FN("shift", array_shift, 0,JSFUN_GENERIC_NATIVE, ArrayShift),
JS_FN("unshift", array_unshift, 1,JSFUN_GENERIC_NATIVE),
JS_INLINABLE_FN("splice", array_splice, 2,JSFUN_GENERIC_NATIVE, ArraySplice),
/* Pythonic sequence methods. */
JS_SELF_HOSTED_FN("concat", "ArrayConcat", 1,0),
JS_INLINABLE_FN("slice", array_slice, 2,0, ArraySlice),
JS_INLINABLE_FN("slice", array_slice, 2,JSFUN_GENERIC_NATIVE, ArraySlice),
JS_SELF_HOSTED_FN("lastIndexOf", "ArrayLastIndexOf", 1,0),
JS_SELF_HOSTED_FN("indexOf", "ArrayIndexOf", 1,0),
@ -3142,15 +3144,6 @@ static const JSFunctionSpec array_static_methods[] = {
JS_SELF_HOSTED_FN("some", "ArrayStaticSome", 2,0),
JS_SELF_HOSTED_FN("reduce", "ArrayStaticReduce", 2,0),
JS_SELF_HOSTED_FN("reduceRight", "ArrayStaticReduceRight", 2,0),
JS_SELF_HOSTED_FN("join", "ArrayStaticJoin", 2,0),
JS_SELF_HOSTED_FN("reverse", "ArrayStaticReverse", 1,0),
JS_SELF_HOSTED_FN("sort", "ArrayStaticSort", 2,0),
JS_SELF_HOSTED_FN("push", "ArrayStaticPush", 2,0),
JS_SELF_HOSTED_FN("pop", "ArrayStaticPop", 1,0),
JS_SELF_HOSTED_FN("shift", "ArrayStaticShift", 1,0),
JS_SELF_HOSTED_FN("unshift", "ArrayStaticUnshift", 2,0),
JS_SELF_HOSTED_FN("splice", "ArrayStaticSplice", 3,0),
JS_SELF_HOSTED_FN("slice", "ArrayStaticSlice", 3,0),
JS_SELF_HOSTED_FN("from", "ArrayFrom", 3,0),
JS_FN("of", array_of, 0,0),

Просмотреть файл

@ -184,12 +184,6 @@ array_slice(JSContext* cx, unsigned argc, js::Value* vp);
extern JSObject*
array_slice_dense(JSContext* cx, HandleObject obj, int32_t begin, int32_t end, HandleObject result);
extern bool
array_reverse(JSContext* cx, unsigned argc, js::Value* vp);
extern bool
array_splice(JSContext* cx, unsigned argc, js::Value* vp);
/*
* Append the given (non-hole) value to the end of an array. The array must be
* a newborn array -- that is, one which has not been exposed to script for

Просмотреть файл

@ -2899,6 +2899,34 @@ js::HasDataProperty(JSContext* cx, NativeObject* obj, jsid id, Value* vp)
return false;
}
static bool
GenericNativeMethodDispatcher(JSContext* cx, unsigned argc, Value* vp)
{
CallArgs args = CallArgsFromVp(argc, vp);
const JSFunctionSpec* fs = (JSFunctionSpec*)
args.callee().as<JSFunction>().getExtendedSlot(0).toPrivate();
MOZ_ASSERT((fs->flags & JSFUN_GENERIC_NATIVE) != 0);
if (argc < 1) {
ReportMissingArg(cx, args.calleev(), 0);
return false;
}
/*
* Copy all actual (argc) arguments down over our |this| parameter, vp[1],
* which is almost always the class constructor object, e.g. Array. Then
* call the corresponding prototype native method with our first argument
* passed as |this|.
*/
memmove(vp + 1, vp + 2, argc * sizeof(Value));
/* Clear the last parameter in case too few arguments were passed. */
vp[2 + --argc].setUndefined();
return fs->call.op(cx, argc, vp);
}
extern bool
PropertySpecNameToId(JSContext* cx, const char* name, MutableHandleId id,
js::PinningBehavior pin = js::DoNotPinAtom);
@ -2926,6 +2954,27 @@ DefineFunctionFromSpec(JSContext* cx, HandleObject obj, const JSFunctionSpec* fs
if (!PropertySpecNameToId(cx, fs->name, &id))
return false;
// Define a generic arity N+1 static method for the arity N prototype
// method if flags contains JSFUN_GENERIC_NATIVE.
if (flags & JSFUN_GENERIC_NATIVE) {
// We require that any consumers using JSFUN_GENERIC_NATIVE stash
// the prototype and constructor in the global slots before invoking
// JS_DefineFunctions on the proto.
JSProtoKey key = JSCLASS_CACHED_PROTO_KEY(obj->getClass());
MOZ_ASSERT(obj == &obj->global().getPrototype(key).toObject());
RootedObject ctor(cx, &obj->global().getConstructor(key).toObject());
flags &= ~JSFUN_GENERIC_NATIVE;
JSFunction* fun = DefineFunction(cx, ctor, id,
GenericNativeMethodDispatcher,
fs->nargs + 1, flags,
gc::AllocKind::FUNCTION_EXTENDED);
if (!fun)
return false;
fun->setExtendedSlot(0, PrivateValue(const_cast<JSFunctionSpec*>(fs)));
}
JSFunction* fun = NewFunctionFromSpec(cx, fs, id);
if (!fun)
return false;

Просмотреть файл

@ -682,8 +682,8 @@ js::str_toLowerCase(JSContext* cx, unsigned argc, Value* vp)
return ToLowerCaseHelper(cx, CallArgsFromVp(argc, vp));
}
bool
js::str_toLocaleLowerCase(JSContext* cx, unsigned argc, Value* vp)
static bool
str_toLocaleLowerCase(JSContext* cx, unsigned argc, Value* vp)
{
CallArgs args = CallArgsFromVp(argc, vp);
@ -833,8 +833,8 @@ js::str_toUpperCase(JSContext* cx, unsigned argc, Value* vp)
return ToUpperCaseHelper(cx, CallArgsFromVp(argc, vp));
}
bool
js::str_toLocaleUpperCase(JSContext* cx, unsigned argc, Value* vp)
static bool
str_toLocaleUpperCase(JSContext* cx, unsigned argc, Value* vp)
{
CallArgs args = CallArgsFromVp(argc, vp);
@ -859,8 +859,8 @@ js::str_toLocaleUpperCase(JSContext* cx, unsigned argc, Value* vp)
}
#if !EXPOSE_INTL_API
bool
js::str_localeCompare(JSContext* cx, unsigned argc, Value* vp)
static bool
str_localeCompare(JSContext* cx, unsigned argc, Value* vp)
{
CallArgs args = CallArgsFromVp(argc, vp);
RootedString str(cx, ThisToStringForStringProto(cx, args));
@ -891,8 +891,8 @@ js::str_localeCompare(JSContext* cx, unsigned argc, Value* vp)
#if EXPOSE_INTL_API
/* ES6 20140210 draft 21.1.3.12. */
bool
js::str_normalize(JSContext* cx, unsigned argc, Value* vp)
static bool
str_normalize(JSContext* cx, unsigned argc, Value* vp)
{
CallArgs args = CallArgsFromVp(argc, vp);
@ -1820,8 +1820,8 @@ js::str_startsWith(JSContext* cx, unsigned argc, Value* vp)
}
/* ES6 draft rc3 21.1.3.6. */
bool
js::str_endsWith(JSContext* cx, unsigned argc, Value* vp)
static bool
str_endsWith(JSContext* cx, unsigned argc, Value* vp)
{
CallArgs args = CallArgsFromVp(argc, vp);
@ -1939,20 +1939,20 @@ TrimString(JSContext* cx, Value* vp, bool trimLeft, bool trimRight)
return true;
}
bool
js::str_trim(JSContext* cx, unsigned argc, Value* vp)
static bool
str_trim(JSContext* cx, unsigned argc, Value* vp)
{
return TrimString(cx, vp, true, true);
}
bool
js::str_trimLeft(JSContext* cx, unsigned argc, Value* vp)
static bool
str_trimLeft(JSContext* cx, unsigned argc, Value* vp)
{
return TrimString(cx, vp, true, false);
}
bool
js::str_trimRight(JSContext* cx, unsigned argc, Value* vp)
static bool
str_trimRight(JSContext* cx, unsigned argc, Value* vp)
{
return TrimString(cx, vp, false, true);
}
@ -2486,8 +2486,8 @@ js::str_split_string(JSContext* cx, HandleObjectGroup group, HandleString str, H
/*
* Python-esque sequence operations.
*/
bool
js::str_concat(JSContext* cx, unsigned argc, Value* vp)
static bool
str_concat(JSContext* cx, unsigned argc, Value* vp)
{
CallArgs args = CallArgsFromVp(argc, vp);
JSString* str = ThisToStringForStringProto(cx, args);
@ -2527,32 +2527,32 @@ static const JSFunctionSpec string_methods[] = {
/* Java-like methods. */
JS_FN(js_toString_str, str_toString, 0,0),
JS_FN(js_valueOf_str, str_toString, 0,0),
JS_FN("toLowerCase", str_toLowerCase, 0,0),
JS_FN("toUpperCase", str_toUpperCase, 0,0),
JS_INLINABLE_FN("charAt", str_charAt, 1,0, StringCharAt),
JS_INLINABLE_FN("charCodeAt", str_charCodeAt, 1,0, StringCharCodeAt),
JS_FN("toLowerCase", str_toLowerCase, 0,JSFUN_GENERIC_NATIVE),
JS_FN("toUpperCase", str_toUpperCase, 0,JSFUN_GENERIC_NATIVE),
JS_INLINABLE_FN("charAt", str_charAt, 1,JSFUN_GENERIC_NATIVE, StringCharAt),
JS_INLINABLE_FN("charCodeAt", str_charCodeAt, 1,JSFUN_GENERIC_NATIVE, StringCharCodeAt),
JS_SELF_HOSTED_FN("substring", "String_substring", 2,0),
JS_SELF_HOSTED_FN("padStart", "String_pad_start", 2,0),
JS_SELF_HOSTED_FN("padEnd", "String_pad_end", 2,0),
JS_SELF_HOSTED_FN("codePointAt", "String_codePointAt", 1,0),
JS_FN("includes", str_includes, 1,0),
JS_FN("indexOf", str_indexOf, 1,0),
JS_FN("lastIndexOf", str_lastIndexOf, 1,0),
JS_FN("startsWith", str_startsWith, 1,0),
JS_FN("endsWith", str_endsWith, 1,0),
JS_FN("trim", str_trim, 0,0),
JS_FN("trimLeft", str_trimLeft, 0,0),
JS_FN("trimRight", str_trimRight, 0,0),
JS_FN("toLocaleLowerCase", str_toLocaleLowerCase, 0,0),
JS_FN("toLocaleUpperCase", str_toLocaleUpperCase, 0,0),
JS_FN("includes", str_includes, 1,JSFUN_GENERIC_NATIVE),
JS_FN("indexOf", str_indexOf, 1,JSFUN_GENERIC_NATIVE),
JS_FN("lastIndexOf", str_lastIndexOf, 1,JSFUN_GENERIC_NATIVE),
JS_FN("startsWith", str_startsWith, 1,JSFUN_GENERIC_NATIVE),
JS_FN("endsWith", str_endsWith, 1,JSFUN_GENERIC_NATIVE),
JS_FN("trim", str_trim, 0,JSFUN_GENERIC_NATIVE),
JS_FN("trimLeft", str_trimLeft, 0,JSFUN_GENERIC_NATIVE),
JS_FN("trimRight", str_trimRight, 0,JSFUN_GENERIC_NATIVE),
JS_FN("toLocaleLowerCase", str_toLocaleLowerCase, 0,JSFUN_GENERIC_NATIVE),
JS_FN("toLocaleUpperCase", str_toLocaleUpperCase, 0,JSFUN_GENERIC_NATIVE),
#if EXPOSE_INTL_API
JS_SELF_HOSTED_FN("localeCompare", "String_localeCompare", 1,0),
#else
JS_FN("localeCompare", str_localeCompare, 1,0),
JS_FN("localeCompare", str_localeCompare, 1,JSFUN_GENERIC_NATIVE),
#endif
JS_SELF_HOSTED_FN("repeat", "String_repeat", 1,0),
#if EXPOSE_INTL_API
JS_FN("normalize", str_normalize, 0,0),
JS_FN("normalize", str_normalize, 0,JSFUN_GENERIC_NATIVE),
#endif
/* Perl-ish methods (search is actually Python-esque). */
@ -2563,7 +2563,7 @@ static const JSFunctionSpec string_methods[] = {
JS_SELF_HOSTED_FN("substr", "String_substr", 2,0),
/* Python-esque sequence methods. */
JS_FN("concat", str_concat, 1,0),
JS_FN("concat", str_concat, 1,JSFUN_GENERIC_NATIVE),
JS_SELF_HOSTED_FN("slice", "String_slice", 2,0),
/* HTML string methods. */
@ -2716,26 +2716,11 @@ static const JSFunctionSpec string_static_methods[] = {
JS_SELF_HOSTED_FN("search", "String_generic_search", 2,0),
JS_SELF_HOSTED_FN("split", "String_generic_split", 3,0),
JS_SELF_HOSTED_FN("toLowerCase", "String_static_toLowerCase", 1,0),
JS_SELF_HOSTED_FN("toUpperCase", "String_static_toUpperCase", 1,0),
JS_SELF_HOSTED_FN("charAt", "String_static_charAt", 2,0),
JS_SELF_HOSTED_FN("charCodeAt", "String_static_charCodeAt", 2,0),
JS_SELF_HOSTED_FN("includes", "String_static_includes", 2,0),
JS_SELF_HOSTED_FN("indexOf", "String_static_indexOf", 2,0),
JS_SELF_HOSTED_FN("lastIndexOf", "String_static_lastIndexOf", 2,0),
JS_SELF_HOSTED_FN("startsWith", "String_static_startsWith", 2,0),
JS_SELF_HOSTED_FN("endsWith", "String_static_endsWith", 2,0),
JS_SELF_HOSTED_FN("trim", "String_static_trim", 1,0),
JS_SELF_HOSTED_FN("trimLeft", "String_static_trimLeft", 1,0),
JS_SELF_HOSTED_FN("trimRight", "String_static_trimRight", 1,0),
JS_SELF_HOSTED_FN("toLocaleLowerCase","String_static_toLocaleLowerCase",1,0),
JS_SELF_HOSTED_FN("toLocaleUpperCase","String_static_toLocaleUpperCase",1,0),
// This must be at the end because of bug 853075: functions listed after
// self-hosted methods aren't available in self-hosted code.
#if EXPOSE_INTL_API
JS_SELF_HOSTED_FN("normalize", "String_static_normalize", 1,0),
#endif
JS_SELF_HOSTED_FN("concat", "String_static_concat", 2,0),
JS_SELF_HOSTED_FN("localeCompare", "String_static_localeCompare", 2,0),
#endif
JS_FS_END
};
@ -2767,6 +2752,9 @@ js::InitStringClass(JSContext* cx, HandleObject obj)
if (!ctor)
return nullptr;
if (!GlobalObject::initBuiltinConstructor(cx, global, JSProto_String, ctor, proto))
return nullptr;
if (!LinkConstructorAndPrototype(cx, ctor, proto))
return nullptr;
@ -2783,9 +2771,6 @@ js::InitStringClass(JSContext* cx, HandleObject obj)
if (!JS_DefineFunctions(cx, global, string_functions))
return nullptr;
if (!GlobalObject::initBuiltinConstructor(cx, global, JSProto_String, ctor, proto))
return nullptr;
return proto;
}

Просмотреть файл

@ -338,39 +338,6 @@ str_charCodeAt_impl(JSContext* cx, HandleString string, HandleValue index, Mutab
extern bool
str_charCodeAt(JSContext* cx, unsigned argc, Value* vp);
extern bool
str_contains(JSContext *cx, unsigned argc, Value *vp);
extern bool
str_endsWith(JSContext* cx, unsigned argc, Value* vp);
extern bool
str_trim(JSContext* cx, unsigned argc, Value* vp);
extern bool
str_trimLeft(JSContext* cx, unsigned argc, Value* vp);
extern bool
str_trimRight(JSContext* cx, unsigned argc, Value* vp);
extern bool
str_toLocaleLowerCase(JSContext* cx, unsigned argc, Value* vp);
extern bool
str_toLocaleUpperCase(JSContext* cx, unsigned argc, Value* vp);
#if !EXPOSE_INTL_API
extern bool
str_localeCompare(JSContext* cx, unsigned argc, Value* vp);
#else
extern bool
str_normalize(JSContext* cx, unsigned argc, Value* vp);
#endif
extern bool
str_concat(JSContext* cx, unsigned argc, Value* vp);
/*
* Convert one UCS-4 char and write it into a UTF-8 buffer, which must be at
* least 4 bytes long. Return the number of UTF-8 bytes of data written.

Просмотреть файл

@ -1,331 +0,0 @@
var BUGNUMBER = 1263558;
var summary = "Self-host all Array generics.";
print(BUGNUMBER + ": " + summary);
var arr, arrLike, tmp, f;
function reset() {
arr = [5, 7, 13];
arrLike = {
length: 3,
0: 5,
1: 7,
2: 13,
toString() {
return "arrLike";
}
};
tmp = [];
}
function toString() {
return "G";
}
// Array.join (test this first to use it in remaining tests).
reset();
assertThrowsInstanceOf(() => Array.join(), TypeError);
assertEq(Array.join(arr), "5,7,13");
assertEq(Array.join(arr, "-"), "5-7-13");
assertEq(Array.join(arrLike), "5,7,13");
assertEq(Array.join(arrLike, "-"), "5-7-13");
// Array.concat.
reset();
assertThrowsInstanceOf(() => Array.concat(), TypeError);
assertEq(Array.join(Array.concat(arr), ","), "5,7,13");
assertEq(Array.join(Array.concat(arr, 11), ","), "5,7,13,11");
assertEq(Array.join(Array.concat(arr, 11, 17), ","), "5,7,13,11,17");
assertEq(Array.join(Array.concat(arrLike), ","), "arrLike");
assertEq(Array.join(Array.concat(arrLike, 11), ","), "arrLike,11");
assertEq(Array.join(Array.concat(arrLike, 11, 17), ","), "arrLike,11,17");
// Array.lastIndexOf.
reset();
assertThrowsInstanceOf(() => Array.lastIndexOf(), TypeError);
assertEq(Array.lastIndexOf(arr), -1);
assertEq(Array.lastIndexOf(arr, 1), -1);
assertEq(Array.lastIndexOf(arr, 5), 0);
assertEq(Array.lastIndexOf(arr, 7), 1);
assertEq(Array.lastIndexOf(arr, 13, 1), -1);
assertEq(Array.lastIndexOf(arrLike), -1);
assertEq(Array.lastIndexOf(arrLike, 1), -1);
assertEq(Array.lastIndexOf(arrLike, 5), 0);
assertEq(Array.lastIndexOf(arrLike, 7), 1);
assertEq(Array.lastIndexOf(arrLike, 13, 1), -1);
// Array.indexOf.
reset();
assertThrowsInstanceOf(() => Array.indexOf(), TypeError);
assertEq(Array.indexOf(arr), -1);
assertEq(Array.indexOf(arr, 1), -1);
assertEq(Array.indexOf(arr, 5), 0);
assertEq(Array.indexOf(arr, 7), 1);
assertEq(Array.indexOf(arr, 1, 5), -1);
assertEq(Array.indexOf(arrLike), -1);
assertEq(Array.indexOf(arrLike, 1), -1);
assertEq(Array.indexOf(arrLike, 5), 0);
assertEq(Array.indexOf(arrLike, 7), 1);
assertEq(Array.indexOf(arrLike, 1, 5), -1);
// Array.forEach.
reset();
assertThrowsInstanceOf(() => Array.forEach(), TypeError);
assertThrowsInstanceOf(() => Array.forEach(arr), TypeError);
assertThrowsInstanceOf(() => Array.forEach(arrLike), TypeError);
f = function(...args) {
tmp.push(this, ...args);
};
tmp = [];
Array.forEach(arr, f);
assertEq(tmp.join(","), "G,5,0,5,7,13," + "G,7,1,5,7,13," + "G,13,2,5,7,13");
tmp = [];
Array.forEach(arr, f, "T");
assertEq(tmp.join(","), "T,5,0,5,7,13," + "T,7,1,5,7,13," + "T,13,2,5,7,13");
tmp = [];
Array.forEach(arrLike, f);
assertEq(tmp.join(","), "G,5,0,arrLike," + "G,7,1,arrLike," + "G,13,2,arrLike");
tmp = [];
Array.forEach(arrLike, f, "T");
assertEq(tmp.join(","), "T,5,0,arrLike," + "T,7,1,arrLike," + "T,13,2,arrLike");
// Array.map.
reset();
assertThrowsInstanceOf(() => Array.map(), TypeError);
assertThrowsInstanceOf(() => Array.map(arr), TypeError);
assertThrowsInstanceOf(() => Array.map(arrLike), TypeError);
f = function(...args) {
tmp.push(this, ...args);
return args[0] * 2;
}
tmp = [];
assertEq(Array.join(Array.map(arr, f), ","), "10,14,26");
assertEq(tmp.join(","), "G,5,0,5,7,13," + "G,7,1,5,7,13," + "G,13,2,5,7,13");
tmp = [];
assertEq(Array.join(Array.map(arr, f, "T"), ","), "10,14,26");
assertEq(tmp.join(","), "T,5,0,5,7,13," + "T,7,1,5,7,13," + "T,13,2,5,7,13");
tmp = [];
assertEq(Array.join(Array.map(arrLike, f), ","), "10,14,26");
assertEq(tmp.join(","), "G,5,0,arrLike," + "G,7,1,arrLike," + "G,13,2,arrLike");
tmp = [];
assertEq(Array.join(Array.map(arrLike, f, "T"), ","), "10,14,26");
assertEq(tmp.join(","), "T,5,0,arrLike," + "T,7,1,arrLike," + "T,13,2,arrLike");
// Array.filter.
reset();
assertThrowsInstanceOf(() => Array.filter(), TypeError);
assertThrowsInstanceOf(() => Array.filter(arr), TypeError);
assertThrowsInstanceOf(() => Array.filter(arrLike), TypeError);
f = function(...args) {
tmp.push(this, ...args);
return args[0] < 10;
}
tmp = [];
assertEq(Array.join(Array.filter(arr, f), ","), "5,7");
assertEq(tmp.join(","), "G,5,0,5,7,13," + "G,7,1,5,7,13," + "G,13,2,5,7,13");
tmp = [];
assertEq(Array.join(Array.filter(arr, f, "T"), ","), "5,7");
assertEq(tmp.join(","), "T,5,0,5,7,13," + "T,7,1,5,7,13," + "T,13,2,5,7,13");
tmp = [];
assertEq(Array.join(Array.filter(arrLike, f), ","), "5,7");
assertEq(tmp.join(","), "G,5,0,arrLike," + "G,7,1,arrLike," + "G,13,2,arrLike");
tmp = [];
assertEq(Array.join(Array.filter(arrLike, f, "T"), ","), "5,7");
assertEq(tmp.join(","), "T,5,0,arrLike," + "T,7,1,arrLike," + "T,13,2,arrLike");
// Array.every.
reset();
assertThrowsInstanceOf(() => Array.every(), TypeError);
assertThrowsInstanceOf(() => Array.every(arr), TypeError);
assertThrowsInstanceOf(() => Array.every(arrLike), TypeError);
f = function(...args) {
tmp.push(this, ...args);
return args[0] < 6;
}
tmp = [];
assertEq(Array.every(arr, f), false);
assertEq(tmp.join(","), "G,5,0,5,7,13," + "G,7,1,5,7,13");
tmp = [];
assertEq(Array.every(arr, f, "T"), false);
assertEq(tmp.join(","), "T,5,0,5,7,13," + "T,7,1,5,7,13");
tmp = [];
assertEq(Array.every(arrLike, f), false);
assertEq(tmp.join(","), "G,5,0,arrLike," + "G,7,1,arrLike");
tmp = [];
assertEq(Array.every(arrLike, f, "T"), false);
assertEq(tmp.join(","), "T,5,0,arrLike," + "T,7,1,arrLike");
// Array.some.
reset();
assertThrowsInstanceOf(() => Array.some(), TypeError);
assertThrowsInstanceOf(() => Array.some(arr), TypeError);
assertThrowsInstanceOf(() => Array.some(arrLike), TypeError);
f = function(...args) {
tmp.push(this, ...args);
return args[0] == 7;
}
tmp = [];
assertEq(Array.some(arr, f), true);
assertEq(tmp.join(","), "G,5,0,5,7,13," + "G,7,1,5,7,13");
tmp = [];
assertEq(Array.some(arr, f, "T"), true);
assertEq(tmp.join(","), "T,5,0,5,7,13," + "T,7,1,5,7,13");
tmp = [];
assertEq(Array.some(arrLike, f), true);
assertEq(tmp.join(","), "G,5,0,arrLike," + "G,7,1,arrLike");
tmp = [];
assertEq(Array.some(arrLike, f, "T"), true);
assertEq(tmp.join(","), "T,5,0,arrLike," + "T,7,1,arrLike");
// Array.reduce.
reset();
assertThrowsInstanceOf(() => Array.reduce(), TypeError);
assertThrowsInstanceOf(() => Array.reduce(arr), TypeError);
assertThrowsInstanceOf(() => Array.reduce(arrLike), TypeError);
f = function(...args) {
tmp.push(...args);
return args[0] + args[1];
}
tmp = [];
assertEq(Array.reduce(arr, f), 25);
assertEq(tmp.join(","), "5,7,1,5,7,13," + "12,13,2,5,7,13");
tmp = [];
assertEq(Array.reduce(arr, f, 17), 42);
assertEq(tmp.join(","), "17,5,0,5,7,13," + "22,7,1,5,7,13," + "29,13,2,5,7,13");
tmp = [];
assertEq(Array.reduce(arrLike, f), 25);
assertEq(tmp.join(","), "5,7,1,arrLike," + "12,13,2,arrLike");
tmp = [];
assertEq(Array.reduce(arrLike, f, 17), 42);
assertEq(tmp.join(","), "17,5,0,arrLike," + "22,7,1,arrLike," + "29,13,2,arrLike");
// Array.reduceRight.
reset();
assertThrowsInstanceOf(() => Array.reduceRight(), TypeError);
assertThrowsInstanceOf(() => Array.reduceRight(arr), TypeError);
assertThrowsInstanceOf(() => Array.reduceRight(arrLike), TypeError);
f = function(...args) {
tmp.push(...args);
return args[0] + args[1];
}
tmp = [];
assertEq(Array.reduceRight(arr, f), 25);
assertEq(tmp.join(","), "13,7,1,5,7,13," + "20,5,0,5,7,13");
tmp = [];
assertEq(Array.reduceRight(arr, f, 17), 42);
assertEq(tmp.join(","), "17,13,2,5,7,13," + "30,7,1,5,7,13," + "37,5,0,5,7,13");
tmp = [];
assertEq(Array.reduceRight(arrLike, f), 25);
assertEq(tmp.join(","), "13,7,1,arrLike," + "20,5,0,arrLike");
tmp = [];
assertEq(Array.reduceRight(arrLike, f, 17), 42);
assertEq(tmp.join(","), "17,13,2,arrLike," + "30,7,1,arrLike," + "37,5,0,arrLike");
// Array.reverse.
reset();
assertThrowsInstanceOf(() => Array.reverse(), TypeError);
assertEq(Array.join(Array.reverse(arr), ","), "13,7,5");
assertEq(Array.join(arr, ","), "13,7,5");
assertEq(Array.join(Array.reverse(arrLike), ","), "13,7,5");
assertEq(Array.join(arrLike, ","), "13,7,5");
// Array.sort.
reset();
assertThrowsInstanceOf(() => Array.sort(), TypeError);
f = function(x, y) {
return y - x;
}
assertEq(Array.join(Array.sort(arr), ","), "13,5,7");
assertEq(Array.join(Array.sort(arr, f), ","), "13,7,5");
assertEq(Array.join(Array.sort(arrLike), ","), "13,5,7");
assertEq(Array.join(Array.sort(arrLike, f), ","), "13,7,5");
// Array.push.
reset();
assertThrowsInstanceOf(() => Array.push(), TypeError);
assertEq(Array.push(arr), 3);
assertEq(Array.join(arr), "5,7,13");
assertEq(Array.push(arr, 17), 4);
assertEq(Array.join(arr), "5,7,13,17");
assertEq(Array.push(arr, 19, 21), 6);
assertEq(Array.join(arr), "5,7,13,17,19,21");
assertEq(Array.push(arrLike), 3);
assertEq(Array.join(arrLike), "5,7,13");
assertEq(Array.push(arrLike, 17), 4);
assertEq(Array.join(arrLike), "5,7,13,17");
assertEq(Array.push(arrLike, 19, 21), 6);
assertEq(Array.join(arrLike), "5,7,13,17,19,21");
// Array.pop.
reset();
assertThrowsInstanceOf(() => Array.pop(), TypeError);
assertEq(Array.pop(arr), 13);
assertEq(Array.join(arr), "5,7");
assertEq(Array.pop(arr), 7);
assertEq(Array.join(arr), "5");
assertEq(Array.pop(arrLike), 13);
assertEq(Array.join(arrLike), "5,7");
assertEq(Array.pop(arrLike), 7);
assertEq(Array.join(arrLike), "5");
// Array.shift.
reset();
assertThrowsInstanceOf(() => Array.shift(), TypeError);
assertEq(Array.shift(arr), 5);
assertEq(Array.join(arr), "7,13");
assertEq(Array.shift(arr), 7);
assertEq(Array.join(arr), "13");
assertEq(Array.shift(arrLike), 5);
assertEq(Array.join(arrLike), "7,13");
assertEq(Array.shift(arrLike), 7);
assertEq(Array.join(arrLike), "13");
// Array.unshift.
reset();
assertThrowsInstanceOf(() => Array.unshift(), TypeError);
assertEq(Array.unshift(arr), 3);
assertEq(Array.join(arr), "5,7,13");
assertEq(Array.unshift(arr, 17), 4);
assertEq(Array.join(arr), "17,5,7,13");
assertEq(Array.unshift(arr, 19, 21), 6);
assertEq(Array.join(arr), "19,21,17,5,7,13");
assertEq(Array.unshift(arrLike), 3);
assertEq(Array.join(arrLike), "5,7,13");
assertEq(Array.unshift(arrLike, 17), 4);
assertEq(Array.join(arrLike), "17,5,7,13");
assertEq(Array.unshift(arrLike, 19, 21), 6);
assertEq(Array.join(arrLike), "19,21,17,5,7,13");
// Array.splice.
reset();
assertThrowsInstanceOf(() => Array.splice(), TypeError);
assertEq(Array.join(Array.splice(arr)), "");
assertEq(Array.join(arr), "5,7,13");
assertEq(Array.join(Array.splice(arr, 1)), "7,13");
assertEq(Array.join(arr), "5");
reset();
assertEq(Array.join(Array.splice(arr, 1, 1)), "7");
assertEq(Array.join(arr), "5,13");
reset();
assertEq(Array.join(Array.splice(arrLike)), "");
assertEq(Array.join(arrLike), "5,7,13");
assertEq(Array.join(Array.splice(arrLike, 1)), "7,13");
assertEq(Array.join(arrLike), "5");
reset();
assertEq(Array.join(Array.splice(arrLike, 1, 1)), "7");
assertEq(Array.join(arrLike), "5,13");
// Array.slice.
reset();
assertThrowsInstanceOf(() => Array.slice(), TypeError);
assertEq(Array.join(Array.slice(arr)), "5,7,13");
assertEq(Array.join(Array.slice(arr, 1)), "7,13");
assertEq(Array.join(Array.slice(arr, 1, 1)), "");
assertEq(Array.join(Array.slice(arr, 1, 2)), "7");
assertEq(Array.join(Array.slice(arrLike)), "5,7,13");
assertEq(Array.join(Array.slice(arrLike, 1)), "7,13");
assertEq(Array.join(Array.slice(arrLike, 1, 1)), "");
assertEq(Array.join(Array.slice(arrLike, 1, 2)), "7");
if (typeof reportCompare === "function")
reportCompare(true, true);

Просмотреть файл

@ -1,228 +0,0 @@
var BUGNUMBER = 1263558;
var summary = "Self-host all String generics.";
print(BUGNUMBER + ": " + summary);
var result;
var str = "ABCde";
var strObj = {
toString() {
return "ABCde";
}
};
// String.substring.
assertThrowsInstanceOf(() => String.substring(), TypeError);
assertEq(String.substring(str), "ABCde");
assertEq(String.substring(str, 1), "BCde");
assertEq(String.substring(str, 1, 3), "BC");
assertEq(String.substring(strObj), "ABCde");
assertEq(String.substring(strObj, 1), "BCde");
assertEq(String.substring(strObj, 1, 3), "BC");
// String.substr.
assertThrowsInstanceOf(() => String.substr(), TypeError);
assertEq(String.substr(str), "ABCde");
assertEq(String.substr(str, 1), "BCde");
assertEq(String.substr(str, 1, 3), "BCd");
assertEq(String.substr(strObj), "ABCde");
assertEq(String.substr(strObj, 1), "BCde");
assertEq(String.substr(strObj, 1, 3), "BCd");
// String.slice.
assertThrowsInstanceOf(() => String.slice(), TypeError);
assertEq(String.slice(str), "ABCde");
assertEq(String.slice(str, 1), "BCde");
assertEq(String.slice(str, 1, 3), "BC");
assertEq(String.slice(strObj), "ABCde");
assertEq(String.slice(strObj, 1), "BCde");
assertEq(String.slice(strObj, 1, 3), "BC");
// String.match.
assertThrowsInstanceOf(() => String.match(), TypeError);
result = String.match(str);
assertEq(result.index, 0);
assertEq(result.length, 1);
assertEq(result[0], "");
result = String.match(str, /c/i);
assertEq(result.index, 2);
assertEq(result.length, 1);
assertEq(result[0], "C");
result = String.match(strObj);
assertEq(result.index, 0);
assertEq(result.length, 1);
assertEq(result[0], "");
result = String.match(strObj, /c/i);
assertEq(result.index, 2);
assertEq(result.length, 1);
assertEq(result[0], "C");
// String.replace.
assertThrowsInstanceOf(() => String.replace(), TypeError);
assertEq(String.replace(str), "ABCde");
assertEq(String.replace(str, /c/i), "ABundefinedde");
assertEq(String.replace(str, /c/i, "x"), "ABxde");
assertEq(String.replace(strObj), "ABCde");
assertEq(String.replace(strObj, /c/i), "ABundefinedde");
assertEq(String.replace(strObj, /c/i, "x"), "ABxde");
// String.search.
assertThrowsInstanceOf(() => String.search(), TypeError);
assertEq(String.search(str), 0);
assertEq(String.search(str, /c/i), 2);
assertEq(String.search(strObj), 0);
assertEq(String.search(strObj, /c/i), 2);
// String.split.
assertThrowsInstanceOf(() => String.split(), TypeError);
assertEq(String.split(str).join(","), "ABCde");
assertEq(String.split(str, /[bd]/i).join(","), "A,C,e");
assertEq(String.split(str, /[bd]/i, 2).join(","), "A,C");
assertEq(String.split(strObj).join(","), "ABCde");
assertEq(String.split(strObj, /[bd]/i).join(","), "A,C,e");
assertEq(String.split(strObj, /[bd]/i, 2).join(","), "A,C");
// String.toLowerCase.
assertThrowsInstanceOf(() => String.toLowerCase(), TypeError);
assertEq(String.toLowerCase(str), "abcde");
assertEq(String.toLowerCase(strObj), "abcde");
// String.toUpperCase.
assertThrowsInstanceOf(() => String.toUpperCase(), TypeError);
assertEq(String.toUpperCase(str), "ABCDE");
assertEq(String.toUpperCase(strObj), "ABCDE");
// String.charAt.
assertThrowsInstanceOf(() => String.charAt(), TypeError);
assertEq(String.charAt(str), "A");
assertEq(String.charAt(str, 2), "C");
assertEq(String.charAt(strObj), "A");
assertEq(String.charAt(strObj, 2), "C");
// String.charCodeAt.
assertThrowsInstanceOf(() => String.charCodeAt(), TypeError);
assertEq(String.charCodeAt(str), 65);
assertEq(String.charCodeAt(str, 2), 67);
assertEq(String.charCodeAt(strObj), 65);
assertEq(String.charCodeAt(strObj, 2), 67);
// String.includes.
assertThrowsInstanceOf(() => String.includes(), TypeError);
assertEq(String.includes(str), false);
assertEq(String.includes(str, "C"), true);
assertEq(String.includes(str, "C", 2), true);
assertEq(String.includes(str, "C", 3), false);
assertEq(String.includes(strObj), false);
assertEq(String.includes(strObj, "C"), true);
assertEq(String.includes(strObj, "C", 2), true);
assertEq(String.includes(strObj, "C", 3), false);
// String.indexOf.
assertThrowsInstanceOf(() => String.indexOf(), TypeError);
assertEq(String.indexOf(str), -1);
assertEq(String.indexOf(str, "C"), 2);
assertEq(String.indexOf(str, "C", 2), 2);
assertEq(String.indexOf(str, "C", 3), -1);
assertEq(String.indexOf(strObj), -1);
assertEq(String.indexOf(strObj, "C"), 2);
assertEq(String.indexOf(strObj, "C", 2), 2);
assertEq(String.indexOf(strObj, "C", 3), -1);
// String.lastIndexOf.
assertThrowsInstanceOf(() => String.lastIndexOf(), TypeError);
assertEq(String.lastIndexOf(str), -1);
assertEq(String.lastIndexOf(str, "C"), 2);
assertEq(String.lastIndexOf(str, "C", 2), 2);
assertEq(String.lastIndexOf(str, "C", 1), -1);
assertEq(String.lastIndexOf(strObj), -1);
assertEq(String.lastIndexOf(strObj, "C"), 2);
assertEq(String.lastIndexOf(strObj, "C", 2), 2);
assertEq(String.lastIndexOf(strObj, "C", 1), -1);
// String.startsWith.
assertThrowsInstanceOf(() => String.startsWith(), TypeError);
assertEq(String.startsWith(str), false);
assertEq(String.startsWith(str, "A"), true);
assertEq(String.startsWith(str, "B", 0), false);
assertEq(String.startsWith(str, "B", 1), true);
assertEq(String.startsWith(strObj), false);
assertEq(String.startsWith(strObj, "A"), true);
assertEq(String.startsWith(strObj, "B", 0), false);
assertEq(String.startsWith(strObj, "B", 1), true);
// String.endsWith.
assertThrowsInstanceOf(() => String.endsWith(), TypeError);
assertEq(String.endsWith(str), false);
assertEq(String.endsWith(str, "e"), true);
assertEq(String.endsWith(str, "B", 0), false);
assertEq(String.endsWith(str, "B", 2), true);
assertEq(String.endsWith(strObj), false);
assertEq(String.endsWith(strObj, "e"), true);
assertEq(String.endsWith(strObj, "B", 0), false);
assertEq(String.endsWith(strObj, "B", 2), true);
// String.trim.
var str2 = " ABCde ";
var strObj2 = {
toString() {
return " ABCde ";
}
};
assertThrowsInstanceOf(() => String.trim(), TypeError);
assertEq(String.trim(str2), "ABCde");
assertEq(String.trim(strObj2), "ABCde");
// String.trimLeft.
assertThrowsInstanceOf(() => String.trimLeft(), TypeError);
assertEq(String.trimLeft(str2), "ABCde ");
assertEq(String.trimLeft(strObj2), "ABCde ");
// String.trimRight.
assertThrowsInstanceOf(() => String.trimRight(), TypeError);
assertEq(String.trimRight(str2), " ABCde");
assertEq(String.trimRight(strObj2), " ABCde");
// String.toLocaleLowerCase.
assertThrowsInstanceOf(() => String.toLocaleLowerCase(), TypeError);
assertEq(String.toLocaleLowerCase(str), str.toLocaleLowerCase());
assertEq(String.toLocaleLowerCase(strObj), str.toLocaleLowerCase());
// String.toLocaleUpperCase.
assertThrowsInstanceOf(() => String.toLocaleUpperCase(), TypeError);
assertEq(String.toLocaleUpperCase(str), str.toLocaleUpperCase());
assertEq(String.toLocaleUpperCase(strObj), str.toLocaleUpperCase());
// String.localeCompare.
assertThrowsInstanceOf(() => String.localeCompare(), TypeError);
assertEq(String.localeCompare(str), str.localeCompare());
assertEq(String.localeCompare(str, "abcde"), str.localeCompare("abcde"));
assertEq(String.localeCompare(strObj), str.localeCompare());
assertEq(String.localeCompare(strObj, "abcde"), str.localeCompare("abcde"));
// String.normalize.
if ("normalize" in String.prototype) {
var str3 = "\u3082\u3058\u3089 \u3082\u3057\u3099\u3089";
var strObj3 = {
toString() {
return "\u3082\u3058\u3089 \u3082\u3057\u3099\u3089";
}
};
assertThrowsInstanceOf(() => String.normalize(), TypeError);
assertEq(String.normalize(str3), "\u3082\u3058\u3089 \u3082\u3058\u3089");
assertEq(String.normalize(str3, "NFD"), "\u3082\u3057\u3099\u3089 \u3082\u3057\u3099\u3089");
assertEq(String.normalize(strObj3), "\u3082\u3058\u3089 \u3082\u3058\u3089");
assertEq(String.normalize(strObj3, "NFD"), "\u3082\u3057\u3099\u3089 \u3082\u3057\u3099\u3089");
}
// String.concat.
assertThrowsInstanceOf(() => String.concat(), TypeError);
assertEq(String.concat(str), "ABCde");
assertEq(String.concat(str, "f"), "ABCdef");
assertEq(String.concat(str, "f", "g"), "ABCdefg");
assertEq(String.concat(strObj), "ABCde");
assertEq(String.concat(strObj, "f"), "ABCdef");
assertEq(String.concat(strObj, "f", "g"), "ABCdefg");
if (typeof reportCompare === "function")
reportCompare(true, true);

Просмотреть файл

@ -2248,8 +2248,6 @@ static const JSFunctionSpec intrinsic_functions[] = {
JS_FN("std_Array_unshift", array_unshift, 1,0),
JS_INLINABLE_FN("std_Array_slice", array_slice, 2,0, ArraySlice),
JS_FN("std_Array_sort", array_sort, 1,0),
JS_FN("std_Array_reverse", array_reverse, 0,0),
JS_INLINABLE_FN("std_Array_splice", array_splice, 2,0, ArraySplice),
JS_FN("std_Date_now", date_now, 0,0),
JS_FN("std_Date_valueOf", date_valueOf, 0,0),
@ -2292,21 +2290,6 @@ static const JSFunctionSpec intrinsic_functions[] = {
JS_FN("std_String_toLowerCase", str_toLowerCase, 0,0),
JS_FN("std_String_toUpperCase", str_toUpperCase, 0,0),
JS_INLINABLE_FN("std_String_charAt", str_charAt, 1,0, StringCharAt),
JS_FN("std_String_endsWith", str_endsWith, 1,0),
JS_FN("std_String_trim", str_trim, 0,0),
JS_FN("std_String_trimLeft", str_trimLeft, 0,0),
JS_FN("std_String_trimRight", str_trimRight, 0,0),
JS_FN("std_String_toLocaleLowerCase", str_toLocaleLowerCase, 0,0),
JS_FN("std_String_toLocaleUpperCase", str_toLocaleUpperCase, 0,0),
#if !EXPOSE_INTL_API
JS_FN("std_String_localeCompare", str_localeCompare, 1,0),
#else
JS_FN("std_String_normalize", str_normalize, 0,0),
#endif
JS_FN("std_String_concat", str_concat, 1,0),
JS_FN("std_WeakMap_has", WeakMap_has, 1,0),
JS_FN("std_WeakMap_get", WeakMap_get, 2,0),
JS_FN("std_WeakMap_set", WeakMap_set, 2,0),

Просмотреть файл

@ -539,7 +539,13 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=933681
// low value.
let propsToSkip = ['length', Symbol.unscopables];
testXray('Array', new iwin.Array(20), new iwin.Array(), propsToSkip);
// On the constructor, we want to skip all the non-standard "generic"
// functions. We're trying to remove them anyway; no point doing extra work
// to expose them over Xrays.
let ctorPropsToSkip = ["join", "reverse", "sort", "push", "pop", "shift",
"unshift", "splice", "slice"];
testXray('Array', new iwin.Array(20), new iwin.Array(), propsToSkip,
ctorPropsToSkip);
let symbolProps = '';
uniqueSymbol = iwin.eval('var uniqueSymbol = Symbol("uniqueSymbol"); uniqueSymbol');