OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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/runtime/runtime-utils.h" | 5 #include "src/runtime/runtime-utils.h" |
6 | 6 |
7 #include "src/arguments.h" | 7 #include "src/arguments.h" |
8 #include "src/ast/prettyprinter.h" | 8 #include "src/ast/prettyprinter.h" |
9 #include "src/bootstrapper.h" | 9 #include "src/bootstrapper.h" |
10 #include "src/conversions.h" | 10 #include "src/conversions.h" |
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 DCHECK(args.length() == 1); | 370 DCHECK(args.length() == 1); |
371 CONVERT_ARG_CHECKED(String, name, 0); | 371 CONVERT_ARG_CHECKED(String, name, 0); |
372 | 372 |
373 if (FLAG_native_code_counters) { | 373 if (FLAG_native_code_counters) { |
374 StatsCounter(isolate, name->ToCString().get()).Increment(); | 374 StatsCounter(isolate, name->ToCString().get()).Increment(); |
375 } | 375 } |
376 return isolate->heap()->undefined_value(); | 376 return isolate->heap()->undefined_value(); |
377 } | 377 } |
378 | 378 |
379 | 379 |
380 namespace { | |
381 | |
382 bool ComputeLocation(Isolate* isolate, MessageLocation* target) { | |
383 JavaScriptFrameIterator it(isolate); | |
384 if (!it.done()) { | |
385 JavaScriptFrame* frame = it.frame(); | |
386 JSFunction* fun = frame->function(); | |
387 Object* script = fun->shared()->script(); | |
388 if (script->IsScript() && | |
389 !(Script::cast(script)->source()->IsUndefined())) { | |
390 Handle<Script> casted_script(Script::cast(script)); | |
391 // Compute the location from the function and the relocation info of the | |
392 // baseline code. For optimized code this will use the deoptimization | |
393 // information to get canonical location information. | |
394 List<FrameSummary> frames(FLAG_max_inlining_levels + 1); | |
395 it.frame()->Summarize(&frames); | |
396 FrameSummary& summary = frames.last(); | |
397 int pos = summary.abstract_code()->SourcePosition(summary.code_offset()); | |
398 *target = MessageLocation(casted_script, pos, pos + 1, handle(fun)); | |
399 return true; | |
400 } | |
401 } | |
402 return false; | |
403 } | |
404 | |
405 | |
406 Handle<String> RenderCallSite(Isolate* isolate, Handle<Object> object) { | |
407 MessageLocation location; | |
408 if (ComputeLocation(isolate, &location)) { | |
409 Zone zone; | |
410 base::SmartPointer<ParseInfo> info( | |
411 location.function()->shared()->is_function() | |
412 ? new ParseInfo(&zone, location.function()) | |
413 : new ParseInfo(&zone, location.script())); | |
414 if (Parser::ParseStatic(info.get())) { | |
415 CallPrinter printer(isolate, location.function()->shared()->IsBuiltin()); | |
416 const char* string = printer.Print(info->literal(), location.start_pos()); | |
417 if (strlen(string) > 0) { | |
418 return isolate->factory()->NewStringFromAsciiChecked(string); | |
419 } | |
420 } else { | |
421 isolate->clear_pending_exception(); | |
422 } | |
423 } | |
424 return Object::TypeOf(isolate, object); | |
425 } | |
426 | |
427 } // namespace | |
428 | |
429 | |
430 RUNTIME_FUNCTION(Runtime_ThrowCalledNonCallable) { | 380 RUNTIME_FUNCTION(Runtime_ThrowCalledNonCallable) { |
431 HandleScope scope(isolate); | 381 HandleScope scope(isolate); |
432 DCHECK_EQ(1, args.length()); | 382 DCHECK_EQ(1, args.length()); |
433 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); | 383 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); |
434 Handle<String> callsite = RenderCallSite(isolate, object); | 384 Handle<String> callsite = Runtime::RenderCallSite(isolate, object); |
435 THROW_NEW_ERROR_RETURN_FAILURE( | 385 THROW_NEW_ERROR_RETURN_FAILURE( |
436 isolate, NewTypeError(MessageTemplate::kCalledNonCallable, callsite)); | 386 isolate, NewTypeError(MessageTemplate::kCalledNonCallable, callsite)); |
437 } | 387 } |
438 | 388 |
439 | 389 |
440 RUNTIME_FUNCTION(Runtime_ThrowConstructedNonConstructable) { | 390 RUNTIME_FUNCTION(Runtime_ThrowConstructedNonConstructable) { |
441 HandleScope scope(isolate); | 391 HandleScope scope(isolate); |
442 DCHECK_EQ(1, args.length()); | 392 DCHECK_EQ(1, args.length()); |
443 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); | 393 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); |
444 Handle<String> callsite = RenderCallSite(isolate, object); | 394 Handle<String> callsite = Runtime::RenderCallSite(isolate, object); |
445 THROW_NEW_ERROR_RETURN_FAILURE( | 395 THROW_NEW_ERROR_RETURN_FAILURE( |
446 isolate, NewTypeError(MessageTemplate::kNotConstructor, callsite)); | 396 isolate, NewTypeError(MessageTemplate::kNotConstructor, callsite)); |
447 } | 397 } |
448 | 398 |
449 | 399 |
450 RUNTIME_FUNCTION(Runtime_ThrowDerivedConstructorReturnedNonObject) { | 400 RUNTIME_FUNCTION(Runtime_ThrowDerivedConstructorReturnedNonObject) { |
451 HandleScope scope(isolate); | 401 HandleScope scope(isolate); |
452 DCHECK_EQ(0, args.length()); | 402 DCHECK_EQ(0, args.length()); |
453 THROW_NEW_ERROR_RETURN_FAILURE( | 403 THROW_NEW_ERROR_RETURN_FAILURE( |
454 isolate, NewTypeError(MessageTemplate::kDerivedConstructorReturn)); | 404 isolate, NewTypeError(MessageTemplate::kDerivedConstructorReturn)); |
(...skipping 28 matching lines...) Expand all Loading... |
483 std::stringstream stats_stream; | 433 std::stringstream stats_stream; |
484 isolate->counters()->runtime_call_stats()->Print(stats_stream); | 434 isolate->counters()->runtime_call_stats()->Print(stats_stream); |
485 Handle<String> result = | 435 Handle<String> result = |
486 isolate->factory()->NewStringFromAsciiChecked(stats_stream.str().c_str()); | 436 isolate->factory()->NewStringFromAsciiChecked(stats_stream.str().c_str()); |
487 isolate->counters()->runtime_call_stats()->Reset(); | 437 isolate->counters()->runtime_call_stats()->Reset(); |
488 return *result; | 438 return *result; |
489 } | 439 } |
490 | 440 |
491 } // namespace internal | 441 } // namespace internal |
492 } // namespace v8 | 442 } // namespace v8 |
OLD | NEW |