Remove uses of MaybeObject in runtime.cc.

R=ulan@chromium.org

Review URL: https://codereview.chromium.org/240253003

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20828 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
yangguo@chromium.org 2014-04-17 05:41:58 +00:00
parent ec73d3db09
commit 556aea63fd
3 changed files with 119 additions and 103 deletions

View File

@ -866,11 +866,12 @@ static Handle<SharedFunctionInfo> CompileToplevel(CompilationInfo* info) {
} }
Handle<JSFunction> Compiler::GetFunctionFromEval(Handle<String> source, MaybeHandle<JSFunction> Compiler::GetFunctionFromEval(
Handle<Context> context, Handle<String> source,
StrictMode strict_mode, Handle<Context> context,
ParseRestriction restriction, StrictMode strict_mode,
int scope_position) { ParseRestriction restriction,
int scope_position) {
Isolate* isolate = source->GetIsolate(); Isolate* isolate = source->GetIsolate();
int source_length = source->length(); int source_length = source->length();
isolate->counters()->total_eval_size()->Increment(source_length); isolate->counters()->total_eval_size()->Increment(source_length);
@ -898,7 +899,7 @@ Handle<JSFunction> Compiler::GetFunctionFromEval(Handle<String> source,
shared_info = CompileToplevel(&info); shared_info = CompileToplevel(&info);
if (shared_info.is_null()) { if (shared_info.is_null()) {
return Handle<JSFunction>::null(); return MaybeHandle<JSFunction>();
} else { } else {
// Explicitly disable optimization for eval code. We're not yet prepared // Explicitly disable optimization for eval code. We're not yet prepared
// to handle eval-code in the optimizing compiler. // to handle eval-code in the optimizing compiler.

View File

@ -626,11 +626,12 @@ class Compiler : public AllStatic {
#endif #endif
// Compile a String source within a context for eval. // Compile a String source within a context for eval.
static Handle<JSFunction> GetFunctionFromEval(Handle<String> source, MUST_USE_RESULT static MaybeHandle<JSFunction> GetFunctionFromEval(
Handle<Context> context, Handle<String> source,
StrictMode strict_mode, Handle<Context> context,
ParseRestriction restriction, StrictMode strict_mode,
int scope_position); ParseRestriction restriction,
int scope_position);
// Compile a String source within a context. // Compile a String source within a context.
static Handle<SharedFunctionInfo> CompileScript( static Handle<SharedFunctionInfo> CompileScript(

View File

@ -7045,6 +7045,7 @@ static inline void StringBuilderConcatHelper(String* special,
sinkchar* sink, sinkchar* sink,
FixedArray* fixed_array, FixedArray* fixed_array,
int array_length) { int array_length) {
DisallowHeapAllocation no_gc;
int position = 0; int position = 0;
for (int i = 0; i < array_length; i++) { for (int i = 0; i < array_length; i++) {
Object* element = fixed_array->get(i); Object* element = fixed_array->get(i);
@ -7079,36 +7080,13 @@ static inline void StringBuilderConcatHelper(String* special,
} }
RUNTIME_FUNCTION(MaybeObject*, Runtime_StringBuilderConcat) { // Returns the result length of the concatenation.
HandleScope scope(isolate); // On illegal argument, -1 is returned.
ASSERT(args.length() == 3); static inline int StringBuilderConcatLength(int special_length,
CONVERT_ARG_HANDLE_CHECKED(JSArray, array, 0); FixedArray* fixed_array,
if (!args[1]->IsSmi()) return isolate->ThrowInvalidStringLength(); int array_length,
int array_length = args.smi_at(1); bool* one_byte) {
CONVERT_ARG_HANDLE_CHECKED(String, special, 2); DisallowHeapAllocation no_gc;
// This assumption is used by the slice encoding in one or two smis.
ASSERT(Smi::kMaxValue >= String::kMaxLength);
JSObject::EnsureCanContainHeapObjectElements(array);
int special_length = special->length();
if (!array->HasFastObjectElements()) {
return isolate->Throw(isolate->heap()->illegal_argument_string());
}
FixedArray* fixed_array = FixedArray::cast(array->elements());
if (fixed_array->length() < array_length) {
array_length = fixed_array->length();
}
if (array_length == 0) {
return isolate->heap()->empty_string();
} else if (array_length == 1) {
Object* first = fixed_array->get(0);
if (first->IsString()) return first;
}
bool one_byte = special->HasOnlyOneByteChars();
int position = 0; int position = 0;
for (int i = 0; i < array_length; i++) { for (int i = 0; i < array_length; i++) {
int increment = 0; int increment = 0;
@ -7127,66 +7105,97 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_StringBuilderConcat) {
len = -smi_value; len = -smi_value;
// Get the position and check that it is a positive smi. // Get the position and check that it is a positive smi.
i++; i++;
if (i >= array_length) { if (i >= array_length) return -1;
return isolate->Throw(isolate->heap()->illegal_argument_string());
}
Object* next_smi = fixed_array->get(i); Object* next_smi = fixed_array->get(i);
if (!next_smi->IsSmi()) { if (!next_smi->IsSmi()) return -1;
return isolate->Throw(isolate->heap()->illegal_argument_string());
}
pos = Smi::cast(next_smi)->value(); pos = Smi::cast(next_smi)->value();
if (pos < 0) { if (pos < 0) return -1;
return isolate->Throw(isolate->heap()->illegal_argument_string());
}
} }
ASSERT(pos >= 0); ASSERT(pos >= 0);
ASSERT(len >= 0); ASSERT(len >= 0);
if (pos > special_length || len > special_length - pos) { if (pos > special_length || len > special_length - pos) return -1;
return isolate->Throw(isolate->heap()->illegal_argument_string());
}
increment = len; increment = len;
} else if (elt->IsString()) { } else if (elt->IsString()) {
String* element = String::cast(elt); String* element = String::cast(elt);
int element_length = element->length(); int element_length = element->length();
increment = element_length; increment = element_length;
if (one_byte && !element->HasOnlyOneByteChars()) { if (*one_byte && !element->HasOnlyOneByteChars()) {
one_byte = false; *one_byte = false;
} }
} else { } else {
ASSERT(!elt->IsTheHole()); ASSERT(!elt->IsTheHole());
return isolate->Throw(isolate->heap()->illegal_argument_string()); return -1;
} }
if (increment > String::kMaxLength - position) { if (increment > String::kMaxLength - position) {
return isolate->ThrowInvalidStringLength(); return kMaxInt; // Provoke throw on allocation.
} }
position += increment; position += increment;
} }
return position;
}
int length = position;
Object* object; RUNTIME_FUNCTION(MaybeObject*, Runtime_StringBuilderConcat) {
HandleScope scope(isolate);
ASSERT(args.length() == 3);
CONVERT_ARG_HANDLE_CHECKED(JSArray, array, 0);
if (!args[1]->IsSmi()) return isolate->ThrowInvalidStringLength();
int array_length = args.smi_at(1);
CONVERT_ARG_HANDLE_CHECKED(String, special, 2);
// This assumption is used by the slice encoding in one or two smis.
ASSERT(Smi::kMaxValue >= String::kMaxLength);
JSObject::EnsureCanContainHeapObjectElements(array);
int special_length = special->length();
if (!array->HasFastObjectElements()) {
return isolate->Throw(isolate->heap()->illegal_argument_string());
}
int length;
bool one_byte = special->HasOnlyOneByteChars();
{ DisallowHeapAllocation no_gc;
FixedArray* fixed_array = FixedArray::cast(array->elements());
if (fixed_array->length() < array_length) {
array_length = fixed_array->length();
}
if (array_length == 0) {
return isolate->heap()->empty_string();
} else if (array_length == 1) {
Object* first = fixed_array->get(0);
if (first->IsString()) return first;
}
length = StringBuilderConcatLength(
special_length, fixed_array, array_length, &one_byte);
}
if (length == -1) {
return isolate->Throw(isolate->heap()->illegal_argument_string());
}
if (one_byte) { if (one_byte) {
{ MaybeObject* maybe_object = Handle<SeqOneByteString> answer;
isolate->heap()->AllocateRawOneByteString(length); ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
if (!maybe_object->ToObject(&object)) return maybe_object; isolate, answer,
} isolate->factory()->NewRawOneByteString(length));
SeqOneByteString* answer = SeqOneByteString::cast(object);
StringBuilderConcatHelper(*special, StringBuilderConcatHelper(*special,
answer->GetChars(), answer->GetChars(),
fixed_array, FixedArray::cast(array->elements()),
array_length); array_length);
return answer; return *answer;
} else { } else {
{ MaybeObject* maybe_object = Handle<SeqTwoByteString> answer;
isolate->heap()->AllocateRawTwoByteString(length); ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
if (!maybe_object->ToObject(&object)) return maybe_object; isolate, answer,
} isolate->factory()->NewRawTwoByteString(length));
SeqTwoByteString* answer = SeqTwoByteString::cast(object);
StringBuilderConcatHelper(*special, StringBuilderConcatHelper(*special,
answer->GetChars(), answer->GetChars(),
fixed_array, FixedArray::cast(array->elements()),
array_length); array_length);
return answer; return *answer;
} }
} }
@ -8814,10 +8823,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_Call) {
} }
for (int i = 0; i < argc; ++i) { for (int i = 0; i < argc; ++i) {
MaybeObject* maybe = args[1 + i]; argv[i] = Handle<Object>(args[1 + i], isolate);
Object* object;
if (!maybe->To<Object>(&object)) return maybe;
argv[i] = Handle<Object>(object, isolate);
} }
Handle<JSReceiver> hfun(fun); Handle<JSReceiver> hfun(fun);
@ -9716,9 +9722,11 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_CompileString) {
// Compile source string in the native context. // Compile source string in the native context.
ParseRestriction restriction = function_literal_only ParseRestriction restriction = function_literal_only
? ONLY_SINGLE_FUNCTION_LITERAL : NO_PARSE_RESTRICTION; ? ONLY_SINGLE_FUNCTION_LITERAL : NO_PARSE_RESTRICTION;
Handle<JSFunction> fun = Compiler::GetFunctionFromEval( Handle<JSFunction> fun;
source, context, SLOPPY, restriction, RelocInfo::kNoPosition); ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
RETURN_IF_EMPTY_HANDLE(isolate, fun); isolate, fun,
Compiler::GetFunctionFromEval(
source, context, SLOPPY, restriction, RelocInfo::kNoPosition));
return *fun; return *fun;
} }
@ -9745,10 +9753,12 @@ static ObjectPair CompileGlobalEval(Isolate* isolate,
// Deal with a normal eval call with a string argument. Compile it // Deal with a normal eval call with a string argument. Compile it
// and return the compiled function bound in the local context. // and return the compiled function bound in the local context.
static const ParseRestriction restriction = NO_PARSE_RESTRICTION; static const ParseRestriction restriction = NO_PARSE_RESTRICTION;
Handle<JSFunction> compiled = Compiler::GetFunctionFromEval( Handle<JSFunction> compiled;
source, context, strict_mode, restriction, scope_position); ASSIGN_RETURN_ON_EXCEPTION_VALUE(
RETURN_IF_EMPTY_HANDLE_VALUE(isolate, compiled, isolate, compiled,
MakePair(Failure::Exception(), NULL)); Compiler::GetFunctionFromEval(
source, context, strict_mode, restriction, scope_position),
MakePair(Failure::Exception(), NULL));
return MakePair(*compiled, *receiver); return MakePair(*compiled, *receiver);
} }
@ -12771,29 +12781,32 @@ MUST_USE_RESULT static MaybeHandle<JSObject> MaterializeArgumentsObject(
// Compile and evaluate source for the given context. // Compile and evaluate source for the given context.
static MaybeObject* DebugEvaluate(Isolate* isolate, static MaybeHandle<Object> DebugEvaluate(Isolate* isolate,
Handle<Context> context, Handle<Context> context,
Handle<Object> context_extension, Handle<Object> context_extension,
Handle<Object> receiver, Handle<Object> receiver,
Handle<String> source) { Handle<String> source) {
if (context_extension->IsJSObject()) { if (context_extension->IsJSObject()) {
Handle<JSObject> extension = Handle<JSObject>::cast(context_extension); Handle<JSObject> extension = Handle<JSObject>::cast(context_extension);
Handle<JSFunction> closure(context->closure(), isolate); Handle<JSFunction> closure(context->closure(), isolate);
context = isolate->factory()->NewWithContext(closure, context, extension); context = isolate->factory()->NewWithContext(closure, context, extension);
} }
Handle<JSFunction> eval_fun = Handle<JSFunction> eval_fun;
ASSIGN_RETURN_ON_EXCEPTION(
isolate, eval_fun,
Compiler::GetFunctionFromEval(source, Compiler::GetFunctionFromEval(source,
context, context,
SLOPPY, SLOPPY,
NO_PARSE_RESTRICTION, NO_PARSE_RESTRICTION,
RelocInfo::kNoPosition); RelocInfo::kNoPosition),
RETURN_IF_EMPTY_HANDLE(isolate, eval_fun); Object);
Handle<Object> result; Handle<Object> result;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION( ASSIGN_RETURN_ON_EXCEPTION(
isolate, result, isolate, result,
Execution::Call(isolate, eval_fun, receiver, 0, NULL)); Execution::Call(isolate, eval_fun, receiver, 0, NULL),
Object);
// Skip the global proxy as it has no properties and always delegates to the // Skip the global proxy as it has no properties and always delegates to the
// real global object. // real global object.
@ -12803,7 +12816,7 @@ static MaybeObject* DebugEvaluate(Isolate* isolate,
// Clear the oneshot breakpoints so that the debugger does not step further. // Clear the oneshot breakpoints so that the debugger does not step further.
isolate->debug()->ClearStepping(); isolate->debug()->ClearStepping();
return *result; return result;
} }
@ -12867,13 +12880,10 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_DebugEvaluate) {
context = isolate->factory()->NewWithContext(function, context, materialized); context = isolate->factory()->NewWithContext(function, context, materialized);
Handle<Object> receiver(frame->receiver(), isolate); Handle<Object> receiver(frame->receiver(), isolate);
Object* evaluate_result_object; Handle<Object> result;
{ MaybeObject* maybe_result = ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
DebugEvaluate(isolate, context, context_extension, receiver, source); isolate, result,
if (!maybe_result->ToObject(&evaluate_result_object)) return maybe_result; DebugEvaluate(isolate, context, context_extension, receiver, source));
}
Handle<Object> result(evaluate_result_object, isolate);
// Write back potential changes to materialized stack locals to the stack. // Write back potential changes to materialized stack locals to the stack.
UpdateStackLocalsFromMaterializedObject( UpdateStackLocalsFromMaterializedObject(
@ -12915,7 +12925,11 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_DebugEvaluateGlobal) {
// debugger was invoked. // debugger was invoked.
Handle<Context> context = isolate->native_context(); Handle<Context> context = isolate->native_context();
Handle<Object> receiver = isolate->global_object(); Handle<Object> receiver = isolate->global_object();
return DebugEvaluate(isolate, context, context_extension, receiver, source); Handle<Object> result;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
isolate, result,
DebugEvaluate(isolate, context, context_extension, receiver, source));
return *result;
} }