Skip to content

Commit

Permalink
Bug 1648646 followup - address review comments, fix handling of unspe…
Browse files Browse the repository at this point in the history
…cified maxNumPaths option

Differential Revision: https://phabricator.services.mozilla.com/D85893
  • Loading branch information
hotsphink committed Aug 4, 2020
1 parent 68c2e9d commit 90823f0
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions js/src/builtin/TestingFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4228,11 +4228,16 @@ static bool ShortestPaths(JSContext* cx, unsigned argc, Value* vp) {
}

RootedValue v(cx, Int32Value(maxNumPaths));
if (!JS_GetProperty(cx, options, "maxNumPaths", &v)) {
if (!JS_HasProperty(cx, options, "maxNumPaths", &exists)) {
return false;
}
if (!JS::ToInt32(cx, v, &maxNumPaths)) {
return false;
if (exists) {
if (!JS_GetProperty(cx, options, "maxNumPaths", &v)) {
return false;
}
if (!JS::ToInt32(cx, v, &maxNumPaths)) {
return false;
}
}
if (maxNumPaths <= 0) {
ReportValueError(cx, JSMSG_UNEXPECTED_TYPE, JSDVG_SEARCH_STACK, v,
Expand All @@ -4250,18 +4255,18 @@ static bool ShortestPaths(JSContext* cx, unsigned argc, Value* vp) {

{
mozilla::Maybe<JS::AutoCheckCannotGC> maybeNoGC;
mozilla::Maybe<JS::ubi::Node> maybeRoot;
JS::ubi::Node root;

JS::ubi::RootList rootList(cx, maybeNoGC, true);
if (start.isNull()) {
if (!rootList.init()) {
ReportOutOfMemory(cx);
return false;
}
maybeRoot.emplace(&rootList);
root = JS::ubi::Node(&rootList);
} else {
maybeNoGC.emplace(cx);
maybeRoot.emplace(start);
root = JS::ubi::Node(start);
}
JS::AutoCheckCannotGC& noGC = maybeNoGC.ref();

Expand All @@ -4276,7 +4281,6 @@ static bool ShortestPaths(JSContext* cx, unsigned argc, Value* vp) {
}
}

JS::ubi::Node& root = maybeRoot.ref();
auto maybeShortestPaths = JS::ubi::ShortestPaths::Create(
cx, noGC, maxNumPaths, root, std::move(targets));
if (maybeShortestPaths.isNothing()) {
Expand Down

0 comments on commit 90823f0

Please sign in to comment.