1 // Copyright 2014 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "gin/per_context_data.h" 6 7 #include "gin/public/context_holder.h" 8 #include "gin/public/isolate_holder.h" 9 #include "gin/test/v8_test.h" 10 #include "v8/include/v8.h" 11 12 namespace gin { 13 14 typedef V8Test PerContextDataTest; 15 16 // Verifies PerContextData can be looked up by context and that it is not 17 // available once ContextHolder is destroyed. 18 TEST_F(PerContextDataTest, LookupAndDestruction) { 19 v8::Isolate::Scope isolate_scope(instance_->isolate()); 20 v8::HandleScope handle_scope(instance_->isolate()); 21 v8::Handle<v8::Context> context = v8::Context::New( 22 instance_->isolate(), NULL, v8::Handle<v8::ObjectTemplate>()); 23 { 24 ContextHolder context_holder(instance_->isolate()); 25 context_holder.SetContext(context); 26 PerContextData* per_context_data = PerContextData::From(context); 27 EXPECT_TRUE(per_context_data != NULL); 28 EXPECT_EQ(&context_holder, per_context_data->context_holder()); 29 } 30 PerContextData* per_context_data = PerContextData::From(context); 31 EXPECT_TRUE(per_context_data == NULL); 32 } 33 34 } // namespace gin 35