blob: b7b4a8fd3fbb50211eedb088aacbe6cee9a8dcb0 [file] [log] [blame]
Avi Drissman468e51b62022-09-13 20:47:011// Copyright 2014 The Chromium Authors
[email protected]6d73d2a62014-03-01 06:45:102// 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 Elphick05acd602021-08-30 15:22:0710#include "v8/include/v8-context.h"
11#include "v8/include/v8-isolate.h"
[email protected]6d73d2a62014-03-01 06:45:1012
13namespace gin {
14
15typedef V8Test PerContextDataTest;
16
17// Verifies PerContextData can be looked up by context and that it is not
18// available once ContextHolder is destroyed.
19TEST_F(PerContextDataTest, LookupAndDestruction) {
20 v8::Isolate::Scope isolate_scope(instance_->isolate());
21 v8::HandleScope handle_scope(instance_->isolate());
deepak.sfaaa1b62015-04-30 07:30:4822 v8::Local<v8::Context> context = v8::Context::New(
23 instance_->isolate(), NULL, v8::Local<v8::ObjectTemplate>());
[email protected]6d73d2a62014-03-01 06:45:1024 {
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