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

Unified Diff: src/runtime.cc

Issue 3522008: This is a little experiment to move Failure to a superclass above Object... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 10 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/property.h ('k') | src/stub-cache.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/runtime.cc
===================================================================
--- src/runtime.cc (revision 5559)
+++ src/runtime.cc (working copy)
@@ -102,9 +102,11 @@
MUST_USE_RESULT static Object* DeepCopyBoilerplate(JSObject* boilerplate) {
StackLimitCheck check;
if (check.HasOverflowed()) return Top::StackOverflow();
+ Object* result;
+ { TryAllocation t = Heap::CopyJSObject(boilerplate);
+ if (!t->ToObject(&result)) return t;
+ }
- Object* result = Heap::CopyJSObject(boilerplate);
- if (result->IsFailure()) return result;
JSObject* copy = JSObject::cast(result);
// Deep copy local properties.
@@ -113,9 +115,10 @@
for (int i = 0; i < properties->length(); i++) {
Object* value = properties->get(i);
if (value->IsJSObject()) {
+ { TryAllocation t = DeepCopyBoilerplate(js_object);
+ if (!t->ToObject(&result)) return t;
+ }
JSObject* js_object = JSObject::cast(value);
- result = DeepCopyBoilerplate(js_object);
- if (result->IsFailure()) return result;
properties->set(i, result);
}
}
@@ -123,15 +126,18 @@
for (int i = 0; i < nof; i++) {
Object* value = copy->InObjectPropertyAt(i);
if (value->IsJSObject()) {
+ { TryAllocation t = DeepCopyBoilerplate(js_object);
+ if (!t->ToObject(&result)) return t;
+ }
JSObject* js_object = JSObject::cast(value);
- result = DeepCopyBoilerplate(js_object);
- if (result->IsFailure()) return result;
copy->InObjectPropertyAtPut(i, result);
}
}
+ { TryAllocation t =
+ Heap::AllocateFixedArray(copy->NumberOfLocalProperties(NONE));
+ if (!t->ToObject(&result)) return t;
+ }
} else {
- result = Heap::AllocateFixedArray(copy->NumberOfLocalProperties(NONE));
- if (result->IsFailure()) return result;
FixedArray* names = FixedArray::cast(result);
copy->GetLocalPropertyNames(names, 0);
for (int i = 0; i < names->length(); i++) {
@@ -146,11 +152,13 @@
Object* value = copy->GetProperty(key_string, &attributes);
ASSERT(!value->IsFailure());
if (value->IsJSObject()) {
+ { TryAllocation t = DeepCopyBoilerplate(js_object);
+ if (!t->ToObject(&result)) return t;
+ }
JSObject* js_object = JSObject::cast(value);
- result = DeepCopyBoilerplate(js_object);
- if (result->IsFailure()) return result;
- result = copy->SetProperty(key_string, result, NONE);
- if (result->IsFailure()) return result;
+ { TryAllocation t = copy->SetProperty(key_string, result, NONE);
+ if (!t->ToObject(&result)) return t;
+ }
}
}
}
@@ -172,9 +180,10 @@
for (int i = 0; i < elements->length(); i++) {
Object* value = elements->get(i);
if (value->IsJSObject()) {
+ { TryAllocation t = DeepCopyBoilerplate(js_object);
+ if (!t->ToObject(&result)) return t;
+ }
JSObject* js_object = JSObject::cast(value);
- result = DeepCopyBoilerplate(js_object);
- if (result->IsFailure()) return result;
elements->set(i, result);
}
}
@@ -189,9 +198,10 @@
if (element_dictionary->IsKey(k)) {
Object* value = element_dictionary->ValueAt(i);
if (value->IsJSObject()) {
+ { TryAllocation t = DeepCopyBoilerplate(js_object);
+ if (!t->ToObject(&result)) return t;
+ }
JSObject* js_object = JSObject::cast(value);
- result = DeepCopyBoilerplate(js_object);
- if (result->IsFailure()) return result;
element_dictionary->ValueAtPut(i, result);
}
}
@@ -518,13 +528,17 @@
Object* value = args[1];
// Create a catch context extension object.
JSFunction* constructor =
+ Object* object;
+ { TryAllocation t = Heap::AllocateJSObject(constructor);
+ if (!t->ToObject(&object)) return t;
+ }
Top::context()->global_context()->context_extension_function();
- Object* object = Heap::AllocateJSObject(constructor);
- if (object->IsFailure()) return object;
// Assign the exception value to the catch variable and make sure
+ { TryAllocation t =
+ JSObject::cast(object)->SetProperty(key, value, DONT_DELETE);
+ if (!t->ToObject(&value)) return t;
+ }
// that the catch variable is DontDelete.
- value = JSObject::cast(object)->SetProperty(key, value, DONT_DELETE);
- if (value->IsFailure()) return value;
return object;
}
@@ -567,13 +581,16 @@
!HeapObject::cast(jsobject->GetPrototype())->map()->is_hidden_prototype());
RUNTIME_ASSERT(!proto->map()->is_hidden_prototype());
+ Object* map_or_failure;
+ { TryAllocation t = proto->map()->CopyDropTransitions();
+ if (!t->ToObject(&map_or_failure)) return t;
+ }
// Allocate up front before we start altering state in case we get a GC.
- Object* map_or_failure = proto->map()->CopyDropTransitions();
- if (map_or_failure->IsFailure()) return map_or_failure;
Map* new_proto_map = Map::cast(map_or_failure);
+ { TryAllocation t = jsobject->map()->CopyDropTransitions();
+ if (!t->ToObject(&map_or_failure)) return t;
+ }
- map_or_failure = jsobject->map()->CopyDropTransitions();
- if (map_or_failure->IsFailure()) return map_or_failure;
Map* new_map = Map::cast(map_or_failure);
// Set proto's prototype to be the old prototype of the object.
@@ -719,9 +736,11 @@
if (structure->IsProxy() || structure->IsAccessorInfo()) {
// Property that is internally implemented as a callback or
// an API defined callback.
- Object* value = obj->GetPropertyWithCallback(
- *obj, structure, *name, result.holder());
- if (value->IsFailure()) return value;
+ Object* value;
+ { TryAllocation t = obj->GetPropertyWithCallback(
+ *obj, structure, *name, result.holder());
+ if (!t->ToObject(&value)) return t;
+ }
elms->set(IS_ACCESSOR_INDEX, Heap::false_value());
elms->set(VALUE_INDEX, value);
elms->set(WRITABLE_INDEX, Heap::ToBoolean(!result.IsReadOnly()));
@@ -812,9 +831,11 @@
Map* old_map = object->map();
bool needs_access_checks = old_map->is_access_check_needed();
if (needs_access_checks) {
+ Object* new_map;
+ { TryAllocation t = old_map->CopyDropTransitions();
+ if (!t->ToObject(&new_map)) return t;
+ }
// Copy map so it won't interfere constructor's initial map.
- Object* new_map = old_map->CopyDropTransitions();
- if (new_map->IsFailure()) return new_map;
Map::cast(new_map)->set_is_access_check_needed(false);
object->set_map(Map::cast(new_map));
@@ -828,9 +849,11 @@
CONVERT_CHECKED(HeapObject, object, args[0]);
Map* old_map = object->map();
if (!old_map->is_access_check_needed()) {
+ Object* new_map;
+ { TryAllocation t = old_map->CopyDropTransitions();
+ if (!t->ToObject(&new_map)) return t;
+ }
// Copy map so it won't interfere constructor's initial map.
- Object* new_map = old_map->CopyDropTransitions();
- if (new_map->IsFailure()) return new_map;
Map::cast(new_map)->set_is_access_check_needed(true);
object->set_map(Map::cast(new_map));
@@ -1366,9 +1389,11 @@
CONVERT_SMI_CHECKED(elements_count, args[0]);
if (elements_count > JSArray::kMaxFastElementsLength) {
return Top::ThrowIllegalOperation();
+ Object* new_object;
+ { TryAllocation t = Heap::AllocateFixedArrayWithHoles(elements_count);
+ if (!t->ToObject(&new_object)) return t;
}
- Object* new_object = Heap::AllocateFixedArrayWithHoles(elements_count);
- if (new_object->IsFailure()) return new_object;
+ }
FixedArray* elements = FixedArray::cast(new_object);
new_object = Heap::AllocateRaw(JSRegExpResult::kSize,
NEW_SPACE,
@@ -1609,9 +1634,11 @@
NoHandleAllocation ha;
ASSERT(args.length() == 1);
+ Object* obj;
+ { TryAllocation t = f->RemovePrototype();
+ if (!t->ToObject(&obj)) return t;
+ }
CONVERT_CHECKED(JSFunction, f, args[0]);
- Object* obj = f->RemovePrototype();
- if (obj->IsFailure()) return obj;
return Heap::undefined_value();
}
@@ -1690,9 +1717,11 @@
ASSERT(args.length() == 2);
CONVERT_CHECKED(JSFunction, fun, args[0]);
+ Object* obj;
+ { TryAllocation t = Accessors::FunctionSetPrototype(fun, args[1], NULL);
+ if (!t->ToObject(&obj)) return t;
+ }
ASSERT(fun->should_have_prototype());
- Object* obj = Accessors::FunctionSetPrototype(fun, args[1], NULL);
- if (obj->IsFailure()) return obj;
return args[0]; // return TOS
}
@@ -1815,9 +1844,11 @@
// Flatten the string. If someone wants to get a char at an index
// in a cons string, it is likely that more indices will be
+ Object* flat;
+ { TryAllocation t = subject->TryFlatten();
+ if (!t->ToObject(&flat)) return t;
+ }
// accessed.
- Object* flat = subject->TryFlatten();
- if (flat->IsFailure()) return flat;
subject = String::cast(flat);
if (i >= static_cast<uint32_t>(subject->length())) {
@@ -3508,9 +3539,11 @@
// handles this incorrectly if the property is readonly (does nothing)
if (result.IsProperty() &&
(result.type() == FIELD || result.type() == NORMAL
+ Object* ok;
+ { TryAllocation t = obj->DeleteProperty(name, JSObject::NORMAL_DELETION);
+ if (!t->ToObject(&ok)) return t;
+ }
|| result.type() == CONSTANT_FUNCTION)) {
- Object* ok = obj->DeleteProperty(name, JSObject::NORMAL_DELETION);
- if (ok->IsFailure()) return ok;
}
return obj->DefineAccessor(name, flag_setter->value() == 0, fun, attr);
}
@@ -4385,9 +4418,11 @@
// No length change implies no change. Return original string if no change.
if (escaped_length == length) {
return source;
+ Object* o;
+ { TryAllocation t = Heap::AllocateRawAsciiString(escaped_length);
+ if (!t->ToObject(&o)) return t;
}
- Object* o = Heap::AllocateRawAsciiString(escaped_length);
- if (o->IsFailure()) return o;
+ }
String* destination = String::cast(o);
int dest_position = 0;
@@ -4692,9 +4727,11 @@
// character is also ascii. This is currently the case, but it
// might break in the future if we implement more context and locale
// dependent upper/lower conversions.
+ Object* o;
+ { TryAllocation t = Heap::AllocateRawAsciiString(length);
+ if (!t->ToObject(&o)) return t;
+ }
if (s->IsSeqAsciiString()) {
- Object* o = Heap::AllocateRawAsciiString(length);
- if (o->IsFailure()) return o;
SeqAsciiString* result = SeqAsciiString::cast(o);
bool has_changed_character = ConvertTraits::ConvertAscii(
result->GetChars(), SeqAsciiString::cast(s)->GetChars(), length);
@@ -4909,9 +4946,11 @@
const int length = s->length();
Handle<FixedArray> elements;
+ Object* obj;
+ { TryAllocation t = Heap::AllocateUninitializedFixedArray(length);
+ if (!t->ToObject(&obj)) return t;
+ }
if (s->IsFlat() && s->IsAsciiRepresentation()) {
- Object* obj = Heap::AllocateUninitializedFixedArray(length);
- if (obj->IsFailure()) return obj;
elements = Handle<FixedArray>(FixedArray::cast(obj));
Vector<const char> chars = s->ToAsciiVector();
@@ -5263,18 +5302,20 @@
int length = position;
Object* object;
+ { TryAllocation t = Heap::AllocateRawAsciiString(length);
+ if (!t->ToObject(&object)) return t;
+ }
if (ascii) {
- object = Heap::AllocateRawAsciiString(length);
- if (object->IsFailure()) return object;
SeqAsciiString* answer = SeqAsciiString::cast(object);
StringBuilderConcatHelper(special,
answer->GetChars(),
fixed_array,
array_length);
return answer;
+ { TryAllocation t = Heap::AllocateRawTwoByteString(length);
+ if (!t->ToObject(&object)) return t;
+ }
} else {
- object = Heap::AllocateRawTwoByteString(length);
- if (object->IsFailure()) return object;
SeqTwoByteString* answer = SeqTwoByteString::cast(object);
StringBuilderConcatHelper(special,
answer->GetChars(),
@@ -5545,11 +5586,14 @@
int d = x->Get(0) - y->Get(0);
if (d < 0) return Smi::FromInt(LESS);
else if (d > 0) return Smi::FromInt(GREATER);
+ Object* obj;
+ { TryAllocation t = Heap::PrepareForCompare(x);
+ if (!t->ToObject(&obj)) return t;
+ }
- Object* obj = Heap::PrepareForCompare(x);
- if (obj->IsFailure()) return obj;
- obj = Heap::PrepareForCompare(y);
- if (obj->IsFailure()) return obj;
+ { TryAllocation t = Heap::PrepareForCompare(y);
+ if (!t->ToObject(&obj)) return t;
+ }
return (x->IsFlat() && y->IsFlat()) ? FlatStringCompare(x, y)
: StringInputBufferCompare(x, y);
@@ -6185,14 +6229,18 @@
JSFunction* callee = JSFunction::cast(args[0]);
Object** parameters = reinterpret_cast<Object**>(args[1]);
const int length = Smi::cast(args[2])->value();
+ Object* result;
+ { TryAllocation t = Heap::AllocateArgumentsObject(callee, length);
+ if (!t->ToObject(&result)) return t;
+ }
- Object* result = Heap::AllocateArgumentsObject(callee, length);
- if (result->IsFailure()) return result;
// Allocate the elements if needed.
if (length > 0) {
+ Object* obj;
+ { TryAllocation t = Heap::AllocateRawFixedArray(length);
+ if (!t->ToObject(&obj)) return t;
+ }
// Allocate the fixed array.
- Object* obj = Heap::AllocateRawFixedArray(length);
- if (obj->IsFailure()) return obj;
AssertNoAllocation no_gc;
FixedArray* array = reinterpret_cast<FixedArray*>(obj);
@@ -6403,9 +6451,11 @@
ASSERT(args.length() == 1);
CONVERT_CHECKED(JSFunction, function, args[0]);
+ Object* result;
+ { TryAllocation t = Heap::AllocateFunctionContext(length, function);
+ if (!t->ToObject(&result)) return t;
+ }
int length = function->shared()->scope_info()->NumberOfContextSlots();
- Object* result = Heap::AllocateFunctionContext(length, function);
- if (result->IsFailure()) return result;
Top::set_context(Context::cast(result));
@@ -7109,9 +7159,11 @@
FixedArray* elements = FixedArray::cast(array->elements());
for (int i = 0; i < length; i++) {
if (elements->get(i) == element) return Heap::false_value();
+ Object* obj;
+ { TryAllocation t = array->SetFastElement(length, element);
+ if (!t->ToObject(&obj)) return t;
}
- Object* obj = array->SetFastElement(length, element);
- if (obj->IsFailure()) return obj;
+ }
return Heap::true_value();
}
@@ -7558,9 +7610,11 @@
if (new_map->IsFailure()) return new_map;
to->set_map(Map::cast(new_map));
to->set_elements(new_elements);
+ Object* obj;
+ { TryAllocation t = from->ResetElements();
+ if (!t->ToObject(&obj)) return t;
+ }
to->set_length(from->length());
- Object* obj = from->ResetElements();
- if (obj->IsFailure()) return obj;
from->set_length(Smi::FromInt(0));
return to;
}
@@ -7845,9 +7899,11 @@
// DebugLookupResultValue can cause GC so details from LookupResult needs
// to be copied to handles before this.
bool caught_exception = false;
- Object* raw_value = DebugLookupResultValue(*obj, *name, &result,
- &caught_exception);
- if (raw_value->IsFailure()) return raw_value;
+ Object* raw_value;
+ { TryAllocation t = DebugLookupResultValue(*obj, *name, &result,
+ &caught_exception);
+ if (!t->ToObject(&raw_value)) return t;
+ }
Handle<Object> value(raw_value);
// If the callback object is a fixed array then it contains JavaScript
@@ -7969,9 +8025,11 @@
HandleScope scope;
ASSERT(args.length() == 1);
+ Object* result;
+ { TryAllocation t = Runtime_CheckExecutionState(args);
+ if (!t->ToObject(&result)) return t;
+ }
// Check arguments.
- Object* result = Runtime_CheckExecutionState(args);
- if (result->IsFailure()) return result;
// Count all frames which are relevant to debugging stack trace.
int n = 0;
@@ -8017,9 +8075,11 @@
HandleScope scope;
ASSERT(args.length() == 2);
+ Object* check;
+ { TryAllocation t = Runtime_CheckExecutionState(args);
+ if (!t->ToObject(&check)) return t;
+ }
// Check arguments.
- Object* check = Runtime_CheckExecutionState(args);
- if (check->IsFailure()) return check;
CONVERT_NUMBER_CHECKED(int, index, Int32, args[1]);
// Find the relevant frame with the requested index.
@@ -8558,9 +8618,11 @@
HandleScope scope;
ASSERT(args.length() == 2);
+ Object* check;
+ { TryAllocation t = Runtime_CheckExecutionState(args);
+ if (!t->ToObject(&check)) return t;
+ }
// Check arguments.
- Object* check = Runtime_CheckExecutionState(args);
- if (check->IsFailure()) return check;
CONVERT_CHECKED(Smi, wrapped_id, args[1]);
// Get the frame where the debugging is performed.
@@ -8594,9 +8656,11 @@
HandleScope scope;
ASSERT(args.length() == 3);
+ Object* check;
+ { TryAllocation t = Runtime_CheckExecutionState(args);
+ if (!t->ToObject(&check)) return t;
+ }
// Check arguments.
- Object* check = Runtime_CheckExecutionState(args);
- if (check->IsFailure()) return check;
CONVERT_CHECKED(Smi, wrapped_id, args[1]);
CONVERT_NUMBER_CHECKED(int, index, Int32, args[2]);
@@ -8646,9 +8710,11 @@
static Object* Runtime_GetCFrames(Arguments args) {
HandleScope scope;
+ Object* result;
+ { TryAllocation t = Runtime_CheckExecutionState(args);
+ if (!t->ToObject(&result)) return t;
+ }
ASSERT(args.length() == 1);
- Object* result = Runtime_CheckExecutionState(args);
- if (result->IsFailure()) return result;
#if V8_HOST_ARCH_64_BIT
UNIMPLEMENTED();
@@ -8695,9 +8761,11 @@
HandleScope scope;
ASSERT(args.length() == 1);
+ Object* result;
+ { TryAllocation t = Runtime_CheckExecutionState(args);
+ if (!t->ToObject(&result)) return t;
+ }
// Check arguments.
- Object* result = Runtime_CheckExecutionState(args);
- if (result->IsFailure()) return result;
// Count all archived V8 threads.
int n = 0;
@@ -8727,9 +8795,11 @@
HandleScope scope;
ASSERT(args.length() == 2);
+ Object* check;
+ { TryAllocation t = Runtime_CheckExecutionState(args);
+ if (!t->ToObject(&check)) return t;
+ }
// Check arguments.
- Object* check = Runtime_CheckExecutionState(args);
- if (check->IsFailure()) return check;
CONVERT_NUMBER_CHECKED(int, index, Int32, args[1]);
// Allocate array for result.
@@ -8979,9 +9049,11 @@
static Object* Runtime_PrepareStep(Arguments args) {
HandleScope scope;
ASSERT(args.length() == 3);
+ Object* check;
+ { TryAllocation t = Runtime_CheckExecutionState(args);
+ if (!t->ToObject(&check)) return t;
+ }
// Check arguments.
- Object* check = Runtime_CheckExecutionState(args);
- if (check->IsFailure()) return check;
if (!args[1]->IsNumber() || !args[2]->IsNumber()) {
return Top::Throw(Heap::illegal_argument_symbol());
}
@@ -9094,9 +9166,11 @@
// Check the execution state and decode arguments frame and source to be
// evaluated.
+ Object* check_result;
+ { TryAllocation t = Runtime_CheckExecutionState(args);
+ if (!t->ToObject(&check_result)) return t;
+ }
ASSERT(args.length() == 4);
- Object* check_result = Runtime_CheckExecutionState(args);
- if (check_result->IsFailure()) return check_result;
CONVERT_CHECKED(Smi, wrapped_id, args[1]);
CONVERT_ARG_CHECKED(String, source, 2);
CONVERT_BOOLEAN_CHECKED(disable_break, args[3]);
@@ -9205,9 +9279,11 @@
// Check the execution state and decode arguments frame and source to be
// evaluated.
+ Object* check_result;
+ { TryAllocation t = Runtime_CheckExecutionState(args);
+ if (!t->ToObject(&check_result)) return t;
+ }
ASSERT(args.length() == 3);
- Object* check_result = Runtime_CheckExecutionState(args);
- if (check_result->IsFailure()) return check_result;
CONVERT_ARG_CHECKED(String, source, 1);
CONVERT_BOOLEAN_CHECKED(disable_break, args[2]);
@@ -9375,9 +9451,11 @@
count = DebugReferencedBy(target, instance_filter, max_references,
NULL, 0, arguments_function);
+ Object* object;
+ { TryAllocation t = Heap::AllocateFixedArray(count);
+ if (!t->ToObject(&object)) return t;
+ }
// Allocate an array to hold the result.
- Object* object = Heap::AllocateFixedArray(count);
- if (object->IsFailure()) return object;
FixedArray* instances = FixedArray::cast(object);
// Fill the referencing objects.
@@ -9441,9 +9519,11 @@
int count;
count = DebugConstructedBy(constructor, max_references, NULL, 0);
+ Object* object;
+ { TryAllocation t = Heap::AllocateFixedArray(count);
+ if (!t->ToObject(&object)) return t;
+ }
// Allocate an array to hold the result.
- Object* object = Heap::AllocateFixedArray(count);
- if (object->IsFailure()) return object;
FixedArray* instances = FixedArray::cast(object);
// Fill the referencing objects.
@@ -10118,9 +10198,11 @@
Object* Runtime::InitializeIntrinsicFunctionNames(Object* dictionary) {
ASSERT(dictionary != NULL);
ASSERT(StringDictionary::cast(dictionary)->NumberOfElements() == 0);
+ Object* name_symbol;
+ { TryAllocation t = Heap::LookupAsciiSymbol(kIntrinsicFunctions[i].name);
+ if (!t->ToObject(&name_symbol)) return t;
+ }
for (int i = 0; i < kNumFunctions; ++i) {
- Object* name_symbol = Heap::LookupAsciiSymbol(kIntrinsicFunctions[i].name);
- if (name_symbol->IsFailure()) return name_symbol;
StringDictionary* string_dictionary = StringDictionary::cast(dictionary);
dictionary = string_dictionary->Add(String::cast(name_symbol),
Smi::FromInt(i),
« no previous file with comments | « src/property.h ('k') | src/stub-cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698