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

Unified Diff: test/cctest/test-api.cc

Issue 234953002: Fail the compilation if the cached data is invalid. (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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/parser.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-api.cc
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index 778bf49597022ff6b6d405430dbb5a40d50ddc0c..9761e039dead5530873ab264135c9f9380fed652 100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -14858,10 +14858,7 @@ TEST(PreCompileDeserializationError) {
const char* data = "DONT CARE";
int invalid_size = 3;
i::ScriptData* sd = i::ScriptData::New(data, invalid_size);
-
- CHECK_EQ(0, sd->Length());
-
- delete sd;
+ CHECK_EQ(NULL, sd);
}
@@ -14911,16 +14908,18 @@ TEST(CompileWithInvalidCachedData) {
v8::ScriptCompiler::CompileUnbound(isolate, &source2);
CHECK(try_catch.HasCaught());
- String::Utf8Value exception_value(try_catch.Message()->Get());
- CHECK_EQ("Uncaught SyntaxError: Invalid preparser data for function bar",
- *exception_value);
+ {
+ String::Utf8Value exception_value(try_catch.Message()->Get());
+ CHECK_EQ("Uncaught SyntaxError: Invalid cached data for function bar",
+ *exception_value);
+ }
try_catch.Reset();
delete sd;
- // Overwrite function bar's start position with 200. The function entry
- // will not be found when searching for it by position and we should fall
- // back on eager compilation.
+ // Overwrite function bar's start position with 200. The function entry will
+ // not be found when searching for it by position, and the compilation fails.
+
// ScriptData does not take ownership of the buffers passed to it.
sd = i::ScriptData::New(reinterpret_cast<const char*>(cd->data), cd->length);
sd_data = reinterpret_cast<unsigned*>(const_cast<char*>(sd->Data()));
@@ -14934,7 +14933,34 @@ TEST(CompileWithInvalidCachedData) {
reinterpret_cast<const uint8_t*>(sd->Data()), sd->Length()));
compiled_script =
v8::ScriptCompiler::CompileUnbound(isolate, &source3);
- CHECK(!try_catch.HasCaught());
+ CHECK(try_catch.HasCaught());
+ {
+ String::Utf8Value exception_value(try_catch.Message()->Get());
+ CHECK_EQ("Uncaught SyntaxError: Invalid cached data for function bar",
+ *exception_value);
+ }
+ CHECK(compiled_script.IsEmpty());
+ try_catch.Reset();
+ delete sd;
+
+ // Try passing in cached data which is obviously invalid (wrong length).
+ sd = i::ScriptData::New(reinterpret_cast<const char*>(cd->data), cd->length);
+ const char* script4 =
+ "function foo(){ return 8;}\n"
+ "function bar(){ return 6 + 7;} foo();";
+ v8::ScriptCompiler::Source source4(
+ v8_str(script4),
+ new v8::ScriptCompiler::CachedData(
+ reinterpret_cast<const uint8_t*>(sd->Data()), sd->Length() - 1));
+ compiled_script =
+ v8::ScriptCompiler::CompileUnbound(isolate, &source4);
+ CHECK(try_catch.HasCaught());
+ {
+ String::Utf8Value exception_value(try_catch.Message()->Get());
+ CHECK_EQ("Uncaught SyntaxError: Invalid cached data",
+ *exception_value);
+ }
+ CHECK(compiled_script.IsEmpty());
delete sd;
}
« no previous file with comments | « src/parser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698