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