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

Overriding Math causes repl crash #8822

Closed
rgrannell1 opened this issue Dec 4, 2014 · 2 comments
Closed

Overriding Math causes repl crash #8822

rgrannell1 opened this issue Dec 4, 2014 · 2 comments

Comments

@rgrannell1
Copy link

I attempted to override Math in the node v0.10.33 repl for fun, and I got this error upon pressing enter.

Math = 1
1
buffer.js:169
    this.length = +encoding > 0 ? Math.ceil(encoding) : 0;
                                       ^
TypeError: Object 1 has no method 'ceil'
    at new Buffer (buffer.js:169:40)
    at SlowBuffer.slice (buffer.js:149:10)
    at TTY.onread (net.js:528:33)

It looks like the node repl is using methods in the user-editable JavaScript environment for its own operation, and overriding them causes an error.

Overriding the Math object works without issue in Firefox and Chromium

Math =1
1
Math
1

This obviously isn't an important bug in itself, but I'm submitting it just in case it highlights a deeper issue in the repl.

@misterdjules
Copy link

This is due to the fact that node's REPL uses the global context. It used to use another context, but it lead to other issues, and eventually it was decided that using the global context was a lesser evil.

@tjfontaine @trevnorris @orangemocha @chrisdickinson OK to close?

@trevnorris
Copy link

Yeah. For now we're going to say we expect at least some form of general JS global functions to exist.

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

No branches or pull requests

3 participants