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/compiler.h" | 9 #include "src/compiler.h" |
10 #include "src/contexts.h" | 10 #include "src/contexts.h" |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
149 // properties. | 149 // properties. |
150 if (!object->map()->is_extensible()) return true; | 150 if (!object->map()->is_extensible()) return true; |
151 JSObject::SetOwnPropertyIgnoreAttributes(object, Utils::OpenHandle(*name), | 151 JSObject::SetOwnPropertyIgnoreAttributes(object, Utils::OpenHandle(*name), |
152 value, NONE).Check(); | 152 value, NONE).Check(); |
153 } | 153 } |
154 return true; | 154 return true; |
155 } | 155 } |
156 | 156 |
157 | 157 |
158 // | 158 // |
159 // Accessors::ArgumentsIterator | |
160 // | |
161 | |
162 | |
163 void Accessors::ArgumentsIteratorGetter( | |
164 v8::Local<v8::Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) { | |
165 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate()); | |
166 DisallowHeapAllocation no_allocation; | |
167 HandleScope scope(isolate); | |
168 Object* result = isolate->native_context()->array_values_iterator(); | |
169 info.GetReturnValue().Set(Utils::ToLocal(Handle<Object>(result, isolate))); | |
170 } | |
171 | |
172 | |
173 void Accessors::ArgumentsIteratorSetter( | |
174 v8::Local<v8::Name> name, v8::Local<v8::Value> val, | |
175 const v8::PropertyCallbackInfo<void>& info) { | |
176 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate()); | |
177 HandleScope scope(isolate); | |
178 Handle<JSObject> object = Utils::OpenHandle(*info.This()); | |
179 Handle<Object> value = Utils::OpenHandle(*val); | |
180 LookupIterator it(object, Utils::OpenHandle(*name)); | |
Toon Verwaest
2014/08/22 11:01:02
What about just
if (SetPropertyOnInstanceIfInheri
wingo
2014/08/25 08:42:30
Done, works fine; thanks for the tip. The differe
| |
181 if (it.HasProperty() && it.HolderIsReceiverOrHiddenPrototype()) { | |
182 // The receiver is an arguments object. Replace this weird accessor with a | |
183 // normal data property. | |
184 Object::SetDataProperty(&it, value).Check(); | |
185 } else { | |
186 // The receiver has an arguments object on the proto chain. Add a new data | |
187 // property to the receiver, if it's extensible. | |
188 if (Object::AddDataProperty(&it, value, DONT_ENUM, STRICT, | |
189 Object::CERTAINLY_NOT_STORE_FROM_KEYED) | |
190 .is_null()) { | |
191 isolate->OptionalRescheduleException(false); | |
192 } | |
193 } | |
194 } | |
195 | |
196 | |
197 Handle<AccessorInfo> Accessors::ArgumentsIteratorInfo( | |
198 Isolate* isolate, PropertyAttributes attributes) { | |
199 Handle<Name> name(isolate->native_context()->iterator_symbol(), isolate); | |
200 return MakeAccessor(isolate, name, &ArgumentsIteratorGetter, | |
201 &ArgumentsIteratorSetter, attributes); | |
202 } | |
203 | |
204 | |
205 // | |
159 // Accessors::ArrayLength | 206 // Accessors::ArrayLength |
160 // | 207 // |
161 | 208 |
162 | 209 |
163 // The helper function will 'flatten' Number objects. | 210 // The helper function will 'flatten' Number objects. |
164 Handle<Object> Accessors::FlattenNumber(Isolate* isolate, | 211 Handle<Object> Accessors::FlattenNumber(Isolate* isolate, |
165 Handle<Object> value) { | 212 Handle<Object> value) { |
166 if (value->IsNumber() || !value->IsJSValue()) return value; | 213 if (value->IsNumber() || !value->IsJSValue()) return value; |
167 Handle<JSValue> wrapper = Handle<JSValue>::cast(value); | 214 Handle<JSValue> wrapper = Handle<JSValue>::cast(value); |
168 DCHECK(wrapper->GetIsolate()->native_context()->number_function()-> | 215 DCHECK(wrapper->GetIsolate()->native_context()->number_function()-> |
(...skipping 1185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1354 info->set_data(Smi::FromInt(index)); | 1401 info->set_data(Smi::FromInt(index)); |
1355 Handle<Object> getter = v8::FromCData(isolate, &ModuleGetExport); | 1402 Handle<Object> getter = v8::FromCData(isolate, &ModuleGetExport); |
1356 Handle<Object> setter = v8::FromCData(isolate, &ModuleSetExport); | 1403 Handle<Object> setter = v8::FromCData(isolate, &ModuleSetExport); |
1357 info->set_getter(*getter); | 1404 info->set_getter(*getter); |
1358 if (!(attributes & ReadOnly)) info->set_setter(*setter); | 1405 if (!(attributes & ReadOnly)) info->set_setter(*setter); |
1359 return info; | 1406 return info; |
1360 } | 1407 } |
1361 | 1408 |
1362 | 1409 |
1363 } } // namespace v8::internal | 1410 } } // namespace v8::internal |
OLD | NEW |