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

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

Issue 8983014: Fix windows build. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Changing to signed int. Created 8 years, 11 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 | « no previous file | 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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 15714 matching lines...) Expand 10 before | Expand all | Expand 10 after
15725 TestReceiver(o, context->Global(), "(1,func)()"); 15725 TestReceiver(o, context->Global(), "(1,func)()");
15726 15726
15727 foreign_context.Dispose(); 15727 foreign_context.Dispose();
15728 } 15728 }
15729 15729
15730 15730
15731 uint8_t callback_fired = 0; 15731 uint8_t callback_fired = 0;
15732 15732
15733 15733
15734 void CallCompletedCallback1() { 15734 void CallCompletedCallback1() {
15735 printf("Firing callback 1.\n"); 15735 i::OS::Print("Firing callback 1.\n");
15736 callback_fired ^= 1; // Toggle first bit. 15736 callback_fired ^= 1; // Toggle first bit.
15737 } 15737 }
15738 15738
15739 15739
15740 void CallCompletedCallback2() { 15740 void CallCompletedCallback2() {
15741 printf("Firing callback 2.\n"); 15741 i::OS::Print("Firing callback 2.\n");
15742 callback_fired ^= 2; // Toggle second bit. 15742 callback_fired ^= 2; // Toggle second bit.
15743 } 15743 }
15744 15744
15745 15745
15746 Handle<Value> RecursiveCall(const Arguments& args) { 15746 Handle<Value> RecursiveCall(const Arguments& args) {
15747 uint32_t level = args[0]->Uint32Value(); 15747 int level = args[0]->Int32Value();
15748 if (level < 3) { 15748 if (level < 3) {
15749 level++; 15749 level++;
15750 printf("Entering recursion level %d.\n", level); 15750 i::OS::Print("Entering recursion level %d.\n", level);
15751 char script[64]; 15751 char script[64];
15752 snprintf(script, sizeof(script), "recursion(%d)", level); 15752 i::Vector<char> script_vector(script, sizeof(script));
15753 CompileRun(script); 15753 i::OS::SNPrintF(script_vector, "recursion(%d)", level);
15754 printf("Leaving recursion level %d.\n", level); 15754 CompileRun(script_vector.start());
15755 i::OS::Print("Leaving recursion level %d.\n", level);
15755 CHECK_EQ(0, callback_fired); 15756 CHECK_EQ(0, callback_fired);
15756 } else { 15757 } else {
15757 printf("Recursion ends.\n"); 15758 i::OS::Print("Recursion ends.\n");
15758 CHECK_EQ(0, callback_fired); 15759 CHECK_EQ(0, callback_fired);
15759 } 15760 }
15760 return Undefined(); 15761 return Undefined();
15761 } 15762 }
15762 15763
15763 15764
15764 TEST(CallCompletedCallback) { 15765 TEST(CallCompletedCallback) {
15765 v8::HandleScope scope; 15766 v8::HandleScope scope;
15766 LocalContext env; 15767 LocalContext env;
15767 v8::Handle<v8::FunctionTemplate> recursive_runtime = 15768 v8::Handle<v8::FunctionTemplate> recursive_runtime =
15768 v8::FunctionTemplate::New(RecursiveCall); 15769 v8::FunctionTemplate::New(RecursiveCall);
15769 env->Global()->Set(v8_str("recursion"), 15770 env->Global()->Set(v8_str("recursion"),
15770 recursive_runtime->GetFunction()); 15771 recursive_runtime->GetFunction());
15771 // Adding the same callback a second time has no effect. 15772 // Adding the same callback a second time has no effect.
15772 v8::V8::AddCallCompletedCallback(CallCompletedCallback1); 15773 v8::V8::AddCallCompletedCallback(CallCompletedCallback1);
15773 v8::V8::AddCallCompletedCallback(CallCompletedCallback1); 15774 v8::V8::AddCallCompletedCallback(CallCompletedCallback1);
15774 v8::V8::AddCallCompletedCallback(CallCompletedCallback2); 15775 v8::V8::AddCallCompletedCallback(CallCompletedCallback2);
15775 printf("--- Script (1) ---\n"); 15776 i::OS::Print("--- Script (1) ---\n");
15776 Local<Script> script = 15777 Local<Script> script =
15777 v8::Script::Compile(v8::String::New("recursion(0)")); 15778 v8::Script::Compile(v8::String::New("recursion(0)"));
15778 script->Run(); 15779 script->Run();
15779 CHECK_EQ(3, callback_fired); 15780 CHECK_EQ(3, callback_fired);
15780 15781
15781 printf("\n--- Script (2) ---\n"); 15782 i::OS::Print("\n--- Script (2) ---\n");
15782 callback_fired = 0; 15783 callback_fired = 0;
15783 v8::V8::RemoveCallCompletedCallback(CallCompletedCallback1); 15784 v8::V8::RemoveCallCompletedCallback(CallCompletedCallback1);
15784 script->Run(); 15785 script->Run();
15785 CHECK_EQ(2, callback_fired); 15786 CHECK_EQ(2, callback_fired);
15786 15787
15787 printf("\n--- Function ---\n"); 15788 i::OS::Print("\n--- Function ---\n");
15788 callback_fired = 0; 15789 callback_fired = 0;
15789 Local<Function> recursive_function = 15790 Local<Function> recursive_function =
15790 Local<Function>::Cast(env->Global()->Get(v8_str("recursion"))); 15791 Local<Function>::Cast(env->Global()->Get(v8_str("recursion")));
15791 v8::Handle<Value> args[] = { v8_num(0) }; 15792 v8::Handle<Value> args[] = { v8_num(0) };
15792 recursive_function->Call(env->Global(), 1, args); 15793 recursive_function->Call(env->Global(), 1, args);
15793 CHECK_EQ(2, callback_fired); 15794 CHECK_EQ(2, callback_fired);
15794 } 15795 }
15795 15796
15796 15797
15797 void CallCompletedCallbackNoException() { 15798 void CallCompletedCallbackNoException() {
(...skipping 15 matching lines...) Expand all
15813 CompileRun("throw 'exception';"); 15814 CompileRun("throw 'exception';");
15814 } 15815 }
15815 15816
15816 15817
15817 TEST(CallCompletedCallbackTwoExceptions) { 15818 TEST(CallCompletedCallbackTwoExceptions) {
15818 v8::HandleScope scope; 15819 v8::HandleScope scope;
15819 LocalContext env; 15820 LocalContext env;
15820 v8::V8::AddCallCompletedCallback(CallCompletedCallbackException); 15821 v8::V8::AddCallCompletedCallback(CallCompletedCallbackException);
15821 CompileRun("throw 'first exception';"); 15822 CompileRun("throw 'first exception';");
15822 } 15823 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698