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

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

Issue 394793002: Verify that source string matches serialized code. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 5 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/serialize.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-serialize.cc
diff --git a/test/cctest/test-serialize.cc b/test/cctest/test-serialize.cc
index f025d8f26c152d7952e2043b24a1ea590a13ec32..135a915585ab58154355f9dc6b5dc9331437102c 100644
--- a/test/cctest/test-serialize.cc
+++ b/test/cctest/test-serialize.cc
@@ -32,6 +32,7 @@
#include "src/v8.h"
#include "src/bootstrapper.h"
+#include "src/compilation-cache.h"
#include "src/debug.h"
#include "src/ic-inl.h"
#include "src/natives.h"
@@ -678,36 +679,41 @@ int CountBuiltins() {
TEST(SerializeToplevelOnePlusOne) {
FLAG_serialize_toplevel = true;
LocalContext context;
- v8::HandleScope scope(CcTest::isolate());
+ Isolate* isolate = CcTest::i_isolate();
+ isolate->compilation_cache()->Disable(); // Disable same-isolate code cache.
- const char* source1 = "1 + 1";
- const char* source2 = "1 + 2"; // Use alternate string to verify caching.
+ v8::HandleScope scope(CcTest::isolate());
- Isolate* isolate = CcTest::i_isolate();
- Handle<String> source1_string = isolate->factory()
- ->NewStringFromUtf8(CStrVector(source1))
- .ToHandleChecked();
+ const char* source = "1 + 1";
- Handle<String> source2_string = isolate->factory()
- ->NewStringFromUtf8(CStrVector(source2))
- .ToHandleChecked();
+ Handle<String> orig_source = isolate->factory()
+ ->NewStringFromUtf8(CStrVector(source))
+ .ToHandleChecked();
+ Handle<String> copy_source = isolate->factory()
+ ->NewStringFromUtf8(CStrVector(source))
+ .ToHandleChecked();
+ CHECK(!orig_source.is_identical_to(copy_source));
+ CHECK(orig_source->Equals(*copy_source));
ScriptData* cache = NULL;
Handle<SharedFunctionInfo> orig =
- Compiler::CompileScript(source1_string, Handle<String>(), 0, 0, false,
+ Compiler::CompileScript(orig_source, Handle<String>(), 0, 0, false,
Handle<Context>(isolate->native_context()), NULL,
&cache, PRODUCE_CACHED_DATA, NOT_NATIVES_CODE);
int builtins_count = CountBuiltins();
- Handle<SharedFunctionInfo> copy =
- Compiler::CompileScript(source2_string, Handle<String>(), 0, 0, false,
- Handle<Context>(isolate->native_context()), NULL,
- &cache, CONSUME_CACHED_DATA, NOT_NATIVES_CODE);
-
+ Handle<SharedFunctionInfo> copy;
+ {
+ DisallowCompilation no_compile_expected(isolate);
mvstanton 2014/07/15 14:54:31 Elegant!
+ copy = Compiler::CompileScript(copy_source, Handle<String>(), 0, 0, false,
+ Handle<Context>(isolate->native_context()),
+ NULL, &cache, CONSUME_CACHED_DATA,
+ NOT_NATIVES_CODE);
+ }
CHECK_NE(*orig, *copy);
- CHECK(Script::cast(copy->script())->source() == *source2_string);
+ CHECK(Script::cast(copy->script())->source() == *copy_source);
Handle<JSFunction> copy_fun =
isolate->factory()->NewFunctionFromSharedFunctionInfo(
@@ -726,24 +732,27 @@ TEST(SerializeToplevelOnePlusOne) {
TEST(SerializeToplevelInternalizedString) {
FLAG_serialize_toplevel = true;
LocalContext context;
+ Isolate* isolate = CcTest::i_isolate();
+ isolate->compilation_cache()->Disable(); // Disable same-isolate code cache.
+
v8::HandleScope scope(CcTest::isolate());
- const char* source1 = "'string1'";
- const char* source2 = "'string2'"; // Use alternate string to verify caching.
+ const char* source = "'string1'";
- Isolate* isolate = CcTest::i_isolate();
- Handle<String> source1_string = isolate->factory()
- ->NewStringFromUtf8(CStrVector(source1))
- .ToHandleChecked();
+ Handle<String> orig_source = isolate->factory()
+ ->NewStringFromUtf8(CStrVector(source))
+ .ToHandleChecked();
+ Handle<String> copy_source = isolate->factory()
+ ->NewStringFromUtf8(CStrVector(source))
+ .ToHandleChecked();
+ CHECK(!orig_source.is_identical_to(copy_source));
+ CHECK(orig_source->Equals(*copy_source));
- Handle<String> source2_string = isolate->factory()
- ->NewStringFromUtf8(CStrVector(source2))
- .ToHandleChecked();
Handle<JSObject> global(isolate->context()->global_object());
ScriptData* cache = NULL;
Handle<SharedFunctionInfo> orig =
- Compiler::CompileScript(source1_string, Handle<String>(), 0, 0, false,
+ Compiler::CompileScript(orig_source, Handle<String>(), 0, 0, false,
Handle<Context>(isolate->native_context()), NULL,
&cache, PRODUCE_CACHED_DATA, NOT_NATIVES_CODE);
Handle<JSFunction> orig_fun =
@@ -755,12 +764,16 @@ TEST(SerializeToplevelInternalizedString) {
int builtins_count = CountBuiltins();
- Handle<SharedFunctionInfo> copy =
- Compiler::CompileScript(source2_string, Handle<String>(), 0, 0, false,
- Handle<Context>(isolate->native_context()), NULL,
- &cache, CONSUME_CACHED_DATA, NOT_NATIVES_CODE);
+ Handle<SharedFunctionInfo> copy;
+ {
+ DisallowCompilation no_compile_expected(isolate);
+ copy = Compiler::CompileScript(copy_source, Handle<String>(), 0, 0, false,
+ Handle<Context>(isolate->native_context()),
+ NULL, &cache, CONSUME_CACHED_DATA,
+ NOT_NATIVES_CODE);
+ }
CHECK_NE(*orig, *copy);
- CHECK(Script::cast(copy->script())->source() == *source2_string);
+ CHECK(Script::cast(copy->script())->source() == *copy_source);
Handle<JSFunction> copy_fun =
isolate->factory()->NewFunctionFromSharedFunctionInfo(
« no previous file with comments | « src/serialize.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698