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

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

Issue 225753004: Remove the PreCompile API and ScriptData. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: rebased Created 6 years, 8 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 | « src/parser.cc ('k') | test/cctest/test-parsing.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 14823 matching lines...) Expand 10 before | Expand all | Expand 10 after
14834 const char* script = "function foo(a) { return a+1; }"; 14834 const char* script = "function foo(a) { return a+1; }";
14835 v8::ScriptCompiler::Source source(v8_str(script)); 14835 v8::ScriptCompiler::Source source(v8_str(script));
14836 v8::ScriptCompiler::Compile(isolate, &source, 14836 v8::ScriptCompiler::Compile(isolate, &source,
14837 v8::ScriptCompiler::kProduceDataToCache); 14837 v8::ScriptCompiler::kProduceDataToCache);
14838 // Serialize. 14838 // Serialize.
14839 const v8::ScriptCompiler::CachedData* cd = source.GetCachedData(); 14839 const v8::ScriptCompiler::CachedData* cd = source.GetCachedData();
14840 char* serialized_data = i::NewArray<char>(cd->length); 14840 char* serialized_data = i::NewArray<char>(cd->length);
14841 i::OS::MemCopy(serialized_data, cd->data, cd->length); 14841 i::OS::MemCopy(serialized_data, cd->data, cd->length);
14842 14842
14843 // Deserialize. 14843 // Deserialize.
14844 v8::ScriptData* deserialized = 14844 i::ScriptData* deserialized = i::ScriptData::New(serialized_data, cd->length);
14845 v8::ScriptData::New(serialized_data, cd->length);
14846 14845
14847 // Verify that the original is the same as the deserialized. 14846 // Verify that the original is the same as the deserialized.
14848 CHECK_EQ(cd->length, deserialized->Length()); 14847 CHECK_EQ(cd->length, deserialized->Length());
14849 CHECK_EQ(0, memcmp(cd->data, deserialized->Data(), cd->length)); 14848 CHECK_EQ(0, memcmp(cd->data, deserialized->Data(), cd->length));
14850 14849
14851 delete deserialized; 14850 delete deserialized;
14852 i::DeleteArray(serialized_data); 14851 i::DeleteArray(serialized_data);
14853 } 14852 }
14854 14853
14855 14854
14856 // Attempts to deserialize bad data. 14855 // Attempts to deserialize bad data.
14857 TEST(PreCompileDeserializationError) { 14856 TEST(PreCompileDeserializationError) {
14858 v8::V8::Initialize(); 14857 v8::V8::Initialize();
14859 const char* data = "DONT CARE"; 14858 const char* data = "DONT CARE";
14860 int invalid_size = 3; 14859 int invalid_size = 3;
14861 v8::ScriptData* sd = v8::ScriptData::New(data, invalid_size); 14860 i::ScriptData* sd = i::ScriptData::New(data, invalid_size);
14862 14861
14863 CHECK_EQ(0, sd->Length()); 14862 CHECK_EQ(0, sd->Length());
14864 14863
14865 delete sd; 14864 delete sd;
14866 } 14865 }
14867 14866
14868 14867
14869 TEST(CompileWithInvalidCachedData) { 14868 TEST(CompileWithInvalidCachedData) {
14870 v8::V8::Initialize(); 14869 v8::V8::Initialize();
14871 v8::Isolate* isolate = CcTest::isolate(); 14870 v8::Isolate* isolate = CcTest::isolate();
14872 LocalContext context; 14871 LocalContext context;
14873 v8::HandleScope scope(context->GetIsolate()); 14872 v8::HandleScope scope(context->GetIsolate());
14874 i::FLAG_min_preparse_length = 0; 14873 i::FLAG_min_preparse_length = 0;
14875 14874
14876 const char* script = "function foo(){ return 5;}\n" 14875 const char* script = "function foo(){ return 5;}\n"
14877 "function bar(){ return 6 + 7;} foo();"; 14876 "function bar(){ return 6 + 7;} foo();";
14878 v8::ScriptCompiler::Source source(v8_str(script)); 14877 v8::ScriptCompiler::Source source(v8_str(script));
14879 v8::ScriptCompiler::Compile(isolate, &source, 14878 v8::ScriptCompiler::Compile(isolate, &source,
14880 v8::ScriptCompiler::kProduceDataToCache); 14879 v8::ScriptCompiler::kProduceDataToCache);
14881 // source owns its cached data. Create a ScriptData based on it. The user 14880 // source owns its cached data. Create a ScriptData based on it. The user
14882 // never needs to create ScriptDatas any more; we only need it here because we 14881 // never needs to create ScriptDatas any more; we only need it here because we
14883 // want to modify the data before passing it back. 14882 // want to modify the data before passing it back.
14884 const v8::ScriptCompiler::CachedData* cd = source.GetCachedData(); 14883 const v8::ScriptCompiler::CachedData* cd = source.GetCachedData();
14885 // ScriptData does not take ownership of the buffers passed to it. 14884 // ScriptData does not take ownership of the buffers passed to it.
14886 v8::ScriptData* sd = 14885 i::ScriptData* sd =
14887 v8::ScriptData::New(reinterpret_cast<const char*>(cd->data), cd->length); 14886 i::ScriptData::New(reinterpret_cast<const char*>(cd->data), cd->length);
14888 CHECK(!sd->HasError()); 14887 CHECK(!sd->HasError());
14889 // ScriptDataImpl private implementation details 14888 // ScriptData private implementation details
14890 const int kHeaderSize = i::PreparseDataConstants::kHeaderSize; 14889 const int kHeaderSize = i::PreparseDataConstants::kHeaderSize;
14891 const int kFunctionEntrySize = i::FunctionEntry::kSize; 14890 const int kFunctionEntrySize = i::FunctionEntry::kSize;
14892 const int kFunctionEntryStartOffset = 0; 14891 const int kFunctionEntryStartOffset = 0;
14893 const int kFunctionEntryEndOffset = 1; 14892 const int kFunctionEntryEndOffset = 1;
14894 unsigned* sd_data = 14893 unsigned* sd_data =
14895 reinterpret_cast<unsigned*>(const_cast<char*>(sd->Data())); 14894 reinterpret_cast<unsigned*>(const_cast<char*>(sd->Data()));
14896 14895
14897 // Overwrite function bar's end position with 0. 14896 // Overwrite function bar's end position with 0.
14898 sd_data[kHeaderSize + 1 * kFunctionEntrySize + kFunctionEntryEndOffset] = 0; 14897 sd_data[kHeaderSize + 1 * kFunctionEntrySize + kFunctionEntryEndOffset] = 0;
14899 v8::TryCatch try_catch; 14898 v8::TryCatch try_catch;
(...skipping 16 matching lines...) Expand all
14916 CHECK_EQ("Uncaught SyntaxError: Invalid preparser data for function bar", 14915 CHECK_EQ("Uncaught SyntaxError: Invalid preparser data for function bar",
14917 *exception_value); 14916 *exception_value);
14918 14917
14919 try_catch.Reset(); 14918 try_catch.Reset();
14920 delete sd; 14919 delete sd;
14921 14920
14922 // Overwrite function bar's start position with 200. The function entry 14921 // Overwrite function bar's start position with 200. The function entry
14923 // will not be found when searching for it by position and we should fall 14922 // will not be found when searching for it by position and we should fall
14924 // back on eager compilation. 14923 // back on eager compilation.
14925 // ScriptData does not take ownership of the buffers passed to it. 14924 // ScriptData does not take ownership of the buffers passed to it.
14926 sd = v8::ScriptData::New(reinterpret_cast<const char*>(cd->data), cd->length); 14925 sd = i::ScriptData::New(reinterpret_cast<const char*>(cd->data), cd->length);
14927 sd_data = reinterpret_cast<unsigned*>(const_cast<char*>(sd->Data())); 14926 sd_data = reinterpret_cast<unsigned*>(const_cast<char*>(sd->Data()));
14928 sd_data[kHeaderSize + 1 * kFunctionEntrySize + kFunctionEntryStartOffset] = 14927 sd_data[kHeaderSize + 1 * kFunctionEntrySize + kFunctionEntryStartOffset] =
14929 200; 14928 200;
14930 const char* script3 = "function foo(){ return 7;}\n" 14929 const char* script3 = "function foo(){ return 7;}\n"
14931 "function bar(){ return 6 + 7;} foo();"; 14930 "function bar(){ return 6 + 7;} foo();";
14932 v8::ScriptCompiler::Source source3( 14931 v8::ScriptCompiler::Source source3(
14933 v8_str(script3), 14932 v8_str(script3),
14934 new v8::ScriptCompiler::CachedData( 14933 new v8::ScriptCompiler::CachedData(
14935 reinterpret_cast<const uint8_t*>(sd->Data()), sd->Length())); 14934 reinterpret_cast<const uint8_t*>(sd->Data()), sd->Length()));
14936 compiled_script = 14935 compiled_script =
(...skipping 7459 matching lines...) Expand 10 before | Expand all | Expand 10 after
22396 "f.call(friend);"); 22395 "f.call(friend);");
22397 CHECK_EQ(2, named_access_count); 22396 CHECK_EQ(2, named_access_count);
22398 22397
22399 // Test access using Object.setPrototypeOf reflective method. 22398 // Test access using Object.setPrototypeOf reflective method.
22400 named_access_count = 0; 22399 named_access_count = 0;
22401 CompileRun("Object.setPrototypeOf(friend, {});"); 22400 CompileRun("Object.setPrototypeOf(friend, {});");
22402 CHECK_EQ(1, named_access_count); 22401 CHECK_EQ(1, named_access_count);
22403 CompileRun("Object.getPrototypeOf(friend);"); 22402 CompileRun("Object.getPrototypeOf(friend);");
22404 CHECK_EQ(2, named_access_count); 22403 CHECK_EQ(2, named_access_count);
22405 } 22404 }
OLDNEW
« no previous file with comments | « src/parser.cc ('k') | test/cctest/test-parsing.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698