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

Side by Side Diff: src/runtime/runtime-promise.cc

Issue 2613723002: [runtime] Use DCHECK_EQ instead of DCHECK for number of args. (Closed)
Patch Set: Rebase. Created 3 years, 11 months 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/runtime/runtime-object.cc ('k') | src/runtime/runtime-proxy.cc » ('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 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 #include "src/runtime/runtime-utils.h" 4 #include "src/runtime/runtime-utils.h"
5 5
6 #include "src/debug/debug.h" 6 #include "src/debug/debug.h"
7 #include "src/elements.h" 7 #include "src/elements.h"
8 #include "src/promise-utils.h" 8 #include "src/promise-utils.h"
9 9
10 namespace v8 { 10 namespace v8 {
(...skipping 14 matching lines...) Expand all
25 // Report only if we don't actually have a handler. 25 // Report only if we don't actually have a handler.
26 if (!promise->has_handler()) { 26 if (!promise->has_handler()) {
27 isolate->ReportPromiseReject(Handle<JSObject>::cast(promise), value, 27 isolate->ReportPromiseReject(Handle<JSObject>::cast(promise), value,
28 v8::kPromiseRejectWithNoHandler); 28 v8::kPromiseRejectWithNoHandler);
29 } 29 }
30 } 30 }
31 31
32 } // namespace 32 } // namespace
33 33
34 RUNTIME_FUNCTION(Runtime_PromiseRejectEventFromStack) { 34 RUNTIME_FUNCTION(Runtime_PromiseRejectEventFromStack) {
35 DCHECK(args.length() == 2); 35 DCHECK_EQ(2, args.length());
36 HandleScope scope(isolate); 36 HandleScope scope(isolate);
37 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0); 37 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0);
38 CONVERT_ARG_HANDLE_CHECKED(Object, value, 1); 38 CONVERT_ARG_HANDLE_CHECKED(Object, value, 1);
39 39
40 Handle<Object> rejected_promise = promise; 40 Handle<Object> rejected_promise = promise;
41 if (isolate->debug()->is_active()) { 41 if (isolate->debug()->is_active()) {
42 // If the Promise.reject call is caught, then this will return 42 // If the Promise.reject call is caught, then this will return
43 // undefined, which will be interpreted by PromiseRejectEvent 43 // undefined, which will be interpreted by PromiseRejectEvent
44 // as being a caught exception event. 44 // as being a caught exception event.
45 rejected_promise = isolate->GetPromiseOnStackOnThrow(); 45 rejected_promise = isolate->GetPromiseOnStackOnThrow();
46 } 46 }
47 PromiseRejectEvent(isolate, promise, rejected_promise, value, true); 47 PromiseRejectEvent(isolate, promise, rejected_promise, value, true);
48 return isolate->heap()->undefined_value(); 48 return isolate->heap()->undefined_value();
49 } 49 }
50 50
51 RUNTIME_FUNCTION(Runtime_PromiseRevokeReject) { 51 RUNTIME_FUNCTION(Runtime_PromiseRevokeReject) {
52 DCHECK(args.length() == 1); 52 DCHECK_EQ(1, args.length());
53 HandleScope scope(isolate); 53 HandleScope scope(isolate);
54 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0); 54 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0);
55 // At this point, no revocation has been issued before 55 // At this point, no revocation has been issued before
56 CHECK(!promise->has_handler()); 56 CHECK(!promise->has_handler());
57 isolate->ReportPromiseReject(promise, Handle<Object>(), 57 isolate->ReportPromiseReject(promise, Handle<Object>(),
58 v8::kPromiseHandlerAddedAfterReject); 58 v8::kPromiseHandlerAddedAfterReject);
59 return isolate->heap()->undefined_value(); 59 return isolate->heap()->undefined_value();
60 } 60 }
61 61
62 namespace { 62 namespace {
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 isolate->native_context()); 165 isolate->native_context());
166 EnqueuePromiseReactionJob(isolate, info, status); 166 EnqueuePromiseReactionJob(isolate, info, status);
167 } 167 }
168 168
169 PromiseSet(isolate, promise, status, value); 169 PromiseSet(isolate, promise, status, value);
170 } 170 }
171 171
172 } // namespace 172 } // namespace
173 173
174 RUNTIME_FUNCTION(Runtime_PromiseReject) { 174 RUNTIME_FUNCTION(Runtime_PromiseReject) {
175 DCHECK(args.length() == 3); 175 DCHECK_EQ(3, args.length());
176 HandleScope scope(isolate); 176 HandleScope scope(isolate);
177 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0); 177 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0);
178 CONVERT_ARG_HANDLE_CHECKED(Object, reason, 1); 178 CONVERT_ARG_HANDLE_CHECKED(Object, reason, 1);
179 CONVERT_BOOLEAN_ARG_CHECKED(debug_event, 2); 179 CONVERT_BOOLEAN_ARG_CHECKED(debug_event, 2);
180 180
181 PromiseRejectEvent(isolate, promise, promise, reason, debug_event); 181 PromiseRejectEvent(isolate, promise, promise, reason, debug_event);
182 PromiseFulfill(isolate, promise, v8::Promise::kRejected, reason); 182 PromiseFulfill(isolate, promise, v8::Promise::kRejected, reason);
183 183
184 return isolate->heap()->undefined_value(); 184 return isolate->heap()->undefined_value();
185 } 185 }
186 186
187 RUNTIME_FUNCTION(Runtime_EnqueuePromiseReactionJob) { 187 RUNTIME_FUNCTION(Runtime_EnqueuePromiseReactionJob) {
188 HandleScope scope(isolate); 188 HandleScope scope(isolate);
189 DCHECK(args.length() == 2); 189 DCHECK_EQ(2, args.length());
190 CONVERT_ARG_HANDLE_CHECKED(PromiseReactionJobInfo, info, 0); 190 CONVERT_ARG_HANDLE_CHECKED(PromiseReactionJobInfo, info, 0);
191 CONVERT_SMI_ARG_CHECKED(status, 1); 191 CONVERT_SMI_ARG_CHECKED(status, 1);
192 EnqueuePromiseReactionJob(isolate, info, status); 192 EnqueuePromiseReactionJob(isolate, info, status);
193 return isolate->heap()->undefined_value(); 193 return isolate->heap()->undefined_value();
194 } 194 }
195 195
196 RUNTIME_FUNCTION(Runtime_EnqueuePromiseResolveThenableJob) { 196 RUNTIME_FUNCTION(Runtime_EnqueuePromiseResolveThenableJob) {
197 HandleScope scope(isolate); 197 HandleScope scope(isolate);
198 DCHECK(args.length() == 3); 198 DCHECK_EQ(3, args.length());
199 CONVERT_ARG_HANDLE_CHECKED(JSObject, promise, 0); 199 CONVERT_ARG_HANDLE_CHECKED(JSObject, promise, 0);
200 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, resolution, 1); 200 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, resolution, 1);
201 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, then, 2); 201 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, then, 2);
202 202
203 // TODO(gsathya): Add fast path for native promises with unmodified 203 // TODO(gsathya): Add fast path for native promises with unmodified
204 // PromiseThen (which don't need these resolving functions, but 204 // PromiseThen (which don't need these resolving functions, but
205 // instead can just call resolve/reject directly). 205 // instead can just call resolve/reject directly).
206 Handle<JSFunction> resolve, reject; 206 Handle<JSFunction> resolve, reject;
207 PromiseUtils::CreateResolvingFunctions( 207 PromiseUtils::CreateResolvingFunctions(
208 isolate, promise, isolate->factory()->false_value(), &resolve, &reject); 208 isolate, promise, isolate->factory()->false_value(), &resolve, &reject);
(...skipping 10 matching lines...) Expand all
219 isolate->factory()->NewPromiseResolveThenableJobInfo( 219 isolate->factory()->NewPromiseResolveThenableJobInfo(
220 resolution, then, resolve, reject, debug_id, debug_name, 220 resolution, then, resolve, reject, debug_id, debug_name,
221 isolate->native_context()); 221 isolate->native_context());
222 isolate->EnqueueMicrotask(info); 222 isolate->EnqueueMicrotask(info);
223 223
224 return isolate->heap()->undefined_value(); 224 return isolate->heap()->undefined_value();
225 } 225 }
226 226
227 RUNTIME_FUNCTION(Runtime_EnqueueMicrotask) { 227 RUNTIME_FUNCTION(Runtime_EnqueueMicrotask) {
228 HandleScope scope(isolate); 228 HandleScope scope(isolate);
229 DCHECK(args.length() == 1); 229 DCHECK_EQ(1, args.length());
230 CONVERT_ARG_HANDLE_CHECKED(JSFunction, microtask, 0); 230 CONVERT_ARG_HANDLE_CHECKED(JSFunction, microtask, 0);
231 isolate->EnqueueMicrotask(microtask); 231 isolate->EnqueueMicrotask(microtask);
232 return isolate->heap()->undefined_value(); 232 return isolate->heap()->undefined_value();
233 } 233 }
234 234
235 RUNTIME_FUNCTION(Runtime_RunMicrotasks) { 235 RUNTIME_FUNCTION(Runtime_RunMicrotasks) {
236 HandleScope scope(isolate); 236 HandleScope scope(isolate);
237 DCHECK(args.length() == 0); 237 DCHECK_EQ(0, args.length());
238 isolate->RunMicrotasks(); 238 isolate->RunMicrotasks();
239 return isolate->heap()->undefined_value(); 239 return isolate->heap()->undefined_value();
240 } 240 }
241 241
242 RUNTIME_FUNCTION(Runtime_CreateResolvingFunctions) { 242 RUNTIME_FUNCTION(Runtime_CreateResolvingFunctions) {
243 HandleScope scope(isolate); 243 HandleScope scope(isolate);
244 CONVERT_ARG_HANDLE_CHECKED(JSObject, promise, 0); 244 CONVERT_ARG_HANDLE_CHECKED(JSObject, promise, 0);
245 DCHECK(args.length() == 1); 245 DCHECK_EQ(1, args.length());
246 Handle<JSFunction> resolve, reject; 246 Handle<JSFunction> resolve, reject;
247 247
248 PromiseUtils::CreateResolvingFunctions( 248 PromiseUtils::CreateResolvingFunctions(
249 isolate, promise, isolate->factory()->true_value(), &resolve, &reject); 249 isolate, promise, isolate->factory()->true_value(), &resolve, &reject);
250 250
251 Handle<FixedArray> result = isolate->factory()->NewFixedArray(2); 251 Handle<FixedArray> result = isolate->factory()->NewFixedArray(2);
252 result->set(0, *resolve); 252 result->set(0, *resolve);
253 result->set(1, *reject); 253 result->set(1, *reject);
254 254
255 return *result; 255 return *result;
256 } 256 }
257 257
258 RUNTIME_FUNCTION(Runtime_PromiseStatus) { 258 RUNTIME_FUNCTION(Runtime_PromiseStatus) {
259 HandleScope scope(isolate); 259 HandleScope scope(isolate);
260 DCHECK(args.length() == 1); 260 DCHECK_EQ(1, args.length());
261 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0); 261 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0);
262 262
263 return Smi::FromInt(promise->status()); 263 return Smi::FromInt(promise->status());
264 } 264 }
265 265
266 RUNTIME_FUNCTION(Runtime_PromiseResult) { 266 RUNTIME_FUNCTION(Runtime_PromiseResult) {
267 HandleScope scope(isolate); 267 HandleScope scope(isolate);
268 DCHECK(args.length() == 1); 268 DCHECK_EQ(1, args.length());
269 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0); 269 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0);
270 return promise->result(); 270 return promise->result();
271 } 271 }
272 272
273 RUNTIME_FUNCTION(Runtime_PromiseMarkAsHandled) { 273 RUNTIME_FUNCTION(Runtime_PromiseMarkAsHandled) {
274 SealHandleScope shs(isolate); 274 SealHandleScope shs(isolate);
275 DCHECK(args.length() == 1); 275 DCHECK_EQ(1, args.length());
276 CONVERT_ARG_CHECKED(JSPromise, promise, 0); 276 CONVERT_ARG_CHECKED(JSPromise, promise, 0);
277 277
278 promise->set_has_handler(true); 278 promise->set_has_handler(true);
279 return isolate->heap()->undefined_value(); 279 return isolate->heap()->undefined_value();
280 } 280 }
281 281
282 RUNTIME_FUNCTION(Runtime_PromiseMarkHandledHint) { 282 RUNTIME_FUNCTION(Runtime_PromiseMarkHandledHint) {
283 SealHandleScope shs(isolate); 283 SealHandleScope shs(isolate);
284 DCHECK(args.length() == 1); 284 DCHECK_EQ(1, args.length());
285 CONVERT_ARG_CHECKED(JSPromise, promise, 0); 285 CONVERT_ARG_CHECKED(JSPromise, promise, 0);
286 286
287 promise->set_handled_hint(true); 287 promise->set_handled_hint(true);
288 return isolate->heap()->undefined_value(); 288 return isolate->heap()->undefined_value();
289 } 289 }
290 290
291 RUNTIME_FUNCTION(Runtime_PromiseHookInit) { 291 RUNTIME_FUNCTION(Runtime_PromiseHookInit) {
292 HandleScope scope(isolate); 292 HandleScope scope(isolate);
293 DCHECK_EQ(2, args.length()); 293 DCHECK_EQ(2, args.length());
294 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0); 294 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0);
(...skipping 24 matching lines...) Expand all
319 HandleScope scope(isolate); 319 HandleScope scope(isolate);
320 DCHECK_EQ(1, args.length()); 320 DCHECK_EQ(1, args.length());
321 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0); 321 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0);
322 isolate->RunPromiseHook(PromiseHookType::kAfter, promise, 322 isolate->RunPromiseHook(PromiseHookType::kAfter, promise,
323 isolate->factory()->undefined_value()); 323 isolate->factory()->undefined_value());
324 return isolate->heap()->undefined_value(); 324 return isolate->heap()->undefined_value();
325 } 325 }
326 326
327 } // namespace internal 327 } // namespace internal
328 } // namespace v8 328 } // namespace v8
OLDNEW
« no previous file with comments | « src/runtime/runtime-object.cc ('k') | src/runtime/runtime-proxy.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698