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

Side by Side Diff: src/promise.js

Issue 486763002: Make all global private symbols own symbols. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Rename Created 6 years, 4 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 | Annotate | Revision Log
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 "use strict"; 5 "use strict";
6 6
7 // This file relies on the fact that the following declaration has been made 7 // This file relies on the fact that the following declaration has been made
8 // in runtime.js: 8 // in runtime.js:
9 // var $Object = global.Object 9 // var $Object = global.Object
10 // var $WeakMap = global.WeakMap 10 // var $WeakMap = global.WeakMap
11 11
12 // For bootstrapper. 12 // For bootstrapper.
13 13
14 var IsPromise; 14 var IsPromise;
15 var PromiseCreate; 15 var PromiseCreate;
16 var PromiseResolve; 16 var PromiseResolve;
17 var PromiseReject; 17 var PromiseReject;
18 var PromiseChain; 18 var PromiseChain;
19 var PromiseCatch; 19 var PromiseCatch;
20 var PromiseThen; 20 var PromiseThen;
21 var PromiseHasRejectHandler; 21 var PromiseHasRejectHandler;
22 22
23 // mirror-debugger.js currently uses builtins.promiseStatus. It would be nice 23 // mirror-debugger.js currently uses builtins.promiseStatus. It would be nice
24 // if we could move these property names into the closure below. 24 // if we could move these property names into the closure below.
25 // TODO(jkummerow/rossberg/yangguo): Find a better solution. 25 // TODO(jkummerow/rossberg/yangguo): Find a better solution.
26 26
27 // Status values: 0 = pending, +1 = resolved, -1 = rejected 27 // Status values: 0 = pending, +1 = resolved, -1 = rejected
28 var promiseStatus = GLOBAL_PRIVATE("Promise#status"); 28 var promiseStatus = GLOBAL_PRIVATE_OWN("Promise#status");
29 var promiseValue = GLOBAL_PRIVATE("Promise#value"); 29 var promiseValue = GLOBAL_PRIVATE_OWN("Promise#value");
30 var promiseOnResolve = GLOBAL_PRIVATE("Promise#onResolve"); 30 var promiseOnResolve = GLOBAL_PRIVATE_OWN("Promise#onResolve");
31 var promiseOnReject = GLOBAL_PRIVATE("Promise#onReject"); 31 var promiseOnReject = GLOBAL_PRIVATE_OWN("Promise#onReject");
32 var promiseRaw = GLOBAL_PRIVATE("Promise#raw"); 32 var promiseRaw = GLOBAL_PRIVATE_OWN("Promise#raw");
33 var promiseDebug = GLOBAL_PRIVATE("Promise#debug"); 33 var promiseDebug = GLOBAL_PRIVATE_OWN("Promise#debug");
34 var lastMicrotaskId = 0; 34 var lastMicrotaskId = 0;
35 35
36 (function() { 36 (function() {
37 37
38 var $Promise = function Promise(resolver) { 38 var $Promise = function Promise(resolver) {
39 if (resolver === promiseRaw) return; 39 if (resolver === promiseRaw) return;
40 if (!%_IsConstructCall()) throw MakeTypeError('not_a_promise', [this]); 40 if (!%_IsConstructCall()) throw MakeTypeError('not_a_promise', [this]);
41 if (!IS_SPEC_FUNCTION(resolver)) 41 if (!IS_SPEC_FUNCTION(resolver))
42 throw MakeTypeError('resolver_not_a_function', [resolver]); 42 throw MakeTypeError('resolver_not_a_function', [resolver]);
43 var promise = PromiseInit(this); 43 var promise = PromiseInit(this);
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 function PromiseIdRejectHandler(r) { throw r } 139 function PromiseIdRejectHandler(r) { throw r }
140 140
141 function PromiseNopResolver() {} 141 function PromiseNopResolver() {}
142 142
143 // ------------------------------------------------------------------- 143 // -------------------------------------------------------------------
144 // Define exported functions. 144 // Define exported functions.
145 145
146 // For bootstrapper. 146 // For bootstrapper.
147 147
148 IsPromise = function IsPromise(x) { 148 IsPromise = function IsPromise(x) {
149 return IS_SPEC_OBJECT(x) && HAS_PRIVATE(x, promiseStatus); 149 return IS_SPEC_OBJECT(x) && HAS_DEFINED_PRIVATE(x, promiseStatus);
150 } 150 }
151 151
152 PromiseCreate = function PromiseCreate() { 152 PromiseCreate = function PromiseCreate() {
153 return new $Promise(PromiseNopResolver) 153 return new $Promise(PromiseNopResolver)
154 } 154 }
155 155
156 PromiseResolve = function PromiseResolve(promise, x) { 156 PromiseResolve = function PromiseResolve(promise, x) {
157 PromiseDone(promise, +1, x, promiseOnResolve) 157 PromiseDone(promise, +1, x, promiseOnResolve)
158 } 158 }
159 159
160 PromiseReject = function PromiseReject(promise, r) { 160 PromiseReject = function PromiseReject(promise, r) {
161 // Check promise status to confirm that this reject has an effect. 161 // Check promise status to confirm that this reject has an effect.
162 // Check promiseDebug property to avoid duplicate event. 162 // Check promiseDebug property to avoid duplicate event.
163 if (DEBUG_IS_ACTIVE && 163 if (DEBUG_IS_ACTIVE &&
164 GET_PRIVATE(promise, promiseStatus) == 0 && 164 GET_PRIVATE(promise, promiseStatus) == 0 &&
165 !HAS_PRIVATE(promise, promiseDebug)) { 165 !HAS_DEFINED_PRIVATE(promise, promiseDebug)) {
166 %DebugPromiseRejectEvent(promise, r); 166 %DebugPromiseRejectEvent(promise, r);
167 } 167 }
168 PromiseDone(promise, -1, r, promiseOnReject) 168 PromiseDone(promise, -1, r, promiseOnReject)
169 } 169 }
170 170
171 // Convenience. 171 // Convenience.
172 172
173 function PromiseDeferred() { 173 function PromiseDeferred() {
174 if (this === $Promise) { 174 if (this === $Promise) {
175 // Optimized case, avoid extra closure. 175 // Optimized case, avoid extra closure.
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 "race", PromiseOne, 356 "race", PromiseOne,
357 "resolve", PromiseCast 357 "resolve", PromiseCast
358 ]); 358 ]);
359 InstallFunctions($Promise.prototype, DONT_ENUM, [ 359 InstallFunctions($Promise.prototype, DONT_ENUM, [
360 "chain", PromiseChain, 360 "chain", PromiseChain,
361 "then", PromiseThen, 361 "then", PromiseThen,
362 "catch", PromiseCatch 362 "catch", PromiseCatch
363 ]); 363 ]);
364 364
365 })(); 365 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698