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

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

Issue 186723005: New Compilation API, part 1 (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: . Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « test/cctest/cctest.h ('k') | test/cctest/test-cpu-profiler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 14934 matching lines...) Expand 10 before | Expand all | Expand 10 after
14945 const int kFunctionEntrySize = i::FunctionEntry::kSize; 14945 const int kFunctionEntrySize = i::FunctionEntry::kSize;
14946 const int kFunctionEntryStartOffset = 0; 14946 const int kFunctionEntryStartOffset = 0;
14947 const int kFunctionEntryEndOffset = 1; 14947 const int kFunctionEntryEndOffset = 1;
14948 unsigned* sd_data = 14948 unsigned* sd_data =
14949 reinterpret_cast<unsigned*>(const_cast<char*>(sd->Data())); 14949 reinterpret_cast<unsigned*>(const_cast<char*>(sd->Data()));
14950 14950
14951 // Overwrite function bar's end position with 0. 14951 // Overwrite function bar's end position with 0.
14952 sd_data[kHeaderSize + 1 * kFunctionEntrySize + kFunctionEntryEndOffset] = 0; 14952 sd_data[kHeaderSize + 1 * kFunctionEntrySize + kFunctionEntryEndOffset] = 0;
14953 v8::TryCatch try_catch; 14953 v8::TryCatch try_catch;
14954 14954
14955 Local<String> source = String::NewFromUtf8(isolate, script); 14955 v8::ScriptCompiler::Source script_source(
14956 Local<Script> compiled_script = Script::New(source, NULL, sd); 14956 String::NewFromUtf8(isolate, script),
14957 v8::ScriptCompiler::CachedData(
14958 reinterpret_cast<const uint8_t*>(sd->Data()), sd->Length()));
14959 Local<v8::UnboundScript> compiled_script =
14960 v8::ScriptCompiler::CompileUnbound(isolate, script_source);
14961
14957 CHECK(try_catch.HasCaught()); 14962 CHECK(try_catch.HasCaught());
14958 String::Utf8Value exception_value(try_catch.Message()->Get()); 14963 String::Utf8Value exception_value(try_catch.Message()->Get());
14959 CHECK_EQ("Uncaught SyntaxError: Invalid preparser data for function bar", 14964 CHECK_EQ("Uncaught SyntaxError: Invalid preparser data for function bar",
14960 *exception_value); 14965 *exception_value);
14961 14966
14962 try_catch.Reset(); 14967 try_catch.Reset();
14963 delete sd; 14968 delete sd;
14964 14969
14965 // Overwrite function bar's start position with 200. The function entry 14970 // Overwrite function bar's start position with 200. The function entry
14966 // will not be found when searching for it by position and we should fall 14971 // will not be found when searching for it by position and we should fall
14967 // back on eager compilation. 14972 // back on eager compilation.
14968 sd = v8::ScriptData::PreCompile(v8::String::NewFromUtf8( 14973 sd = v8::ScriptData::PreCompile(v8::String::NewFromUtf8(
14969 isolate, script, v8::String::kNormalString, i::StrLength(script))); 14974 isolate, script, v8::String::kNormalString, i::StrLength(script)));
14970 sd_data = reinterpret_cast<unsigned*>(const_cast<char*>(sd->Data())); 14975 sd_data = reinterpret_cast<unsigned*>(const_cast<char*>(sd->Data()));
14971 sd_data[kHeaderSize + 1 * kFunctionEntrySize + kFunctionEntryStartOffset] = 14976 sd_data[kHeaderSize + 1 * kFunctionEntrySize + kFunctionEntryStartOffset] =
14972 200; 14977 200;
14973 compiled_script = Script::New(source, NULL, sd); 14978 v8::ScriptCompiler::Source script_source2(
14979 String::NewFromUtf8(isolate, script),
14980 v8::ScriptCompiler::CachedData(
14981 reinterpret_cast<const uint8_t*>(sd->Data()), sd->Length()));
14982 compiled_script =
14983 v8::ScriptCompiler::CompileUnbound(isolate, script_source2);
14974 CHECK(!try_catch.HasCaught()); 14984 CHECK(!try_catch.HasCaught());
14975 14985
14976 delete sd; 14986 delete sd;
14977 } 14987 }
14978 14988
14979 14989
14980 // This tests that we do not allow dictionary load/call inline caches 14990 // This tests that we do not allow dictionary load/call inline caches
14981 // to use functions that have not yet been compiled. The potential 14991 // to use functions that have not yet been compiled. The potential
14982 // problem of loading a function that has not yet been compiled can 14992 // problem of loading a function that has not yet been compiled can
14983 // arise because we share code between contexts via the compilation 14993 // arise because we share code between contexts via the compilation
(...skipping 2090 matching lines...) Expand 10 before | Expand all | Expand 10 after
17074 #undef IS_ARRAY_BUFFER_VIEW_TEST 17084 #undef IS_ARRAY_BUFFER_VIEW_TEST
17075 17085
17076 17086
17077 17087
17078 THREADED_TEST(ScriptContextDependence) { 17088 THREADED_TEST(ScriptContextDependence) {
17079 LocalContext c1; 17089 LocalContext c1;
17080 v8::HandleScope scope(c1->GetIsolate()); 17090 v8::HandleScope scope(c1->GetIsolate());
17081 const char *source = "foo"; 17091 const char *source = "foo";
17082 v8::Handle<v8::Script> dep = 17092 v8::Handle<v8::Script> dep =
17083 v8_compile(source); 17093 v8_compile(source);
17084 v8::Handle<v8::Script> indep = 17094 v8::Handle<v8::UnboundScript> indep =
17085 v8::Script::New(v8::String::NewFromUtf8(c1->GetIsolate(), source)); 17095 v8::ScriptCompiler::CompileUnbound(
17096 c1->GetIsolate(), v8::ScriptCompiler::Source(v8::String::NewFromUtf8(
17097 c1->GetIsolate(), source)));
17086 c1->Global()->Set(v8::String::NewFromUtf8(c1->GetIsolate(), "foo"), 17098 c1->Global()->Set(v8::String::NewFromUtf8(c1->GetIsolate(), "foo"),
17087 v8::Integer::New(c1->GetIsolate(), 100)); 17099 v8::Integer::New(c1->GetIsolate(), 100));
17088 CHECK_EQ(dep->Run()->Int32Value(), 100); 17100 CHECK_EQ(dep->Run()->Int32Value(), 100);
17089 CHECK_EQ(indep->Run()->Int32Value(), 100); 17101 CHECK_EQ(indep->BindToCurrentContext()->Run()->Int32Value(), 100);
17090 LocalContext c2; 17102 LocalContext c2;
17091 c2->Global()->Set(v8::String::NewFromUtf8(c2->GetIsolate(), "foo"), 17103 c2->Global()->Set(v8::String::NewFromUtf8(c2->GetIsolate(), "foo"),
17092 v8::Integer::New(c2->GetIsolate(), 101)); 17104 v8::Integer::New(c2->GetIsolate(), 101));
17093 CHECK_EQ(dep->Run()->Int32Value(), 100); 17105 CHECK_EQ(dep->Run()->Int32Value(), 100);
17094 CHECK_EQ(indep->Run()->Int32Value(), 101); 17106 CHECK_EQ(indep->BindToCurrentContext()->Run()->Int32Value(), 101);
17095 } 17107 }
17096 17108
17097 17109
17098 THREADED_TEST(StackTrace) { 17110 THREADED_TEST(StackTrace) {
17099 LocalContext context; 17111 LocalContext context;
17100 v8::HandleScope scope(context->GetIsolate()); 17112 v8::HandleScope scope(context->GetIsolate());
17101 v8::TryCatch try_catch; 17113 v8::TryCatch try_catch;
17102 const char *source = "function foo() { FAIL.FAIL; }; foo();"; 17114 const char *source = "function foo() { FAIL.FAIL; }; foo();";
17103 v8::Handle<v8::String> src = 17115 v8::Handle<v8::String> src =
17104 v8::String::NewFromUtf8(context->GetIsolate(), source); 17116 v8::String::NewFromUtf8(context->GetIsolate(), source);
17105 v8::Handle<v8::String> origin = 17117 v8::Handle<v8::String> origin =
17106 v8::String::NewFromUtf8(context->GetIsolate(), "stack-trace-test"); 17118 v8::String::NewFromUtf8(context->GetIsolate(), "stack-trace-test");
17107 v8::Script::New(src, origin)->Run(); 17119 v8::ScriptCompiler::CompileUnbound(
17120 context->GetIsolate(),
17121 v8::ScriptCompiler::Source(src, v8::ScriptOrigin(origin)))
17122 ->BindToCurrentContext()
17123 ->Run();
17108 CHECK(try_catch.HasCaught()); 17124 CHECK(try_catch.HasCaught());
17109 v8::String::Utf8Value stack(try_catch.StackTrace()); 17125 v8::String::Utf8Value stack(try_catch.StackTrace());
17110 CHECK(strstr(*stack, "at foo (stack-trace-test") != NULL); 17126 CHECK(strstr(*stack, "at foo (stack-trace-test") != NULL);
17111 } 17127 }
17112 17128
17113 17129
17114 // Checks that a StackFrame has certain expected values. 17130 // Checks that a StackFrame has certain expected values.
17115 void checkStackFrame(const char* expected_script_name, 17131 void checkStackFrame(const char* expected_script_name,
17116 const char* expected_func_name, int expected_line_number, 17132 const char* expected_func_name, int expected_line_number,
17117 int expected_column, bool is_eval, bool is_constructor, 17133 int expected_column, bool is_eval, bool is_constructor,
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
17204 " var y; AnalyzeStackInNativeCode(1);\n" 17220 " var y; AnalyzeStackInNativeCode(1);\n"
17205 "}\n" 17221 "}\n"
17206 "function foo() {\n" 17222 "function foo() {\n"
17207 "\n" 17223 "\n"
17208 " bar();\n" 17224 " bar();\n"
17209 "}\n" 17225 "}\n"
17210 "var x;eval('new foo();');"; 17226 "var x;eval('new foo();');";
17211 v8::Handle<v8::String> overview_src = 17227 v8::Handle<v8::String> overview_src =
17212 v8::String::NewFromUtf8(isolate, overview_source); 17228 v8::String::NewFromUtf8(isolate, overview_source);
17213 v8::Handle<Value> overview_result( 17229 v8::Handle<Value> overview_result(
17214 v8::Script::New(overview_src, origin)->Run()); 17230 v8::ScriptCompiler::CompileUnbound(
17231 isolate,
17232 v8::ScriptCompiler::Source(overview_src, v8::ScriptOrigin(origin)))
17233 ->BindToCurrentContext()
17234 ->Run());
17215 CHECK(!overview_result.IsEmpty()); 17235 CHECK(!overview_result.IsEmpty());
17216 CHECK(overview_result->IsObject()); 17236 CHECK(overview_result->IsObject());
17217 17237
17218 // Test getting DETAILED information. 17238 // Test getting DETAILED information.
17219 const char *detailed_source = 17239 const char *detailed_source =
17220 "function bat() {AnalyzeStackInNativeCode(2);\n" 17240 "function bat() {AnalyzeStackInNativeCode(2);\n"
17221 "}\n" 17241 "}\n"
17222 "\n" 17242 "\n"
17223 "function baz() {\n" 17243 "function baz() {\n"
17224 " bat();\n" 17244 " bat();\n"
17225 "}\n" 17245 "}\n"
17226 "eval('new baz();');"; 17246 "eval('new baz();');";
17227 v8::Handle<v8::String> detailed_src = 17247 v8::Handle<v8::String> detailed_src =
17228 v8::String::NewFromUtf8(isolate, detailed_source); 17248 v8::String::NewFromUtf8(isolate, detailed_source);
17229 // Make the script using a non-zero line and column offset. 17249 // Make the script using a non-zero line and column offset.
17230 v8::Handle<v8::Integer> line_offset = v8::Integer::New(isolate, 3); 17250 v8::Handle<v8::Integer> line_offset = v8::Integer::New(isolate, 3);
17231 v8::Handle<v8::Integer> column_offset = v8::Integer::New(isolate, 5); 17251 v8::Handle<v8::Integer> column_offset = v8::Integer::New(isolate, 5);
17232 v8::ScriptOrigin detailed_origin(origin, line_offset, column_offset); 17252 v8::ScriptOrigin detailed_origin(origin, line_offset, column_offset);
17233 v8::Handle<v8::Script> detailed_script( 17253 v8::Handle<v8::UnboundScript> detailed_script(
17234 v8::Script::New(detailed_src, &detailed_origin)); 17254 v8::ScriptCompiler::CompileUnbound(
17235 v8::Handle<Value> detailed_result(detailed_script->Run()); 17255 isolate, v8::ScriptCompiler::Source(detailed_src, detailed_origin)));
17256 v8::Handle<Value> detailed_result(
17257 detailed_script->BindToCurrentContext()->Run());
17236 CHECK(!detailed_result.IsEmpty()); 17258 CHECK(!detailed_result.IsEmpty());
17237 CHECK(detailed_result->IsObject()); 17259 CHECK(detailed_result->IsObject());
17238 } 17260 }
17239 17261
17240 17262
17241 static void StackTraceForUncaughtExceptionListener( 17263 static void StackTraceForUncaughtExceptionListener(
17242 v8::Handle<v8::Message> message, 17264 v8::Handle<v8::Message> message,
17243 v8::Handle<Value>) { 17265 v8::Handle<Value>) {
17244 v8::Handle<v8::StackTrace> stack_trace = message->GetStackTrace(); 17266 v8::Handle<v8::StackTrace> stack_trace = message->GetStackTrace();
17245 CHECK_EQ(2, stack_trace->GetFrameCount()); 17267 CHECK_EQ(2, stack_trace->GetFrameCount());
(...skipping 5061 matching lines...) Expand 10 before | Expand all | Expand 10 after
22307 CompileRun("x1 = x2 = 0;"); 22329 CompileRun("x1 = x2 = 0;");
22308 r = v8::Promise::New(isolate); 22330 r = v8::Promise::New(isolate);
22309 r->Catch(f1)->Chain(f2); 22331 r->Catch(f1)->Chain(f2);
22310 r->Reject(v8::Integer::New(isolate, 3)); 22332 r->Reject(v8::Integer::New(isolate, 3));
22311 CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value()); 22333 CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value());
22312 CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value()); 22334 CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value());
22313 V8::RunMicrotasks(isolate); 22335 V8::RunMicrotasks(isolate);
22314 CHECK_EQ(3, global->Get(v8_str("x1"))->Int32Value()); 22336 CHECK_EQ(3, global->Get(v8_str("x1"))->Int32Value());
22315 CHECK_EQ(4, global->Get(v8_str("x2"))->Int32Value()); 22337 CHECK_EQ(4, global->Get(v8_str("x2"))->Int32Value());
22316 } 22338 }
OLDNEW
« no previous file with comments | « test/cctest/cctest.h ('k') | test/cctest/test-cpu-profiler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698