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

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

Issue 6524031: Terminate on \0 in data passed to String::New() (Closed)
Patch Set: Created 9 years, 10 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/heap.cc ('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 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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 building_blocks[i] = 96 building_blocks[i] =
97 Factory::NewStringFromTwoByte(Vector<const uc16>(buf, len)); 97 Factory::NewStringFromTwoByte(Vector<const uc16>(buf, len));
98 for (int j = 0; j < len; j++) { 98 for (int j = 0; j < len; j++) {
99 CHECK_EQ(buf[j], building_blocks[i]->Get(j)); 99 CHECK_EQ(buf[j], building_blocks[i]->Get(j));
100 } 100 }
101 break; 101 break;
102 } 102 }
103 case 1: { 103 case 1: {
104 char buf[2000]; 104 char buf[2000];
105 for (int j = 0; j < len; j++) { 105 for (int j = 0; j < len; j++) {
106 buf[j] = gen() % 128; 106 buf[j] = gen() % 127 + 1;
107 } 107 }
108 building_blocks[i] = 108 building_blocks[i] =
109 Factory::NewStringFromAscii(Vector<const char>(buf, len)); 109 Factory::NewStringFromAscii(Vector<const char>(buf, len));
110 for (int j = 0; j < len; j++) { 110 for (int j = 0; j < len; j++) {
111 CHECK_EQ(buf[j], building_blocks[i]->Get(j)); 111 CHECK_EQ(buf[j], building_blocks[i]->Get(j));
112 } 112 }
113 break; 113 break;
114 } 114 }
115 case 2: { 115 case 2: {
116 uc16* buf = Zone::NewArray<uc16>(len); 116 uc16* buf = Zone::NewArray<uc16>(len);
117 for (int j = 0; j < len; j++) { 117 for (int j = 0; j < len; j++) {
118 buf[j] = gen() % 65536; 118 buf[j] = gen() % 65536;
119 } 119 }
120 Resource* resource = new Resource(Vector<const uc16>(buf, len)); 120 Resource* resource = new Resource(Vector<const uc16>(buf, len));
121 building_blocks[i] = Factory::NewExternalStringFromTwoByte(resource); 121 building_blocks[i] = Factory::NewExternalStringFromTwoByte(resource);
122 for (int j = 0; j < len; j++) { 122 for (int j = 0; j < len; j++) {
123 CHECK_EQ(buf[j], building_blocks[i]->Get(j)); 123 CHECK_EQ(buf[j], building_blocks[i]->Get(j));
124 } 124 }
125 break; 125 break;
126 } 126 }
127 case 3: { 127 case 3: {
128 char* buf = NewArray<char>(len); 128 char* buf = NewArray<char>(len);
129 for (int j = 0; j < len; j++) { 129 for (int j = 0; j < len; j++) {
130 buf[j] = gen() % 128; 130 buf[j] = gen() % 127 + 1;
131 } 131 }
132 building_blocks[i] = 132 building_blocks[i] =
133 Factory::NewStringFromAscii(Vector<const char>(buf, len)); 133 Factory::NewStringFromAscii(Vector<const char>(buf, len));
134 for (int j = 0; j < len; j++) { 134 for (int j = 0; j < len; j++) {
135 CHECK_EQ(buf[j], building_blocks[i]->Get(j)); 135 CHECK_EQ(buf[j], building_blocks[i]->Get(j));
136 } 136 }
137 DeleteArray<char>(buf); 137 DeleteArray<char>(buf);
138 break; 138 break;
139 } 139 }
140 } 140 }
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 } 293 }
294 Handle<String> flat_string = Factory::NewConsString(string, foo_string); 294 Handle<String> flat_string = Factory::NewConsString(string, foo_string);
295 FlattenString(flat_string); 295 FlattenString(flat_string);
296 296
297 for (int i = 0; i < 500; i++) { 297 for (int i = 0; i < 500; i++) {
298 TraverseFirst(flat_string, string, DEEP_ASCII_DEPTH); 298 TraverseFirst(flat_string, string, DEEP_ASCII_DEPTH);
299 } 299 }
300 DeleteArray<char>(foo); 300 DeleteArray<char>(foo);
301 } 301 }
302 302
303 TEST(TrailingNulls) {
304 InitializeVM();
305 v8::HandleScope handle_scope;
306
307 const char* hello_ascii = "Hello!\0\0\0\0\0";
308 v8::Handle<v8::String> ascii = v8::String::New(hello_ascii, 11);
309 CHECK_EQ(6, ascii->Utf8Length());
310
311 // hello in hebrew
312 const uint8_t hello_utf[] = { 0xd7, 0xa9, 0xd7, 0x9c,
313 0xd7, 0x95, 0xd7, 0x9d,
314 0x00, 0x00, 0x00, 0x00,
315 0x00, 0x00, 0x00, 0x00 };
316 v8::Handle<v8::String> utf = v8::String::New((char *)hello_utf, 16);
317 CHECK_EQ(8, utf->Utf8Length());
318 }
303 319
304 TEST(Utf8Conversion) { 320 TEST(Utf8Conversion) {
305 // Smoke test for converting strings to utf-8. 321 // Smoke test for converting strings to utf-8.
306 InitializeVM(); 322 InitializeVM();
307 v8::HandleScope handle_scope; 323 v8::HandleScope handle_scope;
308 // A simple ascii string 324 // A simple ascii string
309 const char* ascii_string = "abcdef12345"; 325 const char* ascii_string = "abcdef12345";
310 int len = 326 int len =
311 v8::String::New(ascii_string, 327 v8::String::New(ascii_string,
312 StrLength(ascii_string))->Utf8Length(); 328 StrLength(ascii_string))->Utf8Length();
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 v8::Local<v8::Value> result = 490 v8::Local<v8::Value> result =
475 v8::Script::Compile(v8::String::New(line))->Run(); 491 v8::Script::Compile(v8::String::New(line))->Run();
476 CHECK_EQ(results[i]->IsUndefined(), result->IsUndefined()); 492 CHECK_EQ(results[i]->IsUndefined(), result->IsUndefined());
477 CHECK_EQ(results[i]->IsNumber(), result->IsNumber()); 493 CHECK_EQ(results[i]->IsNumber(), result->IsNumber());
478 if (result->IsNumber()) { 494 if (result->IsNumber()) {
479 CHECK_EQ(Smi::cast(results[i]->ToSmi()->ToObjectChecked())->value(), 495 CHECK_EQ(Smi::cast(results[i]->ToSmi()->ToObjectChecked())->value(),
480 result->ToInt32()->Value()); 496 result->ToInt32()->Value());
481 } 497 }
482 } 498 }
483 } 499 }
OLDNEW
« no previous file with comments | « src/heap.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698