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

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

Issue 2374603003: [stubs] Add a test for canary crashes in SubStringStub (Closed)
Patch Set: Created 4 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
« no previous file with comments | « no previous file | 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 22 matching lines...) Expand all
33 #include <stdlib.h> 33 #include <stdlib.h>
34 34
35 #include "src/v8.h" 35 #include "src/v8.h"
36 36
37 #include "src/api.h" 37 #include "src/api.h"
38 #include "src/factory.h" 38 #include "src/factory.h"
39 #include "src/messages.h" 39 #include "src/messages.h"
40 #include "src/objects.h" 40 #include "src/objects.h"
41 #include "src/unicode-decoder.h" 41 #include "src/unicode-decoder.h"
42 #include "test/cctest/cctest.h" 42 #include "test/cctest/cctest.h"
43 #include "test/cctest/heap/heap-utils.h"
43 44
44 // Adapted from http://en.wikipedia.org/wiki/Multiply-with-carry 45 // Adapted from http://en.wikipedia.org/wiki/Multiply-with-carry
45 class MyRandomNumberGenerator { 46 class MyRandomNumberGenerator {
46 public: 47 public:
47 MyRandomNumberGenerator() { 48 MyRandomNumberGenerator() {
48 init(); 49 init();
49 } 50 }
50 51
51 void init(uint32_t seed = 0x5688c73e) { 52 void init(uint32_t seed = 0x5688c73e) {
52 static const uint32_t phi = 0x9e3779b9; 53 static const uint32_t phi = 0x9e3779b9;
(...skipping 1259 matching lines...) Expand 10 before | Expand all | Expand 10 after
1312 result = CompileRun("%_SubString(long, Math.sqrt(4), 17.1);"); 1313 result = CompileRun("%_SubString(long, Math.sqrt(4), 17.1);");
1313 string = v8::Utils::OpenHandle(v8::String::Cast(*result)); 1314 string = v8::Utils::OpenHandle(v8::String::Cast(*result));
1314 CHECK_EQ(0, strcmp("cdefghijklmnopq", string->ToCString().get())); 1315 CHECK_EQ(0, strcmp("cdefghijklmnopq", string->ToCString().get()));
1315 1316
1316 // Test that out-of-bounds substring of a slice fails when the indices 1317 // Test that out-of-bounds substring of a slice fails when the indices
1317 // would have been valid for the underlying string. 1318 // would have been valid for the underlying string.
1318 CompileRun("var slice = long.slice(1, 15);"); 1319 CompileRun("var slice = long.slice(1, 15);");
1319 CheckException("%_SubString(slice, 0, 17);"); 1320 CheckException("%_SubString(slice, 0, 17);");
1320 } 1321 }
1321 1322
1323 TEST(RobustSubStringStubExternalStrings) {
1324 // Ensure that the specific combination of calling the SubStringStub on an
1325 // external string and triggering a GC on string allocation does not crash.
1326 // See crbug.com/649967.
1327
1328 FLAG_allow_natives_syntax = true;
1329 #ifdef VERIFY_HEAP
1330 FLAG_verify_heap = true;
1331 #endif
1332
1333 CcTest::InitializeVM();
1334 v8::HandleScope handle_scope(CcTest::isolate());
1335
1336 v8::Local<v8::String> underlying =
1337 CompileRun(
1338 "var str = 'abcdefghijklmnopqrstuvwxyz';"
1339 "str")
1340 ->ToString(CcTest::isolate()->GetCurrentContext())
1341 .ToLocalChecked();
1342 CHECK(v8::Utils::OpenHandle(*underlying)->IsSeqOneByteString());
1343
1344 const int length = underlying->Length();
1345 uc16* two_byte = NewArray<uc16>(length + 1);
1346 underlying->Write(two_byte);
1347
1348 Resource* resource = new Resource(two_byte, length);
1349 CHECK(underlying->MakeExternal(resource));
1350 CHECK(v8::Utils::OpenHandle(*underlying)->IsExternalTwoByteString());
1351
1352 v8::Local<v8::Script> script = v8_compile(v8_str("%_SubString(str, 5, 8)"));
1353
1354 // Trigger a GC on string allocation.
1355 i::heap::SimulateFullSpace(CcTest::heap()->new_space());
1356
1357 v8::Local<v8::Value> result;
1358 CHECK(script->Run(v8::Isolate::GetCurrent()->GetCurrentContext())
1359 .ToLocal(&result));
1360 Handle<String> string = v8::Utils::OpenHandle(v8::String::Cast(*result));
1361 CHECK_EQ(0, strcmp("fgh", string->ToCString().get()));
1362 }
1322 1363
1323 namespace { 1364 namespace {
1324 1365
1325 int* global_use_counts = NULL; 1366 int* global_use_counts = NULL;
1326 1367
1327 void MockUseCounterCallback(v8::Isolate* isolate, 1368 void MockUseCounterCallback(v8::Isolate* isolate,
1328 v8::Isolate::UseCounterFeature feature) { 1369 v8::Isolate::UseCounterFeature feature) {
1329 ++global_use_counts[feature]; 1370 ++global_use_counts[feature];
1330 } 1371 }
1331 } 1372 }
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
1524 } 1565 }
1525 { 1566 {
1526 HandleScope scope(isolate); 1567 HandleScope scope(isolate);
1527 v8::Local<v8::Value> result = CompileRun( 1568 v8::Local<v8::Value> result = CompileRun(
1528 "String.fromCharCode(432, 432, 432, 432, 432, " 1569 "String.fromCharCode(432, 432, 432, 432, 432, "
1529 "432, 432, 432, 432, 432, 432, 432, 432, 432, " 1570 "432, 432, 432, 432, 432, 432, 432, 432, 432, "
1530 "432, 432, 432, 432, 432, 432, 432, 432, 432)"); 1571 "432, 432, 432, 432, 432, 432, 432, 432, 432)");
1531 CHECK(v8::Utils::OpenHandle(*result)->IsSeqTwoByteString()); 1572 CHECK(v8::Utils::OpenHandle(*result)->IsSeqTwoByteString());
1532 } 1573 }
1533 } 1574 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698