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

Side by Side Diff: src/runtime.cc

Issue 279863002: Harden %WeakCollectionSet. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Added checks for WeakCollection(Has|Get|Delete) Created 6 years, 7 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 | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stdlib.h> 5 #include <stdlib.h>
6 #include <limits> 6 #include <limits>
7 7
8 #include "v8.h" 8 #include "v8.h"
9 9
10 #include "accessors.h" 10 #include "accessors.h"
(...skipping 1724 matching lines...) Expand 10 before | Expand all | Expand 10 after
1735 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0); 1735 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0);
1736 return *WeakCollectionInitialize(isolate, weak_collection); 1736 return *WeakCollectionInitialize(isolate, weak_collection);
1737 } 1737 }
1738 1738
1739 1739
1740 RUNTIME_FUNCTION(Runtime_WeakCollectionGet) { 1740 RUNTIME_FUNCTION(Runtime_WeakCollectionGet) {
1741 HandleScope scope(isolate); 1741 HandleScope scope(isolate);
1742 ASSERT(args.length() == 2); 1742 ASSERT(args.length() == 2);
1743 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0); 1743 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0);
1744 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); 1744 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
1745 RUNTIME_ASSERT(key->IsJSReceiver() || key->IsSymbol());
1745 Handle<ObjectHashTable> table( 1746 Handle<ObjectHashTable> table(
1746 ObjectHashTable::cast(weak_collection->table())); 1747 ObjectHashTable::cast(weak_collection->table()));
1747 RUNTIME_ASSERT(table->IsKey(*key)); 1748 RUNTIME_ASSERT(table->IsKey(*key));
1748 Handle<Object> lookup(table->Lookup(key), isolate); 1749 Handle<Object> lookup(table->Lookup(key), isolate);
1749 return lookup->IsTheHole() ? isolate->heap()->undefined_value() : *lookup; 1750 return lookup->IsTheHole() ? isolate->heap()->undefined_value() : *lookup;
1750 } 1751 }
1751 1752
1752 1753
1753 RUNTIME_FUNCTION(Runtime_WeakCollectionHas) { 1754 RUNTIME_FUNCTION(Runtime_WeakCollectionHas) {
1754 HandleScope scope(isolate); 1755 HandleScope scope(isolate);
1755 ASSERT(args.length() == 2); 1756 ASSERT(args.length() == 2);
1756 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0); 1757 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0);
1757 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); 1758 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
1759 RUNTIME_ASSERT(key->IsJSReceiver() || key->IsSymbol());
1758 Handle<ObjectHashTable> table( 1760 Handle<ObjectHashTable> table(
1759 ObjectHashTable::cast(weak_collection->table())); 1761 ObjectHashTable::cast(weak_collection->table()));
1760 RUNTIME_ASSERT(table->IsKey(*key)); 1762 RUNTIME_ASSERT(table->IsKey(*key));
1761 Handle<Object> lookup(table->Lookup(key), isolate); 1763 Handle<Object> lookup(table->Lookup(key), isolate);
1762 return isolate->heap()->ToBoolean(!lookup->IsTheHole()); 1764 return isolate->heap()->ToBoolean(!lookup->IsTheHole());
1763 } 1765 }
1764 1766
1765 1767
1766 RUNTIME_FUNCTION(Runtime_WeakCollectionDelete) { 1768 RUNTIME_FUNCTION(Runtime_WeakCollectionDelete) {
1767 HandleScope scope(isolate); 1769 HandleScope scope(isolate);
1768 ASSERT(args.length() == 2); 1770 ASSERT(args.length() == 2);
1769 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0); 1771 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0);
1770 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); 1772 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
1773 RUNTIME_ASSERT(key->IsJSReceiver() || key->IsSymbol());
1771 Handle<ObjectHashTable> table(ObjectHashTable::cast( 1774 Handle<ObjectHashTable> table(ObjectHashTable::cast(
1772 weak_collection->table())); 1775 weak_collection->table()));
1773 RUNTIME_ASSERT(table->IsKey(*key)); 1776 RUNTIME_ASSERT(table->IsKey(*key));
1774 Handle<Object> lookup(table->Lookup(key), isolate); 1777 Handle<Object> lookup(table->Lookup(key), isolate);
1775 Handle<ObjectHashTable> new_table = 1778 Handle<ObjectHashTable> new_table =
1776 ObjectHashTable::Put(table, key, isolate->factory()->the_hole_value()); 1779 ObjectHashTable::Put(table, key, isolate->factory()->the_hole_value());
1777 weak_collection->set_table(*new_table); 1780 weak_collection->set_table(*new_table);
1778 return isolate->heap()->ToBoolean(!lookup->IsTheHole()); 1781 return isolate->heap()->ToBoolean(!lookup->IsTheHole());
1779 } 1782 }
1780 1783
1781 1784
1782 RUNTIME_FUNCTION(Runtime_WeakCollectionSet) { 1785 RUNTIME_FUNCTION(Runtime_WeakCollectionSet) {
1783 HandleScope scope(isolate); 1786 HandleScope scope(isolate);
1784 ASSERT(args.length() == 3); 1787 ASSERT(args.length() == 3);
1785 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0); 1788 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0);
1786 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); 1789 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
1790 RUNTIME_ASSERT(key->IsJSReceiver() || key->IsSymbol());
1787 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); 1791 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2);
1788 Handle<ObjectHashTable> table( 1792 Handle<ObjectHashTable> table(
1789 ObjectHashTable::cast(weak_collection->table())); 1793 ObjectHashTable::cast(weak_collection->table()));
1790 RUNTIME_ASSERT(table->IsKey(*key)); 1794 RUNTIME_ASSERT(table->IsKey(*key));
1791 Handle<ObjectHashTable> new_table = ObjectHashTable::Put(table, key, value); 1795 Handle<ObjectHashTable> new_table = ObjectHashTable::Put(table, key, value);
1792 weak_collection->set_table(*new_table); 1796 weak_collection->set_table(*new_table);
1793 return isolate->heap()->undefined_value(); 1797 return isolate->heap()->undefined_value();
1794 } 1798 }
1795 1799
1796 1800
(...skipping 13422 matching lines...) Expand 10 before | Expand all | Expand 10 after
15219 } 15223 }
15220 return NULL; 15224 return NULL;
15221 } 15225 }
15222 15226
15223 15227
15224 const Runtime::Function* Runtime::FunctionForId(Runtime::FunctionId id) { 15228 const Runtime::Function* Runtime::FunctionForId(Runtime::FunctionId id) {
15225 return &(kIntrinsicFunctions[static_cast<int>(id)]); 15229 return &(kIntrinsicFunctions[static_cast<int>(id)]);
15226 } 15230 }
15227 15231
15228 } } // namespace v8::internal 15232 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698