forked from indexeddbshim/IndexedDBShim
-
Notifications
You must be signed in to change notification settings - Fork 2
/
IDBVersionChangeEvent.js
48 lines (39 loc) · 1.65 KB
/
IDBVersionChangeEvent.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import {ShimEvent} from './Event';
import * as util from './util';
const readonlyProperties = ['oldVersion', 'newVersion'];
// Babel apparently having a problem adding `hasInstance` to a class, so we are redefining as a function
function IDBVersionChangeEvent (type /* , eventInitDict */) { // eventInitDict is a IDBVersionChangeEventInit (but is not defined as a global)
ShimEvent.call(this, type);
this[Symbol.toStringTag] = 'IDBVersionChangeEvent';
this.toString = function () {
return '[object IDBVersionChangeEvent]';
};
this.__eventInitDict = arguments[1] || {};
}
IDBVersionChangeEvent.prototype = Object.create(ShimEvent.prototype);
IDBVersionChangeEvent.prototype[Symbol.toStringTag] = 'IDBVersionChangeEventPrototype';
readonlyProperties.forEach((prop) => {
Object.defineProperty(IDBVersionChangeEvent.prototype, prop, {
enumerable: true,
configurable: true,
get: function () {
if (!(this instanceof IDBVersionChangeEvent)) {
throw new TypeError('Illegal invocation');
}
return (this.__eventInitDict && this.__eventInitDict[prop]) || (prop === 'oldVersion' ? 0 : null);
}
});
});
Object.defineProperty(IDBVersionChangeEvent, Symbol.hasInstance, {
value: obj => util.isObj(obj) && 'oldVersion' in obj && typeof obj.defaultPrevented === 'boolean'
});
Object.defineProperty(IDBVersionChangeEvent.prototype, 'constructor', {
enumerable: false,
writable: true,
configurable: true,
value: IDBVersionChangeEvent
});
Object.defineProperty(IDBVersionChangeEvent, 'prototype', {
writable: false
});
export default IDBVersionChangeEvent;