Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(131)

Side by Side Diff: extensions/renderer/v8_maybe_helpers.h

Issue 1167423002: Use V8 Maybe APIs in extensions/renderer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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_
OLDNEW
« no previous file with comments | « extensions/renderer/v8_context_native_handler.cc ('k') | extensions/renderer/v8_schema_registry.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698