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

Side by Side Diff: src/isolate.cc

Issue 2142933003: Move Error methods to C++ (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Handle exception in GetProperty Created 4 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
« no previous file with comments | « src/isolate.h ('k') | src/js/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 "src/isolate.h" 5 #include "src/isolate.h"
6 6
7 #include <stdlib.h> 7 #include <stdlib.h>
8 8
9 #include <fstream> // NOLINT(readability/streams) 9 #include <fstream> // NOLINT(readability/streams)
10 #include <sstream> 10 #include <sstream>
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 for (int i = 0; i < cur_position; i++) { 322 for (int i = 0; i < cur_position; i++) {
323 new_elements->set(i, elements->get(i)); 323 new_elements->set(i, elements->get(i));
324 } 324 }
325 elements = new_elements; 325 elements = new_elements;
326 } 326 }
327 DCHECK(new_size <= elements->length()); 327 DCHECK(new_size <= elements->length());
328 return elements; 328 return elements;
329 } 329 }
330 330
331 class StackTraceHelper { 331 class StackTraceHelper {
332 private:
333 enum FrameSkipMode {
334 SKIP_FIRST,
335 SKIP_UNTIL_SEEN,
336 SKIP_NONE,
337 };
338
332 public: 339 public:
333 StackTraceHelper(Isolate* isolate, Handle<Object> caller) 340 StackTraceHelper(Isolate* isolate, Handle<Object> caller)
334 : isolate_(isolate), caller_(caller) { 341 : isolate_(isolate), caller_(caller) {
335 // If the caller parameter is a function we skip frames until we're 342 // The caller parameter can be used to skip a specific set of frames in the
336 // under it before starting to collect. 343 // stack trace. It can be:
337 seen_caller_ = !caller->IsJSFunction(); 344 // * null, when called from a standard error constructor. We unconditionally
345 // skip the top frame, which is always a builtin-exit frame for the error
346 // constructor builtin.
347 // * a JSFunction, when called by the user from Error.captureStackTrace().
348 // We skip each frame until encountering the caller function.
349 // * For any other value, all frames are included in the trace.
350 if (caller_.is_null()) {
351 mode_ = SKIP_FIRST;
352 skip_next_frame_ = true;
353 } else if (caller_->IsJSFunction()) {
354 mode_ = SKIP_UNTIL_SEEN;
355 skip_next_frame_ = true;
356 } else {
357 mode_ = SKIP_NONE;
358 skip_next_frame_ = false;
359 }
338 encountered_strict_function_ = false; 360 encountered_strict_function_ = false;
339 sloppy_frames_ = 0; 361 sloppy_frames_ = 0;
340 } 362 }
341 363
342 // The stack trace API should not expose receivers and function 364 // The stack trace API should not expose receivers and function
343 // objects on frames deeper than the top-most one with a strict mode 365 // objects on frames deeper than the top-most one with a strict mode
344 // function. The number of sloppy frames is stored as first element in 366 // function. The number of sloppy frames is stored as first element in
345 // the result array. 367 // the result array.
346 void CountSloppyFrames(JSFunction* fun) { 368 void CountSloppyFrames(JSFunction* fun) {
347 if (!encountered_strict_function_) { 369 if (!encountered_strict_function_) {
348 if (is_strict(fun->shared()->language_mode())) { 370 if (is_strict(fun->shared()->language_mode())) {
349 encountered_strict_function_ = true; 371 encountered_strict_function_ = true;
350 } else { 372 } else {
351 sloppy_frames_++; 373 sloppy_frames_++;
352 } 374 }
353 } 375 }
354 } 376 }
355 377
356 // Determines whether the given stack frame should be displayed in a stack 378 // Determines whether the given stack frame should be displayed in a stack
357 // trace. 379 // trace.
358 bool IsVisibleInStackTrace(JSFunction* fun) { 380 bool IsVisibleInStackTrace(JSFunction* fun) {
359 return IsAfterCaller(fun) && IsNotInNativeScript(fun) && 381 return ShouldIncludeFrame(fun) && IsNotInNativeScript(fun) &&
360 IsInSameSecurityContext(fun); 382 IsInSameSecurityContext(fun);
361 } 383 }
362 384
363 int sloppy_frames() const { return sloppy_frames_; } 385 int sloppy_frames() const { return sloppy_frames_; }
364 386
365 private: 387 private:
366 // The caller is the error constructor that asked 388 // This mechanism excludes a number of uninteresting frames from the stack
367 // for the stack trace to be collected. The first time a construct 389 // trace. This can be be the first frame (which will be a builtin-exit frame
368 // call to this function is encountered it is skipped. The seen_caller 390 // for the error constructor builtin) or every frame until encountering a
369 // in/out parameter is used to remember if the caller has been seen 391 // user-specified function.
370 // yet. 392 bool ShouldIncludeFrame(JSFunction* fun) {
371 bool IsAfterCaller(JSFunction* fun) { 393 switch (mode_) {
372 if ((fun == *caller_) && !(seen_caller_)) { 394 case SKIP_NONE:
373 seen_caller_ = true; 395 return true;
374 return false; 396 case SKIP_FIRST:
397 if (!skip_next_frame_) return true;
398 skip_next_frame_ = false;
399 return false;
400 case SKIP_UNTIL_SEEN:
401 if (skip_next_frame_ && (fun == *caller_)) {
402 skip_next_frame_ = false;
403 return false;
404 }
405 return !skip_next_frame_;
375 } 406 }
376 // Skip all frames until we've seen the caller. 407 UNREACHABLE();
377 if (!seen_caller_) return false; 408 return false;
378 return true;
379 } 409 }
380 410
381 bool IsNotInNativeScript(JSFunction* fun) { 411 bool IsNotInNativeScript(JSFunction* fun) {
382 // Functions defined in native scripts are not visible unless directly 412 // Functions defined in native scripts are not visible unless directly
383 // exposed, in which case the native flag is set. 413 // exposed, in which case the native flag is set.
384 // The --builtins-in-stack-traces command line flag allows including 414 // The --builtins-in-stack-traces command line flag allows including
385 // internal call sites in the stack trace for debugging purposes. 415 // internal call sites in the stack trace for debugging purposes.
386 if (!FLAG_builtins_in_stack_traces && fun->shared()->IsBuiltin()) { 416 if (!FLAG_builtins_in_stack_traces && fun->shared()->IsBuiltin()) {
387 return fun->shared()->native(); 417 return fun->shared()->native();
388 } 418 }
389 return true; 419 return true;
390 } 420 }
391 421
392 bool IsInSameSecurityContext(JSFunction* fun) { 422 bool IsInSameSecurityContext(JSFunction* fun) {
393 return isolate_->context()->HasSameSecurityTokenAs(fun->context()); 423 return isolate_->context()->HasSameSecurityTokenAs(fun->context());
394 } 424 }
395 425
396 Isolate* isolate_; 426 Isolate* isolate_;
427
428 FrameSkipMode mode_;
397 Handle<Object> caller_; 429 Handle<Object> caller_;
430 bool skip_next_frame_;
398 431
399 bool seen_caller_;
400 int sloppy_frames_; 432 int sloppy_frames_;
401 bool encountered_strict_function_; 433 bool encountered_strict_function_;
402 }; 434 };
403 435
404 Handle<Object> Isolate::CaptureSimpleStackTrace(Handle<JSReceiver> error_object, 436 Handle<Object> Isolate::CaptureSimpleStackTrace(Handle<JSReceiver> error_object,
405 Handle<Object> caller) { 437 Handle<Object> caller) {
406 DisallowJavascriptExecution no_js(this); 438 DisallowJavascriptExecution no_js(this);
407 439
408 // Get stack trace limit. 440 // Get stack trace limit.
409 Handle<JSObject> error = error_function(); 441 Handle<JSObject> error = error_function();
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 } 556 }
525 557
526 MaybeHandle<JSReceiver> Isolate::CaptureAndSetDetailedStackTrace( 558 MaybeHandle<JSReceiver> Isolate::CaptureAndSetDetailedStackTrace(
527 Handle<JSReceiver> error_object) { 559 Handle<JSReceiver> error_object) {
528 if (capture_stack_trace_for_uncaught_exceptions_) { 560 if (capture_stack_trace_for_uncaught_exceptions_) {
529 // Capture stack trace for a detailed exception message. 561 // Capture stack trace for a detailed exception message.
530 Handle<Name> key = factory()->detailed_stack_trace_symbol(); 562 Handle<Name> key = factory()->detailed_stack_trace_symbol();
531 Handle<JSArray> stack_trace = CaptureCurrentStackTrace( 563 Handle<JSArray> stack_trace = CaptureCurrentStackTrace(
532 stack_trace_for_uncaught_exceptions_frame_limit_, 564 stack_trace_for_uncaught_exceptions_frame_limit_,
533 stack_trace_for_uncaught_exceptions_options_); 565 stack_trace_for_uncaught_exceptions_options_);
566 // TODO(jgruber): Set back to STRICT once we have eagerly formatted traces.
534 RETURN_ON_EXCEPTION( 567 RETURN_ON_EXCEPTION(
535 this, JSReceiver::SetProperty(error_object, key, stack_trace, STRICT), 568 this, JSReceiver::SetProperty(error_object, key, stack_trace, SLOPPY),
536 JSReceiver); 569 JSReceiver);
537 } 570 }
538 return error_object; 571 return error_object;
539 } 572 }
540 573
541 MaybeHandle<JSReceiver> Isolate::CaptureAndSetSimpleStackTrace( 574 MaybeHandle<JSReceiver> Isolate::CaptureAndSetSimpleStackTrace(
542 Handle<JSReceiver> error_object, Handle<Object> caller) { 575 Handle<JSReceiver> error_object, Handle<Object> caller) {
543 // Capture stack trace for simple stack trace string formatting. 576 // Capture stack trace for simple stack trace string formatting.
544 Handle<Name> key = factory()->stack_trace_symbol(); 577 Handle<Name> key = factory()->stack_trace_symbol();
545 Handle<Object> stack_trace = CaptureSimpleStackTrace(error_object, caller); 578 Handle<Object> stack_trace = CaptureSimpleStackTrace(error_object, caller);
579 // TODO(jgruber): Set back to STRICT once we have eagerly formatted traces.
546 RETURN_ON_EXCEPTION( 580 RETURN_ON_EXCEPTION(
547 this, JSReceiver::SetProperty(error_object, key, stack_trace, STRICT), 581 this, JSReceiver::SetProperty(error_object, key, stack_trace, SLOPPY),
548 JSReceiver); 582 JSReceiver);
549 return error_object; 583 return error_object;
550 } 584 }
551 585
552 586
553 Handle<JSArray> Isolate::GetDetailedStackTrace(Handle<JSObject> error_object) { 587 Handle<JSArray> Isolate::GetDetailedStackTrace(Handle<JSObject> error_object) {
554 Handle<Name> key_detailed = factory()->detailed_stack_trace_symbol(); 588 Handle<Name> key_detailed = factory()->detailed_stack_trace_symbol();
555 Handle<Object> stack_trace = 589 Handle<Object> stack_trace =
556 JSReceiver::GetDataProperty(error_object, key_detailed); 590 JSReceiver::GetDataProperty(error_object, key_detailed);
557 if (stack_trace->IsJSArray()) return Handle<JSArray>::cast(stack_trace); 591 if (stack_trace->IsJSArray()) return Handle<JSArray>::cast(stack_trace);
(...skipping 2534 matching lines...) Expand 10 before | Expand all | Expand 10 after
3092 // Then check whether this scope intercepts. 3126 // Then check whether this scope intercepts.
3093 if ((flag & intercept_mask_)) { 3127 if ((flag & intercept_mask_)) {
3094 intercepted_flags_ |= flag; 3128 intercepted_flags_ |= flag;
3095 return true; 3129 return true;
3096 } 3130 }
3097 return false; 3131 return false;
3098 } 3132 }
3099 3133
3100 } // namespace internal 3134 } // namespace internal
3101 } // namespace v8 3135 } // namespace v8
OLDNEW
« no previous file with comments | « src/isolate.h ('k') | src/js/messages.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698