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 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 | 549 |
550 TEST(MakingExternalStringConditions) { | 550 TEST(MakingExternalStringConditions) { |
551 LocalContext env; | 551 LocalContext env; |
552 v8::HandleScope scope(env->GetIsolate()); | 552 v8::HandleScope scope(env->GetIsolate()); |
553 | 553 |
554 // Free some space in the new space so that we can check freshness. | 554 // Free some space in the new space so that we can check freshness. |
555 CcTest::heap()->CollectGarbage(i::NEW_SPACE); | 555 CcTest::heap()->CollectGarbage(i::NEW_SPACE); |
556 CcTest::heap()->CollectGarbage(i::NEW_SPACE); | 556 CcTest::heap()->CollectGarbage(i::NEW_SPACE); |
557 | 557 |
558 uint16_t* two_byte_string = AsciiToTwoByteString("s1"); | 558 uint16_t* two_byte_string = AsciiToTwoByteString("s1"); |
559 Local<String> small_string = | 559 Local<String> local_string = |
560 String::NewFromTwoByte(env->GetIsolate(), two_byte_string, | 560 String::NewFromTwoByte(env->GetIsolate(), two_byte_string, |
561 v8::NewStringType::kNormal) | 561 v8::NewStringType::kNormal) |
562 .ToLocalChecked(); | 562 .ToLocalChecked(); |
563 i::DeleteArray(two_byte_string); | 563 i::DeleteArray(two_byte_string); |
564 | 564 |
565 // We should refuse to externalize small strings. | 565 // We should refuse to externalize new space strings. |
566 CHECK(!small_string->CanMakeExternal()); | 566 CHECK(!local_string->CanMakeExternal()); |
567 // Trigger GCs so that the newly allocated string moves to old gen. | 567 // Trigger GCs so that the newly allocated string moves to old gen. |
568 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now | 568 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now |
569 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now | 569 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now |
570 // Old space strings should be accepted. | 570 // Old space strings should be accepted. |
571 CHECK(small_string->CanMakeExternal()); | 571 CHECK(local_string->CanMakeExternal()); |
572 | |
573 two_byte_string = AsciiToTwoByteString("small string 2"); | |
574 small_string = String::NewFromTwoByte(env->GetIsolate(), two_byte_string, | |
575 v8::NewStringType::kNormal) | |
576 .ToLocalChecked(); | |
577 i::DeleteArray(two_byte_string); | |
578 | |
579 const int buf_size = 10 * 1024; | |
580 char* buf = i::NewArray<char>(buf_size); | |
581 memset(buf, 'a', buf_size); | |
582 buf[buf_size - 1] = '\0'; | |
583 | |
584 two_byte_string = AsciiToTwoByteString(buf); | |
585 Local<String> large_string = | |
586 String::NewFromTwoByte(env->GetIsolate(), two_byte_string, | |
587 v8::NewStringType::kNormal) | |
588 .ToLocalChecked(); | |
589 i::DeleteArray(buf); | |
590 i::DeleteArray(two_byte_string); | |
591 // Large strings should be immediately accepted. | |
592 CHECK(large_string->CanMakeExternal()); | |
593 } | 572 } |
594 | 573 |
595 | 574 |
596 TEST(MakingExternalOneByteStringConditions) { | 575 TEST(MakingExternalOneByteStringConditions) { |
597 LocalContext env; | 576 LocalContext env; |
598 v8::HandleScope scope(env->GetIsolate()); | 577 v8::HandleScope scope(env->GetIsolate()); |
599 | 578 |
600 // Free some space in the new space so that we can check freshness. | 579 // Free some space in the new space so that we can check freshness. |
601 CcTest::heap()->CollectGarbage(i::NEW_SPACE); | 580 CcTest::heap()->CollectGarbage(i::NEW_SPACE); |
602 CcTest::heap()->CollectGarbage(i::NEW_SPACE); | 581 CcTest::heap()->CollectGarbage(i::NEW_SPACE); |
603 | 582 |
604 Local<String> small_string = v8_str("s1"); | 583 Local<String> local_string = v8_str("s1"); |
605 // We should refuse to externalize small strings. | 584 // We should refuse to externalize new space strings. |
606 CHECK(!small_string->CanMakeExternal()); | 585 CHECK(!local_string->CanMakeExternal()); |
607 // Trigger GCs so that the newly allocated string moves to old gen. | 586 // Trigger GCs so that the newly allocated string moves to old gen. |
608 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now | 587 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now |
609 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now | 588 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now |
610 // Old space strings should be accepted. | 589 // Old space strings should be accepted. |
611 CHECK(small_string->CanMakeExternal()); | 590 CHECK(local_string->CanMakeExternal()); |
612 | |
613 const int buf_size = 10 * 1024; | |
614 char* buf = i::NewArray<char>(buf_size); | |
615 memset(buf, 'a', buf_size); | |
616 buf[buf_size - 1] = '\0'; | |
617 Local<String> large_string = v8_str(buf); | |
618 i::DeleteArray(buf); | |
619 // Large strings should be immediately accepted. | |
620 CHECK(large_string->CanMakeExternal()); | |
621 } | 591 } |
622 | 592 |
623 | 593 |
624 TEST(MakingExternalUnalignedOneByteString) { | 594 TEST(MakingExternalUnalignedOneByteString) { |
625 LocalContext env; | 595 LocalContext env; |
626 v8::HandleScope scope(env->GetIsolate()); | 596 v8::HandleScope scope(env->GetIsolate()); |
627 | 597 |
628 CompileRun("function cons(a, b) { return a + b; }" | 598 CompileRun("function cons(a, b) { return a + b; }" |
629 "function slice(a) { return a.substring(1); }"); | 599 "function slice(a) { return a.substring(1); }"); |
630 // Create a cons string that will land in old pointer space. | 600 // Create a cons string that will land in old pointer space. |
(...skipping 24739 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
25370 } | 25340 } |
25371 | 25341 |
25372 TEST(PrivateForApiIsNumber) { | 25342 TEST(PrivateForApiIsNumber) { |
25373 LocalContext context; | 25343 LocalContext context; |
25374 v8::Isolate* isolate = CcTest::isolate(); | 25344 v8::Isolate* isolate = CcTest::isolate(); |
25375 v8::HandleScope scope(isolate); | 25345 v8::HandleScope scope(isolate); |
25376 | 25346 |
25377 // Shouldn't crash. | 25347 // Shouldn't crash. |
25378 v8::Private::ForApi(isolate, v8_str("42")); | 25348 v8::Private::ForApi(isolate, v8_str("42")); |
25379 } | 25349 } |
OLD | NEW |