Skip to content

Commit b165a39

Browse files
committed
allow disable sync inspection
1 parent 8cceb27 commit b165a39

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

src/synchronous.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,27 @@ Promise.enableSynchronous = function () {
1616
return this._state == 2;
1717
};
1818

19-
Promise.prototype.value = function () {
19+
Promise.prototype.getValue = function () {
2020
if (!this.isFulfilled()) {
2121
throw new Error('Cannot get a value of an unfulfilled promise.');
2222
}
2323

2424
return this._value;
2525
};
2626

27-
Promise.prototype.reason = function () {
27+
Promise.prototype.getReason = function () {
2828
if (!this.isRejected()) {
2929
throw new Error('Cannot get a rejection reason of a non-rejected promise.');
3030
}
3131

3232
return this._value;
3333
};
3434
};
35+
36+
Promise.disableSynchronous = function() {
37+
Promise.prototype.isPending = undefined;
38+
Promise.prototype.isFulfilled = undefined;
39+
Promise.prototype.isRejected = undefined;
40+
Promise.prototype.getValue = undefined;
41+
Promise.prototype.getReason = undefined;
42+
};

test/synchronous-inspection-tests.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ describe('synchronous-inspection-tests', function () {
7070
setTimeout(function () {
7171
assert(fulfilledPromise.isFulfilled());
7272
assert(!fulfilledPromise.isRejected());
73-
assert(fulfilledPromise.value());
73+
assert(fulfilledPromise.getValue());
7474
assert(!fulfilledPromise.isPending());
7575
}, 30);
7676
});
@@ -102,7 +102,7 @@ describe('synchronous-inspection-tests', function () {
102102
setTimeout(function () {
103103
assert(!fulfilledPromise.isFulfilled());
104104
assert(fulfilledPromise.isRejected());
105-
assert(!fulfilledPromise.reason());
105+
assert(!fulfilledPromise.getReason());
106106
assert(!fulfilledPromise.isPending());
107107
}, 30);
108108
});
@@ -130,7 +130,7 @@ describe('synchronous-inspection-tests', function () {
130130
assert(!fulfilledPromise.isRejected());
131131

132132
try {
133-
fulfilledPromise.value();
133+
fulfilledPromise.getValue();
134134

135135
assert(false);
136136
}
@@ -142,7 +142,7 @@ describe('synchronous-inspection-tests', function () {
142142

143143
setTimeout(function () {
144144
try {
145-
fulfilledPromise.value();
145+
fulfilledPromise.getValue();
146146

147147
assert(false);
148148
}
@@ -175,7 +175,7 @@ describe('synchronous-inspection-tests', function () {
175175
assert(!fulfilledPromise.isRejected());
176176

177177
try {
178-
fulfilledPromise.reason();
178+
fulfilledPromise.getReason();
179179

180180
assert(false);
181181
}
@@ -187,7 +187,7 @@ describe('synchronous-inspection-tests', function () {
187187

188188
setTimeout(function () {
189189
try {
190-
fulfilledPromise.reason();
190+
fulfilledPromise.getReason();
191191

192192
assert(false);
193193
}
@@ -196,4 +196,12 @@ describe('synchronous-inspection-tests', function () {
196196
}
197197
}, 30);
198198
});
199+
200+
it('can disable synchronous inspection', function() {
201+
Promise.enableSynchronous();
202+
var testPromise = Promise.resolve('someValue');
203+
assert(testPromise.getValue() == 'someValue');
204+
Promise.disableSynchronous();
205+
assert(testPromise.getValue == undefined);
206+
});
199207
});

0 commit comments

Comments
 (0)