Commit 0fd549f8 authored by Anna Henningsen's avatar Anna Henningsen Committed by Commit Bot

[api] Allow escaping `MaybeLocal` handles on `EscapableHandleScope`

This adds a convenience overload for `EscapableHandleScope::Escape()`
which moves `MaybeLocal<T>`s into the outer scope, like a regular
`Local<T>`.

This basically moves the syntactic clutter of having to write
`maybe_local.FromMaybe(Local<Foo>())` instead of just `maybe_local`
to a central location.

Cq-Include-Trybots: luci.chromium.try:linux_chromium_rel_ng
Change-Id: I1d87d75c6564b10e8ec34957bdd3eac46ffea917
Reviewed-on: https://chromium-review.googlesource.com/1056529Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Commit-Queue: Yang Guo <yangguo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53415}
parent dcc76e7e
......@@ -1022,6 +1022,11 @@ class V8_EXPORT EscapableHandleScope : public HandleScope {
return Local<T>(reinterpret_cast<T*>(slot));
}
template <class T>
V8_INLINE MaybeLocal<T> EscapeMaybe(MaybeLocal<T> value) {
return Escape(value.FromMaybe(Local<T>()));
}
EscapableHandleScope(const EscapableHandleScope&) = delete;
void operator=(const EscapableHandleScope&) = delete;
......
......@@ -23889,8 +23889,7 @@ THREADED_TEST(FunctionNew) {
CHECK(v8::Integer::New(isolate, 17)->Equals(env.local(), result2).FromJust());
}
TEST(EscapeableHandleScope) {
TEST(EscapableHandleScope) {
HandleScope outer_scope(CcTest::isolate());
LocalContext context;
const int runs = 10;
......@@ -23899,7 +23898,12 @@ TEST(EscapeableHandleScope) {
v8::EscapableHandleScope inner_scope(CcTest::isolate());
Local<String> value;
if (i != 0) value = v8_str("escape value");
values[i] = inner_scope.Escape(value);
if (i < runs / 2) {
values[i] = inner_scope.Escape(value);
} else {
values[i] = inner_scope.EscapeMaybe(v8::MaybeLocal<String>(value))
.ToLocalChecked();
}
}
for (int i = 0; i < runs; i++) {
Local<String> expected;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment