| OLD | NEW | 
|---|
| 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 15626 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 15637   CHECK(i->Equals(CompileRun("'abcbd'.replace(/b/g,func)[3]"))); | 15637   CHECK(i->Equals(CompileRun("'abcbd'.replace(/b/g,func)[3]"))); | 
| 15638 | 15638 | 
| 15639   // TODO(1547): Make the following also return "i". | 15639   // TODO(1547): Make the following also return "i". | 
| 15640   // Calling with environment record as base. | 15640   // Calling with environment record as base. | 
| 15641   TestReceiver(o, context->Global(), "func()"); | 15641   TestReceiver(o, context->Global(), "func()"); | 
| 15642   // Calling with no base. | 15642   // Calling with no base. | 
| 15643   TestReceiver(o, context->Global(), "(1,func)()"); | 15643   TestReceiver(o, context->Global(), "(1,func)()"); | 
| 15644 | 15644 | 
| 15645   foreign_context.Dispose(); | 15645   foreign_context.Dispose(); | 
| 15646 } | 15646 } | 
|  | 15647 | 
|  | 15648 | 
|  | 15649 uint8_t callback_fired = 0; | 
|  | 15650 | 
|  | 15651 | 
|  | 15652 void CallCompletedCallback1() { | 
|  | 15653   printf("Firing callback 1.\n"); | 
|  | 15654   callback_fired ^= 1;  // Toggle first bit. | 
|  | 15655 } | 
|  | 15656 | 
|  | 15657 | 
|  | 15658 void CallCompletedCallback2() { | 
|  | 15659   printf("Firing callback 2.\n"); | 
|  | 15660   callback_fired ^= 2;  // Toggle second bit. | 
|  | 15661 } | 
|  | 15662 | 
|  | 15663 | 
|  | 15664 Handle<Value> RecursiveCall(const Arguments& args) { | 
|  | 15665   uint32_t level = args[0]->Uint32Value(); | 
|  | 15666   if (level < 3) { | 
|  | 15667     level++; | 
|  | 15668     printf("Entering recursion level %d.\n", level); | 
|  | 15669     char script[64]; | 
|  | 15670     snprintf(script, sizeof(script), "recursion(%d)", level); | 
|  | 15671     CompileRun(script); | 
|  | 15672     printf("Leaving recursion level %d.\n", level); | 
|  | 15673     CHECK_EQ(0, callback_fired); | 
|  | 15674   } else { | 
|  | 15675     printf("Recursion ends.\n"); | 
|  | 15676     CHECK_EQ(0, callback_fired); | 
|  | 15677   } | 
|  | 15678   return Undefined(); | 
|  | 15679 } | 
|  | 15680 | 
|  | 15681 | 
|  | 15682 TEST(CallCompletedCallback) { | 
|  | 15683   v8::HandleScope scope; | 
|  | 15684   LocalContext env; | 
|  | 15685   v8::Handle<v8::FunctionTemplate> recursive_runtime = | 
|  | 15686       v8::FunctionTemplate::New(RecursiveCall); | 
|  | 15687   env->Global()->Set(v8_str("recursion"), | 
|  | 15688                      recursive_runtime->GetFunction()); | 
|  | 15689   // Adding the same callback a second time has no effect. | 
|  | 15690   v8::V8::AddCallCompletedCallback(CallCompletedCallback1); | 
|  | 15691   v8::V8::AddCallCompletedCallback(CallCompletedCallback1); | 
|  | 15692   v8::V8::AddCallCompletedCallback(CallCompletedCallback2); | 
|  | 15693   printf("--- Script (1) ---\n"); | 
|  | 15694   Local<Script> script = | 
|  | 15695       v8::Script::Compile(v8::String::New("recursion(0)")); | 
|  | 15696   script->Run(); | 
|  | 15697   CHECK_EQ(3, callback_fired); | 
|  | 15698 | 
|  | 15699   printf("\n--- Script (2) ---\n"); | 
|  | 15700   callback_fired = 0; | 
|  | 15701   v8::V8::RemoveCallCompletedCallback(CallCompletedCallback1); | 
|  | 15702   script->Run(); | 
|  | 15703   CHECK_EQ(2, callback_fired); | 
|  | 15704 | 
|  | 15705   printf("\n--- Function ---\n"); | 
|  | 15706   callback_fired = 0; | 
|  | 15707   Local<Function> recursive_function = | 
|  | 15708       Local<Function>::Cast(env->Global()->Get(v8_str("recursion"))); | 
|  | 15709   v8::Handle<Value> args[] = { v8_num(0) }; | 
|  | 15710   recursive_function->Call(env->Global(), 1, args); | 
|  | 15711   CHECK_EQ(2, callback_fired); | 
|  | 15712 } | 
|  | 15713 | 
|  | 15714 | 
|  | 15715 void CallCompletedCallbackNoException() { | 
|  | 15716   v8::HandleScope scope; | 
|  | 15717   CompileRun("1+1;"); | 
|  | 15718 } | 
|  | 15719 | 
|  | 15720 | 
|  | 15721 void CallCompletedCallbackException() { | 
|  | 15722   v8::HandleScope scope; | 
|  | 15723   CompileRun("throw 'second exception';"); | 
|  | 15724 } | 
|  | 15725 | 
|  | 15726 | 
|  | 15727 TEST(CallCompletedCallbackOneException) { | 
|  | 15728   v8::HandleScope scope; | 
|  | 15729   LocalContext env; | 
|  | 15730   v8::V8::AddCallCompletedCallback(CallCompletedCallbackNoException); | 
|  | 15731   CompileRun("throw 'exception';"); | 
|  | 15732 } | 
|  | 15733 | 
|  | 15734 | 
|  | 15735 TEST(CallCompletedCallbackTwoExceptions) { | 
|  | 15736   v8::HandleScope scope; | 
|  | 15737   LocalContext env; | 
|  | 15738   v8::V8::AddCallCompletedCallback(CallCompletedCallbackException); | 
|  | 15739   CompileRun("throw 'first exception';"); | 
|  | 15740 } | 
| OLD | NEW | 
|---|