| OLD | NEW |
| 1 // Copyright 2007-2010 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2010 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 883 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 894 Execution::Call(isolate, copy_fun, global, 0, NULL).ToHandleChecked(); | 894 Execution::Call(isolate, copy_fun, global, 0, NULL).ToHandleChecked(); |
| 895 | 895 |
| 896 CHECK_EQ(6 * 1000000, Handle<String>::cast(copy_result)->length()); | 896 CHECK_EQ(6 * 1000000, Handle<String>::cast(copy_result)->length()); |
| 897 CHECK(isolate->heap()->InSpace(HeapObject::cast(*copy_result), LO_SPACE)); | 897 CHECK(isolate->heap()->InSpace(HeapObject::cast(*copy_result), LO_SPACE)); |
| 898 | 898 |
| 899 delete cache; | 899 delete cache; |
| 900 source.Dispose(); | 900 source.Dispose(); |
| 901 } | 901 } |
| 902 | 902 |
| 903 | 903 |
| 904 class OneByteResource : public v8::String::ExternalOneByteStringResource { | 904 class SerializerOneByteResource |
| 905 : public v8::String::ExternalOneByteStringResource { |
| 905 public: | 906 public: |
| 906 OneByteResource(const char* data, size_t length) | 907 SerializerOneByteResource(const char* data, size_t length) |
| 907 : data_(data), length_(length) {} | 908 : data_(data), length_(length) {} |
| 908 virtual const char* data() const { return data_; } | 909 virtual const char* data() const { return data_; } |
| 909 virtual size_t length() const { return length_; } | 910 virtual size_t length() const { return length_; } |
| 910 | 911 |
| 911 private: | 912 private: |
| 912 const char* data_; | 913 const char* data_; |
| 913 size_t length_; | 914 size_t length_; |
| 914 }; | 915 }; |
| 915 | 916 |
| 916 | 917 |
| 917 class TwoByteResource : public v8::String::ExternalStringResource { | 918 class SerializerTwoByteResource : public v8::String::ExternalStringResource { |
| 918 public: | 919 public: |
| 919 TwoByteResource(const char* data, size_t length) | 920 SerializerTwoByteResource(const char* data, size_t length) |
| 920 : data_(AsciiToTwoByteString(data)), length_(length) {} | 921 : data_(AsciiToTwoByteString(data)), length_(length) {} |
| 921 ~TwoByteResource() { DeleteArray<const uint16_t>(data_); } | 922 ~SerializerTwoByteResource() { DeleteArray<const uint16_t>(data_); } |
| 922 | 923 |
| 923 virtual const uint16_t* data() const { return data_; } | 924 virtual const uint16_t* data() const { return data_; } |
| 924 virtual size_t length() const { return length_; } | 925 virtual size_t length() const { return length_; } |
| 925 | 926 |
| 926 private: | 927 private: |
| 927 const uint16_t* data_; | 928 const uint16_t* data_; |
| 928 size_t length_; | 929 size_t length_; |
| 929 }; | 930 }; |
| 930 | 931 |
| 931 | 932 |
| 932 TEST(SerializeToplevelExternalString) { | 933 TEST(SerializeToplevelExternalString) { |
| 933 FLAG_serialize_toplevel = true; | 934 FLAG_serialize_toplevel = true; |
| 934 LocalContext context; | 935 LocalContext context; |
| 935 Isolate* isolate = CcTest::i_isolate(); | 936 Isolate* isolate = CcTest::i_isolate(); |
| 936 isolate->compilation_cache()->Disable(); // Disable same-isolate code cache. | 937 isolate->compilation_cache()->Disable(); // Disable same-isolate code cache. |
| 937 | 938 |
| 938 v8::HandleScope scope(CcTest::isolate()); | 939 v8::HandleScope scope(CcTest::isolate()); |
| 939 | 940 |
| 940 // Obtain external internalized one-byte string. | 941 // Obtain external internalized one-byte string. |
| 941 OneByteResource one_byte_resource("one_byte", 8); | 942 SerializerOneByteResource one_byte_resource("one_byte", 8); |
| 942 Handle<String> one_byte_string = | 943 Handle<String> one_byte_string = |
| 943 isolate->factory()->NewStringFromAsciiChecked("one_byte"); | 944 isolate->factory()->NewStringFromAsciiChecked("one_byte"); |
| 944 one_byte_string = isolate->factory()->InternalizeString(one_byte_string); | 945 one_byte_string = isolate->factory()->InternalizeString(one_byte_string); |
| 945 one_byte_string->MakeExternal(&one_byte_resource); | 946 one_byte_string->MakeExternal(&one_byte_resource); |
| 946 CHECK(one_byte_string->IsExternalOneByteString()); | 947 CHECK(one_byte_string->IsExternalOneByteString()); |
| 947 CHECK(one_byte_string->IsInternalizedString()); | 948 CHECK(one_byte_string->IsInternalizedString()); |
| 948 | 949 |
| 949 // Obtain external internalized two-byte string. | 950 // Obtain external internalized two-byte string. |
| 950 TwoByteResource two_byte_resource("two_byte", 8); | 951 SerializerTwoByteResource two_byte_resource("two_byte", 8); |
| 951 Handle<String> two_byte_string = | 952 Handle<String> two_byte_string = |
| 952 isolate->factory()->NewStringFromAsciiChecked("two_byte"); | 953 isolate->factory()->NewStringFromAsciiChecked("two_byte"); |
| 953 two_byte_string = isolate->factory()->InternalizeString(two_byte_string); | 954 two_byte_string = isolate->factory()->InternalizeString(two_byte_string); |
| 954 two_byte_string->MakeExternal(&two_byte_resource); | 955 two_byte_string->MakeExternal(&two_byte_resource); |
| 955 CHECK(two_byte_string->IsExternalTwoByteString()); | 956 CHECK(two_byte_string->IsExternalTwoByteString()); |
| 956 CHECK(two_byte_string->IsInternalizedString()); | 957 CHECK(two_byte_string->IsInternalizedString()); |
| 957 | 958 |
| 958 const char* source = | 959 const char* source = |
| 959 "var o = {} \n" | 960 "var o = {} \n" |
| 960 "o.one_byte = 7; \n" | 961 "o.one_byte = 7; \n" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1003 | 1004 |
| 1004 Factory* f = isolate->factory(); | 1005 Factory* f = isolate->factory(); |
| 1005 | 1006 |
| 1006 v8::HandleScope scope(CcTest::isolate()); | 1007 v8::HandleScope scope(CcTest::isolate()); |
| 1007 | 1008 |
| 1008 // Create a huge external internalized string to use as variable name. | 1009 // Create a huge external internalized string to use as variable name. |
| 1009 Vector<const uint8_t> string = | 1010 Vector<const uint8_t> string = |
| 1010 ConstructSource(STATIC_CHAR_VECTOR(""), STATIC_CHAR_VECTOR("abcdef"), | 1011 ConstructSource(STATIC_CHAR_VECTOR(""), STATIC_CHAR_VECTOR("abcdef"), |
| 1011 STATIC_CHAR_VECTOR(""), 1000000); | 1012 STATIC_CHAR_VECTOR(""), 1000000); |
| 1012 Handle<String> name = f->NewStringFromOneByte(string).ToHandleChecked(); | 1013 Handle<String> name = f->NewStringFromOneByte(string).ToHandleChecked(); |
| 1013 OneByteResource one_byte_resource( | 1014 SerializerOneByteResource one_byte_resource( |
| 1014 reinterpret_cast<const char*>(string.start()), string.length()); | 1015 reinterpret_cast<const char*>(string.start()), string.length()); |
| 1015 name = f->InternalizeString(name); | 1016 name = f->InternalizeString(name); |
| 1016 name->MakeExternal(&one_byte_resource); | 1017 name->MakeExternal(&one_byte_resource); |
| 1017 CHECK(name->IsExternalOneByteString()); | 1018 CHECK(name->IsExternalOneByteString()); |
| 1018 CHECK(name->IsInternalizedString()); | 1019 CHECK(name->IsInternalizedString()); |
| 1019 CHECK(isolate->heap()->InSpace(*name, LO_SPACE)); | 1020 CHECK(isolate->heap()->InSpace(*name, LO_SPACE)); |
| 1020 | 1021 |
| 1021 // Create the source, which is "var <literal> = 42; <literal>". | 1022 // Create the source, which is "var <literal> = 42; <literal>". |
| 1022 Handle<String> source_str = | 1023 Handle<String> source_str = |
| 1023 f->NewConsString( | 1024 f->NewConsString( |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1102 { | 1103 { |
| 1103 DisallowCompilation no_compile(reinterpret_cast<Isolate*>(isolate2)); | 1104 DisallowCompilation no_compile(reinterpret_cast<Isolate*>(isolate2)); |
| 1104 script = v8::ScriptCompiler::CompileUnbound( | 1105 script = v8::ScriptCompiler::CompileUnbound( |
| 1105 isolate2, &source, v8::ScriptCompiler::kConsumeCodeCache); | 1106 isolate2, &source, v8::ScriptCompiler::kConsumeCodeCache); |
| 1106 } | 1107 } |
| 1107 v8::Local<v8::Value> result = script->BindToCurrentContext()->Run(); | 1108 v8::Local<v8::Value> result = script->BindToCurrentContext()->Run(); |
| 1108 CHECK(result->ToString()->Equals(v8_str("abcdef"))); | 1109 CHECK(result->ToString()->Equals(v8_str("abcdef"))); |
| 1109 } | 1110 } |
| 1110 isolate2->Dispose(); | 1111 isolate2->Dispose(); |
| 1111 } | 1112 } |
| OLD | NEW |