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

Side by Side Diff: Source/bindings/v8/ScriptPromiseTest.cpp

Issue 273683006: ScriptPromise should understand the ScriptState from which the ScriptPromise is generated (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « Source/bindings/v8/ScriptPromiseResolverWithContext.cpp ('k') | Source/bindings/v8/V8Binding.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 43
44 namespace WebCore { 44 namespace WebCore {
45 45
46 namespace { 46 namespace {
47 47
48 void callback(const v8::FunctionCallbackInfo<v8::Value>& info) { } 48 void callback(const v8::FunctionCallbackInfo<v8::Value>& info) { }
49 49
50 class ScriptPromiseTest : public testing::Test { 50 class ScriptPromiseTest : public testing::Test {
51 public: 51 public:
52 ScriptPromiseTest() 52 ScriptPromiseTest()
53 : m_isolate(v8::Isolate::GetCurrent()) 53 : m_scope(V8ExecutionScope::create(v8::Isolate::GetCurrent()))
54 { 54 {
55 m_scope = V8ExecutionScope::create(m_isolate);
56 } 55 }
57 56
58 ~ScriptPromiseTest() 57 ~ScriptPromiseTest()
59 { 58 {
60 // FIXME: We put this statement here to clear an exception from the isol ate. 59 // FIXME: We put this statement here to clear an exception from the isol ate.
61 createClosure(callback, v8::Undefined(m_isolate), m_isolate); 60 createClosure(callback, v8::Undefined(m_scope->isolate()), m_scope->isol ate());
62 } 61 }
63 62
64 V8PromiseCustom::PromiseState state(ScriptPromise promise) 63 V8PromiseCustom::PromiseState state(ScriptPromise promise)
65 { 64 {
66 return V8PromiseCustom::getState(V8PromiseCustom::getInternal(promise.v8 Value().As<v8::Object>())); 65 return V8PromiseCustom::getState(V8PromiseCustom::getInternal(promise.v8 Value().As<v8::Object>()));
67 } 66 }
68 67
69 protected: 68 protected:
70 v8::Isolate* m_isolate;
71
72 private:
73 OwnPtr<V8ExecutionScope> m_scope; 69 OwnPtr<V8ExecutionScope> m_scope;
74 }; 70 };
75 71
76 TEST_F(ScriptPromiseTest, constructFromNonPromise) 72 TEST_F(ScriptPromiseTest, constructFromNonPromise)
77 { 73 {
78 v8::TryCatch trycatch; 74 v8::TryCatch trycatch;
79 ScriptPromise promise(v8::Undefined(m_isolate), m_isolate); 75 ScriptPromise promise(m_scope->scriptState(), v8::Undefined(m_scope->isolate ()));
80 ASSERT_TRUE(trycatch.HasCaught()); 76 ASSERT_TRUE(trycatch.HasCaught());
81 ASSERT_TRUE(promise.isEmpty()); 77 ASSERT_TRUE(promise.isEmpty());
82 } 78 }
83 79
84 TEST_F(ScriptPromiseTest, castPromise) 80 TEST_F(ScriptPromiseTest, castPromise)
85 { 81 {
86 if (RuntimeEnabledFeatures::scriptPromiseOnV8PromiseEnabled()) 82 if (RuntimeEnabledFeatures::scriptPromiseOnV8PromiseEnabled())
87 return; 83 return;
88 ScriptPromise promise = ScriptPromiseResolver::create(m_isolate)->promise(); 84 ScriptPromise promise = ScriptPromiseResolver::create(m_scope->scriptState() )->promise();
89 ScriptPromise newPromise = ScriptPromise::cast(ScriptValue(ScriptState::curr ent(m_isolate), promise.v8Value())); 85 ScriptPromise newPromise = ScriptPromise::cast(ScriptValue(m_scope->scriptSt ate(), promise.v8Value()));
90 86
91 ASSERT_FALSE(promise.isEmpty()); 87 ASSERT_FALSE(promise.isEmpty());
92 EXPECT_EQ(V8PromiseCustom::Pending, state(promise)); 88 EXPECT_EQ(V8PromiseCustom::Pending, state(promise));
93 EXPECT_EQ(promise.v8Value(), newPromise.v8Value()); 89 EXPECT_EQ(promise.v8Value(), newPromise.v8Value());
94 } 90 }
95 91
96 TEST_F(ScriptPromiseTest, castNonPromise) 92 TEST_F(ScriptPromiseTest, castNonPromise)
97 { 93 {
98 if (RuntimeEnabledFeatures::scriptPromiseOnV8PromiseEnabled()) 94 if (RuntimeEnabledFeatures::scriptPromiseOnV8PromiseEnabled())
99 return; 95 return;
100 ScriptValue value = ScriptValue(ScriptState::current(m_isolate), v8String(m_ isolate, "hello")); 96 ScriptValue value = ScriptValue(m_scope->scriptState(), v8String(m_scope->is olate(), "hello"));
101 ScriptPromise promise1 = ScriptPromise::cast(ScriptValue(value)); 97 ScriptPromise promise1 = ScriptPromise::cast(ScriptValue(value));
102 ScriptPromise promise2 = ScriptPromise::cast(ScriptValue(value)); 98 ScriptPromise promise2 = ScriptPromise::cast(ScriptValue(value));
103 99
104 ASSERT_FALSE(promise1.isEmpty()); 100 ASSERT_FALSE(promise1.isEmpty());
105 ASSERT_FALSE(promise2.isEmpty()); 101 ASSERT_FALSE(promise2.isEmpty());
106 102
107 ASSERT_TRUE(V8PromiseCustom::isPromise(promise1.v8Value(), m_isolate)); 103 ASSERT_TRUE(V8PromiseCustom::isPromise(promise1.v8Value(), m_scope->isolate( )));
108 ASSERT_TRUE(V8PromiseCustom::isPromise(promise2.v8Value(), m_isolate)); 104 ASSERT_TRUE(V8PromiseCustom::isPromise(promise2.v8Value(), m_scope->isolate( )));
109 105
110 EXPECT_EQ(V8PromiseCustom::Fulfilled, state(promise1)); 106 EXPECT_EQ(V8PromiseCustom::Fulfilled, state(promise1));
111 EXPECT_EQ(V8PromiseCustom::Fulfilled, state(promise2)); 107 EXPECT_EQ(V8PromiseCustom::Fulfilled, state(promise2));
112 EXPECT_NE(promise1.v8Value(), promise2.v8Value()); 108 EXPECT_NE(promise1.v8Value(), promise2.v8Value());
113 } 109 }
114 110
115 } // namespace 111 } // namespace
116 112
117 } // namespace WebCore 113 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/bindings/v8/ScriptPromiseResolverWithContext.cpp ('k') | Source/bindings/v8/V8Binding.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698