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

Side by Side Diff: src/js/promise.js

Issue 2575313002: [promisehook] Implement PromiseHook (Closed)
Patch Set: rebase + add comments Created 4 years 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 unified diff | Download patch
« no previous file with comments | « src/js/async-await.js ('k') | src/promise-utils.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 (function(global, utils, extrasUtils) { 5 (function(global, utils, extrasUtils) {
6 6
7 "use strict"; 7 "use strict";
8 8
9 %CheckIsBootstrapping(); 9 %CheckIsBootstrapping();
10 10
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 function PromiseIdRejectHandler(r) { %_ReThrow(r); } 69 function PromiseIdRejectHandler(r) { %_ReThrow(r); }
70 SET_PRIVATE(PromiseIdRejectHandler, promiseForwardingHandlerSymbol, true); 70 SET_PRIVATE(PromiseIdRejectHandler, promiseForwardingHandlerSymbol, true);
71 71
72 // ------------------------------------------------------------------- 72 // -------------------------------------------------------------------
73 // Define exported functions. 73 // Define exported functions.
74 74
75 // For bootstrapper. 75 // For bootstrapper.
76 76
77 // This is used by utils and v8-extras. 77 // This is used by utils and v8-extras.
78 function PromiseCreate() { 78 function PromiseCreate() {
79 return %promise_internal_constructor(); 79 return %promise_internal_constructor(UNDEFINED);
80 } 80 }
81 81
82 // Only used by async-await.js 82 // Only used by async-await.js
83 function RejectPromise(promise, reason, debugEvent) { 83 function RejectPromise(promise, reason, debugEvent) {
84 %PromiseReject(promise, reason, debugEvent); 84 %PromiseReject(promise, reason, debugEvent);
85 } 85 }
86 86
87 // Export to bindings 87 // Export to bindings
88 function DoRejectPromise(promise, reason) { 88 function DoRejectPromise(promise, reason) {
89 %PromiseReject(promise, reason, true); 89 %PromiseReject(promise, reason, true);
90 } 90 }
91 91
92 // The resultCapability.promise is only ever fulfilled internally, 92 // The resultCapability.promise is only ever fulfilled internally,
93 // so we don't need the closures to protect against accidentally 93 // so we don't need the closures to protect against accidentally
94 // calling them multiple times. 94 // calling them multiple times.
95 function CreateInternalPromiseCapability() { 95 function CreateInternalPromiseCapability(parent) {
96 return { 96 return {
97 promise: %promise_internal_constructor(), 97 promise: %promise_internal_constructor(parent),
98 resolve: UNDEFINED, 98 resolve: UNDEFINED,
99 reject: UNDEFINED 99 reject: UNDEFINED
100 }; 100 };
101 } 101 }
102 102
103 // ES#sec-newpromisecapability 103 // ES#sec-newpromisecapability
104 // NewPromiseCapability ( C ) 104 // NewPromiseCapability ( C )
105 function NewPromiseCapability(C, debugEvent) { 105 function NewPromiseCapability(C, debugEvent) {
106 if (C === GlobalPromise) { 106 if (C === GlobalPromise) {
107 // Optimized case, avoid extra closure. 107 // Optimized case, avoid extra closure.
108 var promise = %promise_internal_constructor(); 108 var promise = %promise_internal_constructor(UNDEFINED);
109 // TODO(gsathya): Remove container for callbacks when this is 109 // TODO(gsathya): Remove container for callbacks when this is
110 // moved to CPP/TF. 110 // moved to CPP/TF.
111 var callbacks = %create_resolving_functions(promise, debugEvent); 111 var callbacks = %create_resolving_functions(promise, debugEvent);
112 return { 112 return {
113 promise: promise, 113 promise: promise,
114 resolve: callbacks[kResolveCallback], 114 resolve: callbacks[kResolveCallback],
115 reject: callbacks[kRejectCallback] 115 reject: callbacks[kRejectCallback]
116 }; 116 };
117 } 117 }
118 118
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 // ES#sec-promise.resolve 161 // ES#sec-promise.resolve
162 // Promise.resolve ( x ) 162 // Promise.resolve ( x )
163 function PromiseResolve(x) { 163 function PromiseResolve(x) {
164 if (!IS_RECEIVER(this)) { 164 if (!IS_RECEIVER(this)) {
165 throw %make_type_error(kCalledOnNonObject, PromiseResolve); 165 throw %make_type_error(kCalledOnNonObject, PromiseResolve);
166 } 166 }
167 if (%is_promise(x) && x.constructor === this) return x; 167 if (%is_promise(x) && x.constructor === this) return x;
168 168
169 // Avoid creating resolving functions. 169 // Avoid creating resolving functions.
170 if (this === GlobalPromise) { 170 if (this === GlobalPromise) {
171 var promise = %promise_internal_constructor(); 171 var promise = %promise_internal_constructor(UNDEFINED);
172 %promise_resolve(promise, x); 172 %promise_resolve(promise, x);
173 return promise; 173 return promise;
174 } 174 }
175 175
176 // debugEvent is not so meaningful here as it will be resolved 176 // debugEvent is not so meaningful here as it will be resolved
177 var promiseCapability = NewPromiseCapability(this, true); 177 var promiseCapability = NewPromiseCapability(this, true);
178 %_Call(promiseCapability.resolve, UNDEFINED, x); 178 %_Call(promiseCapability.resolve, UNDEFINED, x);
179 return promiseCapability.promise; 179 return promiseCapability.promise;
180 } 180 }
181 181
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 387
388 utils.Export(function(to) { 388 utils.Export(function(to) {
389 to.PromiseCreate = PromiseCreate; 389 to.PromiseCreate = PromiseCreate;
390 to.PromiseThen = PromiseThen; 390 to.PromiseThen = PromiseThen;
391 391
392 to.CreateInternalPromiseCapability = CreateInternalPromiseCapability; 392 to.CreateInternalPromiseCapability = CreateInternalPromiseCapability;
393 to.RejectPromise = RejectPromise; 393 to.RejectPromise = RejectPromise;
394 }); 394 });
395 395
396 }) 396 })
OLDNEW
« no previous file with comments | « src/js/async-await.js ('k') | src/promise-utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698