dc2e3069e7
Reason for revert: Cannot reproduce gc-stress failures locally. Original issue's description: > Revert of Replace all remaining Oddball checks with new function (patchset #10 id:180001 of https://codereview.chromium.org/2043183003/ ) > > Reason for revert: > failing tests > > Original issue's description: > > Replace all remaining Oddball checks with new function > > > > This CL removes the IsUndefined() and Co. methods from Object and HeapObject. > > The new method all take the isolate as parameter. > > > > BUG= > > > > Committed: https://crrev.com/ccefb3ae5fe967288d568013fb04e8761eafebc5 > > Cr-Commit-Position: refs/heads/master@{#36921} > > TBR=mstarzinger@chromium.org,verwaest@chromium.org,yangguo@chromium.org,ahaas@chromium.org > # Skipping CQ checks because original CL landed less than 1 days ago. > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG= > > Committed: https://crrev.com/33b8bc24a12fb062100c0be84456faeb0b9fa5d1 > Cr-Commit-Position: refs/heads/master@{#36923} TBR=mstarzinger@chromium.org,verwaest@chromium.org,yangguo@chromium.org,ahaas@chromium.org BUG= Review-Url: https://codereview.chromium.org/2059173002 Cr-Commit-Position: refs/heads/master@{#36957}
180 lines
5.3 KiB
C++
180 lines
5.3 KiB
C++
// Copyright 2014 the V8 project authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#ifndef V8_PROTOTYPE_H_
|
|
#define V8_PROTOTYPE_H_
|
|
|
|
#include "src/isolate.h"
|
|
#include "src/objects.h"
|
|
|
|
namespace v8 {
|
|
namespace internal {
|
|
|
|
/**
|
|
* A class to uniformly access the prototype of any Object and walk its
|
|
* prototype chain.
|
|
*
|
|
* The PrototypeIterator can either start at the prototype (default), or
|
|
* include the receiver itself. If a PrototypeIterator is constructed for a
|
|
* Map, it will always start at the prototype.
|
|
*
|
|
* The PrototypeIterator can either run to the null_value(), the first
|
|
* non-hidden prototype, or a given object.
|
|
*/
|
|
|
|
class PrototypeIterator {
|
|
public:
|
|
enum WhereToEnd { END_AT_NULL, END_AT_NON_HIDDEN };
|
|
|
|
const int kProxyPrototypeLimit = 100 * 1000;
|
|
|
|
PrototypeIterator(Isolate* isolate, Handle<JSReceiver> receiver,
|
|
WhereToStart where_to_start = kStartAtPrototype,
|
|
WhereToEnd where_to_end = END_AT_NULL)
|
|
: object_(NULL),
|
|
handle_(receiver),
|
|
isolate_(isolate),
|
|
where_to_end_(where_to_end),
|
|
is_at_end_(false),
|
|
seen_proxies_(0) {
|
|
CHECK(!handle_.is_null());
|
|
if (where_to_start == kStartAtPrototype) Advance();
|
|
}
|
|
|
|
PrototypeIterator(Isolate* isolate, JSReceiver* receiver,
|
|
WhereToStart where_to_start = kStartAtPrototype,
|
|
WhereToEnd where_to_end = END_AT_NULL)
|
|
: object_(receiver),
|
|
isolate_(isolate),
|
|
where_to_end_(where_to_end),
|
|
is_at_end_(false),
|
|
seen_proxies_(0) {
|
|
if (where_to_start == kStartAtPrototype) Advance();
|
|
}
|
|
|
|
explicit PrototypeIterator(Map* receiver_map)
|
|
: object_(receiver_map->prototype()),
|
|
isolate_(receiver_map->GetIsolate()),
|
|
where_to_end_(END_AT_NULL),
|
|
is_at_end_(object_->IsNull(isolate_)),
|
|
seen_proxies_(0) {}
|
|
|
|
explicit PrototypeIterator(Handle<Map> receiver_map)
|
|
: object_(NULL),
|
|
handle_(handle(receiver_map->prototype(), receiver_map->GetIsolate())),
|
|
isolate_(receiver_map->GetIsolate()),
|
|
where_to_end_(END_AT_NULL),
|
|
is_at_end_(handle_->IsNull(isolate_)),
|
|
seen_proxies_(0) {}
|
|
|
|
~PrototypeIterator() {}
|
|
|
|
bool HasAccess() const {
|
|
// We can only perform access check in the handlified version of the
|
|
// PrototypeIterator.
|
|
DCHECK(!handle_.is_null());
|
|
if (handle_->IsAccessCheckNeeded()) {
|
|
return isolate_->MayAccess(handle(isolate_->context()),
|
|
Handle<JSObject>::cast(handle_));
|
|
}
|
|
return true;
|
|
}
|
|
|
|
template <typename T = Object>
|
|
T* GetCurrent() const {
|
|
DCHECK(handle_.is_null());
|
|
return T::cast(object_);
|
|
}
|
|
|
|
template <typename T = Object>
|
|
static Handle<T> GetCurrent(const PrototypeIterator& iterator) {
|
|
DCHECK(!iterator.handle_.is_null());
|
|
DCHECK(iterator.object_ == NULL);
|
|
return Handle<T>::cast(iterator.handle_);
|
|
}
|
|
|
|
void Advance() {
|
|
if (handle_.is_null() && object_->IsJSProxy()) {
|
|
is_at_end_ = true;
|
|
object_ = isolate_->heap()->null_value();
|
|
return;
|
|
} else if (!handle_.is_null() && handle_->IsJSProxy()) {
|
|
is_at_end_ = true;
|
|
handle_ = isolate_->factory()->null_value();
|
|
return;
|
|
}
|
|
AdvanceIgnoringProxies();
|
|
}
|
|
|
|
void AdvanceIgnoringProxies() {
|
|
Object* object = handle_.is_null() ? object_ : *handle_;
|
|
Map* map = HeapObject::cast(object)->map();
|
|
|
|
Object* prototype = map->prototype();
|
|
is_at_end_ = where_to_end_ == END_AT_NON_HIDDEN
|
|
? !map->has_hidden_prototype()
|
|
: prototype->IsNull(isolate_);
|
|
|
|
if (handle_.is_null()) {
|
|
object_ = prototype;
|
|
} else {
|
|
handle_ = handle(prototype, isolate_);
|
|
}
|
|
}
|
|
|
|
// Returns false iff a call to JSProxy::GetPrototype throws.
|
|
// TODO(neis): This should probably replace Advance().
|
|
MUST_USE_RESULT bool AdvanceFollowingProxies() {
|
|
DCHECK(!(handle_.is_null() && object_->IsJSProxy()));
|
|
if (!HasAccess()) {
|
|
// Abort the lookup if we do not have access to the current object.
|
|
handle_ = isolate_->factory()->null_value();
|
|
is_at_end_ = true;
|
|
return true;
|
|
}
|
|
return AdvanceFollowingProxiesIgnoringAccessChecks();
|
|
}
|
|
|
|
MUST_USE_RESULT bool AdvanceFollowingProxiesIgnoringAccessChecks() {
|
|
if (handle_.is_null() || !handle_->IsJSProxy()) {
|
|
AdvanceIgnoringProxies();
|
|
return true;
|
|
}
|
|
|
|
// Due to possible __proto__ recursion limit the number of Proxies
|
|
// we visit to an arbitrarily chosen large number.
|
|
seen_proxies_++;
|
|
if (seen_proxies_ > kProxyPrototypeLimit) {
|
|
isolate_->Throw(
|
|
*isolate_->factory()->NewRangeError(MessageTemplate::kStackOverflow));
|
|
return false;
|
|
}
|
|
MaybeHandle<Object> proto =
|
|
JSProxy::GetPrototype(Handle<JSProxy>::cast(handle_));
|
|
if (!proto.ToHandle(&handle_)) return false;
|
|
is_at_end_ =
|
|
where_to_end_ == END_AT_NON_HIDDEN || handle_->IsNull(isolate_);
|
|
return true;
|
|
}
|
|
|
|
bool IsAtEnd() const { return is_at_end_; }
|
|
|
|
private:
|
|
Object* object_;
|
|
Handle<Object> handle_;
|
|
Isolate* isolate_;
|
|
WhereToEnd where_to_end_;
|
|
bool is_at_end_;
|
|
int seen_proxies_;
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(PrototypeIterator);
|
|
};
|
|
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|
|
|
|
#endif // V8_PROTOTYPE_H_
|