Index: extensions/renderer/v8_maybe_helpers.h |
diff --git a/extensions/renderer/v8_maybe_helpers.h b/extensions/renderer/v8_maybe_helpers.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..70117120d3650d3fa774ae2ba02a2be5a9f2dddf |
--- /dev/null |
+++ b/extensions/renderer/v8_maybe_helpers.h |
@@ -0,0 +1,46 @@ |
+// 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 EXTENSIONS_RENDERER_V8_MAYBE_HELPERS_H_ |
+#define EXTENSIONS_RENDERER_V8_MAYBE_HELPERS_H_ |
+ |
+namespace extensions { |
+ |
+// This crashes when strlen(str) >= v8::String::kMaxLength. |
+inline v8::Local<v8::String> ToV8String( |
+ v8::Isolate* isolate, |
+ const char* str, |
+ v8::NewStringType string_type = v8::NewStringType::kNormal) { |
+ return v8::String::NewFromUtf8(isolate, str, string_type) |
+ .ToLocalChecked(); |
+} |
+ |
+inline bool CheckV8Call(v8::Maybe<bool> maybe) { |
+ return maybe.IsJust() && maybe.FromJust(); |
+} |
+ |
+inline bool SetProperty(v8::Local<v8::Context> context, |
+ v8::Local<v8::Object> object, |
+ v8::Local<v8::Value> key, |
+ v8::Local<v8::Value> value) { |
+ return CheckV8Call(object->Set(context, key, value)); |
+} |
+ |
+inline bool SetProperty(v8::Local<v8::Context> context, |
+ v8::Local<v8::Object> object, |
+ uint32_t index, |
+ v8::Local<v8::Value> value) { |
+ return CheckV8Call(object->Set(context, index, value)); |
+} |
+ |
+// This crashes when an exception is thrown. |
+inline v8::Local<v8::Value> UnsafeGet(v8::Local<v8::Context> context, |
+ v8::Local<v8::Object> object, |
+ v8::Local<v8::Value> key) { |
+ return object->Get(context, key).ToLocalChecked(); |
+} |
+ |
+} // namespace extensions |
+ |
+#endif // EXTENSIONS_RENDERER_V8_MAYBE_HELPERS_H_ |