OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef EXTENSIONS_RENDERER_V8_MAYBE_HELPERS_H_ |
| 6 #define EXTENSIONS_RENDERER_V8_MAYBE_HELPERS_H_ |
| 7 |
| 8 namespace extensions { |
| 9 |
| 10 // This crashes when strlen(str) >= v8::String::kMaxLength. |
| 11 inline v8::Local<v8::String> ToV8String( |
| 12 v8::Isolate* isolate, |
| 13 const char* str, |
| 14 v8::NewStringType string_type = v8::NewStringType::kNormal) { |
| 15 return v8::String::NewFromUtf8(isolate, str, string_type) |
| 16 .ToLocalChecked(); |
| 17 } |
| 18 |
| 19 inline bool CheckV8Call(v8::Maybe<bool> maybe) { |
| 20 return maybe.IsJust() && maybe.FromJust(); |
| 21 } |
| 22 |
| 23 inline bool SetProperty(v8::Local<v8::Context> context, |
| 24 v8::Local<v8::Object> object, |
| 25 v8::Local<v8::Value> key, |
| 26 v8::Local<v8::Value> value) { |
| 27 return CheckV8Call(object->Set(context, key, value)); |
| 28 } |
| 29 |
| 30 inline bool SetProperty(v8::Local<v8::Context> context, |
| 31 v8::Local<v8::Object> object, |
| 32 uint32_t index, |
| 33 v8::Local<v8::Value> value) { |
| 34 return CheckV8Call(object->Set(context, index, value)); |
| 35 } |
| 36 |
| 37 // This crashes when an exception is thrown. |
| 38 inline v8::Local<v8::Value> UnsafeGet(v8::Local<v8::Context> context, |
| 39 v8::Local<v8::Object> object, |
| 40 v8::Local<v8::Value> key) { |
| 41 return object->Get(context, key).ToLocalChecked(); |
| 42 } |
| 43 |
| 44 } // namespace extensions |
| 45 |
| 46 #endif // EXTENSIONS_RENDERER_V8_MAYBE_HELPERS_H_ |
OLD | NEW |