0

I want to use indexedDB polyfill with Dart code compiled to Javascript. When i just added required script, dart2js code does not recognize window.indexedDB property as IDBFactory instance and produce UnknownJavaScriptObject interceptor.

I tried to force constructor.name on elements of polyfill, started with indexedDB:

    var shimIndexedDB = {
        /**
         * Force correct constructor name.
         */
        constructor: function IDBFactory(){},

        /**
         * The IndexedDB Method to create a new database and return the DB
         * @param {Object} name
         * @param {Object} version
         */
        open: function(name, version){

It was step forward, interceptor was correct. Unfortunately, when i added analogous construction to IDBOpenDBRequest, its object got IDBFactory interceptor as well.

How to correctly connect object and interceptor?

MDerks
  • 123
  • 5

1 Answers1

1

Can you use the lawndart library instead?

It provides a common API above local storage, indexed db, and websql.

From the docs:

You can use this library to help deal with the wide array of client-side storage options. You should be able to write your code against the Lawndart interface and have it work across browsers that support at least one of the following: local storage, indexed db, and websql.

To get the indexeddb javascript polyfill to work you would need to call its API via dart:js interop. This is likely to be a lot more complicated than using a library like lawndart. Here is an article about using dart:js interop.

Greg Lowe
  • 15,430
  • 2
  • 30
  • 33
  • Lawndart seems to be good solution, i will consider integrate that into my project. Still, im looking for way to reuse javascript shims for transparent fallback with any web feature (which may not have dart library alternative). – MDerks Dec 03 '13 at 09:13
  • Yeah - the problem is hooking the shim up to the Dart apis. To do this for this indexeddb shim you'd probably need to change the source of dart:html within the Dart project itself. The other option would be to copy the dart:html indexeddb interfaces, and then re-implement them using js interop. – Greg Lowe Dec 03 '13 at 19:38
  • I noticed something new in dart:js today. See [JSObject.fromBrowserObject()](https://api.dartlang.org/docs/channels/stable/latest/dart_js/JsObject.html#fromBrowserObject). This should help making polyfills. – Greg Lowe Dec 18 '13 at 03:25