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

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

Issue 2144413004: Removes abuse of createClosure() from ScriptPromiseTest. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 5 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 | « third_party/WebKit/Source/bindings/core/v8/ScriptPromiseResolverTest.cpp ('k') | no next file » | 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 28 matching lines...) Expand all
39 #include "core/testing/NullExecutionContext.h" 39 #include "core/testing/NullExecutionContext.h"
40 #include "testing/gtest/include/gtest/gtest.h" 40 #include "testing/gtest/include/gtest/gtest.h"
41 #include <v8.h> 41 #include <v8.h>
42 42
43 namespace blink { 43 namespace blink {
44 44
45 namespace { 45 namespace {
46 46
47 typedef ScriptPromise::InternalResolver Resolver; 47 typedef ScriptPromise::InternalResolver Resolver;
48 48
49 void callback(const v8::FunctionCallbackInfo<v8::Value>& info) { }
50
51 class Function : public ScriptFunction { 49 class Function : public ScriptFunction {
52 public: 50 public:
53 static v8::Local<v8::Function> createFunction(ScriptState* scriptState, Scri ptValue* output) 51 static v8::Local<v8::Function> createFunction(ScriptState* scriptState, Scri ptValue* output)
54 { 52 {
55 Function* self = new Function(scriptState, output); 53 Function* self = new Function(scriptState, output);
56 return self->bindToV8Function(); 54 return self->bindToV8Function();
57 } 55 }
58 56
59 private: 57 private:
60 Function(ScriptState* scriptState, ScriptValue* output) 58 Function(ScriptState* scriptState, ScriptValue* output)
(...skipping 15 matching lines...) Expand all
76 class TryCatchScope { 74 class TryCatchScope {
77 public: 75 public:
78 explicit TryCatchScope(v8::Isolate* isolate) 76 explicit TryCatchScope(v8::Isolate* isolate)
79 : m_isolate(isolate) 77 : m_isolate(isolate)
80 , m_trycatch(isolate) 78 , m_trycatch(isolate)
81 { 79 {
82 } 80 }
83 81
84 ~TryCatchScope() 82 ~TryCatchScope()
85 { 83 {
86 // FIXME: We put this statement here to clear an exception from the isol ate.
87 createClosure(callback, v8::Undefined(m_isolate), m_isolate);
88
89 // Execute all pending microtasks 84 // Execute all pending microtasks
90 v8::MicrotasksScope::PerformCheckpoint(m_isolate); 85 v8::MicrotasksScope::PerformCheckpoint(m_isolate);
91 } 86 }
92 87
93 bool hasCaught() const { return m_trycatch.HasCaught(); } 88 bool hasCaught() const { return m_trycatch.HasCaught(); }
94 89
95 private: 90 private:
96 v8::Isolate* m_isolate; 91 v8::Isolate* m_isolate;
97 v8::TryCatch m_trycatch; 92 v8::TryCatch m_trycatch;
98 }; 93 };
(...skipping 10 matching lines...) Expand all
109 } 104 }
110 105
111 106
112 TEST(ScriptPromiseTest, constructFromNonPromise) 107 TEST(ScriptPromiseTest, constructFromNonPromise)
113 { 108 {
114 V8TestingScope scope; 109 V8TestingScope scope;
115 TryCatchScope tryCatchScope(scope.isolate()); 110 TryCatchScope tryCatchScope(scope.isolate());
116 ScriptPromise promise(scope.getScriptState(), v8::Undefined(scope.isolate()) ); 111 ScriptPromise promise(scope.getScriptState(), v8::Undefined(scope.isolate()) );
117 ASSERT_TRUE(tryCatchScope.hasCaught()); 112 ASSERT_TRUE(tryCatchScope.hasCaught());
118 ASSERT_TRUE(promise.isEmpty()); 113 ASSERT_TRUE(promise.isEmpty());
114
115 // TODO(yukishiino): We put this statement here to clear an exception from
116 // the isolate. Otherwise, the leak detector complains. Really mysterious
117 // hack.
118 v8::Function::New(scope.context(), nullptr);
haraken 2016/07/21 13:28:28 I'd add this to the destructor of V8TestingScope.
Yuki 2016/07/22 09:10:31 Done.
119 } 119 }
120 120
121 TEST(ScriptPromiseTest, thenResolve) 121 TEST(ScriptPromiseTest, thenResolve)
122 { 122 {
123 V8TestingScope scope; 123 V8TestingScope scope;
124 TryCatchScope tryCatchScope(scope.isolate()); 124 TryCatchScope tryCatchScope(scope.isolate());
125 Resolver resolver(scope.getScriptState()); 125 Resolver resolver(scope.getScriptState());
126 ScriptPromise promise = resolver.promise(); 126 ScriptPromise promise = resolver.promise();
127 ScriptValue onFulfilled, onRejected; 127 ScriptValue onFulfilled, onRejected;
128 promise.then(Function::createFunction(scope.getScriptState(), &onFulfilled), Function::createFunction(scope.getScriptState(), &onRejected)); 128 promise.then(Function::createFunction(scope.getScriptState(), &onFulfilled), Function::createFunction(scope.getScriptState(), &onRejected));
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 v8::MicrotasksScope::PerformCheckpoint(scope.isolate()); 359 v8::MicrotasksScope::PerformCheckpoint(scope.isolate());
360 360
361 EXPECT_TRUE(onFulfilled.isEmpty()); 361 EXPECT_TRUE(onFulfilled.isEmpty());
362 EXPECT_FALSE(onRejected.isEmpty()); 362 EXPECT_FALSE(onRejected.isEmpty());
363 EXPECT_EQ("world", toString(scope.context(), onRejected)); 363 EXPECT_EQ("world", toString(scope.context(), onRejected));
364 } 364 }
365 365
366 } // namespace 366 } // namespace
367 367
368 } // namespace blink 368 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/bindings/core/v8/ScriptPromiseResolverTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698