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

Side by Side Diff: src/objects.cc

Issue 12957004: ES6 symbols: turn symbols into a proper primitive type (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed comments Created 7 years, 9 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 | « src/objects.h ('k') | src/runtime.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 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 void Object::Lookup(Name* name, LookupResult* result) { 119 void Object::Lookup(Name* name, LookupResult* result) {
120 Object* holder = NULL; 120 Object* holder = NULL;
121 if (IsJSReceiver()) { 121 if (IsJSReceiver()) {
122 holder = this; 122 holder = this;
123 } else { 123 } else {
124 Context* native_context = result->isolate()->context()->native_context(); 124 Context* native_context = result->isolate()->context()->native_context();
125 if (IsNumber()) { 125 if (IsNumber()) {
126 holder = native_context->number_function()->instance_prototype(); 126 holder = native_context->number_function()->instance_prototype();
127 } else if (IsString()) { 127 } else if (IsString()) {
128 holder = native_context->string_function()->instance_prototype(); 128 holder = native_context->string_function()->instance_prototype();
129 } else if (IsSymbol()) {
130 holder = native_context->symbol_function()->instance_prototype();
129 } else if (IsBoolean()) { 131 } else if (IsBoolean()) {
130 holder = native_context->boolean_function()->instance_prototype(); 132 holder = native_context->boolean_function()->instance_prototype();
131 } else if (IsSymbol()) {
132 holder = native_context->symbol_delegate();
133 } else { 133 } else {
134 Isolate::Current()->PushStackTraceAndDie( 134 Isolate::Current()->PushStackTraceAndDie(
135 0xDEAD0000, this, JSReceiver::cast(this)->map(), 0xDEAD0001); 135 0xDEAD0000, this, JSReceiver::cast(this)->map(), 0xDEAD0001);
136 } 136 }
137 } 137 }
138 ASSERT(holder != NULL); // Cannot handle null or undefined. 138 ASSERT(holder != NULL); // Cannot handle null or undefined.
139 JSReceiver::cast(holder)->Lookup(name, result); 139 JSReceiver::cast(holder)->Lookup(name, result);
140 } 140 }
141 141
142 142
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after
749 Heap* heap = isolate->heap(); 749 Heap* heap = isolate->heap();
750 750
751 // Traverse the prototype chain from the current object (this) to 751 // Traverse the prototype chain from the current object (this) to
752 // the holder and check for access rights. This avoids traversing the 752 // the holder and check for access rights. This avoids traversing the
753 // objects more than once in case of interceptors, because the 753 // objects more than once in case of interceptors, because the
754 // holder will always be the interceptor holder and the search may 754 // holder will always be the interceptor holder and the search may
755 // only continue with a current object just after the interceptor 755 // only continue with a current object just after the interceptor
756 // holder in the prototype chain. 756 // holder in the prototype chain.
757 // Proxy handlers do not use the proxy's prototype, so we can skip this. 757 // Proxy handlers do not use the proxy's prototype, so we can skip this.
758 if (!result->IsHandler()) { 758 if (!result->IsHandler()) {
759 Object* last = result->IsProperty() && !receiver->IsSymbol() 759 Object* last = result->IsProperty()
760 ? result->holder() 760 ? result->holder()
761 : Object::cast(heap->null_value()); 761 : Object::cast(heap->null_value());
762 ASSERT(this != this->GetPrototype(isolate)); 762 ASSERT(this != this->GetPrototype(isolate));
763 for (Object* current = this; 763 for (Object* current = this;
764 true; 764 true;
765 current = current->GetPrototype(isolate)) { 765 current = current->GetPrototype(isolate)) {
766 if (current->IsAccessCheckNeeded()) { 766 if (current->IsAccessCheckNeeded()) {
767 // Check if we're allowed to read from the current object. Note 767 // Check if we're allowed to read from the current object. Note
768 // that even though we may not actually end up loading the named 768 // that even though we may not actually end up loading the named
769 // property from the current object, we still check that we have 769 // property from the current object, we still check that we have
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
830 // prototype is encountered. 830 // prototype is encountered.
831 for (holder = this; 831 for (holder = this;
832 holder != heap->null_value(); 832 holder != heap->null_value();
833 holder = holder->GetPrototype(isolate)) { 833 holder = holder->GetPrototype(isolate)) {
834 if (!holder->IsJSObject()) { 834 if (!holder->IsJSObject()) {
835 Context* native_context = isolate->context()->native_context(); 835 Context* native_context = isolate->context()->native_context();
836 if (holder->IsNumber()) { 836 if (holder->IsNumber()) {
837 holder = native_context->number_function()->instance_prototype(); 837 holder = native_context->number_function()->instance_prototype();
838 } else if (holder->IsString()) { 838 } else if (holder->IsString()) {
839 holder = native_context->string_function()->instance_prototype(); 839 holder = native_context->string_function()->instance_prototype();
840 } else if (holder->IsSymbol()) {
841 holder = native_context->symbol_function()->instance_prototype();
840 } else if (holder->IsBoolean()) { 842 } else if (holder->IsBoolean()) {
841 holder = native_context->boolean_function()->instance_prototype(); 843 holder = native_context->boolean_function()->instance_prototype();
842 } else if (holder->IsSymbol()) {
843 holder = native_context->symbol_delegate();
844 } else if (holder->IsJSProxy()) { 844 } else if (holder->IsJSProxy()) {
845 return JSProxy::cast(holder)->GetElementWithHandler(receiver, index); 845 return JSProxy::cast(holder)->GetElementWithHandler(receiver, index);
846 } else { 846 } else {
847 // Undefined and null have no indexed properties. 847 // Undefined and null have no indexed properties.
848 ASSERT(holder->IsUndefined() || holder->IsNull()); 848 ASSERT(holder->IsUndefined() || holder->IsNull());
849 return heap->undefined_value(); 849 return heap->undefined_value();
850 } 850 }
851 } 851 }
852 852
853 // Inline the case for JSObjects. Doing so significantly improves the 853 // Inline the case for JSObjects. Doing so significantly improves the
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
893 return heap_object->map()->prototype(); 893 return heap_object->map()->prototype();
894 } 894 }
895 Context* context = isolate->context()->native_context(); 895 Context* context = isolate->context()->native_context();
896 896
897 if (heap_object->IsHeapNumber()) { 897 if (heap_object->IsHeapNumber()) {
898 return context->number_function()->instance_prototype(); 898 return context->number_function()->instance_prototype();
899 } 899 }
900 if (heap_object->IsString()) { 900 if (heap_object->IsString()) {
901 return context->string_function()->instance_prototype(); 901 return context->string_function()->instance_prototype();
902 } 902 }
903 if (heap_object->IsSymbol()) {
904 return context->symbol_function()->instance_prototype();
905 }
903 if (heap_object->IsBoolean()) { 906 if (heap_object->IsBoolean()) {
904 return context->boolean_function()->instance_prototype(); 907 return context->boolean_function()->instance_prototype();
905 } else { 908 } else {
906 return isolate->heap()->null_value(); 909 return isolate->heap()->null_value();
907 } 910 }
908 } 911 }
909 912
910 913
911 Object* Object::GetDelegate(Isolate* isolate) {
912 if (IsSymbol()) {
913 Heap* heap = Symbol::cast(this)->GetHeap();
914 Context* context = heap->isolate()->context()->native_context();
915 return context->symbol_delegate();
916 }
917 return GetPrototype(isolate);
918 }
919
920
921 MaybeObject* Object::GetHash(CreationFlag flag) { 914 MaybeObject* Object::GetHash(CreationFlag flag) {
922 // The object is either a number, a name, an odd-ball, 915 // The object is either a number, a name, an odd-ball,
923 // a real JS object, or a Harmony proxy. 916 // a real JS object, or a Harmony proxy.
924 if (IsNumber()) { 917 if (IsNumber()) {
925 uint32_t hash = ComputeLongHash(double_to_uint64(Number())); 918 uint32_t hash = ComputeLongHash(double_to_uint64(Number()));
926 return Smi::FromInt(hash & Smi::kMaxValue); 919 return Smi::FromInt(hash & Smi::kMaxValue);
927 } 920 }
928 if (IsName()) { 921 if (IsName()) {
929 uint32_t hash = Name::cast(this)->Hash(); 922 uint32_t hash = Name::cast(this)->Hash();
930 return Smi::FromInt(hash); 923 return Smi::FromInt(hash);
(...skipping 13402 matching lines...) Expand 10 before | Expand all | Expand 10 after
14333 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER); 14326 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER);
14334 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER); 14327 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER);
14335 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER); 14328 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER);
14336 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER); 14329 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER);
14337 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER); 14330 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER);
14338 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER); 14331 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER);
14339 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER); 14332 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER);
14340 } 14333 }
14341 14334
14342 } } // namespace v8::internal 14335 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects.h ('k') | src/runtime.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698