| OLD | NEW |
| 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 Loading... |
| 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 "var iterator = Intl.v8BreakIterator(['en']);" | |
| 1316 "iterator.adoptText('Now is the time');" | |
| 1317 "iterator.next();" | |
| 1318 "iterator.next();"); | |
| 1319 CHECK(result->IsNumber()); | |
| 1320 CHECK_EQ(1, use_counts[v8::Isolate::kBreakIterator]); | |
| 1321 } | |
| 1322 | |
| 1323 | |
| 1324 TEST(StringReplaceAtomTwoByteResult) { | 1295 TEST(StringReplaceAtomTwoByteResult) { |
| 1325 CcTest::InitializeVM(); | 1296 CcTest::InitializeVM(); |
| 1326 v8::HandleScope scope(CcTest::isolate()); | 1297 v8::HandleScope scope(CcTest::isolate()); |
| 1327 LocalContext context; | 1298 LocalContext context; |
| 1328 v8::Local<v8::Value> result = CompileRun( | 1299 v8::Local<v8::Value> result = CompileRun( |
| 1329 "var subject = 'one_byte~only~string~'; " | 1300 "var subject = 'one_byte~only~string~'; " |
| 1330 "var replace = '\x80'; " | 1301 "var replace = '\x80'; " |
| 1331 "subject.replace(/~/g, replace); "); | 1302 "subject.replace(/~/g, replace); "); |
| 1332 CHECK(result->IsString()); | 1303 CHECK(result->IsString()); |
| 1333 Handle<String> string = v8::Utils::OpenHandle(v8::String::Cast(*result)); | 1304 Handle<String> string = v8::Utils::OpenHandle(v8::String::Cast(*result)); |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1448 CHECK(isolate->has_pending_exception()); \ | 1419 CHECK(isolate->has_pending_exception()); \ |
| 1449 isolate->clear_pending_exception(); \ | 1420 isolate->clear_pending_exception(); \ |
| 1450 dummy.Dispose(); \ | 1421 dummy.Dispose(); \ |
| 1451 } | 1422 } |
| 1452 | 1423 |
| 1453 INVALID_STRING_TEST(NewStringFromAscii, char) | 1424 INVALID_STRING_TEST(NewStringFromAscii, char) |
| 1454 INVALID_STRING_TEST(NewStringFromUtf8, char) | 1425 INVALID_STRING_TEST(NewStringFromUtf8, char) |
| 1455 INVALID_STRING_TEST(NewStringFromOneByte, uint8_t) | 1426 INVALID_STRING_TEST(NewStringFromOneByte, uint8_t) |
| 1456 | 1427 |
| 1457 #undef INVALID_STRING_TEST | 1428 #undef INVALID_STRING_TEST |
| OLD | NEW |