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

Side by Side Diff: src/accessors.cc

Issue 1139323002: Version 4.5.1.1 (cherry-pick) (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@4.5.1
Patch Set: Created 5 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
« no previous file with comments | « include/v8-version.h ('k') | src/lookup.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 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 "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/accessors.h" 7 #include "src/accessors.h"
8 #include "src/api.h" 8 #include "src/api.h"
9 #include "src/contexts.h" 9 #include "src/contexts.h"
10 #include "src/deoptimizer.h" 10 #include "src/deoptimizer.h"
(...skipping 14 matching lines...) Expand all
25 Isolate* isolate, 25 Isolate* isolate,
26 Handle<Name> name, 26 Handle<Name> name,
27 AccessorNameGetterCallback getter, 27 AccessorNameGetterCallback getter,
28 AccessorNameSetterCallback setter, 28 AccessorNameSetterCallback setter,
29 PropertyAttributes attributes) { 29 PropertyAttributes attributes) {
30 Factory* factory = isolate->factory(); 30 Factory* factory = isolate->factory();
31 Handle<ExecutableAccessorInfo> info = factory->NewExecutableAccessorInfo(); 31 Handle<ExecutableAccessorInfo> info = factory->NewExecutableAccessorInfo();
32 info->set_property_attributes(attributes); 32 info->set_property_attributes(attributes);
33 info->set_all_can_read(false); 33 info->set_all_can_read(false);
34 info->set_all_can_write(false); 34 info->set_all_can_write(false);
35 info->set_is_special_data_property(true);
36 info->set_name(*name); 35 info->set_name(*name);
37 Handle<Object> get = v8::FromCData(isolate, getter); 36 Handle<Object> get = v8::FromCData(isolate, getter);
38 Handle<Object> set = v8::FromCData(isolate, setter); 37 Handle<Object> set = v8::FromCData(isolate, setter);
39 info->set_getter(*get); 38 info->set_getter(*get);
40 info->set_setter(*set); 39 info->set_setter(*set);
41 return info; 40 return info;
42 } 41 }
43 42
44 43
45 Handle<ExecutableAccessorInfo> Accessors::CloneAccessor( 44 Handle<ExecutableAccessorInfo> Accessors::CloneAccessor(
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 return CheckForName(name, isolate->factory()->byte_length_string(), 119 return CheckForName(name, isolate->factory()->byte_length_string(),
121 JSDataView::kByteLengthOffset, object_offset) || 120 JSDataView::kByteLengthOffset, object_offset) ||
122 CheckForName(name, isolate->factory()->byte_offset_string(), 121 CheckForName(name, isolate->factory()->byte_offset_string(),
123 JSDataView::kByteOffsetOffset, object_offset); 122 JSDataView::kByteOffsetOffset, object_offset);
124 default: 123 default:
125 return false; 124 return false;
126 } 125 }
127 } 126 }
128 127
129 128
129 bool SetPropertyOnInstanceIfInherited(
130 Isolate* isolate, const v8::PropertyCallbackInfo<void>& info,
131 v8::Local<v8::Name> name, Handle<Object> value) {
132 Handle<Object> holder = Utils::OpenHandle(*info.Holder());
133 Handle<Object> receiver = Utils::OpenHandle(*info.This());
134 if (*holder == *receiver) return false;
135 if (receiver->IsJSObject()) {
136 Handle<JSObject> object = Handle<JSObject>::cast(receiver);
137 // This behaves sloppy since we lost the actual strict-mode.
138 // TODO(verwaest): Fix by making ExecutableAccessorInfo behave like data
139 // properties.
140 if (object->IsJSGlobalProxy()) {
141 PrototypeIterator iter(isolate, object);
142 if (iter.IsAtEnd()) return true;
143 DCHECK(PrototypeIterator::GetCurrent(iter)->IsJSGlobalObject());
144 object = Handle<JSObject>::cast(PrototypeIterator::GetCurrent(iter));
145 }
146 if (!object->map()->is_extensible()) return true;
147 JSObject::SetOwnPropertyIgnoreAttributes(object, Utils::OpenHandle(*name),
148 value, NONE).Check();
149 }
150 return true;
151 }
152
153
130 // 154 //
131 // Accessors::ArgumentsIterator 155 // Accessors::ArgumentsIterator
132 // 156 //
133 157
134 158
135 void Accessors::ArgumentsIteratorGetter( 159 void Accessors::ArgumentsIteratorGetter(
136 v8::Local<v8::Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) { 160 v8::Local<v8::Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) {
137 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate()); 161 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
138 DisallowHeapAllocation no_allocation; 162 DisallowHeapAllocation no_allocation;
139 HandleScope scope(isolate); 163 HandleScope scope(isolate);
140 Object* result = isolate->native_context()->array_values_iterator(); 164 Object* result = isolate->native_context()->array_values_iterator();
141 info.GetReturnValue().Set(Utils::ToLocal(Handle<Object>(result, isolate))); 165 info.GetReturnValue().Set(Utils::ToLocal(Handle<Object>(result, isolate)));
142 } 166 }
143 167
144 168
145 void Accessors::ArgumentsIteratorSetter( 169 void Accessors::ArgumentsIteratorSetter(
146 v8::Local<v8::Name> name, v8::Local<v8::Value> val, 170 v8::Local<v8::Name> name, v8::Local<v8::Value> val,
147 const v8::PropertyCallbackInfo<void>& info) { 171 const v8::PropertyCallbackInfo<void>& info) {
148 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate()); 172 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
149 HandleScope scope(isolate); 173 HandleScope scope(isolate);
150 Handle<JSObject> object = Utils::OpenHandle(*info.This()); 174 Handle<JSObject> object = Utils::OpenHandle(*info.This());
151 Handle<Object> value = Utils::OpenHandle(*val); 175 Handle<Object> value = Utils::OpenHandle(*val);
152 176
177 if (SetPropertyOnInstanceIfInherited(isolate, info, name, value)) return;
178
153 LookupIterator it(object, Utils::OpenHandle(*name)); 179 LookupIterator it(object, Utils::OpenHandle(*name));
154 CHECK_EQ(LookupIterator::ACCESSOR, it.state()); 180 CHECK_EQ(LookupIterator::ACCESSOR, it.state());
155 DCHECK(it.HolderIsReceiverOrHiddenPrototype()); 181 DCHECK(it.HolderIsReceiverOrHiddenPrototype());
156 182
157 if (Object::SetDataProperty(&it, value).is_null()) { 183 if (Object::SetDataProperty(&it, value).is_null()) {
158 isolate->OptionalRescheduleException(false); 184 isolate->OptionalRescheduleException(false);
159 } 185 }
160 } 186 }
161 187
162 188
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 227
202 228
203 void Accessors::ArrayLengthSetter( 229 void Accessors::ArrayLengthSetter(
204 v8::Local<v8::Name> name, 230 v8::Local<v8::Name> name,
205 v8::Local<v8::Value> val, 231 v8::Local<v8::Value> val,
206 const v8::PropertyCallbackInfo<void>& info) { 232 const v8::PropertyCallbackInfo<void>& info) {
207 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate()); 233 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
208 HandleScope scope(isolate); 234 HandleScope scope(isolate);
209 Handle<JSObject> object = Utils::OpenHandle(*info.This()); 235 Handle<JSObject> object = Utils::OpenHandle(*info.This());
210 Handle<Object> value = Utils::OpenHandle(*val); 236 Handle<Object> value = Utils::OpenHandle(*val);
237 if (SetPropertyOnInstanceIfInherited(isolate, info, name, value)) {
238 return;
239 }
211 240
212 value = FlattenNumber(isolate, value); 241 value = FlattenNumber(isolate, value);
213 242
214 Handle<JSArray> array_handle = Handle<JSArray>::cast(object); 243 Handle<JSArray> array_handle = Handle<JSArray>::cast(object);
215 MaybeHandle<Object> maybe; 244 MaybeHandle<Object> maybe;
216 Handle<Object> uint32_v; 245 Handle<Object> uint32_v;
217 maybe = Execution::ToUint32(isolate, value); 246 maybe = Execution::ToUint32(isolate, value);
218 if (!maybe.ToHandle(&uint32_v)) { 247 if (!maybe.ToHandle(&uint32_v)) {
219 isolate->OptionalRescheduleException(false); 248 isolate->OptionalRescheduleException(false);
220 return; 249 return;
(...skipping 713 matching lines...) Expand 10 before | Expand all | Expand 10 after
934 } 963 }
935 964
936 965
937 void Accessors::FunctionPrototypeSetter( 966 void Accessors::FunctionPrototypeSetter(
938 v8::Local<v8::Name> name, 967 v8::Local<v8::Name> name,
939 v8::Local<v8::Value> val, 968 v8::Local<v8::Value> val,
940 const v8::PropertyCallbackInfo<void>& info) { 969 const v8::PropertyCallbackInfo<void>& info) {
941 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate()); 970 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
942 HandleScope scope(isolate); 971 HandleScope scope(isolate);
943 Handle<Object> value = Utils::OpenHandle(*val); 972 Handle<Object> value = Utils::OpenHandle(*val);
973 if (SetPropertyOnInstanceIfInherited(isolate, info, name, value)) {
974 return;
975 }
944 Handle<JSFunction> object = 976 Handle<JSFunction> object =
945 Handle<JSFunction>::cast(Utils::OpenHandle(*info.Holder())); 977 Handle<JSFunction>::cast(Utils::OpenHandle(*info.Holder()));
946 if (SetFunctionPrototype(isolate, object, value).is_null()) { 978 if (SetFunctionPrototype(isolate, object, value).is_null()) {
947 isolate->OptionalRescheduleException(false); 979 isolate->OptionalRescheduleException(false);
948 } 980 }
949 } 981 }
950 982
951 983
952 Handle<AccessorInfo> Accessors::FunctionPrototypeInfo( 984 Handle<AccessorInfo> Accessors::FunctionPrototypeInfo(
953 Isolate* isolate, PropertyAttributes attributes) { 985 Isolate* isolate, PropertyAttributes attributes) {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1022 1054
1023 1055
1024 void Accessors::FunctionLengthSetter( 1056 void Accessors::FunctionLengthSetter(
1025 v8::Local<v8::Name> name, 1057 v8::Local<v8::Name> name,
1026 v8::Local<v8::Value> val, 1058 v8::Local<v8::Value> val,
1027 const v8::PropertyCallbackInfo<void>& info) { 1059 const v8::PropertyCallbackInfo<void>& info) {
1028 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate()); 1060 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
1029 HandleScope scope(isolate); 1061 HandleScope scope(isolate);
1030 Handle<Object> value = Utils::OpenHandle(*val); 1062 Handle<Object> value = Utils::OpenHandle(*val);
1031 1063
1064 if (SetPropertyOnInstanceIfInherited(isolate, info, name, value)) return;
1065
1032 Handle<JSFunction> object = 1066 Handle<JSFunction> object =
1033 Handle<JSFunction>::cast(Utils::OpenHandle(*info.Holder())); 1067 Handle<JSFunction>::cast(Utils::OpenHandle(*info.Holder()));
1034 if (SetFunctionLength(isolate, object, value).is_null()) { 1068 if (SetFunctionLength(isolate, object, value).is_null()) {
1035 isolate->OptionalRescheduleException(false); 1069 isolate->OptionalRescheduleException(false);
1036 } 1070 }
1037 } 1071 }
1038 1072
1039 1073
1040 Handle<AccessorInfo> Accessors::FunctionLengthInfo( 1074 Handle<AccessorInfo> Accessors::FunctionLengthInfo(
1041 Isolate* isolate, PropertyAttributes attributes) { 1075 Isolate* isolate, PropertyAttributes attributes) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1079 1113
1080 1114
1081 void Accessors::FunctionNameSetter( 1115 void Accessors::FunctionNameSetter(
1082 v8::Local<v8::Name> name, 1116 v8::Local<v8::Name> name,
1083 v8::Local<v8::Value> val, 1117 v8::Local<v8::Value> val,
1084 const v8::PropertyCallbackInfo<void>& info) { 1118 const v8::PropertyCallbackInfo<void>& info) {
1085 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate()); 1119 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
1086 HandleScope scope(isolate); 1120 HandleScope scope(isolate);
1087 Handle<Object> value = Utils::OpenHandle(*val); 1121 Handle<Object> value = Utils::OpenHandle(*val);
1088 1122
1123 if (SetPropertyOnInstanceIfInherited(isolate, info, name, value)) return;
1124
1089 Handle<JSFunction> object = 1125 Handle<JSFunction> object =
1090 Handle<JSFunction>::cast(Utils::OpenHandle(*info.Holder())); 1126 Handle<JSFunction>::cast(Utils::OpenHandle(*info.Holder()));
1091 if (SetFunctionName(isolate, object, value).is_null()) { 1127 if (SetFunctionName(isolate, object, value).is_null()) {
1092 isolate->OptionalRescheduleException(false); 1128 isolate->OptionalRescheduleException(false);
1093 } 1129 }
1094 } 1130 }
1095 1131
1096 1132
1097 Handle<AccessorInfo> Accessors::FunctionNameInfo( 1133 Handle<AccessorInfo> Accessors::FunctionNameInfo(
1098 Isolate* isolate, PropertyAttributes attributes) { 1134 Isolate* isolate, PropertyAttributes attributes) {
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
1451 info->set_data(Smi::FromInt(index)); 1487 info->set_data(Smi::FromInt(index));
1452 Handle<Object> getter = v8::FromCData(isolate, &ModuleGetExport); 1488 Handle<Object> getter = v8::FromCData(isolate, &ModuleGetExport);
1453 Handle<Object> setter = v8::FromCData(isolate, &ModuleSetExport); 1489 Handle<Object> setter = v8::FromCData(isolate, &ModuleSetExport);
1454 info->set_getter(*getter); 1490 info->set_getter(*getter);
1455 if (!(attributes & ReadOnly)) info->set_setter(*setter); 1491 if (!(attributes & ReadOnly)) info->set_setter(*setter);
1456 return info; 1492 return info;
1457 } 1493 }
1458 1494
1459 1495
1460 } } // namespace v8::internal 1496 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « include/v8-version.h ('k') | src/lookup.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698