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

Side by Side Diff: test/cctest/test-api.cc

Issue 196943014: Split Promise API into Promise/Resolver (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 9 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 | « src/api.cc ('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 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 22213 matching lines...) Expand 10 before | Expand all | Expand 10 after
22224 22224
22225 TEST(Promises) { 22225 TEST(Promises) {
22226 i::FLAG_harmony_promises = true; 22226 i::FLAG_harmony_promises = true;
22227 22227
22228 LocalContext context; 22228 LocalContext context;
22229 v8::Isolate* isolate = context->GetIsolate(); 22229 v8::Isolate* isolate = context->GetIsolate();
22230 v8::HandleScope scope(isolate); 22230 v8::HandleScope scope(isolate);
22231 Handle<Object> global = context->Global(); 22231 Handle<Object> global = context->Global();
22232 22232
22233 // Creation. 22233 // Creation.
22234 Handle<v8::Promise> p = v8::Promise::New(isolate); 22234 Handle<v8::Promise::Resolver> pr = v8::Promise::Resolver::New(isolate);
22235 Handle<v8::Promise> r = v8::Promise::New(isolate); 22235 Handle<v8::Promise::Resolver> rr = v8::Promise::Resolver::New(isolate);
22236 Handle<v8::Promise> p = pr->GetPromise();
22237 Handle<v8::Promise> r = rr->GetPromise();
22236 22238
22237 // IsPromise predicate. 22239 // IsPromise predicate.
22238 CHECK(p->IsPromise()); 22240 CHECK(p->IsPromise());
22239 CHECK(r->IsPromise()); 22241 CHECK(r->IsPromise());
22240 Handle<Value> o = v8::Object::New(isolate); 22242 Handle<Value> o = v8::Object::New(isolate);
22241 CHECK(!o->IsPromise()); 22243 CHECK(!o->IsPromise());
22242 22244
22243 // Resolution and rejection. 22245 // Resolution and rejection.
22244 p->Resolve(v8::Integer::New(isolate, 1)); 22246 pr->Resolve(v8::Integer::New(isolate, 1));
22245 CHECK(p->IsPromise()); 22247 CHECK(p->IsPromise());
22246 r->Reject(v8::Integer::New(isolate, 2)); 22248 rr->Reject(v8::Integer::New(isolate, 2));
22247 CHECK(r->IsPromise()); 22249 CHECK(r->IsPromise());
22248 22250
22249 // Chaining non-pending promises. 22251 // Chaining non-pending promises.
22250 CompileRun( 22252 CompileRun(
22251 "var x1 = 0;\n" 22253 "var x1 = 0;\n"
22252 "var x2 = 0;\n" 22254 "var x2 = 0;\n"
22253 "function f1(x) { x1 = x; return x+1 };\n" 22255 "function f1(x) { x1 = x; return x+1 };\n"
22254 "function f2(x) { x2 = x; return x+1 };\n"); 22256 "function f2(x) { x2 = x; return x+1 };\n");
22255 Handle<Function> f1 = Handle<Function>::Cast(global->Get(v8_str("f1"))); 22257 Handle<Function> f1 = Handle<Function>::Cast(global->Get(v8_str("f1")));
22256 Handle<Function> f2 = Handle<Function>::Cast(global->Get(v8_str("f2"))); 22258 Handle<Function> f2 = Handle<Function>::Cast(global->Get(v8_str("f2")));
(...skipping 11 matching lines...) Expand all
22268 CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value()); 22270 CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value());
22269 V8::RunMicrotasks(isolate); 22271 V8::RunMicrotasks(isolate);
22270 CHECK_EQ(2, global->Get(v8_str("x2"))->Int32Value()); 22272 CHECK_EQ(2, global->Get(v8_str("x2"))->Int32Value());
22271 22273
22272 r->Chain(f1); 22274 r->Chain(f1);
22273 V8::RunMicrotasks(isolate); 22275 V8::RunMicrotasks(isolate);
22274 CHECK_EQ(1, global->Get(v8_str("x1"))->Int32Value()); 22276 CHECK_EQ(1, global->Get(v8_str("x1"))->Int32Value());
22275 22277
22276 // Chaining pending promises. 22278 // Chaining pending promises.
22277 CompileRun("x1 = x2 = 0;"); 22279 CompileRun("x1 = x2 = 0;");
22278 p = v8::Promise::New(isolate); 22280 pr = v8::Promise::Resolver::New(isolate);
22279 r = v8::Promise::New(isolate); 22281 rr = v8::Promise::Resolver::New(isolate);
22280 22282
22281 p->Chain(f1); 22283 pr->GetPromise()->Chain(f1);
22282 r->Catch(f2); 22284 rr->GetPromise()->Catch(f2);
22283 V8::RunMicrotasks(isolate); 22285 V8::RunMicrotasks(isolate);
22284 CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value()); 22286 CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value());
22285 CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value()); 22287 CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value());
22286 22288
22287 p->Resolve(v8::Integer::New(isolate, 1)); 22289 pr->Resolve(v8::Integer::New(isolate, 1));
22288 r->Reject(v8::Integer::New(isolate, 2)); 22290 rr->Reject(v8::Integer::New(isolate, 2));
22289 CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value()); 22291 CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value());
22290 CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value()); 22292 CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value());
22291 22293
22292 V8::RunMicrotasks(isolate); 22294 V8::RunMicrotasks(isolate);
22293 CHECK_EQ(1, global->Get(v8_str("x1"))->Int32Value()); 22295 CHECK_EQ(1, global->Get(v8_str("x1"))->Int32Value());
22294 CHECK_EQ(2, global->Get(v8_str("x2"))->Int32Value()); 22296 CHECK_EQ(2, global->Get(v8_str("x2"))->Int32Value());
22295 22297
22296 // Multi-chaining. 22298 // Multi-chaining.
22297 CompileRun("x1 = x2 = 0;"); 22299 CompileRun("x1 = x2 = 0;");
22298 p = v8::Promise::New(isolate); 22300 pr = v8::Promise::Resolver::New(isolate);
22299 p->Chain(f1)->Chain(f2); 22301 pr->GetPromise()->Chain(f1)->Chain(f2);
22300 p->Resolve(v8::Integer::New(isolate, 3)); 22302 pr->Resolve(v8::Integer::New(isolate, 3));
22301 CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value()); 22303 CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value());
22302 CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value()); 22304 CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value());
22303 V8::RunMicrotasks(isolate); 22305 V8::RunMicrotasks(isolate);
22304 CHECK_EQ(3, global->Get(v8_str("x1"))->Int32Value()); 22306 CHECK_EQ(3, global->Get(v8_str("x1"))->Int32Value());
22305 CHECK_EQ(4, global->Get(v8_str("x2"))->Int32Value()); 22307 CHECK_EQ(4, global->Get(v8_str("x2"))->Int32Value());
22306 22308
22307 CompileRun("x1 = x2 = 0;"); 22309 CompileRun("x1 = x2 = 0;");
22308 r = v8::Promise::New(isolate); 22310 rr = v8::Promise::Resolver::New(isolate);
22309 r->Catch(f1)->Chain(f2); 22311 rr->GetPromise()->Catch(f1)->Chain(f2);
22310 r->Reject(v8::Integer::New(isolate, 3)); 22312 rr->Reject(v8::Integer::New(isolate, 3));
22311 CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value()); 22313 CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value());
22312 CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value()); 22314 CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value());
22313 V8::RunMicrotasks(isolate); 22315 V8::RunMicrotasks(isolate);
22314 CHECK_EQ(3, global->Get(v8_str("x1"))->Int32Value()); 22316 CHECK_EQ(3, global->Get(v8_str("x1"))->Int32Value());
22315 CHECK_EQ(4, global->Get(v8_str("x2"))->Int32Value()); 22317 CHECK_EQ(4, global->Get(v8_str("x2"))->Int32Value());
22316 } 22318 }
OLDNEW
« no previous file with comments | « src/api.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698