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

Side by Side Diff: src/objects.cc

Issue 12296026: ES6 symbols: Implement Symbol intrinsic and basic functionality (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed more 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/objects-inl.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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 if (IsJSReceiver()) { 135 if (IsJSReceiver()) {
136 holder = this; 136 holder = this;
137 } else { 137 } else {
138 Context* native_context = Isolate::Current()->context()->native_context(); 138 Context* native_context = Isolate::Current()->context()->native_context();
139 if (IsNumber()) { 139 if (IsNumber()) {
140 holder = native_context->number_function()->instance_prototype(); 140 holder = native_context->number_function()->instance_prototype();
141 } else if (IsString()) { 141 } else if (IsString()) {
142 holder = native_context->string_function()->instance_prototype(); 142 holder = native_context->string_function()->instance_prototype();
143 } else if (IsBoolean()) { 143 } else if (IsBoolean()) {
144 holder = native_context->boolean_function()->instance_prototype(); 144 holder = native_context->boolean_function()->instance_prototype();
145 } else if (IsSymbol()) {
146 holder = native_context->symbol_delegate();
145 } else { 147 } else {
146 Isolate::Current()->PushStackTraceAndDie( 148 Isolate::Current()->PushStackTraceAndDie(
147 0xDEAD0000, this, JSReceiver::cast(this)->map(), 0xDEAD0001); 149 0xDEAD0000, this, JSReceiver::cast(this)->map(), 0xDEAD0001);
148 } 150 }
149 } 151 }
150 ASSERT(holder != NULL); // Cannot handle null or undefined. 152 ASSERT(holder != NULL); // Cannot handle null or undefined.
151 JSReceiver::cast(holder)->Lookup(name, result); 153 JSReceiver::cast(holder)->Lookup(name, result);
152 } 154 }
153 155
154 156
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 Heap* heap = name->GetHeap(); 612 Heap* heap = name->GetHeap();
611 613
612 // Traverse the prototype chain from the current object (this) to 614 // Traverse the prototype chain from the current object (this) to
613 // the holder and check for access rights. This avoids traversing the 615 // the holder and check for access rights. This avoids traversing the
614 // objects more than once in case of interceptors, because the 616 // objects more than once in case of interceptors, because the
615 // holder will always be the interceptor holder and the search may 617 // holder will always be the interceptor holder and the search may
616 // only continue with a current object just after the interceptor 618 // only continue with a current object just after the interceptor
617 // holder in the prototype chain. 619 // holder in the prototype chain.
618 // Proxy handlers do not use the proxy's prototype, so we can skip this. 620 // Proxy handlers do not use the proxy's prototype, so we can skip this.
619 if (!result->IsHandler()) { 621 if (!result->IsHandler()) {
620 Object* last = result->IsProperty() 622 Object* last = result->IsProperty() && !receiver->IsSymbol()
621 ? result->holder() 623 ? result->holder()
622 : Object::cast(heap->null_value()); 624 : Object::cast(heap->null_value());
623 ASSERT(this != this->GetPrototype()); 625 ASSERT(this != this->GetPrototype());
624 for (Object* current = this; true; current = current->GetPrototype()) { 626 for (Object* current = this; true; current = current->GetPrototype()) {
625 if (current->IsAccessCheckNeeded()) { 627 if (current->IsAccessCheckNeeded()) {
626 // Check if we're allowed to read from the current object. Note 628 // Check if we're allowed to read from the current object. Note
627 // that even though we may not actually end up loading the named 629 // that even though we may not actually end up loading the named
628 // property from the current object, we still check that we have 630 // property from the current object, we still check that we have
629 // access to it. 631 // access to it.
630 // TODO(dcarney): revert. 632 // TODO(dcarney): revert.
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 holder = holder->GetPrototype()) { 695 holder = holder->GetPrototype()) {
694 if (!holder->IsJSObject()) { 696 if (!holder->IsJSObject()) {
695 Isolate* isolate = heap->isolate(); 697 Isolate* isolate = heap->isolate();
696 Context* native_context = isolate->context()->native_context(); 698 Context* native_context = isolate->context()->native_context();
697 if (holder->IsNumber()) { 699 if (holder->IsNumber()) {
698 holder = native_context->number_function()->instance_prototype(); 700 holder = native_context->number_function()->instance_prototype();
699 } else if (holder->IsString()) { 701 } else if (holder->IsString()) {
700 holder = native_context->string_function()->instance_prototype(); 702 holder = native_context->string_function()->instance_prototype();
701 } else if (holder->IsBoolean()) { 703 } else if (holder->IsBoolean()) {
702 holder = native_context->boolean_function()->instance_prototype(); 704 holder = native_context->boolean_function()->instance_prototype();
705 } else if (holder->IsSymbol()) {
706 holder = native_context->symbol_delegate();
703 } else if (holder->IsJSProxy()) { 707 } else if (holder->IsJSProxy()) {
704 return JSProxy::cast(holder)->GetElementWithHandler(receiver, index); 708 return JSProxy::cast(holder)->GetElementWithHandler(receiver, index);
705 } else { 709 } else {
706 // Undefined and null have no indexed properties. 710 // Undefined and null have no indexed properties.
707 ASSERT(holder->IsUndefined() || holder->IsNull()); 711 ASSERT(holder->IsUndefined() || holder->IsNull());
708 return heap->undefined_value(); 712 return heap->undefined_value();
709 } 713 }
710 } 714 }
711 715
712 // Inline the case for JSObjects. Doing so significantly improves the 716 // Inline the case for JSObjects. Doing so significantly improves the
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 return context->string_function()->instance_prototype(); 766 return context->string_function()->instance_prototype();
763 } 767 }
764 if (heap_object->IsBoolean()) { 768 if (heap_object->IsBoolean()) {
765 return context->boolean_function()->instance_prototype(); 769 return context->boolean_function()->instance_prototype();
766 } else { 770 } else {
767 return heap->null_value(); 771 return heap->null_value();
768 } 772 }
769 } 773 }
770 774
771 775
776 Object* Object::GetDelegate() {
777 if (IsSymbol()) {
778 Heap* heap = Symbol::cast(this)->GetHeap();
779 Context* context = heap->isolate()->context()->native_context();
780 return context->symbol_delegate();
781 }
782 return GetPrototype();
783 }
784
785
772 MaybeObject* Object::GetHash(CreationFlag flag) { 786 MaybeObject* Object::GetHash(CreationFlag flag) {
773 // The object is either a number, a string, an odd-ball, 787 // The object is either a number, a string, an odd-ball,
774 // a real JS object, or a Harmony proxy. 788 // a real JS object, or a Harmony proxy.
775 if (IsNumber()) { 789 if (IsNumber()) {
776 uint32_t hash = ComputeLongHash(double_to_uint64(Number())); 790 uint32_t hash = ComputeLongHash(double_to_uint64(Number()));
777 return Smi::FromInt(hash & Smi::kMaxValue); 791 return Smi::FromInt(hash & Smi::kMaxValue);
778 } 792 }
779 if (IsString()) { 793 if (IsName()) {
780 uint32_t hash = String::cast(this)->Hash(); 794 uint32_t hash = Name::cast(this)->Hash();
781 return Smi::FromInt(hash); 795 return Smi::FromInt(hash);
782 } 796 }
783 if (IsOddball()) { 797 if (IsOddball()) {
784 uint32_t hash = Oddball::cast(this)->to_string()->Hash(); 798 uint32_t hash = Oddball::cast(this)->to_string()->Hash();
785 return Smi::FromInt(hash); 799 return Smi::FromInt(hash);
786 } 800 }
787 if (IsJSReceiver()) { 801 if (IsJSReceiver()) {
788 return JSReceiver::cast(this)->GetIdentityHash(flag); 802 return JSReceiver::cast(this)->GetIdentityHash(flag);
789 } 803 }
790 804
(...skipping 13110 matching lines...) Expand 10 before | Expand all | Expand 10 after
13901 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER); 13915 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER);
13902 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER); 13916 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER);
13903 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER); 13917 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER);
13904 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER); 13918 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER);
13905 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER); 13919 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER);
13906 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER); 13920 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER);
13907 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER); 13921 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER);
13908 } 13922 }
13909 13923
13910 } } // namespace v8::internal 13924 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698