OLD | NEW |
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 20723 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
20734 CompileRun("ext1Calls++;"); | 20734 CompileRun("ext1Calls++;"); |
20735 } | 20735 } |
20736 | 20736 |
20737 | 20737 |
20738 static void MicrotaskTwo(const v8::FunctionCallbackInfo<Value>& info) { | 20738 static void MicrotaskTwo(const v8::FunctionCallbackInfo<Value>& info) { |
20739 v8::HandleScope scope(info.GetIsolate()); | 20739 v8::HandleScope scope(info.GetIsolate()); |
20740 CompileRun("ext2Calls++;"); | 20740 CompileRun("ext2Calls++;"); |
20741 } | 20741 } |
20742 | 20742 |
20743 | 20743 |
| 20744 void* g_passed_to_three = NULL; |
| 20745 |
| 20746 |
| 20747 static void MicrotaskThree(void* data) { |
| 20748 g_passed_to_three = data; |
| 20749 } |
| 20750 |
| 20751 |
20744 TEST(EnqueueMicrotask) { | 20752 TEST(EnqueueMicrotask) { |
20745 LocalContext env; | 20753 LocalContext env; |
20746 v8::HandleScope scope(env->GetIsolate()); | 20754 v8::HandleScope scope(env->GetIsolate()); |
20747 CompileRun( | 20755 CompileRun( |
20748 "var ext1Calls = 0;" | 20756 "var ext1Calls = 0;" |
20749 "var ext2Calls = 0;"); | 20757 "var ext2Calls = 0;"); |
20750 CompileRun("1+1;"); | 20758 CompileRun("1+1;"); |
20751 CHECK_EQ(0, CompileRun("ext1Calls")->Int32Value()); | 20759 CHECK_EQ(0, CompileRun("ext1Calls")->Int32Value()); |
20752 CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value()); | 20760 CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value()); |
20753 | 20761 |
(...skipping 13 matching lines...) Expand all Loading... |
20767 | 20775 |
20768 env->GetIsolate()->EnqueueMicrotask( | 20776 env->GetIsolate()->EnqueueMicrotask( |
20769 Function::New(env->GetIsolate(), MicrotaskTwo)); | 20777 Function::New(env->GetIsolate(), MicrotaskTwo)); |
20770 CompileRun("1+1;"); | 20778 CompileRun("1+1;"); |
20771 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value()); | 20779 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value()); |
20772 CHECK_EQ(2, CompileRun("ext2Calls")->Int32Value()); | 20780 CHECK_EQ(2, CompileRun("ext2Calls")->Int32Value()); |
20773 | 20781 |
20774 CompileRun("1+1;"); | 20782 CompileRun("1+1;"); |
20775 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value()); | 20783 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value()); |
20776 CHECK_EQ(2, CompileRun("ext2Calls")->Int32Value()); | 20784 CHECK_EQ(2, CompileRun("ext2Calls")->Int32Value()); |
| 20785 |
| 20786 g_passed_to_three = NULL; |
| 20787 env->GetIsolate()->EnqueueMicrotask(MicrotaskThree); |
| 20788 CompileRun("1+1;"); |
| 20789 CHECK_EQ(NULL, g_passed_to_three); |
| 20790 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value()); |
| 20791 CHECK_EQ(2, CompileRun("ext2Calls")->Int32Value()); |
| 20792 |
| 20793 int dummy; |
| 20794 env->GetIsolate()->EnqueueMicrotask( |
| 20795 Function::New(env->GetIsolate(), MicrotaskOne)); |
| 20796 env->GetIsolate()->EnqueueMicrotask(MicrotaskThree, &dummy); |
| 20797 env->GetIsolate()->EnqueueMicrotask( |
| 20798 Function::New(env->GetIsolate(), MicrotaskTwo)); |
| 20799 CompileRun("1+1;"); |
| 20800 CHECK_EQ(&dummy, g_passed_to_three); |
| 20801 CHECK_EQ(3, CompileRun("ext1Calls")->Int32Value()); |
| 20802 CHECK_EQ(3, CompileRun("ext2Calls")->Int32Value()); |
| 20803 g_passed_to_three = NULL; |
20777 } | 20804 } |
20778 | 20805 |
20779 | 20806 |
20780 static void MicrotaskExceptionOne( | 20807 static void MicrotaskExceptionOne( |
20781 const v8::FunctionCallbackInfo<Value>& info) { | 20808 const v8::FunctionCallbackInfo<Value>& info) { |
20782 v8::HandleScope scope(info.GetIsolate()); | 20809 v8::HandleScope scope(info.GetIsolate()); |
20783 CompileRun("exception1Calls++;"); | 20810 CompileRun("exception1Calls++;"); |
20784 info.GetIsolate()->ThrowException( | 20811 info.GetIsolate()->ThrowException( |
20785 v8::Exception::Error(v8_str("first"))); | 20812 v8::Exception::Error(v8_str("first"))); |
20786 } | 20813 } |
(...skipping 1909 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
22696 Local<Script> script = v8::ScriptCompiler::Compile( | 22723 Local<Script> script = v8::ScriptCompiler::Compile( |
22697 isolate, &script_source); | 22724 isolate, &script_source); |
22698 Local<Value> script_name = script->GetUnboundScript()->GetScriptName(); | 22725 Local<Value> script_name = script->GetUnboundScript()->GetScriptName(); |
22699 CHECK(!script_name.IsEmpty()); | 22726 CHECK(!script_name.IsEmpty()); |
22700 CHECK(script_name->IsString()); | 22727 CHECK(script_name->IsString()); |
22701 String::Utf8Value utf8_name(script_name); | 22728 String::Utf8Value utf8_name(script_name); |
22702 CHECK_EQ(url, *utf8_name); | 22729 CHECK_EQ(url, *utf8_name); |
22703 int line_number = script->GetUnboundScript()->GetLineNumber(0); | 22730 int line_number = script->GetUnboundScript()->GetLineNumber(0); |
22704 CHECK_EQ(13, line_number); | 22731 CHECK_EQ(13, line_number); |
22705 } | 22732 } |
OLD | NEW |