| OLD | NEW |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 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 | 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/promise-utils.h" | 5 #include "src/promise-utils.h" |
| 6 | 6 |
| 7 #include "src/factory.h" | 7 #include "src/factory.h" |
| 8 #include "src/isolate.h" | 8 #include "src/isolate.h" |
| 9 #include "src/objects-inl.h" | 9 #include "src/objects-inl.h" |
| 10 | 10 |
| 11 namespace v8 { | 11 namespace v8 { |
| 12 namespace internal { | 12 namespace internal { |
| 13 | 13 |
| 14 JSPromise* PromiseUtils::GetPromise(Handle<Context> context) { | 14 JSPromise* PromiseUtils::GetPromise(Handle<Context> context) { |
| 15 return JSPromise::cast(context->get(kPromiseSlot)); | 15 return JSPromise::cast(context->get(kPromiseSlot)); |
| 16 } | 16 } |
| 17 | 17 |
| 18 Object* PromiseUtils::GetDebugEvent(Handle<Context> context) { | 18 Object* PromiseUtils::GetDebugEvent(Handle<Context> context) { |
| 19 return context->get(kDebugEventSlot); | 19 return context->get(kDebugEventSlot); |
| 20 } | 20 } |
| 21 | 21 |
| 22 bool PromiseUtils::HasAlreadyVisited(Handle<Context> context) { | 22 bool PromiseUtils::HasAlreadyVisited(Handle<Context> context) { |
| 23 return Smi::cast(context->get(kAlreadyVisitedSlot))->value() != 0; | 23 return Smi::cast(context->get(kAlreadyVisitedSlot))->value() != 0; |
| 24 } | 24 } |
| 25 | 25 |
| 26 void PromiseUtils::SetAlreadyVisited(Handle<Context> context) { | 26 void PromiseUtils::SetAlreadyVisited(Handle<Context> context) { |
| 27 context->set(kAlreadyVisitedSlot, Smi::FromInt(1)); | 27 context->set(kAlreadyVisitedSlot, Smi::FromInt(1)); |
| 28 } | 28 } |
| 29 | 29 |
| 30 void PromiseUtils::CreateResolvingFunctions(Isolate* isolate, | |
| 31 Handle<JSObject> promise, | |
| 32 Handle<Object> debug_event, | |
| 33 Handle<JSFunction>* resolve, | |
| 34 Handle<JSFunction>* reject) { | |
| 35 DCHECK(debug_event->IsTrue(isolate) || debug_event->IsFalse(isolate)); | |
| 36 Handle<Context> context = | |
| 37 isolate->factory()->NewPromiseResolvingFunctionContext( | |
| 38 kPromiseContextLength); | |
| 39 context->set_native_context(*isolate->native_context()); | |
| 40 // We set the closure to be an empty function, same as native context. | |
| 41 context->set_closure(isolate->native_context()->closure()); | |
| 42 context->set(kAlreadyVisitedSlot, Smi::kZero); | |
| 43 context->set(kPromiseSlot, *promise); | |
| 44 context->set(kDebugEventSlot, *debug_event); | |
| 45 | |
| 46 Handle<SharedFunctionInfo> resolve_shared_fun( | |
| 47 isolate->native_context()->promise_resolve_shared_fun(), isolate); | |
| 48 Handle<JSFunction> resolve_fun = | |
| 49 isolate->factory()->NewFunctionFromSharedFunctionInfo( | |
| 50 isolate->sloppy_function_without_prototype_map(), resolve_shared_fun, | |
| 51 isolate->native_context(), TENURED); | |
| 52 | |
| 53 Handle<SharedFunctionInfo> reject_shared_fun( | |
| 54 isolate->native_context()->promise_reject_shared_fun(), isolate); | |
| 55 Handle<JSFunction> reject_fun = | |
| 56 isolate->factory()->NewFunctionFromSharedFunctionInfo( | |
| 57 isolate->sloppy_function_without_prototype_map(), reject_shared_fun, | |
| 58 isolate->native_context(), TENURED); | |
| 59 | |
| 60 resolve_fun->set_context(*context); | |
| 61 reject_fun->set_context(*context); | |
| 62 | |
| 63 *resolve = resolve_fun; | |
| 64 *reject = reject_fun; | |
| 65 } | |
| 66 | |
| 67 } // namespace internal | 30 } // namespace internal |
| 68 } // namespace v8 | 31 } // namespace v8 |
| OLD | NEW |