Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef EXTENSIONS_RENDERER_V8_HELPERS_H_ | 5 #ifndef EXTENSIONS_RENDERER_V8_HELPERS_H_ |
| 6 #define EXTENSIONS_RENDERER_V8_HELPERS_H_ | 6 #define EXTENSIONS_RENDERER_V8_HELPERS_H_ |
| 7 | 7 |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 | 9 |
| 10 #include "v8/include/v8.h" | 10 #include "v8/include/v8.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 49 // Returns true if |maybe| is both a value, and that value is true. | 49 // Returns true if |maybe| is both a value, and that value is true. |
| 50 inline bool IsTrue(v8::Maybe<bool> maybe) { | 50 inline bool IsTrue(v8::Maybe<bool> maybe) { |
| 51 return maybe.IsJust() && maybe.FromJust(); | 51 return maybe.IsJust() && maybe.FromJust(); |
| 52 } | 52 } |
| 53 | 53 |
| 54 // Returns true if |value| is empty or undefined. | 54 // Returns true if |value| is empty or undefined. |
| 55 inline bool IsEmptyOrUndefied(v8::Local<v8::Value> value) { | 55 inline bool IsEmptyOrUndefied(v8::Local<v8::Value> value) { |
| 56 return value.IsEmpty() || value->IsUndefined(); | 56 return value.IsEmpty() || value->IsUndefined(); |
| 57 } | 57 } |
| 58 | 58 |
| 59 // SetProperty() family wraps V8::Object::Set(). Returns true on success. | 59 // SetProperty() family wraps V8::Object::DefineOwnProperty(). |
| 60 // Returns true on success. | |
| 60 inline bool SetProperty(v8::Local<v8::Context> context, | 61 inline bool SetProperty(v8::Local<v8::Context> context, |
| 61 v8::Local<v8::Object> object, | 62 v8::Local<v8::Object> object, |
| 62 v8::Local<v8::Value> key, | 63 v8::Local<v8::String> key, |
| 63 v8::Local<v8::Value> value) { | 64 v8::Local<v8::Value> value) { |
| 64 return IsTrue(object->Set(context, key, value)); | 65 return IsTrue(object->DefineOwnProperty(context, key, value)); |
| 65 } | 66 } |
| 66 | 67 |
| 67 inline bool SetProperty(v8::Local<v8::Context> context, | 68 inline bool SetProperty(v8::Local<v8::Context> context, |
| 68 v8::Local<v8::Object> object, | 69 v8::Local<v8::Object> object, |
| 69 uint32_t index, | 70 uint32_t index, |
| 70 v8::Local<v8::Value> value) { | 71 v8::Local<v8::Value> value) { |
| 71 return IsTrue(object->Set(context, index, value)); | 72 return IsTrue(object->Set(context, index, value)); |
|
Devlin
2015/11/12 23:10:15
Is there a way to bypass setters for an index-base
jochen (gone - plz use gerrit)
2015/11/12 23:17:37
DefineOwnProperty should work for indexed values a
Devlin
2015/11/12 23:40:48
Oh, cool. I wasn't sure if that's what it meant b
| |
| 72 } | 73 } |
| 73 | 74 |
| 74 inline bool SetProperty(v8::Local<v8::Context> context, | 75 inline bool SetProperty(v8::Local<v8::Context> context, |
| 75 v8::Local<v8::Object> object, | 76 v8::Local<v8::Object> object, |
| 76 const char* key, | 77 const char* key, |
| 77 v8::Local<v8::Value> value) { | 78 v8::Local<v8::Value> value) { |
| 78 v8::Local<v8::String> v8_key; | 79 v8::Local<v8::String> v8_key; |
| 79 if (!ToV8String(context->GetIsolate(), key, &v8_key)) | 80 if (!ToV8String(context->GetIsolate(), key, &v8_key)) |
| 80 return false; | 81 return false; |
| 81 return SetProperty(context, object, v8_key, value); | 82 return SetProperty(context, object, v8_key, value); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 126 int argc, | 127 int argc, |
| 127 v8::Local<v8::Value> argv[], | 128 v8::Local<v8::Value> argv[], |
| 128 v8::Local<v8::Value>* out) { | 129 v8::Local<v8::Value>* out) { |
| 129 return function->Call(context, recv, argc, argv).ToLocal(out); | 130 return function->Call(context, recv, argc, argv).ToLocal(out); |
| 130 } | 131 } |
| 131 | 132 |
| 132 } // namespace v8_helpers | 133 } // namespace v8_helpers |
| 133 } // namespace extensions | 134 } // namespace extensions |
| 134 | 135 |
| 135 #endif // EXTENSIONS_RENDERER_V8_HELPERS_H_ | 136 #endif // EXTENSIONS_RENDERER_V8_HELPERS_H_ |
| OLD | NEW |