| 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 676 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 687 virtual const char* data() const { return string_; } | 687 virtual const char* data() const { return string_; } |
| 688 virtual size_t length() const { return length_; } | 688 virtual size_t length() const { return length_; } |
| 689 | 689 |
| 690 private: | 690 private: |
| 691 char string_[10]; | 691 char string_[10]; |
| 692 int length_; | 692 int length_; |
| 693 }; | 693 }; |
| 694 | 694 |
| 695 | 695 |
| 696 THREADED_TEST(NewExternalForVeryLongString) { | 696 THREADED_TEST(NewExternalForVeryLongString) { |
| 697 auto isolate = CcTest::isolate(); |
| 697 { | 698 { |
| 698 LocalContext env; | 699 v8::HandleScope scope(isolate); |
| 699 v8::HandleScope scope(env->GetIsolate()); | |
| 700 v8::TryCatch try_catch; | 700 v8::TryCatch try_catch; |
| 701 RandomLengthOneByteResource r(1 << 30); | 701 RandomLengthOneByteResource r(1 << 30); |
| 702 v8::Local<v8::String> str = v8::String::NewExternal(CcTest::isolate(), &r); | 702 v8::Local<v8::String> str = v8::String::NewExternal(isolate, &r); |
| 703 CHECK(str.IsEmpty()); | 703 CHECK(str.IsEmpty()); |
| 704 CHECK(try_catch.HasCaught()); | 704 CHECK(!try_catch.HasCaught()); |
| 705 String::Utf8Value exception_value(try_catch.Exception()); | |
| 706 CHECK_EQ(0, strcmp("RangeError: Invalid string length", *exception_value)); | |
| 707 } | 705 } |
| 708 | 706 |
| 709 { | 707 { |
| 710 LocalContext env; | 708 v8::HandleScope scope(isolate); |
| 711 v8::HandleScope scope(env->GetIsolate()); | |
| 712 v8::TryCatch try_catch; | 709 v8::TryCatch try_catch; |
| 713 RandomLengthResource r(1 << 30); | 710 RandomLengthResource r(1 << 30); |
| 714 v8::Local<v8::String> str = v8::String::NewExternal(CcTest::isolate(), &r); | 711 v8::Local<v8::String> str = v8::String::NewExternal(isolate, &r); |
| 715 CHECK(str.IsEmpty()); | 712 CHECK(str.IsEmpty()); |
| 716 CHECK(try_catch.HasCaught()); | 713 CHECK(!try_catch.HasCaught()); |
| 717 String::Utf8Value exception_value(try_catch.Exception()); | |
| 718 CHECK_EQ(0, strcmp("RangeError: Invalid string length", *exception_value)); | |
| 719 } | 714 } |
| 720 } | 715 } |
| 721 | 716 |
| 722 | 717 |
| 723 THREADED_TEST(ScavengeExternalString) { | 718 THREADED_TEST(ScavengeExternalString) { |
| 724 i::FLAG_stress_compaction = false; | 719 i::FLAG_stress_compaction = false; |
| 725 i::FLAG_gc_global = false; | 720 i::FLAG_gc_global = false; |
| 726 int dispose_count = 0; | 721 int dispose_count = 0; |
| 727 bool in_new_space = false; | 722 bool in_new_space = false; |
| 728 { | 723 { |
| (...skipping 20882 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 21611 const char* chunks[] = {"function foo() { ret", "urn 13; }\n//#", | 21606 const char* chunks[] = {"function foo() { ret", "urn 13; }\n//#", |
| 21612 " sourceMappingURL=bar2.js\n", "foo();", NULL}; | 21607 " sourceMappingURL=bar2.js\n", "foo();", NULL}; |
| 21613 RunStreamingTest(chunks, v8::ScriptCompiler::StreamedSource::UTF8, true, NULL, | 21608 RunStreamingTest(chunks, v8::ScriptCompiler::StreamedSource::UTF8, true, NULL, |
| 21614 "bar2.js"); | 21609 "bar2.js"); |
| 21615 } | 21610 } |
| 21616 | 21611 |
| 21617 | 21612 |
| 21618 TEST(NewStringRangeError) { | 21613 TEST(NewStringRangeError) { |
| 21619 v8::Isolate* isolate = CcTest::isolate(); | 21614 v8::Isolate* isolate = CcTest::isolate(); |
| 21620 v8::HandleScope handle_scope(isolate); | 21615 v8::HandleScope handle_scope(isolate); |
| 21621 LocalContext env; | |
| 21622 const int length = i::String::kMaxLength + 1; | 21616 const int length = i::String::kMaxLength + 1; |
| 21623 const int buffer_size = length * sizeof(uint16_t); | 21617 const int buffer_size = length * sizeof(uint16_t); |
| 21624 void* buffer = malloc(buffer_size); | 21618 void* buffer = malloc(buffer_size); |
| 21625 if (buffer == NULL) return; | 21619 if (buffer == NULL) return; |
| 21626 memset(buffer, 'A', buffer_size); | 21620 memset(buffer, 'A', buffer_size); |
| 21627 { | 21621 { |
| 21628 v8::TryCatch try_catch; | 21622 v8::TryCatch try_catch; |
| 21629 char* data = reinterpret_cast<char*>(buffer); | 21623 char* data = reinterpret_cast<char*>(buffer); |
| 21630 CHECK(v8::String::NewFromUtf8(isolate, data, v8::String::kNormalString, | 21624 CHECK(v8::String::NewFromUtf8(isolate, data, v8::String::kNormalString, |
| 21631 length).IsEmpty()); | 21625 length).IsEmpty()); |
| 21632 CHECK(try_catch.HasCaught()); | 21626 CHECK(!try_catch.HasCaught()); |
| 21633 } | 21627 } |
| 21634 { | 21628 { |
| 21635 v8::TryCatch try_catch; | 21629 v8::TryCatch try_catch; |
| 21636 uint8_t* data = reinterpret_cast<uint8_t*>(buffer); | 21630 uint8_t* data = reinterpret_cast<uint8_t*>(buffer); |
| 21637 CHECK(v8::String::NewFromOneByte(isolate, data, v8::String::kNormalString, | 21631 CHECK(v8::String::NewFromOneByte(isolate, data, v8::String::kNormalString, |
| 21638 length).IsEmpty()); | 21632 length).IsEmpty()); |
| 21639 CHECK(try_catch.HasCaught()); | 21633 CHECK(!try_catch.HasCaught()); |
| 21640 } | 21634 } |
| 21641 { | 21635 { |
| 21642 v8::TryCatch try_catch; | 21636 v8::TryCatch try_catch; |
| 21643 uint16_t* data = reinterpret_cast<uint16_t*>(buffer); | 21637 uint16_t* data = reinterpret_cast<uint16_t*>(buffer); |
| 21644 CHECK(v8::String::NewFromTwoByte(isolate, data, v8::String::kNormalString, | 21638 CHECK(v8::String::NewFromTwoByte(isolate, data, v8::String::kNormalString, |
| 21645 length).IsEmpty()); | 21639 length).IsEmpty()); |
| 21646 CHECK(try_catch.HasCaught()); | 21640 CHECK(!try_catch.HasCaught()); |
| 21647 } | 21641 } |
| 21648 free(buffer); | 21642 free(buffer); |
| 21649 } | 21643 } |
| OLD | NEW |