Introduces LegacyPromise; polyfills DOM Promise

This commit is contained in:
Yury Delendik 2014-01-03 18:17:05 -06:00
parent 122cd150d4
commit 5bf3e44e30
20 changed files with 263 additions and 156 deletions

View file

@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* globals PDFJS, VIEW_HISTORY_MEMORY, isLocalStorageEnabled */
/* globals PDFJS, VIEW_HISTORY_MEMORY, isLocalStorageEnabled, Promise */
'use strict';
@ -31,11 +31,16 @@
var ViewHistory = (function ViewHistoryClosure() {
function ViewHistory(fingerprint) {
this.fingerprint = fingerprint;
this.initializedPromise = new PDFJS.Promise();
var initializedPromiseResolve;
this.isInitializedPromiseResolved = false;
this.initializedPromise = new Promise(function (resolve) {
initializedPromiseResolve = resolve;
});
var resolvePromise = (function ViewHistoryResolvePromise(db) {
this.isInitializedPromiseResolved = true;
this.initialize(db || '{}');
this.initializedPromise.resolve();
initializedPromiseResolve();
}).bind(this);
//#if B2G
@ -78,7 +83,7 @@ var ViewHistory = (function ViewHistoryClosure() {
},
set: function ViewHistory_set(name, val) {
if (!this.initializedPromise.isResolved) {
if (!this.isInitializedPromiseResolved) {
return;
}
var file = this.file;
@ -101,7 +106,7 @@ var ViewHistory = (function ViewHistoryClosure() {
},
get: function ViewHistory_get(name, defaultValue) {
if (!this.initializedPromise.isResolved) {
if (!this.isInitializedPromiseResolved) {
return defaultValue;
}
return this.file[name] || defaultValue;