| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "bindings/core/v8/NativeValueTraitsImpl.h" | 5 #include "bindings/core/v8/NativeValueTraitsImpl.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 #include "bindings/core/v8/ExceptionState.h" | 8 #include "bindings/core/v8/ExceptionState.h" |
| 9 #include "bindings/core/v8/IDLTypes.h" | 9 #include "bindings/core/v8/IDLTypes.h" |
| 10 #include "bindings/core/v8/TestSequenceCallback.h" | 10 #include "bindings/core/v8/TestSequenceCallback.h" |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 EXPECT_EQ(std::make_pair(String("foo"), String("Ohai")), record[2]); | 193 EXPECT_EQ(std::make_pair(String("foo"), String("Ohai")), record[2]); |
| 194 } | 194 } |
| 195 { | 195 { |
| 196 v8::Local<v8::Object> v8_object = v8::Object::New(scope.GetIsolate()); | 196 v8::Local<v8::Object> v8_object = v8::Object::New(scope.GetIsolate()); |
| 197 EXPECT_TRUE(V8CallBoolean(v8_object->Set( | 197 EXPECT_TRUE(V8CallBoolean(v8_object->Set( |
| 198 scope.GetContext(), v8::Symbol::GetToStringTag(scope.GetIsolate()), | 198 scope.GetContext(), v8::Symbol::GetToStringTag(scope.GetIsolate()), |
| 199 ToV8(&scope, 34)))); | 199 ToV8(&scope, 34)))); |
| 200 EXPECT_TRUE(V8CallBoolean(v8_object->Set( | 200 EXPECT_TRUE(V8CallBoolean(v8_object->Set( |
| 201 scope.GetContext(), ToV8(&scope, "foo"), ToV8(&scope, 42)))); | 201 scope.GetContext(), ToV8(&scope, "foo"), ToV8(&scope, 42)))); |
| 202 | 202 |
| 203 NonThrowableExceptionState exception_state; | 203 // The presence of symbols should throw a TypeError when the conversion to |
| 204 // the record's key type is attempted. |
| 205 DummyExceptionStateForTesting exception_state; |
| 204 const auto& record = | 206 const auto& record = |
| 205 NativeValueTraits<IDLRecord<IDLString, IDLShort>>::NativeValue( | 207 NativeValueTraits<IDLRecord<IDLString, IDLShort>>::NativeValue( |
| 206 scope.GetIsolate(), v8_object, exception_state); | 208 scope.GetIsolate(), v8_object, exception_state); |
| 207 EXPECT_EQ(1U, record.size()); | 209 EXPECT_TRUE(record.IsEmpty()); |
| 208 EXPECT_EQ(std::make_pair(String("foo"), int16_t(42)), record[0]); | 210 EXPECT_TRUE(exception_state.HadException()); |
| 209 } | 211 EXPECT_TRUE(exception_state.Message().IsEmpty()); |
| 210 { | |
| 211 v8::Local<v8::Object> v8_object = v8::Object::New(scope.GetIsolate()); | |
| 212 EXPECT_TRUE(V8CallBoolean(v8_object->Set( | |
| 213 scope.GetContext(), v8::Symbol::GetToStringTag(scope.GetIsolate()), | |
| 214 ToV8(&scope, 34)))); | |
| 215 EXPECT_TRUE(V8CallBoolean(v8_object->Set( | |
| 216 scope.GetContext(), ToV8(&scope, "foo"), ToV8(&scope, 42)))); | |
| 217 | |
| 218 NonThrowableExceptionState exception_state; | |
| 219 const auto& record = | |
| 220 NativeValueTraits<IDLRecord<IDLString, IDLShort>>::NativeValue( | |
| 221 scope.GetIsolate(), v8_object, exception_state); | |
| 222 EXPECT_EQ(1U, record.size()); | |
| 223 EXPECT_EQ(std::make_pair(String("foo"), int16_t(42)), record[0]); | |
| 224 } | 212 } |
| 225 { | 213 { |
| 226 v8::Local<v8::Object> v8_parent_object = | 214 v8::Local<v8::Object> v8_parent_object = |
| 227 v8::Object::New(scope.GetIsolate()); | 215 v8::Object::New(scope.GetIsolate()); |
| 228 EXPECT_TRUE(V8CallBoolean(v8_parent_object->Set( | 216 EXPECT_TRUE(V8CallBoolean(v8_parent_object->Set( |
| 229 scope.GetContext(), ToV8(&scope, "foo"), ToV8(&scope, 34)))); | 217 scope.GetContext(), ToV8(&scope, "foo"), ToV8(&scope, 34)))); |
| 230 EXPECT_TRUE(V8CallBoolean(v8_parent_object->Set( | 218 EXPECT_TRUE(V8CallBoolean(v8_parent_object->Set( |
| 231 scope.GetContext(), ToV8(&scope, "bar"), ToV8(&scope, 512)))); | 219 scope.GetContext(), ToV8(&scope, "bar"), ToV8(&scope, 512)))); |
| 232 v8::Local<v8::Object> v8_object = v8::Object::New(scope.GetIsolate()); | 220 v8::Local<v8::Object> v8_object = v8::Object::New(scope.GetIsolate()); |
| 233 EXPECT_TRUE(V8CallBoolean( | 221 EXPECT_TRUE(V8CallBoolean( |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 const auto& boolean_sequence = | 435 const auto& boolean_sequence = |
| 448 NativeValueTraits<IDLSequence<IDLBoolean>>::NativeValue( | 436 NativeValueTraits<IDLSequence<IDLBoolean>>::NativeValue( |
| 449 scope.GetIsolate(), v8_object, exception_state); | 437 scope.GetIsolate(), v8_object, exception_state); |
| 450 EXPECT_EQ(Vector<bool>({true, false}), boolean_sequence); | 438 EXPECT_EQ(Vector<bool>({true, false}), boolean_sequence); |
| 451 } | 439 } |
| 452 } | 440 } |
| 453 | 441 |
| 454 } // namespace | 442 } // namespace |
| 455 | 443 |
| 456 } // namespace blink | 444 } // namespace blink |
| OLD | NEW |