CSNW / sql-bricks

Transparent, Schemaless SQL Generation
http://csnw.github.io/sql-bricks
MIT License
203 stars 25 forks source link

Infinit recursion in subclass function. #123

Closed recursive-beast closed 3 years ago

recursive-beast commented 3 years ago

I'm trying to get sql-bricks to work on an old environment, specifically Classic ASP using JScript as the scripting language ( javascript in es3 spec ).

everything is working fine when I'm using the standalone library, but when I'm using the mysql-bricks extension, I get an error indicating an "out of stack space" error.

After a day and a half of trying to fix the problem, I discovered that the problem is coming from the subclass function. The this value inside cls seems to cause the issue, If I try to print it every time cls is called here's the result:

function cls() { if(this === Function("return this")()){ Response.Write("global object" + " "); }else{ Response.Write(this + " "); } if (!(this instanceof cls)) return applyNew(cls, arguments); base.apply(this, arguments); }

global object

global object

... (Trancated)

global object

Microsoft JScript runtime error '800a001c'

Out of stack space

C:\USERS\RECURSIVE-BEAST\DESKTOP\REPOSITORIES\WHATS-APP\ROOT../backend/dist/bundle.js, line 1423

The first time, this is cls itself, then it's always the global object, which makes the condition !(this instanceof cls) always true, because applyNew gets called recursively, which in turn calls cls with a this value set to null (global object).

I'm not sure why does this happen, maybe you could shed some light on this?

recursive-beast commented 3 years ago

False alarm.

There are two versions of Function.prototype.bind polyfills in the MDN website:

I was working with the first one.