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

Side by Side Diff: src/api.cc

Issue 7385006: Reintroduced dictionary that can use objects as keys. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Incorporated review by Vitaly Repeshko. Created 9 years, 4 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/factory.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 3174 matching lines...) Expand 10 before | Expand all | Expand 10 after
3185 return Utils::ToLocal(i::Handle<i::Context>(context)); 3185 return Utils::ToLocal(i::Handle<i::Context>(context));
3186 } 3186 }
3187 3187
3188 3188
3189 int v8::Object::GetIdentityHash() { 3189 int v8::Object::GetIdentityHash() {
3190 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); 3190 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3191 ON_BAILOUT(isolate, "v8::Object::GetIdentityHash()", return 0); 3191 ON_BAILOUT(isolate, "v8::Object::GetIdentityHash()", return 0);
3192 ENTER_V8(isolate); 3192 ENTER_V8(isolate);
3193 i::HandleScope scope(isolate); 3193 i::HandleScope scope(isolate);
3194 i::Handle<i::JSObject> self = Utils::OpenHandle(this); 3194 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
3195 i::Handle<i::Object> hidden_props_obj(i::GetHiddenProperties(self, true)); 3195 return i::GetIdentityHash(self);
3196 if (!hidden_props_obj->IsJSObject()) {
3197 // We failed to create hidden properties. That's a detached
3198 // global proxy.
3199 ASSERT(hidden_props_obj->IsUndefined());
3200 return 0;
3201 }
3202 i::Handle<i::JSObject> hidden_props =
3203 i::Handle<i::JSObject>::cast(hidden_props_obj);
3204 i::Handle<i::String> hash_symbol = isolate->factory()->identity_hash_symbol();
3205 if (hidden_props->HasLocalProperty(*hash_symbol)) {
3206 i::Handle<i::Object> hash = i::GetProperty(hidden_props, hash_symbol);
3207 CHECK(!hash.is_null());
3208 CHECK(hash->IsSmi());
3209 return i::Smi::cast(*hash)->value();
3210 }
3211
3212 int hash_value;
3213 int attempts = 0;
3214 do {
3215 // Generate a random 32-bit hash value but limit range to fit
3216 // within a smi.
3217 hash_value = i::V8::Random(self->GetIsolate()) & i::Smi::kMaxValue;
3218 attempts++;
3219 } while (hash_value == 0 && attempts < 30);
3220 hash_value = hash_value != 0 ? hash_value : 1; // never return 0
3221 CHECK(!i::SetLocalPropertyIgnoreAttributes(
3222 hidden_props,
3223 hash_symbol,
3224 i::Handle<i::Object>(i::Smi::FromInt(hash_value)),
3225 static_cast<PropertyAttributes>(None)).is_null());
3226
3227 return hash_value;
3228 } 3196 }
3229 3197
3230 3198
3231 bool v8::Object::SetHiddenValue(v8::Handle<v8::String> key, 3199 bool v8::Object::SetHiddenValue(v8::Handle<v8::String> key,
3232 v8::Handle<v8::Value> value) { 3200 v8::Handle<v8::Value> value) {
3233 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); 3201 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3234 ON_BAILOUT(isolate, "v8::Object::SetHiddenValue()", return false); 3202 ON_BAILOUT(isolate, "v8::Object::SetHiddenValue()", return false);
3235 ENTER_V8(isolate); 3203 ENTER_V8(isolate);
3236 i::HandleScope scope(isolate); 3204 i::HandleScope scope(isolate);
3237 i::Handle<i::JSObject> self = Utils::OpenHandle(this); 3205 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
3238 i::Handle<i::Object> hidden_props(i::GetHiddenProperties(self, true)); 3206 i::Handle<i::Object> hidden_props(i::GetHiddenProperties(
3207 self,
3208 i::JSObject::ALLOW_CREATION));
3239 i::Handle<i::Object> key_obj = Utils::OpenHandle(*key); 3209 i::Handle<i::Object> key_obj = Utils::OpenHandle(*key);
3240 i::Handle<i::Object> value_obj = Utils::OpenHandle(*value); 3210 i::Handle<i::Object> value_obj = Utils::OpenHandle(*value);
3241 EXCEPTION_PREAMBLE(isolate); 3211 EXCEPTION_PREAMBLE(isolate);
3242 i::Handle<i::Object> obj = i::SetProperty( 3212 i::Handle<i::Object> obj = i::SetProperty(
3243 hidden_props, 3213 hidden_props,
3244 key_obj, 3214 key_obj,
3245 value_obj, 3215 value_obj,
3246 static_cast<PropertyAttributes>(None), 3216 static_cast<PropertyAttributes>(None),
3247 i::kNonStrictMode); 3217 i::kNonStrictMode);
3248 has_pending_exception = obj.is_null(); 3218 has_pending_exception = obj.is_null();
3249 EXCEPTION_BAILOUT_CHECK(isolate, false); 3219 EXCEPTION_BAILOUT_CHECK(isolate, false);
3250 return true; 3220 return true;
3251 } 3221 }
3252 3222
3253 3223
3254 v8::Local<v8::Value> v8::Object::GetHiddenValue(v8::Handle<v8::String> key) { 3224 v8::Local<v8::Value> v8::Object::GetHiddenValue(v8::Handle<v8::String> key) {
3255 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); 3225 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3256 ON_BAILOUT(isolate, "v8::Object::GetHiddenValue()", 3226 ON_BAILOUT(isolate, "v8::Object::GetHiddenValue()",
3257 return Local<v8::Value>()); 3227 return Local<v8::Value>());
3258 ENTER_V8(isolate); 3228 ENTER_V8(isolate);
3259 i::Handle<i::JSObject> self = Utils::OpenHandle(this); 3229 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
3260 i::Handle<i::Object> hidden_props(i::GetHiddenProperties(self, false)); 3230 i::Handle<i::Object> hidden_props(i::GetHiddenProperties(
3231 self,
3232 i::JSObject::OMIT_CREATION));
3261 if (hidden_props->IsUndefined()) { 3233 if (hidden_props->IsUndefined()) {
3262 return v8::Local<v8::Value>(); 3234 return v8::Local<v8::Value>();
3263 } 3235 }
3264 i::Handle<i::String> key_obj = Utils::OpenHandle(*key); 3236 i::Handle<i::String> key_obj = Utils::OpenHandle(*key);
3265 EXCEPTION_PREAMBLE(isolate); 3237 EXCEPTION_PREAMBLE(isolate);
3266 i::Handle<i::Object> result = i::GetProperty(hidden_props, key_obj); 3238 i::Handle<i::Object> result = i::GetProperty(hidden_props, key_obj);
3267 has_pending_exception = result.is_null(); 3239 has_pending_exception = result.is_null();
3268 EXCEPTION_BAILOUT_CHECK(isolate, v8::Local<v8::Value>()); 3240 EXCEPTION_BAILOUT_CHECK(isolate, v8::Local<v8::Value>());
3269 if (result->IsUndefined()) { 3241 if (result->IsUndefined()) {
3270 return v8::Local<v8::Value>(); 3242 return v8::Local<v8::Value>();
3271 } 3243 }
3272 return Utils::ToLocal(result); 3244 return Utils::ToLocal(result);
3273 } 3245 }
3274 3246
3275 3247
3276 bool v8::Object::DeleteHiddenValue(v8::Handle<v8::String> key) { 3248 bool v8::Object::DeleteHiddenValue(v8::Handle<v8::String> key) {
3277 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); 3249 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3278 ON_BAILOUT(isolate, "v8::DeleteHiddenValue()", return false); 3250 ON_BAILOUT(isolate, "v8::DeleteHiddenValue()", return false);
3279 ENTER_V8(isolate); 3251 ENTER_V8(isolate);
3280 i::HandleScope scope(isolate); 3252 i::HandleScope scope(isolate);
3281 i::Handle<i::JSObject> self = Utils::OpenHandle(this); 3253 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
3282 i::Handle<i::Object> hidden_props(i::GetHiddenProperties(self, false)); 3254 i::Handle<i::Object> hidden_props(i::GetHiddenProperties(
3255 self,
3256 i::JSObject::OMIT_CREATION));
3283 if (hidden_props->IsUndefined()) { 3257 if (hidden_props->IsUndefined()) {
3284 return true; 3258 return true;
3285 } 3259 }
3286 i::Handle<i::JSObject> js_obj(i::JSObject::cast(*hidden_props)); 3260 i::Handle<i::JSObject> js_obj(i::JSObject::cast(*hidden_props));
3287 i::Handle<i::String> key_obj = Utils::OpenHandle(*key); 3261 i::Handle<i::String> key_obj = Utils::OpenHandle(*key);
3288 return i::DeleteProperty(js_obj, key_obj)->IsTrue(); 3262 return i::DeleteProperty(js_obj, key_obj)->IsTrue();
3289 } 3263 }
3290 3264
3291 3265
3292 namespace { 3266 namespace {
(...skipping 2770 matching lines...) Expand 10 before | Expand all | Expand 10 after
6063 6037
6064 6038
6065 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) { 6039 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) {
6066 HandleScopeImplementer* scope_implementer = 6040 HandleScopeImplementer* scope_implementer =
6067 reinterpret_cast<HandleScopeImplementer*>(storage); 6041 reinterpret_cast<HandleScopeImplementer*>(storage);
6068 scope_implementer->IterateThis(v); 6042 scope_implementer->IterateThis(v);
6069 return storage + ArchiveSpacePerThread(); 6043 return storage + ArchiveSpacePerThread();
6070 } 6044 }
6071 6045
6072 } } // namespace v8::internal 6046 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | src/factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698