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

Side by Side Diff: src/api.cc

Issue 6472001: Fix forging of object's identity hashes. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 10 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 | test/cctest/test-api.cc » ('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 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 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 2637 matching lines...) Expand 10 before | Expand all | Expand 10 after
2648 EXCEPTION_BAILOUT_CHECK(Local<Object>()); 2648 EXCEPTION_BAILOUT_CHECK(Local<Object>());
2649 return Utils::ToLocal(result); 2649 return Utils::ToLocal(result);
2650 } 2650 }
2651 2651
2652 2652
2653 int v8::Object::GetIdentityHash() { 2653 int v8::Object::GetIdentityHash() {
2654 ON_BAILOUT("v8::Object::GetIdentityHash()", return 0); 2654 ON_BAILOUT("v8::Object::GetIdentityHash()", return 0);
2655 ENTER_V8; 2655 ENTER_V8;
2656 HandleScope scope; 2656 HandleScope scope;
2657 i::Handle<i::JSObject> self = Utils::OpenHandle(this); 2657 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
2658 i::Handle<i::Object> hidden_props(i::GetHiddenProperties(self, true)); 2658 i::Handle<i::Object> hidden_props_obj(i::GetHiddenProperties(self, true));
2659 i::Handle<i::Object> hash_symbol = i::Factory::identity_hash_symbol(); 2659 if (!hidden_props_obj->IsJSObject()) {
2660 i::Handle<i::Object> hash = i::GetProperty(hidden_props, hash_symbol); 2660 // We failed to create hidden properties. That's a detached
2661 // global proxy.
2662 ASSERT(hidden_props_obj->IsUndefined());
2663 return 0;
2664 }
2665 i::Handle<i::JSObject> hidden_props =
2666 i::Handle<i::JSObject>::cast(hidden_props_obj);
2667 i::Handle<i::String> hash_symbol = i::Factory::identity_hash_symbol();
2668 if (hidden_props->HasLocalProperty(*hash_symbol)) {
2669 i::Handle<i::Object> hash = i::GetProperty(hidden_props, hash_symbol);
2670 CHECK(!hash.is_null());
2671 CHECK(hash->IsSmi());
2672 return i::Smi::cast(*hash)->value();
2673 }
2674
2661 int hash_value; 2675 int hash_value;
2662 if (hash->IsSmi()) { 2676 int attempts = 0;
2663 hash_value = i::Smi::cast(*hash)->value(); 2677 do {
2664 } else { 2678 // Generate a random 32-bit hash value but limit range to fit
2665 int attempts = 0; 2679 // within a smi.
2666 do { 2680 hash_value = i::V8::Random() & i::Smi::kMaxValue;
2667 // Generate a random 32-bit hash value but limit range to fit 2681 attempts++;
2668 // within a smi. 2682 } while (hash_value == 0 && attempts < 30);
2669 hash_value = i::V8::Random() & i::Smi::kMaxValue; 2683 hash_value = hash_value != 0 ? hash_value : 1; // never return 0
2670 attempts++; 2684 CHECK(!i::SetLocalPropertyIgnoreAttributes(
2671 } while (hash_value == 0 && attempts < 30); 2685 hidden_props,
2672 hash_value = hash_value != 0 ? hash_value : 1; // never return 0 2686 hash_symbol,
2673 i::SetProperty(hidden_props, 2687 i::Handle<i::Object>(i::Smi::FromInt(hash_value)),
2674 hash_symbol, 2688 static_cast<PropertyAttributes>(None)).is_null());
2675 i::Handle<i::Object>(i::Smi::FromInt(hash_value)), 2689
2676 static_cast<PropertyAttributes>(None));
2677 }
2678 return hash_value; 2690 return hash_value;
2679 } 2691 }
2680 2692
2681 2693
2682 bool v8::Object::SetHiddenValue(v8::Handle<v8::String> key, 2694 bool v8::Object::SetHiddenValue(v8::Handle<v8::String> key,
2683 v8::Handle<v8::Value> value) { 2695 v8::Handle<v8::Value> value) {
2684 ON_BAILOUT("v8::Object::SetHiddenValue()", return false); 2696 ON_BAILOUT("v8::Object::SetHiddenValue()", return false);
2685 ENTER_V8; 2697 ENTER_V8;
2686 HandleScope scope; 2698 HandleScope scope;
2687 i::Handle<i::JSObject> self = Utils::OpenHandle(this); 2699 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
(...skipping 2474 matching lines...) Expand 10 before | Expand all | Expand 10 after
5162 5174
5163 5175
5164 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) { 5176 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) {
5165 HandleScopeImplementer* thread_local = 5177 HandleScopeImplementer* thread_local =
5166 reinterpret_cast<HandleScopeImplementer*>(storage); 5178 reinterpret_cast<HandleScopeImplementer*>(storage);
5167 thread_local->IterateThis(v); 5179 thread_local->IterateThis(v);
5168 return storage + ArchiveSpacePerThread(); 5180 return storage + ArchiveSpacePerThread();
5169 } 5181 }
5170 5182
5171 } } // namespace v8::internal 5183 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698