v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
prototype-inl.h
Go to the documentation of this file.
1// Copyright 2018 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_OBJECTS_PROTOTYPE_INL_H_
6#define V8_OBJECTS_PROTOTYPE_INL_H_
7
9// Include the non-inl header before the rest of the headers.
10
13#include "src/objects/map-inl.h"
14
15namespace v8 {
16namespace internal {
17
20 WhereToStart where_to_start,
21 WhereToEnd where_to_end)
22 : isolate_(isolate),
24 where_to_end_(where_to_end),
25 is_at_end_(false),
26 seen_proxies_(0) {
27 CHECK(!handle_.is_null());
28 if (where_to_start == kStartAtPrototype) Advance();
29}
30
33 WhereToStart where_to_start,
34 WhereToEnd where_to_end)
35 : isolate_(isolate),
37 where_to_end_(where_to_end),
38 is_at_end_(false),
39 seen_proxies_(0) {
40 if (where_to_start == kStartAtPrototype) Advance();
41}
42
44 WhereToEnd where_to_end)
45 : isolate_(isolate),
46 object_(receiver_map->GetPrototypeChainRootMap(isolate_)->prototype()),
47 where_to_end_(where_to_end),
48 is_at_end_(IsNull(object_, isolate_)),
49 seen_proxies_(0) {
51 DCHECK(IsJSReceiver(object_));
53 is_at_end_ = !IsJSGlobalProxyMap(map);
54 }
55}
56
58 DirectHandle<Map> receiver_map,
59 WhereToEnd where_to_end)
60 : isolate_(isolate),
61 handle_(receiver_map->GetPrototypeChainRootMap(isolate_)->prototype(),
62 isolate_),
63 where_to_end_(where_to_end),
64 is_at_end_(IsNull(*handle_, isolate_)),
65 seen_proxies_(0) {
67 DCHECK(IsJSReceiver(*handle_));
68 Tagged<Map> map = Cast<JSReceiver>(*handle_)->map();
69 is_at_end_ = !IsJSGlobalProxyMap(map);
70 }
71}
72
74 // We can only perform access check in the handlified version of the
75 // PrototypeIterator.
76 DCHECK(!handle_.is_null());
77 if (IsAccessCheckNeeded(*handle_)) {
80 }
81 return true;
82}
83
85 if (handle_.is_null() && IsJSProxy(object_)) {
86 is_at_end_ = true;
87 object_ = ReadOnlyRoots(isolate_).null_value();
88 return;
89 } else if (!handle_.is_null() && IsJSProxy(*handle_)) {
90 is_at_end_ = true;
91 handle_ = isolate_->factory()->null_value();
92 return;
93 }
95}
96
99 Tagged<Map> map = object->map();
100
101 Tagged<JSPrototype> prototype = map->prototype();
102 is_at_end_ = IsNull(prototype, isolate_) ||
103 (where_to_end_ == END_AT_NON_HIDDEN && !IsJSGlobalProxyMap(map));
104
105 if (handle_.is_null()) {
107 } else {
108 handle_ = handle(prototype, isolate_);
109 }
110}
111
113 DCHECK(!(handle_.is_null() && IsJSProxy(object_)));
114 if (!HasAccess()) {
115 // Abort the lookup if we do not have access to the current object.
116 handle_ = isolate_->factory()->null_value();
117 is_at_end_ = true;
118 return true;
119 }
121}
122
125 if (handle_.is_null() || !IsJSProxy(*handle_)) {
127 return true;
128 }
129
130 // Due to possible __proto__ recursion limit the number of Proxies
131 // we visit to an arbitrarily chosen large number.
135 return false;
136 }
139
140 // TODO(372390038): This can be again simplified when handle_ migrates to a
141 // direct handle.
142 DirectHandle<JSPrototype> proto_direct_handle;
143 bool ok = proto.ToHandle(&proto_direct_handle);
144 handle_ = indirect_handle(proto_direct_handle, isolate_);
145 if (!ok) return false;
146
148 return true;
149}
150
151} // namespace internal
152} // namespace v8
153
154#endif // V8_OBJECTS_PROTOTYPE_INL_H_
Isolate * isolate_
Handle< NativeContext > native_context()
Definition isolate-inl.h:48
v8::internal::Factory * factory()
Definition isolate.h:1527
Tagged< Object > StackOverflow()
Definition isolate.cc:1862
bool MayAccess(DirectHandle< NativeContext > accessing_context, DirectHandle< JSObject > receiver)
Definition isolate.cc:1815
static const int kMaxIterationLimit
Definition js-proxy.h:104
static MaybeDirectHandle< JSPrototype > GetPrototype(DirectHandle< JSProxy > receiver)
Definition objects.cc:1456
V8_WARN_UNUSED_RESULT V8_INLINE bool ToHandle(DirectHandle< S > *out) const
V8_WARN_UNUSED_RESULT bool AdvanceFollowingProxies()
IndirectHandle< JSPrototype > handle_
Definition prototype.h:83
Tagged< JSPrototype > object_
Definition prototype.h:79
PrototypeIterator(Isolate *isolate, DirectHandle< JSReceiver > receiver, WhereToStart where_to_start=kStartAtPrototype, WhereToEnd where_to_end=END_AT_NULL)
V8_WARN_UNUSED_RESULT bool AdvanceFollowingProxiesIgnoringAccessChecks()
V8_INLINE constexpr bool is_null() const
Definition tagged.h:502
Register const object_
TNode< Object > receiver
V8_INLINE IndirectHandle< T > handle(Tagged< T > object, Isolate *isolate)
Definition handles-inl.h:72
V8_INLINE IndirectHandle< T > indirect_handle(DirectHandle< T > handle)
Definition handles.h:757
kInstanceDescriptorsOffset kTransitionsOrPrototypeInfoOffset IsNull(value)||IsJSProxy(value)||IsWasmObject(value)||(IsJSObject(value) &&(HeapLayout
Definition map-inl.h:70
@ kStartAtPrototype
Definition globals.h:1714
kInstanceDescriptorsOffset kTransitionsOrPrototypeInfoOffset prototype
Definition map-inl.h:69
Tagged< To > Cast(Tagged< From > value, const v8::SourceLocation &loc=INIT_SOURCE_LOCATION_IN_DEBUG)
Definition casting.h:150
#define CHECK(condition)
Definition logging.h:124
#define DCHECK(condition)
Definition logging.h:482
#define V8_WARN_UNUSED_RESULT
Definition v8config.h:671
WasmOrphanedGlobalHandle * handle_