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 7162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7173 } | 7173 } |
7174 | 7174 |
7175 | 7175 |
7176 TEST(NoDebugContextWhenDebuggerDisabled) { | 7176 TEST(NoDebugContextWhenDebuggerDisabled) { |
7177 v8::HandleScope scope(CcTest::isolate()); | 7177 v8::HandleScope scope(CcTest::isolate()); |
7178 v8::Local<v8::Context> context = | 7178 v8::Local<v8::Context> context = |
7179 v8::Debug::GetDebugContext(CcTest::isolate()); | 7179 v8::Debug::GetDebugContext(CcTest::isolate()); |
7180 CHECK(context.IsEmpty()); | 7180 CHECK(context.IsEmpty()); |
7181 } | 7181 } |
7182 | 7182 |
| 7183 static void DebugEventCheckContext( |
| 7184 const v8::Debug::EventDetails& event_details) { |
| 7185 if (event_details.GetEvent() == v8::Break) { |
| 7186 v8::Isolate* isolate = event_details.GetIsolate(); |
| 7187 CHECK(v8::Debug::GetDebuggedContext(isolate) |
| 7188 .ToLocalChecked() |
| 7189 ->Global() |
| 7190 ->Equals(isolate->GetCurrentContext(), |
| 7191 event_details.GetEventContext()->Global()) |
| 7192 .FromJust()); |
| 7193 } |
| 7194 } |
| 7195 |
| 7196 static void CheckContext(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 7197 CHECK(v8::Debug::GetDebuggedContext(args.GetIsolate()).IsEmpty()); |
| 7198 } |
| 7199 |
| 7200 TEST(DebuggedContext) { |
| 7201 DebugLocalContext env; |
| 7202 v8::Isolate* isolate = env->GetIsolate(); |
| 7203 |
| 7204 v8::Debug::SetDebugEventListener(isolate, DebugEventCheckContext); |
| 7205 |
| 7206 v8::Local<v8::Function> foo = |
| 7207 CompileFunction(&env, "function foo(){bar=0;}", "foo"); |
| 7208 |
| 7209 SetBreakPoint(foo, 0); |
| 7210 foo->Call(env.context(), env->Global(), 0, nullptr).ToLocalChecked(); |
| 7211 |
| 7212 v8::Local<v8::Function> fun = v8::FunctionTemplate::New(isolate, CheckContext) |
| 7213 ->GetFunction(env.context()) |
| 7214 .ToLocalChecked(); |
| 7215 fun->Call(env.context(), env->Global(), 0, nullptr).ToLocalChecked(); |
| 7216 } |
7183 | 7217 |
7184 static v8::Local<v8::Value> expected_callback_data; | 7218 static v8::Local<v8::Value> expected_callback_data; |
7185 static void DebugEventContextChecker(const v8::Debug::EventDetails& details) { | 7219 static void DebugEventContextChecker(const v8::Debug::EventDetails& details) { |
7186 CHECK(details.GetEventContext() == expected_context); | 7220 CHECK(details.GetEventContext() == expected_context); |
7187 CHECK(expected_callback_data->Equals(details.GetEventContext(), | 7221 CHECK(expected_callback_data->Equals(details.GetEventContext(), |
7188 details.GetCallbackData()) | 7222 details.GetCallbackData()) |
7189 .FromJust()); | 7223 .FromJust()); |
7190 } | 7224 } |
7191 | 7225 |
7192 | 7226 |
(...skipping 982 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8175 "function foo() {\n" | 8209 "function foo() {\n" |
8176 " try { throw new Error(); } catch (e) {}\n" | 8210 " try { throw new Error(); } catch (e) {}\n" |
8177 "}\n" | 8211 "}\n" |
8178 "debugger;\n" | 8212 "debugger;\n" |
8179 "foo();\n" | 8213 "foo();\n" |
8180 "foo();\n"); | 8214 "foo();\n"); |
8181 | 8215 |
8182 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr); | 8216 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr); |
8183 CHECK_EQ(break_point_hit_count, 4); | 8217 CHECK_EQ(break_point_hit_count, 4); |
8184 } | 8218 } |
OLD | NEW |