Commit e730d088 authored by jgruber's avatar jgruber Committed by Commit bot

Simplify accesses to Script::line_ends

line_ends is either undefined (if uninitialized) or a fixed array (after
Script::InitLineEnds). All accesses from JS have been removed, therefore
we can skip assigning a COW map and remove the accessor.

Review-Url: https://codereview.chromium.org/2490903002
Cr-Commit-Position: refs/heads/master@{#40876}
parent fab116be
......@@ -468,40 +468,6 @@ Handle<AccessorInfo> Accessors::ScriptCompilationTypeInfo(
}
//
// Accessors::ScriptGetLineEnds
//
void Accessors::ScriptLineEndsGetter(
v8::Local<v8::Name> name,
const v8::PropertyCallbackInfo<v8::Value>& info) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
HandleScope scope(isolate);
Handle<Object> object = Utils::OpenHandle(*info.Holder());
Handle<Script> script(
Script::cast(Handle<JSValue>::cast(object)->value()), isolate);
Script::InitLineEnds(script);
DCHECK(script->line_ends()->IsFixedArray());
Handle<FixedArray> line_ends(FixedArray::cast(script->line_ends()));
// We do not want anyone to modify this array from JS.
DCHECK(*line_ends == isolate->heap()->empty_fixed_array() ||
line_ends->map() == isolate->heap()->fixed_cow_array_map());
Handle<JSArray> js_array =
isolate->factory()->NewJSArrayWithElements(line_ends);
info.GetReturnValue().Set(Utils::ToLocal(js_array));
}
Handle<AccessorInfo> Accessors::ScriptLineEndsInfo(
Isolate* isolate, PropertyAttributes attributes) {
Handle<String> name(isolate->factory()->InternalizeOneByteString(
STATIC_CHAR_VECTOR("line_ends")));
return MakeAccessor(isolate, name, &ScriptLineEndsGetter, nullptr,
attributes);
}
//
// Accessors::ScriptSourceUrl
//
......
......@@ -37,7 +37,6 @@ class AccessorInfo;
V(ScriptEvalFromScriptPosition) \
V(ScriptEvalFromFunctionName) \
V(ScriptId) \
V(ScriptLineEnds) \
V(ScriptLineOffset) \
V(ScriptName) \
V(ScriptSource) \
......
......@@ -8880,22 +8880,16 @@ int DebugInterface::Script::ColumnOffset() const {
}
std::vector<int> DebugInterface::Script::LineEnds() const {
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
i::Handle<i::Script> script = Utils::OpenHandle(this);
i::Isolate* isolate = script->GetIsolate();
i::HandleScope scope(isolate);
i::Script::InitLineEnds(Utils::OpenHandle(this));
i::Handle<i::Object> line_ends_obj(Utils::OpenHandle(this)->line_ends(),
isolate);
std::vector<int> result;
if (!line_ends_obj->IsFixedArray()) return result;
i::Handle<i::FixedArray> line_ends =
i::Handle<i::FixedArray>::cast(line_ends_obj);
i::Script::InitLineEnds(script);
CHECK(script->line_ends()->IsFixedArray());
i::Handle<i::FixedArray> line_ends(i::FixedArray::cast(script->line_ends()));
std::vector<int> result(line_ends->length());
for (int i = 0; i < line_ends->length(); ++i) {
i::Handle<i::Object> line_end = i::FixedArray::get(*line_ends, i, isolate);
if (line_end->IsSmi()) {
result.push_back(i::Handle<i::Smi>::cast(line_end)->value());
} else {
result.push_back(0);
}
i::Smi* line_end = i::Smi::cast(line_ends->get(i));
result[i] = line_end->value();
}
return result;
}
......
......@@ -3030,15 +3030,6 @@ void Bootstrapper::ExportFromRuntime(Isolate* isolate,
script_map->AppendDescriptor(&d);
}
Handle<AccessorInfo> script_line_ends =
Accessors::ScriptLineEndsInfo(isolate, attribs);
{
AccessorConstantDescriptor d(
Handle<Name>(Name::cast(script_line_ends->name())), script_line_ends,
attribs);
script_map->AppendDescriptor(&d);
}
Handle<AccessorInfo> script_context_data =
Accessors::ScriptContextDataInfo(isolate, attribs);
{
......
......@@ -241,7 +241,6 @@ var SourceLocation;
* source_mapping_url: (string|undefined),
* is_debugger_script: boolean,
* source: string,
* line_ends: !Array<number>,
* line_offset: number,
* column_offset: number,
* nameOrSourceURL: function():string,
......
......@@ -13375,23 +13375,17 @@ void Script::InitLineEnds(Handle<Script> script) {
Isolate* isolate = script->GetIsolate();
if (!script->line_ends()->IsUndefined(isolate)) return;
if (!script->source()->IsString()) {
DCHECK(script->source()->IsUndefined(isolate));
Handle<FixedArray> empty = isolate->factory()->NewFixedArray(0);
script->set_line_ends(*empty);
DCHECK(script->line_ends()->IsFixedArray());
return;
}
Handle<String> src(String::cast(script->source()), isolate);
Handle<FixedArray> array = String::CalculateLineEnds(src, true);
if (*array != isolate->heap()->empty_fixed_array()) {
array->set_map(isolate->heap()->fixed_cow_array_map());
Object* src_obj = script->source();
if (!src_obj->IsString()) {
DCHECK(src_obj->IsUndefined(isolate));
script->set_line_ends(isolate->heap()->empty_fixed_array());
} else {
DCHECK(src_obj->IsString());
Handle<String> src(String::cast(src_obj), isolate);
Handle<FixedArray> array = String::CalculateLineEnds(src, true);
script->set_line_ends(*array);
}
script->set_line_ends(*array);
DCHECK(script->line_ends()->IsFixedArray());
}
......
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