[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/1056529 Reviewed-by: Yang Guo <yangguo@chromium.org> Commit-Queue: Yang Guo <yangguo@chromium.org> Cr-Commit-Position: refs/heads/master@{#53415}
This commit is contained in:
parent
dcc76e7e45
commit
0fd549f885
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user