Bug 1584431 part 4. Use the new length-aware versions of JS_StringEqualsAscii and JS_FlatStringEqualsAscii where possible. r=jwalden

Differential Revision: https://phabricator.services.mozilla.com/D47393

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Boris Zbarsky 2019-09-27 21:25:23 +00:00
Родитель 1a163ad533
Коммит 44c015a4b0
16 изменённых файлов: 77 добавлений и 86 удалений

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

@ -2172,11 +2172,6 @@ class MOZ_STACK_CLASS NullableRootedUnion : public Nullable<T>,
}
};
inline bool IdEquals(jsid id, const char* string) {
return JSID_IS_STRING(id) &&
JS_FlatStringEqualsAscii(JSID_TO_FLAT_STRING(id), string);
}
inline bool AddStringToIDVector(JSContext* cx,
JS::MutableHandleVector<jsid> vector,
const char* name) {

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

@ -14395,10 +14395,8 @@ class CGGlobalNames(CGGeneric):
getter = phfCodegen.gen_jsflatstr_getter(
name='WebIDLGlobalNameHash::GetEntry',
return_type='const WebIDLNameTableEntry*',
# XXX(nika): It would be nice to have a length overload for
# JS_FlatStringEqualsAscii.
return_entry=dedent("""
if (JS_FlatStringEqualsAscii(aKey, sNames + entry.mNameOffset)) {
if (JS_FlatStringEqualsAscii(aKey, sNames + entry.mNameOffset, entry.mNameLength)) {
return &entry;
}
return nullptr;

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

@ -459,7 +459,7 @@ static bool GC(JSContext* cx, unsigned argc, Value* vp) {
if (args.length() >= 1) {
Value arg = args[0];
if (arg.isString()) {
if (!JS_StringEqualsAscii(cx, arg.toString(), "zone", &zone)) {
if (!JS_StringEqualsLiteral(cx, arg.toString(), "zone", &zone)) {
return false;
}
} else if (arg.isObject()) {
@ -472,7 +472,8 @@ static bool GC(JSContext* cx, unsigned argc, Value* vp) {
if (args.length() >= 2) {
Value arg = args[1];
if (arg.isString()) {
if (!JS_StringEqualsAscii(cx, arg.toString(), "shrinking", &shrinking)) {
if (!JS_StringEqualsLiteral(cx, arg.toString(), "shrinking",
&shrinking)) {
return false;
}
}
@ -915,10 +916,10 @@ static bool ConvertToTier(JSContext* cx, HandleValue value,
bool baselineTier = false;
bool ionTier = false;
if (!JS_StringEqualsAscii(cx, option, "stable", &stableTier) ||
!JS_StringEqualsAscii(cx, option, "best", &bestTier) ||
!JS_StringEqualsAscii(cx, option, "baseline", &baselineTier) ||
!JS_StringEqualsAscii(cx, option, "ion", &ionTier)) {
if (!JS_StringEqualsLiteral(cx, option, "stable", &stableTier) ||
!JS_StringEqualsLiteral(cx, option, "best", &bestTier) ||
!JS_StringEqualsLiteral(cx, option, "baseline", &baselineTier) ||
!JS_StringEqualsLiteral(cx, option, "ion", &ionTier)) {
return false;
}
@ -1108,7 +1109,8 @@ static bool InternalConst(JSContext* cx, unsigned argc, Value* vp) {
return false;
}
if (JS_FlatStringEqualsAscii(flat, "INCREMENTAL_MARK_STACK_BASE_CAPACITY")) {
if (JS_FlatStringEqualsLiteral(flat,
"INCREMENTAL_MARK_STACK_BASE_CAPACITY")) {
args.rval().setNumber(uint32_t(js::INCREMENTAL_MARK_STACK_BASE_CAPACITY));
} else {
JS_ReportErrorASCII(cx, "unknown const name");
@ -1451,7 +1453,8 @@ static bool StartGC(JSContext* cx, unsigned argc, Value* vp) {
if (args.length() >= 2) {
Value arg = args[1];
if (arg.isString()) {
if (!JS_StringEqualsAscii(cx, arg.toString(), "shrinking", &shrinking)) {
if (!JS_StringEqualsLiteral(cx, arg.toString(), "shrinking",
&shrinking)) {
return false;
}
}
@ -5804,11 +5807,11 @@ static bool MonitorType(JSContext* cx, unsigned argc, Value* vp) {
bool unknown = false;
bool unknownObject = false;
if (val.isString()) {
if (!JS_StringEqualsAscii(cx, val.toString(), "unknown", &unknown)) {
if (!JS_StringEqualsLiteral(cx, val.toString(), "unknown", &unknown)) {
return false;
}
if (!JS_StringEqualsAscii(cx, val.toString(), "unknownObject",
&unknownObject)) {
if (!JS_StringEqualsLiteral(cx, val.toString(), "unknownObject",
&unknownObject)) {
return false;
}
}

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

@ -43,7 +43,7 @@ Here is a sample test:
EVAL("'42';", &v);
JSString *str = v.toString();
CHECK(JS_StringHasBeenInterned(cx, str));
CHECK(JS_FlatStringEqualsAscii(JS_ASSERT_STRING_IS_FLAT(str), "42"));
CHECK(JS_FlatStringEqualsLiteral(JS_ASSERT_STRING_IS_FLAT(str), "42"));
return true;
}
END_TEST(testIntString_bug515273)

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

@ -87,7 +87,7 @@ BEGIN_TEST(testGCRootedStaticStructInternalStackStorageAugmented) {
obj = heap.obj();
CHECK(JS_GetProperty(cx, obj, "foo", &val));
actual = val.toString();
CHECK(JS_StringEqualsAscii(cx, actual, "Hello", &same));
CHECK(JS_StringEqualsLiteral(cx, actual, "Hello", &same));
CHECK(same);
obj = nullptr;
actual = nullptr;
@ -98,7 +98,7 @@ BEGIN_TEST(testGCRootedStaticStructInternalStackStorageAugmented) {
obj = heap.obj();
CHECK(JS_GetProperty(cx, obj, "foo", &val));
actual = val.toString();
CHECK(JS_StringEqualsAscii(cx, actual, "Hello", &same));
CHECK(JS_StringEqualsLiteral(cx, actual, "Hello", &same));
CHECK(same);
obj = nullptr;
actual = nullptr;
@ -268,12 +268,10 @@ BEGIN_TEST(testGCRootedVector) {
for (size_t i = 0; i < 10; ++i) {
// Check the shape to ensure it did not get collected.
char buffer[2];
buffer[0] = 'a' + i;
buffer[1] = '\0';
char letter = 'a' + i;
bool match;
CHECK(JS_StringEqualsAscii(cx, JSID_TO_STRING(shapes[i]->propid()), buffer,
&match));
CHECK(JS_StringEqualsAscii(cx, JSID_TO_STRING(shapes[i]->propid()), &letter,
1, &match));
CHECK(match);
}
@ -341,12 +339,10 @@ BEGIN_TEST(testTraceableFifo) {
for (size_t i = 0; i < 10; ++i) {
// Check the shape to ensure it did not get collected.
char buffer[2];
buffer[0] = 'a' + i;
buffer[1] = '\0';
char letter = 'a' + i;
bool match;
CHECK(JS_StringEqualsAscii(cx, JSID_TO_STRING(shapes.front()->propid()),
buffer, &match));
&letter, 1, &match));
CHECK(match);
shapes.popFront();
}
@ -388,12 +384,10 @@ static bool FillVector(JSContext* cx, MutableHandle<ShapeVec> shapes) {
static bool CheckVector(JSContext* cx, Handle<ShapeVec> shapes) {
for (size_t i = 0; i < 10; ++i) {
// Check the shape to ensure it did not get collected.
char buffer[2];
buffer[0] = 'a' + i;
buffer[1] = '\0';
char letter = 'a' + i;
bool match;
if (!JS_StringEqualsAscii(cx, JSID_TO_STRING(shapes[i]->propid()), buffer,
&match)) {
if (!JS_StringEqualsAscii(cx, JSID_TO_STRING(shapes[i]->propid()), &letter,
1, &match)) {
return false;
}
if (!match) {

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

@ -35,7 +35,7 @@ BEGIN_TEST(testGCOutOfMemory) {
CHECK(JS_GetPendingException(cx, &root));
CHECK(root.isString());
bool match = false;
CHECK(JS_StringEqualsAscii(cx, root.toString(), "out of memory", &match));
CHECK(JS_StringEqualsLiteral(cx, root.toString(), "out of memory", &match));
CHECK(match);
JS_ClearPendingException(cx);

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

@ -13,28 +13,28 @@ BEGIN_TEST(testIntString_bug515273) {
EVAL("'1';", &v);
JSString* str = v.toString();
CHECK(JS_StringHasBeenPinned(cx, str));
CHECK(JS_FlatStringEqualsAscii(JS_ASSERT_STRING_IS_FLAT(str), "1"));
CHECK(JS_FlatStringEqualsLiteral(JS_ASSERT_STRING_IS_FLAT(str), "1"));
EVAL("'42';", &v);
str = v.toString();
CHECK(JS_StringHasBeenPinned(cx, str));
CHECK(JS_FlatStringEqualsAscii(JS_ASSERT_STRING_IS_FLAT(str), "42"));
CHECK(JS_FlatStringEqualsLiteral(JS_ASSERT_STRING_IS_FLAT(str), "42"));
EVAL("'111';", &v);
str = v.toString();
CHECK(JS_StringHasBeenPinned(cx, str));
CHECK(JS_FlatStringEqualsAscii(JS_ASSERT_STRING_IS_FLAT(str), "111"));
CHECK(JS_FlatStringEqualsLiteral(JS_ASSERT_STRING_IS_FLAT(str), "111"));
/* Test other types of static strings. */
EVAL("'a';", &v);
str = v.toString();
CHECK(JS_StringHasBeenPinned(cx, str));
CHECK(JS_FlatStringEqualsAscii(JS_ASSERT_STRING_IS_FLAT(str), "a"));
CHECK(JS_FlatStringEqualsLiteral(JS_ASSERT_STRING_IS_FLAT(str), "a"));
EVAL("'bc';", &v);
str = v.toString();
CHECK(JS_StringHasBeenPinned(cx, str));
CHECK(JS_FlatStringEqualsAscii(JS_ASSERT_STRING_IS_FLAT(str), "bc"));
CHECK(JS_FlatStringEqualsLiteral(JS_ASSERT_STRING_IS_FLAT(str), "bc"));
return true;
}

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

@ -53,7 +53,7 @@ bool document_resolve(JSContext* cx, JS::HandleObject obj, JS::HandleId id,
if (!flatStr) {
return false;
}
if (JS_FlatStringEqualsAscii(flatStr, "all")) {
if (JS_FlatStringEqualsLiteral(flatStr, "all")) {
JS::Rooted<JSObject*> docAll(cx, JS_NewObject(cx, &DocumentAllClass));
if (!docAll) {
return false;

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

@ -57,7 +57,7 @@ BEGIN_TEST(testGetRegExpSource) {
obj = val.toObjectOrNull();
JSString* source = JS::GetRegExpSource(cx, obj);
CHECK(source);
CHECK(JS_FlatStringEqualsAscii(JS_ASSERT_STRING_IS_FLAT(source), "foopy"));
CHECK(JS_FlatStringEqualsLiteral(JS_ASSERT_STRING_IS_FLAT(source), "foopy"));
return true;
}

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

@ -73,7 +73,7 @@ bool doResolve(JS::HandleObject obj, JS::HandleId id, bool* resolvedp) {
JSFlatString* str = JS_FlattenString(cx, JSID_TO_STRING(id));
CHECK(str);
JS::RootedValue v(cx);
if (JS_FlatStringEqualsAscii(str, "x")) {
if (JS_FlatStringEqualsLiteral(str, "x")) {
if (obj == obj1) {
/* First resolve hook invocation. */
CHECK_EQUAL(resolveEntryCount, 1);
@ -89,7 +89,7 @@ bool doResolve(JS::HandleObject obj, JS::HandleId id, bool* resolvedp) {
*resolvedp = false;
return true;
}
} else if (JS_FlatStringEqualsAscii(str, "y")) {
} else if (JS_FlatStringEqualsLiteral(str, "y")) {
if (obj == obj2) {
CHECK_EQUAL(resolveEntryCount, 2);
CHECK(JS_DefinePropertyById(cx, obj, id, JS::NullHandleValue,

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

@ -19,7 +19,7 @@ class CustomProxyHandler : public Wrapper {
JSContext* cx, HandleObject proxy, HandleId id,
MutableHandle<PropertyDescriptor> desc) const override {
if (JSID_IS_STRING(id) &&
JS_FlatStringEqualsAscii(JSID_TO_FLAT_STRING(id), "phantom")) {
JS_FlatStringEqualsLiteral(JSID_TO_FLAT_STRING(id), "phantom")) {
desc.object().set(proxy);
desc.attributesRef() = JSPROP_ENUMERATE;
desc.value().setInt32(42);

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

@ -293,7 +293,7 @@ static bool ReadFile(JSContext* cx, unsigned argc, Value* vp,
return false;
}
bool match;
if (!JS_StringEqualsAscii(cx, opt, "binary", &match)) {
if (!JS_StringEqualsLiteral(cx, opt, "binary", &match)) {
return false;
}
if (match) {

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

@ -3352,11 +3352,11 @@ struct DisassembleOptionParser {
if (!flatStr) {
return false;
}
if (JS_FlatStringEqualsAscii(flatStr, "-l")) {
if (JS_FlatStringEqualsLiteral(flatStr, "-l")) {
lines = true;
} else if (JS_FlatStringEqualsAscii(flatStr, "-r")) {
} else if (JS_FlatStringEqualsLiteral(flatStr, "-r")) {
recursive = true;
} else if (JS_FlatStringEqualsAscii(flatStr, "-S")) {
} else if (JS_FlatStringEqualsLiteral(flatStr, "-S")) {
sourceNotes = false;
} else {
break;
@ -4536,8 +4536,9 @@ static bool SetJitCompilerOption(JSContext* cx, unsigned argc, Value* vp) {
return false;
}
#define JIT_COMPILER_MATCH(key, string) \
else if (JS_FlatStringEqualsAscii(strArg, string)) opt = JSJITCOMPILER_##key;
#define JIT_COMPILER_MATCH(key, string) \
else if (JS_FlatStringEqualsLiteral(strArg, string)) opt = \
JSJITCOMPILER_##key;
JSJitCompilerOption opt = JSJITCOMPILER_NOT_AN_OPTION;
if (false) {

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

@ -820,64 +820,64 @@ bool xpc::GlobalProperties::Parse(JSContext* cx, JS::HandleObject obj) {
if (!nameStr) {
return false;
}
if (JS_FlatStringEqualsAscii(nameStr, "Blob")) {
if (JS_FlatStringEqualsLiteral(nameStr, "Blob")) {
Blob = true;
} else if (JS_FlatStringEqualsAscii(nameStr, "ChromeUtils")) {
} else if (JS_FlatStringEqualsLiteral(nameStr, "ChromeUtils")) {
ChromeUtils = true;
} else if (JS_FlatStringEqualsAscii(nameStr, "CSS")) {
} else if (JS_FlatStringEqualsLiteral(nameStr, "CSS")) {
CSS = true;
} else if (JS_FlatStringEqualsAscii(nameStr, "CSSRule")) {
} else if (JS_FlatStringEqualsLiteral(nameStr, "CSSRule")) {
CSSRule = true;
} else if (JS_FlatStringEqualsAscii(nameStr, "Directory")) {
} else if (JS_FlatStringEqualsLiteral(nameStr, "Directory")) {
Directory = true;
} else if (JS_FlatStringEqualsAscii(nameStr, "DOMParser")) {
} else if (JS_FlatStringEqualsLiteral(nameStr, "DOMParser")) {
DOMParser = true;
} else if (JS_FlatStringEqualsAscii(nameStr, "Element")) {
} else if (JS_FlatStringEqualsLiteral(nameStr, "Element")) {
Element = true;
} else if (JS_FlatStringEqualsAscii(nameStr, "Event")) {
} else if (JS_FlatStringEqualsLiteral(nameStr, "Event")) {
Event = true;
} else if (JS_FlatStringEqualsAscii(nameStr, "File")) {
} else if (JS_FlatStringEqualsLiteral(nameStr, "File")) {
File = true;
} else if (JS_FlatStringEqualsAscii(nameStr, "FileReader")) {
} else if (JS_FlatStringEqualsLiteral(nameStr, "FileReader")) {
FileReader = true;
} else if (JS_FlatStringEqualsAscii(nameStr, "FormData")) {
} else if (JS_FlatStringEqualsLiteral(nameStr, "FormData")) {
FormData = true;
} else if (JS_FlatStringEqualsAscii(nameStr, "InspectorUtils")) {
} else if (JS_FlatStringEqualsLiteral(nameStr, "InspectorUtils")) {
InspectorUtils = true;
} else if (JS_FlatStringEqualsAscii(nameStr, "MessageChannel")) {
} else if (JS_FlatStringEqualsLiteral(nameStr, "MessageChannel")) {
MessageChannel = true;
} else if (JS_FlatStringEqualsAscii(nameStr, "Node")) {
} else if (JS_FlatStringEqualsLiteral(nameStr, "Node")) {
Node = true;
} else if (JS_FlatStringEqualsAscii(nameStr, "NodeFilter")) {
} else if (JS_FlatStringEqualsLiteral(nameStr, "NodeFilter")) {
NodeFilter = true;
} else if (JS_FlatStringEqualsAscii(nameStr, "PromiseDebugging")) {
} else if (JS_FlatStringEqualsLiteral(nameStr, "PromiseDebugging")) {
PromiseDebugging = true;
} else if (JS_FlatStringEqualsAscii(nameStr, "TextDecoder")) {
} else if (JS_FlatStringEqualsLiteral(nameStr, "TextDecoder")) {
TextDecoder = true;
} else if (JS_FlatStringEqualsAscii(nameStr, "TextEncoder")) {
} else if (JS_FlatStringEqualsLiteral(nameStr, "TextEncoder")) {
TextEncoder = true;
} else if (JS_FlatStringEqualsAscii(nameStr, "URL")) {
} else if (JS_FlatStringEqualsLiteral(nameStr, "URL")) {
URL = true;
} else if (JS_FlatStringEqualsAscii(nameStr, "URLSearchParams")) {
} else if (JS_FlatStringEqualsLiteral(nameStr, "URLSearchParams")) {
URLSearchParams = true;
} else if (JS_FlatStringEqualsAscii(nameStr, "XMLHttpRequest")) {
} else if (JS_FlatStringEqualsLiteral(nameStr, "XMLHttpRequest")) {
XMLHttpRequest = true;
} else if (JS_FlatStringEqualsAscii(nameStr, "XMLSerializer")) {
} else if (JS_FlatStringEqualsLiteral(nameStr, "XMLSerializer")) {
XMLSerializer = true;
} else if (JS_FlatStringEqualsAscii(nameStr, "atob")) {
} else if (JS_FlatStringEqualsLiteral(nameStr, "atob")) {
atob = true;
} else if (JS_FlatStringEqualsAscii(nameStr, "btoa")) {
} else if (JS_FlatStringEqualsLiteral(nameStr, "btoa")) {
btoa = true;
} else if (JS_FlatStringEqualsAscii(nameStr, "caches")) {
} else if (JS_FlatStringEqualsLiteral(nameStr, "caches")) {
caches = true;
} else if (JS_FlatStringEqualsAscii(nameStr, "crypto")) {
} else if (JS_FlatStringEqualsLiteral(nameStr, "crypto")) {
crypto = true;
} else if (JS_FlatStringEqualsAscii(nameStr, "fetch")) {
} else if (JS_FlatStringEqualsLiteral(nameStr, "fetch")) {
fetch = true;
} else if (JS_FlatStringEqualsAscii(nameStr, "indexedDB")) {
} else if (JS_FlatStringEqualsLiteral(nameStr, "indexedDB")) {
indexedDB = true;
#ifdef MOZ_WEBRTC
} else if (JS_FlatStringEqualsAscii(nameStr, "rtcIdentityProvider")) {
} else if (JS_FlatStringEqualsLiteral(nameStr, "rtcIdentityProvider")) {
rtcIdentityProvider = true;
#endif
} else {

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

@ -114,7 +114,7 @@ AsyncStatementJSHelper::Resolve(nsIXPConnectWrappedNative* aWrapper,
}
#endif
if (::JS_FlatStringEqualsAscii(JSID_TO_FLAT_STRING(id), "params")) {
if (::JS_FlatStringEqualsLiteral(JSID_TO_FLAT_STRING(id), "params")) {
JS::RootedValue val(aCtx);
nsresult rv = getParams(stmt, aCtx, scope, val.address());
NS_ENSURE_SUCCESS(rv, rv);

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

@ -207,7 +207,7 @@ StatementJSHelper::Resolve(nsIXPConnectWrappedNative* aWrapper, JSContext* aCtx,
static_cast<mozIStorageStatement*>(aWrapper->Native()));
JSFlatString* str = JSID_TO_FLAT_STRING(id);
if (::JS_FlatStringEqualsAscii(str, "step")) {
if (::JS_FlatStringEqualsLiteral(str, "step")) {
*_retval = ::JS_DefineFunction(aCtx, scope, "step", stepFunc, 0,
JSPROP_RESOLVING) != nullptr;
*aResolvedp = true;
@ -216,7 +216,7 @@ StatementJSHelper::Resolve(nsIXPConnectWrappedNative* aWrapper, JSContext* aCtx,
JS::RootedValue val(aCtx);
if (::JS_FlatStringEqualsAscii(str, "row")) {
if (::JS_FlatStringEqualsLiteral(str, "row")) {
nsresult rv = getRow(stmt, aCtx, scope, val.address());
NS_ENSURE_SUCCESS(rv, rv);
*_retval = ::JS_DefinePropertyById(aCtx, scope, id, val, JSPROP_RESOLVING);
@ -224,7 +224,7 @@ StatementJSHelper::Resolve(nsIXPConnectWrappedNative* aWrapper, JSContext* aCtx,
return NS_OK;
}
if (::JS_FlatStringEqualsAscii(str, "params")) {
if (::JS_FlatStringEqualsLiteral(str, "params")) {
nsresult rv = getParams(stmt, aCtx, scope, val.address());
NS_ENSURE_SUCCESS(rv, rv);
*_retval = ::JS_DefinePropertyById(aCtx, scope, id, val, JSPROP_RESOLVING);