| Index: src/top.cc
|
| ===================================================================
|
| --- src/top.cc (revision 7031)
|
| +++ src/top.cc (working copy)
|
| @@ -192,15 +192,15 @@
|
| int limit = Max(frame_limit, 0);
|
| Handle<JSArray> stack_trace = factory()->NewJSArray(frame_limit);
|
|
|
| - Handle<String> column_key = factory()->LookupAsciiSymbol("column");
|
| - Handle<String> line_key = factory()->LookupAsciiSymbol("lineNumber");
|
| - Handle<String> script_key = factory()->LookupAsciiSymbol("scriptName");
|
| + Handle<String> column_key = factory()->LookupAsciiSymbol("column");
|
| + Handle<String> line_key = factory()->LookupAsciiSymbol("lineNumber");
|
| + Handle<String> script_key = factory()->LookupAsciiSymbol("scriptName");
|
| Handle<String> name_or_source_url_key =
|
| factory()->LookupAsciiSymbol("nameOrSourceURL");
|
| Handle<String> script_name_or_source_url_key =
|
| factory()->LookupAsciiSymbol("scriptNameOrSourceURL");
|
| - Handle<String> function_key = factory()->LookupAsciiSymbol("functionName");
|
| - Handle<String> eval_key = factory()->LookupAsciiSymbol("isEval");
|
| + Handle<String> function_key = factory()->LookupAsciiSymbol("functionName");
|
| + Handle<String> eval_key = factory()->LookupAsciiSymbol("isEval");
|
| Handle<String> constructor_key =
|
| factory()->LookupAsciiSymbol("isConstructor");
|
|
|
| @@ -234,16 +234,16 @@
|
| // tag.
|
| column_offset += script->column_offset()->value();
|
| }
|
| - SetProperty(stackFrame, column_key,
|
| - Handle<Smi>(Smi::FromInt(column_offset + 1), this), NONE);
|
| + SetLocalPropertyNoThrow(stackFrame, column_key,
|
| + Handle<Smi>(Smi::FromInt(column_offset + 1)));
|
| }
|
| - SetProperty(stackFrame, line_key,
|
| - Handle<Smi>(Smi::FromInt(line_number + 1), this), NONE);
|
| + SetLocalPropertyNoThrow(stackFrame, line_key,
|
| + Handle<Smi>(Smi::FromInt(line_number + 1)));
|
| }
|
|
|
| if (options & StackTrace::kScriptName) {
|
| Handle<Object> script_name(script->name(), this);
|
| - SetProperty(stackFrame, script_key, script_name, NONE);
|
| + SetLocalPropertyNoThrow(stackFrame, script_key, script_name);
|
| }
|
|
|
| if (options & StackTrace::kScriptNameOrSourceURL) {
|
| @@ -259,7 +259,8 @@
|
| if (caught_exception) {
|
| result = factory()->undefined_value();
|
| }
|
| - SetProperty(stackFrame, script_name_or_source_url_key, result, NONE);
|
| + SetLocalPropertyNoThrow(stackFrame, script_name_or_source_url_key,
|
| + result);
|
| }
|
|
|
| if (options & StackTrace::kFunctionName) {
|
| @@ -267,20 +268,20 @@
|
| if (fun_name->ToBoolean()->IsFalse()) {
|
| fun_name = Handle<Object>(fun->shared()->inferred_name(), this);
|
| }
|
| - SetProperty(stackFrame, function_key, fun_name, NONE);
|
| + SetLocalPropertyNoThrow(stackFrame, function_key, fun_name);
|
| }
|
|
|
| if (options & StackTrace::kIsEval) {
|
| int type = Smi::cast(script->compilation_type())->value();
|
| Handle<Object> is_eval = (type == Script::COMPILATION_TYPE_EVAL) ?
|
| factory()->true_value() : factory()->false_value();
|
| - SetProperty(stackFrame, eval_key, is_eval, NONE);
|
| + SetLocalPropertyNoThrow(stackFrame, eval_key, is_eval);
|
| }
|
|
|
| if (options & StackTrace::kIsConstructor) {
|
| Handle<Object> is_constructor = (frames[i].is_constructor()) ?
|
| factory()->true_value() : factory()->false_value();
|
| - SetProperty(stackFrame, constructor_key, is_constructor, NONE);
|
| + SetLocalPropertyNoThrow(stackFrame, constructor_key, is_constructor);
|
| }
|
|
|
| FixedArray::cast(stack_trace->elements())->set(frames_seen, *stackFrame);
|
| @@ -545,6 +546,12 @@
|
|
|
|
|
| Failure* Isolate::ReThrow(MaybeObject* exception, MessageLocation* location) {
|
| + bool can_be_caught_externally = false;
|
| + ShouldReportException(&can_be_caught_externally,
|
| + is_catchable_by_javascript(exception));
|
| + thread_local_top()->catcher_ = can_be_caught_externally ?
|
| + try_catch_handler() : NULL;
|
| +
|
| // Set the exception being re-thrown.
|
| set_pending_exception(exception);
|
| return Failure::Exception();
|
| @@ -620,7 +627,7 @@
|
| }
|
|
|
|
|
| -bool Isolate::ShouldReportException(bool* is_caught_externally,
|
| +bool Isolate::ShouldReportException(bool* can_be_caught_externally,
|
| bool catchable_by_javascript) {
|
| // Find the top-most try-catch handler.
|
| StackHandler* handler =
|
| @@ -637,13 +644,13 @@
|
| // The exception has been externally caught if and only if there is
|
| // an external handler which is on top of the top-most try-catch
|
| // handler.
|
| - *is_caught_externally = external_handler_address != NULL &&
|
| + *can_be_caught_externally = external_handler_address != NULL &&
|
| (handler == NULL || handler->address() > external_handler_address ||
|
| !catchable_by_javascript);
|
|
|
| - if (*is_caught_externally) {
|
| + if (*can_be_caught_externally) {
|
| // Only report the exception if the external handler is verbose.
|
| - return thread_local_top()->TryCatchHandler()->is_verbose_;
|
| + return try_catch_handler()->is_verbose_;
|
| } else {
|
| // Report the exception if it isn't caught by JavaScript code.
|
| return handler == NULL;
|
| @@ -662,14 +669,12 @@
|
| Handle<Object> exception_handle(exception_object);
|
|
|
| // Determine reporting and whether the exception is caught externally.
|
| - bool is_out_of_memory = exception == Failure::OutOfMemoryException();
|
| - bool is_termination_exception = exception == heap_.termination_exception();
|
| - bool catchable_by_javascript = !is_termination_exception && !is_out_of_memory;
|
| + bool catchable_by_javascript = is_catchable_by_javascript(exception);
|
| // Only real objects can be caught by JS.
|
| ASSERT(!catchable_by_javascript || is_object);
|
| - bool is_caught_externally = false;
|
| + bool can_be_caught_externally = false;
|
| bool should_report_exception =
|
| - ShouldReportException(&is_caught_externally, catchable_by_javascript);
|
| + ShouldReportException(&can_be_caught_externally, catchable_by_javascript);
|
| bool report_exception = catchable_by_javascript && should_report_exception;
|
|
|
| #ifdef ENABLE_DEBUGGER_SUPPORT
|
| @@ -683,8 +688,8 @@
|
| Handle<Object> message_obj;
|
| MessageLocation potential_computed_location;
|
| bool try_catch_needs_message =
|
| - is_caught_externally &&
|
| - thread_local_top()->TryCatchHandler()->capture_message_;
|
| + can_be_caught_externally &&
|
| + try_catch_handler()->capture_message_;
|
| if (report_exception || try_catch_needs_message) {
|
| if (location == NULL) {
|
| // If no location was specified we use a computed one instead
|
| @@ -722,9 +727,10 @@
|
| }
|
| }
|
|
|
| - if (is_caught_externally) {
|
| - thread_local_top()->catcher_ = thread_local_top()->TryCatchHandler();
|
| - }
|
| + // Do not forget to clean catcher_ if currently thrown exception cannot
|
| + // be caught. If necessary, ReThrow will update the catcher.
|
| + thread_local_top()->catcher_ = can_be_caught_externally ?
|
| + try_catch_handler() : NULL;
|
|
|
| // NOTE: Notifying the debugger or generating the message
|
| // may have caused new exceptions. For now, we just ignore
|
| @@ -739,23 +745,65 @@
|
| }
|
|
|
|
|
| +bool Isolate::IsExternallyCaught() {
|
| + ASSERT(has_pending_exception());
|
| +
|
| + if ((thread_local_top()->catcher_ == NULL) ||
|
| + (try_catch_handler() != thread_local_top()->catcher_)) {
|
| + // When throwing the exception, we found no v8::TryCatch
|
| + // which should care about this exception.
|
| + return false;
|
| + }
|
| +
|
| + if (!is_catchable_by_javascript(pending_exception())) {
|
| + return true;
|
| + }
|
| +
|
| + // Get the address of the external handler so we can compare the address to
|
| + // determine which one is closer to the top of the stack.
|
| + Address external_handler_address =
|
| + thread_local_top()->try_catch_handler_address();
|
| + ASSERT(external_handler_address != NULL);
|
| +
|
| + // The exception has been externally caught if and only if there is
|
| + // an external handler which is on top of the top-most try-finally
|
| + // handler.
|
| + // There should be no try-catch blocks as they would prohibit us from
|
| + // finding external catcher in the first place (see catcher_ check above).
|
| + //
|
| + // Note, that finally clause would rethrow an exception unless it's
|
| + // aborted by jumps in control flow like return, break, etc. and we'll
|
| + // have another chances to set proper v8::TryCatch.
|
| + StackHandler* handler =
|
| + StackHandler::FromAddress(Isolate::handler(thread_local_top()));
|
| + while (handler != NULL && handler->address() < external_handler_address) {
|
| + ASSERT(!handler->is_try_catch());
|
| + if (handler->is_try_finally()) return false;
|
| +
|
| + handler = handler->next();
|
| + }
|
| +
|
| + return true;
|
| +}
|
| +
|
| +
|
| void Isolate::ReportPendingMessages() {
|
| ASSERT(has_pending_exception());
|
| - setup_external_caught();
|
| // If the pending exception is OutOfMemoryException set out_of_memory in
|
| // the global context. Note: We have to mark the global context here
|
| // since the GenerateThrowOutOfMemory stub cannot make a RuntimeCall to
|
| // set it.
|
| - bool external_caught = thread_local_top()->external_caught_exception_;
|
| - HandleScope scope;
|
| + bool external_caught = IsExternallyCaught();
|
| + thread_local_top()->external_caught_exception_ = external_caught;
|
| + HandleScope scope(this);
|
| if (thread_local_top()->pending_exception_ ==
|
| Failure::OutOfMemoryException()) {
|
| context()->mark_out_of_memory();
|
| } else if (thread_local_top()->pending_exception_ ==
|
| heap_.termination_exception()) {
|
| if (external_caught) {
|
| - thread_local_top()->TryCatchHandler()->can_continue_ = false;
|
| - thread_local_top()->TryCatchHandler()->exception_ = heap_.null_value();
|
| + try_catch_handler()->can_continue_ = false;
|
| + try_catch_handler()->exception_ = heap_.null_value();
|
| }
|
| } else {
|
| // At this point all non-object (failure) exceptions have
|
| @@ -764,9 +812,8 @@
|
| Handle<Object> exception(pending_exception_object);
|
| thread_local_top()->external_caught_exception_ = false;
|
| if (external_caught) {
|
| - thread_local_top()->TryCatchHandler()->can_continue_ = true;
|
| - thread_local_top()->TryCatchHandler()->exception_ =
|
| - thread_local_top()->pending_exception_;
|
| + try_catch_handler()->can_continue_ = true;
|
| + try_catch_handler()->exception_ = thread_local_top()->pending_exception_;
|
| if (!thread_local_top()->pending_message_obj_->IsTheHole()) {
|
| try_catch_handler()->message_ =
|
| thread_local_top()->pending_message_obj_;
|
|
|