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 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
547 | 547 |
548 | 548 |
549 TEST(MakingExternalStringConditions) { | 549 TEST(MakingExternalStringConditions) { |
550 LocalContext env; | 550 LocalContext env; |
551 v8::HandleScope scope(env->GetIsolate()); | 551 v8::HandleScope scope(env->GetIsolate()); |
552 | 552 |
553 // Free some space in the new space so that we can check freshness. | 553 // Free some space in the new space so that we can check freshness. |
554 CcTest::heap()->CollectGarbage(i::NEW_SPACE); | 554 CcTest::heap()->CollectGarbage(i::NEW_SPACE); |
555 CcTest::heap()->CollectGarbage(i::NEW_SPACE); | 555 CcTest::heap()->CollectGarbage(i::NEW_SPACE); |
556 | 556 |
557 uint16_t* two_byte_string = AsciiToTwoByteString("s1"); | 557 uint16_t* two_byte_string = AsciiToTwoByteString("ascii string"); |
558 Local<String> small_string = | 558 Local<String> local_string = |
559 String::NewFromTwoByte(env->GetIsolate(), two_byte_string, | 559 String::NewFromTwoByte(env->GetIsolate(), two_byte_string, |
560 v8::NewStringType::kNormal) | 560 v8::NewStringType::kNormal) |
561 .ToLocalChecked(); | 561 .ToLocalChecked(); |
562 i::DeleteArray(two_byte_string); | 562 i::DeleteArray(two_byte_string); |
563 | 563 |
564 // We should refuse to externalize small strings. | 564 // We should refuse to externalize new strings. |
565 CHECK(!small_string->CanMakeExternal()); | 565 CHECK(!local_string->CanMakeExternal()); |
566 // Trigger GCs so that the newly allocated string moves to old gen. | 566 // Trigger GCs so that the newly allocated string moves to old gen. |
567 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now | 567 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now |
568 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now | 568 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now |
569 // Old space strings should be accepted. | 569 // Old space strings should be accepted. |
570 CHECK(small_string->CanMakeExternal()); | 570 CHECK(local_string->CanMakeExternal()); |
571 | |
572 two_byte_string = AsciiToTwoByteString("small string 2"); | |
573 small_string = String::NewFromTwoByte(env->GetIsolate(), two_byte_string, | |
574 v8::NewStringType::kNormal) | |
575 .ToLocalChecked(); | |
576 i::DeleteArray(two_byte_string); | |
577 | |
578 const int buf_size = 10 * 1024; | |
579 char* buf = i::NewArray<char>(buf_size); | |
580 memset(buf, 'a', buf_size); | |
581 buf[buf_size - 1] = '\0'; | |
582 | |
583 two_byte_string = AsciiToTwoByteString(buf); | |
584 Local<String> large_string = | |
585 String::NewFromTwoByte(env->GetIsolate(), two_byte_string, | |
586 v8::NewStringType::kNormal) | |
587 .ToLocalChecked(); | |
588 i::DeleteArray(buf); | |
589 i::DeleteArray(two_byte_string); | |
590 // Large strings should be immediately accepted. | |
591 CHECK(large_string->CanMakeExternal()); | |
592 } | 571 } |
593 | 572 |
594 | 573 |
595 TEST(MakingExternalOneByteStringConditions) { | 574 TEST(MakingExternalOneByteStringConditions) { |
596 LocalContext env; | 575 LocalContext env; |
597 v8::HandleScope scope(env->GetIsolate()); | 576 v8::HandleScope scope(env->GetIsolate()); |
598 | 577 |
599 // Free some space in the new space so that we can check freshness. | 578 // Free some space in the new space so that we can check freshness. |
600 CcTest::heap()->CollectGarbage(i::NEW_SPACE); | 579 CcTest::heap()->CollectGarbage(i::NEW_SPACE); |
601 CcTest::heap()->CollectGarbage(i::NEW_SPACE); | 580 CcTest::heap()->CollectGarbage(i::NEW_SPACE); |
(...skipping 24750 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
25352 } | 25331 } |
25353 | 25332 |
25354 TEST(PrivateForApiIsNumber) { | 25333 TEST(PrivateForApiIsNumber) { |
25355 LocalContext context; | 25334 LocalContext context; |
25356 v8::Isolate* isolate = CcTest::isolate(); | 25335 v8::Isolate* isolate = CcTest::isolate(); |
25357 v8::HandleScope scope(isolate); | 25336 v8::HandleScope scope(isolate); |
25358 | 25337 |
25359 // Shouldn't crash. | 25338 // Shouldn't crash. |
25360 v8::Private::ForApi(isolate, v8_str("42")); | 25339 v8::Private::ForApi(isolate, v8_str("42")); |
25361 } | 25340 } |
OLD | NEW |