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

Side by Side Diff: test/cctest/test-strings.cc

Issue 7477045: Tentative implementation of string slices (hidden under the flag --string-slices). (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Implemented some changes suggested by Anton. Created 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 2
3 // Check that we can traverse very deep stacks of ConsStrings using 3 // Check that we can traverse very deep stacks of ConsStrings using
4 // StringInputBuffer. Check that Get(int) works on very deep stacks 4 // StringInputBuffer. Check that Get(int) works on very deep stacks
5 // of ConsStrings. These operations may not be very fast, but they 5 // of ConsStrings. These operations may not be very fast, but they
6 // should be possible without getting errors due to too deep recursion. 6 // should be possible without getting errors due to too deep recursion.
7 7
8 #include <stdlib.h> 8 #include <stdlib.h>
9 9
10 #include "v8.h" 10 #include "v8.h"
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 v8::Local<v8::Value> result = 474 v8::Local<v8::Value> result =
475 v8::Script::Compile(v8::String::New(line))->Run(); 475 v8::Script::Compile(v8::String::New(line))->Run();
476 CHECK_EQ(results[i]->IsUndefined(), result->IsUndefined()); 476 CHECK_EQ(results[i]->IsUndefined(), result->IsUndefined());
477 CHECK_EQ(results[i]->IsNumber(), result->IsNumber()); 477 CHECK_EQ(results[i]->IsNumber(), result->IsNumber());
478 if (result->IsNumber()) { 478 if (result->IsNumber()) {
479 CHECK_EQ(Smi::cast(results[i]->ToSmi()->ToObjectChecked())->value(), 479 CHECK_EQ(Smi::cast(results[i]->ToSmi()->ToObjectChecked())->value(),
480 result->ToInt32()->Value()); 480 result->ToInt32()->Value());
481 } 481 }
482 } 482 }
483 } 483 }
484
485
486 TEST(TruncateSlice) {
487 FLAG_string_slices = true;
488 InitializeVM();
489 v8::HandleScope scope;
490 Handle<String> string =
491 FACTORY->NewStringFromAscii(CStrVector("parentparentparent"));
492 Handle<String> parent = FACTORY->NewConsString(string, string);
493 CHECK(parent->IsConsString());
494 CHECK(!parent->IsFlat());
495 Handle<String> slice = FACTORY->NewSubString(parent, 1, 25);
496 // After slicing, the original string becomes a flat cons.
497 CHECK(parent->IsFlat());
498 CHECK(slice->IsSlicedString());
499 CHECK_EQ(SlicedString::cast(*slice)->parent(),
500 ConsString::cast(*parent)->first());
501 CHECK(SlicedString::cast(*slice)->parent()->IsSeqString());
502 CHECK(!slice->IsTruncated());
503 CHECK(!slice->IsFlatAndTruncated());
504 CHECK(slice->IsFlat());
505 TruncateString(slice);
506 CHECK(slice->IsTruncated());
507 CHECK(slice->IsFlatAndTruncated());
508 CHECK_NE(slice->GetIndirect(), parent->GetIndirect());
509 }
510
511
512 TEST(TrivialSlice) {
513 // This tests whether a slice that contains the entire parent string
514 // actually creates a new string (it should not).
515 FLAG_string_slices = true;
516 InitializeVM();
517 HandleScope scope;
518 v8::Local<v8::Value> result;
519 Handle<String> string;
520 const char* init = "var str = 'abcdefghijklmnopqrstuvwxyz';";
521 const char* check = "str.slice(0,26)";
522 const char* crosscheck = "str.slice(1,25)";
523
524 v8::Script::Compile(v8::String::New(init))->Run();
525
526 result = v8::Script::Compile(v8::String::New(check))->Run();
527 CHECK(result->IsString());
528 string = v8::Utils::OpenHandle(v8::String::Cast(*result));
529 CHECK(!string->IsSlicedString());
530
531 string = FACTORY->NewSubString(string, 0, 26);
532 CHECK(!string->IsSlicedString());
533
534 result = v8::Script::Compile(v8::String::New(crosscheck))->Run();
535 CHECK(result->IsString());
536 string = v8::Utils::OpenHandle(v8::String::Cast(*result));
537 CHECK(string->IsSlicedString());
538 CHECK_EQ("bcdefghijklmnopqrstuvwxy", *(string->ToCString()));
539 }
OLDNEW
« src/objects.h ('K') | « test/cctest/test-debug.cc ('k') | test/mjsunit/string-slices.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698