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

Unified Diff: test/cctest/test-debug.cc

Issue 90003: Make it possible to add a user data object to each script compiled (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/cctest/test-api.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-debug.cc
===================================================================
--- test/cctest/test-debug.cc (revision 1746)
+++ test/cctest/test-debug.cc (working copy)
@@ -525,6 +525,24 @@
v8::Local<v8::Function> frame_source_column;
+// Source for The JavaScript function which picks out the script name for the
+// top frame.
+const char* frame_script_name_source =
+ "function frame_script_name(exec_state) {"
+ " return exec_state.frame(0).func().script().name();"
+ "}";
+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 returns the number of frames.
static const char* frame_count_source =
"function frame_count(exec_state) {"
@@ -536,6 +554,11 @@
// 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.
+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;
int last_source_column = -1;
@@ -586,6 +609,37 @@
CHECK(result->IsNumber());
last_source_column = result->Int32Value();
}
+
+ if (!frame_script_name.IsEmpty()) {
+ // Get the script name of the function script.
+ const int argc = 1;
+ v8::Handle<v8::Value> argv[argc] = { exec_state };
+ v8::Handle<v8::Value> result = frame_script_name->Call(exec_state,
+ argc, argv);
+ if (result->IsUndefined()) {
+ last_script_name_hit[0] = '\0';
+ } 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);
+ }
+ }
}
}
@@ -4249,3 +4303,58 @@
// Must not crash while accessing line_ends.
i::FLAG_allow_natives_syntax = allow_natives_syntax;
}
+
+
+// Test script break points set on lines.
+TEST(ScriptNameAndData) {
+ v8::HandleScope scope;
+ DebugLocalContext env;
+ env.ExposeDebug();
+
+ // Create functions for retrieving script name and data for the function on
+ // the top frame when hitting a break point.
+ frame_script_name = CompileFunction(&env,
+ frame_script_name_source,
+ "frame_script_name");
+ frame_script_data = CompileFunction(&env,
+ frame_script_data_source,
+ "frame_script_data");
+
+ v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
+ v8::Undefined());
+
+ // Test function source.
+ v8::Local<v8::String> script = v8::String::New(
+ "function f() {\n"
+ " debugger;\n"
+ "}\n");
+
+ v8::ScriptOrigin origin1 = v8::ScriptOrigin(v8::String::New("name"));
+ v8::Handle<v8::Script> script1 = v8::Script::Compile(script, &origin1);
+ script1->SetData(v8::String::New("data"));
+ script1->Run();
+ v8::Script::Compile(script, &origin1)->Run();
+ v8::Local<v8::Function> f;
+ f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("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);
+
+ 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::Handle<v8::Script> script2 = v8::Script::Compile(script, &origin2);
+ script2->Run();
+ script2->SetData(data_obj);
+ f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));
+ f->Call(env->Global(), 0, NULL);
+ CHECK_EQ(2, break_point_hit_count);
+ CHECK_EQ("new name", last_script_name_hit);
+ CHECK_EQ("abc 123", last_script_data_hit);
+}
« no previous file with comments | « test/cctest/test-api.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698