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

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

Issue 1448933002: Introduce a BuiltinsConstructStub that sets up new.target and does a [[call]] per ES6 9.3.2 (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: More accurate regexp Created 5 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 unified diff | Download patch
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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 54
55 return { 55 return {
56 __proto__: null, 56 __proto__: null,
57 resolve: resolve, 57 resolve: resolve,
58 reject: reject 58 reject: reject
59 }; 59 };
60 } 60 }
61 61
62 62
63 var GlobalPromise = function Promise(resolver) { 63 var GlobalPromise = function Promise(resolver) {
64 if (resolver === promiseRawSymbol) return; 64 if (resolver === promiseRawSymbol) {
65 if (!%_IsConstructCall()) throw MakeTypeError(kNotAPromise, this); 65 return %NewObject(GlobalPromise, new.target);
66 }
67 if (IS_UNDEFINED(new.target)) throw MakeTypeError(kNotAPromise, this);
Igor Sheludko 2015/11/19 09:30:53 Perhaps this should be done even before checking r
Toon Verwaest 2015/11/19 09:39:53 %NewObject internally will check that new.target i
66 if (!IS_CALLABLE(resolver)) 68 if (!IS_CALLABLE(resolver))
67 throw MakeTypeError(kResolverNotAFunction, resolver); 69 throw MakeTypeError(kResolverNotAFunction, resolver);
68 var promise = PromiseInit(this); 70
71 var promise = PromiseInit(%NewObject(GlobalPromise, new.target));
72
69 try { 73 try {
70 %DebugPushPromise(promise, Promise, resolver); 74 %DebugPushPromise(promise, Promise, resolver);
71 var callbacks = CreateResolvingFunctions(promise); 75 var callbacks = CreateResolvingFunctions(promise);
72 resolver(callbacks.resolve, callbacks.reject); 76 resolver(callbacks.resolve, callbacks.reject);
73 } catch (e) { 77 } catch (e) {
74 PromiseReject(promise, e); 78 PromiseReject(promise, e);
75 } finally { 79 } finally {
76 %DebugPopPromise(); 80 %DebugPopPromise();
77 } 81 }
82
83 return promise;
78 } 84 }
79 85
80 // Core functionality. 86 // Core functionality.
81 87
82 function PromiseSet(promise, status, value, onResolve, onReject) { 88 function PromiseSet(promise, status, value, onResolve, onReject) {
83 SET_PRIVATE(promise, promiseStatusSymbol, status); 89 SET_PRIVATE(promise, promiseStatusSymbol, status);
84 SET_PRIVATE(promise, promiseValueSymbol, value); 90 SET_PRIVATE(promise, promiseValueSymbol, value);
85 SET_PRIVATE(promise, promiseOnResolveSymbol, onResolve); 91 SET_PRIVATE(promise, promiseOnResolveSymbol, onResolve);
86 SET_PRIVATE(promise, promiseOnRejectSymbol, onReject); 92 SET_PRIVATE(promise, promiseOnRejectSymbol, onReject);
87 if (DEBUG_IS_ACTIVE) { 93 if (DEBUG_IS_ACTIVE) {
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 // This allows extras to create promises quickly without building extra 473 // This allows extras to create promises quickly without building extra
468 // resolve/reject closures, and allows them to later resolve and reject any 474 // resolve/reject closures, and allows them to later resolve and reject any
469 // promise without having to hold on to those closures forever. 475 // promise without having to hold on to those closures forever.
470 utils.InstallFunctions(extrasUtils, 0, [ 476 utils.InstallFunctions(extrasUtils, 0, [
471 "createPromise", PromiseCreate, 477 "createPromise", PromiseCreate,
472 "resolvePromise", PromiseResolve, 478 "resolvePromise", PromiseResolve,
473 "rejectPromise", PromiseReject 479 "rejectPromise", PromiseReject
474 ]); 480 ]);
475 481
476 }) 482 })
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698