OLD | NEW |
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 14824 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14835 const int kFunctionEntrySize = i::FunctionEntry::kSize; | 14835 const int kFunctionEntrySize = i::FunctionEntry::kSize; |
14836 const int kFunctionEntryStartOffset = 0; | 14836 const int kFunctionEntryStartOffset = 0; |
14837 const int kFunctionEntryEndOffset = 1; | 14837 const int kFunctionEntryEndOffset = 1; |
14838 unsigned* sd_data = | 14838 unsigned* sd_data = |
14839 reinterpret_cast<unsigned*>(const_cast<char*>(sd->Data())); | 14839 reinterpret_cast<unsigned*>(const_cast<char*>(sd->Data())); |
14840 | 14840 |
14841 // Overwrite function bar's end position with 0. | 14841 // Overwrite function bar's end position with 0. |
14842 sd_data[kHeaderSize + 1 * kFunctionEntrySize + kFunctionEntryEndOffset] = 0; | 14842 sd_data[kHeaderSize + 1 * kFunctionEntrySize + kFunctionEntryEndOffset] = 0; |
14843 v8::TryCatch try_catch; | 14843 v8::TryCatch try_catch; |
14844 | 14844 |
14845 Local<String> source = String::NewFromUtf8(isolate, script); | 14845 v8::ScriptCompiler::Source script_source( |
14846 Local<Script> compiled_script = Script::New(source, NULL, sd); | 14846 String::NewFromUtf8(isolate, script), |
| 14847 v8::ScriptCompiler::CachedData( |
| 14848 reinterpret_cast<const uint8_t*>(sd->Data()), sd->Length())); |
| 14849 Local<v8::ContextUnboundScript> compiled_script = |
| 14850 v8::ScriptCompiler::CompileContextUnbound(isolate, script_source); |
| 14851 |
14847 CHECK(try_catch.HasCaught()); | 14852 CHECK(try_catch.HasCaught()); |
14848 String::Utf8Value exception_value(try_catch.Message()->Get()); | 14853 String::Utf8Value exception_value(try_catch.Message()->Get()); |
14849 CHECK_EQ("Uncaught SyntaxError: Invalid preparser data for function bar", | 14854 CHECK_EQ("Uncaught SyntaxError: Invalid preparser data for function bar", |
14850 *exception_value); | 14855 *exception_value); |
14851 | 14856 |
14852 try_catch.Reset(); | 14857 try_catch.Reset(); |
14853 delete sd; | 14858 delete sd; |
14854 | 14859 |
14855 // Overwrite function bar's start position with 200. The function entry | 14860 // Overwrite function bar's start position with 200. The function entry |
14856 // will not be found when searching for it by position and we should fall | 14861 // will not be found when searching for it by position and we should fall |
14857 // back on eager compilation. | 14862 // back on eager compilation. |
14858 sd = v8::ScriptData::PreCompile(v8::String::NewFromUtf8( | 14863 sd = v8::ScriptData::PreCompile(v8::String::NewFromUtf8( |
14859 isolate, script, v8::String::kNormalString, i::StrLength(script))); | 14864 isolate, script, v8::String::kNormalString, i::StrLength(script))); |
14860 sd_data = reinterpret_cast<unsigned*>(const_cast<char*>(sd->Data())); | 14865 sd_data = reinterpret_cast<unsigned*>(const_cast<char*>(sd->Data())); |
14861 sd_data[kHeaderSize + 1 * kFunctionEntrySize + kFunctionEntryStartOffset] = | 14866 sd_data[kHeaderSize + 1 * kFunctionEntrySize + kFunctionEntryStartOffset] = |
14862 200; | 14867 200; |
14863 compiled_script = Script::New(source, NULL, sd); | 14868 v8::ScriptCompiler::Source script_source2( |
| 14869 String::NewFromUtf8(isolate, script), |
| 14870 v8::ScriptCompiler::CachedData( |
| 14871 reinterpret_cast<const uint8_t*>(sd->Data()), sd->Length())); |
| 14872 compiled_script = |
| 14873 v8::ScriptCompiler::CompileContextUnbound(isolate, script_source2); |
14864 CHECK(!try_catch.HasCaught()); | 14874 CHECK(!try_catch.HasCaught()); |
14865 | 14875 |
14866 delete sd; | 14876 delete sd; |
14867 } | 14877 } |
14868 | 14878 |
14869 | 14879 |
14870 // This tests that we do not allow dictionary load/call inline caches | 14880 // This tests that we do not allow dictionary load/call inline caches |
14871 // to use functions that have not yet been compiled. The potential | 14881 // to use functions that have not yet been compiled. The potential |
14872 // problem of loading a function that has not yet been compiled can | 14882 // problem of loading a function that has not yet been compiled can |
14873 // arise because we share code between contexts via the compilation | 14883 // arise because we share code between contexts via the compilation |
(...skipping 2093 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16967 #undef IS_ARRAY_BUFFER_VIEW_TEST | 16977 #undef IS_ARRAY_BUFFER_VIEW_TEST |
16968 | 16978 |
16969 | 16979 |
16970 | 16980 |
16971 THREADED_TEST(ScriptContextDependence) { | 16981 THREADED_TEST(ScriptContextDependence) { |
16972 LocalContext c1; | 16982 LocalContext c1; |
16973 v8::HandleScope scope(c1->GetIsolate()); | 16983 v8::HandleScope scope(c1->GetIsolate()); |
16974 const char *source = "foo"; | 16984 const char *source = "foo"; |
16975 v8::Handle<v8::Script> dep = | 16985 v8::Handle<v8::Script> dep = |
16976 v8_compile(source); | 16986 v8_compile(source); |
16977 v8::Handle<v8::Script> indep = | 16987 v8::Handle<v8::ContextUnboundScript> indep = |
16978 v8::Script::New(v8::String::NewFromUtf8(c1->GetIsolate(), source)); | 16988 v8::ScriptCompiler::CompileContextUnbound( |
| 16989 c1->GetIsolate(), v8::ScriptCompiler::Source(v8::String::NewFromUtf8( |
| 16990 c1->GetIsolate(), source))); |
16979 c1->Global()->Set(v8::String::NewFromUtf8(c1->GetIsolate(), "foo"), | 16991 c1->Global()->Set(v8::String::NewFromUtf8(c1->GetIsolate(), "foo"), |
16980 v8::Integer::New(c1->GetIsolate(), 100)); | 16992 v8::Integer::New(c1->GetIsolate(), 100)); |
16981 CHECK_EQ(dep->Run()->Int32Value(), 100); | 16993 CHECK_EQ(dep->Run()->Int32Value(), 100); |
16982 CHECK_EQ(indep->Run()->Int32Value(), 100); | 16994 CHECK_EQ(indep->Run()->Int32Value(), 100); |
16983 LocalContext c2; | 16995 LocalContext c2; |
16984 c2->Global()->Set(v8::String::NewFromUtf8(c2->GetIsolate(), "foo"), | 16996 c2->Global()->Set(v8::String::NewFromUtf8(c2->GetIsolate(), "foo"), |
16985 v8::Integer::New(c2->GetIsolate(), 101)); | 16997 v8::Integer::New(c2->GetIsolate(), 101)); |
16986 CHECK_EQ(dep->Run()->Int32Value(), 100); | 16998 CHECK_EQ(dep->Run()->Int32Value(), 100); |
16987 CHECK_EQ(indep->Run()->Int32Value(), 101); | 16999 CHECK_EQ(indep->Run()->Int32Value(), 101); |
16988 } | 17000 } |
16989 | 17001 |
16990 | 17002 |
16991 THREADED_TEST(StackTrace) { | 17003 THREADED_TEST(StackTrace) { |
16992 LocalContext context; | 17004 LocalContext context; |
16993 v8::HandleScope scope(context->GetIsolate()); | 17005 v8::HandleScope scope(context->GetIsolate()); |
16994 v8::TryCatch try_catch; | 17006 v8::TryCatch try_catch; |
16995 const char *source = "function foo() { FAIL.FAIL; }; foo();"; | 17007 const char *source = "function foo() { FAIL.FAIL; }; foo();"; |
16996 v8::Handle<v8::String> src = | 17008 v8::Handle<v8::String> src = |
16997 v8::String::NewFromUtf8(context->GetIsolate(), source); | 17009 v8::String::NewFromUtf8(context->GetIsolate(), source); |
16998 v8::Handle<v8::String> origin = | 17010 v8::Handle<v8::String> origin = |
16999 v8::String::NewFromUtf8(context->GetIsolate(), "stack-trace-test"); | 17011 v8::String::NewFromUtf8(context->GetIsolate(), "stack-trace-test"); |
17000 v8::Script::New(src, origin)->Run(); | 17012 v8::ScriptCompiler::CompileContextUnbound( |
| 17013 context->GetIsolate(), |
| 17014 v8::ScriptCompiler::Source(src, v8::ScriptOrigin(origin)))->Run(); |
17001 CHECK(try_catch.HasCaught()); | 17015 CHECK(try_catch.HasCaught()); |
17002 v8::String::Utf8Value stack(try_catch.StackTrace()); | 17016 v8::String::Utf8Value stack(try_catch.StackTrace()); |
17003 CHECK(strstr(*stack, "at foo (stack-trace-test") != NULL); | 17017 CHECK(strstr(*stack, "at foo (stack-trace-test") != NULL); |
17004 } | 17018 } |
17005 | 17019 |
17006 | 17020 |
17007 // Checks that a StackFrame has certain expected values. | 17021 // Checks that a StackFrame has certain expected values. |
17008 void checkStackFrame(const char* expected_script_name, | 17022 void checkStackFrame(const char* expected_script_name, |
17009 const char* expected_func_name, int expected_line_number, | 17023 const char* expected_func_name, int expected_line_number, |
17010 int expected_column, bool is_eval, bool is_constructor, | 17024 int expected_column, bool is_eval, bool is_constructor, |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
17097 " var y; AnalyzeStackInNativeCode(1);\n" | 17111 " var y; AnalyzeStackInNativeCode(1);\n" |
17098 "}\n" | 17112 "}\n" |
17099 "function foo() {\n" | 17113 "function foo() {\n" |
17100 "\n" | 17114 "\n" |
17101 " bar();\n" | 17115 " bar();\n" |
17102 "}\n" | 17116 "}\n" |
17103 "var x;eval('new foo();');"; | 17117 "var x;eval('new foo();');"; |
17104 v8::Handle<v8::String> overview_src = | 17118 v8::Handle<v8::String> overview_src = |
17105 v8::String::NewFromUtf8(isolate, overview_source); | 17119 v8::String::NewFromUtf8(isolate, overview_source); |
17106 v8::Handle<Value> overview_result( | 17120 v8::Handle<Value> overview_result( |
17107 v8::Script::New(overview_src, origin)->Run()); | 17121 v8::ScriptCompiler::CompileContextUnbound( |
| 17122 isolate, v8::ScriptCompiler::Source( |
| 17123 overview_src, v8::ScriptOrigin(origin)))->Run()); |
17108 CHECK(!overview_result.IsEmpty()); | 17124 CHECK(!overview_result.IsEmpty()); |
17109 CHECK(overview_result->IsObject()); | 17125 CHECK(overview_result->IsObject()); |
17110 | 17126 |
17111 // Test getting DETAILED information. | 17127 // Test getting DETAILED information. |
17112 const char *detailed_source = | 17128 const char *detailed_source = |
17113 "function bat() {AnalyzeStackInNativeCode(2);\n" | 17129 "function bat() {AnalyzeStackInNativeCode(2);\n" |
17114 "}\n" | 17130 "}\n" |
17115 "\n" | 17131 "\n" |
17116 "function baz() {\n" | 17132 "function baz() {\n" |
17117 " bat();\n" | 17133 " bat();\n" |
17118 "}\n" | 17134 "}\n" |
17119 "eval('new baz();');"; | 17135 "eval('new baz();');"; |
17120 v8::Handle<v8::String> detailed_src = | 17136 v8::Handle<v8::String> detailed_src = |
17121 v8::String::NewFromUtf8(isolate, detailed_source); | 17137 v8::String::NewFromUtf8(isolate, detailed_source); |
17122 // Make the script using a non-zero line and column offset. | 17138 // Make the script using a non-zero line and column offset. |
17123 v8::Handle<v8::Integer> line_offset = v8::Integer::New(isolate, 3); | 17139 v8::Handle<v8::Integer> line_offset = v8::Integer::New(isolate, 3); |
17124 v8::Handle<v8::Integer> column_offset = v8::Integer::New(isolate, 5); | 17140 v8::Handle<v8::Integer> column_offset = v8::Integer::New(isolate, 5); |
17125 v8::ScriptOrigin detailed_origin(origin, line_offset, column_offset); | 17141 v8::ScriptOrigin detailed_origin(origin, line_offset, column_offset); |
17126 v8::Handle<v8::Script> detailed_script( | 17142 v8::Handle<v8::ContextUnboundScript> detailed_script( |
17127 v8::Script::New(detailed_src, &detailed_origin)); | 17143 v8::ScriptCompiler::CompileContextUnbound( |
| 17144 isolate, v8::ScriptCompiler::Source(detailed_src, detailed_origin))); |
17128 v8::Handle<Value> detailed_result(detailed_script->Run()); | 17145 v8::Handle<Value> detailed_result(detailed_script->Run()); |
17129 CHECK(!detailed_result.IsEmpty()); | 17146 CHECK(!detailed_result.IsEmpty()); |
17130 CHECK(detailed_result->IsObject()); | 17147 CHECK(detailed_result->IsObject()); |
17131 } | 17148 } |
17132 | 17149 |
17133 | 17150 |
17134 static void StackTraceForUncaughtExceptionListener( | 17151 static void StackTraceForUncaughtExceptionListener( |
17135 v8::Handle<v8::Message> message, | 17152 v8::Handle<v8::Message> message, |
17136 v8::Handle<Value>) { | 17153 v8::Handle<Value>) { |
17137 v8::Handle<v8::StackTrace> stack_trace = message->GetStackTrace(); | 17154 v8::Handle<v8::StackTrace> stack_trace = message->GetStackTrace(); |
(...skipping 4968 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
22106 new v8::internal::HistogramTimer( | 22123 new v8::internal::HistogramTimer( |
22107 "V8.Test", 0, 10000, 50, | 22124 "V8.Test", 0, 10000, 50, |
22108 reinterpret_cast<v8::internal::Isolate*>(isolate)); | 22125 reinterpret_cast<v8::internal::Isolate*>(isolate)); |
22109 histogramTimer->Start(); | 22126 histogramTimer->Start(); |
22110 CHECK_EQ("V8.Test", last_event_message); | 22127 CHECK_EQ("V8.Test", last_event_message); |
22111 CHECK_EQ(0, last_event_status); | 22128 CHECK_EQ(0, last_event_status); |
22112 histogramTimer->Stop(); | 22129 histogramTimer->Stop(); |
22113 CHECK_EQ("V8.Test", last_event_message); | 22130 CHECK_EQ("V8.Test", last_event_message); |
22114 CHECK_EQ(1, last_event_status); | 22131 CHECK_EQ(1, last_event_status); |
22115 } | 22132 } |
OLD | NEW |