OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/ToV8.h" | 5 #include "bindings/core/v8/ToV8.h" |
6 | 6 |
7 #include "bindings/core/v8/V8Binding.h" | 7 #include "bindings/core/v8/V8Binding.h" |
8 #include "bindings/core/v8/V8BindingForTesting.h" | 8 #include "bindings/core/v8/V8BindingForTesting.h" |
9 #include "core/testing/GarbageCollectedScriptWrappable.h" | 9 #include "core/testing/GarbageCollectedScriptWrappable.h" |
10 #include "core/testing/RefCountedScriptWrappable.h" | |
11 #include "platform/heap/Heap.h" | 10 #include "platform/heap/Heap.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
13 #include "wtf/Vector.h" | 12 #include "wtf/Vector.h" |
14 #include <limits> | 13 #include <limits> |
15 | 14 |
16 #define TEST_TOV8(expected, value) testToV8(expected, value, __FILE__, __LINE__) | 15 #define TEST_TOV8(expected, value) testToV8(expected, value, __FILE__, __LINE__) |
17 | 16 |
18 namespace blink { | 17 namespace blink { |
19 | 18 |
20 namespace { | 19 namespace { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 | 53 |
55 class OffHeapGarbageCollectedHolder { | 54 class OffHeapGarbageCollectedHolder { |
56 public: | 55 public: |
57 OffHeapGarbageCollectedHolder(GarbageCollectedScriptWrappable* scriptWrappab
le) | 56 OffHeapGarbageCollectedHolder(GarbageCollectedScriptWrappable* scriptWrappab
le) |
58 : m_scriptWrappable(scriptWrappable) { } | 57 : m_scriptWrappable(scriptWrappable) { } |
59 | 58 |
60 // This should be public in order to access a Persistent<X> object. | 59 // This should be public in order to access a Persistent<X> object. |
61 Persistent<GarbageCollectedScriptWrappable> m_scriptWrappable; | 60 Persistent<GarbageCollectedScriptWrappable> m_scriptWrappable; |
62 }; | 61 }; |
63 | 62 |
64 TEST_F(ToV8Test, refCountedScriptWrappable) | |
65 { | |
66 RefPtr<RefCountedScriptWrappable> object = RefCountedScriptWrappable::create
("hello"); | |
67 | |
68 TEST_TOV8("hello", object); | |
69 TEST_TOV8("hello", object.get()); | |
70 TEST_TOV8("hello", object.release()); | |
71 | |
72 ASSERT_FALSE(object); | |
73 | |
74 TEST_TOV8("null", object); | |
75 TEST_TOV8("null", object.get()); | |
76 TEST_TOV8("null", object.release()); | |
77 } | |
78 | |
79 TEST_F(ToV8Test, garbageCollectedScriptWrappable) | 63 TEST_F(ToV8Test, garbageCollectedScriptWrappable) |
80 { | 64 { |
81 GarbageCollectedScriptWrappable* object = new GarbageCollectedScriptWrappabl
e("world"); | 65 GarbageCollectedScriptWrappable* object = new GarbageCollectedScriptWrappabl
e("world"); |
82 GarbageCollectedHolder holder(object); | 66 GarbageCollectedHolder holder(object); |
83 OffHeapGarbageCollectedHolder offHeapHolder(object); | 67 OffHeapGarbageCollectedHolder offHeapHolder(object); |
84 | 68 |
85 TEST_TOV8("world", object); | 69 TEST_TOV8("world", object); |
86 TEST_TOV8("world", RawPtr<GarbageCollectedScriptWrappable>(object)); | 70 TEST_TOV8("world", RawPtr<GarbageCollectedScriptWrappable>(object)); |
87 TEST_TOV8("world", holder.m_scriptWrappable); | 71 TEST_TOV8("world", holder.m_scriptWrappable); |
88 TEST_TOV8("world", offHeapHolder.m_scriptWrappable); | 72 TEST_TOV8("world", offHeapHolder.m_scriptWrappable); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 TEST_TOV8("undefined", ToV8UndefinedGenerator()); | 143 TEST_TOV8("undefined", ToV8UndefinedGenerator()); |
160 } | 144 } |
161 | 145 |
162 TEST_F(ToV8Test, scriptValue) | 146 TEST_F(ToV8Test, scriptValue) |
163 { | 147 { |
164 ScriptValue value(m_scope.getScriptState(), v8::Number::New(m_scope.isolate(
), 1234)); | 148 ScriptValue value(m_scope.getScriptState(), v8::Number::New(m_scope.isolate(
), 1234)); |
165 | 149 |
166 TEST_TOV8("1234", value); | 150 TEST_TOV8("1234", value); |
167 } | 151 } |
168 | 152 |
169 TEST_F(ToV8Test, vector) | |
170 { | |
171 Vector<RefPtr<RefCountedScriptWrappable>> v; | |
172 v.append(RefCountedScriptWrappable::create("foo")); | |
173 v.append(RefCountedScriptWrappable::create("bar")); | |
174 | |
175 TEST_TOV8("foo,bar", v); | |
176 } | |
177 | |
178 TEST_F(ToV8Test, stringVectors) | 153 TEST_F(ToV8Test, stringVectors) |
179 { | 154 { |
180 Vector<String> stringVector; | 155 Vector<String> stringVector; |
181 stringVector.append("foo"); | 156 stringVector.append("foo"); |
182 stringVector.append("bar"); | 157 stringVector.append("bar"); |
183 TEST_TOV8("foo,bar", stringVector); | 158 TEST_TOV8("foo,bar", stringVector); |
184 | 159 |
185 Vector<AtomicString> atomicStringVector; | 160 Vector<AtomicString> atomicStringVector; |
186 atomicStringVector.append("quux"); | 161 atomicStringVector.append("quux"); |
187 atomicStringVector.append("bar"); | 162 atomicStringVector.append("bar"); |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 v8::Local<v8::Value> actual = toV8(value, m_scope.getScriptState()); | 285 v8::Local<v8::Value> actual = toV8(value, m_scope.getScriptState()); |
311 EXPECT_FALSE(actual.IsEmpty()); | 286 EXPECT_FALSE(actual.IsEmpty()); |
312 | 287 |
313 double actualAsNumber = actual.As<v8::Number>()->Value(); | 288 double actualAsNumber = actual.As<v8::Number>()->Value(); |
314 EXPECT_EQ(1234.0, actualAsNumber); | 289 EXPECT_EQ(1234.0, actualAsNumber); |
315 } | 290 } |
316 | 291 |
317 } // namespace | 292 } // namespace |
318 | 293 |
319 } // namespace blink | 294 } // namespace blink |
OLD | NEW |