@@ -22,16 +22,37 @@ var globalVar =
2222 ? global
2323 : Function ( "return this;" ) ( ) ;
2424
25- globalVar . indexedDB = fakeIndexedDB ;
26- globalVar . IDBCursor = FDBCursor ;
27- globalVar . IDBCursorWithValue = FDBCursorWithValue ;
28- globalVar . IDBDatabase = FDBDatabase ;
29- globalVar . IDBFactory = FDBFactory ;
30- globalVar . IDBIndex = FDBIndex ;
31- globalVar . IDBKeyRange = FDBKeyRange ;
32- globalVar . IDBObjectStore = FDBObjectStore ;
33- globalVar . IDBOpenDBRequest = FDBOpenDBRequest ;
34- globalVar . IDBRecord = FDBRecord ;
35- globalVar . IDBRequest = FDBRequest ;
36- globalVar . IDBTransaction = FDBTransaction ;
37- globalVar . IDBVersionChangeEvent = FDBVersionChangeEvent ;
25+ // Match the native behavior for `globalThis.indexedDB`, `globlThis.IDBCursor`, etc.
26+ // Per the IDL, `indexedDB` is readonly but the others are readwrite
27+ // https://w3c.github.io/IndexedDB/#idl-index
28+ const createPropertyDescriptor = ( value , readOnly = false ) => {
29+ return {
30+ ...( readOnly
31+ ? {
32+ set : undefined ,
33+ get : ( ) => value ,
34+ }
35+ : {
36+ value,
37+ writable : true ,
38+ } ) ,
39+ enumerable : true ,
40+ configurable : true ,
41+ } ;
42+ } ;
43+
44+ Object . defineProperties ( globalVar , {
45+ indexedDB : createPropertyDescriptor ( fakeIndexedDB , true ) ,
46+ IDBCursor : createPropertyDescriptor ( FDBCursor ) ,
47+ IDBCursorWithValue : createPropertyDescriptor ( FDBCursorWithValue ) ,
48+ IDBDatabase : createPropertyDescriptor ( FDBDatabase ) ,
49+ IDBFactory : createPropertyDescriptor ( FDBFactory ) ,
50+ IDBIndex : createPropertyDescriptor ( FDBIndex ) ,
51+ IDBKeyRange : createPropertyDescriptor ( FDBKeyRange ) ,
52+ IDBObjectStore : createPropertyDescriptor ( FDBObjectStore ) ,
53+ IDBOpenDBRequest : createPropertyDescriptor ( FDBOpenDBRequest ) ,
54+ IDBRecord : createPropertyDescriptor ( FDBRecord ) ,
55+ IDBRequest : createPropertyDescriptor ( FDBRequest ) ,
56+ IDBTransaction : createPropertyDescriptor ( FDBTransaction ) ,
57+ IDBVersionChangeEvent : createPropertyDescriptor ( FDBVersionChangeEvent ) ,
58+ } ) ;
0 commit comments