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 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 | 490 |
491 RUNTIME_FUNCTION(Runtime_GetOrdinaryHasInstance) { | 491 RUNTIME_FUNCTION(Runtime_GetOrdinaryHasInstance) { |
492 HandleScope scope(isolate); | 492 HandleScope scope(isolate); |
493 DCHECK_EQ(0, args.length()); | 493 DCHECK_EQ(0, args.length()); |
494 | 494 |
495 return isolate->native_context()->ordinary_has_instance(); | 495 return isolate->native_context()->ordinary_has_instance(); |
496 } | 496 } |
497 | 497 |
498 RUNTIME_FUNCTION(Runtime_GetAndResetRuntimeCallStats) { | 498 RUNTIME_FUNCTION(Runtime_GetAndResetRuntimeCallStats) { |
499 HandleScope scope(isolate); | 499 HandleScope scope(isolate); |
500 DCHECK_EQ(0, args.length()); | 500 if (args.length() == 0) { |
501 std::stringstream stats_stream; | 501 // Without arguments, the result is returned as a string. |
502 isolate->counters()->runtime_call_stats()->Print(stats_stream); | 502 DCHECK_EQ(0, args.length()); |
503 Handle<String> result = | 503 std::stringstream stats_stream; |
504 isolate->factory()->NewStringFromAsciiChecked(stats_stream.str().c_str()); | 504 isolate->counters()->runtime_call_stats()->Print(stats_stream); |
505 isolate->counters()->runtime_call_stats()->Reset(); | 505 Handle<String> result = isolate->factory()->NewStringFromAsciiChecked( |
506 return *result; | 506 stats_stream.str().c_str()); |
| 507 isolate->counters()->runtime_call_stats()->Reset(); |
| 508 return *result; |
| 509 } else { |
| 510 DCHECK_EQ(1, args.length()); |
| 511 std::FILE* f; |
| 512 if (args[0]->IsString()) { |
| 513 // With a string argument, the results are appended to that file. |
| 514 CONVERT_ARG_HANDLE_CHECKED(String, arg0, 0); |
| 515 String::FlatContent flat = arg0->GetFlatContent(); |
| 516 const char* filename = |
| 517 reinterpret_cast<const char*>(&(flat.ToOneByteVector()[0])); |
| 518 f = std::fopen(filename, "a"); |
| 519 DCHECK_NOT_NULL(f); |
| 520 } else { |
| 521 // With an integer argument, the results are written to stdout/stderr. |
| 522 CONVERT_SMI_ARG_CHECKED(fd, 0); |
| 523 DCHECK(fd == 1 || fd == 2); |
| 524 f = fd == 1 ? stdout : stderr; |
| 525 } |
| 526 OFStream stats_stream(f); |
| 527 isolate->counters()->runtime_call_stats()->Print(stats_stream); |
| 528 isolate->counters()->runtime_call_stats()->Reset(); |
| 529 if (args[0]->IsString()) |
| 530 std::fclose(f); |
| 531 else |
| 532 std::fflush(f); |
| 533 return isolate->heap()->undefined_value(); |
| 534 } |
507 } | 535 } |
508 | 536 |
509 RUNTIME_FUNCTION(Runtime_EnqueueMicrotask) { | 537 RUNTIME_FUNCTION(Runtime_EnqueueMicrotask) { |
510 HandleScope scope(isolate); | 538 HandleScope scope(isolate); |
511 DCHECK(args.length() == 1); | 539 DCHECK(args.length() == 1); |
512 CONVERT_ARG_HANDLE_CHECKED(JSFunction, microtask, 0); | 540 CONVERT_ARG_HANDLE_CHECKED(JSFunction, microtask, 0); |
513 isolate->EnqueueMicrotask(microtask); | 541 isolate->EnqueueMicrotask(microtask); |
514 return isolate->heap()->undefined_value(); | 542 return isolate->heap()->undefined_value(); |
515 } | 543 } |
516 | 544 |
517 RUNTIME_FUNCTION(Runtime_RunMicrotasks) { | 545 RUNTIME_FUNCTION(Runtime_RunMicrotasks) { |
518 HandleScope scope(isolate); | 546 HandleScope scope(isolate); |
519 DCHECK(args.length() == 0); | 547 DCHECK(args.length() == 0); |
520 isolate->RunMicrotasks(); | 548 isolate->RunMicrotasks(); |
521 return isolate->heap()->undefined_value(); | 549 return isolate->heap()->undefined_value(); |
522 } | 550 } |
523 } // namespace internal | 551 } // namespace internal |
524 } // namespace v8 | 552 } // namespace v8 |
OLD | NEW |