Skip to content

sql.js on "strict" mode? #311

@hikaru150s

Description

@hikaru150s

I'm working on combining between sql.js, IndexedDB, and Angular 8 here. everything was so normal until I found this under my desk.

core.js:4799 ERROR Error: Uncaught (in promise): TypeError: Cannot set property 'SQL' of undefined
TypeError: Cannot set property 'SQL' of undefined
    at sql-wasm-debug.js:913
    at doRun (sql-wasm-debug.js:7612)
    at run (sql-wasm-debug.js:7629)
    at runCaller (sql-wasm-debug.js:7578)
    at removeRunDependency (sql-wasm-debug.js:2507)
    at receiveInstance (sql-wasm-debug.js:2607)
    at receiveInstantiatedSource (sql-wasm-debug.js:2624)
    at ZoneDelegate.invoke (zone-evergreen.js:359)
    at Object.onInvoke (core.js:32838)
    at ZoneDelegate.invoke (zone-evergreen.js:358)
    at resolvePromise (zone-evergreen.js:797)
    at zone-evergreen.js:707
    at zone-evergreen.js:723
    at ZoneDelegate.invoke (zone-evergreen.js:359)
    at Object.onInvoke (core.js:32838)
    at ZoneDelegate.invoke (zone-evergreen.js:358)
    at Zone.run (zone-evergreen.js:124)
    at zone-evergreen.js:855
    at ZoneDelegate.invokeTask (zone-evergreen.js:391)
    at Object.onInvokeTask (core.js:32819)

After some frustrating night, I managed to dig deep to the source (thanks for providing the sql-wasm-debug.js, btw) and found this on line 913.

this['SQL'] = {
  'Database': Database
};

As far as I know about 'this' keyword, the keyword was very trivial.

Alright, so far so good. This in functions calls points to the global object. It is not so simple though. This behavior only applies when not in strict mode. When in strict mode, this in functions is undefined.

Curiously, I've made some speculation that this in line 913 was referring to window global object (which I found the SQL sub-object under window object in your native html template).

I made a 'dirty' workaround here, and found my code was running successfully (finally!). Here's the workaround in line 913 to Line 919.

window['SQL'] = {
  'Database': Database
};

for (i in window['SQL']) {
  Module[i] = window['SQL'][i];
}

As for conclusion, would you mind to manage this module on "strict" mode?
Thank you so much for this great library!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions