| OLD | NEW |
| 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 5495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5506 v8::Script::New( | 5506 v8::Script::New( |
| 5507 v8::String::New( | 5507 v8::String::New( |
| 5508 "function runTest(mirror) {" | 5508 "function runTest(mirror) {" |
| 5509 " return mirror.isString() && (mirror.length() == 5);" | 5509 " return mirror.isString() && (mirror.length() == 5);" |
| 5510 "}" | 5510 "}" |
| 5511 "" | 5511 "" |
| 5512 "runTest;"))->Run()); | 5512 "runTest;"))->Run()); |
| 5513 v8::Handle<v8::Value> result = run_test->Call(env->Global(), 1, &obj); | 5513 v8::Handle<v8::Value> result = run_test->Call(env->Global(), 1, &obj); |
| 5514 CHECK(result->IsTrue()); | 5514 CHECK(result->IsTrue()); |
| 5515 } | 5515 } |
| 5516 |
| 5517 |
| 5518 v8::Handle<v8::Context> debugee_context; |
| 5519 v8::Handle<v8::Context> debugger_context; |
| 5520 |
| 5521 |
| 5522 // Property getter that checks that current and calling contexts |
| 5523 // are both the debugee contexts. |
| 5524 static v8::Handle<v8::Value> NamedGetterWithCallingContextCheck( |
| 5525 v8::Local<v8::String> name, |
| 5526 const v8::AccessorInfo& info) { |
| 5527 CHECK_EQ(0, strcmp(*v8::String::AsciiValue(name), "a")); |
| 5528 v8::Handle<v8::Context> current = v8::Context::GetCurrent(); |
| 5529 CHECK(current == debugee_context); |
| 5530 CHECK(current != debugger_context); |
| 5531 v8::Handle<v8::Context> calling = v8::Context::GetCalling(); |
| 5532 CHECK(calling == debugee_context); |
| 5533 CHECK(calling != debugger_context); |
| 5534 return v8::Int32::New(1); |
| 5535 } |
| 5536 |
| 5537 |
| 5538 // Debug event listener that checks if the first argument of a function is |
| 5539 // an object with property 'a' == 1. If the property has custom accessor |
| 5540 // this handler will eventually invoke it. |
| 5541 static void DebugEventGetAtgumentPropertyValue( |
| 5542 v8::DebugEvent event, |
| 5543 v8::Handle<v8::Object> exec_state, |
| 5544 v8::Handle<v8::Object> event_data, |
| 5545 v8::Handle<v8::Value> data) { |
| 5546 if (event == v8::Break) { |
| 5547 break_point_hit_count++; |
| 5548 CHECK(debugger_context == v8::Context::GetCurrent()); |
| 5549 v8::Handle<v8::Function> func(v8::Function::Cast(*CompileRun( |
| 5550 "(function(exec_state) {\n" |
| 5551 " return (exec_state.frame(0).argumentValue(0).property('a').\n" |
| 5552 " value().value() == 1);\n" |
| 5553 "})"))); |
| 5554 const int argc = 1; |
| 5555 v8::Handle<v8::Value> argv[argc] = { exec_state }; |
| 5556 v8::Handle<v8::Value> result = func->Call(exec_state, argc, argv); |
| 5557 CHECK(result->IsTrue()); |
| 5558 } |
| 5559 } |
| 5560 |
| 5561 |
| 5562 TEST(CallingContextIsNotDebugContext) { |
| 5563 // Create and enter a debugee context. |
| 5564 v8::HandleScope scope; |
| 5565 DebugLocalContext env; |
| 5566 env.ExposeDebug(); |
| 5567 |
| 5568 // Save handles to the debugger and debugee contexts to be used in |
| 5569 // NamedGetterWithCallingContextCheck. |
| 5570 debugee_context = v8::Local<v8::Context>(*env); |
| 5571 debugger_context = v8::Utils::ToLocal(Debug::debug_context()); |
| 5572 |
| 5573 // Create object with 'a' property accessor. |
| 5574 v8::Handle<v8::ObjectTemplate> named = v8::ObjectTemplate::New(); |
| 5575 named->SetAccessor(v8::String::New("a"), |
| 5576 NamedGetterWithCallingContextCheck); |
| 5577 env->Global()->Set(v8::String::New("obj"), |
| 5578 named->NewInstance()); |
| 5579 |
| 5580 // Register the debug event listener |
| 5581 v8::Debug::SetDebugEventListener(DebugEventGetAtgumentPropertyValue); |
| 5582 |
| 5583 // Create a function that invokes debugger. |
| 5584 v8::Local<v8::Function> foo = CompileFunction( |
| 5585 &env, |
| 5586 "function bar(x) { debugger; }" |
| 5587 "function foo(){ bar(obj); }", |
| 5588 "foo"); |
| 5589 |
| 5590 break_point_hit_count = 0; |
| 5591 foo->Call(env->Global(), 0, NULL); |
| 5592 CHECK_EQ(1, break_point_hit_count); |
| 5593 |
| 5594 v8::Debug::SetDebugEventListener(NULL); |
| 5595 debugee_context = v8::Handle<v8::Context>(); |
| 5596 debugger_context = v8::Handle<v8::Context>(); |
| 5597 CheckDebuggerUnloaded(); |
| 5598 } |
| OLD | NEW |