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

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

Issue 194663003: API support for promises (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Sven's comments 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/runtime.h ('k') | tools/v8heapconst.py » ('j') | 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 22095 matching lines...) Expand 10 before | Expand all | Expand 10 after
22106 new v8::internal::HistogramTimer( 22106 new v8::internal::HistogramTimer(
22107 "V8.Test", 0, 10000, 50, 22107 "V8.Test", 0, 10000, 50,
22108 reinterpret_cast<v8::internal::Isolate*>(isolate)); 22108 reinterpret_cast<v8::internal::Isolate*>(isolate));
22109 histogramTimer->Start(); 22109 histogramTimer->Start();
22110 CHECK_EQ("V8.Test", last_event_message); 22110 CHECK_EQ("V8.Test", last_event_message);
22111 CHECK_EQ(0, last_event_status); 22111 CHECK_EQ(0, last_event_status);
22112 histogramTimer->Stop(); 22112 histogramTimer->Stop();
22113 CHECK_EQ("V8.Test", last_event_message); 22113 CHECK_EQ("V8.Test", last_event_message);
22114 CHECK_EQ(1, last_event_status); 22114 CHECK_EQ(1, last_event_status);
22115 } 22115 }
22116
22117
22118 TEST(Promises) {
22119 i::FLAG_harmony_promises = true;
22120
22121 LocalContext context;
22122 v8::Isolate* isolate = context->GetIsolate();
22123 v8::HandleScope scope(isolate);
22124 Handle<Object> global = context->Global();
22125
22126 // Creation.
22127 Handle<v8::Promise> p = v8::Promise::New(isolate);
22128 Handle<v8::Promise> r = v8::Promise::New(isolate);
22129
22130 // IsPromise predicate.
22131 CHECK(p->IsPromise());
22132 CHECK(r->IsPromise());
22133 Handle<Value> o = v8::Object::New(isolate);
22134 CHECK(!o->IsPromise());
22135
22136 // Resolution and rejection.
22137 p->Resolve(v8::Integer::New(isolate, 1));
22138 CHECK(p->IsPromise());
22139 r->Reject(v8::Integer::New(isolate, 2));
22140 CHECK(r->IsPromise());
22141
22142 // Chaining non-pending promises.
22143 CompileRun(
22144 "var x1 = 0;\n"
22145 "var x2 = 0;\n"
22146 "function f1(x) { x1 = x; return x+1 };\n"
22147 "function f2(x) { x2 = x; return x+1 };\n");
22148 Handle<Function> f1 = Handle<Function>::Cast(global->Get(v8_str("f1")));
22149 Handle<Function> f2 = Handle<Function>::Cast(global->Get(v8_str("f2")));
22150
22151 p->Chain(f1);
22152 CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value());
22153 V8::RunMicrotasks(isolate);
22154 CHECK_EQ(1, global->Get(v8_str("x1"))->Int32Value());
22155
22156 p->Catch(f2);
22157 V8::RunMicrotasks(isolate);
22158 CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value());
22159
22160 r->Catch(f2);
22161 CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value());
22162 V8::RunMicrotasks(isolate);
22163 CHECK_EQ(2, global->Get(v8_str("x2"))->Int32Value());
22164
22165 r->Chain(f1);
22166 V8::RunMicrotasks(isolate);
22167 CHECK_EQ(1, global->Get(v8_str("x1"))->Int32Value());
22168
22169 // Chaining pending promises.
22170 CompileRun("x1 = x2 = 0;");
22171 p = v8::Promise::New(isolate);
22172 r = v8::Promise::New(isolate);
22173
22174 p->Chain(f1);
22175 r->Catch(f2);
22176 V8::RunMicrotasks(isolate);
22177 CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value());
22178 CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value());
22179
22180 p->Resolve(v8::Integer::New(isolate, 1));
22181 r->Reject(v8::Integer::New(isolate, 2));
22182 CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value());
22183 CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value());
22184
22185 V8::RunMicrotasks(isolate);
22186 CHECK_EQ(1, global->Get(v8_str("x1"))->Int32Value());
22187 CHECK_EQ(2, global->Get(v8_str("x2"))->Int32Value());
22188
22189 // Multi-chaining.
22190 CompileRun("x1 = x2 = 0;");
22191 p = v8::Promise::New(isolate);
22192 p->Chain(f1)->Chain(f2);
22193 p->Resolve(v8::Integer::New(isolate, 3));
22194 CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value());
22195 CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value());
22196 V8::RunMicrotasks(isolate);
22197 CHECK_EQ(3, global->Get(v8_str("x1"))->Int32Value());
22198 CHECK_EQ(4, global->Get(v8_str("x2"))->Int32Value());
22199
22200 CompileRun("x1 = x2 = 0;");
22201 r = v8::Promise::New(isolate);
22202 r->Catch(f1)->Chain(f2);
22203 r->Reject(v8::Integer::New(isolate, 3));
22204 CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value());
22205 CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value());
22206 V8::RunMicrotasks(isolate);
22207 CHECK_EQ(3, global->Get(v8_str("x1"))->Int32Value());
22208 CHECK_EQ(4, global->Get(v8_str("x2"))->Int32Value());
22209 }
OLDNEW
« no previous file with comments | « src/runtime.h ('k') | tools/v8heapconst.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698