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

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

Issue 14793004: deprecate Context::New which returns Persistent (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: use Reset instead of operator= Created 7 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 | « test/cctest/test-api.cc ('k') | test/cctest/test-decls.cc » ('j') | 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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 129
130 130
131 // Helper class for creating a V8 enviromnent for running tests 131 // Helper class for creating a V8 enviromnent for running tests
132 class DebugLocalContext { 132 class DebugLocalContext {
133 public: 133 public:
134 inline DebugLocalContext( 134 inline DebugLocalContext(
135 v8::ExtensionConfiguration* extensions = 0, 135 v8::ExtensionConfiguration* extensions = 0,
136 v8::Handle<v8::ObjectTemplate> global_template = 136 v8::Handle<v8::ObjectTemplate> global_template =
137 v8::Handle<v8::ObjectTemplate>(), 137 v8::Handle<v8::ObjectTemplate>(),
138 v8::Handle<v8::Value> global_object = v8::Handle<v8::Value>()) 138 v8::Handle<v8::Value> global_object = v8::Handle<v8::Value>())
139 : context_(v8::Context::New(extensions, global_template, global_object)) { 139 : scope_(v8::Isolate::GetCurrent()),
140 context_(
141 v8::Context::New(v8::Isolate::GetCurrent(),
142 extensions,
143 global_template,
144 global_object)) {
140 context_->Enter(); 145 context_->Enter();
141 } 146 }
142 inline ~DebugLocalContext() { 147 inline ~DebugLocalContext() {
143 context_->Exit(); 148 context_->Exit();
144 context_.Dispose(context_->GetIsolate());
145 } 149 }
146 inline v8::Context* operator->() { return *context_; } 150 inline v8::Context* operator->() { return *context_; }
147 inline v8::Context* operator*() { return *context_; } 151 inline v8::Context* operator*() { return *context_; }
148 inline bool IsReady() { return !context_.IsEmpty(); } 152 inline bool IsReady() { return !context_.IsEmpty(); }
149 void ExposeDebug() { 153 void ExposeDebug() {
150 v8::internal::Isolate* isolate = 154 v8::internal::Isolate* isolate =
151 reinterpret_cast<v8::internal::Isolate*>(context_->GetIsolate()); 155 reinterpret_cast<v8::internal::Isolate*>(context_->GetIsolate());
152 v8::internal::Debug* debug = isolate->debug(); 156 v8::internal::Debug* debug = isolate->debug();
153 // Expose the debug context global object in the global object for testing. 157 // Expose the debug context global object in the global object for testing.
154 debug->Load(); 158 debug->Load();
155 debug->debug_context()->set_security_token( 159 debug->debug_context()->set_security_token(
156 v8::Utils::OpenHandle(*context_)->security_token()); 160 v8::Utils::OpenHandle(*context_)->security_token());
157 161
158 Handle<JSGlobalProxy> global(Handle<JSGlobalProxy>::cast( 162 Handle<JSGlobalProxy> global(Handle<JSGlobalProxy>::cast(
159 v8::Utils::OpenHandle(*context_->Global()))); 163 v8::Utils::OpenHandle(*context_->Global())));
160 Handle<v8::internal::String> debug_string = 164 Handle<v8::internal::String> debug_string =
161 FACTORY->InternalizeOneByteString(STATIC_ASCII_VECTOR("debug")); 165 FACTORY->InternalizeOneByteString(STATIC_ASCII_VECTOR("debug"));
162 SetProperty(isolate, global, debug_string, 166 SetProperty(isolate, global, debug_string,
163 Handle<Object>(debug->debug_context()->global_proxy(), isolate), 167 Handle<Object>(debug->debug_context()->global_proxy(), isolate),
164 DONT_ENUM, 168 DONT_ENUM,
165 ::v8::internal::kNonStrictMode); 169 ::v8::internal::kNonStrictMode);
166 } 170 }
167 171
168 private: 172 private:
169 v8::Persistent<v8::Context> context_; 173 v8::HandleScope scope_;
174 v8::Local<v8::Context> context_;
170 }; 175 };
171 176
172 177
173 // --- H e l p e r F u n c t i o n s 178 // --- H e l p e r F u n c t i o n s
174 179
175 180
176 // Compile and run the supplied source and return the fequested function. 181 // Compile and run the supplied source and return the fequested function.
177 static v8::Local<v8::Function> CompileFunction(DebugLocalContext* env, 182 static v8::Local<v8::Function> CompileFunction(DebugLocalContext* env,
178 const char* source, 183 const char* source,
179 const char* function_name) { 184 const char* function_name) {
(...skipping 4047 matching lines...) Expand 10 before | Expand all | Expand 10 after
4227 } 4232 }
4228 4233
4229 static const char* kSimpleExtensionSource = 4234 static const char* kSimpleExtensionSource =
4230 "(function Foo() {" 4235 "(function Foo() {"
4231 " return 4;" 4236 " return 4;"
4232 "})() "; 4237 "})() ";
4233 4238
4234 // http://crbug.com/28933 4239 // http://crbug.com/28933
4235 // Test that debug break is disabled when bootstrapper is active. 4240 // Test that debug break is disabled when bootstrapper is active.
4236 TEST(NoBreakWhenBootstrapping) { 4241 TEST(NoBreakWhenBootstrapping) {
4237 v8::HandleScope scope(v8::Isolate::GetCurrent()); 4242 v8::Isolate* isolate = v8::Isolate::GetCurrent();
4243 v8::HandleScope scope(isolate);
4238 4244
4239 // Register a debug event listener which sets the break flag and counts. 4245 // Register a debug event listener which sets the break flag and counts.
4240 v8::Debug::SetDebugEventListener(DebugEventCounter); 4246 v8::Debug::SetDebugEventListener(DebugEventCounter);
4241 4247
4242 // Set the debug break flag. 4248 // Set the debug break flag.
4243 v8::Debug::DebugBreak(); 4249 v8::Debug::DebugBreak();
4244 break_point_hit_count = 0; 4250 break_point_hit_count = 0;
4245 { 4251 {
4246 // Create a context with an extension to make sure that some JavaScript 4252 // Create a context with an extension to make sure that some JavaScript
4247 // code is executed during bootstrapping. 4253 // code is executed during bootstrapping.
4248 v8::RegisterExtension(new v8::Extension("simpletest", 4254 v8::RegisterExtension(new v8::Extension("simpletest",
4249 kSimpleExtensionSource)); 4255 kSimpleExtensionSource));
4250 const char* extension_names[] = { "simpletest" }; 4256 const char* extension_names[] = { "simpletest" };
4251 v8::ExtensionConfiguration extensions(1, extension_names); 4257 v8::ExtensionConfiguration extensions(1, extension_names);
4252 v8::Persistent<v8::Context> context = v8::Context::New(&extensions); 4258 v8::HandleScope handle_scope(isolate);
4253 context.Dispose(context->GetIsolate()); 4259 v8::Context::New(isolate, &extensions);
4254 } 4260 }
4255 // Check that no DebugBreak events occured during the context creation. 4261 // Check that no DebugBreak events occured during the context creation.
4256 CHECK_EQ(0, break_point_hit_count); 4262 CHECK_EQ(0, break_point_hit_count);
4257 4263
4258 // Get rid of the debug event listener. 4264 // Get rid of the debug event listener.
4259 v8::Debug::SetDebugEventListener(NULL); 4265 v8::Debug::SetDebugEventListener(NULL);
4260 CheckDebuggerUnloaded(); 4266 CheckDebuggerUnloaded();
4261 } 4267 }
4262 4268
4263 static v8::Handle<v8::Array> NamedEnum(const v8::AccessorInfo&) { 4269 static v8::Handle<v8::Array> NamedEnum(const v8::AccessorInfo&) {
(...skipping 1964 matching lines...) Expand 10 before | Expand all | Expand 10 after
6228 v8::String::New("in compile")); 6234 v8::String::New("in compile"));
6229 CHECK_EQ("in compile", last_script_data_hit); 6235 CHECK_EQ("in compile", last_script_data_hit);
6230 script3->Run(); 6236 script3->Run();
6231 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); 6237 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));
6232 f->Call(env->Global(), 0, NULL); 6238 f->Call(env->Global(), 0, NULL);
6233 CHECK_EQ(4, break_point_hit_count); 6239 CHECK_EQ(4, break_point_hit_count);
6234 CHECK_EQ("in compile", last_script_data_hit); 6240 CHECK_EQ("in compile", last_script_data_hit);
6235 } 6241 }
6236 6242
6237 6243
6238 static v8::Persistent<v8::Context> expected_context; 6244 static v8::Handle<v8::Context> expected_context;
6239 static v8::Handle<v8::Value> expected_context_data; 6245 static v8::Handle<v8::Value> expected_context_data;
6240 6246
6241 6247
6242 // Check that the expected context is the one generating the debug event. 6248 // Check that the expected context is the one generating the debug event.
6243 static void ContextCheckMessageHandler(const v8::Debug::Message& message) { 6249 static void ContextCheckMessageHandler(const v8::Debug::Message& message) {
6244 CHECK(message.GetEventContext() == expected_context); 6250 CHECK(message.GetEventContext() == expected_context);
6245 CHECK(message.GetEventContext()->GetEmbedderData(0)->StrictEquals( 6251 CHECK(message.GetEventContext()->GetEmbedderData(0)->StrictEquals(
6246 expected_context_data)); 6252 expected_context_data));
6247 message_handler_hit_count++; 6253 message_handler_hit_count++;
6248 6254
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
6286 context_2->SetEmbedderData(0, data_2); 6292 context_2->SetEmbedderData(0, data_2);
6287 CHECK(context_1->GetEmbedderData(0)->StrictEquals(data_1)); 6293 CHECK(context_1->GetEmbedderData(0)->StrictEquals(data_1));
6288 CHECK(context_2->GetEmbedderData(0)->StrictEquals(data_2)); 6294 CHECK(context_2->GetEmbedderData(0)->StrictEquals(data_2));
6289 6295
6290 // Simple test function which causes a break. 6296 // Simple test function which causes a break.
6291 const char* source = "function f() { debugger; }"; 6297 const char* source = "function f() { debugger; }";
6292 6298
6293 // Enter and run function in the first context. 6299 // Enter and run function in the first context.
6294 { 6300 {
6295 v8::Context::Scope context_scope(context_1); 6301 v8::Context::Scope context_scope(context_1);
6296 expected_context = v8::Persistent<v8::Context>(*context_1); 6302 expected_context = context_1;
6297 expected_context_data = data_1; 6303 expected_context_data = data_1;
6298 v8::Local<v8::Function> f = CompileFunction(source, "f"); 6304 v8::Local<v8::Function> f = CompileFunction(source, "f");
6299 f->Call(context_1->Global(), 0, NULL); 6305 f->Call(context_1->Global(), 0, NULL);
6300 } 6306 }
6301 6307
6302 6308
6303 // Enter and run function in the second context. 6309 // Enter and run function in the second context.
6304 { 6310 {
6305 v8::Context::Scope context_scope(context_2); 6311 v8::Context::Scope context_scope(context_2);
6306 expected_context = v8::Persistent<v8::Context>(*context_2); 6312 expected_context = context_2;
6307 expected_context_data = data_2; 6313 expected_context_data = data_2;
6308 v8::Local<v8::Function> f = CompileFunction(source, "f"); 6314 v8::Local<v8::Function> f = CompileFunction(source, "f");
6309 f->Call(context_2->Global(), 0, NULL); 6315 f->Call(context_2->Global(), 0, NULL);
6310 } 6316 }
6311 6317
6312 // Two times compile event and two times break event. 6318 // Two times compile event and two times break event.
6313 CHECK_GT(message_handler_hit_count, 4); 6319 CHECK_GT(message_handler_hit_count, 4);
6314 6320
6315 v8::Debug::SetMessageHandler2(NULL); 6321 v8::Debug::SetMessageHandler2(NULL);
6316 CheckDebuggerUnloaded(); 6322 CheckDebuggerUnloaded();
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
6447 v8::Handle<v8::String> data_1 = v8::String::New("1"); 6453 v8::Handle<v8::String> data_1 = v8::String::New("1");
6448 context_1->SetEmbedderData(0, data_1); 6454 context_1->SetEmbedderData(0, data_1);
6449 CHECK(context_1->GetEmbedderData(0)->StrictEquals(data_1)); 6455 CHECK(context_1->GetEmbedderData(0)->StrictEquals(data_1));
6450 6456
6451 // Simple test function with eval that causes a break. 6457 // Simple test function with eval that causes a break.
6452 const char* source = "function f() { eval('debugger;'); }"; 6458 const char* source = "function f() { eval('debugger;'); }";
6453 6459
6454 // Enter and run function in the context. 6460 // Enter and run function in the context.
6455 { 6461 {
6456 v8::Context::Scope context_scope(context_1); 6462 v8::Context::Scope context_scope(context_1);
6457 expected_context = v8::Persistent<v8::Context>(*context_1); 6463 expected_context = v8::Local<v8::Context>(*context_1);
6458 expected_context_data = data_1; 6464 expected_context_data = data_1;
6459 v8::Local<v8::Function> f = CompileFunction(source, "f"); 6465 v8::Local<v8::Function> f = CompileFunction(source, "f");
6460 f->Call(context_1->Global(), 0, NULL); 6466 f->Call(context_1->Global(), 0, NULL);
6461 } 6467 }
6462 } 6468 }
6463 6469
6464 6470
6465 // Test which creates a context and sets embedder data on it. Checks that this 6471 // Test which creates a context and sets embedder data on it. Checks that this
6466 // data is set correctly and that when the debug message handler is called for 6472 // data is set correctly and that when the debug message handler is called for
6467 // break event in an eval statement the expected context is the one returned by 6473 // break event in an eval statement the expected context is the one returned by
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
6606 } 6612 }
6607 6613
6608 6614
6609 // Test that GetEventContext doesn't fail and return empty handle for 6615 // Test that GetEventContext doesn't fail and return empty handle for
6610 // ScriptCollected events. 6616 // ScriptCollected events.
6611 TEST(ScriptCollectedEventContext) { 6617 TEST(ScriptCollectedEventContext) {
6612 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 6618 v8::Isolate* isolate = v8::Isolate::GetCurrent();
6613 v8::internal::Debug* debug = 6619 v8::internal::Debug* debug =
6614 reinterpret_cast<v8::internal::Isolate*>(isolate)->debug(); 6620 reinterpret_cast<v8::internal::Isolate*>(isolate)->debug();
6615 script_collected_message_count = 0; 6621 script_collected_message_count = 0;
6616 v8::HandleScope scope(isolate);
6617 6622
6618 { // Scope for the DebugLocalContext. 6623 { // Scope for the DebugLocalContext.
6619 DebugLocalContext env; 6624 DebugLocalContext env;
6620 6625
6621 // Request the loaded scripts to initialize the debugger script cache. 6626 // Request the loaded scripts to initialize the debugger script cache.
6622 debug->GetLoadedScripts(); 6627 debug->GetLoadedScripts();
6623 6628
6624 // Do garbage collection to ensure that only the script in this test will be 6629 // Do garbage collection to ensure that only the script in this test will be
6625 // collected afterwards. 6630 // collected afterwards.
6626 HEAP->CollectAllGarbage(Heap::kNoGCFlags); 6631 HEAP->CollectAllGarbage(Heap::kNoGCFlags);
6627 6632
6628 v8::Debug::SetMessageHandler2(ScriptCollectedMessageHandler); 6633 v8::Debug::SetMessageHandler2(ScriptCollectedMessageHandler);
6629 { 6634 v8::Script::Compile(v8::String::New("eval('a=1')"))->Run();
6630 v8::Script::Compile(v8::String::New("eval('a=1')"))->Run(); 6635 v8::Script::Compile(v8::String::New("eval('a=2')"))->Run();
6631 v8::Script::Compile(v8::String::New("eval('a=2')"))->Run();
6632 }
6633 } 6636 }
6634 6637
6635 // Do garbage collection to collect the script above which is no longer 6638 // Do garbage collection to collect the script above which is no longer
6636 // referenced. 6639 // referenced.
6637 HEAP->CollectAllGarbage(Heap::kNoGCFlags); 6640 HEAP->CollectAllGarbage(Heap::kNoGCFlags);
6638 6641
6639 CHECK_EQ(2, script_collected_message_count); 6642 CHECK_EQ(4, script_collected_message_count);
6640 6643
6641 v8::Debug::SetMessageHandler2(NULL); 6644 v8::Debug::SetMessageHandler2(NULL);
6642 } 6645 }
6643 6646
6644 6647
6645 // Debug event listener which counts the after compile events. 6648 // Debug event listener which counts the after compile events.
6646 int after_compile_message_count = 0; 6649 int after_compile_message_count = 0;
6647 static void AfterCompileMessageHandler(const v8::Debug::Message& message) { 6650 static void AfterCompileMessageHandler(const v8::Debug::Message& message) {
6648 // Count the number of scripts collected. 6651 // Count the number of scripts collected.
6649 if (message.IsEvent()) { 6652 if (message.IsEvent()) {
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after
7082 7085
7083 7086
7084 static v8::Handle<v8::Value> expected_callback_data; 7087 static v8::Handle<v8::Value> expected_callback_data;
7085 static void DebugEventContextChecker(const v8::Debug::EventDetails& details) { 7088 static void DebugEventContextChecker(const v8::Debug::EventDetails& details) {
7086 CHECK(details.GetEventContext() == expected_context); 7089 CHECK(details.GetEventContext() == expected_context);
7087 CHECK_EQ(expected_callback_data, details.GetCallbackData()); 7090 CHECK_EQ(expected_callback_data, details.GetCallbackData());
7088 } 7091 }
7089 7092
7090 // Check that event details contain context where debug event occured. 7093 // Check that event details contain context where debug event occured.
7091 TEST(DebugEventContext) { 7094 TEST(DebugEventContext) {
7092 v8::HandleScope scope(v8::Isolate::GetCurrent()); 7095 v8::Isolate* isolate = v8::Isolate::GetCurrent();
7096 v8::HandleScope scope(isolate);
7093 expected_callback_data = v8::Int32::New(2010); 7097 expected_callback_data = v8::Int32::New(2010);
7094 v8::Debug::SetDebugEventListener2(DebugEventContextChecker, 7098 v8::Debug::SetDebugEventListener2(DebugEventContextChecker,
7095 expected_callback_data); 7099 expected_callback_data);
7096 expected_context = v8::Context::New(); 7100 expected_context = v8::Context::New(isolate);
7097 v8::Context::Scope context_scope( 7101 v8::Context::Scope context_scope(expected_context);
7098 v8::Isolate::GetCurrent(), expected_context);
7099 v8::Script::Compile(v8::String::New("(function(){debugger;})();"))->Run(); 7102 v8::Script::Compile(v8::String::New("(function(){debugger;})();"))->Run();
7100 expected_context.Dispose(expected_context->GetIsolate());
7101 expected_context.Clear(); 7103 expected_context.Clear();
7102 v8::Debug::SetDebugEventListener(NULL); 7104 v8::Debug::SetDebugEventListener(NULL);
7103 expected_context_data = v8::Handle<v8::Value>(); 7105 expected_context_data = v8::Handle<v8::Value>();
7104 CheckDebuggerUnloaded(); 7106 CheckDebuggerUnloaded();
7105 } 7107 }
7106 7108
7107 7109
7108 static void* expected_break_data; 7110 static void* expected_break_data;
7109 static bool was_debug_break_called; 7111 static bool was_debug_break_called;
7110 static bool was_debug_event_called; 7112 static bool was_debug_event_called;
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
7551 TEST(LiveEditDisabled) { 7553 TEST(LiveEditDisabled) {
7552 v8::internal::FLAG_allow_natives_syntax = true; 7554 v8::internal::FLAG_allow_natives_syntax = true;
7553 LocalContext env; 7555 LocalContext env;
7554 v8::HandleScope scope(env->GetIsolate()); 7556 v8::HandleScope scope(env->GetIsolate());
7555 v8::Debug::SetLiveEditEnabled(false); 7557 v8::Debug::SetLiveEditEnabled(false);
7556 CompileRun("%LiveEditCompareStrings('', '')"); 7558 CompileRun("%LiveEditCompareStrings('', '')");
7557 } 7559 }
7558 7560
7559 7561
7560 #endif // ENABLE_DEBUGGER_SUPPORT 7562 #endif // ENABLE_DEBUGGER_SUPPORT
OLDNEW
« no previous file with comments | « test/cctest/test-api.cc ('k') | test/cctest/test-decls.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698