context_holder.cc 778 B

123456789101112131415161718192021222324252627282930
  1. // Copyright 2013 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. #include "gin/public/context_holder.h"
  5. #include <memory>
  6. #include "base/check.h"
  7. #include "gin/per_context_data.h"
  8. namespace gin {
  9. ContextHolder::ContextHolder(v8::Isolate* isolate)
  10. : isolate_(isolate) {
  11. }
  12. ContextHolder::~ContextHolder() {
  13. // PerContextData needs to be destroyed before the context.
  14. data_.reset();
  15. }
  16. void ContextHolder::SetContext(v8::Local<v8::Context> context) {
  17. DCHECK(context_.IsEmpty());
  18. context_.Reset(isolate_, context);
  19. context_.AnnotateStrongRetainer("gin::ContextHolder::context_");
  20. data_ = std::make_unique<PerContextData>(this, context);
  21. }
  22. } // namespace gin