OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #include "extensions/renderer/api_binding_test_util.h" | 5 #include "extensions/renderer/api_binding_test_util.h" |
6 | 6 |
7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 return result; | 168 return result; |
169 } | 169 } |
170 | 170 |
171 std::unique_ptr<base::Value> GetBaseValuePropertyFromObject( | 171 std::unique_ptr<base::Value> GetBaseValuePropertyFromObject( |
172 v8::Local<v8::Object> object, | 172 v8::Local<v8::Object> object, |
173 v8::Local<v8::Context> context, | 173 v8::Local<v8::Context> context, |
174 base::StringPiece key) { | 174 base::StringPiece key) { |
175 return V8ToBaseValue(GetPropertyFromObject(object, context, key), context); | 175 return V8ToBaseValue(GetPropertyFromObject(object, context, key), context); |
176 } | 176 } |
177 | 177 |
| 178 std::string GetStringPropertyFromObject(v8::Local<v8::Object> object, |
| 179 v8::Local<v8::Context> context, |
| 180 base::StringPiece key) { |
| 181 v8::Local<v8::Value> v8_val = GetPropertyFromObject(object, context, key); |
| 182 if (v8_val.IsEmpty()) |
| 183 return "empty"; |
| 184 if (v8_val->IsNull()) |
| 185 return "null"; |
| 186 if (v8_val->IsUndefined()) |
| 187 return "undefined"; |
| 188 if (v8_val->IsFunction()) |
| 189 return "function"; |
| 190 std::unique_ptr<base::Value> json_prop = V8ToBaseValue(v8_val, context); |
| 191 DCHECK(json_prop) << key; |
| 192 return ValueToString(*json_prop); |
| 193 } |
| 194 |
178 } // namespace extensions | 195 } // namespace extensions |
OLD | NEW |