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

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: Rebase 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
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 // Get stack trace limit. 438 // Get stack trace limit.
407 Handle<JSObject> error = error_function(); 439 Handle<JSObject> error = error_function();
408 Handle<String> stackTraceLimit = 440 Handle<String> stackTraceLimit =
409 factory()->InternalizeUtf8String("stackTraceLimit"); 441 factory()->InternalizeUtf8String("stackTraceLimit");
(...skipping 2675 matching lines...) Expand 10 before | Expand all | Expand 10 after
3085 // Then check whether this scope intercepts. 3117 // Then check whether this scope intercepts.
3086 if ((flag & intercept_mask_)) { 3118 if ((flag & intercept_mask_)) {
3087 intercepted_flags_ |= flag; 3119 intercepted_flags_ |= flag;
3088 return true; 3120 return true;
3089 } 3121 }
3090 return false; 3122 return false;
3091 } 3123 }
3092 3124
3093 } // namespace internal 3125 } // namespace internal
3094 } // namespace v8 3126 } // namespace v8
OLDNEW
« src/builtins/builtins.cc ('K') | « src/isolate.h ('k') | src/js/messages.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698