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 <memory> | 7 #include <memory> |
8 | 8 |
9 #include "src/arguments.h" | 9 #include "src/arguments.h" |
10 #include "src/ast/prettyprinter.h" | 10 #include "src/ast/prettyprinter.h" |
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
565 isolate->counters()->runtime_call_stats()->Print(stats_stream); | 565 isolate->counters()->runtime_call_stats()->Print(stats_stream); |
566 isolate->counters()->runtime_call_stats()->Reset(); | 566 isolate->counters()->runtime_call_stats()->Reset(); |
567 if (args[0]->IsString()) | 567 if (args[0]->IsString()) |
568 std::fclose(f); | 568 std::fclose(f); |
569 else | 569 else |
570 std::fflush(f); | 570 std::fflush(f); |
571 return isolate->heap()->undefined_value(); | 571 return isolate->heap()->undefined_value(); |
572 } | 572 } |
573 } | 573 } |
574 | 574 |
575 RUNTIME_FUNCTION(Runtime_EnqueuePromiseReactionJob) { | 575 namespace { |
576 HandleScope scope(isolate); | 576 void EnqueuePromiseReactionJob(Isolate* isolate, Handle<Object> value, |
577 DCHECK(args.length() == 4); | 577 Handle<Object> tasks, Handle<Object> deferred, |
578 CONVERT_ARG_HANDLE_CHECKED(Object, value, 0); | 578 Handle<Object> status) { |
579 CONVERT_ARG_HANDLE_CHECKED(Object, tasks, 1); | |
580 CONVERT_ARG_HANDLE_CHECKED(Object, deferred, 2); | |
581 CONVERT_ARG_HANDLE_CHECKED(Object, status, 3); | |
582 Handle<Object> debug_id = isolate->factory()->undefined_value(); | 579 Handle<Object> debug_id = isolate->factory()->undefined_value(); |
583 Handle<Object> debug_name = isolate->factory()->undefined_value(); | 580 Handle<Object> debug_name = isolate->factory()->undefined_value(); |
584 if (isolate->debug()->is_active()) { | 581 if (isolate->debug()->is_active()) { |
| 582 MaybeHandle<Object> maybe_result; |
585 Handle<Object> argv[] = {deferred, status}; | 583 Handle<Object> argv[] = {deferred, status}; |
586 MaybeHandle<Object> maybe_result = Execution::TryCall( | 584 maybe_result = Execution::TryCall( |
587 isolate, isolate->promise_debug_get_info(), | 585 isolate, isolate->promise_debug_get_info(), |
588 isolate->factory()->undefined_value(), arraysize(argv), argv); | 586 isolate->factory()->undefined_value(), arraysize(argv), argv); |
589 Handle<Object> result; | 587 Handle<Object> result; |
590 if ((maybe_result).ToHandle(&result)) { | 588 if ((maybe_result).ToHandle(&result)) { |
591 CHECK(result->IsJSArray()); | 589 CHECK(result->IsJSArray()); |
592 Handle<JSArray> array = Handle<JSArray>::cast(result); | 590 Handle<JSArray> array = Handle<JSArray>::cast(result); |
593 ElementsAccessor* accessor = array->GetElementsAccessor(); | 591 ElementsAccessor* accessor = array->GetElementsAccessor(); |
594 DCHECK(accessor->HasElement(array, 0)); | 592 DCHECK(accessor->HasElement(array, 0)); |
595 DCHECK(accessor->HasElement(array, 1)); | 593 DCHECK(accessor->HasElement(array, 1)); |
596 debug_id = accessor->Get(array, 0); | 594 debug_id = accessor->Get(array, 0); |
597 debug_name = accessor->Get(array, 1); | 595 debug_name = accessor->Get(array, 1); |
598 } | 596 } |
599 } | 597 } |
600 Handle<PromiseReactionJobInfo> info = | 598 Handle<PromiseReactionJobInfo> info = |
601 isolate->factory()->NewPromiseReactionJobInfo(value, tasks, deferred, | 599 isolate->factory()->NewPromiseReactionJobInfo(value, tasks, deferred, |
602 debug_id, debug_name, | 600 debug_id, debug_name, |
603 isolate->native_context()); | 601 isolate->native_context()); |
604 isolate->EnqueueMicrotask(info); | 602 isolate->EnqueueMicrotask(info); |
| 603 } |
| 604 } // namespace |
| 605 |
| 606 RUNTIME_FUNCTION(Runtime_PromiseFulfill) { |
| 607 DCHECK(args.length() == 4); |
| 608 HandleScope scope(isolate); |
| 609 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, promise, 0); |
| 610 CONVERT_ARG_HANDLE_CHECKED(Smi, status, 1); |
| 611 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); |
| 612 CONVERT_ARG_HANDLE_CHECKED(Symbol, reaction, 3); |
| 613 Handle<Object> tasks = JSReceiver::GetDataProperty(promise, reaction); |
| 614 if (!tasks->IsUndefined(isolate)) { |
| 615 Handle<Object> deferred = JSReceiver::GetDataProperty( |
| 616 promise, isolate->factory()->promise_deferred_reaction_symbol()); |
| 617 EnqueuePromiseReactionJob(isolate, value, tasks, deferred, status); |
| 618 } |
605 return isolate->heap()->undefined_value(); | 619 return isolate->heap()->undefined_value(); |
606 } | 620 } |
607 | 621 |
| 622 RUNTIME_FUNCTION(Runtime_EnqueuePromiseReactionJob) { |
| 623 HandleScope scope(isolate); |
| 624 DCHECK(args.length() == 4); |
| 625 CONVERT_ARG_HANDLE_CHECKED(Object, value, 0); |
| 626 CONVERT_ARG_HANDLE_CHECKED(Object, tasks, 1); |
| 627 CONVERT_ARG_HANDLE_CHECKED(Object, deferred, 2); |
| 628 CONVERT_ARG_HANDLE_CHECKED(Object, status, 3); |
| 629 EnqueuePromiseReactionJob(isolate, value, tasks, deferred, status); |
| 630 return isolate->heap()->undefined_value(); |
| 631 } |
| 632 |
608 RUNTIME_FUNCTION(Runtime_EnqueuePromiseResolveThenableJob) { | 633 RUNTIME_FUNCTION(Runtime_EnqueuePromiseResolveThenableJob) { |
609 HandleScope scope(isolate); | 634 HandleScope scope(isolate); |
610 DCHECK(args.length() == 4); | 635 DCHECK(args.length() == 4); |
611 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, resolution, 0); | 636 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, resolution, 0); |
612 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, then, 1); | 637 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, then, 1); |
613 CONVERT_ARG_HANDLE_CHECKED(JSFunction, resolve, 2); | 638 CONVERT_ARG_HANDLE_CHECKED(JSFunction, resolve, 2); |
614 CONVERT_ARG_HANDLE_CHECKED(JSFunction, reject, 3); | 639 CONVERT_ARG_HANDLE_CHECKED(JSFunction, reject, 3); |
615 Handle<Object> debug_id; | 640 Handle<Object> debug_id; |
616 Handle<Object> debug_name; | 641 Handle<Object> debug_name; |
617 if (isolate->debug()->is_active()) { | 642 if (isolate->debug()->is_active()) { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
667 | 692 |
668 RUNTIME_FUNCTION(Runtime_Typeof) { | 693 RUNTIME_FUNCTION(Runtime_Typeof) { |
669 HandleScope scope(isolate); | 694 HandleScope scope(isolate); |
670 DCHECK_EQ(1, args.length()); | 695 DCHECK_EQ(1, args.length()); |
671 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); | 696 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); |
672 return *Object::TypeOf(isolate, object); | 697 return *Object::TypeOf(isolate, object); |
673 } | 698 } |
674 | 699 |
675 } // namespace internal | 700 } // namespace internal |
676 } // namespace v8 | 701 } // namespace v8 |
OLD | NEW |