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 1177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1188 public: | 1188 public: |
1189 explicit OneByteVectorResource(i::Vector<const char> vector) | 1189 explicit OneByteVectorResource(i::Vector<const char> vector) |
1190 : data_(vector) {} | 1190 : data_(vector) {} |
1191 virtual ~OneByteVectorResource() {} | 1191 virtual ~OneByteVectorResource() {} |
1192 virtual size_t length() const { return data_.length(); } | 1192 virtual size_t length() const { return data_.length(); } |
1193 virtual const char* data() const { return data_.start(); } | 1193 virtual const char* data() const { return data_.start(); } |
1194 private: | 1194 private: |
1195 i::Vector<const char> data_; | 1195 i::Vector<const char> data_; |
1196 }; | 1196 }; |
1197 | 1197 |
| 1198 TEST(InternalizeExternal) { |
| 1199 i::Isolate* isolate = CcTest::i_isolate(); |
| 1200 Factory* factory = isolate->factory(); |
| 1201 // This won't leak; the external string mechanism will call Dispose() on it. |
| 1202 OneByteVectorResource* resource = |
| 1203 new OneByteVectorResource(i::Vector<const char>("prop", 4)); |
| 1204 { |
| 1205 v8::HandleScope scope(CcTest::isolate()); |
| 1206 v8::Local<v8::String> ext_string = |
| 1207 v8::String::NewExternalOneByte(CcTest::isolate(), resource) |
| 1208 .ToLocalChecked(); |
| 1209 Handle<String> string = v8::Utils::OpenHandle(*ext_string); |
| 1210 CHECK(string->IsExternalString()); |
| 1211 CHECK(!string->IsInternalizedString()); |
| 1212 CHECK(isolate->heap()->InNewSpace(*string)); |
| 1213 factory->InternalizeName(string); |
| 1214 CHECK(string->IsThinString()); |
| 1215 CcTest::CollectGarbage(i::NEW_SPACE); |
| 1216 CcTest::CollectGarbage(i::NEW_SPACE); |
| 1217 CHECK(string->IsInternalizedString()); |
| 1218 CHECK(!isolate->heap()->InNewSpace(*string)); |
| 1219 } |
| 1220 CcTest::CollectGarbage(i::OLD_SPACE); |
| 1221 CcTest::CollectGarbage(i::OLD_SPACE); |
| 1222 } |
1198 | 1223 |
1199 TEST(SliceFromExternal) { | 1224 TEST(SliceFromExternal) { |
1200 FLAG_string_slices = true; | 1225 FLAG_string_slices = true; |
1201 CcTest::InitializeVM(); | 1226 CcTest::InitializeVM(); |
1202 Factory* factory = CcTest::i_isolate()->factory(); | 1227 Factory* factory = CcTest::i_isolate()->factory(); |
1203 v8::HandleScope scope(CcTest::isolate()); | 1228 v8::HandleScope scope(CcTest::isolate()); |
1204 OneByteVectorResource resource( | 1229 OneByteVectorResource resource( |
1205 i::Vector<const char>("abcdefghijklmnopqrstuvwxyz", 26)); | 1230 i::Vector<const char>("abcdefghijklmnopqrstuvwxyz", 26)); |
1206 Handle<String> string = | 1231 Handle<String> string = |
1207 factory->NewExternalStringFromOneByte(&resource).ToHandleChecked(); | 1232 factory->NewExternalStringFromOneByte(&resource).ToHandleChecked(); |
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1637 CHECK_EQ(1, CompileRun("external.indexOf('', 1)") | 1662 CHECK_EQ(1, CompileRun("external.indexOf('', 1)") |
1638 ->Int32Value(context.local()) | 1663 ->Int32Value(context.local()) |
1639 .FromJust()); | 1664 .FromJust()); |
1640 CHECK_EQ(-1, CompileRun("external.indexOf('a', 1)") | 1665 CHECK_EQ(-1, CompileRun("external.indexOf('a', 1)") |
1641 ->Int32Value(context.local()) | 1666 ->Int32Value(context.local()) |
1642 .FromJust()); | 1667 .FromJust()); |
1643 CHECK_EQ(-1, CompileRun("external.indexOf('$')") | 1668 CHECK_EQ(-1, CompileRun("external.indexOf('$')") |
1644 ->Int32Value(context.local()) | 1669 ->Int32Value(context.local()) |
1645 .FromJust()); | 1670 .FromJust()); |
1646 } | 1671 } |
OLD | NEW |