Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(101)

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/NativeValueTraitsImplTest.cpp

Issue 2802223002: bindings: Throw a type error if converting an interface or callback function fails. (Closed)
Patch Set: Add |callback_function_name| to the callback function template Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/bindings/scripts/v8_callback_function.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/bindings/scripts/v8_callback_function.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698