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:
parent
78abf9d9d9
commit
ed9191221b
@ -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());
|
||||
|
@ -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));
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
17
test/mjsunit/deserialize-script-id.js
Normal file
17
test/mjsunit/deserialize-script-id.js
Normal 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);
|
Loading…
Reference in New Issue
Block a user