OLD | NEW |
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 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 | 337 |
338 Handle<JSArray> Top::CaptureCurrentStackTrace( | 338 Handle<JSArray> Top::CaptureCurrentStackTrace( |
339 int frame_limit, StackTrace::StackTraceOptions options) { | 339 int frame_limit, StackTrace::StackTraceOptions options) { |
340 // Ensure no negative values. | 340 // Ensure no negative values. |
341 int limit = Max(frame_limit, 0); | 341 int limit = Max(frame_limit, 0); |
342 Handle<JSArray> stack_trace = Factory::NewJSArray(frame_limit); | 342 Handle<JSArray> stack_trace = Factory::NewJSArray(frame_limit); |
343 | 343 |
344 Handle<String> column_key = Factory::LookupAsciiSymbol("column"); | 344 Handle<String> column_key = Factory::LookupAsciiSymbol("column"); |
345 Handle<String> line_key = Factory::LookupAsciiSymbol("lineNumber"); | 345 Handle<String> line_key = Factory::LookupAsciiSymbol("lineNumber"); |
346 Handle<String> script_key = Factory::LookupAsciiSymbol("scriptName"); | 346 Handle<String> script_key = Factory::LookupAsciiSymbol("scriptName"); |
| 347 Handle<String> name_or_source_url_key = |
| 348 Factory::LookupAsciiSymbol("nameOrSourceURL"); |
| 349 Handle<String> script_name_or_source_url_key = |
| 350 Factory::LookupAsciiSymbol("scriptNameOrSourceURL"); |
347 Handle<String> function_key = Factory::LookupAsciiSymbol("functionName"); | 351 Handle<String> function_key = Factory::LookupAsciiSymbol("functionName"); |
348 Handle<String> eval_key = Factory::LookupAsciiSymbol("isEval"); | 352 Handle<String> eval_key = Factory::LookupAsciiSymbol("isEval"); |
349 Handle<String> constructor_key = Factory::LookupAsciiSymbol("isConstructor"); | 353 Handle<String> constructor_key = Factory::LookupAsciiSymbol("isConstructor"); |
350 | 354 |
351 StackTraceFrameIterator it; | 355 StackTraceFrameIterator it; |
352 int frames_seen = 0; | 356 int frames_seen = 0; |
353 while (!it.done() && (frames_seen < limit)) { | 357 while (!it.done() && (frames_seen < limit)) { |
354 // Create a JSObject to hold the information for the StackFrame. | 358 // Create a JSObject to hold the information for the StackFrame. |
355 Handle<JSObject> stackFrame = Factory::NewJSObject(object_function()); | 359 Handle<JSObject> stackFrame = Factory::NewJSObject(object_function()); |
356 | 360 |
357 JavaScriptFrame* frame = it.frame(); | 361 JavaScriptFrame* frame = it.frame(); |
358 JSFunction* fun(JSFunction::cast(frame->function())); | 362 Handle<JSFunction> fun(JSFunction::cast(frame->function())); |
359 Script* script = Script::cast(fun->shared()->script()); | 363 Handle<Script> script(Script::cast(fun->shared()->script())); |
360 | 364 |
361 if (options & StackTrace::kLineNumber) { | 365 if (options & StackTrace::kLineNumber) { |
362 int script_line_offset = script->line_offset()->value(); | 366 int script_line_offset = script->line_offset()->value(); |
363 int position = frame->code()->SourcePosition(frame->pc()); | 367 int position = frame->code()->SourcePosition(frame->pc()); |
364 int line_number = GetScriptLineNumber(Handle<Script>(script), position); | 368 int line_number = GetScriptLineNumber(script, position); |
365 // line_number is already shifted by the script_line_offset. | 369 // line_number is already shifted by the script_line_offset. |
366 int relative_line_number = line_number - script_line_offset; | 370 int relative_line_number = line_number - script_line_offset; |
367 if (options & StackTrace::kColumnOffset && relative_line_number >= 0) { | 371 if (options & StackTrace::kColumnOffset && relative_line_number >= 0) { |
368 Handle<FixedArray> line_ends(FixedArray::cast(script->line_ends())); | 372 Handle<FixedArray> line_ends(FixedArray::cast(script->line_ends())); |
369 int start = (relative_line_number == 0) ? 0 : | 373 int start = (relative_line_number == 0) ? 0 : |
370 Smi::cast(line_ends->get(relative_line_number - 1))->value() + 1; | 374 Smi::cast(line_ends->get(relative_line_number - 1))->value() + 1; |
371 int column_offset = position - start; | 375 int column_offset = position - start; |
372 if (relative_line_number == 0) { | 376 if (relative_line_number == 0) { |
373 // For the case where the code is on the same line as the script tag. | 377 // For the case where the code is on the same line as the script tag. |
374 column_offset += script->column_offset()->value(); | 378 column_offset += script->column_offset()->value(); |
375 } | 379 } |
376 SetProperty(stackFrame, column_key, | 380 SetProperty(stackFrame, column_key, |
377 Handle<Smi>(Smi::FromInt(column_offset + 1)), NONE); | 381 Handle<Smi>(Smi::FromInt(column_offset + 1)), NONE); |
378 } | 382 } |
379 SetProperty(stackFrame, line_key, | 383 SetProperty(stackFrame, line_key, |
380 Handle<Smi>(Smi::FromInt(line_number + 1)), NONE); | 384 Handle<Smi>(Smi::FromInt(line_number + 1)), NONE); |
381 } | 385 } |
382 | 386 |
383 if (options & StackTrace::kScriptName) { | 387 if (options & StackTrace::kScriptName) { |
384 Handle<Object> script_name(script->name()); | 388 Handle<Object> script_name(script->name()); |
385 SetProperty(stackFrame, script_key, script_name, NONE); | 389 SetProperty(stackFrame, script_key, script_name, NONE); |
386 } | 390 } |
387 | 391 |
388 if (options & StackTrace::kScriptNameOrSourceURL) { | 392 if (options & StackTrace::kScriptNameOrSourceURL) { |
389 Handle<Object> script_name(script->name()); | 393 Handle<Object> script_name(script->name()); |
390 Handle<String> method_name = | 394 Handle<JSValue> script_wrapper = GetScriptWrapper(script); |
391 Factory::LookupAsciiSymbol("nameOrSourceURL"); | 395 Handle<Object> property = GetProperty(script_wrapper, |
392 Handle<JSValue> script_wrapper = GetScriptWrapper(Handle<Script>(script)); | 396 name_or_source_url_key); |
393 Handle<Object> property = GetProperty(script_wrapper, method_name); | |
394 ASSERT(property->IsJSFunction()); | 397 ASSERT(property->IsJSFunction()); |
395 Handle<JSFunction> method = Handle<JSFunction>::cast(property); | 398 Handle<JSFunction> method = Handle<JSFunction>::cast(property); |
396 bool caught_exception; | 399 bool caught_exception; |
397 Handle<Object> result = Execution::TryCall(method, script_wrapper, 0, | 400 Handle<Object> result = Execution::TryCall(method, script_wrapper, 0, |
398 NULL, &caught_exception); | 401 NULL, &caught_exception); |
399 if (caught_exception) { | 402 if (caught_exception) { |
400 result = Factory::undefined_value(); | 403 result = Factory::undefined_value(); |
401 } | 404 } |
402 Handle<String> script_name_or_source_url_key = | |
403 Factory::LookupAsciiSymbol("scriptNameOrSourceURL"); | |
404 SetProperty(stackFrame, script_name_or_source_url_key, result, NONE); | 405 SetProperty(stackFrame, script_name_or_source_url_key, result, NONE); |
405 } | 406 } |
406 | 407 |
407 if (options & StackTrace::kFunctionName) { | 408 if (options & StackTrace::kFunctionName) { |
408 Handle<Object> fun_name(fun->shared()->name()); | 409 Handle<Object> fun_name(fun->shared()->name()); |
409 if (fun_name->ToBoolean()->IsFalse()) { | 410 if (fun_name->ToBoolean()->IsFalse()) { |
410 fun_name = Handle<Object>(fun->shared()->inferred_name()); | 411 fun_name = Handle<Object>(fun->shared()->inferred_name()); |
411 } | 412 } |
412 SetProperty(stackFrame, function_key, fun_name, NONE); | 413 SetProperty(stackFrame, function_key, fun_name, NONE); |
413 } | 414 } |
(...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1039 Top::break_access_->Lock(); | 1040 Top::break_access_->Lock(); |
1040 } | 1041 } |
1041 | 1042 |
1042 | 1043 |
1043 ExecutionAccess::~ExecutionAccess() { | 1044 ExecutionAccess::~ExecutionAccess() { |
1044 Top::break_access_->Unlock(); | 1045 Top::break_access_->Unlock(); |
1045 } | 1046 } |
1046 | 1047 |
1047 | 1048 |
1048 } } // namespace v8::internal | 1049 } } // namespace v8::internal |
OLD | NEW |