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

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

Issue 628223002: Reland: Add a use counter for Intl.v8BreakIterator (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 2 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
« no previous file with comments | « src/i18n.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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 1274 matching lines...) Expand 10 before | Expand all | Expand 10 after
1285 string = v8::Utils::OpenHandle(v8::String::Cast(*result)); 1285 string = v8::Utils::OpenHandle(v8::String::Cast(*result));
1286 CHECK_EQ("cdefghijklmnopq", string->ToCString().get()); 1286 CHECK_EQ("cdefghijklmnopq", string->ToCString().get());
1287 1287
1288 // Test that out-of-bounds substring of a slice fails when the indices 1288 // Test that out-of-bounds substring of a slice fails when the indices
1289 // would have been valid for the underlying string. 1289 // would have been valid for the underlying string.
1290 CompileRun("var slice = long.slice(1, 15);"); 1290 CompileRun("var slice = long.slice(1, 15);");
1291 CheckException("%_SubString(slice, 0, 17);"); 1291 CheckException("%_SubString(slice, 0, 17);");
1292 } 1292 }
1293 1293
1294 1294
1295 namespace {
1296
1297 int* global_use_counts = NULL;
1298
1299 void MockUseCounterCallback(v8::Isolate* isolate,
1300 v8::Isolate::UseCounterFeature feature) {
1301 ++global_use_counts[feature];
1302 }
1303 }
1304
1305
1306 TEST(CountBreakIterator) {
1307 CcTest::InitializeVM();
1308 v8::HandleScope scope(CcTest::isolate());
1309 LocalContext context;
1310 int use_counts[v8::Isolate::kUseCounterFeatureCount] = {};
1311 global_use_counts = use_counts;
1312 CcTest::isolate()->SetUseCounterCallback(MockUseCounterCallback);
1313 CHECK_EQ(0, use_counts[v8::Isolate::kBreakIterator]);
1314 v8::Local<v8::Value> result = CompileRun(
1315 "(function() {"
1316 " if (!this.Intl) return 0;"
1317 " var iterator = Intl.v8BreakIterator(['en']);"
1318 " iterator.adoptText('Now is the time');"
1319 " iterator.next();"
1320 " return iterator.next();"
1321 "})();");
1322 CHECK(result->IsNumber());
1323 int uses = result->ToInt32()->Value() == 0 ? 0 : 1;
1324 CHECK_EQ(uses, use_counts[v8::Isolate::kBreakIterator]);
1325 // Make sure GC cleans up the break iterator, so we don't get a memory leak
1326 // reported by ASAN.
1327 CcTest::isolate()->LowMemoryNotification();
1328 }
1329
1330
1295 TEST(StringReplaceAtomTwoByteResult) { 1331 TEST(StringReplaceAtomTwoByteResult) {
1296 CcTest::InitializeVM(); 1332 CcTest::InitializeVM();
1297 v8::HandleScope scope(CcTest::isolate()); 1333 v8::HandleScope scope(CcTest::isolate());
1298 LocalContext context; 1334 LocalContext context;
1299 v8::Local<v8::Value> result = CompileRun( 1335 v8::Local<v8::Value> result = CompileRun(
1300 "var subject = 'one_byte~only~string~'; " 1336 "var subject = 'one_byte~only~string~'; "
1301 "var replace = '\x80'; " 1337 "var replace = '\x80'; "
1302 "subject.replace(/~/g, replace); "); 1338 "subject.replace(/~/g, replace); ");
1303 CHECK(result->IsString()); 1339 CHECK(result->IsString());
1304 Handle<String> string = v8::Utils::OpenHandle(v8::String::Cast(*result)); 1340 Handle<String> string = v8::Utils::OpenHandle(v8::String::Cast(*result));
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
1419 CHECK(isolate->has_pending_exception()); \ 1455 CHECK(isolate->has_pending_exception()); \
1420 isolate->clear_pending_exception(); \ 1456 isolate->clear_pending_exception(); \
1421 dummy.Dispose(); \ 1457 dummy.Dispose(); \
1422 } 1458 }
1423 1459
1424 INVALID_STRING_TEST(NewStringFromAscii, char) 1460 INVALID_STRING_TEST(NewStringFromAscii, char)
1425 INVALID_STRING_TEST(NewStringFromUtf8, char) 1461 INVALID_STRING_TEST(NewStringFromUtf8, char)
1426 INVALID_STRING_TEST(NewStringFromOneByte, uint8_t) 1462 INVALID_STRING_TEST(NewStringFromOneByte, uint8_t)
1427 1463
1428 #undef INVALID_STRING_TEST 1464 #undef INVALID_STRING_TEST
OLDNEW
« no previous file with comments | « src/i18n.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698