Serializer: ensure unique script ids when deserializing.

R=jochen@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#27471}
This commit is contained in:
yangguo 2015-03-26 02:50:34 -07:00 committed by Commit bot
parent 78abf9d9d9
commit ed9191221b
6 changed files with 32 additions and 7 deletions

View File

@ -825,17 +825,12 @@ Handle<ExecutableAccessorInfo> Factory::NewExecutableAccessorInfo() {
Handle<Script> Factory::NewScript(Handle<String> source) {
// Generate id for this script.
Heap* heap = isolate()->heap();
int id = heap->last_script_id()->value() + 1;
if (!Smi::IsValid(id) || id < 0) id = 1;
heap->set_last_script_id(Smi::FromInt(id));
// Create and initialize script object.
Heap* heap = isolate()->heap();
Handle<Script> script = Handle<Script>::cast(NewStruct(SCRIPT_TYPE));
script->set_source(*source);
script->set_name(heap->undefined_value());
script->set_id(Smi::FromInt(id));
script->set_id(isolate()->heap()->NextScriptId());
script->set_line_offset(Smi::FromInt(0));
script->set_column_offset(Smi::FromInt(0));
script->set_context_data(heap->undefined_value());

View File

@ -1349,6 +1349,14 @@ class Heap {
return seed;
}
Smi* NextScriptId() {
int next_id = last_script_id()->value() + 1;
if (!Smi::IsValid(next_id) || next_id < 0) next_id = 1;
Smi* next_id_smi = Smi::FromInt(next_id);
set_last_script_id(next_id_smi);
return next_id_smi;
}
void SetArgumentsAdaptorDeoptPCOffset(int pc_offset) {
DCHECK(arguments_adaptor_deopt_pc_offset() == Smi::FromInt(0));
set_arguments_adaptor_deopt_pc_offset(Smi::FromInt(pc_offset));

View File

@ -2329,6 +2329,7 @@ RUNTIME_FUNCTION(Runtime_DebugGetLoadedScripts) {
HandleScope scope(isolate);
DCHECK(args.length() == 0);
DebugScope debug_scope(isolate->debug());
// Fill the script objects.
Handle<FixedArray> instances = isolate->debug()->GetLoadedScripts();

View File

@ -720,6 +720,8 @@ HeapObject* Deserializer::ProcessNewObjectFromSerializedCode(HeapObject* obj) {
string->SetForwardedInternalizedString(canonical);
return canonical;
}
} else if (obj->IsScript()) {
Script::cast(obj)->set_id(isolate_->heap()->NextScriptId());
}
return obj;
}

View File

@ -29,6 +29,8 @@
// Get the Debug object exposed from the debug context global object.
Debug = debug.Debug
Debug.setListener(function() {});
function f() {a=1;b=2}
function g() {
a=1;

View File

@ -0,0 +1,17 @@
// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --allow-natives-syntax --cache=code
// Test that script ids are unique and we found the correct ones.
var scripts = %DebugGetLoadedScripts();
scripts.sort(function(a, b) { return a.id - b.id; });
var user_script_count = 0;
scripts.reduce(function(prev, cur) {
assertTrue(prev === undefined || prev.id != cur.id);
if (cur.type == 2) user_script_count++;
});
// Found mjsunit.js and this script.
assertEquals(2, user_script_count);