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 14840 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14851 i::DeleteArray(serialized_data); | 14851 i::DeleteArray(serialized_data); |
14852 } | 14852 } |
14853 | 14853 |
14854 | 14854 |
14855 // Attempts to deserialize bad data. | 14855 // Attempts to deserialize bad data. |
14856 TEST(PreCompileDeserializationError) { | 14856 TEST(PreCompileDeserializationError) { |
14857 v8::V8::Initialize(); | 14857 v8::V8::Initialize(); |
14858 const char* data = "DONT CARE"; | 14858 const char* data = "DONT CARE"; |
14859 int invalid_size = 3; | 14859 int invalid_size = 3; |
14860 i::ScriptData* sd = i::ScriptData::New(data, invalid_size); | 14860 i::ScriptData* sd = i::ScriptData::New(data, invalid_size); |
14861 | 14861 CHECK_EQ(NULL, sd); |
14862 CHECK_EQ(0, sd->Length()); | |
14863 | |
14864 delete sd; | |
14865 } | 14862 } |
14866 | 14863 |
14867 | 14864 |
14868 TEST(CompileWithInvalidCachedData) { | 14865 TEST(CompileWithInvalidCachedData) { |
14869 v8::V8::Initialize(); | 14866 v8::V8::Initialize(); |
14870 v8::Isolate* isolate = CcTest::isolate(); | 14867 v8::Isolate* isolate = CcTest::isolate(); |
14871 LocalContext context; | 14868 LocalContext context; |
14872 v8::HandleScope scope(context->GetIsolate()); | 14869 v8::HandleScope scope(context->GetIsolate()); |
14873 i::FLAG_min_preparse_length = 0; | 14870 i::FLAG_min_preparse_length = 0; |
14874 | 14871 |
(...skipping 29 matching lines...) Expand all Loading... |
14904 v8::ScriptCompiler::Source source2( | 14901 v8::ScriptCompiler::Source source2( |
14905 v8_str(script2), | 14902 v8_str(script2), |
14906 // CachedData doesn't take ownership of the buffers, Source takes | 14903 // CachedData doesn't take ownership of the buffers, Source takes |
14907 // ownership of CachedData. | 14904 // ownership of CachedData. |
14908 new v8::ScriptCompiler::CachedData( | 14905 new v8::ScriptCompiler::CachedData( |
14909 reinterpret_cast<const uint8_t*>(sd->Data()), sd->Length())); | 14906 reinterpret_cast<const uint8_t*>(sd->Data()), sd->Length())); |
14910 Local<v8::UnboundScript> compiled_script = | 14907 Local<v8::UnboundScript> compiled_script = |
14911 v8::ScriptCompiler::CompileUnbound(isolate, &source2); | 14908 v8::ScriptCompiler::CompileUnbound(isolate, &source2); |
14912 | 14909 |
14913 CHECK(try_catch.HasCaught()); | 14910 CHECK(try_catch.HasCaught()); |
14914 String::Utf8Value exception_value(try_catch.Message()->Get()); | 14911 { |
14915 CHECK_EQ("Uncaught SyntaxError: Invalid preparser data for function bar", | 14912 String::Utf8Value exception_value(try_catch.Message()->Get()); |
14916 *exception_value); | 14913 CHECK_EQ("Uncaught SyntaxError: Invalid cached data for function bar", |
| 14914 *exception_value); |
| 14915 } |
14917 | 14916 |
14918 try_catch.Reset(); | 14917 try_catch.Reset(); |
14919 delete sd; | 14918 delete sd; |
14920 | 14919 |
14921 // Overwrite function bar's start position with 200. The function entry | 14920 // Overwrite function bar's start position with 200. The function entry will |
14922 // will not be found when searching for it by position and we should fall | 14921 // not be found when searching for it by position, and the compilation fails. |
14923 // back on eager compilation. | 14922 |
14924 // ScriptData does not take ownership of the buffers passed to it. | 14923 // ScriptData does not take ownership of the buffers passed to it. |
14925 sd = i::ScriptData::New(reinterpret_cast<const char*>(cd->data), cd->length); | 14924 sd = i::ScriptData::New(reinterpret_cast<const char*>(cd->data), cd->length); |
14926 sd_data = reinterpret_cast<unsigned*>(const_cast<char*>(sd->Data())); | 14925 sd_data = reinterpret_cast<unsigned*>(const_cast<char*>(sd->Data())); |
14927 sd_data[kHeaderSize + 1 * kFunctionEntrySize + kFunctionEntryStartOffset] = | 14926 sd_data[kHeaderSize + 1 * kFunctionEntrySize + kFunctionEntryStartOffset] = |
14928 200; | 14927 200; |
14929 const char* script3 = "function foo(){ return 7;}\n" | 14928 const char* script3 = "function foo(){ return 7;}\n" |
14930 "function bar(){ return 6 + 7;} foo();"; | 14929 "function bar(){ return 6 + 7;} foo();"; |
14931 v8::ScriptCompiler::Source source3( | 14930 v8::ScriptCompiler::Source source3( |
14932 v8_str(script3), | 14931 v8_str(script3), |
14933 new v8::ScriptCompiler::CachedData( | 14932 new v8::ScriptCompiler::CachedData( |
14934 reinterpret_cast<const uint8_t*>(sd->Data()), sd->Length())); | 14933 reinterpret_cast<const uint8_t*>(sd->Data()), sd->Length())); |
14935 compiled_script = | 14934 compiled_script = |
14936 v8::ScriptCompiler::CompileUnbound(isolate, &source3); | 14935 v8::ScriptCompiler::CompileUnbound(isolate, &source3); |
14937 CHECK(!try_catch.HasCaught()); | 14936 CHECK(try_catch.HasCaught()); |
| 14937 { |
| 14938 String::Utf8Value exception_value(try_catch.Message()->Get()); |
| 14939 CHECK_EQ("Uncaught SyntaxError: Invalid cached data for function bar", |
| 14940 *exception_value); |
| 14941 } |
| 14942 CHECK(compiled_script.IsEmpty()); |
| 14943 try_catch.Reset(); |
| 14944 delete sd; |
| 14945 |
| 14946 // Try passing in cached data which is obviously invalid (wrong length). |
| 14947 sd = i::ScriptData::New(reinterpret_cast<const char*>(cd->data), cd->length); |
| 14948 const char* script4 = |
| 14949 "function foo(){ return 8;}\n" |
| 14950 "function bar(){ return 6 + 7;} foo();"; |
| 14951 v8::ScriptCompiler::Source source4( |
| 14952 v8_str(script4), |
| 14953 new v8::ScriptCompiler::CachedData( |
| 14954 reinterpret_cast<const uint8_t*>(sd->Data()), sd->Length() - 1)); |
| 14955 compiled_script = |
| 14956 v8::ScriptCompiler::CompileUnbound(isolate, &source4); |
| 14957 CHECK(try_catch.HasCaught()); |
| 14958 { |
| 14959 String::Utf8Value exception_value(try_catch.Message()->Get()); |
| 14960 CHECK_EQ("Uncaught SyntaxError: Invalid cached data", |
| 14961 *exception_value); |
| 14962 } |
| 14963 CHECK(compiled_script.IsEmpty()); |
14938 delete sd; | 14964 delete sd; |
14939 } | 14965 } |
14940 | 14966 |
14941 | 14967 |
14942 // This tests that we do not allow dictionary load/call inline caches | 14968 // This tests that we do not allow dictionary load/call inline caches |
14943 // to use functions that have not yet been compiled. The potential | 14969 // to use functions that have not yet been compiled. The potential |
14944 // problem of loading a function that has not yet been compiled can | 14970 // problem of loading a function that has not yet been compiled can |
14945 // arise because we share code between contexts via the compilation | 14971 // arise because we share code between contexts via the compilation |
14946 // cache. | 14972 // cache. |
14947 THREADED_TEST(DictionaryICLoadedFunction) { | 14973 THREADED_TEST(DictionaryICLoadedFunction) { |
(...skipping 7447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
22395 "f.call(friend);"); | 22421 "f.call(friend);"); |
22396 CHECK_EQ(2, named_access_count); | 22422 CHECK_EQ(2, named_access_count); |
22397 | 22423 |
22398 // Test access using Object.setPrototypeOf reflective method. | 22424 // Test access using Object.setPrototypeOf reflective method. |
22399 named_access_count = 0; | 22425 named_access_count = 0; |
22400 CompileRun("Object.setPrototypeOf(friend, {});"); | 22426 CompileRun("Object.setPrototypeOf(friend, {});"); |
22401 CHECK_EQ(1, named_access_count); | 22427 CHECK_EQ(1, named_access_count); |
22402 CompileRun("Object.getPrototypeOf(friend);"); | 22428 CompileRun("Object.getPrototypeOf(friend);"); |
22403 CHECK_EQ(2, named_access_count); | 22429 CHECK_EQ(2, named_access_count); |
22404 } | 22430 } |
OLD | NEW |