Skip to content
This repository has been archived by the owner on Jul 14, 2022. It is now read-only.

Strict mode issues #32

Open
sainaen opened this issue Jan 15, 2015 · 1 comment
Open

Strict mode issues #32

sainaen opened this issue Jan 15, 2015 · 1 comment

Comments

@sainaen
Copy link

sainaen commented Jan 15, 2015

While working on arrow functions patch, I found two problems with how strict mode currently works in Rhino.

First, strict mode declared inside body function, should influence function arguments too. For example, eval and arguments are explicitly described as not valid arguments names in strict mode (see Appendix C of ES5, or section 14.1.2 of ES6)

asserthThrows(eval("function f(eval) { 'use strict'; }"), SyntaxError);

but it doesn't.

Second, in strict mode, when this is resolved, it should not be coerced to object, thus inside primitive wrapper's method this is primitive itself, not an object (again, see Appendix C of ES5 or Appendix C of ES6)

Number.prototype.foo = function () { "use strict"; return this; };
for (var i = 0; i < 10; i++) {
    assertEquals(typeof i.foo(), "number");
    assertEquals(i.foo(), i);
}

but right now it's "object", like in non-strict mode.

Although I know that these issues and a lot more were addressed (and fixed) in PR about ES5 compliance by @anba, it's overwhelming huge for me (+5,849 −2,256!) and I don't think I will be able to port it any time soon. But, maybe, we could try to split it and apply in chunks.

@gbrail
Copy link

gbrail commented Jan 15, 2015

I can go back and look at the history, but I believe that anba split the
original PR into two smaller ones that didn't change the public API, and I
already merged the changes in this one:

mozilla#46

as well as this one:

mozilla#45

So that would leave whatever was left in that original PR, which
unfortunately might be hard to work out -- but if you can find commits in
there that you can fix then we can certainly pull those fixes as well.

On Wed, Jan 14, 2015 at 9:13 PM, Ivan Vyshnevskyi [email protected]
wrote:

While working on arrow functions patch, I found two problems with how
strict mode currently works in Rhino.

First, strict mode declared inside body function, should influence
function arguments too. For example, eval and arguments are explicitly
described as not valid arguments names in strict mode (see Appendix C of
ES5 http://www.ecma-international.org/ecma-262/5.1/#sec-C, or section
14.1.2 of ES6
https://people.mozilla.org/%7Ejorendorff/es6-draft.html#sec-function-definitions-static-semantics-early-errors
)

asserthThrows(eval("function f(eval) { 'use strict'; }"), SyntaxError);

but it doesn't.

Second, in strict mode, when this is resolved, it should not be coerced
to object, thus inside primitive wrapper's method this is primitive
itself, not an object (again, see Appendix C of ES5
http://www.ecma-international.org/ecma-262/5.1/#sec-C or Appendix C of
ES6
https://people.mozilla.org/%7Ejorendorff/es6-draft.html#sec-strict-mode-of-ecmascript
)

Number.prototype.foo = function () { "use strict"; return this; };for (var i = 0; i < 10; i++) {
assertEquals(typeof i.foo(), "number");
assertEquals(i.foo(), i);
}

but right now it's "object", like in non-strict mode.

Although I know that these issues and a lot more were addressed (and
fixed) in PR about ES5 compliance
mozilla#39 by @anba
https://github.com/anba, it's overwhelming huge for me (+5,849 −2,256!)
and I don't think I will be able to port it any time soon. But, maybe, we
could try to split it and apply in chunks.


Reply to this email directly or view it on GitHub
#32.

greg brail | apigee https://apigee.com/ | twitter @gbrail
http://twitter.com/gbrail

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