Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 #include "src/builtins/builtins-utils.h" | |
| 5 #include "src/builtins/builtins.h" | |
| 6 | |
| 7 namespace v8 { | |
| 8 namespace internal { | |
| 9 | |
| 10 enum PromiseResolvingFunctionContextSlot { | |
| 11 kAlreadyVisitedSlot = Context::MIN_CONTEXT_SLOTS, | |
| 12 kPromiseSlot, | |
| 13 kDebugEventSlot, | |
| 14 kLength, | |
| 15 }; | |
| 16 | |
| 17 // ES#sec-promise-resolve-functions | |
| 18 // Promise Resolve Functions | |
| 19 BUILTIN(PromiseResolveClosure) { | |
| 20 HandleScope scope(isolate); | |
| 21 | |
| 22 Handle<Context> context(isolate->context(), isolate); | |
| 23 Handle<Smi> already_visited(Smi::cast(context->get(kAlreadyVisitedSlot)), | |
| 24 isolate); | |
| 25 | |
| 26 if (already_visited->value() != 0) { | |
| 27 return isolate->heap()->undefined_value(); | |
| 28 } | |
| 29 | |
| 30 context->set(kAlreadyVisitedSlot, Smi::FromInt(1)); | |
| 31 Handle<JSObject> promise(JSObject::cast(context->get(kPromiseSlot)), isolate); | |
| 32 Handle<Object> value = args.atOrUndefined(isolate, 1); | |
| 33 | |
| 34 MaybeHandle<Object> maybe_result; | |
| 35 Handle<Object> argv[] = {promise, value}; | |
| 36 RETURN_FAILURE_ON_EXCEPTION( | |
| 37 isolate, Execution::Call(isolate, isolate->promise_resolve(), | |
|
Benedikt Meurer
2016/11/09 05:14:30
This is probably a lot slower than the previous JS
gsathya
2016/11/09 15:57:44
Yes. A follow up patch will move PromiseResolve to
| |
| 38 isolate->factory()->undefined_value(), | |
| 39 arraysize(argv), argv)); | |
| 40 return isolate->heap()->undefined_value(); | |
| 41 } | |
| 42 | |
| 43 // ES#sec-promise-reject-functions | |
| 44 // Promise Reject Functions | |
| 45 BUILTIN(PromiseRejectClosure) { | |
| 46 HandleScope scope(isolate); | |
| 47 | |
| 48 Handle<Context> context(isolate->context(), isolate); | |
| 49 Handle<Smi> already_visited(Smi::cast(context->get(kAlreadyVisitedSlot)), | |
| 50 isolate); | |
| 51 | |
| 52 if (already_visited->value() != 0) { | |
| 53 return isolate->heap()->undefined_value(); | |
| 54 } | |
| 55 | |
| 56 context->set(kAlreadyVisitedSlot, Smi::FromInt(1)); | |
| 57 | |
| 58 Handle<Object> value = args.atOrUndefined(isolate, 1); | |
| 59 Handle<JSObject> promise(JSObject::cast(context->get(kPromiseSlot)), isolate); | |
| 60 Handle<Object> debug_event(context->get(kDebugEventSlot), isolate); | |
| 61 MaybeHandle<Object> maybe_result; | |
| 62 Handle<Object> argv[] = {promise, value, debug_event}; | |
| 63 RETURN_FAILURE_ON_EXCEPTION( | |
| 64 isolate, Execution::Call(isolate, isolate->promise_internal_reject(), | |
|
Benedikt Meurer
2016/11/09 05:14:30
Same here.
gsathya
2016/11/09 15:57:44
Yeah, follow up patch will move PromiseReject to c
| |
| 65 isolate->factory()->undefined_value(), | |
| 66 arraysize(argv), argv)); | |
| 67 return isolate->heap()->undefined_value(); | |
| 68 } | |
| 69 | |
| 70 // ES#sec-createresolvingfunctions | |
| 71 // CreateResolvingFunctions ( promise ) | |
| 72 BUILTIN(CreateResolvingFunctions) { | |
| 73 HandleScope scope(isolate); | |
| 74 DCHECK_EQ(3, args.length()); | |
| 75 | |
| 76 Handle<JSObject> promise = args.at<JSObject>(1); | |
| 77 Handle<Object> debug_event = args.at<Object>(2); | |
| 78 | |
| 79 Handle<Context> context = | |
| 80 isolate->factory()->NewPromiseResolvingFunctionContext(kLength); | |
| 81 context->set_native_context(*isolate->native_context()); | |
| 82 context->set(kAlreadyVisitedSlot, Smi::kZero); | |
| 83 context->set(kPromiseSlot, *promise); | |
| 84 context->set(kDebugEventSlot, *debug_event); | |
| 85 | |
| 86 Handle<SharedFunctionInfo> resolve_shared_fun( | |
| 87 isolate->native_context()->promise_resolve_shared_fun(), isolate); | |
| 88 Handle<JSFunction> resolve = | |
| 89 isolate->factory()->NewFunctionFromSharedFunctionInfo( | |
| 90 isolate->sloppy_function_without_prototype_map(), resolve_shared_fun, | |
| 91 isolate->native_context(), TENURED); | |
| 92 | |
| 93 Handle<SharedFunctionInfo> reject_shared_fun( | |
| 94 isolate->native_context()->promise_reject_shared_fun(), isolate); | |
| 95 Handle<JSFunction> reject = | |
| 96 isolate->factory()->NewFunctionFromSharedFunctionInfo( | |
| 97 isolate->sloppy_function_without_prototype_map(), reject_shared_fun, | |
| 98 isolate->native_context(), TENURED); | |
| 99 | |
| 100 resolve->set_context(*context); | |
| 101 reject->set_context(*context); | |
| 102 | |
| 103 Handle<FixedArray> result = isolate->factory()->NewFixedArray(2); | |
| 104 result->set(0, *resolve); | |
| 105 result->set(1, *reject); | |
| 106 | |
| 107 return *isolate->factory()->NewJSArrayWithElements(result, FAST_ELEMENTS, 2, | |
| 108 NOT_TENURED); | |
| 109 } | |
| 110 | |
| 111 } // namespace internal | |
| 112 } // namespace v8 | |
| OLD | NEW |