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

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

Issue 109013: Add the ability to set embedder data on created contexts from the API (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years, 7 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/debug.cc ('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 2007-2008 the V8 project authors. All rights reserved. 1 // Copyright 2007-2008 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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 160
161 // Compile and run the supplied source and return the fequested function. 161 // Compile and run the supplied source and return the fequested function.
162 static v8::Local<v8::Function> CompileFunction(DebugLocalContext* env, 162 static v8::Local<v8::Function> CompileFunction(DebugLocalContext* env,
163 const char* source, 163 const char* source,
164 const char* function_name) { 164 const char* function_name) {
165 v8::Script::Compile(v8::String::New(source))->Run(); 165 v8::Script::Compile(v8::String::New(source))->Run();
166 return v8::Local<v8::Function>::Cast( 166 return v8::Local<v8::Function>::Cast(
167 (*env)->Global()->Get(v8::String::New(function_name))); 167 (*env)->Global()->Get(v8::String::New(function_name)));
168 } 168 }
169 169
170
171 // Compile and run the supplied source and return the requested function.
172 static v8::Local<v8::Function> CompileFunction(const char* source,
173 const char* function_name) {
174
175 v8::Script::Compile(v8::String::New(source))->Run();
176 return v8::Local<v8::Function>::Cast(
177 v8::Context::GetCurrent()->Global()->Get(v8::String::New(function_name)));
178 }
179
180
170 // Helper function that compiles and runs the source. 181 // Helper function that compiles and runs the source.
171 static v8::Local<v8::Value> CompileRun(const char* source) { 182 static v8::Local<v8::Value> CompileRun(const char* source) {
172 return v8::Script::Compile(v8::String::New(source))->Run(); 183 return v8::Script::Compile(v8::String::New(source))->Run();
173 } 184 }
174 185
186
175 // Is there any debug info for the function? 187 // Is there any debug info for the function?
176 static bool HasDebugInfo(v8::Handle<v8::Function> fun) { 188 static bool HasDebugInfo(v8::Handle<v8::Function> fun) {
177 Handle<v8::internal::JSFunction> f = v8::Utils::OpenHandle(*fun); 189 Handle<v8::internal::JSFunction> f = v8::Utils::OpenHandle(*fun);
178 Handle<v8::internal::SharedFunctionInfo> shared(f->shared()); 190 Handle<v8::internal::SharedFunctionInfo> shared(f->shared());
179 return Debug::HasDebugInfo(shared); 191 return Debug::HasDebugInfo(shared);
180 } 192 }
181 193
182 194
183 // Set a break point in a function and return the associated break point 195 // Set a break point in a function and return the associated break point
184 // number. 196 // number.
(...skipping 4396 matching lines...) Expand 10 before | Expand all | Expand 10 after
4581 v8::ScriptOrigin origin2 = v8::ScriptOrigin(v8::String::New("new name")); 4593 v8::ScriptOrigin origin2 = v8::ScriptOrigin(v8::String::New("new name"));
4582 v8::Handle<v8::Script> script2 = v8::Script::Compile(script, &origin2); 4594 v8::Handle<v8::Script> script2 = v8::Script::Compile(script, &origin2);
4583 script2->Run(); 4595 script2->Run();
4584 script2->SetData(data_obj); 4596 script2->SetData(data_obj);
4585 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); 4597 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));
4586 f->Call(env->Global(), 0, NULL); 4598 f->Call(env->Global(), 0, NULL);
4587 CHECK_EQ(2, break_point_hit_count); 4599 CHECK_EQ(2, break_point_hit_count);
4588 CHECK_EQ("new name", last_script_name_hit); 4600 CHECK_EQ("new name", last_script_name_hit);
4589 CHECK_EQ("abc 123", last_script_data_hit); 4601 CHECK_EQ("abc 123", last_script_data_hit);
4590 } 4602 }
4603
4604
4605 static v8::Persistent<v8::Context> expected_context;
4606 static v8::Handle<v8::Value> expected_context_data;
4607
4608
4609 // Check that the expected context is the one generating the debug event.
4610 static void ContextCheckMessageHandler(const v8::Debug::Message& message) {
4611 CHECK(message.GetEventContext() == expected_context);
4612 CHECK(message.GetEventContext()->GetData()->StrictEquals(
4613 expected_context_data));
4614 message_handler_hit_count++;
4615
4616 const int kBufferSize = 1000;
4617 uint16_t buffer[kBufferSize];
4618 const char* command_continue =
4619 "{\"seq\":0,"
4620 "\"type\":\"request\","
4621 "\"command\":\"continue\"}";
4622
4623 // Send a continue command for break events.
4624 if (message.GetEvent() == v8::Break) {
4625 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_continue, buffer));
4626 }
4627 }
4628
4629
4630 // Test which creates two contexts and sets different embedder data on each.
4631 // Checks that this data is set correctly and that when the debug message
4632 // handler is called the expected context is the one active.
4633 TEST(ContextData) {
4634 v8::HandleScope scope;
4635
4636 v8::Debug::SetMessageHandler2(ContextCheckMessageHandler);
4637
4638 // Create two contexts.
4639 v8::Persistent<v8::Context> context_1;
4640 v8::Persistent<v8::Context> context_2;
4641 v8::Handle<v8::ObjectTemplate> global_template =
4642 v8::Handle<v8::ObjectTemplate>();
4643 v8::Handle<v8::Value> global_object = v8::Handle<v8::Value>();
4644 context_1 = v8::Context::New(NULL, global_template, global_object);
4645 context_2 = v8::Context::New(NULL, global_template, global_object);
4646
4647 // Default data value is undefined.
4648 CHECK(context_1->GetData()->IsUndefined());
4649 CHECK(context_2->GetData()->IsUndefined());
4650
4651 // Set and check different data values.
4652 v8::Handle<v8::Value> data_1 = v8::Number::New(1);
4653 v8::Handle<v8::Value> data_2 = v8::String::New("2");
4654 context_1->SetData(data_1);
4655 context_2->SetData(data_2);
4656 CHECK(context_1->GetData()->StrictEquals(data_1));
4657 CHECK(context_2->GetData()->StrictEquals(data_2));
4658
4659 // Simple test function which causes a break.
4660 char* source = "function f() { debugger; }";
4661
4662 // Enter and run function in the first context.
4663 {
4664 v8::Context::Scope context_scope(context_1);
4665 expected_context = context_1;
4666 expected_context_data = data_1;
4667 v8::Local<v8::Function> f = CompileFunction(source, "f");
4668 f->Call(context_1->Global(), 0, NULL);
4669 }
4670
4671
4672 // Enter and run function in the second context.
4673 {
4674 v8::Context::Scope context_scope(context_2);
4675 expected_context = context_2;
4676 expected_context_data = data_2;
4677 v8::Local<v8::Function> f = CompileFunction(source, "f");
4678 f->Call(context_2->Global(), 0, NULL);
4679 }
4680
4681 // Two times compile event and two times break event.
4682 CHECK_GT(message_handler_hit_count, 4);
4683 }
OLDNEW
« no previous file with comments | « src/debug.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698