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

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

Issue 314553002: Add v8::Promise::Then. (Closed) Base URL: https://chromium.googlesource.com/external/v8.git@master
Patch Set: Created 6 years, 6 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 | « src/promise.js ('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 22574 matching lines...) Expand 10 before | Expand all | Expand 10 after
22585 rr->GetPromise()->Catch(f1)->Chain(f2); 22585 rr->GetPromise()->Catch(f1)->Chain(f2);
22586 rr->Reject(v8::Integer::New(isolate, 3)); 22586 rr->Reject(v8::Integer::New(isolate, 3));
22587 CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value()); 22587 CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value());
22588 CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value()); 22588 CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value());
22589 isolate->RunMicrotasks(); 22589 isolate->RunMicrotasks();
22590 CHECK_EQ(3, global->Get(v8_str("x1"))->Int32Value()); 22590 CHECK_EQ(3, global->Get(v8_str("x1"))->Int32Value());
22591 CHECK_EQ(4, global->Get(v8_str("x2"))->Int32Value()); 22591 CHECK_EQ(4, global->Get(v8_str("x2"))->Int32Value());
22592 } 22592 }
22593 22593
22594 22594
22595 TEST(PromiseThen) {
22596 LocalContext context;
22597 v8::Isolate* isolate = context->GetIsolate();
22598 v8::HandleScope scope(isolate);
22599 Handle<Object> global = context->Global();
22600
22601 // Creation.
22602 Handle<v8::Promise::Resolver> pr = v8::Promise::Resolver::New(isolate);
22603 Handle<v8::Promise::Resolver> qr = v8::Promise::Resolver::New(isolate);
22604 Handle<v8::Promise> p = pr->GetPromise();
22605 Handle<v8::Promise> q = qr->GetPromise();
22606
22607 CHECK(p->IsPromise());
22608 CHECK(q->IsPromise());
22609
22610 pr->Resolve(v8::Integer::New(isolate, 1));
22611 qr->Resolve(p);
22612
22613 // Chaining non-pending promises.
22614 CompileRun(
22615 "var x1 = 0;\n"
22616 "var x2 = 0;\n"
22617 "function f1(x) { x1 = x; return x+1 };\n"
22618 "function f2(x) { x2 = x; return x+1 };\n");
22619 Handle<Function> f1 = Handle<Function>::Cast(global->Get(v8_str("f1")));
22620 Handle<Function> f2 = Handle<Function>::Cast(global->Get(v8_str("f2")));
22621
22622 // Chain
22623 q->Chain(f1);
22624 CHECK(global->Get(v8_str("x1"))->IsNumber());
22625 CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value());
22626 isolate->RunMicrotasks();
22627 CHECK(!global->Get(v8_str("x1"))->IsNumber());
22628 CHECK_EQ(p, global->Get(v8_str("x1")));
22629
22630 // Then
22631 CompileRun("x1 = x2 = 0;");
22632 q->Then(f1);
22633 CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value());
22634 isolate->RunMicrotasks();
22635 CHECK_EQ(1, global->Get(v8_str("x1"))->Int32Value());
22636
22637 // Then
22638 CompileRun("x1 = x2 = 0;");
22639 pr = v8::Promise::Resolver::New(isolate);
22640 qr = v8::Promise::Resolver::New(isolate);
22641
22642 qr->Resolve(pr);
22643 qr->GetPromise()->Then(f1)->Then(f2);
22644
22645 CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value());
22646 CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value());
22647 isolate->RunMicrotasks();
22648 CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value());
22649 CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value());
22650
22651 pr->Resolve(v8::Integer::New(isolate, 3));
22652
22653 CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value());
22654 CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value());
22655 isolate->RunMicrotasks();
22656 CHECK_EQ(3, global->Get(v8_str("x1"))->Int32Value());
22657 CHECK_EQ(4, global->Get(v8_str("x2"))->Int32Value());
22658 }
22659
22660
22595 TEST(DisallowJavascriptExecutionScope) { 22661 TEST(DisallowJavascriptExecutionScope) {
22596 LocalContext context; 22662 LocalContext context;
22597 v8::Isolate* isolate = context->GetIsolate(); 22663 v8::Isolate* isolate = context->GetIsolate();
22598 v8::HandleScope scope(isolate); 22664 v8::HandleScope scope(isolate);
22599 v8::Isolate::DisallowJavascriptExecutionScope no_js( 22665 v8::Isolate::DisallowJavascriptExecutionScope no_js(
22600 isolate, v8::Isolate::DisallowJavascriptExecutionScope::CRASH_ON_FAILURE); 22666 isolate, v8::Isolate::DisallowJavascriptExecutionScope::CRASH_ON_FAILURE);
22601 CompileRun("2+2"); 22667 CompileRun("2+2");
22602 } 22668 }
22603 22669
22604 22670
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
22696 Local<Script> script = v8::ScriptCompiler::Compile( 22762 Local<Script> script = v8::ScriptCompiler::Compile(
22697 isolate, &script_source); 22763 isolate, &script_source);
22698 Local<Value> script_name = script->GetUnboundScript()->GetScriptName(); 22764 Local<Value> script_name = script->GetUnboundScript()->GetScriptName();
22699 CHECK(!script_name.IsEmpty()); 22765 CHECK(!script_name.IsEmpty());
22700 CHECK(script_name->IsString()); 22766 CHECK(script_name->IsString());
22701 String::Utf8Value utf8_name(script_name); 22767 String::Utf8Value utf8_name(script_name);
22702 CHECK_EQ(url, *utf8_name); 22768 CHECK_EQ(url, *utf8_name);
22703 int line_number = script->GetUnboundScript()->GetLineNumber(0); 22769 int line_number = script->GetUnboundScript()->GetLineNumber(0);
22704 CHECK_EQ(13, line_number); 22770 CHECK_EQ(13, line_number);
22705 } 22771 }
OLDNEW
« no previous file with comments | « src/promise.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698