OLD | NEW |
---|---|
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 13723 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
13734 if (obj->IsJSGlobalProxy()) { | 13734 if (obj->IsJSGlobalProxy()) { |
13735 Object* proto = obj->GetPrototype(); | 13735 Object* proto = obj->GetPrototype(); |
13736 if (proto->IsNull()) return isolate->heap()->false_value(); | 13736 if (proto->IsNull()) return isolate->heap()->false_value(); |
13737 ASSERT(proto->IsJSGlobalObject()); | 13737 ASSERT(proto->IsJSGlobalObject()); |
13738 obj = JSReceiver::cast(proto); | 13738 obj = JSReceiver::cast(proto); |
13739 } | 13739 } |
13740 return isolate->heap()->ToBoolean(obj->map()->is_observed()); | 13740 return isolate->heap()->ToBoolean(obj->map()->is_observed()); |
13741 } | 13741 } |
13742 | 13742 |
13743 | 13743 |
13744 RUNTIME_FUNCTION(MaybeObject*, Runtime_SetIsObserved) { | 13744 RUNTIME_FUNCTION(MaybeObject*, Runtime_SetIsObserved) { |
rossberg
2013/07/12 06:58:02
Drive-by comment: I think the (by now rather non-t
Toon Verwaest
2013/07/12 09:02:56
I agree.
Also, can we share this logic between Se
rafaelw
2013/07/12 21:17:38
Done.
| |
13745 SealHandleScope shs(isolate); | 13745 SealHandleScope shs(isolate); |
13746 ASSERT(args.length() == 2); | 13746 ASSERT(args.length() == 1); |
13747 CONVERT_ARG_CHECKED(JSReceiver, obj, 0); | 13747 CONVERT_ARG_CHECKED(JSReceiver, obj, 0); |
13748 CONVERT_BOOLEAN_ARG_CHECKED(is_observed, 1); | |
13749 if (obj->IsJSGlobalProxy()) { | 13748 if (obj->IsJSGlobalProxy()) { |
13750 Object* proto = obj->GetPrototype(); | 13749 Object* proto = obj->GetPrototype(); |
13751 if (proto->IsNull()) return isolate->heap()->undefined_value(); | 13750 if (proto->IsNull()) return isolate->heap()->undefined_value(); |
13752 ASSERT(proto->IsJSGlobalObject()); | 13751 ASSERT(proto->IsJSGlobalObject()); |
13753 obj = JSReceiver::cast(proto); | 13752 obj = JSReceiver::cast(proto); |
13754 } | 13753 } |
13755 ASSERT(!(obj->map()->is_observed() && obj->IsJSObject() && | 13754 ASSERT(!(obj->map()->is_observed() && obj->IsJSObject() && |
13756 JSObject::cast(obj)->HasFastElements())); | 13755 JSObject::cast(obj)->HasFastElements())); |
13757 if (obj->map()->is_observed() != is_observed) { | 13756 if (obj->map()->is_observed()) |
13758 if (is_observed && obj->IsJSObject() && | 13757 return isolate->heap()->undefined_value(); |
13759 !JSObject::cast(obj)->HasExternalArrayElements()) { | 13758 |
13760 // Go to dictionary mode, so that we don't skip map checks. | 13759 JSObject* object = JSObject::cast(obj); |
13761 MaybeObject* maybe = JSObject::cast(obj)->NormalizeElements(); | 13760 Heap* heap = isolate->heap(); |
13762 if (maybe->IsFailure()) return maybe; | 13761 |
13763 ASSERT(!JSObject::cast(obj)->HasFastElements()); | 13762 if (!object->HasExternalArrayElements()) { |
13764 } | 13763 // Go to dictionary mode, so that we don't skip map checks. |
13765 MaybeObject* maybe = obj->map()->Copy(); | 13764 MaybeObject* maybe = object->NormalizeElements(); |
13766 Map* map; | 13765 if (maybe->IsFailure()) return maybe; |
13767 if (!maybe->To(&map)) return maybe; | 13766 ASSERT(!object->HasFastElements()); |
13768 map->set_is_observed(is_observed); | |
13769 obj->set_map(map); | |
13770 } | 13767 } |
13771 return isolate->heap()->undefined_value(); | 13768 |
13769 LookupResult result(isolate); | |
13770 object->map()->LookupTransition(object, heap->observed_symbol(), &result); | |
13771 | |
13772 Map* new_map; | |
13773 if (result.IsTransition()) { | |
13774 new_map = result.GetTransitionTarget(); | |
13775 ASSERT(new_map->is_observed()); | |
13776 } else if (object->map()->CanHaveMoreTransitions()) { | |
13777 MaybeObject* maybe_new_map = object->map()->CopyForObserved(); | |
13778 if (!maybe_new_map->To(&new_map)) return maybe_new_map; | |
13779 } else { | |
13780 MaybeObject* maybe_copy = object->map()->Copy(); | |
13781 if (!maybe_copy->To(&new_map)) return maybe_copy; | |
13782 new_map->set_is_observed(true); | |
13783 } | |
13784 object->set_map(new_map); | |
13785 | |
13786 return heap->undefined_value(); | |
13772 } | 13787 } |
13773 | 13788 |
13774 | 13789 |
13775 RUNTIME_FUNCTION(MaybeObject*, Runtime_SetObserverDeliveryPending) { | 13790 RUNTIME_FUNCTION(MaybeObject*, Runtime_SetObserverDeliveryPending) { |
13776 SealHandleScope shs(isolate); | 13791 SealHandleScope shs(isolate); |
13777 ASSERT(args.length() == 0); | 13792 ASSERT(args.length() == 0); |
13778 isolate->set_observer_delivery_pending(true); | 13793 isolate->set_observer_delivery_pending(true); |
13779 return isolate->heap()->undefined_value(); | 13794 return isolate->heap()->undefined_value(); |
13780 } | 13795 } |
13781 | 13796 |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
13995 // Handle last resort GC and make sure to allow future allocations | 14010 // Handle last resort GC and make sure to allow future allocations |
13996 // to grow the heap without causing GCs (if possible). | 14011 // to grow the heap without causing GCs (if possible). |
13997 isolate->counters()->gc_last_resort_from_js()->Increment(); | 14012 isolate->counters()->gc_last_resort_from_js()->Increment(); |
13998 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, | 14013 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, |
13999 "Runtime::PerformGC"); | 14014 "Runtime::PerformGC"); |
14000 } | 14015 } |
14001 } | 14016 } |
14002 | 14017 |
14003 | 14018 |
14004 } } // namespace v8::internal | 14019 } } // namespace v8::internal |
OLD | NEW |