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

Side by Side Diff: src/top.cc

Issue 6463022: Do not invoke any setters when forming stack trace JS object. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 10 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 | « no previous file | test/cctest/test-api.cc » ('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 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 incomplete_message->OutputToStdOut(); 367 incomplete_message->OutputToStdOut();
368 return Factory::empty_symbol(); 368 return Factory::empty_symbol();
369 } else { 369 } else {
370 OS::Abort(); 370 OS::Abort();
371 // Unreachable 371 // Unreachable
372 return Factory::empty_symbol(); 372 return Factory::empty_symbol();
373 } 373 }
374 } 374 }
375 375
376 376
377 static void SetLocalProperty(Handle<JSObject> object,
378 Handle<String> key,
379 Handle<Object> value) {
380 // We set properties on freshly allocated JS object, nothing
381 // should fail except for OOM which is handled by
382 // SetLocalPropertyIgnoreAttributes.
383 ASSERT(!Top::has_pending_exception());
384 CHECK(!SetLocalPropertyIgnoreAttributes(object, key, value, NONE).is_null());
385 CHECK(!Top::has_pending_exception());
386 }
387
388
377 Handle<JSArray> Top::CaptureCurrentStackTrace( 389 Handle<JSArray> Top::CaptureCurrentStackTrace(
378 int frame_limit, StackTrace::StackTraceOptions options) { 390 int frame_limit, StackTrace::StackTraceOptions options) {
379 // Ensure no negative values. 391 // Ensure no negative values.
380 int limit = Max(frame_limit, 0); 392 int limit = Max(frame_limit, 0);
381 Handle<JSArray> stack_trace = Factory::NewJSArray(frame_limit); 393 Handle<JSArray> stack_trace = Factory::NewJSArray(frame_limit);
382 394
383 Handle<String> column_key = Factory::LookupAsciiSymbol("column"); 395 Handle<String> column_key = Factory::LookupAsciiSymbol("column");
384 Handle<String> line_key = Factory::LookupAsciiSymbol("lineNumber"); 396 Handle<String> line_key = Factory::LookupAsciiSymbol("lineNumber");
385 Handle<String> script_key = Factory::LookupAsciiSymbol("scriptName"); 397 Handle<String> script_key = Factory::LookupAsciiSymbol("scriptName");
386 Handle<String> name_or_source_url_key = 398 Handle<String> name_or_source_url_key =
387 Factory::LookupAsciiSymbol("nameOrSourceURL"); 399 Factory::LookupAsciiSymbol("nameOrSourceURL");
388 Handle<String> script_name_or_source_url_key = 400 Handle<String> script_name_or_source_url_key =
389 Factory::LookupAsciiSymbol("scriptNameOrSourceURL"); 401 Factory::LookupAsciiSymbol("scriptNameOrSourceURL");
390 Handle<String> function_key = Factory::LookupAsciiSymbol("functionName"); 402 Handle<String> function_key = Factory::LookupAsciiSymbol("functionName");
391 Handle<String> eval_key = Factory::LookupAsciiSymbol("isEval"); 403 Handle<String> eval_key = Factory::LookupAsciiSymbol("isEval");
392 Handle<String> constructor_key = Factory::LookupAsciiSymbol("isConstructor"); 404 Handle<String> constructor_key = Factory::LookupAsciiSymbol("isConstructor");
393 405
394 StackTraceFrameIterator it; 406 StackTraceFrameIterator it;
395 int frames_seen = 0; 407 int frames_seen = 0;
396 while (!it.done() && (frames_seen < limit)) { 408 while (!it.done() && (frames_seen < limit)) {
397 JavaScriptFrame* frame = it.frame(); 409 JavaScriptFrame* frame = it.frame();
398 410
399 List<FrameSummary> frames(3); // Max 2 levels of inlining. 411 List<FrameSummary> frames(3); // Max 2 levels of inlining.
400 frame->Summarize(&frames); 412 frame->Summarize(&frames);
401 for (int i = frames.length() - 1; i >= 0 && frames_seen < limit; i--) { 413 for (int i = frames.length() - 1; i >= 0 && frames_seen < limit; i--) {
402 // Create a JSObject to hold the information for the StackFrame. 414 // Create a JSObject to hold the information for the StackFrame.
(...skipping 11 matching lines...) Expand all
414 if (options & StackTrace::kColumnOffset && relative_line_number >= 0) { 426 if (options & StackTrace::kColumnOffset && relative_line_number >= 0) {
415 Handle<FixedArray> line_ends(FixedArray::cast(script->line_ends())); 427 Handle<FixedArray> line_ends(FixedArray::cast(script->line_ends()));
416 int start = (relative_line_number == 0) ? 0 : 428 int start = (relative_line_number == 0) ? 0 :
417 Smi::cast(line_ends->get(relative_line_number - 1))->value() + 1; 429 Smi::cast(line_ends->get(relative_line_number - 1))->value() + 1;
418 int column_offset = position - start; 430 int column_offset = position - start;
419 if (relative_line_number == 0) { 431 if (relative_line_number == 0) {
420 // For the case where the code is on the same line as the script 432 // For the case where the code is on the same line as the script
421 // tag. 433 // tag.
422 column_offset += script->column_offset()->value(); 434 column_offset += script->column_offset()->value();
423 } 435 }
424 SetProperty(stackFrame, column_key, 436 SetLocalProperty(stackFrame, column_key,
425 Handle<Smi>(Smi::FromInt(column_offset + 1)), NONE); 437 Handle<Smi>(Smi::FromInt(column_offset + 1)));
426 } 438 }
427 SetProperty(stackFrame, line_key, 439 SetLocalProperty(stackFrame, line_key,
428 Handle<Smi>(Smi::FromInt(line_number + 1)), NONE); 440 Handle<Smi>(Smi::FromInt(line_number + 1)));
429 } 441 }
430 442
431 if (options & StackTrace::kScriptName) { 443 if (options & StackTrace::kScriptName) {
432 Handle<Object> script_name(script->name()); 444 Handle<Object> script_name(script->name());
433 SetProperty(stackFrame, script_key, script_name, NONE); 445 SetLocalProperty(stackFrame, script_key, script_name);
434 } 446 }
435 447
436 if (options & StackTrace::kScriptNameOrSourceURL) { 448 if (options & StackTrace::kScriptNameOrSourceURL) {
437 Handle<Object> script_name(script->name()); 449 Handle<Object> script_name(script->name());
438 Handle<JSValue> script_wrapper = GetScriptWrapper(script); 450 Handle<JSValue> script_wrapper = GetScriptWrapper(script);
439 Handle<Object> property = GetProperty(script_wrapper, 451 Handle<Object> property = GetProperty(script_wrapper,
440 name_or_source_url_key); 452 name_or_source_url_key);
441 ASSERT(property->IsJSFunction()); 453 ASSERT(property->IsJSFunction());
442 Handle<JSFunction> method = Handle<JSFunction>::cast(property); 454 Handle<JSFunction> method = Handle<JSFunction>::cast(property);
443 bool caught_exception; 455 bool caught_exception;
444 Handle<Object> result = Execution::TryCall(method, script_wrapper, 0, 456 Handle<Object> result = Execution::TryCall(method, script_wrapper, 0,
445 NULL, &caught_exception); 457 NULL, &caught_exception);
446 if (caught_exception) { 458 if (caught_exception) {
447 result = Factory::undefined_value(); 459 result = Factory::undefined_value();
448 } 460 }
449 SetProperty(stackFrame, script_name_or_source_url_key, result, NONE); 461 SetLocalProperty(stackFrame, script_name_or_source_url_key, result);
450 } 462 }
451 463
452 if (options & StackTrace::kFunctionName) { 464 if (options & StackTrace::kFunctionName) {
453 Handle<Object> fun_name(fun->shared()->name()); 465 Handle<Object> fun_name(fun->shared()->name());
454 if (fun_name->ToBoolean()->IsFalse()) { 466 if (fun_name->ToBoolean()->IsFalse()) {
455 fun_name = Handle<Object>(fun->shared()->inferred_name()); 467 fun_name = Handle<Object>(fun->shared()->inferred_name());
456 } 468 }
457 SetProperty(stackFrame, function_key, fun_name, NONE); 469 SetLocalProperty(stackFrame, function_key, fun_name);
458 } 470 }
459 471
460 if (options & StackTrace::kIsEval) { 472 if (options & StackTrace::kIsEval) {
461 int type = Smi::cast(script->compilation_type())->value(); 473 int type = Smi::cast(script->compilation_type())->value();
462 Handle<Object> is_eval = (type == Script::COMPILATION_TYPE_EVAL) ? 474 Handle<Object> is_eval = (type == Script::COMPILATION_TYPE_EVAL) ?
463 Factory::true_value() : Factory::false_value(); 475 Factory::true_value() : Factory::false_value();
464 SetProperty(stackFrame, eval_key, is_eval, NONE); 476 SetLocalProperty(stackFrame, eval_key, is_eval);
465 } 477 }
466 478
467 if (options & StackTrace::kIsConstructor) { 479 if (options & StackTrace::kIsConstructor) {
468 Handle<Object> is_constructor = (frames[i].is_constructor()) ? 480 Handle<Object> is_constructor = (frames[i].is_constructor()) ?
469 Factory::true_value() : Factory::false_value(); 481 Factory::true_value() : Factory::false_value();
470 SetProperty(stackFrame, constructor_key, is_constructor, NONE); 482 SetLocalProperty(stackFrame, constructor_key, is_constructor);
471 } 483 }
472 484
473 FixedArray::cast(stack_trace->elements())->set(frames_seen, *stackFrame); 485 FixedArray::cast(stack_trace->elements())->set(frames_seen, *stackFrame);
474 frames_seen++; 486 frames_seen++;
475 } 487 }
476 it.Advance(); 488 it.Advance();
477 } 489 }
478 490
479 stack_trace->set_length(Smi::FromInt(frames_seen)); 491 stack_trace->set_length(Smi::FromInt(frames_seen));
480 return stack_trace; 492 return stack_trace;
(...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after
1097 #ifdef V8_TARGET_ARCH_ARM 1109 #ifdef V8_TARGET_ARCH_ARM
1098 thread_local_.simulator_ = Simulator::current(); 1110 thread_local_.simulator_ = Simulator::current();
1099 #elif V8_TARGET_ARCH_MIPS 1111 #elif V8_TARGET_ARCH_MIPS
1100 thread_local_.simulator_ = assembler::mips::Simulator::current(); 1112 thread_local_.simulator_ = assembler::mips::Simulator::current();
1101 #endif 1113 #endif
1102 #endif 1114 #endif
1103 return from + sizeof(thread_local_); 1115 return from + sizeof(thread_local_);
1104 } 1116 }
1105 1117
1106 } } // namespace v8::internal 1118 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698