| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2014 Google Inc. All rights reserved. | 2 * Copyright (C) 2014 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "bindings/v8/ScriptPromise.h" | 32 #include "bindings/v8/ScriptPromise.h" |
| 33 | 33 |
| 34 #include "RuntimeEnabledFeatures.h" |
| 34 #include "bindings/v8/DOMWrapperWorld.h" | 35 #include "bindings/v8/DOMWrapperWorld.h" |
| 35 #include "bindings/v8/ScriptPromiseResolver.h" | 36 #include "bindings/v8/ScriptPromiseResolver.h" |
| 36 #include "bindings/v8/ScriptValue.h" | 37 #include "bindings/v8/ScriptValue.h" |
| 37 #include "bindings/v8/V8Binding.h" | 38 #include "bindings/v8/V8Binding.h" |
| 38 #include "bindings/v8/custom/V8PromiseCustom.h" | 39 #include "bindings/v8/custom/V8PromiseCustom.h" |
| 39 | 40 |
| 40 #include <gtest/gtest.h> | 41 #include <gtest/gtest.h> |
| 41 #include <v8.h> | 42 #include <v8.h> |
| 42 | 43 |
| 43 namespace WebCore { | 44 namespace WebCore { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 TEST_F(ScriptPromiseTest, constructFromNonPromise) | 76 TEST_F(ScriptPromiseTest, constructFromNonPromise) |
| 76 { | 77 { |
| 77 v8::TryCatch trycatch; | 78 v8::TryCatch trycatch; |
| 78 ScriptPromise promise(v8::Undefined(m_isolate), m_isolate); | 79 ScriptPromise promise(v8::Undefined(m_isolate), m_isolate); |
| 79 ASSERT_TRUE(trycatch.HasCaught()); | 80 ASSERT_TRUE(trycatch.HasCaught()); |
| 80 ASSERT_TRUE(promise.hasNoValue()); | 81 ASSERT_TRUE(promise.hasNoValue()); |
| 81 } | 82 } |
| 82 | 83 |
| 83 TEST_F(ScriptPromiseTest, castPromise) | 84 TEST_F(ScriptPromiseTest, castPromise) |
| 84 { | 85 { |
| 86 if (RuntimeEnabledFeatures::scriptPromiseOnV8PromiseEnabled()) |
| 87 return; |
| 85 ScriptPromise promise = ScriptPromiseResolver::create(m_isolate)->promise(); | 88 ScriptPromise promise = ScriptPromiseResolver::create(m_isolate)->promise(); |
| 86 ScriptPromise newPromise = ScriptPromise::cast(ScriptValue(promise.v8Value()
, m_isolate)); | 89 ScriptPromise newPromise = ScriptPromise::cast(ScriptValue(promise.v8Value()
, m_isolate)); |
| 87 | 90 |
| 88 ASSERT_FALSE(promise.hasNoValue()); | 91 ASSERT_FALSE(promise.hasNoValue()); |
| 89 EXPECT_EQ(V8PromiseCustom::Pending, state(promise)); | 92 EXPECT_EQ(V8PromiseCustom::Pending, state(promise)); |
| 90 EXPECT_EQ(promise.v8Value(), newPromise.v8Value()); | 93 EXPECT_EQ(promise.v8Value(), newPromise.v8Value()); |
| 91 } | 94 } |
| 92 | 95 |
| 93 TEST_F(ScriptPromiseTest, castNonPromise) | 96 TEST_F(ScriptPromiseTest, castNonPromise) |
| 94 { | 97 { |
| 98 if (RuntimeEnabledFeatures::scriptPromiseOnV8PromiseEnabled()) |
| 99 return; |
| 95 ScriptValue value = ScriptValue(v8String(m_isolate, "hello"), m_isolate); | 100 ScriptValue value = ScriptValue(v8String(m_isolate, "hello"), m_isolate); |
| 96 ScriptPromise promise1 = ScriptPromise::cast(ScriptValue(value.v8Value(), m_
isolate)); | 101 ScriptPromise promise1 = ScriptPromise::cast(ScriptValue(value.v8Value(), m_
isolate)); |
| 97 ScriptPromise promise2 = ScriptPromise::cast(ScriptValue(value.v8Value(), m_
isolate)); | 102 ScriptPromise promise2 = ScriptPromise::cast(ScriptValue(value.v8Value(), m_
isolate)); |
| 98 | 103 |
| 99 ASSERT_FALSE(promise1.hasNoValue()); | 104 ASSERT_FALSE(promise1.hasNoValue()); |
| 100 ASSERT_FALSE(promise2.hasNoValue()); | 105 ASSERT_FALSE(promise2.hasNoValue()); |
| 101 | 106 |
| 102 ASSERT_TRUE(V8PromiseCustom::isPromise(promise1.v8Value(), m_isolate)); | 107 ASSERT_TRUE(V8PromiseCustom::isPromise(promise1.v8Value(), m_isolate)); |
| 103 ASSERT_TRUE(V8PromiseCustom::isPromise(promise2.v8Value(), m_isolate)); | 108 ASSERT_TRUE(V8PromiseCustom::isPromise(promise2.v8Value(), m_isolate)); |
| 104 | 109 |
| 105 EXPECT_EQ(V8PromiseCustom::Fulfilled, state(promise1)); | 110 EXPECT_EQ(V8PromiseCustom::Fulfilled, state(promise1)); |
| 106 EXPECT_EQ(V8PromiseCustom::Fulfilled, state(promise2)); | 111 EXPECT_EQ(V8PromiseCustom::Fulfilled, state(promise2)); |
| 107 EXPECT_NE(promise1.v8Value(), promise2.v8Value()); | 112 EXPECT_NE(promise1.v8Value(), promise2.v8Value()); |
| 108 } | 113 } |
| 109 | 114 |
| 110 } // namespace | 115 } // namespace |
| 111 | 116 |
| 112 } // namespace WebCore | 117 } // namespace WebCore |
| OLD | NEW |