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

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

Issue 203353002: New compilation API, part 2. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: rebased 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-compiler.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 14938 matching lines...) Expand 10 before | Expand all | Expand 10 after
14949 const int kFunctionEntryEndOffset = 1; 14949 const int kFunctionEntryEndOffset = 1;
14950 unsigned* sd_data = 14950 unsigned* sd_data =
14951 reinterpret_cast<unsigned*>(const_cast<char*>(sd->Data())); 14951 reinterpret_cast<unsigned*>(const_cast<char*>(sd->Data()));
14952 14952
14953 // Overwrite function bar's end position with 0. 14953 // Overwrite function bar's end position with 0.
14954 sd_data[kHeaderSize + 1 * kFunctionEntrySize + kFunctionEntryEndOffset] = 0; 14954 sd_data[kHeaderSize + 1 * kFunctionEntrySize + kFunctionEntryEndOffset] = 0;
14955 v8::TryCatch try_catch; 14955 v8::TryCatch try_catch;
14956 14956
14957 v8::ScriptCompiler::Source script_source( 14957 v8::ScriptCompiler::Source script_source(
14958 String::NewFromUtf8(isolate, script), 14958 String::NewFromUtf8(isolate, script),
14959 v8::ScriptCompiler::CachedData( 14959 new v8::ScriptCompiler::CachedData(
14960 reinterpret_cast<const uint8_t*>(sd->Data()), sd->Length())); 14960 reinterpret_cast<const uint8_t*>(sd->Data()), sd->Length()));
14961 Local<v8::UnboundScript> compiled_script = 14961 Local<v8::UnboundScript> compiled_script =
14962 v8::ScriptCompiler::CompileUnbound(isolate, script_source); 14962 v8::ScriptCompiler::CompileUnbound(isolate, &script_source);
14963 14963
14964 CHECK(try_catch.HasCaught()); 14964 CHECK(try_catch.HasCaught());
14965 String::Utf8Value exception_value(try_catch.Message()->Get()); 14965 String::Utf8Value exception_value(try_catch.Message()->Get());
14966 CHECK_EQ("Uncaught SyntaxError: Invalid preparser data for function bar", 14966 CHECK_EQ("Uncaught SyntaxError: Invalid preparser data for function bar",
14967 *exception_value); 14967 *exception_value);
14968 14968
14969 try_catch.Reset(); 14969 try_catch.Reset();
14970 delete sd; 14970 delete sd;
14971 14971
14972 // Overwrite function bar's start position with 200. The function entry 14972 // Overwrite function bar's start position with 200. The function entry
14973 // will not be found when searching for it by position and we should fall 14973 // will not be found when searching for it by position and we should fall
14974 // back on eager compilation. 14974 // back on eager compilation.
14975 sd = v8::ScriptData::PreCompile(v8::String::NewFromUtf8( 14975 sd = v8::ScriptData::PreCompile(v8::String::NewFromUtf8(
14976 isolate, script, v8::String::kNormalString, i::StrLength(script))); 14976 isolate, script, v8::String::kNormalString, i::StrLength(script)));
14977 sd_data = reinterpret_cast<unsigned*>(const_cast<char*>(sd->Data())); 14977 sd_data = reinterpret_cast<unsigned*>(const_cast<char*>(sd->Data()));
14978 sd_data[kHeaderSize + 1 * kFunctionEntrySize + kFunctionEntryStartOffset] = 14978 sd_data[kHeaderSize + 1 * kFunctionEntrySize + kFunctionEntryStartOffset] =
14979 200; 14979 200;
14980 v8::ScriptCompiler::Source script_source2( 14980 v8::ScriptCompiler::Source script_source2(
14981 String::NewFromUtf8(isolate, script), 14981 String::NewFromUtf8(isolate, script),
14982 v8::ScriptCompiler::CachedData( 14982 new v8::ScriptCompiler::CachedData(
14983 reinterpret_cast<const uint8_t*>(sd->Data()), sd->Length())); 14983 reinterpret_cast<const uint8_t*>(sd->Data()), sd->Length()));
14984 compiled_script = 14984 compiled_script =
14985 v8::ScriptCompiler::CompileUnbound(isolate, script_source2); 14985 v8::ScriptCompiler::CompileUnbound(isolate, &script_source2);
14986 CHECK(!try_catch.HasCaught()); 14986 CHECK(!try_catch.HasCaught());
14987 14987
14988 delete sd; 14988 delete sd;
14989 } 14989 }
14990 14990
14991 14991
14992 // This tests that we do not allow dictionary load/call inline caches 14992 // This tests that we do not allow dictionary load/call inline caches
14993 // to use functions that have not yet been compiled. The potential 14993 // to use functions that have not yet been compiled. The potential
14994 // problem of loading a function that has not yet been compiled can 14994 // problem of loading a function that has not yet been compiled can
14995 // arise because we share code between contexts via the compilation 14995 // arise because we share code between contexts via the compilation
(...skipping 2088 matching lines...) Expand 10 before | Expand all | Expand 10 after
17084 IS_ARRAY_BUFFER_VIEW_TEST(DataView) 17084 IS_ARRAY_BUFFER_VIEW_TEST(DataView)
17085 17085
17086 #undef IS_ARRAY_BUFFER_VIEW_TEST 17086 #undef IS_ARRAY_BUFFER_VIEW_TEST
17087 17087
17088 17088
17089 17089
17090 THREADED_TEST(ScriptContextDependence) { 17090 THREADED_TEST(ScriptContextDependence) {
17091 LocalContext c1; 17091 LocalContext c1;
17092 v8::HandleScope scope(c1->GetIsolate()); 17092 v8::HandleScope scope(c1->GetIsolate());
17093 const char *source = "foo"; 17093 const char *source = "foo";
17094 v8::Handle<v8::Script> dep = 17094 v8::Handle<v8::Script> dep = v8_compile(source);
17095 v8_compile(source); 17095 v8::ScriptCompiler::Source script_source(v8::String::NewFromUtf8(
17096 c1->GetIsolate(), source));
17096 v8::Handle<v8::UnboundScript> indep = 17097 v8::Handle<v8::UnboundScript> indep =
17097 v8::ScriptCompiler::CompileUnbound( 17098 v8::ScriptCompiler::CompileUnbound(c1->GetIsolate(), &script_source);
17098 c1->GetIsolate(), v8::ScriptCompiler::Source(v8::String::NewFromUtf8(
17099 c1->GetIsolate(), source)));
17100 c1->Global()->Set(v8::String::NewFromUtf8(c1->GetIsolate(), "foo"), 17099 c1->Global()->Set(v8::String::NewFromUtf8(c1->GetIsolate(), "foo"),
17101 v8::Integer::New(c1->GetIsolate(), 100)); 17100 v8::Integer::New(c1->GetIsolate(), 100));
17102 CHECK_EQ(dep->Run()->Int32Value(), 100); 17101 CHECK_EQ(dep->Run()->Int32Value(), 100);
17103 CHECK_EQ(indep->BindToCurrentContext()->Run()->Int32Value(), 100); 17102 CHECK_EQ(indep->BindToCurrentContext()->Run()->Int32Value(), 100);
17104 LocalContext c2; 17103 LocalContext c2;
17105 c2->Global()->Set(v8::String::NewFromUtf8(c2->GetIsolate(), "foo"), 17104 c2->Global()->Set(v8::String::NewFromUtf8(c2->GetIsolate(), "foo"),
17106 v8::Integer::New(c2->GetIsolate(), 101)); 17105 v8::Integer::New(c2->GetIsolate(), 101));
17107 CHECK_EQ(dep->Run()->Int32Value(), 100); 17106 CHECK_EQ(dep->Run()->Int32Value(), 100);
17108 CHECK_EQ(indep->BindToCurrentContext()->Run()->Int32Value(), 101); 17107 CHECK_EQ(indep->BindToCurrentContext()->Run()->Int32Value(), 101);
17109 } 17108 }
17110 17109
17111 17110
17112 THREADED_TEST(StackTrace) { 17111 THREADED_TEST(StackTrace) {
17113 LocalContext context; 17112 LocalContext context;
17114 v8::HandleScope scope(context->GetIsolate()); 17113 v8::HandleScope scope(context->GetIsolate());
17115 v8::TryCatch try_catch; 17114 v8::TryCatch try_catch;
17116 const char *source = "function foo() { FAIL.FAIL; }; foo();"; 17115 const char *source = "function foo() { FAIL.FAIL; }; foo();";
17117 v8::Handle<v8::String> src = 17116 v8::Handle<v8::String> src =
17118 v8::String::NewFromUtf8(context->GetIsolate(), source); 17117 v8::String::NewFromUtf8(context->GetIsolate(), source);
17119 v8::Handle<v8::String> origin = 17118 v8::Handle<v8::String> origin =
17120 v8::String::NewFromUtf8(context->GetIsolate(), "stack-trace-test"); 17119 v8::String::NewFromUtf8(context->GetIsolate(), "stack-trace-test");
17121 v8::ScriptCompiler::CompileUnbound( 17120 v8::ScriptCompiler::Source script_source(src, v8::ScriptOrigin(origin));
17122 context->GetIsolate(), 17121 v8::ScriptCompiler::CompileUnbound(context->GetIsolate(), &script_source)
17123 v8::ScriptCompiler::Source(src, v8::ScriptOrigin(origin)))
17124 ->BindToCurrentContext() 17122 ->BindToCurrentContext()
17125 ->Run(); 17123 ->Run();
17126 CHECK(try_catch.HasCaught()); 17124 CHECK(try_catch.HasCaught());
17127 v8::String::Utf8Value stack(try_catch.StackTrace()); 17125 v8::String::Utf8Value stack(try_catch.StackTrace());
17128 CHECK(strstr(*stack, "at foo (stack-trace-test") != NULL); 17126 CHECK(strstr(*stack, "at foo (stack-trace-test") != NULL);
17129 } 17127 }
17130 17128
17131 17129
17132 // Checks that a StackFrame has certain expected values. 17130 // Checks that a StackFrame has certain expected values.
17133 void checkStackFrame(const char* expected_script_name, 17131 void checkStackFrame(const char* expected_script_name,
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
17221 "function bar() {\n" 17219 "function bar() {\n"
17222 " var y; AnalyzeStackInNativeCode(1);\n" 17220 " var y; AnalyzeStackInNativeCode(1);\n"
17223 "}\n" 17221 "}\n"
17224 "function foo() {\n" 17222 "function foo() {\n"
17225 "\n" 17223 "\n"
17226 " bar();\n" 17224 " bar();\n"
17227 "}\n" 17225 "}\n"
17228 "var x;eval('new foo();');"; 17226 "var x;eval('new foo();');";
17229 v8::Handle<v8::String> overview_src = 17227 v8::Handle<v8::String> overview_src =
17230 v8::String::NewFromUtf8(isolate, overview_source); 17228 v8::String::NewFromUtf8(isolate, overview_source);
17229 v8::ScriptCompiler::Source script_source(overview_src,
17230 v8::ScriptOrigin(origin));
17231 v8::Handle<Value> overview_result( 17231 v8::Handle<Value> overview_result(
17232 v8::ScriptCompiler::CompileUnbound( 17232 v8::ScriptCompiler::CompileUnbound(isolate, &script_source)
17233 isolate,
17234 v8::ScriptCompiler::Source(overview_src, v8::ScriptOrigin(origin)))
17235 ->BindToCurrentContext() 17233 ->BindToCurrentContext()
17236 ->Run()); 17234 ->Run());
17237 CHECK(!overview_result.IsEmpty()); 17235 CHECK(!overview_result.IsEmpty());
17238 CHECK(overview_result->IsObject()); 17236 CHECK(overview_result->IsObject());
17239 17237
17240 // Test getting DETAILED information. 17238 // Test getting DETAILED information.
17241 const char *detailed_source = 17239 const char *detailed_source =
17242 "function bat() {AnalyzeStackInNativeCode(2);\n" 17240 "function bat() {AnalyzeStackInNativeCode(2);\n"
17243 "}\n" 17241 "}\n"
17244 "\n" 17242 "\n"
17245 "function baz() {\n" 17243 "function baz() {\n"
17246 " bat();\n" 17244 " bat();\n"
17247 "}\n" 17245 "}\n"
17248 "eval('new baz();');"; 17246 "eval('new baz();');";
17249 v8::Handle<v8::String> detailed_src = 17247 v8::Handle<v8::String> detailed_src =
17250 v8::String::NewFromUtf8(isolate, detailed_source); 17248 v8::String::NewFromUtf8(isolate, detailed_source);
17251 // Make the script using a non-zero line and column offset. 17249 // Make the script using a non-zero line and column offset.
17252 v8::Handle<v8::Integer> line_offset = v8::Integer::New(isolate, 3); 17250 v8::Handle<v8::Integer> line_offset = v8::Integer::New(isolate, 3);
17253 v8::Handle<v8::Integer> column_offset = v8::Integer::New(isolate, 5); 17251 v8::Handle<v8::Integer> column_offset = v8::Integer::New(isolate, 5);
17254 v8::ScriptOrigin detailed_origin(origin, line_offset, column_offset); 17252 v8::ScriptOrigin detailed_origin(origin, line_offset, column_offset);
17253 v8::ScriptCompiler::Source script_source2(detailed_src, detailed_origin);
17255 v8::Handle<v8::UnboundScript> detailed_script( 17254 v8::Handle<v8::UnboundScript> detailed_script(
17256 v8::ScriptCompiler::CompileUnbound( 17255 v8::ScriptCompiler::CompileUnbound(isolate, &script_source2));
17257 isolate, v8::ScriptCompiler::Source(detailed_src, detailed_origin)));
17258 v8::Handle<Value> detailed_result( 17256 v8::Handle<Value> detailed_result(
17259 detailed_script->BindToCurrentContext()->Run()); 17257 detailed_script->BindToCurrentContext()->Run());
17260 CHECK(!detailed_result.IsEmpty()); 17258 CHECK(!detailed_result.IsEmpty());
17261 CHECK(detailed_result->IsObject()); 17259 CHECK(detailed_result->IsObject());
17262 } 17260 }
17263 17261
17264 17262
17265 static void StackTraceForUncaughtExceptionListener( 17263 static void StackTraceForUncaughtExceptionListener(
17266 v8::Handle<v8::Message> message, 17264 v8::Handle<v8::Message> message,
17267 v8::Handle<Value>) { 17265 v8::Handle<Value>) {
(...skipping 5154 matching lines...) Expand 10 before | Expand all | Expand 10 after
22422 TEST(ThrowOnJavascriptExecution) { 22420 TEST(ThrowOnJavascriptExecution) {
22423 LocalContext context; 22421 LocalContext context;
22424 v8::Isolate* isolate = context->GetIsolate(); 22422 v8::Isolate* isolate = context->GetIsolate();
22425 v8::HandleScope scope(isolate); 22423 v8::HandleScope scope(isolate);
22426 v8::TryCatch try_catch; 22424 v8::TryCatch try_catch;
22427 v8::Isolate::DisallowJavascriptExecutionScope throw_js( 22425 v8::Isolate::DisallowJavascriptExecutionScope throw_js(
22428 isolate, v8::Isolate::DisallowJavascriptExecutionScope::THROW_ON_FAILURE); 22426 isolate, v8::Isolate::DisallowJavascriptExecutionScope::THROW_ON_FAILURE);
22429 CompileRun("1+1"); 22427 CompileRun("1+1");
22430 CHECK(try_catch.HasCaught()); 22428 CHECK(try_catch.HasCaught());
22431 } 22429 }
OLDNEW
« no previous file with comments | « test/cctest/cctest.h ('k') | test/cctest/test-compiler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698