diff --git a/include/v8.h b/include/v8.h index b965b19368..1ade3e3acd 100644 --- a/include/v8.h +++ b/include/v8.h @@ -1022,6 +1022,11 @@ class V8_EXPORT EscapableHandleScope : public HandleScope { return Local(reinterpret_cast(slot)); } + template + V8_INLINE MaybeLocal EscapeMaybe(MaybeLocal value) { + return Escape(value.FromMaybe(Local())); + } + EscapableHandleScope(const EscapableHandleScope&) = delete; void operator=(const EscapableHandleScope&) = delete; diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc index c2737330cf..06ffe2f293 100644 --- a/test/cctest/test-api.cc +++ b/test/cctest/test-api.cc @@ -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 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(value)) + .ToLocalChecked(); + } } for (int i = 0; i < runs; i++) { Local expected;