Upgrade to 3.29
Update V8 to 3.29.88.17 and update makefiles to support building on
all the relevant platforms.
Bug: 17370214
Change-Id: Ia3407c157fd8d72a93e23d8318ccaf6ecf77fa4e
diff --git a/test/cctest/test-debug.cc b/test/cctest/test-debug.cc
index ffa8458..2f0674a 100644
--- a/test/cctest/test-debug.cc
+++ b/test/cctest/test-debug.cc
@@ -25,25 +25,28 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#ifdef ENABLE_DEBUGGER_SUPPORT
-
#include <stdlib.h>
-#include "v8.h"
+#include "src/v8.h"
-#include "api.h"
-#include "cctest.h"
-#include "compilation-cache.h"
-#include "debug.h"
-#include "deoptimizer.h"
-#include "platform.h"
-#include "stub-cache.h"
-#include "utils.h"
+#include "src/api.h"
+#include "src/base/platform/condition-variable.h"
+#include "src/base/platform/platform.h"
+#include "src/compilation-cache.h"
+#include "src/debug.h"
+#include "src/deoptimizer.h"
+#include "src/frames.h"
+#include "src/utils.h"
+#include "test/cctest/cctest.h"
+using ::v8::base::Mutex;
+using ::v8::base::LockGuard;
+using ::v8::base::ConditionVariable;
+using ::v8::base::OS;
+using ::v8::base::Semaphore;
using ::v8::internal::EmbeddedVector;
using ::v8::internal::Object;
-using ::v8::internal::OS;
using ::v8::internal::Handle;
using ::v8::internal::Heap;
using ::v8::internal::JSGlobalProxy;
@@ -52,6 +55,7 @@
using ::v8::internal::Debugger;
using ::v8::internal::CommandMessage;
using ::v8::internal::CommandMessageQueue;
+using ::v8::internal::StackFrame;
using ::v8::internal::StepAction;
using ::v8::internal::StepIn; // From StepAction enum
using ::v8::internal::StepNext; // From StepAction enum
@@ -62,65 +66,6 @@
// Size of temp buffer for formatting small strings.
#define SMALL_STRING_BUFFER_SIZE 80
-// --- A d d i t i o n a l C h e c k H e l p e r s
-
-
-// Helper function used by the CHECK_EQ function when given Address
-// arguments. Should not be called directly.
-static inline void CheckEqualsHelper(const char* file, int line,
- const char* expected_source,
- ::v8::internal::Address expected,
- const char* value_source,
- ::v8::internal::Address value) {
- if (expected != value) {
- V8_Fatal(file, line, "CHECK_EQ(%s, %s) failed\n# "
- "Expected: %i\n# Found: %i",
- expected_source, value_source, expected, value);
- }
-}
-
-
-// Helper function used by the CHECK_NE function when given Address
-// arguments. Should not be called directly.
-static inline void CheckNonEqualsHelper(const char* file, int line,
- const char* unexpected_source,
- ::v8::internal::Address unexpected,
- const char* value_source,
- ::v8::internal::Address value) {
- if (unexpected == value) {
- V8_Fatal(file, line, "CHECK_NE(%s, %s) failed\n# Value: %i",
- unexpected_source, value_source, value);
- }
-}
-
-
-// Helper function used by the CHECK function when given code
-// arguments. Should not be called directly.
-static inline void CheckEqualsHelper(const char* file, int line,
- const char* expected_source,
- const Code* expected,
- const char* value_source,
- const Code* value) {
- if (expected != value) {
- V8_Fatal(file, line, "CHECK_EQ(%s, %s) failed\n# "
- "Expected: %p\n# Found: %p",
- expected_source, value_source, expected, value);
- }
-}
-
-
-static inline void CheckNonEqualsHelper(const char* file, int line,
- const char* expected_source,
- const Code* expected,
- const char* value_source,
- const Code* value) {
- if (expected == value) {
- V8_Fatal(file, line, "CHECK_NE(%s, %s) failed\n# Value: %p",
- expected_source, value_source, value);
- }
-}
-
-
// --- H e l p e r C l a s s e s
@@ -128,38 +73,55 @@
class DebugLocalContext {
public:
inline DebugLocalContext(
+ v8::Isolate* isolate, v8::ExtensionConfiguration* extensions = 0,
+ v8::Handle<v8::ObjectTemplate> global_template =
+ v8::Handle<v8::ObjectTemplate>(),
+ v8::Handle<v8::Value> global_object = v8::Handle<v8::Value>())
+ : scope_(isolate),
+ context_(v8::Context::New(isolate, extensions, global_template,
+ global_object)) {
+ context_->Enter();
+ }
+ inline DebugLocalContext(
v8::ExtensionConfiguration* extensions = 0,
v8::Handle<v8::ObjectTemplate> global_template =
v8::Handle<v8::ObjectTemplate>(),
v8::Handle<v8::Value> global_object = v8::Handle<v8::Value>())
- : context_(v8::Context::New(extensions, global_template, global_object)) {
+ : scope_(CcTest::isolate()),
+ context_(v8::Context::New(CcTest::isolate(), extensions,
+ global_template, global_object)) {
context_->Enter();
}
inline ~DebugLocalContext() {
context_->Exit();
- context_.Dispose();
}
+ inline v8::Local<v8::Context> context() { return context_; }
inline v8::Context* operator->() { return *context_; }
inline v8::Context* operator*() { return *context_; }
+ inline v8::Isolate* GetIsolate() { return context_->GetIsolate(); }
inline bool IsReady() { return !context_.IsEmpty(); }
void ExposeDebug() {
- v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug();
+ v8::internal::Isolate* isolate =
+ reinterpret_cast<v8::internal::Isolate*>(context_->GetIsolate());
+ v8::internal::Factory* factory = isolate->factory();
// Expose the debug context global object in the global object for testing.
- debug->Load();
- debug->debug_context()->set_security_token(
+ CHECK(isolate->debug()->Load());
+ Handle<v8::internal::Context> debug_context =
+ isolate->debug()->debug_context();
+ debug_context->set_security_token(
v8::Utils::OpenHandle(*context_)->security_token());
Handle<JSGlobalProxy> global(Handle<JSGlobalProxy>::cast(
v8::Utils::OpenHandle(*context_->Global())));
Handle<v8::internal::String> debug_string =
- FACTORY->LookupAsciiSymbol("debug");
- SetProperty(global, debug_string,
- Handle<Object>(debug->debug_context()->global_proxy()), DONT_ENUM,
- ::v8::internal::kNonStrictMode);
+ factory->InternalizeOneByteString(STATIC_CHAR_VECTOR("debug"));
+ v8::internal::Runtime::DefineObjectProperty(global, debug_string,
+ handle(debug_context->global_proxy(), isolate), DONT_ENUM).Check();
}
private:
- v8::Persistent<v8::Context> context_;
+ v8::HandleScope scope_;
+ v8::Local<v8::Context> context_;
};
@@ -170,18 +132,21 @@
static v8::Local<v8::Function> CompileFunction(DebugLocalContext* env,
const char* source,
const char* function_name) {
- v8::Script::Compile(v8::String::New(source))->Run();
- return v8::Local<v8::Function>::Cast(
- (*env)->Global()->Get(v8::String::New(function_name)));
+ v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), source))
+ ->Run();
+ return v8::Local<v8::Function>::Cast((*env)->Global()->Get(
+ v8::String::NewFromUtf8(env->GetIsolate(), function_name)));
}
// Compile and run the supplied source and return the requested function.
-static v8::Local<v8::Function> CompileFunction(const char* source,
+static v8::Local<v8::Function> CompileFunction(v8::Isolate* isolate,
+ const char* source,
const char* function_name) {
- v8::Script::Compile(v8::String::New(source))->Run();
+ v8::Script::Compile(v8::String::NewFromUtf8(isolate, source))->Run();
+ v8::Local<v8::Object> global = isolate->GetCurrentContext()->Global();
return v8::Local<v8::Function>::Cast(
- v8::Context::GetCurrent()->Global()->Get(v8::String::New(function_name)));
+ global->Get(v8::String::NewFromUtf8(isolate, function_name)));
}
@@ -197,11 +162,11 @@
// number.
static int SetBreakPoint(Handle<v8::internal::JSFunction> fun, int position) {
static int break_point = 0;
- Handle<v8::internal::SharedFunctionInfo> shared(fun->shared());
- v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug();
+ v8::internal::Isolate* isolate = fun->GetIsolate();
+ v8::internal::Debug* debug = isolate->debug();
debug->SetBreakPoint(
- shared,
- Handle<Object>(v8::internal::Smi::FromInt(++break_point)),
+ fun,
+ Handle<Object>(v8::internal::Smi::FromInt(++break_point), isolate),
&position);
return break_point;
}
@@ -216,36 +181,39 @@
// Set a break point in a function using the Debug object and return the
// associated break point number.
-static int SetBreakPointFromJS(const char* function_name,
+static int SetBreakPointFromJS(v8::Isolate* isolate,
+ const char* function_name,
int line, int position) {
EmbeddedVector<char, SMALL_STRING_BUFFER_SIZE> buffer;
- OS::SNPrintF(buffer,
- "debug.Debug.setBreakPoint(%s,%d,%d)",
- function_name, line, position);
+ SNPrintF(buffer,
+ "debug.Debug.setBreakPoint(%s,%d,%d)",
+ function_name, line, position);
buffer[SMALL_STRING_BUFFER_SIZE - 1] = '\0';
- v8::Handle<v8::String> str = v8::String::New(buffer.start());
+ v8::Handle<v8::String> str = v8::String::NewFromUtf8(isolate, buffer.start());
return v8::Script::Compile(str)->Run()->Int32Value();
}
// Set a break point in a script identified by id using the global Debug object.
-static int SetScriptBreakPointByIdFromJS(int script_id, int line, int column) {
+static int SetScriptBreakPointByIdFromJS(v8::Isolate* isolate, int script_id,
+ int line, int column) {
EmbeddedVector<char, SMALL_STRING_BUFFER_SIZE> buffer;
if (column >= 0) {
// Column specified set script break point on precise location.
- OS::SNPrintF(buffer,
- "debug.Debug.setScriptBreakPointById(%d,%d,%d)",
- script_id, line, column);
+ SNPrintF(buffer,
+ "debug.Debug.setScriptBreakPointById(%d,%d,%d)",
+ script_id, line, column);
} else {
// Column not specified set script break point on line.
- OS::SNPrintF(buffer,
- "debug.Debug.setScriptBreakPointById(%d,%d)",
- script_id, line);
+ SNPrintF(buffer,
+ "debug.Debug.setScriptBreakPointById(%d,%d)",
+ script_id, line);
}
buffer[SMALL_STRING_BUFFER_SIZE - 1] = '\0';
{
v8::TryCatch try_catch;
- v8::Handle<v8::String> str = v8::String::New(buffer.start());
+ v8::Handle<v8::String> str =
+ v8::String::NewFromUtf8(isolate, buffer.start());
v8::Handle<v8::Value> value = v8::Script::Compile(str)->Run();
CHECK(!try_catch.HasCaught());
return value->Int32Value();
@@ -255,24 +223,26 @@
// Set a break point in a script identified by name using the global Debug
// object.
-static int SetScriptBreakPointByNameFromJS(const char* script_name,
- int line, int column) {
+static int SetScriptBreakPointByNameFromJS(v8::Isolate* isolate,
+ const char* script_name, int line,
+ int column) {
EmbeddedVector<char, SMALL_STRING_BUFFER_SIZE> buffer;
if (column >= 0) {
// Column specified set script break point on precise location.
- OS::SNPrintF(buffer,
- "debug.Debug.setScriptBreakPointByName(\"%s\",%d,%d)",
- script_name, line, column);
+ SNPrintF(buffer,
+ "debug.Debug.setScriptBreakPointByName(\"%s\",%d,%d)",
+ script_name, line, column);
} else {
// Column not specified set script break point on line.
- OS::SNPrintF(buffer,
- "debug.Debug.setScriptBreakPointByName(\"%s\",%d)",
- script_name, line);
+ SNPrintF(buffer,
+ "debug.Debug.setScriptBreakPointByName(\"%s\",%d)",
+ script_name, line);
}
buffer[SMALL_STRING_BUFFER_SIZE - 1] = '\0';
{
v8::TryCatch try_catch;
- v8::Handle<v8::String> str = v8::String::New(buffer.start());
+ v8::Handle<v8::String> str =
+ v8::String::NewFromUtf8(isolate, buffer.start());
v8::Handle<v8::Value> value = v8::Script::Compile(str)->Run();
CHECK(!try_catch.HasCaught());
return value->Int32Value();
@@ -282,96 +252,107 @@
// Clear a break point.
static void ClearBreakPoint(int break_point) {
- v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug();
+ v8::internal::Isolate* isolate = CcTest::i_isolate();
+ v8::internal::Debug* debug = isolate->debug();
debug->ClearBreakPoint(
- Handle<Object>(v8::internal::Smi::FromInt(break_point)));
+ Handle<Object>(v8::internal::Smi::FromInt(break_point), isolate));
}
// Clear a break point using the global Debug object.
-static void ClearBreakPointFromJS(int break_point_number) {
+static void ClearBreakPointFromJS(v8::Isolate* isolate,
+ int break_point_number) {
EmbeddedVector<char, SMALL_STRING_BUFFER_SIZE> buffer;
- OS::SNPrintF(buffer,
- "debug.Debug.clearBreakPoint(%d)",
- break_point_number);
+ SNPrintF(buffer,
+ "debug.Debug.clearBreakPoint(%d)",
+ break_point_number);
buffer[SMALL_STRING_BUFFER_SIZE - 1] = '\0';
- v8::Script::Compile(v8::String::New(buffer.start()))->Run();
+ v8::Script::Compile(v8::String::NewFromUtf8(isolate, buffer.start()))->Run();
}
-static void EnableScriptBreakPointFromJS(int break_point_number) {
+static void EnableScriptBreakPointFromJS(v8::Isolate* isolate,
+ int break_point_number) {
EmbeddedVector<char, SMALL_STRING_BUFFER_SIZE> buffer;
- OS::SNPrintF(buffer,
- "debug.Debug.enableScriptBreakPoint(%d)",
- break_point_number);
+ SNPrintF(buffer,
+ "debug.Debug.enableScriptBreakPoint(%d)",
+ break_point_number);
buffer[SMALL_STRING_BUFFER_SIZE - 1] = '\0';
- v8::Script::Compile(v8::String::New(buffer.start()))->Run();
+ v8::Script::Compile(v8::String::NewFromUtf8(isolate, buffer.start()))->Run();
}
-static void DisableScriptBreakPointFromJS(int break_point_number) {
+static void DisableScriptBreakPointFromJS(v8::Isolate* isolate,
+ int break_point_number) {
EmbeddedVector<char, SMALL_STRING_BUFFER_SIZE> buffer;
- OS::SNPrintF(buffer,
- "debug.Debug.disableScriptBreakPoint(%d)",
- break_point_number);
+ SNPrintF(buffer,
+ "debug.Debug.disableScriptBreakPoint(%d)",
+ break_point_number);
buffer[SMALL_STRING_BUFFER_SIZE - 1] = '\0';
- v8::Script::Compile(v8::String::New(buffer.start()))->Run();
+ v8::Script::Compile(v8::String::NewFromUtf8(isolate, buffer.start()))->Run();
}
-static void ChangeScriptBreakPointConditionFromJS(int break_point_number,
+static void ChangeScriptBreakPointConditionFromJS(v8::Isolate* isolate,
+ int break_point_number,
const char* condition) {
EmbeddedVector<char, SMALL_STRING_BUFFER_SIZE> buffer;
- OS::SNPrintF(buffer,
- "debug.Debug.changeScriptBreakPointCondition(%d, \"%s\")",
- break_point_number, condition);
+ SNPrintF(buffer,
+ "debug.Debug.changeScriptBreakPointCondition(%d, \"%s\")",
+ break_point_number, condition);
buffer[SMALL_STRING_BUFFER_SIZE - 1] = '\0';
- v8::Script::Compile(v8::String::New(buffer.start()))->Run();
+ v8::Script::Compile(v8::String::NewFromUtf8(isolate, buffer.start()))->Run();
}
-static void ChangeScriptBreakPointIgnoreCountFromJS(int break_point_number,
+static void ChangeScriptBreakPointIgnoreCountFromJS(v8::Isolate* isolate,
+ int break_point_number,
int ignoreCount) {
EmbeddedVector<char, SMALL_STRING_BUFFER_SIZE> buffer;
- OS::SNPrintF(buffer,
- "debug.Debug.changeScriptBreakPointIgnoreCount(%d, %d)",
- break_point_number, ignoreCount);
+ SNPrintF(buffer,
+ "debug.Debug.changeScriptBreakPointIgnoreCount(%d, %d)",
+ break_point_number, ignoreCount);
buffer[SMALL_STRING_BUFFER_SIZE - 1] = '\0';
- v8::Script::Compile(v8::String::New(buffer.start()))->Run();
+ v8::Script::Compile(v8::String::NewFromUtf8(isolate, buffer.start()))->Run();
}
// Change break on exception.
static void ChangeBreakOnException(bool caught, bool uncaught) {
- v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug();
+ v8::internal::Debug* debug = CcTest::i_isolate()->debug();
debug->ChangeBreakOnException(v8::internal::BreakException, caught);
debug->ChangeBreakOnException(v8::internal::BreakUncaughtException, uncaught);
}
// Change break on exception using the global Debug object.
-static void ChangeBreakOnExceptionFromJS(bool caught, bool uncaught) {
+static void ChangeBreakOnExceptionFromJS(v8::Isolate* isolate, bool caught,
+ bool uncaught) {
if (caught) {
v8::Script::Compile(
- v8::String::New("debug.Debug.setBreakOnException()"))->Run();
+ v8::String::NewFromUtf8(isolate, "debug.Debug.setBreakOnException()"))
+ ->Run();
} else {
v8::Script::Compile(
- v8::String::New("debug.Debug.clearBreakOnException()"))->Run();
+ v8::String::NewFromUtf8(isolate, "debug.Debug.clearBreakOnException()"))
+ ->Run();
}
if (uncaught) {
v8::Script::Compile(
- v8::String::New("debug.Debug.setBreakOnUncaughtException()"))->Run();
+ v8::String::NewFromUtf8(
+ isolate, "debug.Debug.setBreakOnUncaughtException()"))->Run();
} else {
v8::Script::Compile(
- v8::String::New("debug.Debug.clearBreakOnUncaughtException()"))->Run();
+ v8::String::NewFromUtf8(
+ isolate, "debug.Debug.clearBreakOnUncaughtException()"))->Run();
}
}
// Prepare to step to next break location.
static void PrepareStep(StepAction step_action) {
- v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug();
- debug->PrepareStep(step_action, 1);
+ v8::internal::Debug* debug = CcTest::i_isolate()->debug();
+ debug->PrepareStep(step_action, 1, StackFrame::NO_ID);
}
@@ -382,7 +363,7 @@
// Collect the currently debugged functions.
Handle<FixedArray> GetDebuggedFunctions() {
- Debug* debug = Isolate::Current()->debug();
+ Debug* debug = CcTest::i_isolate()->debug();
v8::internal::DebugInfoListNode* node = debug->debug_info_list_;
@@ -395,7 +376,7 @@
// Allocate array for the debugged functions
Handle<FixedArray> debugged_functions =
- FACTORY->NewFixedArray(count);
+ CcTest::i_isolate()->factory()->NewFixedArray(count);
// Run through the debug info objects and collect all functions.
count = 0;
@@ -408,25 +389,19 @@
}
-static Handle<Code> ComputeCallDebugBreak(int argc) {
- return Isolate::Current()->stub_cache()->ComputeCallDebugBreak(argc,
- Code::CALL_IC);
-}
-
-
// Check that the debugger has been fully unloaded.
void CheckDebuggerUnloaded(bool check_functions) {
// Check that the debugger context is cleared and that there is no debug
// information stored for the debugger.
- CHECK(Isolate::Current()->debug()->debug_context().is_null());
- CHECK_EQ(NULL, Isolate::Current()->debug()->debug_info_list_);
+ CHECK(CcTest::i_isolate()->debug()->debug_context().is_null());
+ CHECK_EQ(NULL, CcTest::i_isolate()->debug()->debug_info_list_);
// Collect garbage to ensure weak handles are cleared.
- HEAP->CollectAllGarbage(Heap::kNoGCFlags);
- HEAP->CollectAllGarbage(Heap::kMakeHeapIterableMask);
+ CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags);
+ CcTest::heap()->CollectAllGarbage(Heap::kMakeHeapIterableMask);
// Iterate the head and check that there are no debugger related objects left.
- HeapIterator iterator;
+ HeapIterator iterator(CcTest::heap());
for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) {
CHECK(!obj->IsDebugInfo());
CHECK(!obj->IsBreakPointInfo());
@@ -450,12 +425,6 @@
}
-void ForceUnloadDebugger() {
- Isolate::Current()->debugger()->never_unload_debugger_ = false;
- Isolate::Current()->debugger()->UnloadDebugger();
-}
-
-
} } // namespace v8::internal
@@ -487,7 +456,7 @@
const char* source, const char* name,
int position, v8::internal::RelocInfo::Mode mode,
Code* debug_break) {
- v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug();
+ v8::internal::Debug* debug = CcTest::i_isolate()->debug();
// Create function and set the break point.
Handle<v8::internal::JSFunction> fun = v8::Utils::OpenHandle(
@@ -498,7 +467,7 @@
Handle<v8::internal::SharedFunctionInfo> shared(fun->shared());
CHECK(Debug::HasDebugInfo(shared));
TestBreakLocationIterator it1(Debug::GetDebugInfo(shared));
- it1.FindBreakLocationFromPosition(position);
+ it1.FindBreakLocationFromPosition(position, v8::internal::STATEMENT_ALIGNED);
v8::internal::RelocInfo::Mode actual_mode = it1.it()->rinfo()->rmode();
if (actual_mode == v8::internal::RelocInfo::CODE_TARGET_WITH_ID) {
actual_mode = v8::internal::RelocInfo::CODE_TARGET;
@@ -515,9 +484,9 @@
// there
ClearBreakPoint(bp);
CHECK(!debug->HasDebugInfo(shared));
- CHECK(debug->EnsureDebugInfo(shared));
+ CHECK(debug->EnsureDebugInfo(shared, fun));
TestBreakLocationIterator it2(Debug::GetDebugInfo(shared));
- it2.FindBreakLocationFromPosition(position);
+ it2.FindBreakLocationFromPosition(position, v8::internal::STATEMENT_ALIGNED);
actual_mode = it2.it()->rinfo()->rmode();
if (actual_mode == v8::internal::RelocInfo::CODE_TARGET_WITH_ID) {
actual_mode = v8::internal::RelocInfo::CODE_TARGET;
@@ -607,24 +576,6 @@
v8::Local<v8::Function> frame_script_name;
-// Source for the JavaScript function which picks out the script data for the
-// top frame.
-const char* frame_script_data_source =
- "function frame_script_data(exec_state) {"
- " return exec_state.frame(0).func().script().data();"
- "}";
-v8::Local<v8::Function> frame_script_data;
-
-
-// Source for the JavaScript function which picks out the script data from
-// AfterCompile event
-const char* compiled_script_data_source =
- "function compiled_script_data(event_data) {"
- " return event_data.script().data();"
- "}";
-v8::Local<v8::Function> compiled_script_data;
-
-
// Source for the JavaScript function which returns the number of frames.
static const char* frame_count_source =
"function frame_count(exec_state) {"
@@ -636,10 +587,8 @@
// Global variable to store the last function hit - used by some tests.
char last_function_hit[80];
-// Global variable to store the name and data for last script hit - used by some
-// tests.
+// Global variable to store the name for last script hit - used by some tests.
char last_script_name_hit[80];
-char last_script_data_hit[80];
// Global variables to store the last source position - used by some tests.
int last_source_line = -1;
@@ -648,11 +597,12 @@
// Debug event handler which counts the break points which have been hit.
int break_point_hit_count = 0;
int break_point_hit_count_deoptimize = 0;
-static void DebugEventBreakPointHitCount(v8::DebugEvent event,
- v8::Handle<v8::Object> exec_state,
- v8::Handle<v8::Object> event_data,
- v8::Handle<v8::Value> data) {
- Debug* debug = v8::internal::Isolate::Current()->debug();
+static void DebugEventBreakPointHitCount(
+ const v8::Debug::EventDetails& event_details) {
+ v8::DebugEvent event = event_details.GetEvent();
+ v8::Handle<v8::Object> exec_state = event_details.GetExecutionState();
+ v8::internal::Isolate* isolate = CcTest::i_isolate();
+ Debug* debug = isolate->debug();
// When hitting a debug event listener there must be a break set.
CHECK_NE(debug->break_id(), 0);
@@ -662,7 +612,9 @@
if (!frame_function_name.IsEmpty()) {
// Get the name of the function.
const int argc = 2;
- v8::Handle<v8::Value> argv[argc] = { exec_state, v8::Integer::New(0) };
+ v8::Handle<v8::Value> argv[argc] = {
+ exec_state, v8::Integer::New(CcTest::isolate(), 0)
+ };
v8::Handle<v8::Value> result = frame_function_name->Call(exec_state,
argc, argv);
if (result->IsUndefined()) {
@@ -670,7 +622,7 @@
} else {
CHECK(result->IsString());
v8::Handle<v8::String> function_name(result->ToString());
- function_name->WriteAscii(last_function_hit);
+ function_name->WriteUtf8(last_function_hit);
}
}
@@ -705,43 +657,14 @@
} else {
CHECK(result->IsString());
v8::Handle<v8::String> script_name(result->ToString());
- script_name->WriteAscii(last_script_name_hit);
- }
- }
-
- if (!frame_script_data.IsEmpty()) {
- // Get the script data of the function script.
- const int argc = 1;
- v8::Handle<v8::Value> argv[argc] = { exec_state };
- v8::Handle<v8::Value> result = frame_script_data->Call(exec_state,
- argc, argv);
- if (result->IsUndefined()) {
- last_script_data_hit[0] = '\0';
- } else {
- result = result->ToString();
- CHECK(result->IsString());
- v8::Handle<v8::String> script_data(result->ToString());
- script_data->WriteAscii(last_script_data_hit);
+ script_name->WriteUtf8(last_script_name_hit);
}
}
// Perform a full deoptimization when the specified number of
// breaks have been hit.
if (break_point_hit_count == break_point_hit_count_deoptimize) {
- i::Deoptimizer::DeoptimizeAll();
- }
- } else if (event == v8::AfterCompile && !compiled_script_data.IsEmpty()) {
- const int argc = 1;
- v8::Handle<v8::Value> argv[argc] = { event_data };
- v8::Handle<v8::Value> result = compiled_script_data->Call(exec_state,
- argc, argv);
- if (result->IsUndefined()) {
- last_script_data_hit[0] = '\0';
- } else {
- result = result->ToString();
- CHECK(result->IsString());
- v8::Handle<v8::String> script_data(result->ToString());
- script_data->WriteAscii(last_script_data_hit);
+ i::Deoptimizer::DeoptimizeAll(isolate);
}
}
}
@@ -752,6 +675,8 @@
int exception_hit_count = 0;
int uncaught_exception_hit_count = 0;
int last_js_stack_height = -1;
+v8::Handle<v8::Function> debug_event_listener_callback;
+int debug_event_listener_callback_result;
static void DebugEventCounterClear() {
break_point_hit_count = 0;
@@ -759,11 +684,12 @@
uncaught_exception_hit_count = 0;
}
-static void DebugEventCounter(v8::DebugEvent event,
- v8::Handle<v8::Object> exec_state,
- v8::Handle<v8::Object> event_data,
- v8::Handle<v8::Value> data) {
- v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug();
+static void DebugEventCounter(
+ const v8::Debug::EventDetails& event_details) {
+ v8::DebugEvent event = event_details.GetEvent();
+ v8::Handle<v8::Object> exec_state = event_details.GetExecutionState();
+ v8::Handle<v8::Object> event_data = event_details.GetEventData();
+ v8::internal::Debug* debug = CcTest::i_isolate()->debug();
// When hitting a debug event listener there must be a break set.
CHECK_NE(debug->break_id(), 0);
@@ -775,10 +701,11 @@
exception_hit_count++;
// Check whether the exception was uncaught.
- v8::Local<v8::String> fun_name = v8::String::New("uncaught");
+ v8::Local<v8::String> fun_name =
+ v8::String::NewFromUtf8(CcTest::isolate(), "uncaught");
v8::Local<v8::Function> fun =
- v8::Function::Cast(*event_data->Get(fun_name));
- v8::Local<v8::Value> result = *fun->Call(event_data, 0, NULL);
+ v8::Local<v8::Function>::Cast(event_data->Get(fun_name));
+ v8::Local<v8::Value> result = fun->Call(event_data, 0, NULL);
if (result->IsTrue()) {
uncaught_exception_hit_count++;
}
@@ -790,9 +717,17 @@
static const int kArgc = 1;
v8::Handle<v8::Value> argv[kArgc] = { exec_state };
// Using exec_state as receiver is just to have a receiver.
- v8::Handle<v8::Value> result = frame_count->Call(exec_state, kArgc, argv);
+ v8::Handle<v8::Value> result = frame_count->Call(exec_state, kArgc, argv);
last_js_stack_height = result->Int32Value();
}
+
+ // Run callback from DebugEventListener and check the result.
+ if (!debug_event_listener_callback.IsEmpty()) {
+ v8::Handle<v8::Value> result =
+ debug_event_listener_callback->Call(event_data, 0, NULL);
+ CHECK(!result.IsEmpty());
+ CHECK_EQ(debug_event_listener_callback_result, result->Int32Value());
+ }
}
@@ -808,6 +743,8 @@
const char* expr; // An expression to evaluate when a break point is hit.
v8::Handle<v8::Value> expected; // The expected result.
};
+
+
// Array of checks to do.
struct EvaluateCheck* checks = NULL;
// Source for The JavaScript function which can do the evaluation when a break
@@ -819,25 +756,27 @@
v8::Local<v8::Function> evaluate_check_function;
// The actual debug event described by the longer comment above.
-static void DebugEventEvaluate(v8::DebugEvent event,
- v8::Handle<v8::Object> exec_state,
- v8::Handle<v8::Object> event_data,
- v8::Handle<v8::Value> data) {
- v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug();
+static void DebugEventEvaluate(
+ const v8::Debug::EventDetails& event_details) {
+ v8::DebugEvent event = event_details.GetEvent();
+ v8::Handle<v8::Object> exec_state = event_details.GetExecutionState();
+ v8::internal::Debug* debug = CcTest::i_isolate()->debug();
// When hitting a debug event listener there must be a break set.
CHECK_NE(debug->break_id(), 0);
if (event == v8::Break) {
+ break_point_hit_count++;
for (int i = 0; checks[i].expr != NULL; i++) {
const int argc = 3;
- v8::Handle<v8::Value> argv[argc] = { exec_state,
- v8::String::New(checks[i].expr),
- checks[i].expected };
+ v8::Handle<v8::Value> argv[argc] = {
+ exec_state,
+ v8::String::NewFromUtf8(CcTest::isolate(), checks[i].expr),
+ checks[i].expected};
v8::Handle<v8::Value> result =
evaluate_check_function->Call(exec_state, argc, argv);
if (!result->IsTrue()) {
- v8::String::AsciiValue ascii(checks[i].expected->ToString());
- V8_Fatal(__FILE__, __LINE__, "%s != %s", checks[i].expr, *ascii);
+ v8::String::Utf8Value utf8(checks[i].expected->ToString());
+ V8_Fatal(__FILE__, __LINE__, "%s != %s", checks[i].expr, *utf8);
}
}
}
@@ -846,11 +785,11 @@
// This debug event listener removes a breakpoint in a function
int debug_event_remove_break_point = 0;
-static void DebugEventRemoveBreakPoint(v8::DebugEvent event,
- v8::Handle<v8::Object> exec_state,
- v8::Handle<v8::Object> event_data,
- v8::Handle<v8::Value> data) {
- v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug();
+static void DebugEventRemoveBreakPoint(
+ const v8::Debug::EventDetails& event_details) {
+ v8::DebugEvent event = event_details.GetEvent();
+ v8::Handle<v8::Value> data = event_details.GetCallbackData();
+ v8::internal::Debug* debug = CcTest::i_isolate()->debug();
// When hitting a debug event listener there must be a break set.
CHECK_NE(debug->break_id(), 0);
@@ -865,11 +804,10 @@
// Debug event handler which counts break points hit and performs a step
// afterwards.
StepAction step_action = StepIn; // Step action to perform when stepping.
-static void DebugEventStep(v8::DebugEvent event,
- v8::Handle<v8::Object> exec_state,
- v8::Handle<v8::Object> event_data,
- v8::Handle<v8::Value> data) {
- v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug();
+static void DebugEventStep(
+ const v8::Debug::EventDetails& event_details) {
+ v8::DebugEvent event = event_details.GetEvent();
+ v8::internal::Debug* debug = CcTest::i_isolate()->debug();
// When hitting a debug event listener there must be a break set.
CHECK_NE(debug->break_id(), 0);
@@ -892,11 +830,11 @@
const char* expected_step_sequence = NULL;
// The actual debug event described by the longer comment above.
-static void DebugEventStepSequence(v8::DebugEvent event,
- v8::Handle<v8::Object> exec_state,
- v8::Handle<v8::Object> event_data,
- v8::Handle<v8::Value> data) {
- v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug();
+static void DebugEventStepSequence(
+ const v8::Debug::EventDetails& event_details) {
+ v8::DebugEvent event = event_details.GetEvent();
+ v8::Handle<v8::Object> exec_state = event_details.GetExecutionState();
+ v8::internal::Debug* debug = CcTest::i_isolate()->debug();
// When hitting a debug event listener there must be a break set.
CHECK_NE(debug->break_id(), 0);
@@ -905,11 +843,13 @@
CHECK(break_point_hit_count <
StrLength(expected_step_sequence));
const int argc = 2;
- v8::Handle<v8::Value> argv[argc] = { exec_state, v8::Integer::New(0) };
+ v8::Handle<v8::Value> argv[argc] = {
+ exec_state, v8::Integer::New(CcTest::isolate(), 0)
+ };
v8::Handle<v8::Value> result = frame_function_name->Call(exec_state,
argc, argv);
CHECK(result->IsString());
- v8::String::AsciiValue function_name(result->ToString());
+ v8::String::Utf8Value function_name(result->ToString());
CHECK_EQ(1, StrLength(*function_name));
CHECK_EQ((*function_name)[0],
expected_step_sequence[break_point_hit_count]);
@@ -923,11 +863,9 @@
// Debug event handler which performs a garbage collection.
static void DebugEventBreakPointCollectGarbage(
- v8::DebugEvent event,
- v8::Handle<v8::Object> exec_state,
- v8::Handle<v8::Object> event_data,
- v8::Handle<v8::Value> data) {
- v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug();
+ const v8::Debug::EventDetails& event_details) {
+ v8::DebugEvent event = event_details.GetEvent();
+ v8::internal::Debug* debug = CcTest::i_isolate()->debug();
// When hitting a debug event listener there must be a break set.
CHECK_NE(debug->break_id(), 0);
@@ -938,10 +876,10 @@
break_point_hit_count++;
if (break_point_hit_count % 2 == 0) {
// Scavenge.
- HEAP->CollectGarbage(v8::internal::NEW_SPACE);
+ CcTest::heap()->CollectGarbage(v8::internal::NEW_SPACE);
} else {
// Mark sweep compact.
- HEAP->CollectAllGarbage(Heap::kNoGCFlags);
+ CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags);
}
}
}
@@ -949,11 +887,10 @@
// Debug event handler which re-issues a debug break and calls the garbage
// collector to have the heap verified.
-static void DebugEventBreak(v8::DebugEvent event,
- v8::Handle<v8::Object> exec_state,
- v8::Handle<v8::Object> event_data,
- v8::Handle<v8::Value> data) {
- v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug();
+static void DebugEventBreak(
+ const v8::Debug::EventDetails& event_details) {
+ v8::DebugEvent event = event_details.GetEvent();
+ v8::internal::Debug* debug = CcTest::i_isolate()->debug();
// When hitting a debug event listener there must be a break set.
CHECK_NE(debug->break_id(), 0);
@@ -963,10 +900,10 @@
// Run the garbage collector to enforce heap verification if option
// --verify-heap is set.
- HEAP->CollectGarbage(v8::internal::NEW_SPACE);
+ CcTest::heap()->CollectGarbage(v8::internal::NEW_SPACE);
// Set the break flag again to come back here as soon as possible.
- v8::Debug::DebugBreak();
+ v8::Debug::DebugBreak(CcTest::isolate());
}
}
@@ -975,11 +912,13 @@
// reached.
int max_break_point_hit_count = 0;
bool terminate_after_max_break_point_hit = false;
-static void DebugEventBreakMax(v8::DebugEvent event,
- v8::Handle<v8::Object> exec_state,
- v8::Handle<v8::Object> event_data,
- v8::Handle<v8::Value> data) {
- v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug();
+static void DebugEventBreakMax(
+ const v8::Debug::EventDetails& event_details) {
+ v8::DebugEvent event = event_details.GetEvent();
+ v8::Handle<v8::Object> exec_state = event_details.GetExecutionState();
+ v8::Isolate* v8_isolate = CcTest::isolate();
+ v8::internal::Isolate* isolate = CcTest::i_isolate();
+ v8::internal::Debug* debug = isolate->debug();
// When hitting a debug event listener there must be a break set.
CHECK_NE(debug->break_id(), 0);
@@ -1000,17 +939,17 @@
}
// Set the break flag again to come back here as soon as possible.
- v8::Debug::DebugBreak();
+ v8::Debug::DebugBreak(v8_isolate);
} else if (terminate_after_max_break_point_hit) {
// Terminate execution after the last break if requested.
- v8::V8::TerminateExecution();
+ v8::V8::TerminateExecution(v8_isolate);
}
// Perform a full deoptimization when the specified number of
// breaks have been hit.
if (break_point_hit_count == break_point_hit_count_deoptimize) {
- i::Deoptimizer::DeoptimizeAll();
+ i::Deoptimizer::DeoptimizeAll(isolate);
}
}
}
@@ -1040,8 +979,8 @@
TEST(DebugStub) {
using ::v8::internal::Builtins;
using ::v8::internal::Isolate;
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
CheckDebugBreakFunction(&env,
"function f1(){}", "f1",
@@ -1051,14 +990,14 @@
CheckDebugBreakFunction(&env,
"function f2(){x=1;}", "f2",
0,
- v8::internal::RelocInfo::CODE_TARGET_CONTEXT,
- Isolate::Current()->builtins()->builtin(
+ v8::internal::RelocInfo::CODE_TARGET,
+ CcTest::i_isolate()->builtins()->builtin(
Builtins::kStoreIC_DebugBreak));
CheckDebugBreakFunction(&env,
"function f3(){var a=x;}", "f3",
0,
- v8::internal::RelocInfo::CODE_TARGET_CONTEXT,
- Isolate::Current()->builtins()->builtin(
+ v8::internal::RelocInfo::CODE_TARGET,
+ CcTest::i_isolate()->builtins()->builtin(
Builtins::kLoadIC_DebugBreak));
// TODO(1240753): Make the test architecture independent or split
@@ -1072,7 +1011,7 @@
"f4",
0,
v8::internal::RelocInfo::CODE_TARGET,
- Isolate::Current()->builtins()->builtin(
+ CcTest::i_isolate()->builtins()->builtin(
Builtins::kKeyedStoreIC_DebugBreak));
CheckDebugBreakFunction(
&env,
@@ -1080,41 +1019,51 @@
"f5",
0,
v8::internal::RelocInfo::CODE_TARGET,
- Isolate::Current()->builtins()->builtin(
+ CcTest::i_isolate()->builtins()->builtin(
Builtins::kKeyedLoadIC_DebugBreak));
#endif
+ CheckDebugBreakFunction(
+ &env,
+ "function f6(a){return a==null;}",
+ "f6",
+ 0,
+ v8::internal::RelocInfo::CODE_TARGET,
+ CcTest::i_isolate()->builtins()->builtin(
+ Builtins::kCompareNilIC_DebugBreak));
+
// Check the debug break code stubs for call ICs with different number of
// parameters.
- Handle<Code> debug_break_0 = v8::internal::ComputeCallDebugBreak(0);
- Handle<Code> debug_break_1 = v8::internal::ComputeCallDebugBreak(1);
- Handle<Code> debug_break_4 = v8::internal::ComputeCallDebugBreak(4);
+ // TODO(verwaest): XXX update test.
+ // Handle<Code> debug_break_0 = v8::internal::ComputeCallDebugBreak(0);
+ // Handle<Code> debug_break_1 = v8::internal::ComputeCallDebugBreak(1);
+ // Handle<Code> debug_break_4 = v8::internal::ComputeCallDebugBreak(4);
- CheckDebugBreakFunction(&env,
- "function f4_0(){x();}", "f4_0",
- 0,
- v8::internal::RelocInfo::CODE_TARGET_CONTEXT,
- *debug_break_0);
+ // CheckDebugBreakFunction(&env,
+ // "function f4_0(){x();}", "f4_0",
+ // 0,
+ // v8::internal::RelocInfo::CODE_TARGET,
+ // *debug_break_0);
- CheckDebugBreakFunction(&env,
- "function f4_1(){x(1);}", "f4_1",
- 0,
- v8::internal::RelocInfo::CODE_TARGET_CONTEXT,
- *debug_break_1);
+ // CheckDebugBreakFunction(&env,
+ // "function f4_1(){x(1);}", "f4_1",
+ // 0,
+ // v8::internal::RelocInfo::CODE_TARGET,
+ // *debug_break_1);
- CheckDebugBreakFunction(&env,
- "function f4_4(){x(1,2,3,4);}", "f4_4",
- 0,
- v8::internal::RelocInfo::CODE_TARGET_CONTEXT,
- *debug_break_4);
+ // CheckDebugBreakFunction(&env,
+ // "function f4_4(){x(1,2,3,4);}", "f4_4",
+ // 0,
+ // v8::internal::RelocInfo::CODE_TARGET,
+ // *debug_break_4);
}
// Test that the debug info in the VM is in sync with the functions being
// debugged.
TEST(DebugInfo) {
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
// Create a couple of functions for the test.
v8::Local<v8::Function> foo =
CompileFunction(&env, "function foo(){}", "foo");
@@ -1150,14 +1099,14 @@
// Test that a break point can be set at an IC store location.
TEST(BreakPointICStore) {
break_point_hit_count = 0;
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
- v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
- v8::Undefined());
- v8::Script::Compile(v8::String::New("function foo(){bar=0;}"))->Run();
- v8::Local<v8::Function> foo =
- v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("foo")));
+ v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount);
+ v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(),
+ "function foo(){bar=0;}"))->Run();
+ v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast(
+ env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "foo")));
// Run without breakpoints.
foo->Call(env->Global(), 0, NULL);
@@ -1183,14 +1132,16 @@
// Test that a break point can be set at an IC load location.
TEST(BreakPointICLoad) {
break_point_hit_count = 0;
- v8::HandleScope scope;
DebugLocalContext env;
- v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
- v8::Undefined());
- v8::Script::Compile(v8::String::New("bar=1"))->Run();
- v8::Script::Compile(v8::String::New("function foo(){var x=bar;}"))->Run();
- v8::Local<v8::Function> foo =
- v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("foo")));
+ v8::HandleScope scope(env->GetIsolate());
+ v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount);
+ v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), "bar=1"))
+ ->Run();
+ v8::Script::Compile(
+ v8::String::NewFromUtf8(env->GetIsolate(), "function foo(){var x=bar;}"))
+ ->Run();
+ v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast(
+ env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "foo")));
// Run without breakpoints.
foo->Call(env->Global(), 0, NULL);
@@ -1216,14 +1167,15 @@
// Test that a break point can be set at an IC call location.
TEST(BreakPointICCall) {
break_point_hit_count = 0;
- v8::HandleScope scope;
DebugLocalContext env;
- v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
- v8::Undefined());
- v8::Script::Compile(v8::String::New("function bar(){}"))->Run();
- v8::Script::Compile(v8::String::New("function foo(){bar();}"))->Run();
- v8::Local<v8::Function> foo =
- v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("foo")));
+ v8::HandleScope scope(env->GetIsolate());
+ v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount);
+ v8::Script::Compile(
+ v8::String::NewFromUtf8(env->GetIsolate(), "function bar(){}"))->Run();
+ v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(),
+ "function foo(){bar();}"))->Run();
+ v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast(
+ env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "foo")));
// Run without breakpoints.
foo->Call(env->Global(), 0, NULL);
@@ -1249,14 +1201,17 @@
// Test that a break point can be set at an IC call location and survive a GC.
TEST(BreakPointICCallWithGC) {
break_point_hit_count = 0;
- v8::HandleScope scope;
DebugLocalContext env;
- v8::Debug::SetDebugEventListener(DebugEventBreakPointCollectGarbage,
- v8::Undefined());
- v8::Script::Compile(v8::String::New("function bar(){return 1;}"))->Run();
- v8::Script::Compile(v8::String::New("function foo(){return bar();}"))->Run();
- v8::Local<v8::Function> foo =
- v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("foo")));
+ v8::HandleScope scope(env->GetIsolate());
+ v8::Debug::SetDebugEventListener(DebugEventBreakPointCollectGarbage);
+ v8::Script::Compile(
+ v8::String::NewFromUtf8(env->GetIsolate(), "function bar(){return 1;}"))
+ ->Run();
+ v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(),
+ "function foo(){return bar();}"))
+ ->Run();
+ v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast(
+ env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "foo")));
// Run without breakpoints.
CHECK_EQ(1, foo->Call(env->Global(), 0, NULL)->Int32Value());
@@ -1282,15 +1237,17 @@
// Test that a break point can be set at an IC call location and survive a GC.
TEST(BreakPointConstructCallWithGC) {
break_point_hit_count = 0;
- v8::HandleScope scope;
DebugLocalContext env;
- v8::Debug::SetDebugEventListener(DebugEventBreakPointCollectGarbage,
- v8::Undefined());
- v8::Script::Compile(v8::String::New("function bar(){ this.x = 1;}"))->Run();
- v8::Script::Compile(v8::String::New(
- "function foo(){return new bar(1).x;}"))->Run();
- v8::Local<v8::Function> foo =
- v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("foo")));
+ v8::HandleScope scope(env->GetIsolate());
+ v8::Debug::SetDebugEventListener(DebugEventBreakPointCollectGarbage);
+ v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(),
+ "function bar(){ this.x = 1;}"))
+ ->Run();
+ v8::Script::Compile(
+ v8::String::NewFromUtf8(env->GetIsolate(),
+ "function foo(){return new bar(1).x;}"))->Run();
+ v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast(
+ env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "foo")));
// Run without breakpoints.
CHECK_EQ(1, foo->Call(env->Global(), 0, NULL)->Int32Value());
@@ -1316,8 +1273,8 @@
// Test that a break point can be set at a return store location.
TEST(BreakPointReturn) {
break_point_hit_count = 0;
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
// Create a functions for checking the source line and column when hitting
// a break point.
@@ -1329,11 +1286,11 @@
"frame_source_column");
- v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
- v8::Undefined());
- v8::Script::Compile(v8::String::New("function foo(){}"))->Run();
- v8::Local<v8::Function> foo =
- v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("foo")));
+ v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount);
+ v8::Script::Compile(
+ v8::String::NewFromUtf8(env->GetIsolate(), "function foo(){}"))->Run();
+ v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast(
+ env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "foo")));
// Run without breakpoints.
foo->Call(env->Global(), 0, NULL);
@@ -1371,14 +1328,14 @@
}
}
+
// Test GC during break point processing.
TEST(GCDuringBreakPointProcessing) {
break_point_hit_count = 0;
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
- v8::Debug::SetDebugEventListener(DebugEventBreakPointCollectGarbage,
- v8::Undefined());
+ v8::Debug::SetDebugEventListener(DebugEventBreakPointCollectGarbage);
v8::Local<v8::Function> foo;
// Test IC store break point with garbage collection.
@@ -1423,12 +1380,12 @@
CHECK_EQ(1 + i * 3, break_point_hit_count);
// Scavenge and call function.
- HEAP->CollectGarbage(v8::internal::NEW_SPACE);
+ CcTest::heap()->CollectGarbage(v8::internal::NEW_SPACE);
f->Call(recv, 0, NULL);
CHECK_EQ(2 + i * 3, break_point_hit_count);
// Mark sweep (and perhaps compact) and call function.
- HEAP->CollectAllGarbage(Heap::kNoGCFlags);
+ CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags);
f->Call(recv, 0, NULL);
CHECK_EQ(3 + i * 3, break_point_hit_count);
}
@@ -1438,11 +1395,10 @@
// Test that a break point can be set at a return store location.
TEST(BreakPointSurviveGC) {
break_point_hit_count = 0;
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
- v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
- v8::Undefined());
+ v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount);
v8::Local<v8::Function> foo;
// Test IC store break point with garbage collection.
@@ -1496,46 +1452,49 @@
// Test that break points can be set using the global Debug object.
TEST(BreakPointThroughJavaScript) {
break_point_hit_count = 0;
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
env.ExposeDebug();
- v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
- v8::Undefined());
- v8::Script::Compile(v8::String::New("function bar(){}"))->Run();
- v8::Script::Compile(v8::String::New("function foo(){bar();bar();}"))->Run();
+ v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount);
+ v8::Script::Compile(
+ v8::String::NewFromUtf8(env->GetIsolate(), "function bar(){}"))->Run();
+ v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(),
+ "function foo(){bar();bar();}"))
+ ->Run();
// 012345678901234567890
// 1 2
// Break points are set at position 3 and 9
- v8::Local<v8::Script> foo = v8::Script::Compile(v8::String::New("foo()"));
+ v8::Local<v8::Script> foo =
+ v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), "foo()"));
// Run without breakpoints.
foo->Run();
CHECK_EQ(0, break_point_hit_count);
// Run with one breakpoint
- int bp1 = SetBreakPointFromJS("foo", 0, 3);
+ int bp1 = SetBreakPointFromJS(env->GetIsolate(), "foo", 0, 3);
foo->Run();
CHECK_EQ(1, break_point_hit_count);
foo->Run();
CHECK_EQ(2, break_point_hit_count);
// Run with two breakpoints
- int bp2 = SetBreakPointFromJS("foo", 0, 9);
+ int bp2 = SetBreakPointFromJS(env->GetIsolate(), "foo", 0, 9);
foo->Run();
CHECK_EQ(4, break_point_hit_count);
foo->Run();
CHECK_EQ(6, break_point_hit_count);
// Run with one breakpoint
- ClearBreakPointFromJS(bp2);
+ ClearBreakPointFromJS(env->GetIsolate(), bp2);
foo->Run();
CHECK_EQ(7, break_point_hit_count);
foo->Run();
CHECK_EQ(8, break_point_hit_count);
// Run without breakpoints.
- ClearBreakPointFromJS(bp1);
+ ClearBreakPointFromJS(env->GetIsolate(), bp1);
foo->Run();
CHECK_EQ(8, break_point_hit_count);
@@ -1552,14 +1511,14 @@
// global Debug object.
TEST(ScriptBreakPointByNameThroughJavaScript) {
break_point_hit_count = 0;
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
env.ExposeDebug();
- v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
- v8::Undefined());
+ v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount);
- v8::Local<v8::String> script = v8::String::New(
+ v8::Local<v8::String> script = v8::String::NewFromUtf8(
+ env->GetIsolate(),
"function f() {\n"
" function h() {\n"
" a = 0; // line 2\n"
@@ -1580,12 +1539,12 @@
// Compile the script and get the two functions.
v8::ScriptOrigin origin =
- v8::ScriptOrigin(v8::String::New("test"));
+ v8::ScriptOrigin(v8::String::NewFromUtf8(env->GetIsolate(), "test"));
v8::Script::Compile(script, &origin)->Run();
- v8::Local<v8::Function> f =
- v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));
- v8::Local<v8::Function> g =
- v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("g")));
+ v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast(
+ env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f")));
+ v8::Local<v8::Function> g = v8::Local<v8::Function>::Cast(
+ env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "g")));
// Call f and g without break points.
break_point_hit_count = 0;
@@ -1595,7 +1554,7 @@
CHECK_EQ(0, break_point_hit_count);
// Call f and g with break point on line 12.
- int sbp1 = SetScriptBreakPointByNameFromJS("test", 12, 0);
+ int sbp1 = SetScriptBreakPointByNameFromJS(env->GetIsolate(), "test", 12, 0);
break_point_hit_count = 0;
f->Call(env->Global(), 0, NULL);
CHECK_EQ(0, break_point_hit_count);
@@ -1604,14 +1563,14 @@
// Remove the break point again.
break_point_hit_count = 0;
- ClearBreakPointFromJS(sbp1);
+ ClearBreakPointFromJS(env->GetIsolate(), sbp1);
f->Call(env->Global(), 0, NULL);
CHECK_EQ(0, break_point_hit_count);
g->Call(env->Global(), 0, NULL);
CHECK_EQ(0, break_point_hit_count);
// Call f and g with break point on line 2.
- int sbp2 = SetScriptBreakPointByNameFromJS("test", 2, 0);
+ int sbp2 = SetScriptBreakPointByNameFromJS(env->GetIsolate(), "test", 2, 0);
break_point_hit_count = 0;
f->Call(env->Global(), 0, NULL);
CHECK_EQ(1, break_point_hit_count);
@@ -1619,10 +1578,10 @@
CHECK_EQ(2, break_point_hit_count);
// Call f and g with break point on line 2, 4, 12, 14 and 15.
- int sbp3 = SetScriptBreakPointByNameFromJS("test", 4, 0);
- int sbp4 = SetScriptBreakPointByNameFromJS("test", 12, 0);
- int sbp5 = SetScriptBreakPointByNameFromJS("test", 14, 0);
- int sbp6 = SetScriptBreakPointByNameFromJS("test", 15, 0);
+ int sbp3 = SetScriptBreakPointByNameFromJS(env->GetIsolate(), "test", 4, 0);
+ int sbp4 = SetScriptBreakPointByNameFromJS(env->GetIsolate(), "test", 12, 0);
+ int sbp5 = SetScriptBreakPointByNameFromJS(env->GetIsolate(), "test", 14, 0);
+ int sbp6 = SetScriptBreakPointByNameFromJS(env->GetIsolate(), "test", 15, 0);
break_point_hit_count = 0;
f->Call(env->Global(), 0, NULL);
CHECK_EQ(2, break_point_hit_count);
@@ -1631,11 +1590,11 @@
// Remove all the break points again.
break_point_hit_count = 0;
- ClearBreakPointFromJS(sbp2);
- ClearBreakPointFromJS(sbp3);
- ClearBreakPointFromJS(sbp4);
- ClearBreakPointFromJS(sbp5);
- ClearBreakPointFromJS(sbp6);
+ ClearBreakPointFromJS(env->GetIsolate(), sbp2);
+ ClearBreakPointFromJS(env->GetIsolate(), sbp3);
+ ClearBreakPointFromJS(env->GetIsolate(), sbp4);
+ ClearBreakPointFromJS(env->GetIsolate(), sbp5);
+ ClearBreakPointFromJS(env->GetIsolate(), sbp6);
f->Call(env->Global(), 0, NULL);
CHECK_EQ(0, break_point_hit_count);
g->Call(env->Global(), 0, NULL);
@@ -1656,14 +1615,14 @@
TEST(ScriptBreakPointByIdThroughJavaScript) {
break_point_hit_count = 0;
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
env.ExposeDebug();
- v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
- v8::Undefined());
+ v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount);
- v8::Local<v8::String> source = v8::String::New(
+ v8::Local<v8::String> source = v8::String::NewFromUtf8(
+ env->GetIsolate(),
"function f() {\n"
" function h() {\n"
" a = 0; // line 2\n"
@@ -1684,16 +1643,16 @@
// Compile the script and get the two functions.
v8::ScriptOrigin origin =
- v8::ScriptOrigin(v8::String::New("test"));
+ v8::ScriptOrigin(v8::String::NewFromUtf8(env->GetIsolate(), "test"));
v8::Local<v8::Script> script = v8::Script::Compile(source, &origin);
script->Run();
- v8::Local<v8::Function> f =
- v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));
- v8::Local<v8::Function> g =
- v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("g")));
+ v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast(
+ env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f")));
+ v8::Local<v8::Function> g = v8::Local<v8::Function>::Cast(
+ env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "g")));
// Get the script id knowing that internally it is a 32 integer.
- uint32_t script_id = script->Id()->Uint32Value();
+ int script_id = script->GetUnboundScript()->GetId();
// Call f and g without break points.
break_point_hit_count = 0;
@@ -1703,7 +1662,7 @@
CHECK_EQ(0, break_point_hit_count);
// Call f and g with break point on line 12.
- int sbp1 = SetScriptBreakPointByIdFromJS(script_id, 12, 0);
+ int sbp1 = SetScriptBreakPointByIdFromJS(env->GetIsolate(), script_id, 12, 0);
break_point_hit_count = 0;
f->Call(env->Global(), 0, NULL);
CHECK_EQ(0, break_point_hit_count);
@@ -1712,14 +1671,14 @@
// Remove the break point again.
break_point_hit_count = 0;
- ClearBreakPointFromJS(sbp1);
+ ClearBreakPointFromJS(env->GetIsolate(), sbp1);
f->Call(env->Global(), 0, NULL);
CHECK_EQ(0, break_point_hit_count);
g->Call(env->Global(), 0, NULL);
CHECK_EQ(0, break_point_hit_count);
// Call f and g with break point on line 2.
- int sbp2 = SetScriptBreakPointByIdFromJS(script_id, 2, 0);
+ int sbp2 = SetScriptBreakPointByIdFromJS(env->GetIsolate(), script_id, 2, 0);
break_point_hit_count = 0;
f->Call(env->Global(), 0, NULL);
CHECK_EQ(1, break_point_hit_count);
@@ -1727,10 +1686,10 @@
CHECK_EQ(2, break_point_hit_count);
// Call f and g with break point on line 2, 4, 12, 14 and 15.
- int sbp3 = SetScriptBreakPointByIdFromJS(script_id, 4, 0);
- int sbp4 = SetScriptBreakPointByIdFromJS(script_id, 12, 0);
- int sbp5 = SetScriptBreakPointByIdFromJS(script_id, 14, 0);
- int sbp6 = SetScriptBreakPointByIdFromJS(script_id, 15, 0);
+ int sbp3 = SetScriptBreakPointByIdFromJS(env->GetIsolate(), script_id, 4, 0);
+ int sbp4 = SetScriptBreakPointByIdFromJS(env->GetIsolate(), script_id, 12, 0);
+ int sbp5 = SetScriptBreakPointByIdFromJS(env->GetIsolate(), script_id, 14, 0);
+ int sbp6 = SetScriptBreakPointByIdFromJS(env->GetIsolate(), script_id, 15, 0);
break_point_hit_count = 0;
f->Call(env->Global(), 0, NULL);
CHECK_EQ(2, break_point_hit_count);
@@ -1739,11 +1698,11 @@
// Remove all the break points again.
break_point_hit_count = 0;
- ClearBreakPointFromJS(sbp2);
- ClearBreakPointFromJS(sbp3);
- ClearBreakPointFromJS(sbp4);
- ClearBreakPointFromJS(sbp5);
- ClearBreakPointFromJS(sbp6);
+ ClearBreakPointFromJS(env->GetIsolate(), sbp2);
+ ClearBreakPointFromJS(env->GetIsolate(), sbp3);
+ ClearBreakPointFromJS(env->GetIsolate(), sbp4);
+ ClearBreakPointFromJS(env->GetIsolate(), sbp5);
+ ClearBreakPointFromJS(env->GetIsolate(), sbp6);
f->Call(env->Global(), 0, NULL);
CHECK_EQ(0, break_point_hit_count);
g->Call(env->Global(), 0, NULL);
@@ -1765,52 +1724,53 @@
// Test conditional script break points.
TEST(EnableDisableScriptBreakPoint) {
break_point_hit_count = 0;
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
env.ExposeDebug();
- v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
- v8::Undefined());
+ v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount);
- v8::Local<v8::String> script = v8::String::New(
+ v8::Local<v8::String> script = v8::String::NewFromUtf8(
+ env->GetIsolate(),
"function f() {\n"
" a = 0; // line 1\n"
"};");
// Compile the script and get function f.
v8::ScriptOrigin origin =
- v8::ScriptOrigin(v8::String::New("test"));
+ v8::ScriptOrigin(v8::String::NewFromUtf8(env->GetIsolate(), "test"));
v8::Script::Compile(script, &origin)->Run();
- v8::Local<v8::Function> f =
- v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));
+ v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast(
+ env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f")));
// Set script break point on line 1 (in function f).
- int sbp = SetScriptBreakPointByNameFromJS("test", 1, 0);
+ int sbp = SetScriptBreakPointByNameFromJS(env->GetIsolate(), "test", 1, 0);
// Call f while enabeling and disabling the script break point.
break_point_hit_count = 0;
f->Call(env->Global(), 0, NULL);
CHECK_EQ(1, break_point_hit_count);
- DisableScriptBreakPointFromJS(sbp);
+ DisableScriptBreakPointFromJS(env->GetIsolate(), sbp);
f->Call(env->Global(), 0, NULL);
CHECK_EQ(1, break_point_hit_count);
- EnableScriptBreakPointFromJS(sbp);
+ EnableScriptBreakPointFromJS(env->GetIsolate(), sbp);
f->Call(env->Global(), 0, NULL);
CHECK_EQ(2, break_point_hit_count);
- DisableScriptBreakPointFromJS(sbp);
+ DisableScriptBreakPointFromJS(env->GetIsolate(), sbp);
f->Call(env->Global(), 0, NULL);
CHECK_EQ(2, break_point_hit_count);
// Reload the script and get f again checking that the disabeling survives.
v8::Script::Compile(script, &origin)->Run();
- f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));
+ f = v8::Local<v8::Function>::Cast(
+ env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f")));
f->Call(env->Global(), 0, NULL);
CHECK_EQ(2, break_point_hit_count);
- EnableScriptBreakPointFromJS(sbp);
+ EnableScriptBreakPointFromJS(env->GetIsolate(), sbp);
f->Call(env->Global(), 0, NULL);
CHECK_EQ(3, break_point_hit_count);
@@ -1822,14 +1782,14 @@
// Test conditional script break points.
TEST(ConditionalScriptBreakPoint) {
break_point_hit_count = 0;
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
env.ExposeDebug();
- v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
- v8::Undefined());
+ v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount);
- v8::Local<v8::String> script = v8::String::New(
+ v8::Local<v8::String> script = v8::String::NewFromUtf8(
+ env->GetIsolate(),
"count = 0;\n"
"function f() {\n"
" g(count++); // line 2\n"
@@ -1840,26 +1800,26 @@
// Compile the script and get function f.
v8::ScriptOrigin origin =
- v8::ScriptOrigin(v8::String::New("test"));
+ v8::ScriptOrigin(v8::String::NewFromUtf8(env->GetIsolate(), "test"));
v8::Script::Compile(script, &origin)->Run();
- v8::Local<v8::Function> f =
- v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));
+ v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast(
+ env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f")));
// Set script break point on line 5 (in function g).
- int sbp1 = SetScriptBreakPointByNameFromJS("test", 5, 0);
+ int sbp1 = SetScriptBreakPointByNameFromJS(env->GetIsolate(), "test", 5, 0);
// Call f with different conditions on the script break point.
break_point_hit_count = 0;
- ChangeScriptBreakPointConditionFromJS(sbp1, "false");
+ ChangeScriptBreakPointConditionFromJS(env->GetIsolate(), sbp1, "false");
f->Call(env->Global(), 0, NULL);
CHECK_EQ(0, break_point_hit_count);
- ChangeScriptBreakPointConditionFromJS(sbp1, "true");
+ ChangeScriptBreakPointConditionFromJS(env->GetIsolate(), sbp1, "true");
break_point_hit_count = 0;
f->Call(env->Global(), 0, NULL);
CHECK_EQ(1, break_point_hit_count);
- ChangeScriptBreakPointConditionFromJS(sbp1, "x % 2 == 0");
+ ChangeScriptBreakPointConditionFromJS(env->GetIsolate(), sbp1, "x % 2 == 0");
break_point_hit_count = 0;
for (int i = 0; i < 10; i++) {
f->Call(env->Global(), 0, NULL);
@@ -1868,7 +1828,8 @@
// Reload the script and get f again checking that the condition survives.
v8::Script::Compile(script, &origin)->Run();
- f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));
+ f = v8::Local<v8::Function>::Cast(
+ env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f")));
break_point_hit_count = 0;
for (int i = 0; i < 10; i++) {
@@ -1884,37 +1845,37 @@
// Test ignore count on script break points.
TEST(ScriptBreakPointIgnoreCount) {
break_point_hit_count = 0;
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
env.ExposeDebug();
- v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
- v8::Undefined());
+ v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount);
- v8::Local<v8::String> script = v8::String::New(
+ v8::Local<v8::String> script = v8::String::NewFromUtf8(
+ env->GetIsolate(),
"function f() {\n"
" a = 0; // line 1\n"
"};");
// Compile the script and get function f.
v8::ScriptOrigin origin =
- v8::ScriptOrigin(v8::String::New("test"));
+ v8::ScriptOrigin(v8::String::NewFromUtf8(env->GetIsolate(), "test"));
v8::Script::Compile(script, &origin)->Run();
- v8::Local<v8::Function> f =
- v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));
+ v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast(
+ env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f")));
// Set script break point on line 1 (in function f).
- int sbp = SetScriptBreakPointByNameFromJS("test", 1, 0);
+ int sbp = SetScriptBreakPointByNameFromJS(env->GetIsolate(), "test", 1, 0);
// Call f with different ignores on the script break point.
break_point_hit_count = 0;
- ChangeScriptBreakPointIgnoreCountFromJS(sbp, 1);
+ ChangeScriptBreakPointIgnoreCountFromJS(env->GetIsolate(), sbp, 1);
f->Call(env->Global(), 0, NULL);
CHECK_EQ(0, break_point_hit_count);
f->Call(env->Global(), 0, NULL);
CHECK_EQ(1, break_point_hit_count);
- ChangeScriptBreakPointIgnoreCountFromJS(sbp, 5);
+ ChangeScriptBreakPointIgnoreCountFromJS(env->GetIsolate(), sbp, 5);
break_point_hit_count = 0;
for (int i = 0; i < 10; i++) {
f->Call(env->Global(), 0, NULL);
@@ -1923,7 +1884,8 @@
// Reload the script and get f again checking that the ignore survives.
v8::Script::Compile(script, &origin)->Run();
- f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));
+ f = v8::Local<v8::Function>::Cast(
+ env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f")));
break_point_hit_count = 0;
for (int i = 0; i < 10; i++) {
@@ -1939,15 +1901,15 @@
// Test that script break points survive when a script is reloaded.
TEST(ScriptBreakPointReload) {
break_point_hit_count = 0;
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
env.ExposeDebug();
- v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
- v8::Undefined());
+ v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount);
v8::Local<v8::Function> f;
- v8::Local<v8::String> script = v8::String::New(
+ v8::Local<v8::String> script = v8::String::NewFromUtf8(
+ env->GetIsolate(),
"function f() {\n"
" function h() {\n"
" a = 0; // line 2\n"
@@ -1956,15 +1918,18 @@
" return h();\n"
"}");
- v8::ScriptOrigin origin_1 = v8::ScriptOrigin(v8::String::New("1"));
- v8::ScriptOrigin origin_2 = v8::ScriptOrigin(v8::String::New("2"));
+ v8::ScriptOrigin origin_1 =
+ v8::ScriptOrigin(v8::String::NewFromUtf8(env->GetIsolate(), "1"));
+ v8::ScriptOrigin origin_2 =
+ v8::ScriptOrigin(v8::String::NewFromUtf8(env->GetIsolate(), "2"));
// Set a script break point before the script is loaded.
- SetScriptBreakPointByNameFromJS("1", 2, 0);
+ SetScriptBreakPointByNameFromJS(env->GetIsolate(), "1", 2, 0);
// Compile the script and get the function.
v8::Script::Compile(script, &origin_1)->Run();
- f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));
+ f = v8::Local<v8::Function>::Cast(
+ env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f")));
// Call f and check that the script break point is active.
break_point_hit_count = 0;
@@ -1974,7 +1939,8 @@
// Compile the script again with a different script data and get the
// function.
v8::Script::Compile(script, &origin_2)->Run();
- f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));
+ f = v8::Local<v8::Function>::Cast(
+ env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f")));
// Call f and check that no break points are set.
break_point_hit_count = 0;
@@ -1983,7 +1949,8 @@
// Compile the script again and get the function.
v8::Script::Compile(script, &origin_1)->Run();
- f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));
+ f = v8::Local<v8::Function>::Cast(
+ env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f")));
// Call f and check that the script break point is active.
break_point_hit_count = 0;
@@ -1998,36 +1965,39 @@
// Test when several scripts has the same script data
TEST(ScriptBreakPointMultiple) {
break_point_hit_count = 0;
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
env.ExposeDebug();
- v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
- v8::Undefined());
+ v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount);
v8::Local<v8::Function> f;
- v8::Local<v8::String> script_f = v8::String::New(
- "function f() {\n"
- " a = 0; // line 1\n"
- "}");
+ v8::Local<v8::String> script_f =
+ v8::String::NewFromUtf8(env->GetIsolate(),
+ "function f() {\n"
+ " a = 0; // line 1\n"
+ "}");
v8::Local<v8::Function> g;
- v8::Local<v8::String> script_g = v8::String::New(
- "function g() {\n"
- " b = 0; // line 1\n"
- "}");
+ v8::Local<v8::String> script_g =
+ v8::String::NewFromUtf8(env->GetIsolate(),
+ "function g() {\n"
+ " b = 0; // line 1\n"
+ "}");
v8::ScriptOrigin origin =
- v8::ScriptOrigin(v8::String::New("test"));
+ v8::ScriptOrigin(v8::String::NewFromUtf8(env->GetIsolate(), "test"));
// Set a script break point before the scripts are loaded.
- int sbp = SetScriptBreakPointByNameFromJS("test", 1, 0);
+ int sbp = SetScriptBreakPointByNameFromJS(env->GetIsolate(), "test", 1, 0);
// Compile the scripts with same script data and get the functions.
v8::Script::Compile(script_f, &origin)->Run();
- f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));
+ f = v8::Local<v8::Function>::Cast(
+ env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f")));
v8::Script::Compile(script_g, &origin)->Run();
- g = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("g")));
+ g = v8::Local<v8::Function>::Cast(
+ env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "g")));
// Call f and g and check that the script break point is active.
break_point_hit_count = 0;
@@ -2037,7 +2007,7 @@
CHECK_EQ(2, break_point_hit_count);
// Clear the script break point.
- ClearBreakPointFromJS(sbp);
+ ClearBreakPointFromJS(env->GetIsolate(), sbp);
// Call f and g and check that the script break point is no longer active.
break_point_hit_count = 0;
@@ -2047,7 +2017,7 @@
CHECK_EQ(0, break_point_hit_count);
// Set script break point with the scripts loaded.
- sbp = SetScriptBreakPointByNameFromJS("test", 1, 0);
+ sbp = SetScriptBreakPointByNameFromJS(env->GetIsolate(), "test", 1, 0);
// Call f and g and check that the script break point is active.
break_point_hit_count = 0;
@@ -2064,31 +2034,35 @@
// Test the script origin which has both name and line offset.
TEST(ScriptBreakPointLineOffset) {
break_point_hit_count = 0;
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
env.ExposeDebug();
- v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
- v8::Undefined());
+ v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount);
v8::Local<v8::Function> f;
- v8::Local<v8::String> script = v8::String::New(
- "function f() {\n"
- " a = 0; // line 8 as this script has line offset 7\n"
- " b = 0; // line 9 as this script has line offset 7\n"
- "}");
+ v8::Local<v8::String> script = v8::String::NewFromUtf8(
+ env->GetIsolate(),
+ "function f() {\n"
+ " a = 0; // line 8 as this script has line offset 7\n"
+ " b = 0; // line 9 as this script has line offset 7\n"
+ "}");
// Create script origin both name and line offset.
- v8::ScriptOrigin origin(v8::String::New("test.html"),
- v8::Integer::New(7));
+ v8::ScriptOrigin origin(
+ v8::String::NewFromUtf8(env->GetIsolate(), "test.html"),
+ v8::Integer::New(env->GetIsolate(), 7));
// Set two script break points before the script is loaded.
- int sbp1 = SetScriptBreakPointByNameFromJS("test.html", 8, 0);
- int sbp2 = SetScriptBreakPointByNameFromJS("test.html", 9, 0);
+ int sbp1 =
+ SetScriptBreakPointByNameFromJS(env->GetIsolate(), "test.html", 8, 0);
+ int sbp2 =
+ SetScriptBreakPointByNameFromJS(env->GetIsolate(), "test.html", 9, 0);
// Compile the script and get the function.
v8::Script::Compile(script, &origin)->Run();
- f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));
+ f = v8::Local<v8::Function>::Cast(
+ env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f")));
// Call f and check that the script break point is active.
break_point_hit_count = 0;
@@ -2096,8 +2070,8 @@
CHECK_EQ(2, break_point_hit_count);
// Clear the script break points.
- ClearBreakPointFromJS(sbp1);
- ClearBreakPointFromJS(sbp2);
+ ClearBreakPointFromJS(env->GetIsolate(), sbp1);
+ ClearBreakPointFromJS(env->GetIsolate(), sbp2);
// Call f and check that no script break points are active.
break_point_hit_count = 0;
@@ -2105,7 +2079,7 @@
CHECK_EQ(0, break_point_hit_count);
// Set a script break point with the script loaded.
- sbp1 = SetScriptBreakPointByNameFromJS("test.html", 9, 0);
+ sbp1 = SetScriptBreakPointByNameFromJS(env->GetIsolate(), "test.html", 9, 0);
// Call f and check that the script break point is active.
break_point_hit_count = 0;
@@ -2119,8 +2093,8 @@
// Test script break points set on lines.
TEST(ScriptBreakPointLine) {
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
env.ExposeDebug();
// Create a function for checking the function when hitting a break point.
@@ -2128,37 +2102,44 @@
frame_function_name_source,
"frame_function_name");
- v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
- v8::Undefined());
+ v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount);
v8::Local<v8::Function> f;
v8::Local<v8::Function> g;
- v8::Local<v8::String> script = v8::String::New(
- "a = 0 // line 0\n"
- "function f() {\n"
- " a = 1; // line 2\n"
- "}\n"
- " a = 2; // line 4\n"
- " /* xx */ function g() { // line 5\n"
- " function h() { // line 6\n"
- " a = 3; // line 7\n"
- " }\n"
- " h(); // line 9\n"
- " a = 4; // line 10\n"
- " }\n"
- " a=5; // line 12");
+ v8::Local<v8::String> script =
+ v8::String::NewFromUtf8(env->GetIsolate(),
+ "a = 0 // line 0\n"
+ "function f() {\n"
+ " a = 1; // line 2\n"
+ "}\n"
+ " a = 2; // line 4\n"
+ " /* xx */ function g() { // line 5\n"
+ " function h() { // line 6\n"
+ " a = 3; // line 7\n"
+ " }\n"
+ " h(); // line 9\n"
+ " a = 4; // line 10\n"
+ " }\n"
+ " a=5; // line 12");
// Set a couple script break point before the script is loaded.
- int sbp1 = SetScriptBreakPointByNameFromJS("test.html", 0, -1);
- int sbp2 = SetScriptBreakPointByNameFromJS("test.html", 1, -1);
- int sbp3 = SetScriptBreakPointByNameFromJS("test.html", 5, -1);
+ int sbp1 =
+ SetScriptBreakPointByNameFromJS(env->GetIsolate(), "test.html", 0, -1);
+ int sbp2 =
+ SetScriptBreakPointByNameFromJS(env->GetIsolate(), "test.html", 1, -1);
+ int sbp3 =
+ SetScriptBreakPointByNameFromJS(env->GetIsolate(), "test.html", 5, -1);
// Compile the script and get the function.
break_point_hit_count = 0;
- v8::ScriptOrigin origin(v8::String::New("test.html"), v8::Integer::New(0));
+ v8::ScriptOrigin origin(
+ v8::String::NewFromUtf8(env->GetIsolate(), "test.html"),
+ v8::Integer::New(env->GetIsolate(), 0));
v8::Script::Compile(script, &origin)->Run();
- f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));
- g = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("g")));
+ f = v8::Local<v8::Function>::Cast(
+ env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f")));
+ g = v8::Local<v8::Function>::Cast(
+ env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "g")));
// Check that a break point was hit when the script was run.
CHECK_EQ(1, break_point_hit_count);
@@ -2175,8 +2156,9 @@
CHECK_EQ("g", last_function_hit);
// Clear the script break point on g and set one on h.
- ClearBreakPointFromJS(sbp3);
- int sbp4 = SetScriptBreakPointByNameFromJS("test.html", 6, -1);
+ ClearBreakPointFromJS(env->GetIsolate(), sbp3);
+ int sbp4 =
+ SetScriptBreakPointByNameFromJS(env->GetIsolate(), "test.html", 6, -1);
// Call g and check that the script break point in h is hit.
g->Call(env->Global(), 0, NULL);
@@ -2186,9 +2168,10 @@
// Clear break points in f and h. Set a new one in the script between
// functions f and g and test that there is no break points in f and g any
// more.
- ClearBreakPointFromJS(sbp2);
- ClearBreakPointFromJS(sbp4);
- int sbp5 = SetScriptBreakPointByNameFromJS("test.html", 4, -1);
+ ClearBreakPointFromJS(env->GetIsolate(), sbp2);
+ ClearBreakPointFromJS(env->GetIsolate(), sbp4);
+ int sbp5 =
+ SetScriptBreakPointByNameFromJS(env->GetIsolate(), "test.html", 4, -1);
break_point_hit_count = 0;
f->Call(env->Global(), 0, NULL);
g->Call(env->Global(), 0, NULL);
@@ -2201,7 +2184,8 @@
CHECK_EQ(0, StrLength(last_function_hit));
// Set a break point in the code after the last function decleration.
- int sbp6 = SetScriptBreakPointByNameFromJS("test.html", 12, -1);
+ int sbp6 =
+ SetScriptBreakPointByNameFromJS(env->GetIsolate(), "test.html", 12, -1);
// Reload the script which should hit three break points.
break_point_hit_count = 0;
@@ -2211,9 +2195,9 @@
// Clear the last break points, and reload the script which should not hit any
// break points.
- ClearBreakPointFromJS(sbp1);
- ClearBreakPointFromJS(sbp5);
- ClearBreakPointFromJS(sbp6);
+ ClearBreakPointFromJS(env->GetIsolate(), sbp1);
+ ClearBreakPointFromJS(env->GetIsolate(), sbp5);
+ ClearBreakPointFromJS(env->GetIsolate(), sbp6);
break_point_hit_count = 0;
v8::Script::Compile(script, &origin)->Run();
CHECK_EQ(0, break_point_hit_count);
@@ -2225,28 +2209,29 @@
// Test top level script break points set on lines.
TEST(ScriptBreakPointLineTopLevel) {
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
env.ExposeDebug();
- v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
- v8::Undefined());
+ v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount);
- v8::Local<v8::String> script = v8::String::New(
- "function f() {\n"
- " a = 1; // line 1\n"
- "}\n"
- "a = 2; // line 3\n");
+ v8::Local<v8::String> script =
+ v8::String::NewFromUtf8(env->GetIsolate(),
+ "function f() {\n"
+ " a = 1; // line 1\n"
+ "}\n"
+ "a = 2; // line 3\n");
v8::Local<v8::Function> f;
{
- v8::HandleScope scope;
- v8::Script::Compile(script, v8::String::New("test.html"))->Run();
+ v8::HandleScope scope(env->GetIsolate());
+ CompileRunWithOrigin(script, "test.html");
}
- f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));
+ f = v8::Local<v8::Function>::Cast(
+ env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f")));
- HEAP->CollectAllGarbage(Heap::kNoGCFlags);
+ CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags);
- SetScriptBreakPointByNameFromJS("test.html", 3, -1);
+ SetScriptBreakPointByNameFromJS(env->GetIsolate(), "test.html", 3, -1);
// Call f and check that there was no break points.
break_point_hit_count = 0;
@@ -2255,12 +2240,13 @@
// Recompile and run script and check that break point was hit.
break_point_hit_count = 0;
- v8::Script::Compile(script, v8::String::New("test.html"))->Run();
+ CompileRunWithOrigin(script, "test.html");
CHECK_EQ(1, break_point_hit_count);
// Call f and check that there are still no break points.
break_point_hit_count = 0;
- f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));
+ f = v8::Local<v8::Function>::Cast(
+ env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f")));
CHECK_EQ(0, break_point_hit_count);
v8::Debug::SetDebugEventListener(NULL);
@@ -2271,30 +2257,32 @@
// Test that it is possible to add and remove break points in a top level
// function which has no references but has not been collected yet.
TEST(ScriptBreakPointTopLevelCrash) {
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
env.ExposeDebug();
- v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
- v8::Undefined());
+ v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount);
- v8::Local<v8::String> script_source = v8::String::New(
- "function f() {\n"
- " return 0;\n"
- "}\n"
- "f()");
+ v8::Local<v8::String> script_source =
+ v8::String::NewFromUtf8(env->GetIsolate(),
+ "function f() {\n"
+ " return 0;\n"
+ "}\n"
+ "f()");
- int sbp1 = SetScriptBreakPointByNameFromJS("test.html", 3, -1);
+ int sbp1 =
+ SetScriptBreakPointByNameFromJS(env->GetIsolate(), "test.html", 3, -1);
{
- v8::HandleScope scope;
+ v8::HandleScope scope(env->GetIsolate());
break_point_hit_count = 0;
- v8::Script::Compile(script_source, v8::String::New("test.html"))->Run();
+ CompileRunWithOrigin(script_source, "test.html");
CHECK_EQ(1, break_point_hit_count);
}
- int sbp2 = SetScriptBreakPointByNameFromJS("test.html", 3, -1);
- ClearBreakPointFromJS(sbp1);
- ClearBreakPointFromJS(sbp2);
+ int sbp2 =
+ SetScriptBreakPointByNameFromJS(env->GetIsolate(), "test.html", 3, -1);
+ ClearBreakPointFromJS(env->GetIsolate(), sbp1);
+ ClearBreakPointFromJS(env->GetIsolate(), sbp2);
v8::Debug::SetDebugEventListener(NULL);
CheckDebuggerUnloaded();
@@ -2304,8 +2292,8 @@
// Test that it is possible to remove the last break point for a function
// inside the break handling of that break point.
TEST(RemoveBreakPointInBreak) {
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
v8::Local<v8::Function> foo =
CompileFunction(&env, "function foo(){a=1;}", "foo");
@@ -2330,17 +2318,19 @@
// Test that the debugger statement causes a break.
TEST(DebuggerStatement) {
break_point_hit_count = 0;
- v8::HandleScope scope;
DebugLocalContext env;
- v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
- v8::Undefined());
- v8::Script::Compile(v8::String::New("function bar(){debugger}"))->Run();
- v8::Script::Compile(v8::String::New(
- "function foo(){debugger;debugger;}"))->Run();
- v8::Local<v8::Function> foo =
- v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("foo")));
- v8::Local<v8::Function> bar =
- v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("bar")));
+ v8::HandleScope scope(env->GetIsolate());
+ v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount);
+ v8::Script::Compile(
+ v8::String::NewFromUtf8(env->GetIsolate(), "function bar(){debugger}"))
+ ->Run();
+ v8::Script::Compile(
+ v8::String::NewFromUtf8(env->GetIsolate(),
+ "function foo(){debugger;debugger;}"))->Run();
+ v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast(
+ env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "foo")));
+ v8::Local<v8::Function> bar = v8::Local<v8::Function>::Cast(
+ env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "bar")));
// Run function with debugger statement
bar->Call(env->Global(), 0, NULL);
@@ -2358,13 +2348,14 @@
// Test setting a breakpoint on the debugger statement.
TEST(DebuggerStatementBreakpoint) {
break_point_hit_count = 0;
- v8::HandleScope scope;
DebugLocalContext env;
- v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
- v8::Undefined());
- v8::Script::Compile(v8::String::New("function foo(){debugger;}"))->Run();
- v8::Local<v8::Function> foo =
- v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("foo")));
+ v8::HandleScope scope(env->GetIsolate());
+ v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount);
+ v8::Script::Compile(
+ v8::String::NewFromUtf8(env->GetIsolate(), "function foo(){debugger;}"))
+ ->Run();
+ v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast(
+ env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "foo")));
// The debugger statement triggers breakpint hit
foo->Call(env->Global(), 0, NULL);
@@ -2382,11 +2373,12 @@
}
-// Thest that the evaluation of expressions when a break point is hit generates
+// Test that the evaluation of expressions when a break point is hit generates
// the correct results.
TEST(DebugEvaluate) {
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::Isolate* isolate = env->GetIsolate();
+ v8::HandleScope scope(isolate);
env.ExposeDebug();
// Create a function for checking the evaluation when hitting a break point.
@@ -2399,23 +2391,23 @@
// Different expected vaules of x and a when in a break point (u = undefined,
// d = Hello, world!).
struct EvaluateCheck checks_uu[] = {
- {"x", v8::Undefined()},
- {"a", v8::Undefined()},
+ {"x", v8::Undefined(isolate)},
+ {"a", v8::Undefined(isolate)},
{NULL, v8::Handle<v8::Value>()}
};
struct EvaluateCheck checks_hu[] = {
- {"x", v8::String::New("Hello, world!")},
- {"a", v8::Undefined()},
+ {"x", v8::String::NewFromUtf8(env->GetIsolate(), "Hello, world!")},
+ {"a", v8::Undefined(isolate)},
{NULL, v8::Handle<v8::Value>()}
};
struct EvaluateCheck checks_hh[] = {
- {"x", v8::String::New("Hello, world!")},
- {"a", v8::String::New("Hello, world!")},
+ {"x", v8::String::NewFromUtf8(env->GetIsolate(), "Hello, world!")},
+ {"a", v8::String::NewFromUtf8(env->GetIsolate(), "Hello, world!")},
{NULL, v8::Handle<v8::Value>()}
};
// Simple test function. The "y=0" is in the function foo to provide a break
- // location. For "y=0" the "y" is at position 15 in the barbar function
+ // location. For "y=0" the "y" is at position 15 in the foo function
// therefore setting breakpoint at position 15 will break at "y=0" and
// setting it higher will break after.
v8::Local<v8::Function> foo = CompileFunction(&env,
@@ -2430,7 +2422,8 @@
const int foo_break_position_2 = 29;
// Arguments with one parameter "Hello, world!"
- v8::Handle<v8::Value> argv_foo[1] = { v8::String::New("Hello, world!") };
+ v8::Handle<v8::Value> argv_foo[1] = {
+ v8::String::NewFromUtf8(env->GetIsolate(), "Hello, world!")};
// Call foo with breakpoint set before a=x and undefined as parameter.
int bp = SetBreakPoint(foo, foo_break_position_1);
@@ -2447,6 +2440,34 @@
checks = checks_hh;
foo->Call(env->Global(), 1, argv_foo);
+ // Test that overriding Object.prototype will not interfere into evaluation
+ // on call frame.
+ v8::Local<v8::Function> zoo =
+ CompileFunction(&env,
+ "x = undefined;"
+ "function zoo(t) {"
+ " var a=x;"
+ " Object.prototype.x = 42;"
+ " x=t;"
+ " y=0;" // To ensure break location.
+ " delete Object.prototype.x;"
+ " x=a;"
+ "}",
+ "zoo");
+ const int zoo_break_position = 50;
+
+ // Arguments with one parameter "Hello, world!"
+ v8::Handle<v8::Value> argv_zoo[1] = {
+ v8::String::NewFromUtf8(env->GetIsolate(), "Hello, world!")};
+
+ // Call zoo with breakpoint set at y=0.
+ DebugEventCounterClear();
+ bp = SetBreakPoint(zoo, zoo_break_position);
+ checks = checks_hu;
+ zoo->Call(env->Global(), 1, argv_zoo);
+ CHECK_EQ(1, break_point_hit_count);
+ ClearBreakPoint(bp);
+
// Test function with an inner function. The "y=0" is in function barbar
// to provide a break location. For "y=0" the "y" is at position 8 in the
// barbar function therefore setting breakpoint at position 8 will break at
@@ -2471,8 +2492,8 @@
// parameter.
checks = checks_uu;
v8::Handle<v8::Value> argv_bar_1[2] = {
- v8::Undefined(),
- v8::Number::New(barbar_break_position)
+ v8::Undefined(isolate),
+ v8::Number::New(isolate, barbar_break_position)
};
bar->Call(env->Global(), 2, argv_bar_1);
@@ -2480,8 +2501,8 @@
// "Hello, world!".
checks = checks_hu;
v8::Handle<v8::Value> argv_bar_2[2] = {
- v8::String::New("Hello, world!"),
- v8::Number::New(barbar_break_position)
+ v8::String::NewFromUtf8(env->GetIsolate(), "Hello, world!"),
+ v8::Number::New(env->GetIsolate(), barbar_break_position)
};
bar->Call(env->Global(), 2, argv_bar_2);
@@ -2489,8 +2510,8 @@
// "Hello, world!".
checks = checks_hh;
v8::Handle<v8::Value> argv_bar_3[2] = {
- v8::String::New("Hello, world!"),
- v8::Number::New(barbar_break_position + 1)
+ v8::String::NewFromUtf8(env->GetIsolate(), "Hello, world!"),
+ v8::Number::New(env->GetIsolate(), barbar_break_position + 1)
};
bar->Call(env->Global(), 2, argv_bar_3);
@@ -2498,6 +2519,100 @@
CheckDebuggerUnloaded();
}
+
+int debugEventCount = 0;
+static void CheckDebugEvent(const v8::Debug::EventDetails& eventDetails) {
+ if (eventDetails.GetEvent() == v8::Break) ++debugEventCount;
+}
+
+
+// Test that the conditional breakpoints work event if code generation from
+// strings is prohibited in the debugee context.
+TEST(ConditionalBreakpointWithCodeGenerationDisallowed) {
+ DebugLocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
+ env.ExposeDebug();
+
+ v8::Debug::SetDebugEventListener(CheckDebugEvent);
+
+ v8::Local<v8::Function> foo = CompileFunction(&env,
+ "function foo(x) {\n"
+ " var s = 'String value2';\n"
+ " return s + x;\n"
+ "}",
+ "foo");
+
+ // Set conditional breakpoint with condition 'true'.
+ CompileRun("debug.Debug.setBreakPoint(foo, 2, 0, 'true')");
+
+ debugEventCount = 0;
+ env->AllowCodeGenerationFromStrings(false);
+ foo->Call(env->Global(), 0, NULL);
+ CHECK_EQ(1, debugEventCount);
+
+ v8::Debug::SetDebugEventListener(NULL);
+ CheckDebuggerUnloaded();
+}
+
+
+bool checkedDebugEvals = true;
+v8::Handle<v8::Function> checkGlobalEvalFunction;
+v8::Handle<v8::Function> checkFrameEvalFunction;
+static void CheckDebugEval(const v8::Debug::EventDetails& eventDetails) {
+ if (eventDetails.GetEvent() == v8::Break) {
+ ++debugEventCount;
+ v8::HandleScope handleScope(CcTest::isolate());
+
+ v8::Handle<v8::Value> args[] = { eventDetails.GetExecutionState() };
+ CHECK(checkGlobalEvalFunction->Call(
+ eventDetails.GetEventContext()->Global(), 1, args)->IsTrue());
+ CHECK(checkFrameEvalFunction->Call(
+ eventDetails.GetEventContext()->Global(), 1, args)->IsTrue());
+ }
+}
+
+
+// Test that the evaluation of expressions when a break point is hit generates
+// the correct results in case code generation from strings is disallowed in the
+// debugee context.
+TEST(DebugEvaluateWithCodeGenerationDisallowed) {
+ DebugLocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
+ env.ExposeDebug();
+
+ v8::Debug::SetDebugEventListener(CheckDebugEval);
+
+ v8::Local<v8::Function> foo = CompileFunction(&env,
+ "var global = 'Global';\n"
+ "function foo(x) {\n"
+ " var local = 'Local';\n"
+ " debugger;\n"
+ " return local + x;\n"
+ "}",
+ "foo");
+ checkGlobalEvalFunction = CompileFunction(&env,
+ "function checkGlobalEval(exec_state) {\n"
+ " return exec_state.evaluateGlobal('global').value() === 'Global';\n"
+ "}",
+ "checkGlobalEval");
+
+ checkFrameEvalFunction = CompileFunction(&env,
+ "function checkFrameEval(exec_state) {\n"
+ " return exec_state.frame(0).evaluate('local').value() === 'Local';\n"
+ "}",
+ "checkFrameEval");
+ debugEventCount = 0;
+ env->AllowCodeGenerationFromStrings(false);
+ foo->Call(env->Global(), 0, NULL);
+ CHECK_EQ(1, debugEventCount);
+
+ checkGlobalEvalFunction.Clear();
+ checkFrameEvalFunction.Clear();
+ v8::Debug::SetDebugEventListener(NULL);
+ CheckDebuggerUnloaded();
+}
+
+
// Copies a C string to a 16-bit string. Does not check for buffer overflow.
// Does not use the V8 engine to convert strings, so it can be used
// in any thread. Returns the length of the string.
@@ -2511,6 +2626,7 @@
return i;
}
+
// Copies a 16-bit string to a C string by dropping the high byte of
// each character. Does not check for buffer overflow.
// Can be used in any thread. Requires string length as an input.
@@ -2550,7 +2666,7 @@
if (len > buffer_size - 1) {
len = buffer_size - 1;
}
- OS::StrNCpy(buf, pos1, len);
+ StrNCpy(buf, pos1, len);
buffer[buffer_size - 1] = '\0';
return true;
}
@@ -2580,17 +2696,12 @@
DebugProcessDebugMessagesData process_debug_messages_data;
static void DebugProcessDebugMessagesHandler(
- const uint16_t* message,
- int length,
- v8::Debug::ClientData* client_data) {
-
- const int kBufferSize = 100000;
- char print_buffer[kBufferSize];
- Utf16ToAscii(message, length, print_buffer, kBufferSize);
-
+ const v8::Debug::Message& message) {
+ v8::Handle<v8::String> json = message.GetJSON();
+ v8::String::Utf8Value utf8(json);
EvaluateResult* array_item = process_debug_messages_data.current();
- bool res = GetEvaluateStringResult(print_buffer,
+ bool res = GetEvaluateStringResult(*utf8,
array_item->buffer,
EvaluateResult::kBufferSize);
if (res) {
@@ -2598,18 +2709,20 @@
}
}
+
// Test that the evaluation of expressions works even from ProcessDebugMessages
// i.e. with empty stack.
TEST(DebugEvaluateWithoutStack) {
v8::Debug::SetMessageHandler(DebugProcessDebugMessagesHandler);
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
const char* source =
"var v1 = 'Pinguin';\n function getAnimal() { return 'Capy' + 'bara'; }";
- v8::Script::Compile(v8::String::New(source))->Run();
+ v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), source))
+ ->Run();
v8::Debug::ProcessDebugMessages();
@@ -2624,7 +2737,8 @@
" \"expression\":\"v1\",\"disable_break\":true"
"}}";
- v8::Debug::SendCommand(buffer, AsciiToUtf16(command_111, buffer));
+ v8::Isolate* isolate = CcTest::isolate();
+ v8::Debug::SendCommand(isolate, buffer, AsciiToUtf16(command_111, buffer));
const char* command_112 = "{\"seq\":112,"
"\"type\":\"request\","
@@ -2634,7 +2748,7 @@
" \"expression\":\"getAnimal()\",\"disable_break\":true"
"}}";
- v8::Debug::SendCommand(buffer, AsciiToUtf16(command_112, buffer));
+ v8::Debug::SendCommand(isolate, buffer, AsciiToUtf16(command_112, buffer));
const char* command_113 = "{\"seq\":113,"
"\"type\":\"request\","
@@ -2644,7 +2758,7 @@
" \"expression\":\"239 + 566\",\"disable_break\":true"
"}}";
- v8::Debug::SendCommand(buffer, AsciiToUtf16(command_113, buffer));
+ v8::Debug::SendCommand(isolate, buffer, AsciiToUtf16(command_113, buffer));
v8::Debug::ProcessDebugMessages();
@@ -2663,8 +2777,8 @@
// Simple test of the stepping mechanism using only store ICs.
TEST(DebugStepLinear) {
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
// Create a function for testing stepping.
v8::Local<v8::Function> foo = CompileFunction(&env,
@@ -2706,8 +2820,8 @@
// Test of the stepping mechanism for keyed load in a loop.
TEST(DebugStepKeyedLoadLoop) {
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
// Register a debug event listener which steps and counts.
v8::Debug::SetDebugEventListener(DebugEventStep);
@@ -2728,9 +2842,58 @@
"foo");
// Create array [0,1,2,3,4,5,6,7,8,9]
- v8::Local<v8::Array> a = v8::Array::New(10);
+ v8::Local<v8::Array> a = v8::Array::New(env->GetIsolate(), 10);
for (int i = 0; i < 10; i++) {
- a->Set(v8::Number::New(i), v8::Number::New(i));
+ a->Set(v8::Number::New(env->GetIsolate(), i),
+ v8::Number::New(env->GetIsolate(), i));
+ }
+
+ // Call function without any break points to ensure inlining is in place.
+ const int kArgc = 1;
+ v8::Handle<v8::Value> args[kArgc] = { a };
+ foo->Call(env->Global(), kArgc, args);
+
+ // Set up break point and step through the function.
+ SetBreakPoint(foo, 3);
+ step_action = StepNext;
+ break_point_hit_count = 0;
+ foo->Call(env->Global(), kArgc, args);
+
+ // With stepping all break locations are hit.
+ CHECK_EQ(35, break_point_hit_count);
+
+ v8::Debug::SetDebugEventListener(NULL);
+ CheckDebuggerUnloaded();
+}
+
+
+// Test of the stepping mechanism for keyed store in a loop.
+TEST(DebugStepKeyedStoreLoop) {
+ DebugLocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
+
+ // Register a debug event listener which steps and counts.
+ v8::Debug::SetDebugEventListener(DebugEventStep);
+
+ // Create a function for testing stepping of keyed store. The statement 'y=1'
+ // is there to have more than one breakable statement in the loop, TODO(315).
+ v8::Local<v8::Function> foo = CompileFunction(
+ &env,
+ "function foo(a) {\n"
+ " var len = a.length;\n"
+ " for (var i = 0; i < len; i++) {\n"
+ " y = 1;\n"
+ " a[i] = 42;\n"
+ " }\n"
+ "}\n"
+ "y=0\n",
+ "foo");
+
+ // Create array [0,1,2,3,4,5,6,7,8,9]
+ v8::Local<v8::Array> a = v8::Array::New(env->GetIsolate(), 10);
+ for (int i = 0; i < 10; i++) {
+ a->Set(v8::Number::New(env->GetIsolate(), i),
+ v8::Number::New(env->GetIsolate(), i));
}
// Call function without any break points to ensure inlining is in place.
@@ -2752,57 +2915,10 @@
}
-// Test of the stepping mechanism for keyed store in a loop.
-TEST(DebugStepKeyedStoreLoop) {
- v8::HandleScope scope;
- DebugLocalContext env;
-
- // Register a debug event listener which steps and counts.
- v8::Debug::SetDebugEventListener(DebugEventStep);
-
- // Create a function for testing stepping of keyed store. The statement 'y=1'
- // is there to have more than one breakable statement in the loop, TODO(315).
- v8::Local<v8::Function> foo = CompileFunction(
- &env,
- "function foo(a) {\n"
- " var len = a.length;\n"
- " for (var i = 0; i < len; i++) {\n"
- " y = 1;\n"
- " a[i] = 42;\n"
- " }\n"
- "}\n"
- "y=0\n",
- "foo");
-
- // Create array [0,1,2,3,4,5,6,7,8,9]
- v8::Local<v8::Array> a = v8::Array::New(10);
- for (int i = 0; i < 10; i++) {
- a->Set(v8::Number::New(i), v8::Number::New(i));
- }
-
- // Call function without any break points to ensure inlining is in place.
- const int kArgc = 1;
- v8::Handle<v8::Value> args[kArgc] = { a };
- foo->Call(env->Global(), kArgc, args);
-
- // Set up break point and step through the function.
- SetBreakPoint(foo, 3);
- step_action = StepNext;
- break_point_hit_count = 0;
- foo->Call(env->Global(), kArgc, args);
-
- // With stepping all break locations are hit.
- CHECK_EQ(33, break_point_hit_count);
-
- v8::Debug::SetDebugEventListener(NULL);
- CheckDebuggerUnloaded();
-}
-
-
// Test of the stepping mechanism for named load in a loop.
TEST(DebugStepNamedLoadLoop) {
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
// Register a debug event listener which steps and counts.
v8::Debug::SetDebugEventListener(DebugEventStep);
@@ -2836,7 +2952,7 @@
foo->Call(env->Global(), 0, NULL);
// With stepping all break locations are hit.
- CHECK_EQ(54, break_point_hit_count);
+ CHECK_EQ(55, break_point_hit_count);
v8::Debug::SetDebugEventListener(NULL);
CheckDebuggerUnloaded();
@@ -2844,8 +2960,8 @@
static void DoDebugStepNamedStoreLoop(int expected) {
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
// Register a debug event listener which steps and counts.
v8::Debug::SetDebugEventListener(DebugEventStep);
@@ -2880,14 +2996,14 @@
// Test of the stepping mechanism for named load in a loop.
TEST(DebugStepNamedStoreLoop) {
- DoDebugStepNamedStoreLoop(23);
+ DoDebugStepNamedStoreLoop(24);
}
// Test the stepping mechanism with different ICs.
TEST(DebugStepLinearMixedICs) {
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
// Register a debug event listener which steps and counts.
v8::Debug::SetDebugEventListener(DebugEventStep);
@@ -2932,8 +3048,8 @@
TEST(DebugStepDeclarations) {
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
// Register a debug event listener which steps and counts.
v8::Debug::SetDebugEventListener(DebugEventStep);
@@ -2965,8 +3081,8 @@
TEST(DebugStepLocals) {
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
// Register a debug event listener which steps and counts.
v8::Debug::SetDebugEventListener(DebugEventStep);
@@ -2998,8 +3114,9 @@
TEST(DebugStepIf) {
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::Isolate* isolate = env->GetIsolate();
+ v8::HandleScope scope(isolate);
// Register a debug event listener which steps and counts.
v8::Debug::SetDebugEventListener(DebugEventStep);
@@ -3023,14 +3140,14 @@
// Stepping through the true part.
step_action = StepIn;
break_point_hit_count = 0;
- v8::Handle<v8::Value> argv_true[argc] = { v8::True() };
+ v8::Handle<v8::Value> argv_true[argc] = { v8::True(isolate) };
foo->Call(env->Global(), argc, argv_true);
CHECK_EQ(4, break_point_hit_count);
// Stepping through the false part.
step_action = StepIn;
break_point_hit_count = 0;
- v8::Handle<v8::Value> argv_false[argc] = { v8::False() };
+ v8::Handle<v8::Value> argv_false[argc] = { v8::False(isolate) };
foo->Call(env->Global(), argc, argv_false);
CHECK_EQ(5, break_point_hit_count);
@@ -3041,8 +3158,9 @@
TEST(DebugStepSwitch) {
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::Isolate* isolate = env->GetIsolate();
+ v8::HandleScope scope(isolate);
// Register a debug event listener which steps and counts.
v8::Debug::SetDebugEventListener(DebugEventStep);
@@ -3072,21 +3190,21 @@
// One case with fall-through.
step_action = StepIn;
break_point_hit_count = 0;
- v8::Handle<v8::Value> argv_1[argc] = { v8::Number::New(1) };
+ v8::Handle<v8::Value> argv_1[argc] = { v8::Number::New(isolate, 1) };
foo->Call(env->Global(), argc, argv_1);
CHECK_EQ(6, break_point_hit_count);
// Another case.
step_action = StepIn;
break_point_hit_count = 0;
- v8::Handle<v8::Value> argv_2[argc] = { v8::Number::New(2) };
+ v8::Handle<v8::Value> argv_2[argc] = { v8::Number::New(isolate, 2) };
foo->Call(env->Global(), argc, argv_2);
CHECK_EQ(5, break_point_hit_count);
// Last case.
step_action = StepIn;
break_point_hit_count = 0;
- v8::Handle<v8::Value> argv_3[argc] = { v8::Number::New(3) };
+ v8::Handle<v8::Value> argv_3[argc] = { v8::Number::New(isolate, 3) };
foo->Call(env->Global(), argc, argv_3);
CHECK_EQ(7, break_point_hit_count);
@@ -3097,8 +3215,9 @@
TEST(DebugStepWhile) {
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::Isolate* isolate = env->GetIsolate();
+ v8::HandleScope scope(isolate);
// Register a debug event listener which steps and counts.
v8::Debug::SetDebugEventListener(DebugEventStep);
@@ -3116,19 +3235,26 @@
v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo");
SetBreakPoint(foo, 8); // "var a = 0;"
+ // Looping 0 times. We still should break at the while-condition once.
+ step_action = StepIn;
+ break_point_hit_count = 0;
+ v8::Handle<v8::Value> argv_0[argc] = { v8::Number::New(isolate, 0) };
+ foo->Call(env->Global(), argc, argv_0);
+ CHECK_EQ(3, break_point_hit_count);
+
// Looping 10 times.
step_action = StepIn;
break_point_hit_count = 0;
- v8::Handle<v8::Value> argv_10[argc] = { v8::Number::New(10) };
+ v8::Handle<v8::Value> argv_10[argc] = { v8::Number::New(isolate, 10) };
foo->Call(env->Global(), argc, argv_10);
- CHECK_EQ(22, break_point_hit_count);
+ CHECK_EQ(23, break_point_hit_count);
// Looping 100 times.
step_action = StepIn;
break_point_hit_count = 0;
- v8::Handle<v8::Value> argv_100[argc] = { v8::Number::New(100) };
+ v8::Handle<v8::Value> argv_100[argc] = { v8::Number::New(isolate, 100) };
foo->Call(env->Global(), argc, argv_100);
- CHECK_EQ(202, break_point_hit_count);
+ CHECK_EQ(203, break_point_hit_count);
// Get rid of the debug event listener.
v8::Debug::SetDebugEventListener(NULL);
@@ -3137,8 +3263,9 @@
TEST(DebugStepDoWhile) {
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::Isolate* isolate = env->GetIsolate();
+ v8::HandleScope scope(isolate);
// Register a debug event listener which steps and counts.
v8::Debug::SetDebugEventListener(DebugEventStep);
@@ -3159,14 +3286,14 @@
// Looping 10 times.
step_action = StepIn;
break_point_hit_count = 0;
- v8::Handle<v8::Value> argv_10[argc] = { v8::Number::New(10) };
+ v8::Handle<v8::Value> argv_10[argc] = { v8::Number::New(isolate, 10) };
foo->Call(env->Global(), argc, argv_10);
CHECK_EQ(22, break_point_hit_count);
// Looping 100 times.
step_action = StepIn;
break_point_hit_count = 0;
- v8::Handle<v8::Value> argv_100[argc] = { v8::Number::New(100) };
+ v8::Handle<v8::Value> argv_100[argc] = { v8::Number::New(isolate, 100) };
foo->Call(env->Global(), argc, argv_100);
CHECK_EQ(202, break_point_hit_count);
@@ -3177,8 +3304,9 @@
TEST(DebugStepFor) {
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::Isolate* isolate = env->GetIsolate();
+ v8::HandleScope scope(isolate);
// Register a debug event listener which steps and counts.
v8::Debug::SetDebugEventListener(DebugEventStep);
@@ -3200,14 +3328,14 @@
// Looping 10 times.
step_action = StepIn;
break_point_hit_count = 0;
- v8::Handle<v8::Value> argv_10[argc] = { v8::Number::New(10) };
+ v8::Handle<v8::Value> argv_10[argc] = { v8::Number::New(isolate, 10) };
foo->Call(env->Global(), argc, argv_10);
CHECK_EQ(23, break_point_hit_count);
// Looping 100 times.
step_action = StepIn;
break_point_hit_count = 0;
- v8::Handle<v8::Value> argv_100[argc] = { v8::Number::New(100) };
+ v8::Handle<v8::Value> argv_100[argc] = { v8::Number::New(isolate, 100) };
foo->Call(env->Global(), argc, argv_100);
CHECK_EQ(203, break_point_hit_count);
@@ -3218,8 +3346,9 @@
TEST(DebugStepForContinue) {
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::Isolate* isolate = env->GetIsolate();
+ v8::HandleScope scope(isolate);
// Register a debug event listener which steps and counts.
v8::Debug::SetDebugEventListener(DebugEventStep);
@@ -3249,18 +3378,18 @@
// Looping 10 times.
step_action = StepIn;
break_point_hit_count = 0;
- v8::Handle<v8::Value> argv_10[argc] = { v8::Number::New(10) };
+ v8::Handle<v8::Value> argv_10[argc] = { v8::Number::New(isolate, 10) };
result = foo->Call(env->Global(), argc, argv_10);
CHECK_EQ(5, result->Int32Value());
- CHECK_EQ(51, break_point_hit_count);
+ CHECK_EQ(52, break_point_hit_count);
// Looping 100 times.
step_action = StepIn;
break_point_hit_count = 0;
- v8::Handle<v8::Value> argv_100[argc] = { v8::Number::New(100) };
+ v8::Handle<v8::Value> argv_100[argc] = { v8::Number::New(isolate, 100) };
result = foo->Call(env->Global(), argc, argv_100);
CHECK_EQ(50, result->Int32Value());
- CHECK_EQ(456, break_point_hit_count);
+ CHECK_EQ(457, break_point_hit_count);
// Get rid of the debug event listener.
v8::Debug::SetDebugEventListener(NULL);
@@ -3269,8 +3398,9 @@
TEST(DebugStepForBreak) {
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::Isolate* isolate = env->GetIsolate();
+ v8::HandleScope scope(isolate);
// Register a debug event listener which steps and counts.
v8::Debug::SetDebugEventListener(DebugEventStep);
@@ -3301,18 +3431,18 @@
// Looping 10 times.
step_action = StepIn;
break_point_hit_count = 0;
- v8::Handle<v8::Value> argv_10[argc] = { v8::Number::New(10) };
+ v8::Handle<v8::Value> argv_10[argc] = { v8::Number::New(isolate, 10) };
result = foo->Call(env->Global(), argc, argv_10);
CHECK_EQ(9, result->Int32Value());
- CHECK_EQ(54, break_point_hit_count);
+ CHECK_EQ(55, break_point_hit_count);
// Looping 100 times.
step_action = StepIn;
break_point_hit_count = 0;
- v8::Handle<v8::Value> argv_100[argc] = { v8::Number::New(100) };
+ v8::Handle<v8::Value> argv_100[argc] = { v8::Number::New(isolate, 100) };
result = foo->Call(env->Global(), argc, argv_100);
CHECK_EQ(99, result->Int32Value());
- CHECK_EQ(504, break_point_hit_count);
+ CHECK_EQ(505, break_point_hit_count);
// Get rid of the debug event listener.
v8::Debug::SetDebugEventListener(NULL);
@@ -3321,8 +3451,8 @@
TEST(DebugStepForIn) {
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
// Register a debug event listener which steps and counts.
v8::Debug::SetDebugEventListener(DebugEventStep);
@@ -3369,8 +3499,8 @@
TEST(DebugStepWith) {
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
// Register a debug event listener which steps and counts.
v8::Debug::SetDebugEventListener(DebugEventStep);
@@ -3383,7 +3513,8 @@
" with (b) {}"
"}"
"foo()";
- env->Global()->Set(v8::String::New("b"), v8::Object::New());
+ env->Global()->Set(v8::String::NewFromUtf8(env->GetIsolate(), "b"),
+ v8::Object::New(env->GetIsolate()));
v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo");
v8::Handle<v8::Value> result;
SetBreakPoint(foo, 8); // "var a = {};"
@@ -3400,8 +3531,9 @@
TEST(DebugConditional) {
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::Isolate* isolate = env->GetIsolate();
+ v8::HandleScope scope(isolate);
// Register a debug event listener which steps and counts.
v8::Debug::SetDebugEventListener(DebugEventStep);
@@ -3425,7 +3557,7 @@
step_action = StepIn;
break_point_hit_count = 0;
const int argc = 1;
- v8::Handle<v8::Value> argv_true[argc] = { v8::True() };
+ v8::Handle<v8::Value> argv_true[argc] = { v8::True(isolate) };
foo->Call(env->Global(), argc, argv_true);
CHECK_EQ(5, break_point_hit_count);
@@ -3436,8 +3568,8 @@
TEST(StepInOutSimple) {
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
// Create a function for checking the function when hitting a break point.
frame_function_name = CompileFunction(&env,
@@ -3487,8 +3619,8 @@
TEST(StepInOutTree) {
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
// Create a function for checking the function when hitting a break point.
frame_function_name = CompileFunction(&env,
@@ -3539,8 +3671,8 @@
TEST(StepInOutBranch) {
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
// Create a function for checking the function when hitting a break point.
frame_function_name = CompileFunction(&env,
@@ -3575,8 +3707,8 @@
// Test that step in does not step into native functions.
TEST(DebugStepNatives) {
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
// Create a function for testing stepping.
v8::Local<v8::Function> foo = CompileFunction(
@@ -3613,8 +3745,8 @@
// Test that step in works with function.apply.
TEST(DebugStepFunctionApply) {
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
// Create a function for testing stepping.
v8::Local<v8::Function> foo = CompileFunction(
@@ -3652,8 +3784,9 @@
// Test that step in works with function.call.
TEST(DebugStepFunctionCall) {
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::Isolate* isolate = env->GetIsolate();
+ v8::HandleScope scope(isolate);
// Create a function for testing stepping.
v8::Local<v8::Function> foo = CompileFunction(
@@ -3680,7 +3813,7 @@
// Check stepping where the if condition in bar is true.
break_point_hit_count = 0;
const int argc = 1;
- v8::Handle<v8::Value> argv[argc] = { v8::True() };
+ v8::Handle<v8::Value> argv[argc] = { v8::True(isolate) };
foo->Call(env->Global(), argc, argv);
CHECK_EQ(8, break_point_hit_count);
@@ -3703,8 +3836,8 @@
// Tests that breakpoint will be hit if it's set in script.
TEST(PauseInScript) {
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
env.ExposeDebug();
// Register a debug event listener which counts.
@@ -3715,12 +3848,14 @@
const char* script_name = "StepInHandlerTest";
// Set breakpoint in the script.
- SetScriptBreakPointByNameFromJS(script_name, 0, -1);
+ SetScriptBreakPointByNameFromJS(env->GetIsolate(), script_name, 0, -1);
break_point_hit_count = 0;
- v8::ScriptOrigin origin(v8::String::New(script_name), v8::Integer::New(0));
- v8::Handle<v8::Script> script = v8::Script::Compile(v8::String::New(src),
- &origin);
+ v8::ScriptOrigin origin(
+ v8::String::NewFromUtf8(env->GetIsolate(), script_name),
+ v8::Integer::New(env->GetIsolate(), 0));
+ v8::Handle<v8::Script> script = v8::Script::Compile(
+ v8::String::NewFromUtf8(env->GetIsolate(), src), &origin);
v8::Local<v8::Value> r = script->Run();
CHECK(r->IsFunction());
@@ -3739,12 +3874,10 @@
// check that uncaught exceptions are still returned even if there is a break
// for them.
TEST(BreakOnException) {
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
env.ExposeDebug();
- v8::internal::Isolate::Current()->TraceException(false);
-
// Create functions for testing break on exception.
CompileFunction(&env, "function throws(){throw 1;}", "throws");
v8::Local<v8::Function> caught =
@@ -3824,7 +3957,7 @@
// No break on exception using JavaScript
DebugEventCounterClear();
MessageCallbackCountClear();
- ChangeBreakOnExceptionFromJS(false, false);
+ ChangeBreakOnExceptionFromJS(env->GetIsolate(), false, false);
caught->Call(env->Global(), 0, NULL);
CHECK_EQ(0, exception_hit_count);
CHECK_EQ(0, uncaught_exception_hit_count);
@@ -3837,7 +3970,7 @@
// Break on uncaught exception using JavaScript
DebugEventCounterClear();
MessageCallbackCountClear();
- ChangeBreakOnExceptionFromJS(false, true);
+ ChangeBreakOnExceptionFromJS(env->GetIsolate(), false, true);
caught->Call(env->Global(), 0, NULL);
CHECK_EQ(0, exception_hit_count);
CHECK_EQ(0, uncaught_exception_hit_count);
@@ -3850,7 +3983,7 @@
// Break on exception and uncaught exception using JavaScript
DebugEventCounterClear();
MessageCallbackCountClear();
- ChangeBreakOnExceptionFromJS(true, true);
+ ChangeBreakOnExceptionFromJS(env->GetIsolate(), true, true);
caught->Call(env->Global(), 0, NULL);
CHECK_EQ(1, exception_hit_count);
CHECK_EQ(0, message_callback_count);
@@ -3863,7 +3996,7 @@
// Break on exception using JavaScript
DebugEventCounterClear();
MessageCallbackCountClear();
- ChangeBreakOnExceptionFromJS(true, false);
+ ChangeBreakOnExceptionFromJS(env->GetIsolate(), true, false);
caught->Call(env->Global(), 0, NULL);
CHECK_EQ(1, exception_hit_count);
CHECK_EQ(0, uncaught_exception_hit_count);
@@ -3879,18 +4012,53 @@
}
+TEST(EvalJSInDebugEventListenerOnNativeReThrownException) {
+ DebugLocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
+ env.ExposeDebug();
+
+ // Create functions for testing break on exception.
+ v8::Local<v8::Function> noThrowJS = CompileFunction(
+ &env, "function noThrowJS(){var a=[1]; a.push(2); return a.length;}",
+ "noThrowJS");
+
+ debug_event_listener_callback = noThrowJS;
+ debug_event_listener_callback_result = 2;
+
+ v8::V8::AddMessageListener(MessageCallbackCount);
+ v8::Debug::SetDebugEventListener(DebugEventCounter);
+ // Break on uncaught exception
+ ChangeBreakOnException(false, true);
+ DebugEventCounterClear();
+ MessageCallbackCountClear();
+
+ // ReThrow native error
+ {
+ v8::TryCatch tryCatch;
+ env->GetIsolate()->ThrowException(v8::Exception::TypeError(
+ v8::String::NewFromUtf8(env->GetIsolate(), "Type error")));
+ CHECK(tryCatch.HasCaught());
+ tryCatch.ReThrow();
+ }
+ CHECK_EQ(1, exception_hit_count);
+ CHECK_EQ(1, uncaught_exception_hit_count);
+ CHECK_EQ(0, message_callback_count); // FIXME: Should it be 1 ?
+ CHECK(!debug_event_listener_callback.IsEmpty());
+
+ debug_event_listener_callback.Clear();
+}
+
+
// Test break on exception from compiler errors. When compiling using
// v8::Script::Compile there is no JavaScript stack whereas when compiling using
// eval there are JavaScript frames.
TEST(BreakOnCompileException) {
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
// For this test, we want to break on uncaught exceptions:
ChangeBreakOnException(false, true);
- v8::internal::Isolate::Current()->TraceException(false);
-
// Create a function for checking the function when hitting a break point.
frame_count = CompileFunction(&env, frame_count_source, "frame_count");
@@ -3907,28 +4075,30 @@
CHECK_EQ(-1, last_js_stack_height);
// Throws SyntaxError: Unexpected end of input
- v8::Script::Compile(v8::String::New("+++"));
+ v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), "+++"));
CHECK_EQ(1, exception_hit_count);
CHECK_EQ(1, uncaught_exception_hit_count);
CHECK_EQ(1, message_callback_count);
CHECK_EQ(0, last_js_stack_height); // No JavaScript stack.
// Throws SyntaxError: Unexpected identifier
- v8::Script::Compile(v8::String::New("x x"));
+ v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), "x x"));
CHECK_EQ(2, exception_hit_count);
CHECK_EQ(2, uncaught_exception_hit_count);
CHECK_EQ(2, message_callback_count);
CHECK_EQ(0, last_js_stack_height); // No JavaScript stack.
// Throws SyntaxError: Unexpected end of input
- v8::Script::Compile(v8::String::New("eval('+++')"))->Run();
+ v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), "eval('+++')"))
+ ->Run();
CHECK_EQ(3, exception_hit_count);
CHECK_EQ(3, uncaught_exception_hit_count);
CHECK_EQ(3, message_callback_count);
CHECK_EQ(1, last_js_stack_height);
// Throws SyntaxError: Unexpected identifier
- v8::Script::Compile(v8::String::New("eval('x x')"))->Run();
+ v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), "eval('x x')"))
+ ->Run();
CHECK_EQ(4, exception_hit_count);
CHECK_EQ(4, uncaught_exception_hit_count);
CHECK_EQ(4, message_callback_count);
@@ -3937,8 +4107,8 @@
TEST(StepWithException) {
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
// For this test, we want to break on uncaught exceptions:
ChangeBreakOnException(false, true);
@@ -4027,14 +4197,13 @@
TEST(DebugBreak) {
- v8::HandleScope scope;
- DebugLocalContext env;
-
- // This test should be run with option --verify-heap. As --verify-heap is
- // only available in debug mode only check for it in that case.
-#ifdef DEBUG
- CHECK(v8::internal::FLAG_verify_heap);
+ i::FLAG_stress_compaction = false;
+#ifdef VERIFY_HEAP
+ i::FLAG_verify_heap = true;
#endif
+ DebugLocalContext env;
+ v8::Isolate* isolate = env->GetIsolate();
+ v8::HandleScope scope(isolate);
// Register a debug event listener which sets the break flag and counts.
v8::Debug::SetDebugEventListener(DebugEventBreak);
@@ -4050,10 +4219,10 @@
v8::Local<v8::Function> f3 = CompileFunction(&env, src, "f3");
// Call the function to make sure it is compiled.
- v8::Handle<v8::Value> argv[] = { v8::Number::New(1),
- v8::Number::New(1),
- v8::Number::New(1),
- v8::Number::New(1) };
+ v8::Handle<v8::Value> argv[] = { v8::Number::New(isolate, 1),
+ v8::Number::New(isolate, 1),
+ v8::Number::New(isolate, 1),
+ v8::Number::New(isolate, 1) };
// Call all functions to make sure that they are compiled.
f0->Call(env->Global(), 0, NULL);
@@ -4062,11 +4231,12 @@
f3->Call(env->Global(), 0, NULL);
// Set the debug break flag.
- v8::Debug::DebugBreak();
+ v8::Debug::DebugBreak(env->GetIsolate());
+ CHECK(v8::Debug::CheckDebugBreak(env->GetIsolate()));
// Call all functions with different argument count.
break_point_hit_count = 0;
- for (unsigned int i = 0; i < ARRAY_SIZE(argv); i++) {
+ for (unsigned int i = 0; i < arraysize(argv); i++) {
f0->Call(env->Global(), i, argv);
f1->Call(env->Global(), i, argv);
f2->Call(env->Global(), i, argv);
@@ -4074,7 +4244,7 @@
}
// One break for each function called.
- CHECK_EQ(4 * ARRAY_SIZE(argv), break_point_hit_count);
+ CHECK_EQ(4 * arraysize(argv), break_point_hit_count);
// Get rid of the debug event listener.
v8::Debug::SetDebugEventListener(NULL);
@@ -4085,8 +4255,8 @@
// Test to ensure that JavaScript code keeps running while the debug break
// through the stack limit flag is set but breaks are disabled.
TEST(DisableBreak) {
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
// Register a debug event listener which sets the break flag and counts.
v8::Debug::SetDebugEventListener(DebugEventCounter);
@@ -4095,8 +4265,14 @@
const char* src = "function f() {g()};function g(){i=0; while(i<10){i++}}";
v8::Local<v8::Function> f = CompileFunction(&env, src, "f");
+ // Set, test and cancel debug break.
+ v8::Debug::DebugBreak(env->GetIsolate());
+ CHECK(v8::Debug::CheckDebugBreak(env->GetIsolate()));
+ v8::Debug::CancelDebugBreak(env->GetIsolate());
+ CHECK(!v8::Debug::CheckDebugBreak(env->GetIsolate()));
+
// Set the debug break flag.
- v8::Debug::DebugBreak();
+ v8::Debug::DebugBreak(env->GetIsolate());
// Call all functions with different argument count.
break_point_hit_count = 0;
@@ -4104,8 +4280,9 @@
CHECK_EQ(1, break_point_hit_count);
{
- v8::Debug::DebugBreak();
- v8::internal::DisableBreak disable_break(true);
+ v8::Debug::DebugBreak(env->GetIsolate());
+ i::Isolate* isolate = reinterpret_cast<i::Isolate*>(env->GetIsolate());
+ v8::internal::DisableBreak disable_break(isolate->debug(), true);
f->Call(env->Global(), 0, NULL);
CHECK_EQ(1, break_point_hit_count);
}
@@ -4126,13 +4303,14 @@
// http://crbug.com/28933
// Test that debug break is disabled when bootstrapper is active.
TEST(NoBreakWhenBootstrapping) {
- v8::HandleScope scope;
+ v8::Isolate* isolate = CcTest::isolate();
+ v8::HandleScope scope(isolate);
// Register a debug event listener which sets the break flag and counts.
v8::Debug::SetDebugEventListener(DebugEventCounter);
// Set the debug break flag.
- v8::Debug::DebugBreak();
+ v8::Debug::DebugBreak(isolate);
break_point_hit_count = 0;
{
// Create a context with an extension to make sure that some JavaScript
@@ -4141,8 +4319,8 @@
kSimpleExtensionSource));
const char* extension_names[] = { "simpletest" };
v8::ExtensionConfiguration extensions(1, extension_names);
- v8::Persistent<v8::Context> context = v8::Context::New(&extensions);
- context.Dispose();
+ v8::HandleScope handle_scope(isolate);
+ v8::Context::New(isolate, &extensions);
}
// Check that no DebugBreak events occured during the context creation.
CHECK_EQ(0, break_point_hit_count);
@@ -4152,73 +4330,86 @@
CheckDebuggerUnloaded();
}
-static v8::Handle<v8::Array> NamedEnum(const v8::AccessorInfo&) {
- v8::Handle<v8::Array> result = v8::Array::New(3);
- result->Set(v8::Integer::New(0), v8::String::New("a"));
- result->Set(v8::Integer::New(1), v8::String::New("b"));
- result->Set(v8::Integer::New(2), v8::String::New("c"));
- return result;
+
+static void NamedEnum(const v8::PropertyCallbackInfo<v8::Array>& info) {
+ v8::Handle<v8::Array> result = v8::Array::New(info.GetIsolate(), 3);
+ result->Set(v8::Integer::New(info.GetIsolate(), 0),
+ v8::String::NewFromUtf8(info.GetIsolate(), "a"));
+ result->Set(v8::Integer::New(info.GetIsolate(), 1),
+ v8::String::NewFromUtf8(info.GetIsolate(), "b"));
+ result->Set(v8::Integer::New(info.GetIsolate(), 2),
+ v8::String::NewFromUtf8(info.GetIsolate(), "c"));
+ info.GetReturnValue().Set(result);
}
-static v8::Handle<v8::Array> IndexedEnum(const v8::AccessorInfo&) {
- v8::Handle<v8::Array> result = v8::Array::New(2);
- result->Set(v8::Integer::New(0), v8::Number::New(1));
- result->Set(v8::Integer::New(1), v8::Number::New(10));
- return result;
+static void IndexedEnum(const v8::PropertyCallbackInfo<v8::Array>& info) {
+ v8::Isolate* isolate = info.GetIsolate();
+ v8::Handle<v8::Array> result = v8::Array::New(isolate, 2);
+ result->Set(v8::Integer::New(isolate, 0), v8::Number::New(isolate, 1));
+ result->Set(v8::Integer::New(isolate, 1), v8::Number::New(isolate, 10));
+ info.GetReturnValue().Set(result);
}
-static v8::Handle<v8::Value> NamedGetter(v8::Local<v8::String> name,
- const v8::AccessorInfo& info) {
- v8::String::AsciiValue n(name);
+static void NamedGetter(v8::Local<v8::String> name,
+ const v8::PropertyCallbackInfo<v8::Value>& info) {
+ v8::String::Utf8Value n(name);
if (strcmp(*n, "a") == 0) {
- return v8::String::New("AA");
+ info.GetReturnValue().Set(v8::String::NewFromUtf8(info.GetIsolate(), "AA"));
+ return;
} else if (strcmp(*n, "b") == 0) {
- return v8::String::New("BB");
+ info.GetReturnValue().Set(v8::String::NewFromUtf8(info.GetIsolate(), "BB"));
+ return;
} else if (strcmp(*n, "c") == 0) {
- return v8::String::New("CC");
+ info.GetReturnValue().Set(v8::String::NewFromUtf8(info.GetIsolate(), "CC"));
+ return;
} else {
- return v8::Undefined();
+ info.GetReturnValue().SetUndefined();
+ return;
}
-
- return name;
+ info.GetReturnValue().Set(name);
}
-static v8::Handle<v8::Value> IndexedGetter(uint32_t index,
- const v8::AccessorInfo& info) {
- return v8::Number::New(index + 1);
+static void IndexedGetter(uint32_t index,
+ const v8::PropertyCallbackInfo<v8::Value>& info) {
+ info.GetReturnValue().Set(static_cast<double>(index + 1));
}
TEST(InterceptorPropertyMirror) {
// Create a V8 environment with debug access.
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::Isolate* isolate = env->GetIsolate();
+ v8::HandleScope scope(isolate);
env.ExposeDebug();
// Create object with named interceptor.
- v8::Handle<v8::ObjectTemplate> named = v8::ObjectTemplate::New();
+ v8::Handle<v8::ObjectTemplate> named = v8::ObjectTemplate::New(isolate);
named->SetNamedPropertyHandler(NamedGetter, NULL, NULL, NULL, NamedEnum);
- env->Global()->Set(v8::String::New("intercepted_named"),
- named->NewInstance());
+ env->Global()->Set(
+ v8::String::NewFromUtf8(isolate, "intercepted_named"),
+ named->NewInstance());
// Create object with indexed interceptor.
- v8::Handle<v8::ObjectTemplate> indexed = v8::ObjectTemplate::New();
+ v8::Handle<v8::ObjectTemplate> indexed = v8::ObjectTemplate::New(isolate);
indexed->SetIndexedPropertyHandler(IndexedGetter,
NULL,
NULL,
NULL,
IndexedEnum);
- env->Global()->Set(v8::String::New("intercepted_indexed"),
- indexed->NewInstance());
+ env->Global()->Set(
+ v8::String::NewFromUtf8(isolate, "intercepted_indexed"),
+ indexed->NewInstance());
// Create object with both named and indexed interceptor.
- v8::Handle<v8::ObjectTemplate> both = v8::ObjectTemplate::New();
+ v8::Handle<v8::ObjectTemplate> both = v8::ObjectTemplate::New(isolate);
both->SetNamedPropertyHandler(NamedGetter, NULL, NULL, NULL, NamedEnum);
both->SetIndexedPropertyHandler(IndexedGetter, NULL, NULL, NULL, IndexedEnum);
- env->Global()->Set(v8::String::New("intercepted_both"), both->NewInstance());
+ env->Global()->Set(
+ v8::String::NewFromUtf8(isolate, "intercepted_both"),
+ both->NewInstance());
// Get mirrors for the three objects with interceptor.
CompileRun(
@@ -4270,15 +4461,11 @@
// Check that the properties are interceptor properties.
for (int i = 0; i < 3; i++) {
EmbeddedVector<char, SMALL_STRING_BUFFER_SIZE> buffer;
- OS::SNPrintF(buffer,
- "named_values[%d] instanceof debug.PropertyMirror", i);
+ SNPrintF(buffer,
+ "named_values[%d] instanceof debug.PropertyMirror", i);
CHECK(CompileRun(buffer.start())->BooleanValue());
- // 5 is PropertyType.Interceptor
- OS::SNPrintF(buffer, "named_values[%d].propertyType()", i);
- CHECK_EQ(5, CompileRun(buffer.start())->Int32Value());
-
- OS::SNPrintF(buffer, "named_values[%d].isNative()", i);
+ SNPrintF(buffer, "named_values[%d].isNative()", i);
CHECK(CompileRun(buffer.start())->BooleanValue());
}
@@ -4289,8 +4476,8 @@
// Check that the properties are interceptor properties.
for (int i = 0; i < 2; i++) {
EmbeddedVector<char, SMALL_STRING_BUFFER_SIZE> buffer;
- OS::SNPrintF(buffer,
- "indexed_values[%d] instanceof debug.PropertyMirror", i);
+ SNPrintF(buffer,
+ "indexed_values[%d] instanceof debug.PropertyMirror", i);
CHECK(CompileRun(buffer.start())->BooleanValue());
}
@@ -4301,7 +4488,7 @@
// Check that the properties are interceptor properties.
for (int i = 0; i < 5; i++) {
EmbeddedVector<char, SMALL_STRING_BUFFER_SIZE> buffer;
- OS::SNPrintF(buffer, "both_values[%d] instanceof debug.PropertyMirror", i);
+ SNPrintF(buffer, "both_values[%d] instanceof debug.PropertyMirror", i);
CHECK(CompileRun(buffer.start())->BooleanValue());
}
@@ -4325,30 +4512,35 @@
TEST(HiddenPrototypePropertyMirror) {
// Create a V8 environment with debug access.
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::Isolate* isolate = env->GetIsolate();
+ v8::HandleScope scope(isolate);
env.ExposeDebug();
- v8::Handle<v8::FunctionTemplate> t0 = v8::FunctionTemplate::New();
- t0->InstanceTemplate()->Set(v8::String::New("x"), v8::Number::New(0));
- v8::Handle<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New();
+ v8::Handle<v8::FunctionTemplate> t0 = v8::FunctionTemplate::New(isolate);
+ t0->InstanceTemplate()->Set(v8::String::NewFromUtf8(isolate, "x"),
+ v8::Number::New(isolate, 0));
+ v8::Handle<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(isolate);
t1->SetHiddenPrototype(true);
- t1->InstanceTemplate()->Set(v8::String::New("y"), v8::Number::New(1));
- v8::Handle<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New();
+ t1->InstanceTemplate()->Set(v8::String::NewFromUtf8(isolate, "y"),
+ v8::Number::New(isolate, 1));
+ v8::Handle<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New(isolate);
t2->SetHiddenPrototype(true);
- t2->InstanceTemplate()->Set(v8::String::New("z"), v8::Number::New(2));
- v8::Handle<v8::FunctionTemplate> t3 = v8::FunctionTemplate::New();
- t3->InstanceTemplate()->Set(v8::String::New("u"), v8::Number::New(3));
+ t2->InstanceTemplate()->Set(v8::String::NewFromUtf8(isolate, "z"),
+ v8::Number::New(isolate, 2));
+ v8::Handle<v8::FunctionTemplate> t3 = v8::FunctionTemplate::New(isolate);
+ t3->InstanceTemplate()->Set(v8::String::NewFromUtf8(isolate, "u"),
+ v8::Number::New(isolate, 3));
// Create object and set them on the global object.
v8::Handle<v8::Object> o0 = t0->GetFunction()->NewInstance();
- env->Global()->Set(v8::String::New("o0"), o0);
+ env->Global()->Set(v8::String::NewFromUtf8(isolate, "o0"), o0);
v8::Handle<v8::Object> o1 = t1->GetFunction()->NewInstance();
- env->Global()->Set(v8::String::New("o1"), o1);
+ env->Global()->Set(v8::String::NewFromUtf8(isolate, "o1"), o1);
v8::Handle<v8::Object> o2 = t2->GetFunction()->NewInstance();
- env->Global()->Set(v8::String::New("o2"), o2);
+ env->Global()->Set(v8::String::NewFromUtf8(isolate, "o2"), o2);
v8::Handle<v8::Object> o3 = t3->GetFunction()->NewInstance();
- env->Global()->Set(v8::String::New("o3"), o3);
+ env->Global()->Set(v8::String::NewFromUtf8(isolate, "o3"), o3);
// Get mirrors for the four objects.
CompileRun(
@@ -4373,7 +4565,7 @@
// Set o1 as prototype for o0. o1 has the hidden prototype flag so all
// properties on o1 should be seen on o0.
- o0->Set(v8::String::New("__proto__"), o1);
+ o0->Set(v8::String::NewFromUtf8(isolate, "__proto__"), o1);
CHECK_EQ(2, CompileRun(
"o0_mirror.propertyNames().length")->Int32Value());
CHECK_EQ(0, CompileRun(
@@ -4384,7 +4576,7 @@
// Set o2 as prototype for o0 (it will end up after o1 as o1 has the hidden
// prototype flag. o2 also has the hidden prototype flag so all properties
// on o2 should be seen on o0 as well as properties on o1.
- o0->Set(v8::String::New("__proto__"), o2);
+ o0->Set(v8::String::NewFromUtf8(isolate, "__proto__"), o2);
CHECK_EQ(3, CompileRun(
"o0_mirror.propertyNames().length")->Int32Value());
CHECK_EQ(0, CompileRun(
@@ -4400,7 +4592,7 @@
// from o1 and o2 should still be seen on o0.
// Final prototype chain: o0 -> o1 -> o2 -> o3
// Hidden prototypes: ^^ ^^
- o0->Set(v8::String::New("__proto__"), o3);
+ o0->Set(v8::String::NewFromUtf8(isolate, "__proto__"), o3);
CHECK_EQ(3, CompileRun(
"o0_mirror.propertyNames().length")->Int32Value());
CHECK_EQ(1, CompileRun(
@@ -4418,26 +4610,29 @@
}
-static v8::Handle<v8::Value> ProtperyXNativeGetter(
- v8::Local<v8::String> property, const v8::AccessorInfo& info) {
- return v8::Integer::New(10);
+static void ProtperyXNativeGetter(
+ v8::Local<v8::String> property,
+ const v8::PropertyCallbackInfo<v8::Value>& info) {
+ info.GetReturnValue().Set(10);
}
TEST(NativeGetterPropertyMirror) {
// Create a V8 environment with debug access.
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::Isolate* isolate = env->GetIsolate();
+ v8::HandleScope scope(isolate);
env.ExposeDebug();
- v8::Handle<v8::String> name = v8::String::New("x");
+ v8::Handle<v8::String> name = v8::String::NewFromUtf8(isolate, "x");
// Create object with named accessor.
- v8::Handle<v8::ObjectTemplate> named = v8::ObjectTemplate::New();
+ v8::Handle<v8::ObjectTemplate> named = v8::ObjectTemplate::New(isolate);
named->SetAccessor(name, &ProtperyXNativeGetter, NULL,
v8::Handle<v8::Value>(), v8::DEFAULT, v8::None);
// Create object with named property getter.
- env->Global()->Set(v8::String::New("instance"), named->NewInstance());
+ env->Global()->Set(v8::String::NewFromUtf8(isolate, "instance"),
+ named->NewInstance());
CHECK_EQ(10, CompileRun("instance.x")->Int32Value());
// Get mirror for the object with property getter.
@@ -4455,26 +4650,29 @@
}
-static v8::Handle<v8::Value> ProtperyXNativeGetterThrowingError(
- v8::Local<v8::String> property, const v8::AccessorInfo& info) {
- return CompileRun("throw new Error('Error message');");
+static void ProtperyXNativeGetterThrowingError(
+ v8::Local<v8::String> property,
+ const v8::PropertyCallbackInfo<v8::Value>& info) {
+ CompileRun("throw new Error('Error message');");
}
TEST(NativeGetterThrowingErrorPropertyMirror) {
// Create a V8 environment with debug access.
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::Isolate* isolate = env->GetIsolate();
+ v8::HandleScope scope(isolate);
env.ExposeDebug();
- v8::Handle<v8::String> name = v8::String::New("x");
+ v8::Handle<v8::String> name = v8::String::NewFromUtf8(isolate, "x");
// Create object with named accessor.
- v8::Handle<v8::ObjectTemplate> named = v8::ObjectTemplate::New();
+ v8::Handle<v8::ObjectTemplate> named = v8::ObjectTemplate::New(isolate);
named->SetAccessor(name, &ProtperyXNativeGetterThrowingError, NULL,
v8::Handle<v8::Value>(), v8::DEFAULT, v8::None);
// Create object with named property getter.
- env->Global()->Set(v8::String::New("instance"), named->NewInstance());
+ env->Global()->Set(v8::String::NewFromUtf8(isolate, "instance"),
+ named->NewInstance());
// Get mirror for the object with property getter.
CompileRun("var instance_mirror = debug.MakeMirror(instance);");
@@ -4498,18 +4696,21 @@
// See http://crbug.com/26491
TEST(NoHiddenProperties) {
// Create a V8 environment with debug access.
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::Isolate* isolate = env->GetIsolate();
+ v8::HandleScope scope(isolate);
env.ExposeDebug();
// Create an object in the global scope.
const char* source = "var obj = {a: 1};";
- v8::Script::Compile(v8::String::New(source))->Run();
+ v8::Script::Compile(v8::String::NewFromUtf8(isolate, source))
+ ->Run();
v8::Local<v8::Object> obj = v8::Local<v8::Object>::Cast(
- env->Global()->Get(v8::String::New("obj")));
+ env->Global()->Get(v8::String::NewFromUtf8(isolate, "obj")));
// Set a hidden property on the object.
- obj->SetHiddenValue(v8::String::New("v8::test-debug::a"),
- v8::Int32::New(11));
+ obj->SetHiddenValue(
+ v8::String::NewFromUtf8(isolate, "v8::test-debug::a"),
+ v8::Int32::New(isolate, 11));
// Get mirror for the object with property getter.
CompileRun("var obj_mirror = debug.MakeMirror(obj);");
@@ -4525,26 +4726,34 @@
"obj_mirror.property('a').value().value() == 1")->BooleanValue());
// Object created by t0 will become hidden prototype of object 'obj'.
- v8::Handle<v8::FunctionTemplate> t0 = v8::FunctionTemplate::New();
- t0->InstanceTemplate()->Set(v8::String::New("b"), v8::Number::New(2));
+ v8::Handle<v8::FunctionTemplate> t0 = v8::FunctionTemplate::New(isolate);
+ t0->InstanceTemplate()->Set(v8::String::NewFromUtf8(isolate, "b"),
+ v8::Number::New(isolate, 2));
t0->SetHiddenPrototype(true);
- v8::Handle<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New();
- t1->InstanceTemplate()->Set(v8::String::New("c"), v8::Number::New(3));
+ v8::Handle<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(isolate);
+ t1->InstanceTemplate()->Set(v8::String::NewFromUtf8(isolate, "c"),
+ v8::Number::New(isolate, 3));
// Create proto objects, add hidden properties to them and set them on
// the global object.
v8::Handle<v8::Object> protoObj = t0->GetFunction()->NewInstance();
- protoObj->SetHiddenValue(v8::String::New("v8::test-debug::b"),
- v8::Int32::New(12));
- env->Global()->Set(v8::String::New("protoObj"), protoObj);
+ protoObj->SetHiddenValue(
+ v8::String::NewFromUtf8(isolate, "v8::test-debug::b"),
+ v8::Int32::New(isolate, 12));
+ env->Global()->Set(v8::String::NewFromUtf8(isolate, "protoObj"),
+ protoObj);
v8::Handle<v8::Object> grandProtoObj = t1->GetFunction()->NewInstance();
- grandProtoObj->SetHiddenValue(v8::String::New("v8::test-debug::c"),
- v8::Int32::New(13));
- env->Global()->Set(v8::String::New("grandProtoObj"), grandProtoObj);
+ grandProtoObj->SetHiddenValue(
+ v8::String::NewFromUtf8(isolate, "v8::test-debug::c"),
+ v8::Int32::New(isolate, 13));
+ env->Global()->Set(
+ v8::String::NewFromUtf8(isolate, "grandProtoObj"),
+ grandProtoObj);
// Setting prototypes: obj->protoObj->grandProtoObj
- protoObj->Set(v8::String::New("__proto__"), grandProtoObj);
- obj->Set(v8::String::New("__proto__"), protoObj);
+ protoObj->Set(v8::String::NewFromUtf8(isolate, "__proto__"),
+ grandProtoObj);
+ obj->Set(v8::String::NewFromUtf8(isolate, "__proto__"), protoObj);
// Get mirror for the object with property getter.
CompileRun("var obj_mirror = debug.MakeMirror(obj);");
@@ -4567,79 +4776,62 @@
// Support classes
-// Provides synchronization between k threads, where k is an input to the
-// constructor. The Wait() call blocks a thread until it is called for the
-// k'th time, then all calls return. Each ThreadBarrier object can only
-// be used once.
-class ThreadBarrier {
+// Provides synchronization between N threads, where N is a template parameter.
+// The Wait() call blocks a thread until it is called for the Nth time, then all
+// calls return. Each ThreadBarrier object can only be used once.
+template <int N>
+class ThreadBarrier FINAL {
public:
- explicit ThreadBarrier(int num_threads);
- ~ThreadBarrier();
- void Wait();
+ ThreadBarrier() : num_blocked_(0) {}
+
+ ~ThreadBarrier() {
+ LockGuard<Mutex> lock_guard(&mutex_);
+ if (num_blocked_ != 0) {
+ CHECK_EQ(N, num_blocked_);
+ }
+ }
+
+ void Wait() {
+ LockGuard<Mutex> lock_guard(&mutex_);
+ CHECK_LT(num_blocked_, N);
+ num_blocked_++;
+ if (N == num_blocked_) {
+ // Signal and unblock all waiting threads.
+ cv_.NotifyAll();
+ printf("BARRIER\n\n");
+ fflush(stdout);
+ } else { // Wait for the semaphore.
+ while (num_blocked_ < N) {
+ cv_.Wait(&mutex_);
+ }
+ }
+ CHECK_EQ(N, num_blocked_);
+ }
+
private:
- int num_threads_;
+ ConditionVariable cv_;
+ Mutex mutex_;
int num_blocked_;
- v8::internal::Mutex* lock_;
- v8::internal::Semaphore* sem_;
- bool invalid_;
+
+ STATIC_ASSERT(N > 0);
+
+ DISALLOW_COPY_AND_ASSIGN(ThreadBarrier);
};
-ThreadBarrier::ThreadBarrier(int num_threads)
- : num_threads_(num_threads), num_blocked_(0) {
- lock_ = OS::CreateMutex();
- sem_ = OS::CreateSemaphore(0);
- invalid_ = false; // A barrier may only be used once. Then it is invalid.
-}
-
-// Do not call, due to race condition with Wait().
-// Could be resolved with Pthread condition variables.
-ThreadBarrier::~ThreadBarrier() {
- lock_->Lock();
- delete lock_;
- delete sem_;
-}
-
-void ThreadBarrier::Wait() {
- lock_->Lock();
- CHECK(!invalid_);
- if (num_blocked_ == num_threads_ - 1) {
- // Signal and unblock all waiting threads.
- for (int i = 0; i < num_threads_ - 1; ++i) {
- sem_->Signal();
- }
- invalid_ = true;
- printf("BARRIER\n\n");
- fflush(stdout);
- lock_->Unlock();
- } else { // Wait for the semaphore.
- ++num_blocked_;
- lock_->Unlock(); // Potential race condition with destructor because
- sem_->Wait(); // these two lines are not atomic.
- }
-}
// A set containing enough barriers and semaphores for any of the tests.
class Barriers {
public:
- Barriers();
- void Initialize();
- ThreadBarrier barrier_1;
- ThreadBarrier barrier_2;
- ThreadBarrier barrier_3;
- ThreadBarrier barrier_4;
- ThreadBarrier barrier_5;
- v8::internal::Semaphore* semaphore_1;
- v8::internal::Semaphore* semaphore_2;
+ Barriers() : semaphore_1(0), semaphore_2(0) {}
+ ThreadBarrier<2> barrier_1;
+ ThreadBarrier<2> barrier_2;
+ ThreadBarrier<2> barrier_3;
+ ThreadBarrier<2> barrier_4;
+ ThreadBarrier<2> barrier_5;
+ v8::base::Semaphore semaphore_1;
+ v8::base::Semaphore semaphore_2;
};
-Barriers::Barriers() : barrier_1(2), barrier_2(2),
- barrier_3(2), barrier_4(2), barrier_5(2) {}
-
-void Barriers::Initialize() {
- semaphore_1 = OS::CreateSemaphore(0);
- semaphore_2 = OS::CreateSemaphore(0);
-}
-
// We match parts of the message to decide if it is a break message.
bool IsBreakEventMessage(char *message) {
@@ -4727,6 +4919,7 @@
return res;
}
+
/* Test MessageQueues */
/* Tests the message queues that hold debugger commands and
* response messages to the debugger. Fills queues and makes
@@ -4736,28 +4929,29 @@
// This is the debugger thread, that executes no v8 calls except
// placing JSON debugger commands in the queue.
-class MessageQueueDebuggerThread : public v8::internal::Thread {
+class MessageQueueDebuggerThread : public v8::base::Thread {
public:
MessageQueueDebuggerThread()
- : Thread("MessageQueueDebuggerThread") { }
+ : Thread(Options("MessageQueueDebuggerThread")) {}
void Run();
};
-static void MessageHandler(const uint16_t* message, int length,
- v8::Debug::ClientData* client_data) {
- static char print_buffer[1000];
- Utf16ToAscii(message, length, print_buffer);
- if (IsBreakEventMessage(print_buffer)) {
+
+static void MessageHandler(const v8::Debug::Message& message) {
+ v8::Handle<v8::String> json = message.GetJSON();
+ v8::String::Utf8Value utf8(json);
+ if (IsBreakEventMessage(*utf8)) {
// Lets test script wait until break occurs to send commands.
// Signals when a break is reported.
- message_queue_barriers.semaphore_2->Signal();
+ message_queue_barriers.semaphore_2.Signal();
}
// Allow message handler to block on a semaphore, to test queueing of
// messages while blocked.
- message_queue_barriers.semaphore_1->Wait();
+ message_queue_barriers.semaphore_1.Wait();
}
+
void MessageQueueDebuggerThread::Run() {
const int kBufferSize = 1000;
uint16_t buffer_1[kBufferSize];
@@ -4789,18 +4983,19 @@
/* Interleaved sequence of actions by the two threads:*/
// Main thread compiles and runs source_1
- message_queue_barriers.semaphore_1->Signal();
+ message_queue_barriers.semaphore_1.Signal();
message_queue_barriers.barrier_1.Wait();
// Post 6 commands, filling the command queue and making it expand.
// These calls return immediately, but the commands stay on the queue
// until the execution of source_2.
// Note: AsciiToUtf16 executes before SendCommand, so command is copied
// to buffer before buffer is sent to SendCommand.
- v8::Debug::SendCommand(buffer_1, AsciiToUtf16(command_1, buffer_1));
- v8::Debug::SendCommand(buffer_2, AsciiToUtf16(command_2, buffer_2));
- v8::Debug::SendCommand(buffer_2, AsciiToUtf16(command_3, buffer_2));
- v8::Debug::SendCommand(buffer_2, AsciiToUtf16(command_3, buffer_2));
- v8::Debug::SendCommand(buffer_2, AsciiToUtf16(command_3, buffer_2));
+ v8::Isolate* isolate = CcTest::isolate();
+ v8::Debug::SendCommand(isolate, buffer_1, AsciiToUtf16(command_1, buffer_1));
+ v8::Debug::SendCommand(isolate, buffer_2, AsciiToUtf16(command_2, buffer_2));
+ v8::Debug::SendCommand(isolate, buffer_2, AsciiToUtf16(command_3, buffer_2));
+ v8::Debug::SendCommand(isolate, buffer_2, AsciiToUtf16(command_3, buffer_2));
+ v8::Debug::SendCommand(isolate, buffer_2, AsciiToUtf16(command_3, buffer_2));
message_queue_barriers.barrier_2.Wait();
// Main thread compiles and runs source_2.
// Queued commands are executed at the start of compilation of source_2(
@@ -4810,31 +5005,33 @@
// All the commands added so far will fail to execute as long as call stack
// is empty on beforeCompile event.
for (int i = 0; i < 6 ; ++i) {
- message_queue_barriers.semaphore_1->Signal();
+ message_queue_barriers.semaphore_1.Signal();
}
message_queue_barriers.barrier_3.Wait();
// Main thread compiles and runs source_3.
// Don't stop in the afterCompile handler.
- message_queue_barriers.semaphore_1->Signal();
+ message_queue_barriers.semaphore_1.Signal();
// source_3 includes a debugger statement, which causes a break event.
// Wait on break event from hitting "debugger" statement
- message_queue_barriers.semaphore_2->Wait();
+ message_queue_barriers.semaphore_2.Wait();
// These should execute after the "debugger" statement in source_2
- v8::Debug::SendCommand(buffer_1, AsciiToUtf16(command_1, buffer_1));
- v8::Debug::SendCommand(buffer_2, AsciiToUtf16(command_2, buffer_2));
- v8::Debug::SendCommand(buffer_2, AsciiToUtf16(command_3, buffer_2));
- v8::Debug::SendCommand(buffer_2, AsciiToUtf16(command_single_step, buffer_2));
+ v8::Debug::SendCommand(isolate, buffer_1, AsciiToUtf16(command_1, buffer_1));
+ v8::Debug::SendCommand(isolate, buffer_2, AsciiToUtf16(command_2, buffer_2));
+ v8::Debug::SendCommand(isolate, buffer_2, AsciiToUtf16(command_3, buffer_2));
+ v8::Debug::SendCommand(
+ isolate, buffer_2, AsciiToUtf16(command_single_step, buffer_2));
// Run after 2 break events, 4 responses.
for (int i = 0; i < 6 ; ++i) {
- message_queue_barriers.semaphore_1->Signal();
+ message_queue_barriers.semaphore_1.Signal();
}
// Wait on break event after a single step executes.
- message_queue_barriers.semaphore_2->Wait();
- v8::Debug::SendCommand(buffer_1, AsciiToUtf16(command_2, buffer_1));
- v8::Debug::SendCommand(buffer_2, AsciiToUtf16(command_continue, buffer_2));
+ message_queue_barriers.semaphore_2.Wait();
+ v8::Debug::SendCommand(isolate, buffer_1, AsciiToUtf16(command_2, buffer_1));
+ v8::Debug::SendCommand(
+ isolate, buffer_2, AsciiToUtf16(command_continue, buffer_2));
// Run after 2 responses.
for (int i = 0; i < 2 ; ++i) {
- message_queue_barriers.semaphore_1->Signal();
+ message_queue_barriers.semaphore_1.Signal();
}
// Main thread continues running source_3 to end, waits for this thread.
}
@@ -4845,9 +5042,8 @@
MessageQueueDebuggerThread message_queue_debugger_thread;
// Create a V8 environment
- v8::HandleScope scope;
DebugLocalContext env;
- message_queue_barriers.Initialize();
+ v8::HandleScope scope(env->GetIsolate());
v8::Debug::SetMessageHandler(MessageHandler);
message_queue_debugger_thread.Start();
@@ -4937,11 +5133,12 @@
// Tests that all client data passed to the debugger are sent to the handler.
TEST(SendClientDataToHandler) {
// Create a V8 environment
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::Isolate* isolate = env->GetIsolate();
+ v8::HandleScope scope(isolate);
TestClientData::ResetCounters();
handled_client_data_instances_count = 0;
- v8::Debug::SetMessageHandler2(MessageHandlerCountingClientData);
+ v8::Debug::SetMessageHandler(MessageHandlerCountingClientData);
const char* source_1 = "a = 3; b = 4; c = new Object(); c.d = 5;";
const int kBufferSize = 1000;
uint16_t buffer[kBufferSize];
@@ -4960,16 +5157,18 @@
"\"type\":\"request\","
"\"command\":\"continue\"}";
- v8::Debug::SendCommand(buffer, AsciiToUtf16(command_1, buffer),
+ v8::Debug::SendCommand(isolate, buffer, AsciiToUtf16(command_1, buffer),
new TestClientData());
- v8::Debug::SendCommand(buffer, AsciiToUtf16(command_2, buffer), NULL);
- v8::Debug::SendCommand(buffer, AsciiToUtf16(command_2, buffer),
+ v8::Debug::SendCommand(
+ isolate, buffer, AsciiToUtf16(command_2, buffer), NULL);
+ v8::Debug::SendCommand(isolate, buffer, AsciiToUtf16(command_2, buffer),
new TestClientData());
- v8::Debug::SendCommand(buffer, AsciiToUtf16(command_2, buffer),
+ v8::Debug::SendCommand(isolate, buffer, AsciiToUtf16(command_2, buffer),
new TestClientData());
// All the messages will be processed on beforeCompile event.
CompileRun(source_1);
- v8::Debug::SendCommand(buffer, AsciiToUtf16(command_continue, buffer));
+ v8::Debug::SendCommand(
+ isolate, buffer, AsciiToUtf16(command_continue, buffer));
CHECK_EQ(3, TestClientData::constructor_call_counter);
CHECK_EQ(TestClientData::constructor_call_counter,
handled_client_data_instances_count);
@@ -4987,22 +5186,30 @@
Barriers threaded_debugging_barriers;
-class V8Thread : public v8::internal::Thread {
+class V8Thread : public v8::base::Thread {
public:
- V8Thread() : Thread("V8Thread") { }
+ V8Thread() : Thread(Options("V8Thread")) {}
void Run();
+ v8::Isolate* isolate() { return isolate_; }
+
+ private:
+ v8::Isolate* isolate_;
};
-class DebuggerThread : public v8::internal::Thread {
+class DebuggerThread : public v8::base::Thread {
public:
- DebuggerThread() : Thread("DebuggerThread") { }
+ explicit DebuggerThread(v8::Isolate* isolate)
+ : Thread(Options("DebuggerThread")), isolate_(isolate) {}
void Run();
+
+ private:
+ v8::Isolate* isolate_;
};
-static v8::Handle<v8::Value> ThreadedAtBarrier1(const v8::Arguments& args) {
+static void ThreadedAtBarrier1(
+ const v8::FunctionCallbackInfo<v8::Value>& args) {
threaded_debugging_barriers.barrier_1.Wait();
- return v8::Undefined();
}
@@ -5039,19 +5246,28 @@
"\n"
"foo();\n";
- v8::V8::Initialize();
- v8::HandleScope scope;
- DebugLocalContext env;
- v8::Debug::SetMessageHandler2(&ThreadedMessageHandler);
- v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
- global_template->Set(v8::String::New("ThreadedAtBarrier1"),
- v8::FunctionTemplate::New(ThreadedAtBarrier1));
- v8::Handle<v8::Context> context = v8::Context::New(NULL, global_template);
- v8::Context::Scope context_scope(context);
+ isolate_ = v8::Isolate::New();
+ threaded_debugging_barriers.barrier_3.Wait();
+ {
+ v8::Isolate::Scope isolate_scope(isolate_);
+ DebugLocalContext env(isolate_);
+ v8::HandleScope scope(isolate_);
+ v8::Debug::SetMessageHandler(&ThreadedMessageHandler);
+ v8::Handle<v8::ObjectTemplate> global_template =
+ v8::ObjectTemplate::New(env->GetIsolate());
+ global_template->Set(
+ v8::String::NewFromUtf8(env->GetIsolate(), "ThreadedAtBarrier1"),
+ v8::FunctionTemplate::New(isolate_, ThreadedAtBarrier1));
+ v8::Handle<v8::Context> context =
+ v8::Context::New(isolate_, NULL, global_template);
+ v8::Context::Scope context_scope(context);
- CompileRun(source);
+ CompileRun(source);
+ }
+ isolate_->Dispose();
}
+
void DebuggerThread::Run() {
const int kBufSize = 1000;
uint16_t buffer[kBufSize];
@@ -5065,27 +5281,27 @@
"\"command\":\"continue\"}";
threaded_debugging_barriers.barrier_1.Wait();
- v8::Debug::DebugBreak();
+ v8::Debug::DebugBreak(isolate_);
threaded_debugging_barriers.barrier_2.Wait();
- v8::Debug::SendCommand(buffer, AsciiToUtf16(command_1, buffer));
- v8::Debug::SendCommand(buffer, AsciiToUtf16(command_2, buffer));
+ v8::Debug::SendCommand(isolate_, buffer, AsciiToUtf16(command_1, buffer));
+ v8::Debug::SendCommand(isolate_, buffer, AsciiToUtf16(command_2, buffer));
}
TEST(ThreadedDebugging) {
- DebuggerThread debugger_thread;
V8Thread v8_thread;
// Create a V8 environment
- threaded_debugging_barriers.Initialize();
-
v8_thread.Start();
+ threaded_debugging_barriers.barrier_3.Wait();
+ DebuggerThread debugger_thread(v8_thread.isolate());
debugger_thread.Start();
v8_thread.Join();
debugger_thread.Join();
}
+
/* Test RecursiveBreakpoints */
/* In this test, the debugger evaluates a function with a breakpoint, after
* hitting a breakpoint in another function. We do this with both values
@@ -5093,21 +5309,28 @@
* breakpoint is hit when enabled, and missed when disabled.
*/
-class BreakpointsV8Thread : public v8::internal::Thread {
+class BreakpointsV8Thread : public v8::base::Thread {
public:
- BreakpointsV8Thread() : Thread("BreakpointsV8Thread") { }
+ BreakpointsV8Thread() : Thread(Options("BreakpointsV8Thread")) {}
void Run();
+
+ v8::Isolate* isolate() { return isolate_; }
+
+ private:
+ v8::Isolate* isolate_;
};
-class BreakpointsDebuggerThread : public v8::internal::Thread {
+class BreakpointsDebuggerThread : public v8::base::Thread {
public:
- explicit BreakpointsDebuggerThread(bool global_evaluate)
- : Thread("BreakpointsDebuggerThread"),
- global_evaluate_(global_evaluate) {}
+ BreakpointsDebuggerThread(bool global_evaluate, v8::Isolate* isolate)
+ : Thread(Options("BreakpointsDebuggerThread")),
+ global_evaluate_(global_evaluate),
+ isolate_(isolate) {}
void Run();
private:
bool global_evaluate_;
+ v8::Isolate* isolate_;
};
@@ -5123,10 +5346,10 @@
if (IsBreakEventMessage(print_buffer)) {
break_event_breakpoint_id =
GetBreakpointIdFromBreakEventMessage(print_buffer);
- breakpoints_barriers->semaphore_1->Signal();
+ breakpoints_barriers->semaphore_1.Signal();
} else if (IsEvaluateResponseMessage(print_buffer)) {
evaluate_int_result = GetEvaluateIntResult(print_buffer);
- breakpoints_barriers->semaphore_1->Signal();
+ breakpoints_barriers->semaphore_1.Signal();
}
}
@@ -5152,15 +5375,20 @@
const char* source_2 = "cat(17);\n"
"cat(19);\n";
- v8::V8::Initialize();
- v8::HandleScope scope;
- DebugLocalContext env;
- v8::Debug::SetMessageHandler2(&BreakpointsMessageHandler);
+ isolate_ = v8::Isolate::New();
+ breakpoints_barriers->barrier_3.Wait();
+ {
+ v8::Isolate::Scope isolate_scope(isolate_);
+ DebugLocalContext env(isolate_);
+ v8::HandleScope scope(isolate_);
+ v8::Debug::SetMessageHandler(&BreakpointsMessageHandler);
- CompileRun(source_1);
- breakpoints_barriers->barrier_1.Wait();
- breakpoints_barriers->barrier_2.Wait();
- CompileRun(source_2);
+ CompileRun(source_1);
+ breakpoints_barriers->barrier_1.Wait();
+ breakpoints_barriers->barrier_2.Wait();
+ CompileRun(source_2);
+ }
+ isolate_->Dispose();
}
@@ -5229,85 +5457,85 @@
// v8 thread initializes, runs source_1
breakpoints_barriers->barrier_1.Wait();
// 1:Set breakpoint in cat() (will get id 1).
- v8::Debug::SendCommand(buffer, AsciiToUtf16(command_1, buffer));
+ v8::Debug::SendCommand(isolate_, buffer, AsciiToUtf16(command_1, buffer));
// 2:Set breakpoint in dog() (will get id 2).
- v8::Debug::SendCommand(buffer, AsciiToUtf16(command_2, buffer));
+ v8::Debug::SendCommand(isolate_, buffer, AsciiToUtf16(command_2, buffer));
breakpoints_barriers->barrier_2.Wait();
// V8 thread starts compiling source_2.
// Automatic break happens, to run queued commands
- // breakpoints_barriers->semaphore_1->Wait();
+ // breakpoints_barriers->semaphore_1.Wait();
// Commands 1 through 3 run, thread continues.
// v8 thread runs source_2 to breakpoint in cat().
// message callback receives break event.
- breakpoints_barriers->semaphore_1->Wait();
+ breakpoints_barriers->semaphore_1.Wait();
// Must have hit breakpoint #1.
CHECK_EQ(1, break_event_breakpoint_id);
// 4:Evaluate dog() (which has a breakpoint).
- v8::Debug::SendCommand(buffer, AsciiToUtf16(command_3, buffer));
+ v8::Debug::SendCommand(isolate_, buffer, AsciiToUtf16(command_3, buffer));
// V8 thread hits breakpoint in dog().
- breakpoints_barriers->semaphore_1->Wait(); // wait for break event
+ breakpoints_barriers->semaphore_1.Wait(); // wait for break event
// Must have hit breakpoint #2.
CHECK_EQ(2, break_event_breakpoint_id);
// 5:Evaluate (x + 1).
- v8::Debug::SendCommand(buffer, AsciiToUtf16(command_4, buffer));
+ v8::Debug::SendCommand(isolate_, buffer, AsciiToUtf16(command_4, buffer));
// Evaluate (x + 1) finishes.
- breakpoints_barriers->semaphore_1->Wait();
+ breakpoints_barriers->semaphore_1.Wait();
// Must have result 108.
CHECK_EQ(108, evaluate_int_result);
// 6:Continue evaluation of dog().
- v8::Debug::SendCommand(buffer, AsciiToUtf16(command_5, buffer));
+ v8::Debug::SendCommand(isolate_, buffer, AsciiToUtf16(command_5, buffer));
// Evaluate dog() finishes.
- breakpoints_barriers->semaphore_1->Wait();
+ breakpoints_barriers->semaphore_1.Wait();
// Must have result 107.
CHECK_EQ(107, evaluate_int_result);
// 7:Continue evaluation of source_2, finish cat(17), hit breakpoint
// in cat(19).
- v8::Debug::SendCommand(buffer, AsciiToUtf16(command_6, buffer));
+ v8::Debug::SendCommand(isolate_, buffer, AsciiToUtf16(command_6, buffer));
// Message callback gets break event.
- breakpoints_barriers->semaphore_1->Wait(); // wait for break event
+ breakpoints_barriers->semaphore_1.Wait(); // wait for break event
// Must have hit breakpoint #1.
CHECK_EQ(1, break_event_breakpoint_id);
// 8: Evaluate dog() with breaks disabled.
- v8::Debug::SendCommand(buffer, AsciiToUtf16(command_7, buffer));
+ v8::Debug::SendCommand(isolate_, buffer, AsciiToUtf16(command_7, buffer));
// Evaluate dog() finishes.
- breakpoints_barriers->semaphore_1->Wait();
+ breakpoints_barriers->semaphore_1.Wait();
// Must have result 116.
CHECK_EQ(116, evaluate_int_result);
// 9: Continue evaluation of source2, reach end.
- v8::Debug::SendCommand(buffer, AsciiToUtf16(command_8, buffer));
+ v8::Debug::SendCommand(isolate_, buffer, AsciiToUtf16(command_8, buffer));
}
-void TestRecursiveBreakpointsGeneric(bool global_evaluate) {
- i::FLAG_debugger_auto_break = true;
- BreakpointsDebuggerThread breakpoints_debugger_thread(global_evaluate);
+void TestRecursiveBreakpointsGeneric(bool global_evaluate) {
BreakpointsV8Thread breakpoints_v8_thread;
// Create a V8 environment
Barriers stack_allocated_breakpoints_barriers;
- stack_allocated_breakpoints_barriers.Initialize();
breakpoints_barriers = &stack_allocated_breakpoints_barriers;
breakpoints_v8_thread.Start();
+ breakpoints_barriers->barrier_3.Wait();
+ BreakpointsDebuggerThread breakpoints_debugger_thread(
+ global_evaluate, breakpoints_v8_thread.isolate());
breakpoints_debugger_thread.Start();
breakpoints_v8_thread.Join();
breakpoints_debugger_thread.Join();
}
+
TEST(RecursiveBreakpoints) {
TestRecursiveBreakpointsGeneric(false);
}
+
TEST(RecursiveBreakpointsGlobal) {
TestRecursiveBreakpointsGeneric(true);
}
-static void DummyDebugEventListener(v8::DebugEvent event,
- v8::Handle<v8::Object> exec_state,
- v8::Handle<v8::Object> event_data,
- v8::Handle<v8::Value> data) {
+static void DummyDebugEventListener(
+ const v8::Debug::EventDetails& event_details) {
}
@@ -5321,20 +5549,7 @@
TEST(SetMessageHandlerOnUninitializedVM) {
- v8::Debug::SetMessageHandler2(DummyMessageHandler);
-}
-
-
-TEST(DebugBreakOnUninitializedVM) {
- v8::Debug::DebugBreak();
-}
-
-
-TEST(SendCommandToUninitializedVM) {
- const char* dummy_command = "{}";
- uint16_t dummy_buffer[80];
- int dummy_length = AsciiToUtf16(dummy_command, dummy_buffer);
- v8::Debug::SendCommand(dummy_buffer, dummy_length);
+ v8::Debug::SetMessageHandler(DummyMessageHandler);
}
@@ -5363,48 +5578,44 @@
// Function to retrieve the number of JavaScript frames by calling a JavaScript
// in the debugger.
-static v8::Handle<v8::Value> CheckFrameCount(const v8::Arguments& args) {
+static void CheckFrameCount(const v8::FunctionCallbackInfo<v8::Value>& args) {
CHECK(v8::Debug::Call(frame_count)->IsNumber());
CHECK_EQ(args[0]->Int32Value(),
v8::Debug::Call(frame_count)->Int32Value());
- return v8::Undefined();
}
// Function to retrieve the source line of the top JavaScript frame by calling a
// JavaScript function in the debugger.
-static v8::Handle<v8::Value> CheckSourceLine(const v8::Arguments& args) {
+static void CheckSourceLine(const v8::FunctionCallbackInfo<v8::Value>& args) {
CHECK(v8::Debug::Call(frame_source_line)->IsNumber());
CHECK_EQ(args[0]->Int32Value(),
v8::Debug::Call(frame_source_line)->Int32Value());
- return v8::Undefined();
}
// Function to test passing an additional parameter to a JavaScript function
// called in the debugger. It also tests that functions called in the debugger
// can throw exceptions.
-static v8::Handle<v8::Value> CheckDataParameter(const v8::Arguments& args) {
- v8::Handle<v8::String> data = v8::String::New("Test");
+static void CheckDataParameter(
+ const v8::FunctionCallbackInfo<v8::Value>& args) {
+ v8::Handle<v8::String> data =
+ v8::String::NewFromUtf8(args.GetIsolate(), "Test");
CHECK(v8::Debug::Call(debugger_call_with_data, data)->IsString());
- CHECK(v8::Debug::Call(debugger_call_with_data).IsEmpty());
- CHECK(v8::Debug::Call(debugger_call_with_data).IsEmpty());
-
- v8::TryCatch catcher;
- v8::Debug::Call(debugger_call_with_data);
- CHECK(catcher.HasCaught());
- CHECK(catcher.Exception()->IsString());
-
- return v8::Undefined();
+ for (int i = 0; i < 3; i++) {
+ v8::TryCatch catcher;
+ CHECK(v8::Debug::Call(debugger_call_with_data).IsEmpty());
+ CHECK(catcher.HasCaught());
+ CHECK(catcher.Exception()->IsString());
+ }
}
// Function to test using a JavaScript with closure in the debugger.
-static v8::Handle<v8::Value> CheckClosure(const v8::Arguments& args) {
+static void CheckClosure(const v8::FunctionCallbackInfo<v8::Value>& args) {
CHECK(v8::Debug::Call(debugger_call_with_closure)->IsNumber());
CHECK_EQ(3, v8::Debug::Call(debugger_call_with_closure)->Int32Value());
- return v8::Undefined();
}
@@ -5412,73 +5623,97 @@
TEST(CallFunctionInDebugger) {
// Create and enter a context with the functions CheckFrameCount,
// CheckSourceLine and CheckDataParameter installed.
- v8::HandleScope scope;
- v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
- global_template->Set(v8::String::New("CheckFrameCount"),
- v8::FunctionTemplate::New(CheckFrameCount));
- global_template->Set(v8::String::New("CheckSourceLine"),
- v8::FunctionTemplate::New(CheckSourceLine));
- global_template->Set(v8::String::New("CheckDataParameter"),
- v8::FunctionTemplate::New(CheckDataParameter));
- global_template->Set(v8::String::New("CheckClosure"),
- v8::FunctionTemplate::New(CheckClosure));
- v8::Handle<v8::Context> context = v8::Context::New(NULL, global_template);
+ v8::Isolate* isolate = CcTest::isolate();
+ v8::HandleScope scope(isolate);
+ v8::Handle<v8::ObjectTemplate> global_template =
+ v8::ObjectTemplate::New(isolate);
+ global_template->Set(
+ v8::String::NewFromUtf8(isolate, "CheckFrameCount"),
+ v8::FunctionTemplate::New(isolate, CheckFrameCount));
+ global_template->Set(
+ v8::String::NewFromUtf8(isolate, "CheckSourceLine"),
+ v8::FunctionTemplate::New(isolate, CheckSourceLine));
+ global_template->Set(
+ v8::String::NewFromUtf8(isolate, "CheckDataParameter"),
+ v8::FunctionTemplate::New(isolate, CheckDataParameter));
+ global_template->Set(
+ v8::String::NewFromUtf8(isolate, "CheckClosure"),
+ v8::FunctionTemplate::New(isolate, CheckClosure));
+ v8::Handle<v8::Context> context = v8::Context::New(isolate,
+ NULL,
+ global_template);
v8::Context::Scope context_scope(context);
// Compile a function for checking the number of JavaScript frames.
- v8::Script::Compile(v8::String::New(frame_count_source))->Run();
- frame_count = v8::Local<v8::Function>::Cast(
- context->Global()->Get(v8::String::New("frame_count")));
+ v8::Script::Compile(
+ v8::String::NewFromUtf8(isolate, frame_count_source))->Run();
+ frame_count = v8::Local<v8::Function>::Cast(context->Global()->Get(
+ v8::String::NewFromUtf8(isolate, "frame_count")));
// Compile a function for returning the source line for the top frame.
- v8::Script::Compile(v8::String::New(frame_source_line_source))->Run();
- frame_source_line = v8::Local<v8::Function>::Cast(
- context->Global()->Get(v8::String::New("frame_source_line")));
+ v8::Script::Compile(v8::String::NewFromUtf8(isolate,
+ frame_source_line_source))->Run();
+ frame_source_line = v8::Local<v8::Function>::Cast(context->Global()->Get(
+ v8::String::NewFromUtf8(isolate, "frame_source_line")));
// Compile a function returning the data parameter.
- v8::Script::Compile(v8::String::New(debugger_call_with_data_source))->Run();
+ v8::Script::Compile(v8::String::NewFromUtf8(isolate,
+ debugger_call_with_data_source))
+ ->Run();
debugger_call_with_data = v8::Local<v8::Function>::Cast(
- context->Global()->Get(v8::String::New("debugger_call_with_data")));
+ context->Global()->Get(v8::String::NewFromUtf8(
+ isolate, "debugger_call_with_data")));
// Compile a function capturing closure.
- debugger_call_with_closure = v8::Local<v8::Function>::Cast(
- v8::Script::Compile(
- v8::String::New(debugger_call_with_closure_source))->Run());
+ debugger_call_with_closure =
+ v8::Local<v8::Function>::Cast(v8::Script::Compile(
+ v8::String::NewFromUtf8(isolate,
+ debugger_call_with_closure_source))->Run());
// Calling a function through the debugger returns 0 frames if there are
// no JavaScript frames.
- CHECK_EQ(v8::Integer::New(0), v8::Debug::Call(frame_count));
+ CHECK_EQ(v8::Integer::New(isolate, 0),
+ v8::Debug::Call(frame_count));
// Test that the number of frames can be retrieved.
- v8::Script::Compile(v8::String::New("CheckFrameCount(1)"))->Run();
- v8::Script::Compile(v8::String::New("function f() {"
- " CheckFrameCount(2);"
- "}; f()"))->Run();
+ v8::Script::Compile(
+ v8::String::NewFromUtf8(isolate, "CheckFrameCount(1)"))->Run();
+ v8::Script::Compile(v8::String::NewFromUtf8(isolate,
+ "function f() {"
+ " CheckFrameCount(2);"
+ "}; f()"))->Run();
// Test that the source line can be retrieved.
- v8::Script::Compile(v8::String::New("CheckSourceLine(0)"))->Run();
- v8::Script::Compile(v8::String::New("function f() {\n"
- " CheckSourceLine(1)\n"
- " CheckSourceLine(2)\n"
- " CheckSourceLine(3)\n"
- "}; f()"))->Run();
+ v8::Script::Compile(
+ v8::String::NewFromUtf8(isolate, "CheckSourceLine(0)"))->Run();
+ v8::Script::Compile(v8::String::NewFromUtf8(isolate,
+ "function f() {\n"
+ " CheckSourceLine(1)\n"
+ " CheckSourceLine(2)\n"
+ " CheckSourceLine(3)\n"
+ "}; f()"))->Run();
// Test that a parameter can be passed to a function called in the debugger.
- v8::Script::Compile(v8::String::New("CheckDataParameter()"))->Run();
+ v8::Script::Compile(v8::String::NewFromUtf8(isolate,
+ "CheckDataParameter()"))->Run();
// Test that a function with closure can be run in the debugger.
- v8::Script::Compile(v8::String::New("CheckClosure()"))->Run();
-
+ v8::Script::Compile(
+ v8::String::NewFromUtf8(isolate, "CheckClosure()"))->Run();
// Test that the source line is correct when there is a line offset.
- v8::ScriptOrigin origin(v8::String::New("test"),
- v8::Integer::New(7));
- v8::Script::Compile(v8::String::New("CheckSourceLine(7)"), &origin)->Run();
- v8::Script::Compile(v8::String::New("function f() {\n"
- " CheckSourceLine(8)\n"
- " CheckSourceLine(9)\n"
- " CheckSourceLine(10)\n"
- "}; f()"), &origin)->Run();
+ v8::ScriptOrigin origin(v8::String::NewFromUtf8(isolate, "test"),
+ v8::Integer::New(isolate, 7));
+ v8::Script::Compile(
+ v8::String::NewFromUtf8(isolate, "CheckSourceLine(7)"), &origin)
+ ->Run();
+ v8::Script::Compile(v8::String::NewFromUtf8(isolate,
+ "function f() {\n"
+ " CheckSourceLine(8)\n"
+ " CheckSourceLine(9)\n"
+ " CheckSourceLine(10)\n"
+ "}; f()"),
+ &origin)->Run();
}
@@ -5505,10 +5740,9 @@
// Set a debug event listener.
break_point_hit_count = 0;
- v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
- v8::Undefined());
+ v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount);
{
- v8::HandleScope scope;
+ v8::HandleScope scope(env->GetIsolate());
// Create a couple of functions for the test.
v8::Local<v8::Function> foo =
CompileFunction(&env, "function foo(){x=1}", "foo");
@@ -5536,13 +5770,13 @@
// Now set a debug message handler.
break_point_hit_count = 0;
- v8::Debug::SetMessageHandler2(MessageHandlerBreakPointHitCount);
+ v8::Debug::SetMessageHandler(MessageHandlerBreakPointHitCount);
{
- v8::HandleScope scope;
+ v8::HandleScope scope(env->GetIsolate());
// Get the test functions again.
v8::Local<v8::Function> foo(v8::Local<v8::Function>::Cast(
- env->Global()->Get(v8::String::New("foo"))));
+ env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "foo"))));
foo->Call(env->Global(), 0, NULL);
CHECK_EQ(0, break_point_hit_count);
@@ -5556,7 +5790,7 @@
// Remove the debug message handler without clearing breakpoints. Do this
// outside a handle scope.
- v8::Debug::SetMessageHandler2(NULL);
+ v8::Debug::SetMessageHandler(NULL);
CheckDebuggerUnloaded(true);
}
@@ -5570,7 +5804,8 @@
"\"type\":\"request\","
"\"command\":\"continue\"}";
- v8::Debug::SendCommand(buffer, AsciiToUtf16(command_continue, buffer));
+ v8::Debug::SendCommand(
+ CcTest::isolate(), buffer, AsciiToUtf16(command_continue, buffer));
}
@@ -5591,14 +5826,14 @@
// Test clearing the debug message handler.
TEST(DebuggerClearMessageHandler) {
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
// Check debugger is unloaded before it is used.
CheckDebuggerUnloaded();
// Set a debug message handler.
- v8::Debug::SetMessageHandler2(MessageHandlerHitCount);
+ v8::Debug::SetMessageHandler(MessageHandlerHitCount);
// Run code to throw a unhandled exception. This should end up in the message
// handler.
@@ -5634,14 +5869,14 @@
// Test clearing the debug message handler while processing a debug event.
TEST(DebuggerClearMessageHandlerWhileActive) {
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
// Check debugger is unloaded before it is used.
CheckDebuggerUnloaded();
// Set a debug message handler.
- v8::Debug::SetMessageHandler2(MessageHandlerClearingMessageHandler);
+ v8::Debug::SetMessageHandler(MessageHandlerClearingMessageHandler);
// Run code to throw a unhandled exception. This should end up in the message
// handler.
@@ -5654,350 +5889,6 @@
}
-/* Test DebuggerHostDispatch */
-/* In this test, the debugger waits for a command on a breakpoint
- * and is dispatching host commands while in the infinite loop.
- */
-
-class HostDispatchV8Thread : public v8::internal::Thread {
- public:
- HostDispatchV8Thread() : Thread("HostDispatchV8Thread") { }
- void Run();
-};
-
-class HostDispatchDebuggerThread : public v8::internal::Thread {
- public:
- HostDispatchDebuggerThread() : Thread("HostDispatchDebuggerThread") { }
- void Run();
-};
-
-Barriers* host_dispatch_barriers;
-
-static void HostDispatchMessageHandler(const v8::Debug::Message& message) {
- static char print_buffer[1000];
- v8::String::Value json(message.GetJSON());
- Utf16ToAscii(*json, json.length(), print_buffer);
-}
-
-
-static void HostDispatchDispatchHandler() {
- host_dispatch_barriers->semaphore_1->Signal();
-}
-
-
-void HostDispatchV8Thread::Run() {
- const char* source_1 = "var y_global = 3;\n"
- "function cat( new_value ) {\n"
- " var x = new_value;\n"
- " y_global = 4;\n"
- " x = 3 * x + 1;\n"
- " y_global = 5;\n"
- " return x;\n"
- "}\n"
- "\n";
- const char* source_2 = "cat(17);\n";
-
- v8::V8::Initialize();
- v8::HandleScope scope;
- DebugLocalContext env;
-
- // Set up message and host dispatch handlers.
- v8::Debug::SetMessageHandler2(HostDispatchMessageHandler);
- v8::Debug::SetHostDispatchHandler(HostDispatchDispatchHandler, 10 /* ms */);
-
- CompileRun(source_1);
- host_dispatch_barriers->barrier_1.Wait();
- host_dispatch_barriers->barrier_2.Wait();
- CompileRun(source_2);
-}
-
-
-void HostDispatchDebuggerThread::Run() {
- const int kBufSize = 1000;
- uint16_t buffer[kBufSize];
-
- const char* command_1 = "{\"seq\":101,"
- "\"type\":\"request\","
- "\"command\":\"setbreakpoint\","
- "\"arguments\":{\"type\":\"function\",\"target\":\"cat\",\"line\":3}}";
- const char* command_2 = "{\"seq\":102,"
- "\"type\":\"request\","
- "\"command\":\"continue\"}";
-
- // v8 thread initializes, runs source_1
- host_dispatch_barriers->barrier_1.Wait();
- // 1: Set breakpoint in cat().
- v8::Debug::SendCommand(buffer, AsciiToUtf16(command_1, buffer));
-
- host_dispatch_barriers->barrier_2.Wait();
- // v8 thread starts compiling source_2.
- // Break happens, to run queued commands and host dispatches.
- // Wait for host dispatch to be processed.
- host_dispatch_barriers->semaphore_1->Wait();
- // 2: Continue evaluation
- v8::Debug::SendCommand(buffer, AsciiToUtf16(command_2, buffer));
-}
-
-
-TEST(DebuggerHostDispatch) {
- HostDispatchDebuggerThread host_dispatch_debugger_thread;
- HostDispatchV8Thread host_dispatch_v8_thread;
- i::FLAG_debugger_auto_break = true;
-
- // Create a V8 environment
- Barriers stack_allocated_host_dispatch_barriers;
- stack_allocated_host_dispatch_barriers.Initialize();
- host_dispatch_barriers = &stack_allocated_host_dispatch_barriers;
-
- host_dispatch_v8_thread.Start();
- host_dispatch_debugger_thread.Start();
-
- host_dispatch_v8_thread.Join();
- host_dispatch_debugger_thread.Join();
-}
-
-
-/* Test DebugMessageDispatch */
-/* In this test, the V8 thread waits for a message from the debug thread.
- * The DebugMessageDispatchHandler is executed from the debugger thread
- * which signals the V8 thread to wake up.
- */
-
-class DebugMessageDispatchV8Thread : public v8::internal::Thread {
- public:
- DebugMessageDispatchV8Thread() : Thread("DebugMessageDispatchV8Thread") { }
- void Run();
-};
-
-class DebugMessageDispatchDebuggerThread : public v8::internal::Thread {
- public:
- DebugMessageDispatchDebuggerThread()
- : Thread("DebugMessageDispatchDebuggerThread") { }
- void Run();
-};
-
-Barriers* debug_message_dispatch_barriers;
-
-
-static void DebugMessageHandler() {
- debug_message_dispatch_barriers->semaphore_1->Signal();
-}
-
-
-void DebugMessageDispatchV8Thread::Run() {
- v8::V8::Initialize();
- v8::HandleScope scope;
- DebugLocalContext env;
-
- // Set up debug message dispatch handler.
- v8::Debug::SetDebugMessageDispatchHandler(DebugMessageHandler);
-
- CompileRun("var y = 1 + 2;\n");
- debug_message_dispatch_barriers->barrier_1.Wait();
- debug_message_dispatch_barriers->semaphore_1->Wait();
- debug_message_dispatch_barriers->barrier_2.Wait();
-}
-
-
-void DebugMessageDispatchDebuggerThread::Run() {
- debug_message_dispatch_barriers->barrier_1.Wait();
- SendContinueCommand();
- debug_message_dispatch_barriers->barrier_2.Wait();
-}
-
-
-TEST(DebuggerDebugMessageDispatch) {
- DebugMessageDispatchDebuggerThread debug_message_dispatch_debugger_thread;
- DebugMessageDispatchV8Thread debug_message_dispatch_v8_thread;
-
- i::FLAG_debugger_auto_break = true;
-
- // Create a V8 environment
- Barriers stack_allocated_debug_message_dispatch_barriers;
- stack_allocated_debug_message_dispatch_barriers.Initialize();
- debug_message_dispatch_barriers =
- &stack_allocated_debug_message_dispatch_barriers;
-
- debug_message_dispatch_v8_thread.Start();
- debug_message_dispatch_debugger_thread.Start();
-
- debug_message_dispatch_v8_thread.Join();
- debug_message_dispatch_debugger_thread.Join();
-}
-
-
-TEST(DebuggerAgent) {
- v8::V8::Initialize();
- i::Debugger* debugger = i::Isolate::Current()->debugger();
- // Make sure these ports is not used by other tests to allow tests to run in
- // parallel.
- const int kPort1 = 5858;
- const int kPort2 = 5857;
- const int kPort3 = 5856;
-
- // Make a string with the port2 number.
- const int kPortBufferLen = 6;
- char port2_str[kPortBufferLen];
- OS::SNPrintF(i::Vector<char>(port2_str, kPortBufferLen), "%d", kPort2);
-
- bool ok;
-
- // Initialize the socket library.
- i::Socket::SetUp();
-
- // Test starting and stopping the agent without any client connection.
- debugger->StartAgent("test", kPort1);
- debugger->StopAgent();
- // Test starting the agent, connecting a client and shutting down the agent
- // with the client connected.
- ok = debugger->StartAgent("test", kPort2);
- CHECK(ok);
- debugger->WaitForAgent();
- i::Socket* client = i::OS::CreateSocket();
- ok = client->Connect("localhost", port2_str);
- CHECK(ok);
- // It is important to wait for a message from the agent. Otherwise,
- // we can close the server socket during "accept" syscall, making it failing
- // (at least on Linux), and the test will work incorrectly.
- char buf;
- ok = client->Receive(&buf, 1) == 1;
- CHECK(ok);
- debugger->StopAgent();
- delete client;
-
- // Test starting and stopping the agent with the required port already
- // occoupied.
- i::Socket* server = i::OS::CreateSocket();
- server->Bind(kPort3);
-
- debugger->StartAgent("test", kPort3);
- debugger->StopAgent();
-
- delete server;
-}
-
-
-class DebuggerAgentProtocolServerThread : public i::Thread {
- public:
- explicit DebuggerAgentProtocolServerThread(int port)
- : Thread("DebuggerAgentProtocolServerThread"),
- port_(port),
- server_(NULL),
- client_(NULL),
- listening_(OS::CreateSemaphore(0)) {
- }
- ~DebuggerAgentProtocolServerThread() {
- // Close both sockets.
- delete client_;
- delete server_;
- delete listening_;
- }
-
- void Run();
- void WaitForListening() { listening_->Wait(); }
- char* body() { return *body_; }
-
- private:
- int port_;
- i::SmartArrayPointer<char> body_;
- i::Socket* server_; // Server socket used for bind/accept.
- i::Socket* client_; // Single client connection used by the test.
- i::Semaphore* listening_; // Signalled when the server is in listen mode.
-};
-
-
-void DebuggerAgentProtocolServerThread::Run() {
- bool ok;
-
- // Create the server socket and bind it to the requested port.
- server_ = i::OS::CreateSocket();
- CHECK(server_ != NULL);
- ok = server_->Bind(port_);
- CHECK(ok);
-
- // Listen for new connections.
- ok = server_->Listen(1);
- CHECK(ok);
- listening_->Signal();
-
- // Accept a connection.
- client_ = server_->Accept();
- CHECK(client_ != NULL);
-
- // Receive a debugger agent protocol message.
- i::DebuggerAgentUtil::ReceiveMessage(client_);
-}
-
-
-TEST(DebuggerAgentProtocolOverflowHeader) {
- // Make sure this port is not used by other tests to allow tests to run in
- // parallel.
- const int kPort = 5860;
- static const char* kLocalhost = "localhost";
-
- // Make a string with the port number.
- const int kPortBufferLen = 6;
- char port_str[kPortBufferLen];
- OS::SNPrintF(i::Vector<char>(port_str, kPortBufferLen), "%d", kPort);
-
- // Initialize the socket library.
- i::Socket::SetUp();
-
- // Create a socket server to receive a debugger agent message.
- DebuggerAgentProtocolServerThread* server =
- new DebuggerAgentProtocolServerThread(kPort);
- server->Start();
- server->WaitForListening();
-
- // Connect.
- i::Socket* client = i::OS::CreateSocket();
- CHECK(client != NULL);
- bool ok = client->Connect(kLocalhost, port_str);
- CHECK(ok);
-
- // Send headers which overflow the receive buffer.
- static const int kBufferSize = 1000;
- char buffer[kBufferSize];
-
- // Long key and short value: XXXX....XXXX:0\r\n.
- for (int i = 0; i < kBufferSize - 4; i++) {
- buffer[i] = 'X';
- }
- buffer[kBufferSize - 4] = ':';
- buffer[kBufferSize - 3] = '0';
- buffer[kBufferSize - 2] = '\r';
- buffer[kBufferSize - 1] = '\n';
- client->Send(buffer, kBufferSize);
-
- // Short key and long value: X:XXXX....XXXX\r\n.
- buffer[0] = 'X';
- buffer[1] = ':';
- for (int i = 2; i < kBufferSize - 2; i++) {
- buffer[i] = 'X';
- }
- buffer[kBufferSize - 2] = '\r';
- buffer[kBufferSize - 1] = '\n';
- client->Send(buffer, kBufferSize);
-
- // Add empty body to request.
- const char* content_length_zero_header = "Content-Length:0\r\n";
- client->Send(content_length_zero_header,
- StrLength(content_length_zero_header));
- client->Send("\r\n", 2);
-
- // Wait until data is received.
- server->Join();
-
- // Check for empty body.
- CHECK(server->body() == NULL);
-
- // Close the client before the server to avoid TIME_WAIT issues.
- client->Shutdown();
- delete client;
- delete server;
-}
-
-
// Test for issue http://code.google.com/p/v8/issues/detail?id=289.
// Make sure that DebugGetLoadedScripts doesn't return scripts
// with disposed external source.
@@ -6013,12 +5904,13 @@
TEST(DebugGetLoadedScripts) {
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
env.ExposeDebug();
EmptyExternalStringResource source_ext_str;
- v8::Local<v8::String> source = v8::String::NewExternal(&source_ext_str);
+ v8::Local<v8::String> source =
+ v8::String::NewExternal(env->GetIsolate(), &source_ext_str);
v8::Handle<v8::Script> evil_script(v8::Script::Compile(source));
// "use" evil_script to make the compiler happy.
(void) evil_script;
@@ -6040,14 +5932,18 @@
i::FLAG_allow_natives_syntax = allow_natives_syntax;
// Some scripts are retrieved - at least the number of native scripts.
- CHECK_GT((*env)->Global()->Get(v8::String::New("count"))->Int32Value(), 8);
+ CHECK_GT((*env)
+ ->Global()
+ ->Get(v8::String::NewFromUtf8(env->GetIsolate(), "count"))
+ ->Int32Value(),
+ 8);
}
// Test script break points set on lines.
TEST(ScriptNameAndData) {
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
env.ExposeDebug();
// Create functions for retrieving script name and data for the function on
@@ -6055,79 +5951,70 @@
frame_script_name = CompileFunction(&env,
frame_script_name_source,
"frame_script_name");
- frame_script_data = CompileFunction(&env,
- frame_script_data_source,
- "frame_script_data");
- compiled_script_data = CompileFunction(&env,
- compiled_script_data_source,
- "compiled_script_data");
- v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
- v8::Undefined());
+ v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount);
// Test function source.
- v8::Local<v8::String> script = v8::String::New(
- "function f() {\n"
- " debugger;\n"
- "}\n");
+ v8::Local<v8::String> script = v8::String::NewFromUtf8(env->GetIsolate(),
+ "function f() {\n"
+ " debugger;\n"
+ "}\n");
- v8::ScriptOrigin origin1 = v8::ScriptOrigin(v8::String::New("name"));
+ v8::ScriptOrigin origin1 =
+ v8::ScriptOrigin(v8::String::NewFromUtf8(env->GetIsolate(), "name"));
v8::Handle<v8::Script> script1 = v8::Script::Compile(script, &origin1);
- script1->SetData(v8::String::New("data"));
script1->Run();
v8::Local<v8::Function> f;
- f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));
+ f = v8::Local<v8::Function>::Cast(
+ env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f")));
f->Call(env->Global(), 0, NULL);
CHECK_EQ(1, break_point_hit_count);
CHECK_EQ("name", last_script_name_hit);
- CHECK_EQ("data", last_script_data_hit);
// Compile the same script again without setting data. As the compilation
// cache is disabled when debugging expect the data to be missing.
v8::Script::Compile(script, &origin1)->Run();
- f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));
+ f = v8::Local<v8::Function>::Cast(
+ env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f")));
f->Call(env->Global(), 0, NULL);
CHECK_EQ(2, break_point_hit_count);
CHECK_EQ("name", last_script_name_hit);
- CHECK_EQ("", last_script_data_hit); // Undefined results in empty string.
- v8::Local<v8::String> data_obj_source = v8::String::New(
- "({ a: 'abc',\n"
- " b: 123,\n"
- " toString: function() { return this.a + ' ' + this.b; }\n"
- "})\n");
- v8::Local<v8::Value> data_obj = v8::Script::Compile(data_obj_source)->Run();
- v8::ScriptOrigin origin2 = v8::ScriptOrigin(v8::String::New("new name"));
+ v8::Local<v8::String> data_obj_source = v8::String::NewFromUtf8(
+ env->GetIsolate(),
+ "({ a: 'abc',\n"
+ " b: 123,\n"
+ " toString: function() { return this.a + ' ' + this.b; }\n"
+ "})\n");
+ v8::Script::Compile(data_obj_source)->Run();
+ v8::ScriptOrigin origin2 =
+ v8::ScriptOrigin(v8::String::NewFromUtf8(env->GetIsolate(), "new name"));
v8::Handle<v8::Script> script2 = v8::Script::Compile(script, &origin2);
script2->Run();
- script2->SetData(data_obj->ToString());
- f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));
+ f = v8::Local<v8::Function>::Cast(
+ env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f")));
f->Call(env->Global(), 0, NULL);
CHECK_EQ(3, break_point_hit_count);
CHECK_EQ("new name", last_script_name_hit);
- CHECK_EQ("abc 123", last_script_data_hit);
- v8::Handle<v8::Script> script3 =
- v8::Script::Compile(script, &origin2, NULL,
- v8::String::New("in compile"));
- CHECK_EQ("in compile", last_script_data_hit);
+ v8::Handle<v8::Script> script3 = v8::Script::Compile(script, &origin2);
script3->Run();
- f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));
+ f = v8::Local<v8::Function>::Cast(
+ env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f")));
f->Call(env->Global(), 0, NULL);
CHECK_EQ(4, break_point_hit_count);
- CHECK_EQ("in compile", last_script_data_hit);
}
-static v8::Persistent<v8::Context> expected_context;
+static v8::Handle<v8::Context> expected_context;
static v8::Handle<v8::Value> expected_context_data;
// Check that the expected context is the one generating the debug event.
static void ContextCheckMessageHandler(const v8::Debug::Message& message) {
CHECK(message.GetEventContext() == expected_context);
- CHECK(message.GetEventContext()->GetData()->StrictEquals(
+ CHECK(message.GetEventContext()->GetEmbedderData(0)->StrictEquals(
expected_context_data));
message_handler_hit_count++;
@@ -6146,30 +6033,31 @@
// Checks that this data is set correctly and that when the debug message
// handler is called the expected context is the one active.
TEST(ContextData) {
- v8::HandleScope scope;
-
- v8::Debug::SetMessageHandler2(ContextCheckMessageHandler);
+ v8::Isolate* isolate = CcTest::isolate();
+ v8::HandleScope scope(isolate);
// Create two contexts.
- v8::Persistent<v8::Context> context_1;
- v8::Persistent<v8::Context> context_2;
+ v8::Handle<v8::Context> context_1;
+ v8::Handle<v8::Context> context_2;
v8::Handle<v8::ObjectTemplate> global_template =
v8::Handle<v8::ObjectTemplate>();
v8::Handle<v8::Value> global_object = v8::Handle<v8::Value>();
- context_1 = v8::Context::New(NULL, global_template, global_object);
- context_2 = v8::Context::New(NULL, global_template, global_object);
+ context_1 = v8::Context::New(isolate, NULL, global_template, global_object);
+ context_2 = v8::Context::New(isolate, NULL, global_template, global_object);
+
+ v8::Debug::SetMessageHandler(ContextCheckMessageHandler);
// Default data value is undefined.
- CHECK(context_1->GetData()->IsUndefined());
- CHECK(context_2->GetData()->IsUndefined());
+ CHECK(context_1->GetEmbedderData(0)->IsUndefined());
+ CHECK(context_2->GetEmbedderData(0)->IsUndefined());
// Set and check different data values.
- v8::Handle<v8::String> data_1 = v8::String::New("1");
- v8::Handle<v8::String> data_2 = v8::String::New("2");
- context_1->SetData(data_1);
- context_2->SetData(data_2);
- CHECK(context_1->GetData()->StrictEquals(data_1));
- CHECK(context_2->GetData()->StrictEquals(data_2));
+ v8::Handle<v8::String> data_1 = v8::String::NewFromUtf8(isolate, "1");
+ v8::Handle<v8::String> data_2 = v8::String::NewFromUtf8(isolate, "2");
+ context_1->SetEmbedderData(0, data_1);
+ context_2->SetEmbedderData(0, data_2);
+ CHECK(context_1->GetEmbedderData(0)->StrictEquals(data_1));
+ CHECK(context_2->GetEmbedderData(0)->StrictEquals(data_2));
// Simple test function which causes a break.
const char* source = "function f() { debugger; }";
@@ -6179,7 +6067,7 @@
v8::Context::Scope context_scope(context_1);
expected_context = context_1;
expected_context_data = data_1;
- v8::Local<v8::Function> f = CompileFunction(source, "f");
+ v8::Local<v8::Function> f = CompileFunction(isolate, source, "f");
f->Call(context_1->Global(), 0, NULL);
}
@@ -6189,14 +6077,14 @@
v8::Context::Scope context_scope(context_2);
expected_context = context_2;
expected_context_data = data_2;
- v8::Local<v8::Function> f = CompileFunction(source, "f");
+ v8::Local<v8::Function> f = CompileFunction(isolate, source, "f");
f->Call(context_2->Global(), 0, NULL);
}
// Two times compile event and two times break event.
CHECK_GT(message_handler_hit_count, 4);
- v8::Debug::SetMessageHandler2(NULL);
+ v8::Debug::SetMessageHandler(NULL);
CheckDebuggerUnloaded();
}
@@ -6208,7 +6096,7 @@
if (message.IsEvent() && message.GetEvent() == v8::Break) {
message_handler_break_hit_count++;
if (message_handler_break_hit_count == 1) {
- v8::Debug::DebugBreak();
+ v8::Debug::DebugBreak(message.GetIsolate());
}
}
@@ -6222,18 +6110,18 @@
// Test that a debug break can be scheduled while in a message handler.
TEST(DebugBreakInMessageHandler) {
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
- v8::Debug::SetMessageHandler2(DebugBreakMessageHandler);
+ v8::Debug::SetMessageHandler(DebugBreakMessageHandler);
// Test functions.
const char* script = "function f() { debugger; g(); } function g() { }";
CompileRun(script);
- v8::Local<v8::Function> f =
- v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));
- v8::Local<v8::Function> g =
- v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("g")));
+ v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast(
+ env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f")));
+ v8::Local<v8::Function> g = v8::Local<v8::Function>::Cast(
+ env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "g")));
// Call f then g. The debugger statement in f will casue a break which will
// cause another break.
@@ -6249,10 +6137,9 @@
// Debug event handler which gets the function on the top frame and schedules a
// break a number of times.
static void DebugEventDebugBreak(
- v8::DebugEvent event,
- v8::Handle<v8::Object> exec_state,
- v8::Handle<v8::Object> event_data,
- v8::Handle<v8::Value> data) {
+ const v8::Debug::EventDetails& event_details) {
+ v8::DebugEvent event = event_details.GetEvent();
+ v8::Handle<v8::Object> exec_state = event_details.GetExecutionState();
if (event == v8::Break) {
break_point_hit_count++;
@@ -6261,7 +6148,9 @@
if (!frame_function_name.IsEmpty()) {
// Get the name of the function.
const int argc = 2;
- v8::Handle<v8::Value> argv[argc] = { exec_state, v8::Integer::New(0) };
+ v8::Handle<v8::Value> argv[argc] = {
+ exec_state, v8::Integer::New(CcTest::isolate(), 0)
+ };
v8::Handle<v8::Value> result = frame_function_name->Call(exec_state,
argc, argv);
if (result->IsUndefined()) {
@@ -6269,13 +6158,13 @@
} else {
CHECK(result->IsString());
v8::Handle<v8::String> function_name(result->ToString());
- function_name->WriteAscii(last_function_hit);
+ function_name->WriteUtf8(last_function_hit);
}
}
// Keep forcing breaks.
if (break_point_hit_count < 20) {
- v8::Debug::DebugBreak();
+ v8::Debug::DebugBreak(CcTest::isolate());
}
}
}
@@ -6283,8 +6172,8 @@
TEST(RegExpDebugBreak) {
// This test only applies to native regexps.
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
// Create a function for checking the function when hitting a break point.
frame_function_name = CompileFunction(&env,
@@ -6297,14 +6186,15 @@
"var sourceLineBeginningSkip = /^(?:[ \\v\\h]*(?:\\/\\*.*?\\*\\/)*)*/;\n"
"function f(s) { return s.match(sourceLineBeginningSkip)[0].length; }";
- v8::Local<v8::Function> f = CompileFunction(script, "f");
+ v8::Local<v8::Function> f = CompileFunction(env->GetIsolate(), script, "f");
const int argc = 1;
- v8::Handle<v8::Value> argv[argc] = { v8::String::New(" /* xxx */ a=0;") };
+ v8::Handle<v8::Value> argv[argc] = {
+ v8::String::NewFromUtf8(env->GetIsolate(), " /* xxx */ a=0;")};
v8::Local<v8::Value> result = f->Call(env->Global(), argc, argv);
CHECK_EQ(12, result->Int32Value());
v8::Debug::SetDebugEventListener(DebugEventDebugBreak);
- v8::Debug::DebugBreak();
+ v8::Debug::DebugBreak(env->GetIsolate());
result = f->Call(env->Global(), argc, argv);
// Check that there was only one break event. Matching RegExp should not
@@ -6316,20 +6206,25 @@
// Common part of EvalContextData and NestedBreakEventContextData tests.
-static void ExecuteScriptForContextCheck() {
+static void ExecuteScriptForContextCheck(
+ v8::Debug::MessageHandler message_handler) {
// Create a context.
- v8::Persistent<v8::Context> context_1;
+ v8::Handle<v8::Context> context_1;
v8::Handle<v8::ObjectTemplate> global_template =
v8::Handle<v8::ObjectTemplate>();
- context_1 = v8::Context::New(NULL, global_template);
+ context_1 =
+ v8::Context::New(CcTest::isolate(), NULL, global_template);
+
+ v8::Debug::SetMessageHandler(message_handler);
// Default data value is undefined.
- CHECK(context_1->GetData()->IsUndefined());
+ CHECK(context_1->GetEmbedderData(0)->IsUndefined());
// Set and check a data value.
- v8::Handle<v8::String> data_1 = v8::String::New("1");
- context_1->SetData(data_1);
- CHECK(context_1->GetData()->StrictEquals(data_1));
+ v8::Handle<v8::String> data_1 =
+ v8::String::NewFromUtf8(CcTest::isolate(), "1");
+ context_1->SetEmbedderData(0, data_1);
+ CHECK(context_1->GetEmbedderData(0)->StrictEquals(data_1));
// Simple test function with eval that causes a break.
const char* source = "function f() { eval('debugger;'); }";
@@ -6339,9 +6234,11 @@
v8::Context::Scope context_scope(context_1);
expected_context = context_1;
expected_context_data = data_1;
- v8::Local<v8::Function> f = CompileFunction(source, "f");
+ v8::Local<v8::Function> f = CompileFunction(CcTest::isolate(), source, "f");
f->Call(context_1->Global(), 0, NULL);
}
+
+ v8::Debug::SetMessageHandler(NULL);
}
@@ -6350,14 +6247,12 @@
// break event in an eval statement the expected context is the one returned by
// Message.GetEventContext.
TEST(EvalContextData) {
- v8::HandleScope scope;
- v8::Debug::SetMessageHandler2(ContextCheckMessageHandler);
+ v8::HandleScope scope(CcTest::isolate());
- ExecuteScriptForContextCheck();
+ ExecuteScriptForContextCheck(ContextCheckMessageHandler);
// One time compile event and one time break event.
CHECK_GT(message_handler_hit_count, 2);
- v8::Debug::SetMessageHandler2(NULL);
CheckDebuggerUnloaded();
}
@@ -6370,7 +6265,7 @@
static void DebugEvalContextCheckMessageHandler(
const v8::Debug::Message& message) {
CHECK(message.GetEventContext() == expected_context);
- CHECK(message.GetEventContext()->GetData()->StrictEquals(
+ CHECK(message.GetEventContext()->GetEmbedderData(0)->StrictEquals(
expected_context_data));
message_handler_hit_count++;
@@ -6378,6 +6273,7 @@
v8::String::Value json(message.GetJSON());
Utf16ToAscii(*json, json.length(), print_buffer);
+ v8::Isolate* isolate = message.GetIsolate();
if (IsBreakEventMessage(print_buffer)) {
break_count++;
if (!sent_eval) {
@@ -6393,7 +6289,8 @@
"\"global\":true,\"disable_break\":false}}";
// Send evaluate command.
- v8::Debug::SendCommand(buffer, AsciiToUtf16(eval_command, buffer));
+ v8::Debug::SendCommand(
+ isolate, buffer, AsciiToUtf16(eval_command, buffer));
return;
} else {
// It's a break event caused by the evaluation request above.
@@ -6413,116 +6310,21 @@
// Tests that context returned for break event is correct when the event occurs
// in 'evaluate' debugger request.
TEST(NestedBreakEventContextData) {
- v8::HandleScope scope;
+ v8::HandleScope scope(CcTest::isolate());
break_count = 0;
message_handler_hit_count = 0;
- v8::Debug::SetMessageHandler2(DebugEvalContextCheckMessageHandler);
- ExecuteScriptForContextCheck();
+ ExecuteScriptForContextCheck(DebugEvalContextCheckMessageHandler);
// One time compile event and two times break event.
CHECK_GT(message_handler_hit_count, 3);
// One break from the source and another from the evaluate request.
CHECK_EQ(break_count, 2);
- v8::Debug::SetMessageHandler2(NULL);
CheckDebuggerUnloaded();
}
-// Debug event listener which counts the script collected events.
-int script_collected_count = 0;
-static void DebugEventScriptCollectedEvent(v8::DebugEvent event,
- v8::Handle<v8::Object> exec_state,
- v8::Handle<v8::Object> event_data,
- v8::Handle<v8::Value> data) {
- // Count the number of breaks.
- if (event == v8::ScriptCollected) {
- script_collected_count++;
- }
-}
-
-
-// Test that scripts collected are reported through the debug event listener.
-TEST(ScriptCollectedEvent) {
- v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug();
- break_point_hit_count = 0;
- script_collected_count = 0;
- v8::HandleScope scope;
- DebugLocalContext env;
-
- // Request the loaded scripts to initialize the debugger script cache.
- debug->GetLoadedScripts();
-
- // Do garbage collection to ensure that only the script in this test will be
- // collected afterwards.
- HEAP->CollectAllGarbage(Heap::kNoGCFlags);
-
- script_collected_count = 0;
- v8::Debug::SetDebugEventListener(DebugEventScriptCollectedEvent,
- v8::Undefined());
- {
- v8::Script::Compile(v8::String::New("eval('a=1')"))->Run();
- v8::Script::Compile(v8::String::New("eval('a=2')"))->Run();
- }
-
- // Do garbage collection to collect the script above which is no longer
- // referenced.
- HEAP->CollectAllGarbage(Heap::kNoGCFlags);
-
- CHECK_EQ(2, script_collected_count);
-
- v8::Debug::SetDebugEventListener(NULL);
- CheckDebuggerUnloaded();
-}
-
-
-// Debug event listener which counts the script collected events.
-int script_collected_message_count = 0;
-static void ScriptCollectedMessageHandler(const v8::Debug::Message& message) {
- // Count the number of scripts collected.
- if (message.IsEvent() && message.GetEvent() == v8::ScriptCollected) {
- script_collected_message_count++;
- v8::Handle<v8::Context> context = message.GetEventContext();
- CHECK(context.IsEmpty());
- }
-}
-
-
-// Test that GetEventContext doesn't fail and return empty handle for
-// ScriptCollected events.
-TEST(ScriptCollectedEventContext) {
- v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug();
- script_collected_message_count = 0;
- v8::HandleScope scope;
-
- { // Scope for the DebugLocalContext.
- DebugLocalContext env;
-
- // Request the loaded scripts to initialize the debugger script cache.
- debug->GetLoadedScripts();
-
- // Do garbage collection to ensure that only the script in this test will be
- // collected afterwards.
- HEAP->CollectAllGarbage(Heap::kNoGCFlags);
-
- v8::Debug::SetMessageHandler2(ScriptCollectedMessageHandler);
- {
- v8::Script::Compile(v8::String::New("eval('a=1')"))->Run();
- v8::Script::Compile(v8::String::New("eval('a=2')"))->Run();
- }
- }
-
- // Do garbage collection to collect the script above which is no longer
- // referenced.
- HEAP->CollectAllGarbage(Heap::kNoGCFlags);
-
- CHECK_EQ(2, script_collected_message_count);
-
- v8::Debug::SetMessageHandler2(NULL);
-}
-
-
// Debug event listener which counts the after compile events.
int after_compile_message_count = 0;
static void AfterCompileMessageHandler(const v8::Debug::Message& message) {
@@ -6540,21 +6342,23 @@
// Tests that after compile event is sent as many times as there are scripts
// compiled.
TEST(AfterCompileMessageWhenMessageHandlerIsReset) {
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
after_compile_message_count = 0;
const char* script = "var a=1";
- v8::Debug::SetMessageHandler2(AfterCompileMessageHandler);
- v8::Script::Compile(v8::String::New(script))->Run();
- v8::Debug::SetMessageHandler2(NULL);
+ v8::Debug::SetMessageHandler(AfterCompileMessageHandler);
+ v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), script))
+ ->Run();
+ v8::Debug::SetMessageHandler(NULL);
- v8::Debug::SetMessageHandler2(AfterCompileMessageHandler);
- v8::Debug::DebugBreak();
- v8::Script::Compile(v8::String::New(script))->Run();
+ v8::Debug::SetMessageHandler(AfterCompileMessageHandler);
+ v8::Debug::DebugBreak(env->GetIsolate());
+ v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), script))
+ ->Run();
// Setting listener to NULL should cause debugger unload.
- v8::Debug::SetMessageHandler2(NULL);
+ v8::Debug::SetMessageHandler(NULL);
CheckDebuggerUnloaded();
// Compilation cache should be disabled when debugger is active.
@@ -6562,25 +6366,80 @@
}
+// Syntax error event handler which counts a number of events.
+int compile_error_event_count = 0;
+
+static void CompileErrorEventCounterClear() {
+ compile_error_event_count = 0;
+}
+
+static void CompileErrorEventCounter(
+ const v8::Debug::EventDetails& event_details) {
+ v8::DebugEvent event = event_details.GetEvent();
+
+ if (event == v8::CompileError) {
+ compile_error_event_count++;
+ }
+}
+
+
+// Tests that syntax error event is sent as many times as there are scripts
+// with syntax error compiled.
+TEST(SyntaxErrorMessageOnSyntaxException) {
+ DebugLocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
+
+ // For this test, we want to break on uncaught exceptions:
+ ChangeBreakOnException(false, true);
+
+ v8::Debug::SetDebugEventListener(CompileErrorEventCounter);
+
+ CompileErrorEventCounterClear();
+
+ // Check initial state.
+ CHECK_EQ(0, compile_error_event_count);
+
+ // Throws SyntaxError: Unexpected end of input
+ v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), "+++"));
+ CHECK_EQ(1, compile_error_event_count);
+
+ v8::Script::Compile(
+ v8::String::NewFromUtf8(env->GetIsolate(), "/sel\\/: \\"));
+ CHECK_EQ(2, compile_error_event_count);
+
+ v8::Script::Compile(
+ v8::String::NewFromUtf8(env->GetIsolate(), "JSON.parse('1234:')"));
+ CHECK_EQ(2, compile_error_event_count);
+
+ v8::Script::Compile(
+ v8::String::NewFromUtf8(env->GetIsolate(), "new RegExp('/\\/\\\\');"));
+ CHECK_EQ(2, compile_error_event_count);
+
+ v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), "throw 1;"));
+ CHECK_EQ(2, compile_error_event_count);
+}
+
+
// Tests that break event is sent when message handler is reset.
TEST(BreakMessageWhenMessageHandlerIsReset) {
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
after_compile_message_count = 0;
const char* script = "function f() {};";
- v8::Debug::SetMessageHandler2(AfterCompileMessageHandler);
- v8::Script::Compile(v8::String::New(script))->Run();
- v8::Debug::SetMessageHandler2(NULL);
+ v8::Debug::SetMessageHandler(AfterCompileMessageHandler);
+ v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), script))
+ ->Run();
+ v8::Debug::SetMessageHandler(NULL);
- v8::Debug::SetMessageHandler2(AfterCompileMessageHandler);
- v8::Debug::DebugBreak();
- v8::Local<v8::Function> f =
- v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));
+ v8::Debug::SetMessageHandler(AfterCompileMessageHandler);
+ v8::Debug::DebugBreak(env->GetIsolate());
+ v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast(
+ env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f")));
f->Call(env->Global(), 0, NULL);
// Setting message handler to NULL should cause debugger unload.
- v8::Debug::SetMessageHandler2(NULL);
+ v8::Debug::SetMessageHandler(NULL);
CheckDebuggerUnloaded();
// Compilation cache should be disabled when debugger is active.
@@ -6599,8 +6458,8 @@
// Tests that exception event is sent when message handler is reset.
TEST(ExceptionMessageWhenMessageHandlerIsReset) {
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
// For this test, we want to break on uncaught exceptions:
ChangeBreakOnException(false, true);
@@ -6608,17 +6467,18 @@
exception_event_count = 0;
const char* script = "function f() {throw new Error()};";
- v8::Debug::SetMessageHandler2(AfterCompileMessageHandler);
- v8::Script::Compile(v8::String::New(script))->Run();
- v8::Debug::SetMessageHandler2(NULL);
+ v8::Debug::SetMessageHandler(AfterCompileMessageHandler);
+ v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), script))
+ ->Run();
+ v8::Debug::SetMessageHandler(NULL);
- v8::Debug::SetMessageHandler2(ExceptionMessageHandler);
- v8::Local<v8::Function> f =
- v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));
+ v8::Debug::SetMessageHandler(ExceptionMessageHandler);
+ v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast(
+ env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f")));
f->Call(env->Global(), 0, NULL);
// Setting message handler to NULL should cause debugger unload.
- v8::Debug::SetMessageHandler2(NULL);
+ v8::Debug::SetMessageHandler(NULL);
CheckDebuggerUnloaded();
CHECK_EQ(1, exception_event_count);
@@ -6628,66 +6488,61 @@
// Tests after compile event is sent when there are some provisional
// breakpoints out of the scripts lines range.
TEST(ProvisionalBreakpointOnLineOutOfRange) {
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
env.ExposeDebug();
const char* script = "function f() {};";
const char* resource_name = "test_resource";
// Set a couple of provisional breakpoint on lines out of the script lines
// range.
- int sbp1 = SetScriptBreakPointByNameFromJS(resource_name, 3,
- -1 /* no column */);
- int sbp2 = SetScriptBreakPointByNameFromJS(resource_name, 5, 5);
+ int sbp1 = SetScriptBreakPointByNameFromJS(env->GetIsolate(), resource_name,
+ 3, -1 /* no column */);
+ int sbp2 =
+ SetScriptBreakPointByNameFromJS(env->GetIsolate(), resource_name, 5, 5);
after_compile_message_count = 0;
- v8::Debug::SetMessageHandler2(AfterCompileMessageHandler);
+ v8::Debug::SetMessageHandler(AfterCompileMessageHandler);
v8::ScriptOrigin origin(
- v8::String::New(resource_name),
- v8::Integer::New(10),
- v8::Integer::New(1));
+ v8::String::NewFromUtf8(env->GetIsolate(), resource_name),
+ v8::Integer::New(env->GetIsolate(), 10),
+ v8::Integer::New(env->GetIsolate(), 1));
// Compile a script whose first line number is greater than the breakpoints'
// lines.
- v8::Script::Compile(v8::String::New(script), &origin)->Run();
+ v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), script),
+ &origin)->Run();
// If the script is compiled successfully there is exactly one after compile
// event. In case of an exception in debugger code after compile event is not
// sent.
CHECK_EQ(1, after_compile_message_count);
- ClearBreakPointFromJS(sbp1);
- ClearBreakPointFromJS(sbp2);
- v8::Debug::SetMessageHandler2(NULL);
+ ClearBreakPointFromJS(env->GetIsolate(), sbp1);
+ ClearBreakPointFromJS(env->GetIsolate(), sbp2);
+ v8::Debug::SetMessageHandler(NULL);
}
static void BreakMessageHandler(const v8::Debug::Message& message) {
- i::Isolate* isolate = i::Isolate::Current();
+ i::Isolate* isolate = CcTest::i_isolate();
if (message.IsEvent() && message.GetEvent() == v8::Break) {
// Count the number of breaks.
break_point_hit_count++;
- v8::HandleScope scope;
+ i::HandleScope scope(isolate);
message.GetJSON();
SendContinueCommand();
} else if (message.IsEvent() && message.GetEvent() == v8::AfterCompile) {
- v8::HandleScope scope;
+ i::HandleScope scope(isolate);
- bool is_debug_break = isolate->stack_guard()->IsDebugBreak();
- // Force DebugBreak flag while serializer is working.
- isolate->stack_guard()->DebugBreak();
+ int current_count = break_point_hit_count;
// Force serialization to trigger some internal JS execution.
message.GetJSON();
- // Restore previous state.
- if (is_debug_break) {
- isolate->stack_guard()->DebugBreak();
- } else {
- isolate->stack_guard()->Continue(i::DEBUGBREAK);
- }
+ CHECK_EQ(current_count, break_point_hit_count);
}
}
@@ -6695,14 +6550,14 @@
// Test that if DebugBreak is forced it is ignored when code from
// debug-delay.js is executed.
TEST(NoDebugBreakInAfterCompileMessageHandler) {
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
// Register a debug event listener which sets the break flag and counts.
- v8::Debug::SetMessageHandler2(BreakMessageHandler);
+ v8::Debug::SetMessageHandler(BreakMessageHandler);
// Set the debug break flag.
- v8::Debug::DebugBreak();
+ v8::Debug::DebugBreak(env->GetIsolate());
// Create a function for testing stepping.
const char* src = "function f() { eval('var x = 10;'); } ";
@@ -6712,13 +6567,13 @@
CHECK_EQ(1, break_point_hit_count);
// Set the debug break flag again.
- v8::Debug::DebugBreak();
+ v8::Debug::DebugBreak(env->GetIsolate());
f->Call(env->Global(), 0, NULL);
// There should be one more break event when the script is evaluated in 'f'.
CHECK_EQ(2, break_point_hit_count);
// Get rid of the debug message handler.
- v8::Debug::SetMessageHandler2(NULL);
+ v8::Debug::SetMessageHandler(NULL);
CheckDebuggerUnloaded();
}
@@ -6726,17 +6581,19 @@
static int counting_message_handler_counter;
static void CountingMessageHandler(const v8::Debug::Message& message) {
- counting_message_handler_counter++;
+ if (message.IsResponse()) counting_message_handler_counter++;
}
+
// Test that debug messages get processed when ProcessDebugMessages is called.
TEST(ProcessDebugMessages) {
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::Isolate* isolate = env->GetIsolate();
+ v8::HandleScope scope(isolate);
counting_message_handler_counter = 0;
- v8::Debug::SetMessageHandler2(CountingMessageHandler);
+ v8::Debug::SetMessageHandler(CountingMessageHandler);
const int kBufferSize = 1000;
uint16_t buffer[kBufferSize];
@@ -6746,7 +6603,8 @@
"\"command\":\"scripts\"}";
// Send scripts command.
- v8::Debug::SendCommand(buffer, AsciiToUtf16(scripts_command, buffer));
+ v8::Debug::SendCommand(
+ isolate, buffer, AsciiToUtf16(scripts_command, buffer));
CHECK_EQ(0, counting_message_handler_counter);
v8::Debug::ProcessDebugMessages();
@@ -6755,15 +6613,101 @@
counting_message_handler_counter = 0;
- v8::Debug::SendCommand(buffer, AsciiToUtf16(scripts_command, buffer));
- v8::Debug::SendCommand(buffer, AsciiToUtf16(scripts_command, buffer));
+ v8::Debug::SendCommand(
+ isolate, buffer, AsciiToUtf16(scripts_command, buffer));
+ v8::Debug::SendCommand(
+ isolate, buffer, AsciiToUtf16(scripts_command, buffer));
CHECK_EQ(0, counting_message_handler_counter);
v8::Debug::ProcessDebugMessages();
// At least two messages should come
CHECK_GE(counting_message_handler_counter, 2);
// Get rid of the debug message handler.
- v8::Debug::SetMessageHandler2(NULL);
+ v8::Debug::SetMessageHandler(NULL);
+ CheckDebuggerUnloaded();
+}
+
+
+class SendCommandThread;
+static SendCommandThread* send_command_thread_ = NULL;
+
+
+class SendCommandThread : public v8::base::Thread {
+ public:
+ explicit SendCommandThread(v8::Isolate* isolate)
+ : Thread(Options("SendCommandThread")),
+ semaphore_(0),
+ isolate_(isolate) {}
+
+ static void CountingAndSignallingMessageHandler(
+ const v8::Debug::Message& message) {
+ if (message.IsResponse()) {
+ counting_message_handler_counter++;
+ send_command_thread_->semaphore_.Signal();
+ }
+ }
+
+ virtual void Run() {
+ semaphore_.Wait();
+ const int kBufferSize = 1000;
+ uint16_t buffer[kBufferSize];
+ const char* scripts_command =
+ "{\"seq\":0,"
+ "\"type\":\"request\","
+ "\"command\":\"scripts\"}";
+ int length = AsciiToUtf16(scripts_command, buffer);
+ // Send scripts command.
+
+ for (int i = 0; i < 20; i++) {
+ v8::base::ElapsedTimer timer;
+ timer.Start();
+ CHECK_EQ(i, counting_message_handler_counter);
+ // Queue debug message.
+ v8::Debug::SendCommand(isolate_, buffer, length);
+ // Wait for the message handler to pick up the response.
+ semaphore_.Wait();
+ i::PrintF("iteration %d took %f ms\n", i,
+ timer.Elapsed().InMillisecondsF());
+ }
+
+ v8::V8::TerminateExecution(isolate_);
+ }
+
+ void StartSending() { semaphore_.Signal(); }
+
+ private:
+ v8::base::Semaphore semaphore_;
+ v8::Isolate* isolate_;
+};
+
+
+static void StartSendingCommands(
+ const v8::FunctionCallbackInfo<v8::Value>& info) {
+ send_command_thread_->StartSending();
+}
+
+
+TEST(ProcessDebugMessagesThreaded) {
+ DebugLocalContext env;
+ v8::Isolate* isolate = env->GetIsolate();
+ v8::HandleScope scope(isolate);
+
+ counting_message_handler_counter = 0;
+
+ v8::Debug::SetMessageHandler(
+ SendCommandThread::CountingAndSignallingMessageHandler);
+ send_command_thread_ = new SendCommandThread(isolate);
+ send_command_thread_->Start();
+
+ v8::Handle<v8::FunctionTemplate> start =
+ v8::FunctionTemplate::New(isolate, StartSendingCommands);
+ env->Global()->Set(v8_str("start"), start->GetFunction());
+
+ CompileRun("start(); while (true) { }");
+
+ CHECK_EQ(20, counting_message_handler_counter);
+
+ v8::Debug::SetMessageHandler(NULL);
CheckDebuggerUnloaded();
}
@@ -6787,10 +6731,11 @@
// Test that debug messages get processed when ProcessDebugMessages is called.
TEST(Backtrace) {
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::Isolate* isolate = env->GetIsolate();
+ v8::HandleScope scope(isolate);
- v8::Debug::SetMessageHandler2(BacktraceData::MessageHandler);
+ v8::Debug::SetMessageHandler(BacktraceData::MessageHandler);
const int kBufferSize = 1000;
uint16_t buffer[kBufferSize];
@@ -6801,37 +6746,50 @@
// Check backtrace from ProcessDebugMessages.
BacktraceData::frame_counter = -10;
- v8::Debug::SendCommand(buffer, AsciiToUtf16(scripts_command, buffer));
+ v8::Debug::SendCommand(
+ isolate,
+ buffer,
+ AsciiToUtf16(scripts_command, buffer),
+ NULL);
v8::Debug::ProcessDebugMessages();
CHECK_EQ(BacktraceData::frame_counter, 0);
- v8::Handle<v8::String> void0 = v8::String::New("void(0)");
- v8::Handle<v8::Script> script = v8::Script::Compile(void0, void0);
+ v8::Handle<v8::String> void0 =
+ v8::String::NewFromUtf8(env->GetIsolate(), "void(0)");
+ v8::Handle<v8::Script> script = CompileWithOrigin(void0, void0);
// Check backtrace from "void(0)" script.
BacktraceData::frame_counter = -10;
- v8::Debug::SendCommand(buffer, AsciiToUtf16(scripts_command, buffer));
+ v8::Debug::SendCommand(
+ isolate,
+ buffer,
+ AsciiToUtf16(scripts_command, buffer),
+ NULL);
script->Run();
CHECK_EQ(BacktraceData::frame_counter, 1);
// Get rid of the debug message handler.
- v8::Debug::SetMessageHandler2(NULL);
+ v8::Debug::SetMessageHandler(NULL);
CheckDebuggerUnloaded();
}
TEST(GetMirror) {
- v8::HandleScope scope;
DebugLocalContext env;
- v8::Handle<v8::Value> obj = v8::Debug::GetMirror(v8::String::New("hodja"));
+ v8::Isolate* isolate = env->GetIsolate();
+ v8::HandleScope scope(isolate);
+ v8::Handle<v8::Value> obj =
+ v8::Debug::GetMirror(v8::String::NewFromUtf8(isolate, "hodja"));
+ v8::ScriptCompiler::Source source(v8_str(
+ "function runTest(mirror) {"
+ " return mirror.isString() && (mirror.length() == 5);"
+ "}"
+ ""
+ "runTest;"));
v8::Handle<v8::Function> run_test = v8::Handle<v8::Function>::Cast(
- v8::Script::New(
- v8::String::New(
- "function runTest(mirror) {"
- " return mirror.isString() && (mirror.length() == 5);"
- "}"
- ""
- "runTest;"))->Run());
+ v8::ScriptCompiler::CompileUnbound(isolate, &source)
+ ->BindToCurrentContext()
+ ->Run());
v8::Handle<v8::Value> result = run_test->Call(env->Global(), 1, &obj);
CHECK(result->IsTrue());
}
@@ -6839,8 +6797,8 @@
// Test that the debug break flag works with function.apply.
TEST(DebugBreakFunctionApply) {
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
// Create a function for testing breaking in apply.
v8::Local<v8::Function> foo = CompileFunction(
@@ -6854,7 +6812,7 @@
v8::Debug::SetDebugEventListener(DebugEventBreakMax);
// Set the debug break flag before calling the code using function.apply.
- v8::Debug::DebugBreak();
+ v8::Debug::DebugBreak(env->GetIsolate());
// Limit the number of debug breaks. This is a regression test for issue 493
// where this test would enter an infinite loop.
@@ -6876,17 +6834,17 @@
// Property getter that checks that current and calling contexts
// are both the debugee contexts.
-static v8::Handle<v8::Value> NamedGetterWithCallingContextCheck(
+static void NamedGetterWithCallingContextCheck(
v8::Local<v8::String> name,
- const v8::AccessorInfo& info) {
- CHECK_EQ(0, strcmp(*v8::String::AsciiValue(name), "a"));
- v8::Handle<v8::Context> current = v8::Context::GetCurrent();
+ const v8::PropertyCallbackInfo<v8::Value>& info) {
+ CHECK_EQ(0, strcmp(*v8::String::Utf8Value(name), "a"));
+ v8::Handle<v8::Context> current = info.GetIsolate()->GetCurrentContext();
CHECK(current == debugee_context);
CHECK(current != debugger_context);
- v8::Handle<v8::Context> calling = v8::Context::GetCalling();
+ v8::Handle<v8::Context> calling = info.GetIsolate()->GetCallingContext();
CHECK(calling == debugee_context);
CHECK(calling != debugger_context);
- return v8::Int32::New(1);
+ info.GetReturnValue().Set(1);
}
@@ -6894,18 +6852,17 @@
// an object with property 'a' == 1. If the property has custom accessor
// this handler will eventually invoke it.
static void DebugEventGetAtgumentPropertyValue(
- v8::DebugEvent event,
- v8::Handle<v8::Object> exec_state,
- v8::Handle<v8::Object> event_data,
- v8::Handle<v8::Value> data) {
+ const v8::Debug::EventDetails& event_details) {
+ v8::DebugEvent event = event_details.GetEvent();
+ v8::Handle<v8::Object> exec_state = event_details.GetExecutionState();
if (event == v8::Break) {
break_point_hit_count++;
- CHECK(debugger_context == v8::Context::GetCurrent());
- v8::Handle<v8::Function> func(v8::Function::Cast(*CompileRun(
+ CHECK(debugger_context == CcTest::isolate()->GetCurrentContext());
+ v8::Handle<v8::Function> func = v8::Handle<v8::Function>::Cast(CompileRun(
"(function(exec_state) {\n"
" return (exec_state.frame(0).argumentValue(0).property('a').\n"
" value().value() == 1);\n"
- "})")));
+ "})"));
const int argc = 1;
v8::Handle<v8::Value> argv[argc] = { exec_state };
v8::Handle<v8::Value> result = func->Call(exec_state, argc, argv);
@@ -6915,22 +6872,23 @@
TEST(CallingContextIsNotDebugContext) {
- v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug();
+ v8::internal::Debug* debug = CcTest::i_isolate()->debug();
// Create and enter a debugee context.
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::Isolate* isolate = env->GetIsolate();
+ v8::HandleScope scope(isolate);
env.ExposeDebug();
// Save handles to the debugger and debugee contexts to be used in
// NamedGetterWithCallingContextCheck.
- debugee_context = v8::Local<v8::Context>(*env);
+ debugee_context = env.context();
debugger_context = v8::Utils::ToLocal(debug->debug_context());
// Create object with 'a' property accessor.
- v8::Handle<v8::ObjectTemplate> named = v8::ObjectTemplate::New();
- named->SetAccessor(v8::String::New("a"),
+ v8::Handle<v8::ObjectTemplate> named = v8::ObjectTemplate::New(isolate);
+ named->SetAccessor(v8::String::NewFromUtf8(isolate, "a"),
NamedGetterWithCallingContextCheck);
- env->Global()->Set(v8::String::New("obj"),
+ env->Global()->Set(v8::String::NewFromUtf8(isolate, "obj"),
named->NewInstance());
// Register the debug event listener
@@ -6955,10 +6913,13 @@
TEST(DebugContextIsPreservedBetweenAccesses) {
- v8::HandleScope scope;
+ v8::HandleScope scope(CcTest::isolate());
+ v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount);
v8::Local<v8::Context> context1 = v8::Debug::GetDebugContext();
v8::Local<v8::Context> context2 = v8::Debug::GetDebugContext();
- CHECK_EQ(*context1, *context2);
+ CHECK(v8::Utils::OpenHandle(*context1).is_identical_to(
+ v8::Utils::OpenHandle(*context2)));
+ v8::Debug::SetDebugEventListener(NULL);
}
@@ -6968,16 +6929,18 @@
CHECK_EQ(expected_callback_data, details.GetCallbackData());
}
+
// Check that event details contain context where debug event occured.
TEST(DebugEventContext) {
- v8::HandleScope scope;
- expected_callback_data = v8::Int32::New(2010);
- v8::Debug::SetDebugEventListener2(DebugEventContextChecker,
+ v8::Isolate* isolate = CcTest::isolate();
+ v8::HandleScope scope(isolate);
+ expected_context = v8::Context::New(isolate);
+ expected_callback_data = v8::Int32::New(isolate, 2010);
+ v8::Debug::SetDebugEventListener(DebugEventContextChecker,
expected_callback_data);
- expected_context = v8::Context::New();
v8::Context::Scope context_scope(expected_context);
- v8::Script::Compile(v8::String::New("(function(){debugger;})();"))->Run();
- expected_context.Dispose();
+ v8::Script::Compile(
+ v8::String::NewFromUtf8(isolate, "(function(){debugger;})();"))->Run();
expected_context.Clear();
v8::Debug::SetDebugEventListener(NULL);
expected_context_data = v8::Handle<v8::Value>();
@@ -7000,9 +6963,10 @@
// Check that event details contain context where debug event occured.
TEST(DebugEventBreakData) {
- v8::HandleScope scope;
DebugLocalContext env;
- v8::Debug::SetDebugEventListener2(DebugEventBreakDataChecker);
+ v8::Isolate* isolate = env->GetIsolate();
+ v8::HandleScope scope(isolate);
+ v8::Debug::SetDebugEventListener(DebugEventBreakDataChecker);
TestClientData::constructor_call_counter = 0;
TestClientData::destructor_call_counter = 0;
@@ -7010,8 +6974,10 @@
expected_break_data = NULL;
was_debug_event_called = false;
was_debug_break_called = false;
- v8::Debug::DebugBreakForCommand();
- v8::Script::Compile(v8::String::New("(function(x){return x;})(1);"))->Run();
+ v8::Debug::DebugBreakForCommand(isolate, NULL);
+ v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(),
+ "(function(x){return x;})(1);"))
+ ->Run();
CHECK(was_debug_event_called);
CHECK(!was_debug_break_called);
@@ -7019,16 +6985,20 @@
expected_break_data = data1;
was_debug_event_called = false;
was_debug_break_called = false;
- v8::Debug::DebugBreakForCommand(data1);
- v8::Script::Compile(v8::String::New("(function(x){return x+1;})(1);"))->Run();
+ v8::Debug::DebugBreakForCommand(isolate, data1);
+ v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(),
+ "(function(x){return x+1;})(1);"))
+ ->Run();
CHECK(was_debug_event_called);
CHECK(!was_debug_break_called);
expected_break_data = NULL;
was_debug_event_called = false;
was_debug_break_called = false;
- v8::Debug::DebugBreak();
- v8::Script::Compile(v8::String::New("(function(x){return x+2;})(1);"))->Run();
+ v8::Debug::DebugBreak(isolate);
+ v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(),
+ "(function(x){return x+2;})(1);"))
+ ->Run();
CHECK(!was_debug_event_called);
CHECK(was_debug_break_called);
@@ -7036,9 +7006,11 @@
expected_break_data = data2;
was_debug_event_called = false;
was_debug_break_called = false;
- v8::Debug::DebugBreak();
- v8::Debug::DebugBreakForCommand(data2);
- v8::Script::Compile(v8::String::New("(function(x){return x+3;})(1);"))->Run();
+ v8::Debug::DebugBreak(isolate);
+ v8::Debug::DebugBreakForCommand(isolate, data2);
+ v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(),
+ "(function(x){return x+3;})(1);"))
+ ->Run();
CHECK(was_debug_event_called);
CHECK(was_debug_break_called);
@@ -7052,30 +7024,32 @@
static bool debug_event_break_deoptimize_done = false;
-static void DebugEventBreakDeoptimize(v8::DebugEvent event,
- v8::Handle<v8::Object> exec_state,
- v8::Handle<v8::Object> event_data,
- v8::Handle<v8::Value> data) {
+static void DebugEventBreakDeoptimize(
+ const v8::Debug::EventDetails& event_details) {
+ v8::DebugEvent event = event_details.GetEvent();
+ v8::Handle<v8::Object> exec_state = event_details.GetExecutionState();
if (event == v8::Break) {
if (!frame_function_name.IsEmpty()) {
// Get the name of the function.
const int argc = 2;
- v8::Handle<v8::Value> argv[argc] = { exec_state, v8::Integer::New(0) };
+ v8::Handle<v8::Value> argv[argc] = {
+ exec_state, v8::Integer::New(CcTest::isolate(), 0)
+ };
v8::Handle<v8::Value> result =
frame_function_name->Call(exec_state, argc, argv);
if (!result->IsUndefined()) {
char fn[80];
CHECK(result->IsString());
v8::Handle<v8::String> function_name(result->ToString());
- function_name->WriteAscii(fn);
+ function_name->WriteUtf8(fn);
if (strcmp(fn, "bar") == 0) {
- i::Deoptimizer::DeoptimizeAll();
+ i::Deoptimizer::DeoptimizeAll(CcTest::i_isolate());
debug_event_break_deoptimize_done = true;
}
}
}
- v8::Debug::DebugBreak();
+ v8::Debug::DebugBreak(CcTest::isolate());
}
}
@@ -7083,8 +7057,8 @@
// Test deoptimization when execution is broken using the debug break stack
// check interrupt.
TEST(DeoptimizeDuringDebugBreak) {
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
env.ExposeDebug();
// Create a function for checking the function when hitting a break point.
@@ -7098,15 +7072,16 @@
// This tests lazy deoptimization bailout for the stack check, as the first
// time in function bar when using debug break and no break points will be at
// the initial stack check.
- v8::Debug::SetDebugEventListener(DebugEventBreakDeoptimize,
- v8::Undefined());
+ v8::Debug::SetDebugEventListener(DebugEventBreakDeoptimize);
// Compile and run function bar which will optimize it for some flag settings.
- v8::Script::Compile(v8::String::New("function bar(){}; bar()"))->Run();
+ v8::Script::Compile(v8::String::NewFromUtf8(
+ env->GetIsolate(), "function bar(){}; bar()"))->Run();
// Set debug break and call bar again.
- v8::Debug::DebugBreak();
- v8::Script::Compile(v8::String::New("bar()"))->Run();
+ v8::Debug::DebugBreak(env->GetIsolate());
+ v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), "bar()"))
+ ->Run();
CHECK(debug_event_break_deoptimize_done);
@@ -7114,26 +7089,29 @@
}
-static void DebugEventBreakWithOptimizedStack(v8::DebugEvent event,
- v8::Handle<v8::Object> exec_state,
- v8::Handle<v8::Object> event_data,
- v8::Handle<v8::Value> data) {
+static void DebugEventBreakWithOptimizedStack(
+ const v8::Debug::EventDetails& event_details) {
+ v8::Isolate* isolate = event_details.GetEventContext()->GetIsolate();
+ v8::DebugEvent event = event_details.GetEvent();
+ v8::Handle<v8::Object> exec_state = event_details.GetExecutionState();
if (event == v8::Break) {
if (!frame_function_name.IsEmpty()) {
for (int i = 0; i < 2; i++) {
const int argc = 2;
- v8::Handle<v8::Value> argv[argc] = { exec_state, v8::Integer::New(i) };
+ v8::Handle<v8::Value> argv[argc] = {
+ exec_state, v8::Integer::New(isolate, i)
+ };
// Get the name of the function in frame i.
v8::Handle<v8::Value> result =
frame_function_name->Call(exec_state, argc, argv);
CHECK(result->IsString());
v8::Handle<v8::String> function_name(result->ToString());
- CHECK(function_name->Equals(v8::String::New("loop")));
+ CHECK(function_name->Equals(v8::String::NewFromUtf8(isolate, "loop")));
// Get the name of the first argument in frame i.
result = frame_argument_name->Call(exec_state, argc, argv);
CHECK(result->IsString());
v8::Handle<v8::String> argument_name(result->ToString());
- CHECK(argument_name->Equals(v8::String::New("count")));
+ CHECK(argument_name->Equals(v8::String::NewFromUtf8(isolate, "count")));
// Get the value of the first argument in frame i. If the
// funtion is optimized the value will be undefined, otherwise
// the value will be '1 - i'.
@@ -7146,7 +7124,7 @@
result = frame_local_name->Call(exec_state, argc, argv);
CHECK(result->IsString());
v8::Handle<v8::String> local_name(result->ToString());
- CHECK(local_name->Equals(v8::String::New("local")));
+ CHECK(local_name->Equals(v8::String::NewFromUtf8(isolate, "local")));
// Get the value of the first local variable. If the function
// is optimized the value will be undefined, otherwise it will
// be 42.
@@ -7161,17 +7139,15 @@
}
-static v8::Handle<v8::Value> ScheduleBreak(const v8::Arguments& args) {
- v8::Debug::SetDebugEventListener(DebugEventBreakWithOptimizedStack,
- v8::Undefined());
- v8::Debug::DebugBreak();
- return v8::Undefined();
+static void ScheduleBreak(const v8::FunctionCallbackInfo<v8::Value>& args) {
+ v8::Debug::SetDebugEventListener(DebugEventBreakWithOptimizedStack);
+ v8::Debug::DebugBreak(args.GetIsolate());
}
TEST(DebugBreakStackInspection) {
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
frame_function_name =
CompileFunction(&env, frame_function_name_source, "frame_function_name");
@@ -7186,7 +7162,7 @@
CompileFunction(&env, frame_local_value_source, "frame_local_value");
v8::Handle<v8::FunctionTemplate> schedule_break_template =
- v8::FunctionTemplate::New(ScheduleBreak);
+ v8::FunctionTemplate::New(env->GetIsolate(), ScheduleBreak);
v8::Handle<v8::Function> schedule_break =
schedule_break_template->GetFunction();
env->Global()->Set(v8_str("scheduleBreak"), schedule_break);
@@ -7197,7 +7173,7 @@
" if (count < 1) { scheduleBreak(); loop(count + 1); }"
"}"
"loop(0);";
- v8::Script::Compile(v8::String::New(src))->Run();
+ v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), src))->Run();
}
@@ -7211,9 +7187,9 @@
for (int i = 0; loop_bodies[i] != NULL; i++) {
// Perform a lazy deoptimization after various numbers of breaks
// have been hit.
- for (int j = 0; j < 11; j++) {
+ for (int j = 0; j < 7; j++) {
break_point_hit_count_deoptimize = j;
- if (j == 10) {
+ if (j == 6) {
break_point_hit_count_deoptimize = kBreaksPerTest;
}
@@ -7222,15 +7198,15 @@
terminate_after_max_break_point_hit = true;
EmbeddedVector<char, 1024> buffer;
- OS::SNPrintF(buffer,
- "function f() {%s%s%s}",
- loop_head, loop_bodies[i], loop_tail);
+ SNPrintF(buffer,
+ "function f() {%s%s%s}",
+ loop_head, loop_bodies[i], loop_tail);
// Function with infinite loop.
CompileRun(buffer.start());
// Set the debug break to enter the debugger as soon as possible.
- v8::Debug::DebugBreak();
+ v8::Debug::DebugBreak(CcTest::isolate());
// Call function with infinite loop.
CompileRun("f();");
@@ -7243,8 +7219,8 @@
TEST(DebugBreakLoop) {
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
// Register a debug event listener which sets the break flag and counts.
v8::Debug::SetDebugEventListener(DebugEventBreakMax);
@@ -7288,10 +7264,9 @@
v8::Local<v8::Script> inline_script;
-static void DebugBreakInlineListener(v8::DebugEvent event,
- v8::Handle<v8::Object> exec_state,
- v8::Handle<v8::Object> event_data,
- v8::Handle<v8::Value> data) {
+static void DebugBreakInlineListener(
+ const v8::Debug::EventDetails& event_details) {
+ v8::DebugEvent event = event_details.GetEvent();
if (event != v8::Break) return;
int expected_frame_count = 4;
@@ -7301,10 +7276,10 @@
i::Handle<i::Script> source_script = i::Handle<i::Script>(i::Script::cast(
i::JSFunction::cast(*compiled_script)->shared()->script()));
- int break_id = v8::internal::Isolate::Current()->debug()->break_id();
+ int break_id = CcTest::i_isolate()->debug()->break_id();
char script[128];
i::Vector<char> script_vector(script, sizeof(script));
- OS::SNPrintF(script_vector, "%%GetFrameCount(%d)", break_id);
+ SNPrintF(script_vector, "%%GetFrameCount(%d)", break_id);
v8::Local<v8::Value> result = CompileRun(script);
int frame_count = result->Int32Value();
@@ -7313,20 +7288,20 @@
for (int i = 0; i < frame_count; i++) {
// The 5. element in the returned array of GetFrameDetails contains the
// source position of that frame.
- OS::SNPrintF(script_vector, "%%GetFrameDetails(%d, %d)[5]", break_id, i);
+ SNPrintF(script_vector, "%%GetFrameDetails(%d, %d)[5]", break_id, i);
v8::Local<v8::Value> result = CompileRun(script);
CHECK_EQ(expected_line_number[i],
- i::GetScriptLineNumber(source_script, result->Int32Value()));
+ i::Script::GetLineNumber(source_script, result->Int32Value()));
}
v8::Debug::SetDebugEventListener(NULL);
- v8::V8::TerminateExecution();
+ v8::V8::TerminateExecution(CcTest::isolate());
}
TEST(DebugBreakInline) {
i::FLAG_allow_natives_syntax = true;
- v8::HandleScope scope;
DebugLocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
const char* source =
"function debug(b) { \n"
" if (b) debugger; \n"
@@ -7342,9 +7317,204 @@
"%OptimizeFunctionOnNextCall(g); \n"
"g(true);";
v8::Debug::SetDebugEventListener(DebugBreakInlineListener);
- inline_script = v8::Script::Compile(v8::String::New(source));
+ inline_script =
+ v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), source));
inline_script->Run();
}
-#endif // ENABLE_DEBUGGER_SUPPORT
+static void DebugEventStepNext(
+ const v8::Debug::EventDetails& event_details) {
+ v8::DebugEvent event = event_details.GetEvent();
+ if (event == v8::Break) {
+ PrepareStep(StepNext);
+ }
+}
+
+
+static void RunScriptInANewCFrame(const char* source) {
+ v8::TryCatch try_catch;
+ CompileRun(source);
+ CHECK(try_catch.HasCaught());
+}
+
+
+TEST(Regress131642) {
+ // Bug description:
+ // When doing StepNext through the first script, the debugger is not reset
+ // after exiting through exception. A flawed implementation enabling the
+ // debugger to step into Array.prototype.forEach breaks inside the callback
+ // for forEach in the second script under the assumption that we are in a
+ // recursive call. In an attempt to step out, we crawl the stack using the
+ // recorded frame pointer from the first script and fail when not finding it
+ // on the stack.
+ DebugLocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
+ v8::Debug::SetDebugEventListener(DebugEventStepNext);
+
+ // We step through the first script. It exits through an exception. We run
+ // this inside a new frame to record a different FP than the second script
+ // would expect.
+ const char* script_1 = "debugger; throw new Error();";
+ RunScriptInANewCFrame(script_1);
+
+ // The second script uses forEach.
+ const char* script_2 = "[0].forEach(function() { });";
+ CompileRun(script_2);
+
+ v8::Debug::SetDebugEventListener(NULL);
+}
+
+
+// Import from test-heap.cc
+int CountNativeContexts();
+
+
+static void NopListener(const v8::Debug::EventDetails& event_details) {
+}
+
+
+TEST(DebuggerCreatesContextIffActive) {
+ DebugLocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
+ CHECK_EQ(1, CountNativeContexts());
+
+ v8::Debug::SetDebugEventListener(NULL);
+ CompileRun("debugger;");
+ CHECK_EQ(1, CountNativeContexts());
+
+ v8::Debug::SetDebugEventListener(NopListener);
+ CompileRun("debugger;");
+ CHECK_EQ(2, CountNativeContexts());
+
+ v8::Debug::SetDebugEventListener(NULL);
+}
+
+
+TEST(LiveEditEnabled) {
+ v8::internal::FLAG_allow_natives_syntax = true;
+ LocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
+ v8::Debug::SetLiveEditEnabled(env->GetIsolate(), true);
+ CompileRun("%LiveEditCompareStrings('', '')");
+}
+
+
+TEST(LiveEditDisabled) {
+ v8::internal::FLAG_allow_natives_syntax = true;
+ LocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
+ v8::Debug::SetLiveEditEnabled(env->GetIsolate(), false);
+ CompileRun("%LiveEditCompareStrings('', '')");
+}
+
+
+TEST(PrecompiledFunction) {
+ // Regression test for crbug.com/346207. If we have preparse data, parsing the
+ // function in the presence of the debugger (and breakpoints) should still
+ // succeed. The bug was that preparsing was done lazily and parsing was done
+ // eagerly, so, the symbol streams didn't match.
+ DebugLocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
+ env.ExposeDebug();
+ v8::Debug::SetDebugEventListener(DebugBreakInlineListener);
+
+ v8::Local<v8::Function> break_here =
+ CompileFunction(&env, "function break_here(){}", "break_here");
+ SetBreakPoint(break_here, 0);
+
+ const char* source =
+ "var a = b = c = 1; \n"
+ "function this_is_lazy() { \n"
+ // This symbol won't appear in the preparse data.
+ " var a; \n"
+ "} \n"
+ "function bar() { \n"
+ " return \"bar\"; \n"
+ "}; \n"
+ "a = b = c = 2; \n"
+ "bar(); \n";
+ v8::Local<v8::Value> result = ParserCacheCompileRun(source);
+ CHECK(result->IsString());
+ v8::String::Utf8Value utf8(result);
+ CHECK_EQ("bar", *utf8);
+
+ v8::Debug::SetDebugEventListener(NULL);
+ CheckDebuggerUnloaded();
+}
+
+
+static void DebugBreakStackTraceListener(
+ const v8::Debug::EventDetails& event_details) {
+ v8::StackTrace::CurrentStackTrace(CcTest::isolate(), 10);
+}
+
+
+static void AddDebugBreak(const v8::FunctionCallbackInfo<v8::Value>& args) {
+ v8::Debug::DebugBreak(args.GetIsolate());
+}
+
+
+TEST(DebugBreakStackTrace) {
+ DebugLocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
+ v8::Debug::SetDebugEventListener(DebugBreakStackTraceListener);
+ v8::Handle<v8::FunctionTemplate> add_debug_break_template =
+ v8::FunctionTemplate::New(env->GetIsolate(), AddDebugBreak);
+ v8::Handle<v8::Function> add_debug_break =
+ add_debug_break_template->GetFunction();
+ env->Global()->Set(v8_str("add_debug_break"), add_debug_break);
+
+ CompileRun("(function loop() {"
+ " for (var j = 0; j < 1000; j++) {"
+ " for (var i = 0; i < 1000; i++) {"
+ " if (i == 999) add_debug_break();"
+ " }"
+ " }"
+ "})()");
+}
+
+
+v8::base::Semaphore terminate_requested_semaphore(0);
+v8::base::Semaphore terminate_fired_semaphore(0);
+bool terminate_already_fired = false;
+
+
+static void DebugBreakTriggerTerminate(
+ const v8::Debug::EventDetails& event_details) {
+ if (event_details.GetEvent() != v8::Break || terminate_already_fired) return;
+ terminate_requested_semaphore.Signal();
+ // Wait for at most 2 seconds for the terminate request.
+ CHECK(terminate_fired_semaphore.WaitFor(v8::base::TimeDelta::FromSeconds(2)));
+ terminate_already_fired = true;
+}
+
+
+class TerminationThread : public v8::base::Thread {
+ public:
+ explicit TerminationThread(v8::Isolate* isolate)
+ : Thread(Options("terminator")), isolate_(isolate) {}
+
+ virtual void Run() {
+ terminate_requested_semaphore.Wait();
+ v8::V8::TerminateExecution(isolate_);
+ terminate_fired_semaphore.Signal();
+ }
+
+ private:
+ v8::Isolate* isolate_;
+};
+
+
+TEST(DebugBreakOffThreadTerminate) {
+ DebugLocalContext env;
+ v8::Isolate* isolate = env->GetIsolate();
+ v8::HandleScope scope(isolate);
+ v8::Debug::SetDebugEventListener(DebugBreakTriggerTerminate);
+ TerminationThread terminator(isolate);
+ terminator.Start();
+ v8::TryCatch try_catch;
+ v8::Debug::DebugBreak(isolate);
+ CompileRun("while (true);");
+ CHECK(try_catch.HasTerminated());
+}