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

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

Issue 2695593002: [promises] cleanup default promise handlers (Closed)
Patch Set: remove unused var Created 3 years, 10 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 | « no previous file | src/contexts.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 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 4
5 #include "src/builtins/builtins-promise.h" 5 #include "src/builtins/builtins-promise.h"
6 #include "src/builtins/builtins-constructor.h" 6 #include "src/builtins/builtins-constructor.h"
7 #include "src/builtins/builtins-utils.h" 7 #include "src/builtins/builtins-utils.h"
8 #include "src/builtins/builtins.h" 8 #include "src/builtins/builtins.h"
9 #include "src/code-factory.h" 9 #include "src/code-factory.h"
10 #include "src/code-stub-assembler.h" 10 #include "src/code-stub-assembler.h"
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 Node* const result = InternalPerformPromiseThen( 413 Node* const result = InternalPerformPromiseThen(
414 context, promise, on_resolve, on_reject, var_deferred_promise.value(), 414 context, promise, on_resolve, on_reject, var_deferred_promise.value(),
415 var_deferred_on_resolve.value(), var_deferred_on_reject.value()); 415 var_deferred_on_resolve.value(), var_deferred_on_reject.value());
416 return result; 416 return result;
417 } 417 }
418 418
419 Node* PromiseBuiltinsAssembler::InternalPerformPromiseThen( 419 Node* PromiseBuiltinsAssembler::InternalPerformPromiseThen(
420 Node* context, Node* promise, Node* on_resolve, Node* on_reject, 420 Node* context, Node* promise, Node* on_resolve, Node* on_reject,
421 Node* deferred_promise, Node* deferred_on_resolve, 421 Node* deferred_promise, Node* deferred_on_resolve,
422 Node* deferred_on_reject) { 422 Node* deferred_on_reject) {
423 Node* const native_context = LoadNativeContext(context);
424 423
425 Variable var_on_resolve(this, MachineRepresentation::kTagged), 424 Variable var_on_resolve(this, MachineRepresentation::kTagged),
426 var_on_reject(this, MachineRepresentation::kTagged); 425 var_on_reject(this, MachineRepresentation::kTagged);
427 426
428 var_on_resolve.Bind(on_resolve); 427 var_on_resolve.Bind(on_resolve);
429 var_on_reject.Bind(on_reject); 428 var_on_reject.Bind(on_reject);
430 429
431 Label out(this), if_onresolvenotcallable(this), onrejectcheck(this), 430 Label out(this), if_onresolvenotcallable(this), onrejectcheck(this),
432 append_callbacks(this); 431 append_callbacks(this);
433 GotoIf(TaggedIsSmi(on_resolve), &if_onresolvenotcallable); 432 GotoIf(TaggedIsSmi(on_resolve), &if_onresolvenotcallable);
434 433
434 Isolate* isolate = this->isolate();
435 Node* const on_resolve_map = LoadMap(on_resolve); 435 Node* const on_resolve_map = LoadMap(on_resolve);
436 Branch(IsCallableMap(on_resolve_map), &onrejectcheck, 436 Branch(IsCallableMap(on_resolve_map), &onrejectcheck,
437 &if_onresolvenotcallable); 437 &if_onresolvenotcallable);
438 438
439 Bind(&if_onresolvenotcallable); 439 Bind(&if_onresolvenotcallable);
440 { 440 {
441 var_on_resolve.Bind(LoadContextElement( 441 Isolate* isolate = this->isolate();
442 native_context, Context::PROMISE_ID_RESOLVE_HANDLER_INDEX)); 442 Node* const default_resolve_handler_symbol = HeapConstant(
443 isolate->factory()->promise_default_resolve_handler_symbol());
444 var_on_resolve.Bind(default_resolve_handler_symbol);
443 Goto(&onrejectcheck); 445 Goto(&onrejectcheck);
444 } 446 }
445 447
446 Bind(&onrejectcheck); 448 Bind(&onrejectcheck);
447 { 449 {
448 Label if_onrejectnotcallable(this); 450 Label if_onrejectnotcallable(this);
449 GotoIf(TaggedIsSmi(on_reject), &if_onrejectnotcallable); 451 GotoIf(TaggedIsSmi(on_reject), &if_onrejectnotcallable);
450 452
451 Node* const on_reject_map = LoadMap(on_reject); 453 Node* const on_reject_map = LoadMap(on_reject);
452 Branch(IsCallableMap(on_reject_map), &append_callbacks, 454 Branch(IsCallableMap(on_reject_map), &append_callbacks,
453 &if_onrejectnotcallable); 455 &if_onrejectnotcallable);
454 456
455 Bind(&if_onrejectnotcallable); 457 Bind(&if_onrejectnotcallable);
456 { 458 {
457 var_on_reject.Bind(LoadContextElement( 459 Node* const default_reject_handler_symbol = HeapConstant(
458 native_context, Context::PROMISE_ID_REJECT_HANDLER_INDEX)); 460 isolate->factory()->promise_default_reject_handler_symbol());
461 var_on_reject.Bind(default_reject_handler_symbol);
459 Goto(&append_callbacks); 462 Goto(&append_callbacks);
460 } 463 }
461 } 464 }
462 465
463 Bind(&append_callbacks); 466 Bind(&append_callbacks);
464 { 467 {
465 Label fulfilled_check(this); 468 Label fulfilled_check(this);
466 Node* const status = LoadObjectField(promise, JSPromise::kStatusOffset); 469 Node* const status = LoadObjectField(promise, JSPromise::kStatusOffset);
467 GotoUnless(SmiEqual(status, SmiConstant(v8::Promise::kPending)), 470 GotoUnless(SmiEqual(status, SmiConstant(v8::Promise::kPending)),
468 &fulfilled_check); 471 &fulfilled_check);
(...skipping 789 matching lines...) Expand 10 before | Expand all | Expand 10 after
1258 1261
1259 Bind(&promisehook_before); 1262 Bind(&promisehook_before);
1260 { 1263 {
1261 GotoUnless(IsPromiseHookEnabledOrDebugIsActive(), &run_handler); 1264 GotoUnless(IsPromiseHookEnabledOrDebugIsActive(), &run_handler);
1262 CallRuntime(Runtime::kPromiseHookBefore, context, deferred_promise); 1265 CallRuntime(Runtime::kPromiseHookBefore, context, deferred_promise);
1263 Goto(&run_handler); 1266 Goto(&run_handler);
1264 } 1267 }
1265 1268
1266 Bind(&run_handler); 1269 Bind(&run_handler);
1267 { 1270 {
1268 Callable call_callable = CodeFactory::Call(isolate); 1271 Label if_defaulthandler(this), if_callablehandler(this),
1269 Node* const result = 1272 if_internalhandler(this), if_customhandler(this, Label::kDeferred);
1270 CallJS(call_callable, context, handler, UndefinedConstant(), value); 1273 Variable var_result(this, MachineRepresentation::kTagged);
1271 1274
1272 GotoIfException(result, &if_rejectpromise, &var_reason); 1275 Branch(IsSymbol(handler), &if_defaulthandler, &if_callablehandler);
1273 1276
1274 Label if_internalhandler(this), if_customhandler(this, Label::kDeferred); 1277 Bind(&if_defaulthandler);
1275 Branch(IsUndefined(deferred_on_resolve), &if_internalhandler, 1278 {
1276 &if_customhandler); 1279 Label if_resolve(this), if_reject(this);
1280 Node* const default_resolve_handler_symbol = HeapConstant(
1281 isolate->factory()->promise_default_resolve_handler_symbol());
1282 Branch(WordEqual(default_resolve_handler_symbol, handler), &if_resolve,
1283 &if_reject);
1284
1285 Bind(&if_resolve);
1286 {
1287 var_result.Bind(value);
1288 Branch(IsUndefined(deferred_on_resolve), &if_internalhandler,
1289 &if_customhandler);
1290 }
1291
1292 Bind(&if_reject);
1293 {
1294 var_reason.Bind(value);
1295 Goto(&if_rejectpromise);
1296 }
1297 }
1298
1299 Bind(&if_callablehandler);
1300 {
1301 Callable call_callable = CodeFactory::Call(isolate);
1302 Node* const result =
1303 CallJS(call_callable, context, handler, UndefinedConstant(), value);
1304 var_result.Bind(result);
1305 GotoIfException(result, &if_rejectpromise, &var_reason);
1306 Branch(IsUndefined(deferred_on_resolve), &if_internalhandler,
1307 &if_customhandler);
1308 }
1277 1309
1278 Bind(&if_internalhandler); 1310 Bind(&if_internalhandler);
1279 InternalResolvePromise(context, deferred_promise, result); 1311 InternalResolvePromise(context, deferred_promise, var_result.value());
1280 Goto(&promisehook_after); 1312 Goto(&promisehook_after);
1281 1313
1282 Bind(&if_customhandler); 1314 Bind(&if_customhandler);
1283 { 1315 {
1316 Callable call_callable = CodeFactory::Call(isolate);
1284 Node* const maybe_exception = 1317 Node* const maybe_exception =
1285 CallJS(call_callable, context, deferred_on_resolve, 1318 CallJS(call_callable, context, deferred_on_resolve,
1286 UndefinedConstant(), result); 1319 UndefinedConstant(), var_result.value());
1287 GotoIfException(maybe_exception, &if_rejectpromise, &var_reason); 1320 GotoIfException(maybe_exception, &if_rejectpromise, &var_reason);
1288 Goto(&promisehook_after); 1321 Goto(&promisehook_after);
1289 } 1322 }
1290 } 1323 }
1291 1324
1292 Bind(&if_rejectpromise); 1325 Bind(&if_rejectpromise);
1293 { 1326 {
1294 Callable promise_handle_reject = CodeFactory::PromiseHandleReject(isolate); 1327 Callable promise_handle_reject = CodeFactory::PromiseHandleReject(isolate);
1295 CallStub(promise_handle_reject, context, deferred_promise, 1328 CallStub(promise_handle_reject, context, deferred_promise,
1296 deferred_on_reject, var_reason.value()); 1329 deferred_on_reject, var_reason.value());
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
1526 Node* const reason = Parameter(2); 1559 Node* const reason = Parameter(2);
1527 Node* const debug_event = Parameter(3); 1560 Node* const debug_event = Parameter(3);
1528 Node* const context = Parameter(6); 1561 Node* const context = Parameter(6);
1529 1562
1530 InternalPromiseReject(context, promise, reason, debug_event); 1563 InternalPromiseReject(context, promise, reason, debug_event);
1531 Return(UndefinedConstant()); 1564 Return(UndefinedConstant());
1532 } 1565 }
1533 1566
1534 } // namespace internal 1567 } // namespace internal
1535 } // namespace v8 1568 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | src/contexts.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698