Reinstate string.prototype.contains()

This adds a compatibility function aliased to string.prototype.includes().
This commit is contained in:
wolfbeast 2018-06-07 13:21:06 +02:00 committed by Roy Tam
commit 591dc9ea93

View file

@ -1534,7 +1534,7 @@ RopeMatch(JSContext* cx, JSRope* text, JSLinearString* pat, int* match)
return true;
}
/* ES6 draft rc4 21.1.3.7. */
/* ES6 2015 ST 21.1.3.7 String.prototype.includes */
bool
js::str_includes(JSContext* cx, unsigned argc, Value* vp)
{
@ -1591,6 +1591,13 @@ js::str_includes(JSContext* cx, unsigned argc, Value* vp)
return true;
}
/* ES6 draft <RC4 String.prototype.contains for compatibility */
bool
js::str_contains(JSContext* cx, unsigned argc, Value* vp)
{
return js::str_includes(cx, argc, vp);
}
/* ES6 20120927 draft 15.5.4.7. */
bool
js::str_indexOf(JSContext* cx, unsigned argc, Value* vp)
@ -2555,6 +2562,7 @@ static const JSFunctionSpec string_methods[] = {
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("contains", str_contains, 1,0),
JS_FN("indexOf", str_indexOf, 1,0),
JS_FN("lastIndexOf", str_lastIndexOf, 1,0),
JS_FN("startsWith", str_startsWith, 1,0),