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 14934 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 v8::ScriptCompiler::Source script_source( | 14955 Local<String> source = String::NewFromUtf8(isolate, script); |
14956 String::NewFromUtf8(isolate, script), | 14956 Local<Script> compiled_script = Script::New(source, NULL, sd); |
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 | |
14962 CHECK(try_catch.HasCaught()); | 14957 CHECK(try_catch.HasCaught()); |
14963 String::Utf8Value exception_value(try_catch.Message()->Get()); | 14958 String::Utf8Value exception_value(try_catch.Message()->Get()); |
14964 CHECK_EQ("Uncaught SyntaxError: Invalid preparser data for function bar", | 14959 CHECK_EQ("Uncaught SyntaxError: Invalid preparser data for function bar", |
14965 *exception_value); | 14960 *exception_value); |
14966 | 14961 |
14967 try_catch.Reset(); | 14962 try_catch.Reset(); |
14968 delete sd; | 14963 delete sd; |
14969 | 14964 |
14970 // Overwrite function bar's start position with 200. The function entry | 14965 // Overwrite function bar's start position with 200. The function entry |
14971 // will not be found when searching for it by position and we should fall | 14966 // will not be found when searching for it by position and we should fall |
14972 // back on eager compilation. | 14967 // back on eager compilation. |
14973 sd = v8::ScriptData::PreCompile(v8::String::NewFromUtf8( | 14968 sd = v8::ScriptData::PreCompile(v8::String::NewFromUtf8( |
14974 isolate, script, v8::String::kNormalString, i::StrLength(script))); | 14969 isolate, script, v8::String::kNormalString, i::StrLength(script))); |
14975 sd_data = reinterpret_cast<unsigned*>(const_cast<char*>(sd->Data())); | 14970 sd_data = reinterpret_cast<unsigned*>(const_cast<char*>(sd->Data())); |
14976 sd_data[kHeaderSize + 1 * kFunctionEntrySize + kFunctionEntryStartOffset] = | 14971 sd_data[kHeaderSize + 1 * kFunctionEntrySize + kFunctionEntryStartOffset] = |
14977 200; | 14972 200; |
14978 v8::ScriptCompiler::Source script_source2( | 14973 compiled_script = Script::New(source, NULL, sd); |
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); | |
14984 CHECK(!try_catch.HasCaught()); | 14974 CHECK(!try_catch.HasCaught()); |
14985 | 14975 |
14986 delete sd; | 14976 delete sd; |
14987 } | 14977 } |
14988 | 14978 |
14989 | 14979 |
14990 // This tests that we do not allow dictionary load/call inline caches | 14980 // This tests that we do not allow dictionary load/call inline caches |
14991 // to use functions that have not yet been compiled. The potential | 14981 // to use functions that have not yet been compiled. The potential |
14992 // problem of loading a function that has not yet been compiled can | 14982 // problem of loading a function that has not yet been compiled can |
14993 // arise because we share code between contexts via the compilation | 14983 // arise because we share code between contexts via the compilation |
(...skipping 2090 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
17084 #undef IS_ARRAY_BUFFER_VIEW_TEST | 17074 #undef IS_ARRAY_BUFFER_VIEW_TEST |
17085 | 17075 |
17086 | 17076 |
17087 | 17077 |
17088 THREADED_TEST(ScriptContextDependence) { | 17078 THREADED_TEST(ScriptContextDependence) { |
17089 LocalContext c1; | 17079 LocalContext c1; |
17090 v8::HandleScope scope(c1->GetIsolate()); | 17080 v8::HandleScope scope(c1->GetIsolate()); |
17091 const char *source = "foo"; | 17081 const char *source = "foo"; |
17092 v8::Handle<v8::Script> dep = | 17082 v8::Handle<v8::Script> dep = |
17093 v8_compile(source); | 17083 v8_compile(source); |
17094 v8::Handle<v8::UnboundScript> indep = | 17084 v8::Handle<v8::Script> indep = |
17095 v8::ScriptCompiler::CompileUnbound( | 17085 v8::Script::New(v8::String::NewFromUtf8(c1->GetIsolate(), source)); |
17096 c1->GetIsolate(), v8::ScriptCompiler::Source(v8::String::NewFromUtf8( | |
17097 c1->GetIsolate(), source))); | |
17098 c1->Global()->Set(v8::String::NewFromUtf8(c1->GetIsolate(), "foo"), | 17086 c1->Global()->Set(v8::String::NewFromUtf8(c1->GetIsolate(), "foo"), |
17099 v8::Integer::New(c1->GetIsolate(), 100)); | 17087 v8::Integer::New(c1->GetIsolate(), 100)); |
17100 CHECK_EQ(dep->Run()->Int32Value(), 100); | 17088 CHECK_EQ(dep->Run()->Int32Value(), 100); |
17101 CHECK_EQ(indep->BindToCurrentContext()->Run()->Int32Value(), 100); | 17089 CHECK_EQ(indep->Run()->Int32Value(), 100); |
17102 LocalContext c2; | 17090 LocalContext c2; |
17103 c2->Global()->Set(v8::String::NewFromUtf8(c2->GetIsolate(), "foo"), | 17091 c2->Global()->Set(v8::String::NewFromUtf8(c2->GetIsolate(), "foo"), |
17104 v8::Integer::New(c2->GetIsolate(), 101)); | 17092 v8::Integer::New(c2->GetIsolate(), 101)); |
17105 CHECK_EQ(dep->Run()->Int32Value(), 100); | 17093 CHECK_EQ(dep->Run()->Int32Value(), 100); |
17106 CHECK_EQ(indep->BindToCurrentContext()->Run()->Int32Value(), 101); | 17094 CHECK_EQ(indep->Run()->Int32Value(), 101); |
17107 } | 17095 } |
17108 | 17096 |
17109 | 17097 |
17110 THREADED_TEST(StackTrace) { | 17098 THREADED_TEST(StackTrace) { |
17111 LocalContext context; | 17099 LocalContext context; |
17112 v8::HandleScope scope(context->GetIsolate()); | 17100 v8::HandleScope scope(context->GetIsolate()); |
17113 v8::TryCatch try_catch; | 17101 v8::TryCatch try_catch; |
17114 const char *source = "function foo() { FAIL.FAIL; }; foo();"; | 17102 const char *source = "function foo() { FAIL.FAIL; }; foo();"; |
17115 v8::Handle<v8::String> src = | 17103 v8::Handle<v8::String> src = |
17116 v8::String::NewFromUtf8(context->GetIsolate(), source); | 17104 v8::String::NewFromUtf8(context->GetIsolate(), source); |
17117 v8::Handle<v8::String> origin = | 17105 v8::Handle<v8::String> origin = |
17118 v8::String::NewFromUtf8(context->GetIsolate(), "stack-trace-test"); | 17106 v8::String::NewFromUtf8(context->GetIsolate(), "stack-trace-test"); |
17119 v8::ScriptCompiler::CompileUnbound( | 17107 v8::Script::New(src, origin)->Run(); |
17120 context->GetIsolate(), | |
17121 v8::ScriptCompiler::Source(src, v8::ScriptOrigin(origin))) | |
17122 ->BindToCurrentContext() | |
17123 ->Run(); | |
17124 CHECK(try_catch.HasCaught()); | 17108 CHECK(try_catch.HasCaught()); |
17125 v8::String::Utf8Value stack(try_catch.StackTrace()); | 17109 v8::String::Utf8Value stack(try_catch.StackTrace()); |
17126 CHECK(strstr(*stack, "at foo (stack-trace-test") != NULL); | 17110 CHECK(strstr(*stack, "at foo (stack-trace-test") != NULL); |
17127 } | 17111 } |
17128 | 17112 |
17129 | 17113 |
17130 // Checks that a StackFrame has certain expected values. | 17114 // Checks that a StackFrame has certain expected values. |
17131 void checkStackFrame(const char* expected_script_name, | 17115 void checkStackFrame(const char* expected_script_name, |
17132 const char* expected_func_name, int expected_line_number, | 17116 const char* expected_func_name, int expected_line_number, |
17133 int expected_column, bool is_eval, bool is_constructor, | 17117 int expected_column, bool is_eval, bool is_constructor, |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
17220 " var y; AnalyzeStackInNativeCode(1);\n" | 17204 " var y; AnalyzeStackInNativeCode(1);\n" |
17221 "}\n" | 17205 "}\n" |
17222 "function foo() {\n" | 17206 "function foo() {\n" |
17223 "\n" | 17207 "\n" |
17224 " bar();\n" | 17208 " bar();\n" |
17225 "}\n" | 17209 "}\n" |
17226 "var x;eval('new foo();');"; | 17210 "var x;eval('new foo();');"; |
17227 v8::Handle<v8::String> overview_src = | 17211 v8::Handle<v8::String> overview_src = |
17228 v8::String::NewFromUtf8(isolate, overview_source); | 17212 v8::String::NewFromUtf8(isolate, overview_source); |
17229 v8::Handle<Value> overview_result( | 17213 v8::Handle<Value> overview_result( |
17230 v8::ScriptCompiler::CompileUnbound( | 17214 v8::Script::New(overview_src, origin)->Run()); |
17231 isolate, | |
17232 v8::ScriptCompiler::Source(overview_src, v8::ScriptOrigin(origin))) | |
17233 ->BindToCurrentContext() | |
17234 ->Run()); | |
17235 CHECK(!overview_result.IsEmpty()); | 17215 CHECK(!overview_result.IsEmpty()); |
17236 CHECK(overview_result->IsObject()); | 17216 CHECK(overview_result->IsObject()); |
17237 | 17217 |
17238 // Test getting DETAILED information. | 17218 // Test getting DETAILED information. |
17239 const char *detailed_source = | 17219 const char *detailed_source = |
17240 "function bat() {AnalyzeStackInNativeCode(2);\n" | 17220 "function bat() {AnalyzeStackInNativeCode(2);\n" |
17241 "}\n" | 17221 "}\n" |
17242 "\n" | 17222 "\n" |
17243 "function baz() {\n" | 17223 "function baz() {\n" |
17244 " bat();\n" | 17224 " bat();\n" |
17245 "}\n" | 17225 "}\n" |
17246 "eval('new baz();');"; | 17226 "eval('new baz();');"; |
17247 v8::Handle<v8::String> detailed_src = | 17227 v8::Handle<v8::String> detailed_src = |
17248 v8::String::NewFromUtf8(isolate, detailed_source); | 17228 v8::String::NewFromUtf8(isolate, detailed_source); |
17249 // Make the script using a non-zero line and column offset. | 17229 // Make the script using a non-zero line and column offset. |
17250 v8::Handle<v8::Integer> line_offset = v8::Integer::New(isolate, 3); | 17230 v8::Handle<v8::Integer> line_offset = v8::Integer::New(isolate, 3); |
17251 v8::Handle<v8::Integer> column_offset = v8::Integer::New(isolate, 5); | 17231 v8::Handle<v8::Integer> column_offset = v8::Integer::New(isolate, 5); |
17252 v8::ScriptOrigin detailed_origin(origin, line_offset, column_offset); | 17232 v8::ScriptOrigin detailed_origin(origin, line_offset, column_offset); |
17253 v8::Handle<v8::UnboundScript> detailed_script( | 17233 v8::Handle<v8::Script> detailed_script( |
17254 v8::ScriptCompiler::CompileUnbound( | 17234 v8::Script::New(detailed_src, &detailed_origin)); |
17255 isolate, v8::ScriptCompiler::Source(detailed_src, detailed_origin))); | 17235 v8::Handle<Value> detailed_result(detailed_script->Run()); |
17256 v8::Handle<Value> detailed_result( | |
17257 detailed_script->BindToCurrentContext()->Run()); | |
17258 CHECK(!detailed_result.IsEmpty()); | 17236 CHECK(!detailed_result.IsEmpty()); |
17259 CHECK(detailed_result->IsObject()); | 17237 CHECK(detailed_result->IsObject()); |
17260 } | 17238 } |
17261 | 17239 |
17262 | 17240 |
17263 static void StackTraceForUncaughtExceptionListener( | 17241 static void StackTraceForUncaughtExceptionListener( |
17264 v8::Handle<v8::Message> message, | 17242 v8::Handle<v8::Message> message, |
17265 v8::Handle<Value>) { | 17243 v8::Handle<Value>) { |
17266 v8::Handle<v8::StackTrace> stack_trace = message->GetStackTrace(); | 17244 v8::Handle<v8::StackTrace> stack_trace = message->GetStackTrace(); |
17267 CHECK_EQ(2, stack_trace->GetFrameCount()); | 17245 CHECK_EQ(2, stack_trace->GetFrameCount()); |
(...skipping 5061 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
22329 CompileRun("x1 = x2 = 0;"); | 22307 CompileRun("x1 = x2 = 0;"); |
22330 r = v8::Promise::New(isolate); | 22308 r = v8::Promise::New(isolate); |
22331 r->Catch(f1)->Chain(f2); | 22309 r->Catch(f1)->Chain(f2); |
22332 r->Reject(v8::Integer::New(isolate, 3)); | 22310 r->Reject(v8::Integer::New(isolate, 3)); |
22333 CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value()); | 22311 CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value()); |
22334 CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value()); | 22312 CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value()); |
22335 V8::RunMicrotasks(isolate); | 22313 V8::RunMicrotasks(isolate); |
22336 CHECK_EQ(3, global->Get(v8_str("x1"))->Int32Value()); | 22314 CHECK_EQ(3, global->Get(v8_str("x1"))->Int32Value()); |
22337 CHECK_EQ(4, global->Get(v8_str("x2"))->Int32Value()); | 22315 CHECK_EQ(4, global->Get(v8_str("x2"))->Int32Value()); |
22338 } | 22316 } |
OLD | NEW |