Index: src/promise-utils.cc |
diff --git a/src/promise-utils.cc b/src/promise-utils.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..91af73c45ce60a6b553bc09bb52d38fc76078266 |
--- /dev/null |
+++ b/src/promise-utils.cc |
@@ -0,0 +1,77 @@ |
+// Copyright 2016 the V8 project authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "src/promise-utils.h" |
+ |
+#include "src/factory.h" |
+#include "src/isolate.h" |
+#include "src/objects-inl.h" |
+ |
+namespace v8 { |
+namespace internal { |
+ |
+enum PromiseResolvingFunctionContextSlot { |
+ kAlreadyVisitedSlot = Context::MIN_CONTEXT_SLOTS, |
+ kPromiseSlot, |
+ kDebugEventSlot, |
+ kPromiseContextLength, |
+}; |
+ |
+Handle<JSObject> PromiseUtils::GetPromise(Isolate* isolate, |
adamk
2016/11/10 18:10:54
You could make these just return raw pointers, lea
gsathya
2016/11/11 02:34:37
Done.
|
+ Handle<Context> context) { |
+ return handle(JSObject::cast(context->get(PromiseUtils::kPromiseSlot)), |
adamk
2016/11/10 18:10:54
Hmm, looks like these need updating to refer to th
gsathya
2016/11/11 02:34:37
Done.
|
+ isolate); |
+} |
+ |
+Handle<Object> PromiseUtils::GetDebugEvent(Isolate* isolate, |
+ Handle<Context> context) { |
+ return handle(context->get(PromiseUtils::kDebugEventSlot), isolate); |
+} |
+ |
+Handle<Smi> PromiseUtils::GetAlreadyVisited(Isolate* isolate, |
+ Handle<Context> context) { |
+ return handle(Smi::cast(context->get(PromiseUtils::kAlreadyVisitedSlot)), |
+ isolate); |
+} |
+ |
+void PromiseUtils::SetAlreadyVisitedToTrue(Handle<Context> context) { |
+ context->set(PromiseUtils::kAlreadyVisitedSlot, Smi::FromInt(1)); |
+} |
+ |
+void PromiseUtils::CreateResolvingFunctions(Isolate* isolate, |
+ Handle<JSObject> promise, |
+ Handle<Object> debug_event, |
adamk
2016/11/10 18:10:54
Can you add the same DCHECK here for debug_event b
gsathya
2016/11/11 02:34:36
It seems redundant to have the same DCHECK in both
|
+ Handle<JSFunction>* resolve, |
+ Handle<JSFunction>* reject) { |
+ Handle<Context> context = |
+ isolate->factory()->NewPromiseResolvingFunctionContext( |
+ kPromiseContextLength); |
+ context->set_native_context(*isolate->native_context()); |
+ context->set(kAlreadyVisitedSlot, Smi::kZero); |
+ context->set(kPromiseSlot, *promise); |
+ context->set(kDebugEventSlot, *debug_event); |
+ |
+ Handle<SharedFunctionInfo> resolve_shared_fun( |
+ isolate->native_context()->promise_resolve_shared_fun(), isolate); |
+ Handle<JSFunction> resolve_fun = |
+ isolate->factory()->NewFunctionFromSharedFunctionInfo( |
+ isolate->sloppy_function_without_prototype_map(), resolve_shared_fun, |
+ isolate->native_context(), TENURED); |
+ |
+ Handle<SharedFunctionInfo> reject_shared_fun( |
+ isolate->native_context()->promise_reject_shared_fun(), isolate); |
+ Handle<JSFunction> reject_fun = |
+ isolate->factory()->NewFunctionFromSharedFunctionInfo( |
+ isolate->sloppy_function_without_prototype_map(), reject_shared_fun, |
+ isolate->native_context(), TENURED); |
+ |
+ resolve_fun->set_context(*context); |
+ reject_fun->set_context(*context); |
+ |
+ *resolve = resolve_fun; |
+ *reject = reject_fun; |
+} |
+ |
+} // namespace internal |
+} // namespace v8 |