OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/renderer/pepper/v8_var_converter.h" | 5 #include "content/renderer/pepper/v8_var_converter.h" |
6 | 6 |
| 7 #include <stddef.h> |
| 8 #include <stdint.h> |
| 9 |
7 #include <cmath> | 10 #include <cmath> |
8 | 11 |
9 #include "base/logging.h" | 12 #include "base/logging.h" |
10 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
11 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
12 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
13 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
14 #include "base/synchronization/waitable_event.h" | 17 #include "base/synchronization/waitable_event.h" |
15 #include "base/values.h" | 18 #include "base/values.h" |
16 #include "content/renderer/pepper/resource_converter.h" | 19 #include "content/renderer/pepper/resource_converter.h" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 v8::String::Utf8Value utf8(val); | 109 v8::String::Utf8Value utf8(val); |
107 return std::string(*utf8, utf8.length()) == string_var->value(); | 110 return std::string(*utf8, utf8.length()) == string_var->value(); |
108 } else if (val->IsArray()) { | 111 } else if (val->IsArray()) { |
109 if (var.type != PP_VARTYPE_ARRAY) | 112 if (var.type != PP_VARTYPE_ARRAY) |
110 return false; | 113 return false; |
111 ArrayVar* array_var = ArrayVar::FromPPVar(var); | 114 ArrayVar* array_var = ArrayVar::FromPPVar(var); |
112 DCHECK(array_var); | 115 DCHECK(array_var); |
113 v8::Local<v8::Array> v8_array = val.As<v8::Array>(); | 116 v8::Local<v8::Array> v8_array = val.As<v8::Array>(); |
114 if (v8_array->Length() != array_var->elements().size()) | 117 if (v8_array->Length() != array_var->elements().size()) |
115 return false; | 118 return false; |
116 for (uint32 i = 0; i < v8_array->Length(); ++i) { | 119 for (uint32_t i = 0; i < v8_array->Length(); ++i) { |
117 v8::Local<v8::Value> child_v8 = v8_array->Get(i); | 120 v8::Local<v8::Value> child_v8 = v8_array->Get(i); |
118 if (!Equals(array_var->elements()[i].get(), child_v8, visited_ids)) | 121 if (!Equals(array_var->elements()[i].get(), child_v8, visited_ids)) |
119 return false; | 122 return false; |
120 } | 123 } |
121 return true; | 124 return true; |
122 } else if (val->IsObject()) { | 125 } else if (val->IsObject()) { |
123 if (var.type == PP_VARTYPE_ARRAY_BUFFER) { | 126 if (var.type == PP_VARTYPE_ARRAY_BUFFER) { |
124 // TODO(raymes): Implement this when we have tests for array buffers. | 127 // TODO(raymes): Implement this when we have tests for array buffers. |
125 NOTIMPLEMENTED(); | 128 NOTIMPLEMENTED(); |
126 return false; | 129 return false; |
127 } else { | 130 } else { |
128 v8::Local<v8::Object> v8_object = val.As<v8::Object>(); | 131 v8::Local<v8::Object> v8_object = val.As<v8::Object>(); |
129 if (var.type != PP_VARTYPE_DICTIONARY) | 132 if (var.type != PP_VARTYPE_DICTIONARY) |
130 return false; | 133 return false; |
131 DictionaryVar* dict_var = DictionaryVar::FromPPVar(var); | 134 DictionaryVar* dict_var = DictionaryVar::FromPPVar(var); |
132 DCHECK(dict_var); | 135 DCHECK(dict_var); |
133 v8::Local<v8::Array> property_names(v8_object->GetOwnPropertyNames()); | 136 v8::Local<v8::Array> property_names(v8_object->GetOwnPropertyNames()); |
134 if (property_names->Length() != dict_var->key_value_map().size()) | 137 if (property_names->Length() != dict_var->key_value_map().size()) |
135 return false; | 138 return false; |
136 for (uint32 i = 0; i < property_names->Length(); ++i) { | 139 for (uint32_t i = 0; i < property_names->Length(); ++i) { |
137 v8::Local<v8::Value> key(property_names->Get(i)); | 140 v8::Local<v8::Value> key(property_names->Get(i)); |
138 | 141 |
139 if (!key->IsString() && !key->IsNumber()) | 142 if (!key->IsString() && !key->IsNumber()) |
140 return false; | 143 return false; |
141 v8::Local<v8::Value> child_v8 = v8_object->Get(key); | 144 v8::Local<v8::Value> child_v8 = v8_object->Get(key); |
142 | 145 |
143 v8::String::Utf8Value name_utf8(key); | 146 v8::String::Utf8Value name_utf8(key); |
144 ScopedPPVar release_key(ScopedPPVar::PassRef(), | 147 ScopedPPVar release_key(ScopedPPVar::PassRef(), |
145 StringVar::StringToPPVar(std::string( | 148 StringVar::StringToPPVar(std::string( |
146 *name_utf8, name_utf8.length()))); | 149 *name_utf8, name_utf8.length()))); |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 expected->SetWithStringKey("null", quux.get()); | 440 expected->SetWithStringKey("null", quux.get()); |
438 ScopedPPVar oops(ScopedPPVar::PassRef(), StringVar::StringToPPVar("oops")); | 441 ScopedPPVar oops(ScopedPPVar::PassRef(), StringVar::StringToPPVar("oops")); |
439 expected->SetWithStringKey("undefined", oops.get()); | 442 expected->SetWithStringKey("undefined", oops.get()); |
440 ScopedPPVar release_expected(ScopedPPVar::PassRef(), expected->GetPPVar()); | 443 ScopedPPVar release_expected(ScopedPPVar::PassRef(), expected->GetPPVar()); |
441 | 444 |
442 ASSERT_TRUE(TestEqual(release_expected.get(), release_actual.get(), true)); | 445 ASSERT_TRUE(TestEqual(release_expected.get(), release_actual.get(), true)); |
443 } | 446 } |
444 } | 447 } |
445 | 448 |
446 } // namespace content | 449 } // namespace content |
OLD | NEW |