Avi Drissman | 468e51b6 | 2022-09-13 20:47:01 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors |
[email protected] | 6d73d2a6 | 2014-03-01 06:45:10 | [diff] [blame] | 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" |
Dan Elphick | 05acd60 | 2021-08-30 15:22:07 | [diff] [blame] | 10 | #include "v8/include/v8-context.h" |
| 11 | #include "v8/include/v8-isolate.h" |
[email protected] | 6d73d2a6 | 2014-03-01 06:45:10 | [diff] [blame] | 12 | |
| 13 | namespace gin { |
| 14 | |
| 15 | typedef V8Test PerContextDataTest; |
| 16 | |
| 17 | // Verifies PerContextData can be looked up by context and that it is not |
| 18 | // available once ContextHolder is destroyed. |
| 19 | TEST_F(PerContextDataTest, LookupAndDestruction) { |
| 20 | v8::Isolate::Scope isolate_scope(instance_->isolate()); |
| 21 | v8::HandleScope handle_scope(instance_->isolate()); |
deepak.s | faaa1b6 | 2015-04-30 07:30:48 | [diff] [blame] | 22 | v8::Local<v8::Context> context = v8::Context::New( |
| 23 | instance_->isolate(), NULL, v8::Local<v8::ObjectTemplate>()); |
[email protected] | 6d73d2a6 | 2014-03-01 06:45:10 | [diff] [blame] | 24 | { |
| 25 | ContextHolder context_holder(instance_->isolate()); |
| 26 | context_holder.SetContext(context); |
| 27 | PerContextData* per_context_data = PerContextData::From(context); |
| 28 | EXPECT_TRUE(per_context_data != NULL); |
| 29 | EXPECT_EQ(&context_holder, per_context_data->context_holder()); |
| 30 | } |
| 31 | PerContextData* per_context_data = PerContextData::From(context); |
| 32 | EXPECT_TRUE(per_context_data == NULL); |
| 33 | } |
| 34 | |
| 35 | } // namespace gin |