зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1102219 - Part 1: Add `String.prototype.includes`; keep `String.prototype.contains` around as an alias with a (non-release builds only) warning. r=till
This commit is contained in:
Родитель
178a2e3c00
Коммит
df121464f3
|
@ -124,6 +124,7 @@ MSG_DEF(JSMSG_INVALID_NORMALIZE_FORM, 0, JSEXN_RANGEERR, "form must be one of '
|
|||
MSG_DEF(JSMSG_NEGATIVE_REPETITION_COUNT, 0, JSEXN_RANGEERR, "repeat count must be non-negative")
|
||||
MSG_DEF(JSMSG_NOT_A_CODEPOINT, 1, JSEXN_RANGEERR, "{0} is not a valid code point")
|
||||
MSG_DEF(JSMSG_RESULTING_STRING_TOO_LARGE, 0, JSEXN_RANGEERR, "repeat count must be less than infinity and not overflow maximum string size")
|
||||
MSG_DEF(JSMSG_DEPRECATED_STRING_CONTAINS, 0, JSEXN_NONE, "String.prototype.contains() is deprecated and will be removed in a future release; use String.prototype.includes() instead")
|
||||
|
||||
// Number
|
||||
MSG_DEF(JSMSG_BAD_RADIX, 0, JSEXN_RANGEERR, "radix must be an integer at least 2 and no greater than 36")
|
||||
|
|
|
@ -1517,9 +1517,9 @@ RopeMatch(JSContext* cx, JSRope* text, JSLinearString* pat, int* match)
|
|||
return true;
|
||||
}
|
||||
|
||||
/* ES6 draft rc3 21.1.3.7. */
|
||||
/* ES6 draft rc4 21.1.3.7. */
|
||||
static bool
|
||||
str_contains(JSContext* cx, unsigned argc, Value* vp)
|
||||
str_includes(JSContext* cx, unsigned argc, Value* vp)
|
||||
{
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
|
||||
|
@ -1574,6 +1574,19 @@ str_contains(JSContext* cx, unsigned argc, Value* vp)
|
|||
return true;
|
||||
}
|
||||
|
||||
/* TODO: remove String.prototype.contains (bug 1103588) */
|
||||
static bool
|
||||
str_contains(JSContext *cx, unsigned argc, Value *vp)
|
||||
{
|
||||
#ifndef RELEASE_BUILD
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
RootedObject callee(cx, &args.callee());
|
||||
if (!GlobalObject::warnOnceAboutStringContains(cx, callee))
|
||||
return false;
|
||||
#endif
|
||||
return str_includes(cx, argc, vp);
|
||||
}
|
||||
|
||||
/* ES6 20120927 draft 15.5.4.7. */
|
||||
bool
|
||||
js::str_indexOf(JSContext* cx, unsigned argc, Value* vp)
|
||||
|
@ -3985,6 +3998,7 @@ static const JSFunctionSpec string_methods[] = {
|
|||
JS_FN("charCodeAt", str_charCodeAt, 1,JSFUN_GENERIC_NATIVE),
|
||||
JS_SELF_HOSTED_FN("substring", "String_substring", 2,0),
|
||||
JS_SELF_HOSTED_FN("codePointAt", "String_codePointAt", 1,0),
|
||||
JS_FN("includes", str_includes, 1,JSFUN_GENERIC_NATIVE),
|
||||
JS_FN("contains", str_contains, 1,JSFUN_GENERIC_NATIVE),
|
||||
JS_FN("indexOf", str_indexOf, 1,JSFUN_GENERIC_NATIVE),
|
||||
JS_FN("lastIndexOf", str_lastIndexOf, 1,JSFUN_GENERIC_NATIVE),
|
||||
|
|
|
@ -121,7 +121,8 @@ class GlobalObject : public NativeObject
|
|||
|
||||
enum WarnOnceFlag : int32_t {
|
||||
WARN_WATCH_DEPRECATED = 0x00000001,
|
||||
WARN_PROTO_SETTING_SLOW = 0x00000002
|
||||
WARN_PROTO_SETTING_SLOW = 0x00000002,
|
||||
WARN_STRING_CONTAINS_DEPRECATED = 0x00000004
|
||||
};
|
||||
|
||||
// Emit the specified warning if the given slot in |obj|'s global isn't
|
||||
|
@ -658,6 +659,12 @@ class GlobalObject : public NativeObject
|
|||
return warnOnceAbout(cx, protoSetter, WARN_PROTO_SETTING_SLOW, JSMSG_PROTO_SETTING_SLOW);
|
||||
}
|
||||
|
||||
// Warn about use of the deprecated String.prototype.contains method
|
||||
static bool warnOnceAboutStringContains(JSContext *cx, HandleObject strContains) {
|
||||
return warnOnceAbout(cx, strContains, WARN_STRING_CONTAINS_DEPRECATED,
|
||||
JSMSG_DEPRECATED_STRING_CONTAINS);
|
||||
}
|
||||
|
||||
static bool getOrCreateEval(JSContext* cx, Handle<GlobalObject*> global,
|
||||
MutableHandleObject eval);
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ static const uint32_t XDR_BYTECODE_VERSION_SUBTRAHEND = 281;
|
|||
static const uint32_t XDR_BYTECODE_VERSION =
|
||||
uint32_t(0xb973c0de - XDR_BYTECODE_VERSION_SUBTRAHEND);
|
||||
|
||||
static_assert(JSErr_Limit == 392,
|
||||
static_assert(JSErr_Limit == 393,
|
||||
"GREETINGS, POTENTIAL SUBTRAHEND INCREMENTER! If you added or "
|
||||
"removed MSG_DEFs from js.msg, you should increment "
|
||||
"XDR_BYTECODE_VERSION_SUBTRAHEND and update this assertion's "
|
||||
|
|
Загрузка…
Ссылка в новой задаче