Skip to content
This repository has been archived by the owner on Jun 23, 2018. It is now read-only.

"use strict" lost if entered line-by-line #64

Open
domenic opened this issue May 7, 2012 · 1 comment
Open

"use strict" lost if entered line-by-line #64

domenic opened this issue May 7, 2012 · 1 comment

Comments

@domenic
Copy link

domenic commented May 7, 2012

Using Firefox 12, Windows. Amjad said at the last NYC.js that this was a bug, so I finally am getting around to filing it.

Consider the following code:

"use strict";

var x = Object.freeze({});
x.foo = "bar";

if I type it in the left pane, and press the array to send it rightward, I get an error, as expected:

TypeError: x.foo is not extensible

But if I reload the page and type it in line-by-line, over in the right pane, no error appears. But of course, typing in x subsequently gives => {}. That is, strict mode was never entered, and it reverted to the non-strict behavior of silently ignoring the property write instead of throwing noisily.


Presumably the same problem is occurring here as is described in this article under "Why can’t I run global Strict Mode in my browser console?"

I would really love this feature in order to give live REPL demonstrations of certain ES5 features in a lightning talk. Things like Object.freeze and Object.defineProperty have much more obvious behavior (viz. throwing errors) when in strict mode. If JSRepl added the ability to keep your code in strict mode, it would be ahead of all the current browser consoles I've tested for such purposes.

One solution might be to have a JavaScript Strict Mode option on the web page, just like there's currently a JavaScript.next.

I'm open to submitting a pull request for this myself, if you want to give some implementation hints :)

@amasad
Copy link
Contributor

amasad commented May 9, 2012

Thanks domenic. Will look into this shortly.

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

2 participants