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

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: 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 | « no previous file | 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->IsSmi() && !value->IsHeapNumber() && !value->IsUndefined()) {
Michael Starzinger 2013/06/17 11:30:29 nit: Better use "!value->IsNumber() && !value->IsU
Jakob Kummerow 2013/06/17 16:50:29 Done.
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->IsSmi() &&
4777 !value->IsHeapNumber() &&
Michael Starzinger 2013/06/17 11:30:29 nit: Likewise.
Jakob Kummerow 2013/06/17 16:50:29 Done.
4778 !value->IsUndefined()) {
4779 bool has_exception;
4780 Handle<Object> number = Execution::ToNumber(value, &has_exception);
4781 if (has_exception) return Failure::Exception();
4782 value = number;
4783 }
4784 }
4785 result = js_object->SetElement(
4786 index, *value, attr, strict_mode, true, set_mode);
4769 } else { 4787 } else {
4770 if (name->IsString()) Handle<String>::cast(name)->TryFlatten(); 4788 if (name->IsString()) Handle<String>::cast(name)->TryFlatten();
4771 result = JSReceiver::SetProperty( 4789 result = js_object->SetProperty(*name, *value, attr, strict_mode);
4772 js_object, name, value, attr, strict_mode);
4773 } 4790 }
4774 if (result.is_null()) return Failure::Exception(); 4791 if (result->IsFailure()) return result;
4775 return *value; 4792 return *value;
4776 } 4793 }
4777 4794
4778 // Call-back into JavaScript to convert the key to a string. 4795 // Call-back into JavaScript to convert the key to a string.
4779 bool has_pending_exception = false; 4796 bool has_pending_exception = false;
4780 Handle<Object> converted = Execution::ToString(key, &has_pending_exception); 4797 Handle<Object> converted = Execution::ToString(key, &has_pending_exception);
4781 if (has_pending_exception) return Failure::Exception(); 4798 if (has_pending_exception) return Failure::Exception();
4782 Handle<String> name = Handle<String>::cast(converted); 4799 Handle<String> name = Handle<String>::cast(converted);
4783 4800
4784 if (name->AsArrayIndex(&index)) { 4801 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 13651 // Handle last resort GC and make sure to allow future allocations
13635 // to grow the heap without causing GCs (if possible). 13652 // to grow the heap without causing GCs (if possible).
13636 isolate->counters()->gc_last_resort_from_js()->Increment(); 13653 isolate->counters()->gc_last_resort_from_js()->Increment();
13637 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, 13654 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags,
13638 "Runtime::PerformGC"); 13655 "Runtime::PerformGC");
13639 } 13656 }
13640 } 13657 }
13641 13658
13642 13659
13643 } } // namespace v8::internal 13660 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698