Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1419)

Unified Diff: src/promise-utils.cc

Issue 2487053002: [promises] Remove one runtime call to create_resolving_functions (Closed)
Patch Set: add dcheck Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/promise-utils.h ('k') | src/runtime/runtime.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/promise-utils.cc
diff --git a/src/promise-utils.cc b/src/promise-utils.cc
new file mode 100644
index 0000000000000000000000000000000000000000..fa5213463b6f4709f181578797af279ba6702d73
--- /dev/null
+++ b/src/promise-utils.cc
@@ -0,0 +1,73 @@
+// 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,
+};
+
+JSObject* PromiseUtils::GetPromise(Handle<Context> context) {
+ return JSObject::cast(context->get(kPromiseSlot));
+}
+
+Object* PromiseUtils::GetDebugEvent(Handle<Context> context) {
+ return context->get(kDebugEventSlot);
+}
+
+bool PromiseUtils::HasAlreadyVisited(Handle<Context> context) {
+ return Smi::cast(context->get(kAlreadyVisitedSlot))->value() != 0;
+}
+
+void PromiseUtils::SetAlreadyVisited(Handle<Context> context) {
+ context->set(kAlreadyVisitedSlot, Smi::FromInt(1));
+}
+
+void PromiseUtils::CreateResolvingFunctions(Isolate* isolate,
+ Handle<JSObject> promise,
+ Handle<Object> debug_event,
+ Handle<JSFunction>* resolve,
+ Handle<JSFunction>* reject) {
+ DCHECK(debug_event->IsTrue(isolate) || debug_event->IsFalse(isolate));
+ 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
« no previous file with comments | « src/promise-utils.h ('k') | src/runtime/runtime.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698