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/ToV8.h" | 11 #include "bindings/core/v8/ToV8.h" |
11 #include "bindings/core/v8/V8BindingForTesting.h" | 12 #include "bindings/core/v8/V8BindingForTesting.h" |
| 13 #include "bindings/core/v8/V8Internals.h" |
12 #include "platform/wtf/Vector.h" | 14 #include "platform/wtf/Vector.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
14 | 16 |
15 namespace blink { | 17 namespace blink { |
16 | 18 |
17 namespace { | 19 namespace { |
18 | 20 |
19 template <typename T> | 21 template <typename T> |
20 v8::Local<v8::Value> ToV8(V8TestingScope* scope, T value) { | 22 v8::Local<v8::Value> ToV8(V8TestingScope* scope, T value) { |
21 return blink::ToV8(value, scope->context()->Global(), scope->isolate()); | 23 return blink::ToV8(value, scope->context()->Global(), scope->isolate()); |
22 } | 24 } |
23 | 25 |
| 26 TEST(NativeValueTraitsImplTest, IDLInterface) { |
| 27 V8TestingScope scope; |
| 28 { |
| 29 DummyExceptionStateForTesting exceptionState; |
| 30 Internals* internals = NativeValueTraits<Internals>::nativeValue( |
| 31 scope.isolate(), v8::Number::New(scope.isolate(), 42), exceptionState); |
| 32 EXPECT_TRUE(exceptionState.hadException()); |
| 33 EXPECT_EQ("Unable to convert value to Internals.", |
| 34 exceptionState.message()); |
| 35 EXPECT_EQ(nullptr, internals); |
| 36 } |
| 37 { |
| 38 DummyExceptionStateForTesting exceptionState; |
| 39 TestSequenceCallback* callbackFunction = |
| 40 NativeValueTraits<TestSequenceCallback>::nativeValue( |
| 41 scope.isolate(), v8::Undefined(scope.isolate()), exceptionState); |
| 42 EXPECT_TRUE(exceptionState.hadException()); |
| 43 EXPECT_EQ("Unable to convert value to TestSequenceCallback.", |
| 44 exceptionState.message()); |
| 45 EXPECT_EQ(nullptr, callbackFunction); |
| 46 } |
| 47 } |
| 48 |
24 void ThrowException(v8::Local<v8::Name>, | 49 void ThrowException(v8::Local<v8::Name>, |
25 const v8::PropertyCallbackInfo<v8::Value>& info) { | 50 const v8::PropertyCallbackInfo<v8::Value>& info) { |
26 info.GetIsolate()->ThrowException(v8String(info.GetIsolate(), "bogus!")); | 51 info.GetIsolate()->ThrowException(v8String(info.GetIsolate(), "bogus!")); |
27 } | 52 } |
28 | 53 |
29 void ReturnBogusObjectDescriptor( | 54 void ReturnBogusObjectDescriptor( |
30 const v8::FunctionCallbackInfo<v8::Value>& info) { | 55 const v8::FunctionCallbackInfo<v8::Value>& info) { |
31 v8::Isolate* isolate = info.GetIsolate(); | 56 v8::Isolate* isolate = info.GetIsolate(); |
32 auto context = isolate->GetCurrentContext(); | 57 auto context = isolate->GetCurrentContext(); |
33 | 58 |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 EXPECT_EQ(1U, record.size()); | 261 EXPECT_EQ(1U, record.size()); |
237 EXPECT_EQ("foo", record[0].first); | 262 EXPECT_EQ("foo", record[0].first); |
238 EXPECT_EQ("Hello, World!", record[0].second[0]); | 263 EXPECT_EQ("Hello, World!", record[0].second[0]); |
239 EXPECT_EQ("Hi, Mom!", record[0].second[1]); | 264 EXPECT_EQ("Hi, Mom!", record[0].second[1]); |
240 } | 265 } |
241 } | 266 } |
242 | 267 |
243 } // namespace | 268 } // namespace |
244 | 269 |
245 } // namespace blink | 270 } // namespace blink |
OLD | NEW |