V8 Project
prototype.h
Go to the documentation of this file.
1 // Copyright 2014 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 
5 #ifndef V8_PROTOTYPE_H_
6 #define V8_PROTOTYPE_H_
7 
8 #include "src/isolate.h"
9 #include "src/objects.h"
10 
11 namespace v8 {
12 namespace internal {
13 
14 /**
15  * A class to uniformly access the prototype of any Object and walk its
16  * prototype chain.
17  *
18  * The PrototypeIterator can either start at the prototype (default), or
19  * include the receiver itself. If a PrototypeIterator is constructed for a
20  * Map, it will always start at the prototype.
21  *
22  * The PrototypeIterator can either run to the null_value(), the first
23  * non-hidden prototype, or a given object.
24  */
26  public:
28 
30 
32  WhereToStart where_to_start = START_AT_PROTOTYPE)
34  object_(NULL),
35  handle_(receiver),
36  isolate_(isolate) {
37  CHECK(!handle_.is_null());
38  if (where_to_start == START_AT_PROTOTYPE) {
39  Advance();
40  }
41  }
42  PrototypeIterator(Isolate* isolate, Object* receiver,
43  WhereToStart where_to_start = START_AT_PROTOTYPE)
45  object_(receiver),
46  isolate_(isolate) {
47  if (where_to_start == START_AT_PROTOTYPE) {
48  Advance();
49  }
50  }
51  explicit PrototypeIterator(Map* receiver_map)
53  object_(receiver_map->prototype()),
54  isolate_(receiver_map->GetIsolate()) {}
55  explicit PrototypeIterator(Handle<Map> receiver_map)
57  object_(NULL),
58  handle_(handle(receiver_map->prototype(), receiver_map->GetIsolate())),
59  isolate_(receiver_map->GetIsolate()) {}
61 
62  Object* GetCurrent() const {
63  DCHECK(handle_.is_null());
64  return object_;
65  }
66  static Handle<Object> GetCurrent(const PrototypeIterator& iterator) {
67  DCHECK(!iterator.handle_.is_null());
68  return iterator.handle_;
69  }
70  void Advance() {
71  if (handle_.is_null() && object_->IsJSProxy()) {
73  object_ = isolate_->heap()->null_value();
74  return;
75  } else if (!handle_.is_null() && handle_->IsJSProxy()) {
77  handle_ = handle(isolate_->heap()->null_value(), isolate_);
78  return;
79  }
81  }
85  if (handle_.is_null()) {
86  object_ = object_->GetRootMap(isolate_)->prototype();
87  } else {
88  handle_ = handle(handle_->GetRootMap(isolate_)->prototype(), isolate_);
89  }
90  } else {
91  if (handle_.is_null()) {
92  object_ = HeapObject::cast(object_)->map()->prototype();
93  } else {
94  handle_ =
95  handle(HeapObject::cast(*handle_)->map()->prototype(), isolate_);
96  }
97  }
98  }
99  bool IsAtEnd(WhereToEnd where_to_end = END_AT_NULL) const {
100  if (handle_.is_null()) {
101  return object_->IsNull() ||
103  where_to_end == END_AT_NON_HIDDEN &&
104  !HeapObject::cast(object_)->map()->is_hidden_prototype());
105  } else {
106  return handle_->IsNull() ||
108  where_to_end == END_AT_NON_HIDDEN &&
109  !Handle<HeapObject>::cast(handle_)->map()->is_hidden_prototype());
110  }
111  }
112  bool IsAtEnd(Object* final_object) {
113  DCHECK(handle_.is_null());
114  return object_->IsNull() || object_ == final_object;
115  }
116  bool IsAtEnd(Handle<Object> final_object) {
117  DCHECK(!handle_.is_null());
118  return handle_->IsNull() || *handle_ == *final_object;
119  }
120 
121  private:
126 
128 };
129 
130 
131 } // namespace internal
132 
133 } // namespace v8
134 
135 #endif // V8_PROTOTYPE_H_
static Handle< T > cast(Handle< S > that)
Definition: handles.h:116
Map * GetRootMap(Isolate *isolate)
Definition: objects.cc:803
A class to uniformly access the prototype of any Object and walk its prototype chain.
Definition: prototype.h:25
bool IsAtEnd(Object *final_object)
Definition: prototype.h:112
PrototypeIterator(Isolate *isolate, Object *receiver, WhereToStart where_to_start=START_AT_PROTOTYPE)
Definition: prototype.h:42
static Handle< Object > GetCurrent(const PrototypeIterator &iterator)
Definition: prototype.h:66
PrototypeIterator(Map *receiver_map)
Definition: prototype.h:51
PrototypeIterator(Isolate *isolate, Handle< Object > receiver, WhereToStart where_to_start=START_AT_PROTOTYPE)
Definition: prototype.h:31
PrototypeIterator(Handle< Map > receiver_map)
Definition: prototype.h:55
bool IsAtEnd(Handle< Object > final_object)
Definition: prototype.h:116
bool IsAtEnd(WhereToEnd where_to_end=END_AT_NULL) const
Definition: prototype.h:99
DISALLOW_COPY_AND_ASSIGN(PrototypeIterator)
Object * GetCurrent() const
Definition: prototype.h:62
enable harmony numeric enable harmony object literal extensions true
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be NULL
#define CHECK(condition)
Definition: logging.h:36
#define DCHECK(condition)
Definition: logging.h:205
Handle< T > handle(T *t, Isolate *isolate)
Definition: handles.h:146
Debugger support for the V8 JavaScript engine.
Definition: accessors.cc:20