Commit f0e3ae8e authored by yangguo@chromium.org's avatar yangguo@chromium.org

Prohibit serializing with --harmony-scoping.

R=jochen@chromium.org
BUG=v8:3628
LOG=N

Review URL: https://codereview.chromium.org/650423005

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@24686 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent a7791502
......@@ -1226,7 +1226,10 @@ Handle<SharedFunctionInfo> Compiler::CompileScript(
result = CompileToplevel(&info);
if (extension == NULL && !result.is_null() && !result->dont_cache()) {
compilation_cache->PutScript(source, context, result);
if (FLAG_serialize_toplevel &&
// TODO(yangguo): Issue 3628
// With block scoping, top-level variables may resolve to a global,
// context, which makes the code context-dependent.
if (FLAG_serialize_toplevel && !FLAG_harmony_scoping &&
compile_options == ScriptCompiler::kProduceCodeCache) {
HistogramTimerScope histogram_timer(
isolate->counters()->compile_serialize());
......
......@@ -29,6 +29,7 @@
[ALWAYS, {
# All tests prefixed with 'Bug' are expected to fail.
'test-api/Bug*': [FAIL],
'test-serialize/Bug*': [FAIL],
##############################################################################
......
......@@ -1181,6 +1181,7 @@ TEST(SerializeToplevelIsolates) {
v8::Local<v8::UnboundScript> script = v8::ScriptCompiler::CompileUnbound(
isolate1, &source, v8::ScriptCompiler::kProduceCodeCache);
const v8::ScriptCompiler::CachedData* data = source.GetCachedData();
CHECK(data);
// Persist cached data.
uint8_t* buffer = NewArray<uint8_t>(data->length);
MemCopy(buffer, data->data, data->length);
......@@ -1213,3 +1214,67 @@ TEST(SerializeToplevelIsolates) {
}
isolate2->Dispose();
}
TEST(Bug3628) {
FLAG_serialize_toplevel = true;
FLAG_harmony_scoping = true;
const char* source1 = "'use strict'; let x = 'X'";
const char* source2 = "'use strict'; let y = 'Y'";
const char* source3 = "'use strict'; x + y";
v8::ScriptCompiler::CachedData* cache;
v8::Isolate* isolate1 = v8::Isolate::New();
{
v8::Isolate::Scope iscope(isolate1);
v8::HandleScope scope(isolate1);
v8::Local<v8::Context> context = v8::Context::New(isolate1);
v8::Context::Scope context_scope(context);
CompileRun(source1);
CompileRun(source2);
v8::Local<v8::String> source_str = v8_str(source3);
v8::ScriptOrigin origin(v8_str("test"));
v8::ScriptCompiler::Source source(source_str, origin);
v8::Local<v8::UnboundScript> script = v8::ScriptCompiler::CompileUnbound(
isolate1, &source, v8::ScriptCompiler::kProduceCodeCache);
const v8::ScriptCompiler::CachedData* data = source.GetCachedData();
// Persist cached data.
uint8_t* buffer = NewArray<uint8_t>(data->length);
MemCopy(buffer, data->data, data->length);
cache = new v8::ScriptCompiler::CachedData(
buffer, data->length, v8::ScriptCompiler::CachedData::BufferOwned);
v8::Local<v8::Value> result = script->BindToCurrentContext()->Run();
CHECK(result->ToString()->Equals(v8_str("XY")));
}
isolate1->Dispose();
v8::Isolate* isolate2 = v8::Isolate::New();
{
v8::Isolate::Scope iscope(isolate2);
v8::HandleScope scope(isolate2);
v8::Local<v8::Context> context = v8::Context::New(isolate2);
v8::Context::Scope context_scope(context);
// Reverse order of prior running scripts.
CompileRun(source2);
CompileRun(source1);
v8::Local<v8::String> source_str = v8_str(source3);
v8::ScriptOrigin origin(v8_str("test"));
v8::ScriptCompiler::Source source(source_str, origin, cache);
v8::Local<v8::UnboundScript> script;
{
DisallowCompilation no_compile(reinterpret_cast<Isolate*>(isolate2));
script = v8::ScriptCompiler::CompileUnbound(
isolate2, &source, v8::ScriptCompiler::kConsumeCodeCache);
}
v8::Local<v8::Value> result = script->BindToCurrentContext()->Run();
CHECK(result->ToString()->Equals(v8_str("XY")));
}
isolate2->Dispose();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment