 Chromium Code Reviews
 Chromium Code Reviews Issue 978783002:
  give UniquePersistent full move semantics  (Closed) 
  Base URL: https://chromium.googlesource.com/v8/v8.git@master
    
  
    Issue 978783002:
  give UniquePersistent full move semantics  (Closed) 
  Base URL: https://chromium.googlesource.com/v8/v8.git@master| 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 10 matching lines...) Expand all Loading... | |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 
| 27 | 27 | 
| 28 #include <climits> | 28 #include <climits> | 
| 29 #include <csignal> | 29 #include <csignal> | 
| 30 #include <map> | 30 #include <map> | 
| 31 #include <memory> | |
| 31 #include <string> | 32 #include <string> | 
| 32 | 33 | 
| 33 #include "test/cctest/test-api.h" | 34 #include "test/cctest/test-api.h" | 
| 34 | 35 | 
| 35 #if V8_OS_POSIX | 36 #if V8_OS_POSIX | 
| 36 #include <unistd.h> // NOLINT | 37 #include <unistd.h> // NOLINT | 
| 37 #endif | 38 #endif | 
| 38 | 39 | 
| 39 #include "include/v8-util.h" | 40 #include "include/v8-util.h" | 
| 40 #include "src/api.h" | 41 #include "src/api.h" | 
| (...skipping 3195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3236 | 3237 | 
| 3237 CHECK_EQ(5 + handle_count, global_handles->global_handles_count()); | 3238 CHECK_EQ(5 + handle_count, global_handles->global_handles_count()); | 
| 3238 | 3239 | 
| 3239 vector.Clear(); | 3240 vector.Clear(); | 
| 3240 CHECK(vector.IsEmpty()); | 3241 CHECK(vector.IsEmpty()); | 
| 3241 CHECK_EQ(0, static_cast<int>(vector.Size())); | 3242 CHECK_EQ(0, static_cast<int>(vector.Size())); | 
| 3242 CHECK_EQ(handle_count, global_handles->global_handles_count()); | 3243 CHECK_EQ(handle_count, global_handles->global_handles_count()); | 
| 3243 } | 3244 } | 
| 3244 | 3245 | 
| 3245 | 3246 | 
| 3247 TEST(PersistentStdContainerCompatible) { | |
| 3248 LocalContext env; | |
| 3249 v8::Isolate* isolate = env->GetIsolate(); | |
| 3250 v8::internal::GlobalHandles* global_handles = | |
| 3251 reinterpret_cast<v8::internal::Isolate*>(isolate)->global_handles(); | |
| 3252 int handle_count = global_handles->global_handles_count(); | |
| 3253 HandleScope scope(isolate); | |
| 3254 | |
| 3255 std::vector<v8::UniquePersistent<v8::Object>> vector; | |
| 3256 | |
| 3257 auto obj = v8::Object::New(isolate); | |
| 3258 v8::UniquePersistent<v8::Object> global(isolate, obj); | |
| 3259 | |
| 3260 vector.push_back(std::move(global)); | |
| 
jamesr
2015/03/04 18:52:37
this won't compile on all platforms that chromium
 
dcarney
2015/03/04 19:40:24
this test stuff is v8 only.  I just wanted to chec
 | |
| 3261 | |
| 3262 CHECK_EQ(1, static_cast<int>(vector.size())); | |
| 3263 CHECK(global.IsEmpty()); | |
| 3264 CHECK(obj == vector[0]); | |
| 3265 | |
| 3266 CHECK_EQ(1 + handle_count, global_handles->global_handles_count()); | |
| 3267 | |
| 3268 vector.clear(); | |
| 3269 CHECK_EQ(handle_count, global_handles->global_handles_count()); | |
| 3270 } | |
| 3271 | |
| 3272 | |
| 3246 THREADED_TEST(GlobalHandleUpcast) { | 3273 THREADED_TEST(GlobalHandleUpcast) { | 
| 3247 v8::Isolate* isolate = CcTest::isolate(); | 3274 v8::Isolate* isolate = CcTest::isolate(); | 
| 3248 v8::HandleScope scope(isolate); | 3275 v8::HandleScope scope(isolate); | 
| 3249 v8::Local<String> local = v8::Local<String>::New(isolate, v8_str("str")); | 3276 v8::Local<String> local = v8::Local<String>::New(isolate, v8_str("str")); | 
| 3250 v8::Persistent<String> global_string(isolate, local); | 3277 v8::Persistent<String> global_string(isolate, local); | 
| 3251 v8::Persistent<Value>& global_value = | 3278 v8::Persistent<Value>& global_value = | 
| 3252 v8::Persistent<Value>::Cast(global_string); | 3279 v8::Persistent<Value>::Cast(global_string); | 
| 3253 CHECK(v8::Local<v8::Value>::New(isolate, global_value)->IsString()); | 3280 CHECK(v8::Local<v8::Value>::New(isolate, global_value)->IsString()); | 
| 3254 CHECK(global_string == v8::Persistent<String>::Cast(global_value)); | 3281 CHECK(global_string == v8::Persistent<String>::Cast(global_value)); | 
| 3255 global_string.Reset(); | 3282 global_string.Reset(); | 
| (...skipping 18327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 21583 } | 21610 } | 
| 21584 { | 21611 { | 
| 21585 v8::TryCatch try_catch; | 21612 v8::TryCatch try_catch; | 
| 21586 uint16_t* data = reinterpret_cast<uint16_t*>(buffer); | 21613 uint16_t* data = reinterpret_cast<uint16_t*>(buffer); | 
| 21587 CHECK(v8::String::NewFromTwoByte(isolate, data, v8::String::kNormalString, | 21614 CHECK(v8::String::NewFromTwoByte(isolate, data, v8::String::kNormalString, | 
| 21588 length).IsEmpty()); | 21615 length).IsEmpty()); | 
| 21589 CHECK(try_catch.HasCaught()); | 21616 CHECK(try_catch.HasCaught()); | 
| 21590 } | 21617 } | 
| 21591 free(buffer); | 21618 free(buffer); | 
| 21592 } | 21619 } | 
| OLD | NEW |