OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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/runtime/runtime-utils.h" | 5 #include "src/runtime/runtime-utils.h" |
6 | 6 |
7 #include "src/arguments.h" | 7 #include "src/arguments.h" |
8 #include "src/bootstrapper.h" | 8 #include "src/bootstrapper.h" |
9 #include "src/debug/debug.h" | 9 #include "src/debug/debug.h" |
10 #include "src/isolate-inl.h" | 10 #include "src/isolate-inl.h" |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 HandleScope scope(isolate); | 263 HandleScope scope(isolate); |
264 DCHECK(args.length() == 2); | 264 DCHECK(args.length() == 2); |
265 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, obj, 0); | 265 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, obj, 0); |
266 CONVERT_ARG_HANDLE_CHECKED(Object, prototype, 1); | 266 CONVERT_ARG_HANDLE_CHECKED(Object, prototype, 1); |
267 MAYBE_RETURN( | 267 MAYBE_RETURN( |
268 JSReceiver::SetPrototype(obj, prototype, true, Object::THROW_ON_ERROR), | 268 JSReceiver::SetPrototype(obj, prototype, true, Object::THROW_ON_ERROR), |
269 isolate->heap()->exception()); | 269 isolate->heap()->exception()); |
270 return *obj; | 270 return *obj; |
271 } | 271 } |
272 | 272 |
273 | |
274 // Enumerator used as indices into the array returned from GetOwnProperty | |
275 enum PropertyDescriptorIndices { | |
276 IS_ACCESSOR_INDEX, | |
277 VALUE_INDEX, | |
278 GETTER_INDEX, | |
279 SETTER_INDEX, | |
280 WRITABLE_INDEX, | |
281 ENUMERABLE_INDEX, | |
282 CONFIGURABLE_INDEX, | |
283 DESCRIPTOR_SIZE | |
284 }; | |
285 | |
286 | |
287 MUST_USE_RESULT static MaybeHandle<Object> GetOwnProperty(Isolate* isolate, | |
288 Handle<JSObject> obj, | |
289 Handle<Name> name) { | |
290 Heap* heap = isolate->heap(); | |
291 Factory* factory = isolate->factory(); | |
292 | |
293 // Get attributes. | |
294 LookupIterator it = LookupIterator::PropertyOrElement(isolate, obj, name, obj, | |
295 LookupIterator::HIDDEN); | |
296 Maybe<PropertyAttributes> maybe = JSObject::GetPropertyAttributes(&it); | |
297 | |
298 if (!maybe.IsJust()) return MaybeHandle<Object>(); | |
299 PropertyAttributes attrs = maybe.FromJust(); | |
300 if (attrs == ABSENT) return factory->undefined_value(); | |
301 | |
302 DCHECK(!isolate->has_pending_exception()); | |
303 Handle<FixedArray> elms = factory->NewFixedArray(DESCRIPTOR_SIZE); | |
304 elms->set(ENUMERABLE_INDEX, heap->ToBoolean((attrs & DONT_ENUM) == 0)); | |
305 elms->set(CONFIGURABLE_INDEX, heap->ToBoolean((attrs & DONT_DELETE) == 0)); | |
306 | |
307 bool is_accessor_pair = it.state() == LookupIterator::ACCESSOR && | |
308 it.GetAccessors()->IsAccessorPair(); | |
309 elms->set(IS_ACCESSOR_INDEX, heap->ToBoolean(is_accessor_pair)); | |
310 | |
311 if (is_accessor_pair) { | |
312 Handle<AccessorPair> accessors = | |
313 Handle<AccessorPair>::cast(it.GetAccessors()); | |
314 Handle<Object> getter = | |
315 AccessorPair::GetComponent(accessors, ACCESSOR_GETTER); | |
316 Handle<Object> setter = | |
317 AccessorPair::GetComponent(accessors, ACCESSOR_SETTER); | |
318 elms->set(GETTER_INDEX, *getter); | |
319 elms->set(SETTER_INDEX, *setter); | |
320 } else { | |
321 Handle<Object> value; | |
322 ASSIGN_RETURN_ON_EXCEPTION(isolate, value, Object::GetProperty(&it), | |
323 Object); | |
324 elms->set(WRITABLE_INDEX, heap->ToBoolean((attrs & READ_ONLY) == 0)); | |
325 elms->set(VALUE_INDEX, *value); | |
326 } | |
327 | |
328 return factory->NewJSArrayWithElements(elms); | |
329 } | |
330 | |
331 | |
332 // Returns an array with the property description: | |
333 // if args[1] is not a property on args[0] | |
334 // returns undefined | |
335 // if args[1] is a data property on args[0] | |
336 // [false, value, Writeable, Enumerable, Configurable] | |
337 // if args[1] is an accessor on args[0] | |
338 // [true, GetFunction, SetFunction, Enumerable, Configurable] | |
339 // TODO(jkummerow): Deprecated. Remove all callers and delete. | |
340 RUNTIME_FUNCTION(Runtime_GetOwnProperty_Legacy) { | |
341 HandleScope scope(isolate); | |
342 DCHECK(args.length() == 2); | |
343 CONVERT_ARG_HANDLE_CHECKED(JSObject, obj, 0); | |
344 CONVERT_ARG_HANDLE_CHECKED(Name, name, 1); | |
345 Handle<Object> result; | |
346 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result, | |
347 GetOwnProperty(isolate, obj, name)); | |
348 return *result; | |
349 } | |
350 | |
351 | |
352 RUNTIME_FUNCTION(Runtime_OptimizeObjectForAddingMultipleProperties) { | 273 RUNTIME_FUNCTION(Runtime_OptimizeObjectForAddingMultipleProperties) { |
353 HandleScope scope(isolate); | 274 HandleScope scope(isolate); |
354 DCHECK(args.length() == 2); | 275 DCHECK(args.length() == 2); |
355 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); | 276 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); |
356 CONVERT_SMI_ARG_CHECKED(properties, 1); | 277 CONVERT_SMI_ARG_CHECKED(properties, 1); |
357 // Conservative upper limit to prevent fuzz tests from going OOM. | 278 // Conservative upper limit to prevent fuzz tests from going OOM. |
358 RUNTIME_ASSERT(properties <= 100000); | 279 RUNTIME_ASSERT(properties <= 100000); |
359 if (object->HasFastProperties() && !object->IsJSGlobalProxy()) { | 280 if (object->HasFastProperties() && !object->IsJSGlobalProxy()) { |
360 JSObject::NormalizeProperties(object, KEEP_INOBJECT_PROPERTIES, properties, | 281 JSObject::NormalizeProperties(object, KEEP_INOBJECT_PROPERTIES, properties, |
361 "OptimizeForAdding"); | 282 "OptimizeForAdding"); |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
729 HandleScope scope(isolate); | 650 HandleScope scope(isolate); |
730 DCHECK(args.length() == 1); | 651 DCHECK(args.length() == 1); |
731 | 652 |
732 CONVERT_ARG_HANDLE_CHECKED(Map, initial_map, 0); | 653 CONVERT_ARG_HANDLE_CHECKED(Map, initial_map, 0); |
733 initial_map->CompleteInobjectSlackTracking(); | 654 initial_map->CompleteInobjectSlackTracking(); |
734 | 655 |
735 return isolate->heap()->undefined_value(); | 656 return isolate->heap()->undefined_value(); |
736 } | 657 } |
737 | 658 |
738 | 659 |
739 RUNTIME_FUNCTION(Runtime_GlobalProxy) { | |
740 SealHandleScope shs(isolate); | |
741 DCHECK(args.length() == 1); | |
742 CONVERT_ARG_CHECKED(JSFunction, function, 0); | |
743 return function->context()->global_proxy(); | |
744 } | |
745 | |
746 | |
747 RUNTIME_FUNCTION(Runtime_LookupAccessor) { | |
748 HandleScope scope(isolate); | |
749 DCHECK(args.length() == 3); | |
750 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, receiver, 0); | |
751 CONVERT_ARG_HANDLE_CHECKED(Name, name, 1); | |
752 CONVERT_SMI_ARG_CHECKED(flag, 2); | |
753 AccessorComponent component = flag == 0 ? ACCESSOR_GETTER : ACCESSOR_SETTER; | |
754 if (!receiver->IsJSObject()) return isolate->heap()->undefined_value(); | |
755 Handle<Object> result; | |
756 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | |
757 isolate, result, | |
758 JSObject::GetAccessor(Handle<JSObject>::cast(receiver), name, component)); | |
759 return *result; | |
760 } | |
761 | |
762 | |
763 RUNTIME_FUNCTION(Runtime_LoadMutableDouble) { | 660 RUNTIME_FUNCTION(Runtime_LoadMutableDouble) { |
764 HandleScope scope(isolate); | 661 HandleScope scope(isolate); |
765 DCHECK(args.length() == 2); | 662 DCHECK(args.length() == 2); |
766 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); | 663 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); |
767 CONVERT_ARG_HANDLE_CHECKED(Smi, index, 1); | 664 CONVERT_ARG_HANDLE_CHECKED(Smi, index, 1); |
768 RUNTIME_ASSERT((index->value() & 1) == 1); | 665 RUNTIME_ASSERT((index->value() & 1) == 1); |
769 FieldIndex field_index = | 666 FieldIndex field_index = |
770 FieldIndex::ForLoadByFieldIndex(object->map(), index->value()); | 667 FieldIndex::ForLoadByFieldIndex(object->map(), index->value()); |
771 if (field_index.is_inobject()) { | 668 if (field_index.is_inobject()) { |
772 RUNTIME_ASSERT(field_index.property_index() < | 669 RUNTIME_ASSERT(field_index.property_index() < |
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1222 isolate, o, key, &success, LookupIterator::HIDDEN); | 1119 isolate, o, key, &success, LookupIterator::HIDDEN); |
1223 if (!success) return isolate->heap()->exception(); | 1120 if (!success) return isolate->heap()->exception(); |
1224 MAYBE_RETURN( | 1121 MAYBE_RETURN( |
1225 JSReceiver::CreateDataProperty(&it, value, Object::THROW_ON_ERROR), | 1122 JSReceiver::CreateDataProperty(&it, value, Object::THROW_ON_ERROR), |
1226 isolate->heap()->exception()); | 1123 isolate->heap()->exception()); |
1227 return *value; | 1124 return *value; |
1228 } | 1125 } |
1229 | 1126 |
1230 } // namespace internal | 1127 } // namespace internal |
1231 } // namespace v8 | 1128 } // namespace v8 |
OLD | NEW |