per_context_data.cc 1.0 KB

12345678910111213141516171819202122232425262728293031
  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/per_context_data.h"
  5. #include "gin/public/context_holder.h"
  6. #include "gin/public/wrapper_info.h"
  7. namespace gin {
  8. PerContextData::PerContextData(ContextHolder* context_holder,
  9. v8::Local<v8::Context> context)
  10. : context_holder_(context_holder), runner_(nullptr) {
  11. context->SetAlignedPointerInEmbedderData(
  12. int{kPerContextDataStartIndex} + kEmbedderNativeGin, this);
  13. }
  14. PerContextData::~PerContextData() {
  15. v8::HandleScope handle_scope(context_holder_->isolate());
  16. context_holder_->context()->SetAlignedPointerInEmbedderData(
  17. int{kPerContextDataStartIndex} + kEmbedderNativeGin, NULL);
  18. }
  19. // static
  20. PerContextData* PerContextData::From(v8::Local<v8::Context> context) {
  21. return static_cast<PerContextData*>(
  22. context->GetAlignedPointerFromEmbedderData(kEncodedValueIndex));
  23. }
  24. } // namespace gin