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

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: Patched RegExp for string slices. 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 printf("Truncate Sliced String\n");
488 FLAG_string_slices = true;
489 InitializeVM();
490 v8::HandleScope scope;
491 Handle<String> string =
492 FACTORY->NewStringFromAscii(CStrVector("parentparentparent"));
493 Handle<String> parent = FACTORY->NewConsString(string, string);
494 CHECK(parent->IsConsString());
495 CHECK(!parent->IsFlat());
496 Handle<String> slice = FACTORY->NewSubString(parent, 1, 25);
497 CHECK(parent->IsFlat()); // After slicing, parent becomes flat.
498 CHECK(slice->IsSlicedString());
499 CHECK(!slice->IsTruncated());
500 CHECK(!slice->IsFlatAndTruncated());
501 CHECK(slice->IsFlat());
502 TruncateString(slice);
503 CHECK(slice->IsTruncated());
504 CHECK(slice->IsFlatAndTruncated());
505 }
506
507
508 TEST(TrivialSlice) {
509 // This tests whether a slice that contains the entire parent string
510 // actually creates a new string (it should not).
511 FLAG_string_slices = true;
512 InitializeVM();
513 HandleScope scope;
514 v8::Local<v8::Value> result;
515 Handle<String> string;
516 const char* init = "var str = 'abcdefghijklmnopqrstuvwxyz';";
517 const char* check = "str.slice(0,26)";
518 const char* crosscheck = "str.slice(1,25)";
519
520 v8::Script::Compile(v8::String::New(init))->Run();
521
522 result = v8::Script::Compile(v8::String::New(check))->Run();
antonm 2011/08/04 12:18:48 I think we have something like CompileAndRun
523 CHECK(result->IsString());
524 string = v8::Utils::OpenHandle(v8::String::Cast(*result));
525 CHECK(!string->IsSlicedString());
526
527 string = FACTORY->NewSubString(string, 0, 26);
528 CHECK(!string->IsSlicedString());
529
530 result = v8::Script::Compile(v8::String::New(crosscheck))->Run();
531 CHECK(result->IsString());
532 string = v8::Utils::OpenHandle(v8::String::Cast(*result));
533 CHECK(string->IsSlicedString());
534 CHECK_EQ("bcdefghijklmnopqrstuvwxy", *(string->ToCString()));
535 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698