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_HELPERS_H_ | |
6 #define EXTENSIONS_RENDERER_V8_HELPERS_H_ | |
7 | |
8 #include <string.h> | |
9 | |
10 #include "v8/include/v8.h" | |
11 | |
12 namespace extensions { | |
13 namespace v8_helpers { | |
not at google - send to devlin
2015/06/16 20:52:25
Comments in this class, and its methods, would be
bashi
2015/06/17 01:40:45
Done.
| |
14 | |
15 // This crashes when strlen(str) >= v8::String::kMaxLength. | |
16 inline v8::Local<v8::String> ToV8StringUnsafe( | |
17 v8::Isolate* isolate, | |
18 const char* str, | |
19 v8::NewStringType string_type = v8::NewStringType::kNormal) { | |
20 DCHECK(strlen(str) < v8::String::kMaxLength); | |
not at google - send to devlin
2015/06/16 20:52:25
Seems like it should be <= really, "max length" sh
bashi
2015/06/17 01:40:45
Yes. Thanks for the catch.
| |
21 return v8::String::NewFromUtf8(isolate, str, string_type) | |
22 .ToLocalChecked(); | |
23 } | |
24 | |
25 inline bool ToV8String(v8::Isolate* isolate, | |
26 const char* str, | |
27 v8::Local<v8::String>* out) { | |
28 return v8::String::NewFromUtf8(isolate, str, v8::NewStringType::kNormal) | |
29 .ToLocal(out); | |
30 } | |
31 | |
32 inline bool CheckV8Call(v8::Maybe<bool> maybe) { | |
not at google - send to devlin
2015/06/16 20:52:25
CheckV8Call is not a good name, it sounds like thi
bashi
2015/06/17 01:40:45
Done.
| |
33 return maybe.IsJust() && maybe.FromJust(); | |
34 } | |
35 | |
36 inline bool SetProperty(v8::Local<v8::Context> context, | |
37 v8::Local<v8::Object> object, | |
38 v8::Local<v8::Value> key, | |
not at google - send to devlin
2015/06/16 20:52:25
Another suggestion: provide a version of SetProper
bashi
2015/06/17 01:40:45
Done.
| |
39 v8::Local<v8::Value> value) { | |
40 return CheckV8Call(object->Set(context, key, value)); | |
41 } | |
42 | |
43 inline bool SetProperty(v8::Local<v8::Context> context, | |
44 v8::Local<v8::Object> object, | |
45 uint32_t index, | |
46 v8::Local<v8::Value> value) { | |
47 return CheckV8Call(object->Set(context, index, value)); | |
48 } | |
49 | |
50 // This crashes when an exception is thrown. | |
51 inline v8::Local<v8::Value> UnsafeGet(v8::Local<v8::Context> context, | |
52 v8::Local<v8::Object> object, | |
53 v8::Local<v8::Value> key) { | |
54 return object->Get(context, key).ToLocalChecked(); | |
55 } | |
56 | |
57 } // namespace v8_helpers | |
58 } // namespace extensions | |
59 | |
60 #endif // EXTENSIONS_RENDERER_V8_HELPERS_H_ | |
OLD | NEW |