Chromium Code Reviews| Index: Source/bindings/core/v8/V8MaybeLocalToLocal.h |
| diff --git a/Source/bindings/core/v8/V8MaybeLocalToLocal.h b/Source/bindings/core/v8/V8MaybeLocalToLocal.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b55a592b0d47dcbc723840572ffa020890951858 |
| --- /dev/null |
| +++ b/Source/bindings/core/v8/V8MaybeLocalToLocal.h |
| @@ -0,0 +1,44 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef V8MaybeLocalToLocal_h |
| +#define V8MaybeLocalToLocal_h |
| + |
| +#include <v8.h> |
| + |
| +namespace blink { |
| + |
| +template <typename T> |
| +struct UnwrapV8Local { |
| +}; |
| + |
| +template <typename T> |
| +struct UnwrapV8Local<v8::Local<T>> { |
| + typedef T type; |
| +}; |
| + |
| +template <typename T> |
| +struct V8ToMaybeLocal { |
| +}; |
| + |
| +template <> |
| +struct V8ToMaybeLocal<v8::Object> { |
| + static v8::MaybeLocal<v8::Object> to(v8::Local<v8::Context> context, v8::Local<v8::Value> value) |
| + { |
| + return value->ToObject(context); |
| + } |
| +}; |
| + |
| +// Converts a V8 value to a specific V8 type using ToXXX() methods with checks. |
| + |
| +#define MAYBE_LOCAL_TO_LOCAL_VOID(context, inValue, outValue) do { \ |
|
bashi
2015/03/04 04:42:11
I'm planning to add MAYBE_LOCAL_TO_LOCAL_DEFAULT(c
|
| + using ValueType = UnwrapV8Local<decltype(outValue)>::type; \ |
| + v8::MaybeLocal<ValueType> maybeValue = V8ToMaybeLocal<ValueType>::to(context, inValue); \ |
| + if (maybeValue.IsEmpty() || !maybeValue.ToLocal(&outValue)) \ |
| + return; \ |
| +} while (false); |
|
Yuki
2015/03/04 05:14:31
You don't want the last semi-colon.
|
| + |
| +} // namespace blink |
| + |
| +#endif // V8MaybeLocalToLocal_h |