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

Side by Side Diff: src/objects.cc

Issue 2173403002: Replace SmartArrayPointer<T> with unique_ptr<T[]> (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: updates Created 4 years, 4 months 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/objects.h ('k') | src/objects-printer.cc » ('j') | 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 <sstream> 10 #include <sstream>
10 11
11 #include "src/objects-inl.h" 12 #include "src/objects-inl.h"
12 13
13 #include "src/accessors.h" 14 #include "src/accessors.h"
14 #include "src/allocation-site-scopes.h" 15 #include "src/allocation-site-scopes.h"
15 #include "src/api-arguments-inl.h" 16 #include "src/api-arguments-inl.h"
16 #include "src/api-natives.h" 17 #include "src/api-natives.h"
17 #include "src/api.h" 18 #include "src/api.h"
18 #include "src/base/bits.h" 19 #include "src/base/bits.h"
(...skipping 2434 matching lines...) Expand 10 before | Expand all | Expand 10 after
2453 case FIXED_##TYPE##_ARRAY_TYPE: \ 2454 case FIXED_##TYPE##_ARRAY_TYPE: \
2454 os << "<Fixed" #Type "Array[" << Fixed##Type##Array::cast(this)->length() \ 2455 os << "<Fixed" #Type "Array[" << Fixed##Type##Array::cast(this)->length() \
2455 << "]>"; \ 2456 << "]>"; \
2456 break; 2457 break;
2457 2458
2458 TYPED_ARRAYS(TYPED_ARRAY_SHORT_PRINT) 2459 TYPED_ARRAYS(TYPED_ARRAY_SHORT_PRINT)
2459 #undef TYPED_ARRAY_SHORT_PRINT 2460 #undef TYPED_ARRAY_SHORT_PRINT
2460 2461
2461 case SHARED_FUNCTION_INFO_TYPE: { 2462 case SHARED_FUNCTION_INFO_TYPE: {
2462 SharedFunctionInfo* shared = SharedFunctionInfo::cast(this); 2463 SharedFunctionInfo* shared = SharedFunctionInfo::cast(this);
2463 base::SmartArrayPointer<char> debug_name = 2464 std::unique_ptr<char[]> debug_name = shared->DebugName()->ToCString();
2464 shared->DebugName()->ToCString();
2465 if (debug_name[0] != 0) { 2465 if (debug_name[0] != 0) {
2466 os << "<SharedFunctionInfo " << debug_name.get() << ">"; 2466 os << "<SharedFunctionInfo " << debug_name.get() << ">";
2467 } else { 2467 } else {
2468 os << "<SharedFunctionInfo>"; 2468 os << "<SharedFunctionInfo>";
2469 } 2469 }
2470 break; 2470 break;
2471 } 2471 }
2472 case JS_MESSAGE_OBJECT_TYPE: 2472 case JS_MESSAGE_OBJECT_TYPE:
2473 os << "<JSMessageObject>"; 2473 os << "<JSMessageObject>";
2474 break; 2474 break;
(...skipping 7930 matching lines...) Expand 10 before | Expand all | Expand 10 after
10405 const uc16* start; 10405 const uc16* start;
10406 if (shape.representation_tag() == kSeqStringTag) { 10406 if (shape.representation_tag() == kSeqStringTag) {
10407 start = SeqTwoByteString::cast(string)->GetChars(); 10407 start = SeqTwoByteString::cast(string)->GetChars();
10408 } else { 10408 } else {
10409 start = ExternalTwoByteString::cast(string)->GetChars(); 10409 start = ExternalTwoByteString::cast(string)->GetChars();
10410 } 10410 }
10411 return FlatContent(start + offset, length); 10411 return FlatContent(start + offset, length);
10412 } 10412 }
10413 } 10413 }
10414 10414
10415 10415 std::unique_ptr<char[]> String::ToCString(AllowNullsFlag allow_nulls,
10416 base::SmartArrayPointer<char> String::ToCString(AllowNullsFlag allow_nulls, 10416 RobustnessFlag robust_flag,
10417 RobustnessFlag robust_flag, 10417 int offset, int length,
10418 int offset, int length, 10418 int* length_return) {
10419 int* length_return) {
10420 if (robust_flag == ROBUST_STRING_TRAVERSAL && !LooksValid()) { 10419 if (robust_flag == ROBUST_STRING_TRAVERSAL && !LooksValid()) {
10421 return base::SmartArrayPointer<char>(NULL); 10420 return std::unique_ptr<char[]>();
10422 } 10421 }
10423 // Negative length means the to the end of the string. 10422 // Negative length means the to the end of the string.
10424 if (length < 0) length = kMaxInt - offset; 10423 if (length < 0) length = kMaxInt - offset;
10425 10424
10426 // Compute the size of the UTF-8 string. Start at the specified offset. 10425 // Compute the size of the UTF-8 string. Start at the specified offset.
10427 StringCharacterStream stream(this, offset); 10426 StringCharacterStream stream(this, offset);
10428 int character_position = offset; 10427 int character_position = offset;
10429 int utf8_bytes = 0; 10428 int utf8_bytes = 0;
10430 int last = unibrow::Utf16::kNoPreviousCharacter; 10429 int last = unibrow::Utf16::kNoPreviousCharacter;
10431 while (stream.HasMore() && character_position++ < offset + length) { 10430 while (stream.HasMore() && character_position++ < offset + length) {
(...skipping 16 matching lines...) Expand all
10448 while (stream.HasMore() && character_position++ < offset + length) { 10447 while (stream.HasMore() && character_position++ < offset + length) {
10449 uint16_t character = stream.GetNext(); 10448 uint16_t character = stream.GetNext();
10450 if (allow_nulls == DISALLOW_NULLS && character == 0) { 10449 if (allow_nulls == DISALLOW_NULLS && character == 0) {
10451 character = ' '; 10450 character = ' ';
10452 } 10451 }
10453 utf8_byte_position += 10452 utf8_byte_position +=
10454 unibrow::Utf8::Encode(result + utf8_byte_position, character, last); 10453 unibrow::Utf8::Encode(result + utf8_byte_position, character, last);
10455 last = character; 10454 last = character;
10456 } 10455 }
10457 result[utf8_byte_position] = 0; 10456 result[utf8_byte_position] = 0;
10458 return base::SmartArrayPointer<char>(result); 10457 return std::unique_ptr<char[]>(result);
10459 } 10458 }
10460 10459
10461 10460 std::unique_ptr<char[]> String::ToCString(AllowNullsFlag allow_nulls,
10462 base::SmartArrayPointer<char> String::ToCString(AllowNullsFlag allow_nulls, 10461 RobustnessFlag robust_flag,
10463 RobustnessFlag robust_flag, 10462 int* length_return) {
10464 int* length_return) {
10465 return ToCString(allow_nulls, robust_flag, 0, -1, length_return); 10463 return ToCString(allow_nulls, robust_flag, 0, -1, length_return);
10466 } 10464 }
10467 10465
10468 10466
10469 const uc16* String::GetTwoByteData(unsigned start) { 10467 const uc16* String::GetTwoByteData(unsigned start) {
10470 DCHECK(!IsOneByteRepresentationUnderneath()); 10468 DCHECK(!IsOneByteRepresentationUnderneath());
10471 switch (StringShape(this).representation_tag()) { 10469 switch (StringShape(this).representation_tag()) {
10472 case kSeqStringTag: 10470 case kSeqStringTag:
10473 return SeqTwoByteString::cast(this)->SeqTwoByteStringGetData(start); 10471 return SeqTwoByteString::cast(this)->SeqTwoByteStringGetData(start);
10474 case kExternalStringTag: 10472 case kExternalStringTag:
(...skipping 2064 matching lines...) Expand 10 before | Expand all | Expand 10 after
12539 DCHECK(prototype->IsJSReceiver()); 12537 DCHECK(prototype->IsJSReceiver());
12540 if (map->prototype() != *prototype) { 12538 if (map->prototype() != *prototype) {
12541 Map::SetPrototype(map, prototype, FAST_PROTOTYPE); 12539 Map::SetPrototype(map, prototype, FAST_PROTOTYPE);
12542 } 12540 }
12543 map->SetConstructor(*constructor); 12541 map->SetConstructor(*constructor);
12544 return map; 12542 return map;
12545 } 12543 }
12546 12544
12547 12545
12548 void JSFunction::PrintName(FILE* out) { 12546 void JSFunction::PrintName(FILE* out) {
12549 base::SmartArrayPointer<char> name = shared()->DebugName()->ToCString(); 12547 std::unique_ptr<char[]> name = shared()->DebugName()->ToCString();
12550 PrintF(out, "%s", name.get()); 12548 PrintF(out, "%s", name.get());
12551 } 12549 }
12552 12550
12553 12551
12554 Handle<String> JSFunction::GetName(Handle<JSFunction> function) { 12552 Handle<String> JSFunction::GetName(Handle<JSFunction> function) {
12555 Isolate* isolate = function->GetIsolate(); 12553 Isolate* isolate = function->GetIsolate();
12556 Handle<Object> name = 12554 Handle<Object> name =
12557 JSReceiver::GetDataProperty(function, isolate->factory()->name_string()); 12555 JSReceiver::GetDataProperty(function, isolate->factory()->name_string());
12558 if (name->IsString()) return Handle<String>::cast(name); 12556 if (name->IsString()) return Handle<String>::cast(name);
12559 return handle(function->shared()->DebugName(), isolate); 12557 return handle(function->shared()->DebugName(), isolate);
(...skipping 6430 matching lines...) Expand 10 before | Expand all | Expand 10 after
18990 for (PrototypeIterator iter(isolate, this, kStartAtReceiver, 18988 for (PrototypeIterator iter(isolate, this, kStartAtReceiver,
18991 PrototypeIterator::END_AT_NULL); 18989 PrototypeIterator::END_AT_NULL);
18992 !iter.IsAtEnd(); iter.AdvanceIgnoringProxies()) { 18990 !iter.IsAtEnd(); iter.AdvanceIgnoringProxies()) {
18993 if (iter.GetCurrent<Object>()->IsJSProxy()) return true; 18991 if (iter.GetCurrent<Object>()->IsJSProxy()) return true;
18994 } 18992 }
18995 return false; 18993 return false;
18996 } 18994 }
18997 18995
18998 } // namespace internal 18996 } // namespace internal
18999 } // namespace v8 18997 } // namespace v8
OLDNEW
« no previous file with comments | « src/objects.h ('k') | src/objects-printer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698