Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(405)

Unified Diff: src/objects.cc

Issue 254433002: Store JSGlobalProxy's identity hash directly on the proxy itself (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Re-introduce %UnwrapProxy to make Object.observe work Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« src/object-observe.js ('K') | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index 48f962503c320a904c53285395a6a595845ee11d..5b0aac71c03915cd106ce09440853d5ca05422e6 100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -4965,9 +4965,7 @@ Handle<SeededNumberDictionary> JSObject::NormalizeElements(
}
-Smi* JSReceiver::GenerateIdentityHash() {
- Isolate* isolate = GetIsolate();
-
+static Smi* GenerateIdentityHash(Isolate* isolate) {
int hash_value;
int attempts = 0;
do {
@@ -4983,33 +4981,48 @@ Smi* JSReceiver::GenerateIdentityHash() {
void JSObject::SetIdentityHash(Handle<JSObject> object, Handle<Smi> hash) {
+ ASSERT(!object->IsJSGlobalProxy());
Isolate* isolate = object->GetIsolate();
SetHiddenProperty(object, isolate->factory()->identity_hash_string(), hash);
}
+template<typename ProxyType>
+static Handle<Object> GetOrCreateIdentityHashHelper(Handle<ProxyType> proxy) {
+ Isolate* isolate = proxy->GetIsolate();
+
+ Handle<Object> hash(proxy->hash(), isolate);
+ if (hash->IsSmi())
Toon Verwaest 2014/04/28 14:32:50 Either put on single line or use { }
adamk 2014/04/28 18:44:50 Done. This was pre-existing code, fwiw.
+ return hash;
+
+ hash = handle(GenerateIdentityHash(isolate), isolate);
+ proxy->set_hash(*hash);
+ return hash;
+}
+
+
Object* JSObject::GetIdentityHash() {
+ if (IsJSGlobalProxy()) {
+ return JSGlobalProxy::cast(this)->hash();
+ }
Object* stored_value = GetHiddenProperty(GetHeap()->identity_hash_string());
return stored_value->IsSmi() ? stored_value : GetHeap()->undefined_value();
}
Handle<Object> JSObject::GetOrCreateIdentityHash(Handle<JSObject> object) {
- Handle<Object> hash(object->GetIdentityHash(), object->GetIsolate());
- if (hash->IsSmi())
- return hash;
+ if (object->IsJSGlobalProxy()) {
+ return GetOrCreateIdentityHashHelper(Handle<JSGlobalProxy>::cast(object));
+ }
Isolate* isolate = object->GetIsolate();
- hash = handle(object->GenerateIdentityHash(), isolate);
- Handle<Object> result = SetHiddenProperty(object,
- isolate->factory()->identity_hash_string(), hash);
-
- if (result->IsUndefined()) {
- // Trying to get hash of detached proxy.
- return handle(Smi::FromInt(0), isolate);
- }
+ Handle<Object> hash(object->GetIdentityHash(), isolate);
+ if (hash->IsSmi())
Toon Verwaest 2014/04/28 14:32:50 Same as above
adamk 2014/04/28 18:44:50 Done.
+ return hash;
+ hash = handle(GenerateIdentityHash(isolate), isolate);
+ SetHiddenProperty(object, isolate->factory()->identity_hash_string(), hash);
return hash;
}
@@ -5020,21 +5033,15 @@ Object* JSProxy::GetIdentityHash() {
Handle<Object> JSProxy::GetOrCreateIdentityHash(Handle<JSProxy> proxy) {
- Isolate* isolate = proxy->GetIsolate();
-
- Handle<Object> hash(proxy->GetIdentityHash(), isolate);
- if (hash->IsSmi())
- return hash;
-
- hash = handle(proxy->GenerateIdentityHash(), isolate);
- proxy->set_hash(*hash);
- return hash;
+ return GetOrCreateIdentityHashHelper(proxy);
}
Object* JSObject::GetHiddenProperty(Name* key) {
ASSERT(key->IsUniqueName());
if (IsJSGlobalProxy()) {
+ // JSGlobalProxies store their hash internally.
+ ASSERT(key != GetHeap()->identity_hash_string());
// For a proxy, use the prototype as target object.
Object* proxy_parent = GetPrototype();
// If the proxy is detached, return undefined.
@@ -5069,6 +5076,8 @@ Handle<Object> JSObject::SetHiddenProperty(Handle<JSObject> object,
ASSERT(key->IsUniqueName());
if (object->IsJSGlobalProxy()) {
+ // JSGlobalProxies store their hash internally.
+ ASSERT(*key != *isolate->factory()->identity_hash_string());
// For a proxy, use the prototype as target object.
Handle<Object> proxy_parent(object->GetPrototype(), isolate);
// If the proxy is detached, return undefined.
« src/object-observe.js ('K') | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698