Commit 0dcaac19 authored by erik.corry@gmail.com's avatar erik.corry@gmail.com

Make Failure inherit from MaybeObject instead of Object.

Review URL: http://codereview.chromium.org/3970005

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@5698 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent a21fc8e2
This diff is collapsed.
......@@ -75,40 +75,44 @@ class Accessors : public AllStatic {
};
// Accessor functions called directly from the runtime system.
MUST_USE_RESULT static Object* FunctionGetPrototype(Object* object, void*);
MUST_USE_RESULT static Object* FunctionSetPrototype(JSObject* object,
Object* value,
void*);
MUST_USE_RESULT static MaybeObject* FunctionGetPrototype(Object* object,
void*);
MUST_USE_RESULT static MaybeObject* FunctionSetPrototype(JSObject* object,
Object* value,
void*);
private:
// Accessor functions only used through the descriptor.
static Object* FunctionGetLength(Object* object, void*);
static Object* FunctionGetName(Object* object, void*);
static Object* FunctionGetArguments(Object* object, void*);
static Object* FunctionGetCaller(Object* object, void*);
static Object* ArraySetLength(JSObject* object, Object* value, void*);
static Object* ArrayGetLength(Object* object, void*);
static Object* StringGetLength(Object* object, void*);
static Object* ScriptGetName(Object* object, void*);
static Object* ScriptGetId(Object* object, void*);
static Object* ScriptGetSource(Object* object, void*);
static Object* ScriptGetLineOffset(Object* object, void*);
static Object* ScriptGetColumnOffset(Object* object, void*);
static Object* ScriptGetData(Object* object, void*);
static Object* ScriptGetType(Object* object, void*);
static Object* ScriptGetCompilationType(Object* object, void*);
static Object* ScriptGetLineEnds(Object* object, void*);
static Object* ScriptGetContextData(Object* object, void*);
static Object* ScriptGetEvalFromScript(Object* object, void*);
static Object* ScriptGetEvalFromScriptPosition(Object* object, void*);
static Object* ScriptGetEvalFromFunctionName(Object* object, void*);
static Object* ObjectGetPrototype(Object* receiver, void*);
static Object* ObjectSetPrototype(JSObject* receiver, Object* value, void*);
static MaybeObject* FunctionGetLength(Object* object, void*);
static MaybeObject* FunctionGetName(Object* object, void*);
static MaybeObject* FunctionGetArguments(Object* object, void*);
static MaybeObject* FunctionGetCaller(Object* object, void*);
MUST_USE_RESULT static MaybeObject* ArraySetLength(JSObject* object,
Object* value, void*);
static MaybeObject* ArrayGetLength(Object* object, void*);
static MaybeObject* StringGetLength(Object* object, void*);
static MaybeObject* ScriptGetName(Object* object, void*);
static MaybeObject* ScriptGetId(Object* object, void*);
static MaybeObject* ScriptGetSource(Object* object, void*);
static MaybeObject* ScriptGetLineOffset(Object* object, void*);
static MaybeObject* ScriptGetColumnOffset(Object* object, void*);
static MaybeObject* ScriptGetData(Object* object, void*);
static MaybeObject* ScriptGetType(Object* object, void*);
static MaybeObject* ScriptGetCompilationType(Object* object, void*);
static MaybeObject* ScriptGetLineEnds(Object* object, void*);
static MaybeObject* ScriptGetContextData(Object* object, void*);
static MaybeObject* ScriptGetEvalFromScript(Object* object, void*);
static MaybeObject* ScriptGetEvalFromScriptPosition(Object* object, void*);
static MaybeObject* ScriptGetEvalFromFunctionName(Object* object, void*);
static MaybeObject* ObjectGetPrototype(Object* receiver, void*);
static MaybeObject* ObjectSetPrototype(JSObject* receiver,
Object* value,
void*);
// Helper functions.
static Object* FlattenNumber(Object* value);
static Object* IllegalSetter(JSObject*, Object*, void*);
static MaybeObject* IllegalSetter(JSObject*, Object*, void*);
static Object* IllegalGetAccessor(Object* object, void*);
static Object* ReadOnlySetAccessor(JSObject*, Object* value, void*);
static MaybeObject* ReadOnlySetAccessor(JSObject*, Object* value, void*);
};
} } // namespace v8::internal
......
......@@ -1507,7 +1507,8 @@ static i::Handle<i::Object> CallV8HeapFunction(const char* name,
i::Object** argv[],
bool* has_pending_exception) {
i::Handle<i::String> fmt_str = i::Factory::LookupAsciiSymbol(name);
i::Object* object_fun = i::Top::builtins()->GetProperty(*fmt_str);
i::Object* object_fun =
i::Top::builtins()->GetPropertyNoExceptionThrown(*fmt_str);
i::Handle<i::JSFunction> fun =
i::Handle<i::JSFunction>(i::JSFunction::cast(object_fun));
i::Handle<i::Object> value =
......@@ -1623,7 +1624,8 @@ Local<StackFrame> StackTrace::GetFrame(uint32_t index) const {
ENTER_V8;
HandleScope scope;
i::Handle<i::JSArray> self = Utils::OpenHandle(this);
i::Handle<i::JSObject> obj(i::JSObject::cast(self->GetElement(index)));
i::Object* raw_object = self->GetElementNoExceptionThrown(index);
i::Handle<i::JSObject> obj(i::JSObject::cast(raw_object));
return scope.Close(Utils::StackFrameToLocal(obj));
}
......@@ -2539,10 +2541,12 @@ Local<Value> v8::Object::GetRealNamedPropertyInPrototypeChain(
self_obj->LookupRealNamedPropertyInPrototypes(*key_obj, &lookup);
if (lookup.IsProperty()) {
PropertyAttributes attributes;
i::Handle<i::Object> result(self_obj->GetProperty(*self_obj,
&lookup,
*key_obj,
&attributes));
i::Object* property =
self_obj->GetProperty(*self_obj,
&lookup,
*key_obj,
&attributes)->ToObjectUnchecked();
i::Handle<i::Object> result(property);
return Utils::ToLocal(result);
}
return Local<Value>(); // No real property was found in prototype chain.
......@@ -2558,10 +2562,12 @@ Local<Value> v8::Object::GetRealNamedProperty(Handle<String> key) {
self_obj->LookupRealNamedProperty(*key_obj, &lookup);
if (lookup.IsProperty()) {
PropertyAttributes attributes;
i::Handle<i::Object> result(self_obj->GetProperty(*self_obj,
&lookup,
*key_obj,
&attributes));
i::Object* property =
self_obj->GetProperty(*self_obj,
&lookup,
*key_obj,
&attributes)->ToObjectUnchecked();
i::Handle<i::Object> result(property);
return Utils::ToLocal(result);
}
return Local<Value>(); // No real property was found in prototype chain.
......
......@@ -1030,7 +1030,7 @@ int RegExpMacroAssemblerARM::CheckStackGuardState(Address* return_address,
ASSERT(*return_address <=
re_code->instruction_start() + re_code->instruction_size());
Object* result = Execution::HandleStackGuardInterrupt();
MaybeObject* result = Execution::HandleStackGuardInterrupt();
if (*code_handle != re_code) { // Return address no longer valid
int delta = *code_handle - re_code;
......
This diff is collapsed.
......@@ -1009,11 +1009,10 @@ bool Genesis::CompileScriptCached(Vector<const char> name,
}
#define INSTALL_NATIVE(Type, name, var) \
Handle<String> var##_name = Factory::LookupAsciiSymbol(name); \
global_context()->set_##var(Type::cast(global_context()-> \
builtins()-> \
GetProperty(*var##_name)));
#define INSTALL_NATIVE(Type, name, var) \
Handle<String> var##_name = Factory::LookupAsciiSymbol(name); \
global_context()->set_##var(Type::cast( \
global_context()->builtins()->GetPropertyNoExceptionThrown(*var##_name)));
void Genesis::InstallNativeFunctions() {
HandleScope scope;
......@@ -1369,7 +1368,8 @@ static void InstallCustomCallGenerator(Handle<JSObject> holder,
const char* function_name,
int id) {
Handle<String> name = Factory::LookupAsciiSymbol(function_name);
Handle<JSFunction> function(JSFunction::cast(holder->GetProperty(*name)));
Object* function_object = holder->GetProperty(*name)->ToObjectUnchecked();
Handle<JSFunction> function(JSFunction::cast(function_object));
function->shared()->set_function_data(Smi::FromInt(id));
}
......@@ -1584,8 +1584,9 @@ bool Genesis::InstallJSBuiltins(Handle<JSBuiltinsObject> builtins) {
for (int i = 0; i < Builtins::NumberOfJavaScriptBuiltins(); i++) {
Builtins::JavaScript id = static_cast<Builtins::JavaScript>(i);
Handle<String> name = Factory::LookupAsciiSymbol(Builtins::GetName(id));
Object* function_object = builtins->GetPropertyNoExceptionThrown(*name);
Handle<JSFunction> function
= Handle<JSFunction>(JSFunction::cast(builtins->GetProperty(*name)));
= Handle<JSFunction>(JSFunction::cast(function_object));
builtins->set_javascript_builtin(id, *function);
Handle<SharedFunctionInfo> shared
= Handle<SharedFunctionInfo>(function->shared());
......
This diff is collapsed.
......@@ -123,7 +123,7 @@ Handle<Code> CodeStub::GetCode() {
}
Object* CodeStub::TryGetCode() {
MaybeObject* CodeStub::TryGetCode() {
Code* code;
if (!FindCodeInCache(&code)) {
// Generate the new code.
......@@ -139,8 +139,11 @@ Object* CodeStub::TryGetCode() {
static_cast<Code::Kind>(GetCodeKind()),
InLoop(),
GetICState());
Object* new_object = Heap::CreateCode(desc, flags, masm.CodeObject());
if (new_object->IsFailure()) return new_object;
Object* new_object;
{ MaybeObject* maybe_new_object =
Heap::CreateCode(desc, flags, masm.CodeObject());
if (!maybe_new_object->ToObject(&new_object)) return maybe_new_object;
}
code = Code::cast(new_object);
RecordCodeGeneration(code, &masm);
......@@ -148,8 +151,9 @@ Object* CodeStub::TryGetCode() {
SetCustomCache(code);
} else {
// Try to update the code cache but do not fail if unable.
new_object = Heap::code_stubs()->AtNumberPut(GetKey(), code);
if (!new_object->IsFailure()) {
MaybeObject* maybe_new_object =
Heap::code_stubs()->AtNumberPut(GetKey(), code);
if (maybe_new_object->ToObject(&new_object)) {
Heap::public_set_code_stubs(NumberDictionary::cast(new_object));
}
}
......
......@@ -106,7 +106,7 @@ class CodeStub BASE_EMBEDDED {
// Retrieve the code for the stub if already generated. Do not
// generate the code if not already generated and instead return a
// retry after GC Failure object.
Object* TryGetCode();
MUST_USE_RESULT MaybeObject* TryGetCode();
static Major MajorKeyFromKey(uint32_t key) {
return static_cast<Major>(MajorKeyBits::decode(key));
......
......@@ -110,7 +110,7 @@ class CompilationCacheScript : public CompilationSubCache {
void Put(Handle<String> source, Handle<SharedFunctionInfo> function_info);
private:
MUST_USE_RESULT Object* TryTablePut(
MUST_USE_RESULT MaybeObject* TryTablePut(
Handle<String> source, Handle<SharedFunctionInfo> function_info);
// Note: Returns a new hash table if operation results in expansion.
......@@ -140,7 +140,7 @@ class CompilationCacheEval: public CompilationSubCache {
Handle<SharedFunctionInfo> function_info);
private:
MUST_USE_RESULT Object* TryTablePut(
MUST_USE_RESULT MaybeObject* TryTablePut(
Handle<String> source,
Handle<Context> context,
Handle<SharedFunctionInfo> function_info);
......@@ -168,9 +168,9 @@ class CompilationCacheRegExp: public CompilationSubCache {
JSRegExp::Flags flags,
Handle<FixedArray> data);
private:
MUST_USE_RESULT Object* TryTablePut(Handle<String> source,
JSRegExp::Flags flags,
Handle<FixedArray> data);
MUST_USE_RESULT MaybeObject* TryTablePut(Handle<String> source,
JSRegExp::Flags flags,
Handle<FixedArray> data);
// Note: Returns a new hash table if operation results in expansion.
Handle<CompilationCacheTable> TablePut(Handle<String> source,
......@@ -333,7 +333,7 @@ Handle<SharedFunctionInfo> CompilationCacheScript::Lookup(Handle<String> source,
}
Object* CompilationCacheScript::TryTablePut(
MaybeObject* CompilationCacheScript::TryTablePut(
Handle<String> source,
Handle<SharedFunctionInfo> function_info) {
Handle<CompilationCacheTable> table = GetFirstTable();
......@@ -386,7 +386,7 @@ Handle<SharedFunctionInfo> CompilationCacheEval::Lookup(
}
Object* CompilationCacheEval::TryTablePut(
MaybeObject* CompilationCacheEval::TryTablePut(
Handle<String> source,
Handle<Context> context,
Handle<SharedFunctionInfo> function_info) {
......@@ -442,7 +442,7 @@ Handle<FixedArray> CompilationCacheRegExp::Lookup(Handle<String> source,
}
Object* CompilationCacheRegExp::TryTablePut(
MaybeObject* CompilationCacheRegExp::TryTablePut(
Handle<String> source,
JSRegExp::Flags flags,
Handle<FixedArray> data) {
......
......@@ -1038,7 +1038,7 @@ bool Debug::CheckBreakPoint(Handle<Object> break_point_object) {
Factory::LookupAsciiSymbol("IsBreakPointTriggered");
Handle<JSFunction> check_break_point =
Handle<JSFunction>(JSFunction::cast(
debug_context()->global()->GetProperty(
debug_context()->global()->GetPropertyNoExceptionThrown(
*is_break_point_triggered_symbol)));
// Get the break id as an object.
......@@ -1847,7 +1847,8 @@ void Debug::ClearMirrorCache() {
// Clear the mirror cache.
Handle<String> function_name =
Factory::LookupSymbol(CStrVector("ClearMirrorCache"));
Handle<Object> fun(Top::global()->GetProperty(*function_name));
Handle<Object> fun(Top::global()->GetPropertyNoExceptionThrown(
*function_name));
ASSERT(fun->IsJSFunction());
bool caught_exception;
Handle<Object> js_object = Execution::TryCall(
......@@ -1954,7 +1955,8 @@ Handle<Object> Debugger::MakeJSObject(Vector<const char> constructor_name,
// Create the execution state object.
Handle<String> constructor_str = Factory::LookupSymbol(constructor_name);
Handle<Object> constructor(Top::global()->GetProperty(*constructor_str));
Handle<Object> constructor(Top::global()->GetPropertyNoExceptionThrown(
*constructor_str));
ASSERT(constructor->IsJSFunction());
if (!constructor->IsJSFunction()) {
*caught_exception = true;
......@@ -2181,8 +2183,8 @@ void Debugger::OnAfterCompile(Handle<Script> script,
Handle<String> update_script_break_points_symbol =
Factory::LookupAsciiSymbol("UpdateScriptBreakPoints");
Handle<Object> update_script_break_points =
Handle<Object>(Debug::debug_context()->global()->GetProperty(
*update_script_break_points_symbol));
Handle<Object>(Debug::debug_context()->global()->
GetPropertyNoExceptionThrown(*update_script_break_points_symbol));
if (!update_script_break_points->IsJSFunction()) {
return;
}
......
......@@ -50,7 +50,7 @@ static Handle<Object> Invoke(bool construct,
VMState state(JS);
// Placeholder for return value.
Object* value = reinterpret_cast<Object*>(kZapValue);
MaybeObject* value = reinterpret_cast<Object*>(kZapValue);
typedef Object* (*JSEntryFunction)(
byte* entry,
......@@ -109,7 +109,7 @@ static Handle<Object> Invoke(bool construct,
Top::clear_pending_message();
}
return Handle<Object>(value);
return Handle<Object>(value->ToObjectUnchecked());
}
......@@ -172,7 +172,17 @@ Handle<Object> Execution::GetFunctionDelegate(Handle<Object> object) {
// and Safari so we allow it too.
if (object->IsJSRegExp()) {
Handle<String> exec = Factory::exec_symbol();
return Handle<Object>(object->GetProperty(*exec));
// TODO(lrn): Bug 617. We should use the default function here, not the
// one on the RegExp object.
Object* exec_function;
{ MaybeObject* maybe_exec_function = object->GetProperty(*exec);
// This can lose an exception, but the alternative is to put a failure
// object in a handle, which is not GC safe.
if (!maybe_exec_function->ToObject(&exec_function)) {
return Factory::undefined_value();
}
}
return Handle<Object>(exec_function);
}
// Objects created through the API can have an instance-call handler
......@@ -517,8 +527,8 @@ Handle<JSFunction> Execution::InstantiateFunction(
Handle<FunctionTemplateInfo> data, bool* exc) {
// Fast case: see if the function has already been instantiated
int serial_number = Smi::cast(data->serial_number())->value();
Object* elm =
Top::global_context()->function_cache()->GetElement(serial_number);
Object* elm = Top::global_context()->function_cache()->
GetElementNoExceptionThrown(serial_number);
if (elm->IsJSFunction()) return Handle<JSFunction>(JSFunction::cast(elm));
// The function has not yet been instantiated in this context; do it.
Object** args[1] = { Handle<Object>::cast(data).location() };
......@@ -671,7 +681,7 @@ void Execution::ProcessDebugMesssages(bool debug_command_only) {
#endif
Object* Execution::HandleStackGuardInterrupt() {
MaybeObject* Execution::HandleStackGuardInterrupt() {
#ifdef ENABLE_DEBUGGER_SUPPORT
if (StackGuard::IsDebugBreak() || StackGuard::IsDebugCommand()) {
DebugBreakHelper();
......
......@@ -132,7 +132,7 @@ class Execution : public AllStatic {
// If the stack guard is triggered, but it is not an actual
// stack overflow, then handle the interruption accordingly.
static Object* HandleStackGuardInterrupt();
MUST_USE_RESULT static MaybeObject* HandleStackGuardInterrupt();
// Get a function delegate (or undefined) for the given non-function
// object. Used for support calling objects as functions.
......
......@@ -431,7 +431,8 @@ Handle<Object> Factory::NewError(const char* maker,
const char* type,
Handle<JSArray> args) {
Handle<String> make_str = Factory::LookupAsciiSymbol(maker);
Handle<Object> fun_obj(Top::builtins()->GetProperty(*make_str));
Handle<Object> fun_obj(Top::builtins()->GetPropertyNoExceptionThrown(
*make_str));
// If the builtins haven't been properly configured yet this error
// constructor may not have been defined. Bail out.
if (!fun_obj->IsJSFunction())
......@@ -464,7 +465,7 @@ Handle<Object> Factory::NewError(const char* constructor,
Handle<JSFunction> fun =
Handle<JSFunction>(
JSFunction::cast(
Top::builtins()->GetProperty(*constr)));
Top::builtins()->GetPropertyNoExceptionThrown(*constr)));
Object** argv[1] = { Handle<Object>::cast(message).location() };
// Invoke the JavaScript factory method. If an exception is thrown while
......@@ -567,12 +568,13 @@ Handle<Code> Factory::CopyCode(Handle<Code> code, Vector<byte> reloc_info) {
}
static inline Object* DoCopyInsert(DescriptorArray* array,
String* key,
Object* value,
PropertyAttributes attributes) {
MUST_USE_RESULT static inline MaybeObject* DoCopyInsert(
DescriptorArray* array,
String* key,
Object* value,
PropertyAttributes attributes) {
CallbacksDescriptor desc(key, value, attributes);
Object* obj = array->CopyInsert(&desc, REMOVE_TRANSITIONS);
MaybeObject* obj = array->CopyInsert(&desc, REMOVE_TRANSITIONS);
return obj;
}
......@@ -921,11 +923,15 @@ Handle<MapCache> Factory::NewMapCache(int at_least_space_for) {
}
static Object* UpdateMapCacheWith(Context* context,
FixedArray* keys,
Map* map) {
Object* result = MapCache::cast(context->map_cache())->Put(keys, map);
if (!result->IsFailure()) context->set_map_cache(MapCache::cast(result));
MUST_USE_RESULT static MaybeObject* UpdateMapCacheWith(Context* context,
FixedArray* keys,
Map* map) {
Object* result;
{ MaybeObject* maybe_result =
MapCache::cast(context->map_cache())->Put(keys, map);
if (!maybe_result->ToObject(&result)) return maybe_result;
}
context->set_map_cache(MapCache::cast(result));
return result;
}
......
......@@ -324,6 +324,7 @@ class MarkCompactCollector;
class NewSpace;
class NodeVisitor;
class Object;
class MaybeObject;
class OldSpace;
class Property;
class Proxy;
......@@ -542,8 +543,8 @@ union IeeeDoubleBigEndianArchType {
// AccessorCallback
struct AccessorDescriptor {
Object* (*getter)(Object* object, void* data);
Object* (*setter)(JSObject* object, Object* value, void* data);
MaybeObject* (*getter)(Object* object, void* data);
MaybeObject* (*setter)(JSObject* object, Object* value, void* data);
void* data;
};
......
......@@ -40,23 +40,23 @@ int Heap::MaxObjectSizeInPagedSpace() {
}
Object* Heap::AllocateSymbol(Vector<const char> str,
int chars,
uint32_t hash_field) {
MaybeObject* Heap::AllocateSymbol(Vector<const char> str,
int chars,
uint32_t hash_field) {
unibrow::Utf8InputBuffer<> buffer(str.start(),
static_cast<unsigned>(str.length()));
return AllocateInternalSymbol(&buffer, chars, hash_field);
}
Object* Heap::CopyFixedArray(FixedArray* src) {
MaybeObject* Heap::CopyFixedArray(FixedArray* src) {
return CopyFixedArrayWithMap(src, src->map());
}
Object* Heap::AllocateRaw(int size_in_bytes,
AllocationSpace space,
AllocationSpace retry_space) {
MaybeObject* Heap::AllocateRaw(int size_in_bytes,
AllocationSpace space,
AllocationSpace retry_space) {
ASSERT(allocation_allowed_ && gc_state_ == NOT_IN_GC);
ASSERT(space != NEW_SPACE ||
retry_space == OLD_POINTER_SPACE ||
......@@ -71,7 +71,7 @@ Object* Heap::AllocateRaw(int size_in_bytes,
Counters::objs_since_last_full.Increment();
Counters::objs_since_last_young.Increment();
#endif
Object* result;
MaybeObject* result;
if (NEW_SPACE == space) {
result = new_space_.AllocateRaw(size_in_bytes);
if (always_allocate() && result->IsFailure()) {
......@@ -100,14 +100,14 @@ Object* Heap::AllocateRaw(int size_in_bytes,
}
Object* Heap::NumberFromInt32(int32_t value) {
MaybeObject* Heap::NumberFromInt32(int32_t value) {
if (Smi::IsValid(value)) return Smi::FromInt(value);
// Bypass NumberFromDouble to avoid various redundant checks.
return AllocateHeapNumber(FastI2D(value));
}
Object* Heap::NumberFromUint32(uint32_t value) {
MaybeObject* Heap::NumberFromUint32(uint32_t value) {
if ((int32_t)value >= 0 && Smi::IsValid((int32_t)value)) {
return Smi::FromInt((int32_t)value);
}
......@@ -134,12 +134,12 @@ void Heap::FinalizeExternalString(String* string) {
}
Object* Heap::AllocateRawMap() {
MaybeObject* Heap::AllocateRawMap() {
#ifdef DEBUG
Counters::objs_since_last_full.Increment();
Counters::objs_since_last_young.Increment();
#endif
Object* result = map_space_->AllocateRaw(Map::kSize);
MaybeObject* result = map_space_->AllocateRaw(Map::kSize);
if (result->IsFailure()) old_gen_exhausted_ = true;
#ifdef DEBUG
if (!result->IsFailure()) {
......@@ -152,12 +152,12 @@ Object* Heap::AllocateRawMap() {
}
Object* Heap::AllocateRawCell() {
MaybeObject* Heap::AllocateRawCell() {
#ifdef DEBUG
Counters::objs_since_last_full.Increment();
Counters::objs_since_last_young.Increment();
#endif
Object* result = cell_space_->AllocateRaw(JSGlobalPropertyCell::kSize);
MaybeObject* result = cell_space_->AllocateRaw(JSGlobalPropertyCell::kSize);
if (result->IsFailure()) old_gen_exhausted_ = true;
return result;
}
......@@ -330,14 +330,14 @@ void Heap::ScavengeObject(HeapObject** p, HeapObject* object) {
}
Object* Heap::PrepareForCompare(String* str) {
MaybeObject* Heap::PrepareForCompare(String* str) {
// Always flatten small strings and force flattening of long strings
// after we have accumulated a certain amount we failed to flatten.
static const int kMaxAlwaysFlattenLength = 32;
static const int kFlattenLongThreshold = 16*KB;
const int length = str->length();
Object* obj = str->TryFlatten();
MaybeObject* obj = str->TryFlatten();
if (length <= kMaxAlwaysFlattenLength ||
unflattened_strings_length_ >= kFlattenLongThreshold) {
return obj;
......@@ -391,34 +391,36 @@ void Heap::SetLastScriptId(Object* last_script_id) {
// to guarantee that any allocations performed during the call will
// succeed if there's enough memory.
// Warning: Do not use the identifiers __object__ or __scope__ in a
// call to this macro.
// Warning: Do not use the identifiers __object__, __maybe_object__ or
// __scope__ in a call to this macro.
#define CALL_AND_RETRY(FUNCTION_CALL, RETURN_VALUE, RETURN_EMPTY) \
do { \
GC_GREEDY_CHECK(); \
Object* __object__ = FUNCTION_CALL; \
if (!__object__->IsFailure()) RETURN_VALUE; \
if (__object__->IsOutOfMemoryFailure()) { \
MaybeObject* __maybe_object__ = FUNCTION_CALL; \
Object* __object__ = NULL; \
if (__maybe_object__->ToObject(&__object__)) RETURN_VALUE; \
if (__maybe_object__->IsOutOfMemory()) { \
v8::internal::V8::FatalProcessOutOfMemory("CALL_AND_RETRY_0", true);\
} \
if (!__object__->IsRetryAfterGC()) RETURN_EMPTY; \
Heap::CollectGarbage(Failure::cast(__object__)->allocation_space()); \
__object__ = FUNCTION_CALL; \
if (!__object__->IsFailure()) RETURN_VALUE; \
if (__object__->IsOutOfMemoryFailure()) { \
if (!__maybe_object__->IsRetryAfterGC()) RETURN_EMPTY; \
Heap::CollectGarbage(Failure::cast(__maybe_object__)-> \
allocation_space()); \
__maybe_object__ = FUNCTION_CALL; \
if (__maybe_object__->ToObject(&__object__)) RETURN_VALUE; \
if (__maybe_object__->IsOutOfMemory()) { \
v8::internal::V8::FatalProcessOutOfMemory("CALL_AND_RETRY_1", true);\
} \
if (!__object__->IsRetryAfterGC()) RETURN_EMPTY; \
if (!__maybe_object__->IsRetryAfterGC()) RETURN_EMPTY; \
Counters::gc_last_resort_from_handles.Increment(); \
Heap::CollectAllGarbage(false); \
{ \
AlwaysAllocateScope __scope__; \
__object__ = FUNCTION_CALL; \
__maybe_object__ = FUNCTION_CALL; \
} \
if (!__object__->IsFailure()) RETURN_VALUE; \
if (__object__->IsOutOfMemoryFailure() || \
__object__->IsRetryAfterGC()) { \
if (__maybe_object__->ToObject(&__object__)) RETURN_VALUE; \
if (__maybe_object__->IsOutOfMemory() || \
__maybe_object__->IsRetryAfterGC()) { \
/* TODO(1181417): Fix this. */ \
v8::internal::V8::FatalProcessOutOfMemory("CALL_AND_RETRY_2", true);\
} \
......
This diff is collapsed.
This diff is collapsed.
......@@ -120,10 +120,15 @@ void CpuFeatures::Probe() {
CodeDesc desc;
assm.GetCode(&desc);
Object* code = Heap::CreateCode(desc,
Code::ComputeFlags(Code::STUB),
Handle<Code>::null());
Object* code;
{ MaybeObject* maybe_code = Heap::CreateCode(desc,
Code::ComputeFlags(Code::STUB),
Handle<Code>::null());
if (!maybe_code->ToObject(&code)) return;
}
if (!code->IsCode()) return;
PROFILE(CodeCreateEvent(Logger::BUILTIN_TAG,
Code::cast(code), "CpuFeatures::Probe"));
typedef uint64_t (*F0)();
......
......@@ -976,12 +976,13 @@ void MacroAssembler::CallStub(CodeStub* stub) {
}
Object* MacroAssembler::TryCallStub(CodeStub* stub) {
MaybeObject* MacroAssembler::TryCallStub(CodeStub* stub) {
ASSERT(allow_stub_calls()); // Calls are not allowed in some stubs.
Object* result = stub->TryGetCode();
if (!result->IsFailure()) {
call(Handle<Code>(Code::cast(result)), RelocInfo::CODE_TARGET);
Object* result;
{ MaybeObject* maybe_result = stub->TryGetCode();
if (!maybe_result->ToObject(&result)) return maybe_result;
}
call(Handle<Code>(Code::cast(result)), RelocInfo::CODE_TARGET);
return result;
}
......@@ -992,12 +993,13 @@ void MacroAssembler::TailCallStub(CodeStub* stub) {
}
Object* MacroAssembler::TryTailCallStub(CodeStub* stub) {
MaybeObject* MacroAssembler::TryTailCallStub(CodeStub* stub) {
ASSERT(allow_stub_calls()); // Calls are not allowed in some stubs.
Object* result = stub->TryGetCode();
if (!result->IsFailure()) {
jmp(Handle<Code>(Code::cast(result)), RelocInfo::CODE_TARGET);
Object* result;
{ MaybeObject* maybe_result = stub->TryGetCode();
if (!maybe_result->ToObject(&result)) return maybe_result;
}
jmp(Handle<Code>(Code::cast(result)), RelocInfo::CODE_TARGET);
return result;
}
......@@ -1040,8 +1042,8 @@ void MacroAssembler::CallRuntime(Runtime::FunctionId id, int num_arguments) {
}
Object* MacroAssembler::TryCallRuntime(Runtime::FunctionId id,
int num_arguments) {
MaybeObject* MacroAssembler::TryCallRuntime(Runtime::FunctionId id,
int num_arguments) {
return TryCallRuntime(Runtime::FunctionForId(id), num_arguments);
}
......@@ -1066,8 +1068,8 @@ void MacroAssembler::CallRuntime(Runtime::Function* f, int num_arguments) {
}
Object* MacroAssembler::TryCallRuntime(Runtime::Function* f,
int num_arguments) {
MaybeObject* MacroAssembler::TryCallRuntime(Runtime::Function* f,
int num_arguments) {
if (f->nargs >= 0 && f->nargs != num_arguments) {
IllegalOperation(num_arguments);
// Since we did not call the stub, there was no allocation failure.
......
......@@ -421,7 +421,7 @@ class MacroAssembler: public Assembler {
// Call a code stub and return the code object called. Try to generate
// the code if necessary. Do not perform a GC but instead return a retry
// after GC failure.
Object* TryCallStub(CodeStub* stub);
MUST_USE_RESULT MaybeObject* TryCallStub(CodeStub* stub);
// Tail call a code stub (jump). Generate the code if necessary.
void TailCallStub(CodeStub* stub);
......@@ -429,7 +429,7 @@ class MacroAssembler: public Assembler {
// Tail call a code stub (jump) and return the code object called. Try to
// generate the code if necessary. Do not perform a GC but instead return
// a retry after GC failure.
Object* TryTailCallStub(CodeStub* stub);
MUST_USE_RESULT MaybeObject* TryTailCallStub(CodeStub* stub);
// Return from a code stub after popping its arguments.
void StubReturn(int argc);
......@@ -440,13 +440,15 @@ class MacroAssembler: public Assembler {
// Call a runtime function, returning the CodeStub object called.
// Try to generate the stub code if necessary. Do not perform a GC
// but instead return a retry after GC failure.
Object* TryCallRuntime(Runtime::Function* f, int num_arguments);
MUST_USE_RESULT MaybeObject* TryCallRuntime(Runtime::Function* f,
int num_arguments);
// Convenience function: Same as above, but takes the fid instead.
void CallRuntime(Runtime::FunctionId id, int num_arguments);
// Convenience function: Same as above, but takes the fid instead.
Object* TryCallRuntime(Runtime::FunctionId id, int num_arguments);
MUST_USE_RESULT MaybeObject* TryCallRuntime(Runtime::FunctionId id,
int num_arguments);
// Convenience function: call an external reference.
void CallExternalReference(ExternalReference ref, int num_arguments);
......@@ -597,9 +599,9 @@ class MacroAssembler: public Assembler {
// Helper for PopHandleScope. Allowed to perform a GC and returns
// NULL if gc_allowed. Does not perform a GC if !gc_allowed, and
// possibly returns a failure object indicating an allocation failure.
Object* PopHandleScopeHelper(Register saved,
Register scratch,
bool gc_allowed);
MUST_USE_RESULT MaybeObject* PopHandleScopeHelper(Register saved,
Register scratch,
bool gc_allowed);
};
......
......@@ -1067,7 +1067,7 @@ int RegExpMacroAssemblerIA32::CheckStackGuardState(Address* return_address,
ASSERT(*return_address <=
re_code->instruction_start() + re_code->instruction_size());
Object* result = Execution::HandleStackGuardInterrupt();
MaybeObject* result = Execution::HandleStackGuardInterrupt();
if (*code_handle != re_code) { // Return address no longer valid
int delta = *code_handle - re_code;
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -83,14 +83,15 @@ class LiveEdit : AllStatic {
static void WrapSharedFunctionInfos(Handle<JSArray> array);
static Object* ReplaceFunctionCode(Handle<JSArray> new_compile_info_array,
Handle<JSArray> shared_info_array);
MUST_USE_RESULT static MaybeObject* ReplaceFunctionCode(
Handle<JSArray> new_compile_info_array,
Handle<JSArray> shared_info_array);
// Updates script field in FunctionSharedInfo.
static void SetFunctionScript(Handle<JSValue> function_wrapper,
Handle<Object> script_handle);
static Object* PatchFunctionPositions(
MUST_USE_RESULT static MaybeObject* PatchFunctionPositions(
Handle<JSArray> shared_info_array, Handle<JSArray> position_change_array);
// For a script updates its source field. If old_script_name is provided
......
......@@ -559,7 +559,12 @@ void Logger::LogRuntime(Vector<const char> format, JSArray* args) {
if (c == '%' && i <= format.length() - 2) {
i++;
ASSERT('0' <= format[i] && format[i] <= '9');
Object* obj = args->GetElement(format[i] - '0');
MaybeObject* maybe = args->GetElement(format[i] - '0');
Object* obj;
if (!maybe->ToObject(&obj)) {
msg.Append("<exception>");
continue;
}
i++;
switch (format[i]) {
case 's':
......
This diff is collapsed.
......@@ -53,7 +53,8 @@ class MarkCompactCollector: public AllStatic {
// Object* that will be the object after forwarding. There is a separate
// allocation function for each (compactable) space based on the location
// of the object before compaction.
typedef Object* (*AllocationFunction)(HeapObject* object, int object_size);
typedef MaybeObject* (*AllocationFunction)(HeapObject* object,
int object_size);
// Type of functions to encode the forwarding address for an object.
// Given the object, its size, and the new (non-failure) object it will be
......
......@@ -152,8 +152,8 @@ void MessageHandler::ReportMessage(MessageLocation* loc,
Handle<String> MessageHandler::GetMessage(Handle<Object> data) {
Handle<String> fmt_str = Factory::LookupAsciiSymbol("FormatMessage");
Handle<JSFunction> fun =
Handle<JSFunction>(
JSFunction::cast(Top::builtins()->GetProperty(*fmt_str)));
Handle<JSFunction>(JSFunction::cast(
Top::builtins()->GetPropertyNoExceptionThrown(*fmt_str)));
Object** argv[1] = { data.location() };
bool caught_exception;
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -4266,11 +4266,9 @@ Expression* Parser::NewThrowError(Handle<String> constructor,
for (int i = 0; i < argc; i++) {
Handle<Object> element = arguments[i];
if (!element.is_null()) {
Object* ok = array->SetFastElement(i, *element);
USE(ok); // Don't get an unused variable warning.
// We know this doesn't cause a GC here because we allocated the JSArray
// large enough.
ASSERT(!ok->IsFailure());
array->SetFastElement(i, *element)->ToObjectUnchecked();
}
}
ZoneList<Expression*>* args = new ZoneList<Expression*>(2);
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment