From: mvstanton@chromium.org Date: Tue, 22 Apr 2014 14:55:47 +0000 (+0000) Subject: Use MaybeHandles in Compiler to indicate failure instead of a null Handle. X-Git-Tag: upstream/4.7.83~9496 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5600046f594d78be42cd94c571c1c8486e7b6b91;p=platform%2Fupstream%2Fv8.git Use MaybeHandles in Compiler to indicate failure instead of a null Handle. R=yangguo@chromium.org Review URL: https://codereview.chromium.org/246603003 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20890 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- diff --git a/src/builtins.cc b/src/builtins.cc index d74741e..f4ce991 100644 --- a/src/builtins.cc +++ b/src/builtins.cc @@ -529,7 +529,7 @@ BUILTIN(ArrayPop) { } Handle element; ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, element, maybe_element); - RETURN_IF_EMPTY_HANDLE( + RETURN_FAILURE_ON_EXCEPTION( isolate, accessor->SetLength(array, handle(Smi::FromInt(new_length), isolate))); return *element; diff --git a/src/compiler.cc b/src/compiler.cc index 6978da4..86e8f2f 100644 --- a/src/compiler.cc +++ b/src/compiler.cc @@ -637,13 +637,14 @@ static bool CompileUnoptimizedCode(CompilationInfo* info) { } -static Handle GetUnoptimizedCodeCommon(CompilationInfo* info) { +MUST_USE_RESULT static MaybeHandle GetUnoptimizedCodeCommon( + CompilationInfo* info) { VMState state(info->isolate()); PostponeInterruptsScope postpone(info->isolate()); - if (!Parser::Parse(info)) return Handle::null(); + if (!Parser::Parse(info)) return MaybeHandle(); info->SetStrictMode(info->function()->strict_mode()); - if (!CompileUnoptimizedCode(info)) return Handle::null(); + if (!CompileUnoptimizedCode(info)) return MaybeHandle(); Compiler::RecordFunctionCompilation( Logger::LAZY_COMPILE_TAG, info, info->shared_info()); UpdateSharedFunctionInfo(info); @@ -652,7 +653,7 @@ static Handle GetUnoptimizedCodeCommon(CompilationInfo* info) { } -Handle Compiler::GetUnoptimizedCode(Handle function) { +MaybeHandle Compiler::GetUnoptimizedCode(Handle function) { ASSERT(!function->GetIsolate()->has_pending_exception()); ASSERT(!function->is_compiled()); if (function->shared()->is_compiled()) { @@ -660,39 +661,43 @@ Handle Compiler::GetUnoptimizedCode(Handle function) { } CompilationInfoWithZone info(function); - Handle result = GetUnoptimizedCodeCommon(&info); - ASSERT_EQ(result.is_null(), info.isolate()->has_pending_exception()); + Handle result; + ASSIGN_RETURN_ON_EXCEPTION(info.isolate(), result, + GetUnoptimizedCodeCommon(&info), + Code); if (FLAG_always_opt && - !result.is_null() && info.isolate()->use_crankshaft() && !info.shared_info()->optimization_disabled() && !info.isolate()->DebuggerHasBreakPoints()) { - Handle opt_code = Compiler::GetOptimizedCode( - function, result, Compiler::NOT_CONCURRENT); - if (!opt_code.is_null()) result = opt_code; + Handle opt_code; + if (Compiler::GetOptimizedCode( + function, result, + Compiler::NOT_CONCURRENT).ToHandle(&opt_code)) { + result = opt_code; + } } return result; } -Handle Compiler::GetUnoptimizedCode(Handle shared) { +MaybeHandle Compiler::GetUnoptimizedCode( + Handle shared) { ASSERT(!shared->GetIsolate()->has_pending_exception()); ASSERT(!shared->is_compiled()); CompilationInfoWithZone info(shared); - Handle result = GetUnoptimizedCodeCommon(&info); - ASSERT_EQ(result.is_null(), info.isolate()->has_pending_exception()); - return result; + return GetUnoptimizedCodeCommon(&info); } bool Compiler::EnsureCompiled(Handle function, ClearExceptionFlag flag) { if (function->is_compiled()) return true; - Handle code = Compiler::GetUnoptimizedCode(function); - if (code.is_null()) { + MaybeHandle maybe_code = Compiler::GetUnoptimizedCode(function); + Handle code; + if (!maybe_code.ToHandle(&code)) { if (flag == CLEAR_EXCEPTION) { function->GetIsolate()->clear_pending_exception(); } @@ -713,7 +718,7 @@ bool Compiler::EnsureCompiled(Handle function, // full code without debug break slots to full code with debug break slots // depends on the generated code is otherwise exactly the same. // If compilation fails, just keep the existing code. -Handle Compiler::GetCodeForDebugging(Handle function) { +MaybeHandle Compiler::GetCodeForDebugging(Handle function) { CompilationInfoWithZone info(function); Isolate* isolate = info.isolate(); VMState state(isolate); @@ -729,14 +734,15 @@ Handle Compiler::GetCodeForDebugging(Handle function) { } else { info.MarkNonOptimizable(); } - Handle new_code = GetUnoptimizedCodeCommon(&info); - if (new_code.is_null()) { + MaybeHandle maybe_new_code = GetUnoptimizedCodeCommon(&info); + Handle new_code; + if (!maybe_new_code.ToHandle(&new_code)) { isolate->clear_pending_exception(); } else { ASSERT_EQ(old_code->is_compiled_optimizable(), new_code->is_compiled_optimizable()); } - return new_code; + return maybe_new_code; } @@ -1048,8 +1054,9 @@ Handle Compiler::BuildFunctionInfo(FunctionLiteral* literal, } -static Handle GetCodeFromOptimizedCodeMap(Handle function, - BailoutId osr_ast_id) { +MUST_USE_RESULT static MaybeHandle GetCodeFromOptimizedCodeMap( + Handle function, + BailoutId osr_ast_id) { if (FLAG_cache_optimized_code) { Handle shared(function->shared()); DisallowHeapAllocation no_gc; @@ -1069,7 +1076,7 @@ static Handle GetCodeFromOptimizedCodeMap(Handle function, return Handle(shared->GetCodeFromOptimizedCodeMap(index)); } } - return Handle::null(); + return MaybeHandle(); } @@ -1156,12 +1163,15 @@ static bool GetOptimizedCodeLater(CompilationInfo* info) { } -Handle Compiler::GetOptimizedCode(Handle function, - Handle current_code, - ConcurrencyMode mode, - BailoutId osr_ast_id) { - Handle cached_code = GetCodeFromOptimizedCodeMap(function, osr_ast_id); - if (!cached_code.is_null()) return cached_code; +MaybeHandle Compiler::GetOptimizedCode(Handle function, + Handle current_code, + ConcurrencyMode mode, + BailoutId osr_ast_id) { + Handle cached_code; + if (GetCodeFromOptimizedCodeMap( + function, osr_ast_id).ToHandle(&cached_code)) { + return cached_code; + } SmartPointer info(new CompilationInfoWithZone(function)); Isolate* isolate = info->isolate(); @@ -1194,7 +1204,7 @@ Handle Compiler::GetOptimizedCode(Handle function, } if (isolate->has_pending_exception()) isolate->clear_pending_exception(); - return Handle::null(); + return MaybeHandle(); } diff --git a/src/compiler.h b/src/compiler.h index f16dd59..ca49c79 100644 --- a/src/compiler.h +++ b/src/compiler.h @@ -615,11 +615,14 @@ class OptimizedCompileJob: public ZoneObject { class Compiler : public AllStatic { public: - static Handle GetUnoptimizedCode(Handle function); - static Handle GetUnoptimizedCode(Handle shared); + MUST_USE_RESULT static MaybeHandle GetUnoptimizedCode( + Handle function); + MUST_USE_RESULT static MaybeHandle GetUnoptimizedCode( + Handle shared); static bool EnsureCompiled(Handle function, ClearExceptionFlag flag); - static Handle GetCodeForDebugging(Handle function); + MUST_USE_RESULT static MaybeHandle GetCodeForDebugging( + Handle function); #ifdef ENABLE_DEBUGGER_SUPPORT static void CompileForLiveEdit(Handle