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