• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2021 the V8 project 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 #ifndef V8_HEAP_EMBEDDER_TRACING_INL_H_
5 #define V8_HEAP_EMBEDDER_TRACING_INL_H_
6 
7 #include "src/heap/embedder-tracing.h"
8 #include "src/objects/embedder-data-slot.h"
9 #include "src/objects/js-objects-inl.h"
10 
11 namespace v8 {
12 namespace internal {
13 
14 // static
ExtractWrappableInfo(Isolate * isolate,JSObject js_object,const WrapperDescriptor & wrapper_descriptor,WrapperInfo * info)15 bool LocalEmbedderHeapTracer::ExtractWrappableInfo(
16     Isolate* isolate, JSObject js_object,
17     const WrapperDescriptor& wrapper_descriptor, WrapperInfo* info) {
18   DCHECK(js_object.MayHaveEmbedderFields());
19   if (js_object.GetEmbedderFieldCount() < 2) return false;
20 
21   return ExtractWrappableInfo(
22       isolate, wrapper_descriptor,
23       EmbedderDataSlot(js_object, wrapper_descriptor.wrappable_type_index),
24       EmbedderDataSlot(js_object, wrapper_descriptor.wrappable_instance_index),
25       info);
26 }
27 
28 // static
ExtractWrappableInfo(Isolate * isolate,const WrapperDescriptor & wrapper_descriptor,const EmbedderDataSlot & type_slot,const EmbedderDataSlot & instance_slot,WrapperInfo * info)29 bool LocalEmbedderHeapTracer::ExtractWrappableInfo(
30     Isolate* isolate, const WrapperDescriptor& wrapper_descriptor,
31     const EmbedderDataSlot& type_slot, const EmbedderDataSlot& instance_slot,
32     WrapperInfo* info) {
33   if (type_slot.ToAlignedPointer(isolate, &info->first) && info->first &&
34       instance_slot.ToAlignedPointer(isolate, &info->second) && info->second) {
35     return (wrapper_descriptor.embedder_id_for_garbage_collected ==
36             WrapperDescriptor::kUnknownEmbedderId) ||
37            (*static_cast<uint16_t*>(info->first) ==
38             wrapper_descriptor.embedder_id_for_garbage_collected);
39   }
40   return false;
41 }
42 
43 }  // namespace internal
44 }  // namespace v8
45 
46 #endif  // V8_HEAP_EMBEDDER_TRACING_INL_H_
47