summaryrefslogtreecommitdiffstats
path: root/src/builtins/builtins-promise.cc
diff options
context:
space:
mode:
authorBen Murdoch <benm@google.com>2017-03-08 14:04:23 +0000
committerBen Murdoch <benm@google.com>2017-03-13 15:00:19 +0000
commitc8c1d9e03f4babd16833b0f8ccf6aab5fa6e8c7a (patch)
tree0626f6eea22bedac0b27890e0a710e790758a92d /src/builtins/builtins-promise.cc
parent3ed978da7c05e4bc0a6b95033aeea85c7e480adf (diff)
downloadandroid_external_v8-c8c1d9e03f4babd16833b0f8ccf6aab5fa6e8c7a.tar.gz
android_external_v8-c8c1d9e03f4babd16833b0f8ccf6aab5fa6e8c7a.tar.bz2
android_external_v8-c8c1d9e03f4babd16833b0f8ccf6aab5fa6e8c7a.zip
Merge V8 5.6.326.50
Test: manual, ran D8, tested connecting through PAC proxy. Change-Id: I6067097f8ded999e9930a7dfd2fdc3733d7c6284
Diffstat (limited to 'src/builtins/builtins-promise.cc')
-rw-r--r--src/builtins/builtins-promise.cc84
1 files changed, 84 insertions, 0 deletions
diff --git a/src/builtins/builtins-promise.cc b/src/builtins/builtins-promise.cc
new file mode 100644
index 00000000..9f5d7c88
--- /dev/null
+++ b/src/builtins/builtins-promise.cc
@@ -0,0 +1,84 @@
+// 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/builtins/builtins-utils.h"
+#include "src/builtins/builtins.h"
+
+#include "src/promise-utils.h"
+
+namespace v8 {
+namespace internal {
+
+// ES#sec-promise-resolve-functions
+// Promise Resolve Functions
+BUILTIN(PromiseResolveClosure) {
+ HandleScope scope(isolate);
+
+ Handle<Context> context(isolate->context(), isolate);
+
+ if (PromiseUtils::HasAlreadyVisited(context)) {
+ return isolate->heap()->undefined_value();
+ }
+
+ PromiseUtils::SetAlreadyVisited(context);
+ Handle<JSObject> promise = handle(PromiseUtils::GetPromise(context), isolate);
+ Handle<Object> value = args.atOrUndefined(isolate, 1);
+
+ MaybeHandle<Object> maybe_result;
+ Handle<Object> argv[] = {promise, value};
+ RETURN_FAILURE_ON_EXCEPTION(
+ isolate, Execution::Call(isolate, isolate->promise_resolve(),
+ isolate->factory()->undefined_value(),
+ arraysize(argv), argv));
+ return isolate->heap()->undefined_value();
+}
+
+// ES#sec-promise-reject-functions
+// Promise Reject Functions
+BUILTIN(PromiseRejectClosure) {
+ HandleScope scope(isolate);
+
+ Handle<Context> context(isolate->context(), isolate);
+
+ if (PromiseUtils::HasAlreadyVisited(context)) {
+ return isolate->heap()->undefined_value();
+ }
+
+ PromiseUtils::SetAlreadyVisited(context);
+ Handle<Object> value = args.atOrUndefined(isolate, 1);
+ Handle<JSObject> promise = handle(PromiseUtils::GetPromise(context), isolate);
+ Handle<Object> debug_event =
+ handle(PromiseUtils::GetDebugEvent(context), isolate);
+ MaybeHandle<Object> maybe_result;
+ Handle<Object> argv[] = {promise, value, debug_event};
+ RETURN_FAILURE_ON_EXCEPTION(
+ isolate, Execution::Call(isolate, isolate->promise_internal_reject(),
+ isolate->factory()->undefined_value(),
+ arraysize(argv), argv));
+ return isolate->heap()->undefined_value();
+}
+
+// ES#sec-createresolvingfunctions
+// CreateResolvingFunctions ( promise )
+BUILTIN(CreateResolvingFunctions) {
+ HandleScope scope(isolate);
+ DCHECK_EQ(3, args.length());
+
+ Handle<JSObject> promise = args.at<JSObject>(1);
+ Handle<Object> debug_event = args.at<Object>(2);
+ Handle<JSFunction> resolve, reject;
+
+ PromiseUtils::CreateResolvingFunctions(isolate, promise, debug_event,
+ &resolve, &reject);
+
+ Handle<FixedArray> result = isolate->factory()->NewFixedArray(2);
+ result->set(0, *resolve);
+ result->set(1, *reject);
+
+ return *isolate->factory()->NewJSArrayWithElements(result, FAST_ELEMENTS, 2,
+ NOT_TENURED);
+}
+
+} // namespace internal
+} // namespace v8