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

Side by Side Diff: src/isolate.cc

Issue 343563009: Fix stack trace accessor behavior. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: fix for the prototype chain lookup Created 6 years, 5 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/isolate.h ('k') | src/messages.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stdlib.h> 5 #include <stdlib.h>
6 6
7 #include "src/v8.h" 7 #include "src/v8.h"
8 8
9 #include "src/ast.h" 9 #include "src/ast.h"
10 #include "src/bootstrapper.h" 10 #include "src/bootstrapper.h"
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 if (!FLAG_builtins_in_stack_traces) { 346 if (!FLAG_builtins_in_stack_traces) {
347 if (frame->receiver()->IsJSBuiltinsObject() || 347 if (frame->receiver()->IsJSBuiltinsObject() ||
348 (fun->IsBuiltin() && !fun->shared()->native())) { 348 (fun->IsBuiltin() && !fun->shared()->native())) {
349 return false; 349 return false;
350 } 350 }
351 } 351 }
352 return true; 352 return true;
353 } 353 }
354 354
355 355
356 Handle<JSArray> Isolate::CaptureSimpleStackTrace(Handle<JSObject> error_object, 356 Handle<Object> Isolate::CaptureSimpleStackTrace(Handle<JSObject> error_object,
357 Handle<Object> caller, 357 Handle<Object> caller) {
358 int limit) { 358 // Get stack trace limit.
359 Handle<Object> error = Object::GetProperty(
360 this, js_builtins_object(), "$Error").ToHandleChecked();
361 if (!error->IsJSObject()) return factory()->undefined_value();
362
363 Handle<String> stackTraceLimit =
364 factory()->InternalizeUtf8String("stackTraceLimit");
365 ASSERT(!stackTraceLimit.is_null());
366 Handle<Object> stack_trace_limit =
367 JSObject::GetDataProperty(Handle<JSObject>::cast(error),
368 stackTraceLimit);
369 if (!stack_trace_limit->IsNumber()) return factory()->undefined_value();
370 int limit = FastD2IChecked(stack_trace_limit->Number());
359 limit = Max(limit, 0); // Ensure that limit is not negative. 371 limit = Max(limit, 0); // Ensure that limit is not negative.
372
360 int initial_size = Min(limit, 10); 373 int initial_size = Min(limit, 10);
361 Handle<FixedArray> elements = 374 Handle<FixedArray> elements =
362 factory()->NewFixedArrayWithHoles(initial_size * 4 + 1); 375 factory()->NewFixedArrayWithHoles(initial_size * 4 + 1);
363 376
364 // If the caller parameter is a function we skip frames until we're 377 // If the caller parameter is a function we skip frames until we're
365 // under it before starting to collect. 378 // under it before starting to collect.
366 bool seen_caller = !caller->IsJSFunction(); 379 bool seen_caller = !caller->IsJSFunction();
367 // First element is reserved to store the number of sloppy frames. 380 // First element is reserved to store the number of sloppy frames.
368 int cursor = 1; 381 int cursor = 1;
369 int frames_seen = 0; 382 int frames_seen = 0;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 elements->set(0, Smi::FromInt(sloppy_frames)); 432 elements->set(0, Smi::FromInt(sloppy_frames));
420 Handle<JSArray> result = factory()->NewJSArrayWithElements(elements); 433 Handle<JSArray> result = factory()->NewJSArrayWithElements(elements);
421 result->set_length(Smi::FromInt(cursor)); 434 result->set_length(Smi::FromInt(cursor));
422 return result; 435 return result;
423 } 436 }
424 437
425 438
426 void Isolate::CaptureAndSetDetailedStackTrace(Handle<JSObject> error_object) { 439 void Isolate::CaptureAndSetDetailedStackTrace(Handle<JSObject> error_object) {
427 if (capture_stack_trace_for_uncaught_exceptions_) { 440 if (capture_stack_trace_for_uncaught_exceptions_) {
428 // Capture stack trace for a detailed exception message. 441 // Capture stack trace for a detailed exception message.
429 Handle<String> key = factory()->hidden_stack_trace_string(); 442 Handle<Name> key = factory()->detailed_stack_trace_symbol();
430 Handle<JSArray> stack_trace = CaptureCurrentStackTrace( 443 Handle<JSArray> stack_trace = CaptureCurrentStackTrace(
431 stack_trace_for_uncaught_exceptions_frame_limit_, 444 stack_trace_for_uncaught_exceptions_frame_limit_,
432 stack_trace_for_uncaught_exceptions_options_); 445 stack_trace_for_uncaught_exceptions_options_);
433 JSObject::SetHiddenProperty(error_object, key, stack_trace); 446 JSObject::SetProperty(
447 error_object, key, stack_trace, NONE, STRICT).Assert();
434 } 448 }
435 } 449 }
436 450
437 451
452 void Isolate::CaptureAndSetSimpleStackTrace(Handle<JSObject> error_object,
453 Handle<Object> caller) {
454 // Capture stack trace for simple stack trace string formatting.
455 Handle<Name> key = factory()->stack_trace_symbol();
456 Handle<Object> stack_trace = CaptureSimpleStackTrace(error_object, caller);
457 JSObject::SetProperty(error_object, key, stack_trace, NONE, STRICT).Assert();
458 }
459
460
438 Handle<JSArray> Isolate::CaptureCurrentStackTrace( 461 Handle<JSArray> Isolate::CaptureCurrentStackTrace(
439 int frame_limit, StackTrace::StackTraceOptions options) { 462 int frame_limit, StackTrace::StackTraceOptions options) {
440 // Ensure no negative values. 463 // Ensure no negative values.
441 int limit = Max(frame_limit, 0); 464 int limit = Max(frame_limit, 0);
442 Handle<JSArray> stack_trace = factory()->NewJSArray(frame_limit); 465 Handle<JSArray> stack_trace = factory()->NewJSArray(frame_limit);
443 466
444 Handle<String> column_key = 467 Handle<String> column_key =
445 factory()->InternalizeOneByteString(STATIC_ASCII_VECTOR("column")); 468 factory()->InternalizeOneByteString(STATIC_ASCII_VECTOR("column"));
446 Handle<String> line_key = 469 Handle<String> line_key =
447 factory()->InternalizeOneByteString(STATIC_ASCII_VECTOR("lineNumber")); 470 factory()->InternalizeOneByteString(STATIC_ASCII_VECTOR("lineNumber"));
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
773 HandleScope scope(this); 796 HandleScope scope(this);
774 // At this point we cannot create an Error object using its javascript 797 // At this point we cannot create an Error object using its javascript
775 // constructor. Instead, we copy the pre-constructed boilerplate and 798 // constructor. Instead, we copy the pre-constructed boilerplate and
776 // attach the stack trace as a hidden property. 799 // attach the stack trace as a hidden property.
777 Handle<String> key = factory()->stack_overflow_string(); 800 Handle<String> key = factory()->stack_overflow_string();
778 Handle<JSObject> boilerplate = Handle<JSObject>::cast( 801 Handle<JSObject> boilerplate = Handle<JSObject>::cast(
779 Object::GetProperty(js_builtins_object(), key).ToHandleChecked()); 802 Object::GetProperty(js_builtins_object(), key).ToHandleChecked());
780 Handle<JSObject> exception = factory()->CopyJSObject(boilerplate); 803 Handle<JSObject> exception = factory()->CopyJSObject(boilerplate);
781 DoThrow(*exception, NULL); 804 DoThrow(*exception, NULL);
782 805
783 // Get stack trace limit. 806 CaptureAndSetSimpleStackTrace(exception, factory()->undefined_value());
784 Handle<Object> error = Object::GetProperty(
785 this, js_builtins_object(), "$Error").ToHandleChecked();
786 if (!error->IsJSObject()) return heap()->exception();
787
788 Handle<String> stackTraceLimit =
789 factory()->InternalizeUtf8String("stackTraceLimit");
790 ASSERT(!stackTraceLimit.is_null());
791 Handle<Object> stack_trace_limit =
792 JSObject::GetDataProperty(Handle<JSObject>::cast(error),
793 stackTraceLimit);
794 if (!stack_trace_limit->IsNumber()) return heap()->exception();
795 int limit = FastD2IChecked(stack_trace_limit->Number());
796 if (limit < 0) limit = 0;
797 Handle<JSArray> stack_trace = CaptureSimpleStackTrace(
798 exception, factory()->undefined_value(), limit);
799 JSObject::SetHiddenProperty(exception,
800 factory()->hidden_stack_trace_string(),
801 stack_trace);
802 return heap()->exception(); 807 return heap()->exception();
803 } 808 }
804 809
805 810
806 Object* Isolate::TerminateExecution() { 811 Object* Isolate::TerminateExecution() {
807 DoThrow(heap_.termination_exception(), NULL); 812 DoThrow(heap_.termination_exception(), NULL);
808 return heap()->exception(); 813 return heap()->exception();
809 } 814 }
810 815
811 816
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
1047 location = &potential_computed_location; 1052 location = &potential_computed_location;
1048 } 1053 }
1049 // It's not safe to try to make message objects or collect stack traces 1054 // It's not safe to try to make message objects or collect stack traces
1050 // while the bootstrapper is active since the infrastructure may not have 1055 // while the bootstrapper is active since the infrastructure may not have
1051 // been properly initialized. 1056 // been properly initialized.
1052 if (!bootstrapping) { 1057 if (!bootstrapping) {
1053 Handle<JSArray> stack_trace_object; 1058 Handle<JSArray> stack_trace_object;
1054 if (capture_stack_trace_for_uncaught_exceptions_) { 1059 if (capture_stack_trace_for_uncaught_exceptions_) {
1055 if (IsErrorObject(exception_handle)) { 1060 if (IsErrorObject(exception_handle)) {
1056 // We fetch the stack trace that corresponds to this error object. 1061 // We fetch the stack trace that corresponds to this error object.
1057 Handle<String> key = factory()->hidden_stack_trace_string(); 1062 Handle<Name> key = factory()->detailed_stack_trace_symbol();
1058 Object* stack_property = 1063 // Look up as own property. If the lookup fails, the exception is
1059 JSObject::cast(*exception_handle)->GetHiddenProperty(key); 1064 // probably not a valid Error object. In that case, we fall through
1060 // Property lookup may have failed. In this case it's probably not 1065 // and capture the stack trace at this throw site.
1061 // a valid Error object. 1066 LookupIterator lookup(
1062 if (stack_property->IsJSArray()) { 1067 exception_handle, key, LookupIterator::CHECK_OWN_REAL);
1063 stack_trace_object = Handle<JSArray>(JSArray::cast(stack_property)); 1068 Handle<Object> stack_trace_property;
1069 if (Object::GetProperty(&lookup).ToHandle(&stack_trace_property) &&
1070 stack_trace_property->IsJSArray()) {
1071 stack_trace_object = Handle<JSArray>::cast(stack_trace_property);
1064 } 1072 }
1065 } 1073 }
1066 if (stack_trace_object.is_null()) { 1074 if (stack_trace_object.is_null()) {
1067 // Not an error object, we capture at throw site. 1075 // Not an error object, we capture at throw site.
1068 stack_trace_object = CaptureCurrentStackTrace( 1076 stack_trace_object = CaptureCurrentStackTrace(
1069 stack_trace_for_uncaught_exceptions_frame_limit_, 1077 stack_trace_for_uncaught_exceptions_frame_limit_,
1070 stack_trace_for_uncaught_exceptions_options_); 1078 stack_trace_for_uncaught_exceptions_options_);
1071 } 1079 }
1072 } 1080 }
1073 1081
(...skipping 1291 matching lines...) Expand 10 before | Expand all | Expand 10 after
2365 // The simulator uses a separate JS stack. 2373 // The simulator uses a separate JS stack.
2366 Address jssp_address = Simulator::current(isolate_)->get_sp(); 2374 Address jssp_address = Simulator::current(isolate_)->get_sp();
2367 uintptr_t jssp = reinterpret_cast<uintptr_t>(jssp_address); 2375 uintptr_t jssp = reinterpret_cast<uintptr_t>(jssp_address);
2368 if (jssp < stack_guard->real_jslimit()) return true; 2376 if (jssp < stack_guard->real_jslimit()) return true;
2369 #endif // USE_SIMULATOR 2377 #endif // USE_SIMULATOR
2370 return reinterpret_cast<uintptr_t>(this) < stack_guard->real_climit(); 2378 return reinterpret_cast<uintptr_t>(this) < stack_guard->real_climit();
2371 } 2379 }
2372 2380
2373 2381
2374 } } // namespace v8::internal 2382 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/isolate.h ('k') | src/messages.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698