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

Side by Side Diff: src/objects.cc

Issue 2490903002: Simplify accesses to Script::line_ends (Closed)
Patch Set: Address comments Created 4 years, 1 month 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 unified diff | Download patch
« no previous file with comments | « src/inspector/debugger_script_externs.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/objects.h" 5 #include "src/objects.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <iomanip> 8 #include <iomanip>
9 #include <memory> 9 #include <memory>
10 #include <sstream> 10 #include <sstream>
(...skipping 13357 matching lines...) Expand 10 before | Expand all | Expand 10 after
13368 DCHECK(position >= 0); 13368 DCHECK(position >= 0);
13369 set_eval_from_position(position); 13369 set_eval_from_position(position);
13370 } 13370 }
13371 return position; 13371 return position;
13372 } 13372 }
13373 13373
13374 void Script::InitLineEnds(Handle<Script> script) { 13374 void Script::InitLineEnds(Handle<Script> script) {
13375 Isolate* isolate = script->GetIsolate(); 13375 Isolate* isolate = script->GetIsolate();
13376 if (!script->line_ends()->IsUndefined(isolate)) return; 13376 if (!script->line_ends()->IsUndefined(isolate)) return;
13377 13377
13378 if (!script->source()->IsString()) { 13378 Object* src_obj = script->source();
13379 DCHECK(script->source()->IsUndefined(isolate)); 13379 if (!src_obj->IsString()) {
13380 Handle<FixedArray> empty = isolate->factory()->NewFixedArray(0); 13380 DCHECK(src_obj->IsUndefined(isolate));
13381 script->set_line_ends(*empty); 13381 script->set_line_ends(isolate->heap()->empty_fixed_array());
13382 DCHECK(script->line_ends()->IsFixedArray()); 13382 } else {
13383 return; 13383 DCHECK(src_obj->IsString());
13384 Handle<String> src(String::cast(src_obj), isolate);
13385 Handle<FixedArray> array = String::CalculateLineEnds(src, true);
13386 script->set_line_ends(*array);
13384 } 13387 }
13385 13388
13386 Handle<String> src(String::cast(script->source()), isolate);
13387
13388 Handle<FixedArray> array = String::CalculateLineEnds(src, true);
13389
13390 if (*array != isolate->heap()->empty_fixed_array()) {
13391 array->set_map(isolate->heap()->fixed_cow_array_map());
13392 }
13393
13394 script->set_line_ends(*array);
13395 DCHECK(script->line_ends()->IsFixedArray()); 13389 DCHECK(script->line_ends()->IsFixedArray());
13396 } 13390 }
13397 13391
13398 #define SMI_VALUE(x) (Smi::cast(x)->value()) 13392 #define SMI_VALUE(x) (Smi::cast(x)->value())
13399 bool Script::GetPositionInfo(int position, PositionInfo* info, 13393 bool Script::GetPositionInfo(int position, PositionInfo* info,
13400 OffsetFlag offset_flag) { 13394 OffsetFlag offset_flag) {
13401 Handle<Script> script(this); 13395 Handle<Script> script(this);
13402 InitLineEnds(script); 13396 InitLineEnds(script);
13403 13397
13404 DisallowHeapAllocation no_allocation; 13398 DisallowHeapAllocation no_allocation;
(...skipping 6904 matching lines...) Expand 10 before | Expand all | Expand 10 after
20309 // Check if the accessor uses a cached property. 20303 // Check if the accessor uses a cached property.
20310 if (!fti->cached_property_name()->IsTheHole(isolate)) { 20304 if (!fti->cached_property_name()->IsTheHole(isolate)) {
20311 return handle(Name::cast(fti->cached_property_name())); 20305 return handle(Name::cast(fti->cached_property_name()));
20312 } 20306 }
20313 } 20307 }
20314 return MaybeHandle<Name>(); 20308 return MaybeHandle<Name>();
20315 } 20309 }
20316 20310
20317 } // namespace internal 20311 } // namespace internal
20318 } // namespace v8 20312 } // namespace v8
OLDNEW
« no previous file with comments | « src/inspector/debugger_script_externs.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698