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