V8 Project
v8::internal::JSObjectWalkVisitor< ContextObject > Class Template Reference
+ Collaboration diagram for v8::internal::JSObjectWalkVisitor< ContextObject >:

Public Member Functions

 JSObjectWalkVisitor (ContextObject *site_context, bool copying, JSObject::DeepCopyHints hints)
 
MUST_USE_RESULT MaybeHandle< JSObjectStructureWalk (Handle< JSObject > object)
 

Protected Member Functions

MUST_USE_RESULT MaybeHandle< JSObjectVisitElementOrProperty (Handle< JSObject > object, Handle< JSObject > value)
 
ContextObject * site_context ()
 
Isolateisolate ()
 
bool copying () const
 

Private Attributes

ContextObject * site_context_
 
const bool copying_
 
const JSObject::DeepCopyHints hints_
 

Detailed Description

template<class ContextObject>
class v8::internal::JSObjectWalkVisitor< ContextObject >

Definition at line 5372 of file objects.cc.

Constructor & Destructor Documentation

◆ JSObjectWalkVisitor()

template<class ContextObject >
v8::internal::JSObjectWalkVisitor< ContextObject >::JSObjectWalkVisitor ( ContextObject *  site_context,
bool  copying,
JSObject::DeepCopyHints  hints 
)
inline

Definition at line 5374 of file objects.cc.

5377  copying_(copying),
5378  hints_(hints) {}
ContextObject * site_context()
Definition: objects.cc:5392
const JSObject::DeepCopyHints hints_
Definition: objects.cc:5400

Member Function Documentation

◆ copying()

template<class ContextObject >
bool v8::internal::JSObjectWalkVisitor< ContextObject >::copying ( ) const
inlineprotected

Definition at line 5395 of file objects.cc.

5395 { return copying_; }

◆ isolate()

template<class ContextObject >
Isolate* v8::internal::JSObjectWalkVisitor< ContextObject >::isolate ( )
inlineprotected

Definition at line 5393 of file objects.cc.

5393 { return site_context()->isolate(); }

◆ site_context()

template<class ContextObject >
ContextObject* v8::internal::JSObjectWalkVisitor< ContextObject >::site_context ( )
inlineprotected

Definition at line 5392 of file objects.cc.

5392 { return site_context_; }

◆ StructureWalk()

template<class ContextObject >
MaybeHandle< JSObject > v8::internal::JSObjectWalkVisitor< ContextObject >::StructureWalk ( Handle< JSObject object)

Definition at line 5405 of file objects.cc.

5406  {
5407  Isolate* isolate = this->isolate();
5408  bool copying = this->copying();
5409  bool shallow = hints_ == JSObject::kObjectIsShallow;
5410 
5411  if (!shallow) {
5412  StackLimitCheck check(isolate);
5413 
5414  if (check.HasOverflowed()) {
5416  return MaybeHandle<JSObject>();
5417  }
5418  }
5419 
5420  if (object->map()->is_deprecated()) {
5421  JSObject::MigrateInstance(object);
5422  }
5423 
5424  Handle<JSObject> copy;
5425  if (copying) {
5426  Handle<AllocationSite> site_to_pass;
5427  if (site_context()->ShouldCreateMemento(object)) {
5428  site_to_pass = site_context()->current();
5429  }
5430  copy = isolate->factory()->CopyJSObjectWithAllocationSite(
5431  object, site_to_pass);
5432  } else {
5433  copy = object;
5434  }
5435 
5436  DCHECK(copying || copy.is_identical_to(object));
5437 
5438  ElementsKind kind = copy->GetElementsKind();
5439  if (copying && IsFastSmiOrObjectElementsKind(kind) &&
5440  FixedArray::cast(copy->elements())->map() ==
5441  isolate->heap()->fixed_cow_array_map()) {
5442  isolate->counters()->cow_arrays_created_runtime()->Increment();
5443  }
5444 
5445  if (!shallow) {
5446  HandleScope scope(isolate);
5447 
5448  // Deep copy own properties.
5449  if (copy->HasFastProperties()) {
5450  Handle<DescriptorArray> descriptors(copy->map()->instance_descriptors());
5451  int limit = copy->map()->NumberOfOwnDescriptors();
5452  for (int i = 0; i < limit; i++) {
5453  PropertyDetails details = descriptors->GetDetails(i);
5454  if (details.type() != FIELD) continue;
5455  FieldIndex index = FieldIndex::ForDescriptor(copy->map(), i);
5456  Handle<Object> value(object->RawFastPropertyAt(index), isolate);
5457  if (value->IsJSObject()) {
5459  isolate, value,
5461  JSObject);
5462  } else {
5463  Representation representation = details.representation();
5464  value = Object::NewStorageFor(isolate, value, representation);
5465  }
5466  if (copying) {
5467  copy->FastPropertyAtPut(index, *value);
5468  }
5469  }
5470  } else {
5471  Handle<FixedArray> names =
5472  isolate->factory()->NewFixedArray(copy->NumberOfOwnProperties());
5473  copy->GetOwnPropertyNames(*names, 0);
5474  for (int i = 0; i < names->length(); i++) {
5475  DCHECK(names->get(i)->IsString());
5476  Handle<String> key_string(String::cast(names->get(i)));
5477  Maybe<PropertyAttributes> maybe =
5478  JSReceiver::GetOwnPropertyAttributes(copy, key_string);
5479  DCHECK(maybe.has_value);
5480  PropertyAttributes attributes = maybe.value;
5481  // Only deep copy fields from the object literal expression.
5482  // In particular, don't try to copy the length attribute of
5483  // an array.
5484  if (attributes != NONE) continue;
5485  Handle<Object> value =
5486  Object::GetProperty(copy, key_string).ToHandleChecked();
5487  if (value->IsJSObject()) {
5488  Handle<JSObject> result;
5490  isolate, result,
5492  JSObject);
5493  if (copying) {
5494  // Creating object copy for literals. No strict mode needed.
5495  JSObject::SetProperty(copy, key_string, result, SLOPPY).Assert();
5496  }
5497  }
5498  }
5499  }
5500 
5501  // Deep copy own elements.
5502  // Pixel elements cannot be created using an object literal.
5503  DCHECK(!copy->HasExternalArrayElements());
5504  switch (kind) {
5505  case FAST_SMI_ELEMENTS:
5506  case FAST_ELEMENTS:
5508  case FAST_HOLEY_ELEMENTS: {
5509  Handle<FixedArray> elements(FixedArray::cast(copy->elements()));
5510  if (elements->map() == isolate->heap()->fixed_cow_array_map()) {
5511 #ifdef DEBUG
5512  for (int i = 0; i < elements->length(); i++) {
5513  DCHECK(!elements->get(i)->IsJSObject());
5514  }
5515 #endif
5516  } else {
5517  for (int i = 0; i < elements->length(); i++) {
5518  Handle<Object> value(elements->get(i), isolate);
5519  DCHECK(value->IsSmi() ||
5520  value->IsTheHole() ||
5521  (IsFastObjectElementsKind(copy->GetElementsKind())));
5522  if (value->IsJSObject()) {
5523  Handle<JSObject> result;
5525  isolate, result,
5527  JSObject);
5528  if (copying) {
5529  elements->set(i, *result);
5530  }
5531  }
5532  }
5533  }
5534  break;
5535  }
5536  case DICTIONARY_ELEMENTS: {
5537  Handle<SeededNumberDictionary> element_dictionary(
5538  copy->element_dictionary());
5539  int capacity = element_dictionary->Capacity();
5540  for (int i = 0; i < capacity; i++) {
5541  Object* k = element_dictionary->KeyAt(i);
5542  if (element_dictionary->IsKey(k)) {
5543  Handle<Object> value(element_dictionary->ValueAt(i), isolate);
5544  if (value->IsJSObject()) {
5545  Handle<JSObject> result;
5547  isolate, result,
5549  JSObject);
5550  if (copying) {
5551  element_dictionary->ValueAtPut(i, *result);
5552  }
5553  }
5554  }
5555  }
5556  break;
5557  }
5559  UNIMPLEMENTED();
5560  break;
5561 
5562 
5563 #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \
5564  case EXTERNAL_##TYPE##_ELEMENTS: \
5565  case TYPE##_ELEMENTS: \
5566 
5568 #undef TYPED_ARRAY_CASE
5569 
5570  case FAST_DOUBLE_ELEMENTS:
5572  // No contained objects, nothing to do.
5573  break;
5574  }
5575  }
5576 
5577  return copy;
5578 }
static Handle< T > cast(Handle< S > that)
Definition: handles.h:116
Counters * counters()
Definition: isolate.h:857
Object * StackOverflow()
Definition: isolate.cc:773
Factory * factory()
Definition: isolate.h:982
MUST_USE_RESULT MaybeHandle< JSObject > VisitElementOrProperty(Handle< JSObject > object, Handle< JSObject > value)
Definition: objects.cc:5383
static void MigrateInstance(Handle< JSObject > instance)
Definition: objects.cc:3728
static MUST_USE_RESULT Maybe< PropertyAttributes > GetOwnPropertyAttributes(Handle< JSReceiver > object, Handle< Name > name)
Definition: objects.cc:3983
static MUST_USE_RESULT MaybeHandle< Object > GetProperty(LookupIterator *it)
Definition: objects.cc:109
static Handle< Object > NewStorageFor(Isolate *isolate, Handle< Object > object, Representation representation)
Definition: objects-inl.h:277
static MUST_USE_RESULT MaybeHandle< Object > SetProperty(Handle< Object > object, Handle< Name > key, Handle< Object > value, StrictMode strict_mode, StoreFromKeyed store_mode=MAY_BE_STORE_FROM_KEYED)
Definition: objects.cc:2798
#define ASSIGN_RETURN_ON_EXCEPTION(isolate, dst, call, T)
Definition: isolate.h:135
#define UNIMPLEMENTED()
Definition: logging.h:28
#define DCHECK(condition)
Definition: logging.h:205
bool IsFastSmiOrObjectElementsKind(ElementsKind kind)
kSerializedDataOffset Object
Definition: objects-inl.h:5322
@ FAST_HOLEY_DOUBLE_ELEMENTS
Definition: elements-kind.h:27
@ SLOPPY_ARGUMENTS_ELEMENTS
Definition: elements-kind.h:31
@ FAST_HOLEY_SMI_ELEMENTS
Definition: elements-kind.h:17
bool IsFastObjectElementsKind(ElementsKind kind)
Maybe< T > maybe(T t)
Definition: v8.h:902
#define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size)
#define TYPED_ARRAYS(V)
Definition: objects.h:4433
PropertyAttributes
@ NONE

References ASSIGN_RETURN_ON_EXCEPTION, v8::internal::Isolate::counters(), DCHECK, v8::internal::DICTIONARY_ELEMENTS, v8::internal::Isolate::factory(), v8::internal::FAST_DOUBLE_ELEMENTS, v8::internal::FAST_ELEMENTS, v8::internal::FAST_HOLEY_DOUBLE_ELEMENTS, v8::internal::FAST_HOLEY_ELEMENTS, v8::internal::FAST_HOLEY_SMI_ELEMENTS, v8::internal::FAST_SMI_ELEMENTS, v8::internal::FIELD, v8::internal::JSReceiver::GetOwnPropertyAttributes(), v8::internal::Object::GetProperty(), v8::internal::Isolate::heap(), v8::internal::IsFastObjectElementsKind(), v8::internal::IsFastSmiOrObjectElementsKind(), v8::internal::JSObject::kObjectIsShallow, v8::maybe(), v8::internal::JSObject::MigrateInstance(), v8::internal::Object::NewStorageFor(), NONE, v8::internal::Object::SetProperty(), v8::internal::SLOPPY, v8::internal::SLOPPY_ARGUMENTS_ELEMENTS, v8::internal::Isolate::StackOverflow(), TYPED_ARRAY_CASE, TYPED_ARRAYS, and UNIMPLEMENTED.

Referenced by v8::internal::JSObject::DeepCopy(), and v8::internal::JSObject::DeepWalk().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ VisitElementOrProperty()

template<class ContextObject >
MUST_USE_RESULT MaybeHandle<JSObject> v8::internal::JSObjectWalkVisitor< ContextObject >::VisitElementOrProperty ( Handle< JSObject object,
Handle< JSObject value 
)
inlineprotected

Definition at line 5383 of file objects.cc.

5385  {
5386  Handle<AllocationSite> current_site = site_context()->EnterNewScope();
5387  MaybeHandle<JSObject> copy_of_value = StructureWalk(value);
5388  site_context()->ExitScope(current_site, value);
5389  return copy_of_value;
5390  }
MUST_USE_RESULT MaybeHandle< JSObject > StructureWalk(Handle< JSObject > object)
Definition: objects.cc:5405

Member Data Documentation

◆ copying_

template<class ContextObject >
const bool v8::internal::JSObjectWalkVisitor< ContextObject >::copying_
private

Definition at line 5399 of file objects.cc.

◆ hints_

template<class ContextObject >
const JSObject::DeepCopyHints v8::internal::JSObjectWalkVisitor< ContextObject >::hints_
private

Definition at line 5400 of file objects.cc.

◆ site_context_

template<class ContextObject >
ContextObject* v8::internal::JSObjectWalkVisitor< ContextObject >::site_context_
private

Definition at line 5398 of file objects.cc.


The documentation for this class was generated from the following file: