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

Side by Side Diff: src/isolate.cc

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