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

Side by Side Diff: src/runtime.cc

Issue 17167002: Fix Runtime_SetProperty to properly handle OOM failures (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: addressed comments Created 7 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « src/objects.cc ('k') | no next file » | 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 // 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 4735 matching lines...) Expand 10 before | Expand all | Expand 10 after
4746 // JavaScript. 4746 // JavaScript.
4747 // In the case of a String object we just need to redirect the assignment to 4747 // In the case of a String object we just need to redirect the assignment to
4748 // the underlying string if the index is in range. Since the underlying 4748 // the underlying string if the index is in range. Since the underlying
4749 // string does nothing with the assignment then we can ignore such 4749 // string does nothing with the assignment then we can ignore such
4750 // assignments. 4750 // assignments.
4751 if (js_object->IsStringObjectWithCharacterAt(index)) { 4751 if (js_object->IsStringObjectWithCharacterAt(index)) {
4752 return *value; 4752 return *value;
4753 } 4753 }
4754 4754
4755 js_object->ValidateElements(); 4755 js_object->ValidateElements();
4756 Handle<Object> result = JSObject::SetElement( 4756 if (js_object->HasExternalArrayElements()) {
4757 js_object, index, value, attr, strict_mode, set_mode); 4757 if (!value->IsNumber() && !value->IsUndefined()) {
4758 bool has_exception;
4759 Handle<Object> number = Execution::ToNumber(value, &has_exception);
4760 if (has_exception) return Failure::Exception();
4761 value = number;
4762 }
4763 }
4764 MaybeObject* result = js_object->SetElement(
4765 index, *value, attr, strict_mode, true, set_mode);
4758 js_object->ValidateElements(); 4766 js_object->ValidateElements();
4759 if (result.is_null()) return Failure::Exception(); 4767 if (result->IsFailure()) return result;
4760 return *value; 4768 return *value;
4761 } 4769 }
4762 4770
4763 if (key->IsName()) { 4771 if (key->IsName()) {
4764 Handle<Object> result; 4772 MaybeObject* result;
4765 Handle<Name> name = Handle<Name>::cast(key); 4773 Handle<Name> name = Handle<Name>::cast(key);
4766 if (name->AsArrayIndex(&index)) { 4774 if (name->AsArrayIndex(&index)) {
4767 result = JSObject::SetElement( 4775 if (js_object->HasExternalArrayElements()) {
4768 js_object, index, value, attr, strict_mode, set_mode); 4776 if (!value->IsNumber() && !value->IsUndefined()) {
4777 bool has_exception;
4778 Handle<Object> number = Execution::ToNumber(value, &has_exception);
4779 if (has_exception) return Failure::Exception();
4780 value = number;
4781 }
4782 }
4783 result = js_object->SetElement(
4784 index, *value, attr, strict_mode, true, set_mode);
4769 } else { 4785 } else {
4770 if (name->IsString()) Handle<String>::cast(name)->TryFlatten(); 4786 if (name->IsString()) Handle<String>::cast(name)->TryFlatten();
4771 result = JSReceiver::SetProperty( 4787 result = js_object->SetProperty(*name, *value, attr, strict_mode);
4772 js_object, name, value, attr, strict_mode);
4773 } 4788 }
4774 if (result.is_null()) return Failure::Exception(); 4789 if (result->IsFailure()) return result;
4775 return *value; 4790 return *value;
4776 } 4791 }
4777 4792
4778 // Call-back into JavaScript to convert the key to a string. 4793 // Call-back into JavaScript to convert the key to a string.
4779 bool has_pending_exception = false; 4794 bool has_pending_exception = false;
4780 Handle<Object> converted = Execution::ToString(key, &has_pending_exception); 4795 Handle<Object> converted = Execution::ToString(key, &has_pending_exception);
4781 if (has_pending_exception) return Failure::Exception(); 4796 if (has_pending_exception) return Failure::Exception();
4782 Handle<String> name = Handle<String>::cast(converted); 4797 Handle<String> name = Handle<String>::cast(converted);
4783 4798
4784 if (name->AsArrayIndex(&index)) { 4799 if (name->AsArrayIndex(&index)) {
(...skipping 8849 matching lines...) Expand 10 before | Expand all | Expand 10 after
13634 // Handle last resort GC and make sure to allow future allocations 13649 // Handle last resort GC and make sure to allow future allocations
13635 // to grow the heap without causing GCs (if possible). 13650 // to grow the heap without causing GCs (if possible).
13636 isolate->counters()->gc_last_resort_from_js()->Increment(); 13651 isolate->counters()->gc_last_resort_from_js()->Increment();
13637 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, 13652 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags,
13638 "Runtime::PerformGC"); 13653 "Runtime::PerformGC");
13639 } 13654 }
13640 } 13655 }
13641 13656
13642 13657
13643 } } // namespace v8::internal 13658 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698