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

Side by Side Diff: src/api.cc

Issue 7349005: Added dictionary that can use objects as keys. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Added unit test to gyp buildfile as well. Created 9 years, 5 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | src/handles.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 3074 matching lines...) Expand 10 before | Expand all | Expand 10 after
3085 return Utils::ToLocal(i::Handle<i::Context>(context)); 3085 return Utils::ToLocal(i::Handle<i::Context>(context));
3086 } 3086 }
3087 3087
3088 3088
3089 int v8::Object::GetIdentityHash() { 3089 int v8::Object::GetIdentityHash() {
3090 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); 3090 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3091 ON_BAILOUT(isolate, "v8::Object::GetIdentityHash()", return 0); 3091 ON_BAILOUT(isolate, "v8::Object::GetIdentityHash()", return 0);
3092 ENTER_V8(isolate); 3092 ENTER_V8(isolate);
3093 i::HandleScope scope(isolate); 3093 i::HandleScope scope(isolate);
3094 i::Handle<i::JSObject> self = Utils::OpenHandle(this); 3094 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
3095 i::Handle<i::Object> hidden_props_obj(i::GetHiddenProperties(self, true)); 3095 return i::GetIdentityHash(self)->value();
3096 if (!hidden_props_obj->IsJSObject()) {
3097 // We failed to create hidden properties. That's a detached
3098 // global proxy.
3099 ASSERT(hidden_props_obj->IsUndefined());
3100 return 0;
3101 }
3102 i::Handle<i::JSObject> hidden_props =
3103 i::Handle<i::JSObject>::cast(hidden_props_obj);
3104 i::Handle<i::String> hash_symbol = isolate->factory()->identity_hash_symbol();
3105 if (hidden_props->HasLocalProperty(*hash_symbol)) {
3106 i::Handle<i::Object> hash = i::GetProperty(hidden_props, hash_symbol);
3107 CHECK(!hash.is_null());
3108 CHECK(hash->IsSmi());
3109 return i::Smi::cast(*hash)->value();
3110 }
3111
3112 int hash_value;
3113 int attempts = 0;
3114 do {
3115 // Generate a random 32-bit hash value but limit range to fit
3116 // within a smi.
3117 hash_value = i::V8::Random(self->GetIsolate()) & i::Smi::kMaxValue;
3118 attempts++;
3119 } while (hash_value == 0 && attempts < 30);
3120 hash_value = hash_value != 0 ? hash_value : 1; // never return 0
3121 CHECK(!i::SetLocalPropertyIgnoreAttributes(
3122 hidden_props,
3123 hash_symbol,
3124 i::Handle<i::Object>(i::Smi::FromInt(hash_value)),
3125 static_cast<PropertyAttributes>(None)).is_null());
3126
3127 return hash_value;
3128 } 3096 }
3129 3097
3130 3098
3131 bool v8::Object::SetHiddenValue(v8::Handle<v8::String> key, 3099 bool v8::Object::SetHiddenValue(v8::Handle<v8::String> key,
3132 v8::Handle<v8::Value> value) { 3100 v8::Handle<v8::Value> value) {
3133 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); 3101 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3134 ON_BAILOUT(isolate, "v8::Object::SetHiddenValue()", return false); 3102 ON_BAILOUT(isolate, "v8::Object::SetHiddenValue()", return false);
3135 ENTER_V8(isolate); 3103 ENTER_V8(isolate);
3136 i::HandleScope scope(isolate); 3104 i::HandleScope scope(isolate);
3137 i::Handle<i::JSObject> self = Utils::OpenHandle(this); 3105 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
(...skipping 2960 matching lines...) Expand 10 before | Expand all | Expand 10 after
6098 6066
6099 6067
6100 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) { 6068 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) {
6101 HandleScopeImplementer* scope_implementer = 6069 HandleScopeImplementer* scope_implementer =
6102 reinterpret_cast<HandleScopeImplementer*>(storage); 6070 reinterpret_cast<HandleScopeImplementer*>(storage);
6103 scope_implementer->IterateThis(v); 6071 scope_implementer->IterateThis(v);
6104 return storage + ArchiveSpacePerThread(); 6072 return storage + ArchiveSpacePerThread();
6105 } 6073 }
6106 6074
6107 } } // namespace v8::internal 6075 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | src/handles.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698