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_ | |
not at google - send to devlin
2015/06/12 16:51:37
I think just "v8_helpers" is fine, maybe extension
bashi
2015/06/16 03:12:47
Done.
| |
7 | |
8 #include "v8/include/v8.h" | |
9 | |
10 namespace extensions { | |
11 | |
not at google - send to devlin
2015/06/12 16:51:37
I'm a little bit put off by a function as generic
bashi
2015/06/16 03:12:47
Done.
| |
12 // This crashes when strlen(str) >= v8::String::kMaxLength. | |
13 inline v8::Local<v8::String> ToV8String( | |
14 v8::Isolate* isolate, | |
15 const char* str, | |
16 v8::NewStringType string_type = v8::NewStringType::kNormal) { | |
not at google - send to devlin
2015/06/12 16:51:37
You may also want to CHECK the string length here?
bashi
2015/06/16 03:12:47
Added as DCHECK(). ToLocalChecked() has CHECK() so
| |
17 return v8::String::NewFromUtf8(isolate, str, string_type) | |
18 .ToLocalChecked(); | |
19 } | |
20 | |
21 inline bool CheckV8Call(v8::Maybe<bool> maybe) { | |
not at google - send to devlin
2015/06/12 16:51:37
Put in an "internal" namespace? I don't see a util
bashi
2015/06/16 03:12:47
I'd prefer putting this in the current namespace.
| |
22 return maybe.IsJust() && maybe.FromJust(); | |
23 } | |
24 | |
25 inline bool SetProperty(v8::Local<v8::Context> context, | |
26 v8::Local<v8::Object> object, | |
27 v8::Local<v8::Value> key, | |
28 v8::Local<v8::Value> value) { | |
29 return CheckV8Call(object->Set(context, key, value)); | |
30 } | |
31 | |
32 inline bool SetProperty(v8::Local<v8::Context> context, | |
33 v8::Local<v8::Object> object, | |
34 uint32_t index, | |
35 v8::Local<v8::Value> value) { | |
36 return CheckV8Call(object->Set(context, index, value)); | |
37 } | |
38 | |
39 // This crashes when an exception is thrown. | |
40 inline v8::Local<v8::Value> UnsafeGet(v8::Local<v8::Context> context, | |
41 v8::Local<v8::Object> object, | |
42 v8::Local<v8::Value> key) { | |
43 return object->Get(context, key).ToLocalChecked(); | |
44 } | |
45 | |
46 } // namespace extensions | |
47 | |
48 #endif // EXTENSIONS_RENDERER_V8_MAYBE_HELPERS_H_ | |
OLD | NEW |