Skip to content
This repository has been archived by the owner on Dec 15, 2023. It is now read-only.

Proxy that override toString() could lead to TypeError from indexOf() #145

Closed
Suisse00 opened this issue Oct 20, 2019 · 1 comment · Fixed by #163
Closed

Proxy that override toString() could lead to TypeError from indexOf() #145

Suisse00 opened this issue Oct 20, 2019 · 1 comment · Fixed by #163

Comments

@Suisse00
Copy link
Contributor

I was trying to create the definition for an addon of https://github.com/sequelize/sequelize 5.21.1 which would end up generating the sequelize definition as well.

the exception

Exception has occurred: TypeError
TypeError: Cannot read property 'indexOf' of undefined
at isNativeFunction (D:\Windows\Suisse\AppData\Roaming\npm\node_modules\dts-gen\bin\lib\index.js:358:25)
at getParameterListAndReturnType (D:\Windows\Suisse\AppData\Roaming\npm\node_modules\dts-gen\bin\lib\index.js:302:9)
at getResult (D:\Windows\Suisse\AppData\Roaming\npm\node_modules\dts-gen\bin\lib\index.js:135:30)
at getTopLevelDeclarations (D:\Windows\Suisse\AppData\Roaming\npm\node_modules\dts-gen\bin\lib\index.js:129:17)
at getResult (D:\Windows\Suisse\AppData\Roaming\npm\node_modules\dts-gen\bin\lib\index.js:197:35)
at getTopLevelDeclarations (D:\Windows\Suisse\AppData\Roaming\npm\node_modules\dts-gen\bin\lib\index.js:129:17)
at getResult (D:\Windows\Suisse\AppData\Roaming\npm\node_modules\dts-gen\bin\lib\index.js:153:17)
at getTopLevelDeclarations (D:\Windows\Suisse\AppData\Roaming\npm\node_modules\dts-gen\bin\lib\index.js:129:17)
at Object.generateIdentifierDeclarationFile (D:\Windows\Suisse\AppData\Roaming\npm\node_modules\dts-gen\bin\lib\index.js:73:20)
at Object. (D:\Windows\Suisse\AppData\Roaming\npm\node_modules\dts-gen\bin\lib\run.js:62:24)
at Module._compile (internal/modules/cjs/loader.js:685:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
at Module.load (internal/modules/cjs/loader.js:598:32)
at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
at Function.Module._load (internal/modules/cjs/loader.js:529:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:741:12)
at startup (internal/bootstrap/node.js:285:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:739:3)

After investigating I found out the issue is when Proxy override the toString() method and return undefined.

Reproduction steps (from sequelize)

npm i -g sequelize
use my only changes from 5.21.1 - Suisse00/sequelize@eb1c7b1
dst-gen -m sequelize

Reproduction steps (POC)
poc.js
class Dummy {
static toString(...args) { return undefined; }
}

new Proxy(Dummy, {
get(target, p) {
return target[p];
}})

command

dts-gen --expression-file poc.js

dst-gen --version 0.5.8
sequelize 5.21.1 (with patch)

@Suisse00
Copy link
Contributor Author

I did fix my errors by updating dts-gen, I have no idea if it will break something else but that could be a start.
Unfortunately, I updated the .js instead of the .ts, and I can't find the equivalent of Object.toString(X) in TS so... good luck!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant