-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Misc tests categorized as "pass", but are not valid programs #8
Comments
Should I raise a new issue or report here?
|
Ah, thanks. Either way is fine. (That is indeed invalid - it's actually the only early error specified for regular expression literals.) |
As far as I can tell, these are also incorrectly marked as "pass":
In all these cases test assumes that |
@RReverser, there's some disagreement about that, in fact. The relevant early errors are here or here; it says "If the source code matching this production is strict mode code [...]", where "this production" is The only relevant part of the definition of "strict mode code" is "Function code is strict mode code if [...] the code that produces the value of the function's [[ECMAScriptCode]] internal slot begins with a Directive Prologue that contains a Use Strict Directive.". And "function code" is "the source text that is parsed to supply the value of the [[ECMAScriptCode]] and [[FormalParameters]] internal slots (see 9.2) of an ECMAScript function object" - notably, not the BindingIdentifier. As I read it, then, the production There's an old bugzilla bug about this somewhere, and I think raised it again a couple of years ago, but it's not been resolved. (No one cares all that much, I think.) I'm going to leave those tests as they are, since they match what the spec actually says. |
Well, I've just retested to make sure and SpiderMonkey (Firefox), V8 (Node.js, Chrome), JSC (Safari) and ChakraCore (Edge) all produce an error on such functions. So in the best traditions of web standards 😄 , I would say if something is unclear for us when reading the spec but all engines agree, then this is indeed an error and should be tested as such. |
Also
So I would say engines implement spec correctly - first function is parsed to fill slots including [[ECMAScriptCode]], then [[ECMAScriptCode]] of the function is checked for a Use Strict Directive, then all the strictness rules start being applied by early errors. |
@RReverser: I know engines don't match the spec, and yes, it's probably a spec bug, but that's what it says! I'm hesitant to write tests against what the spec should be rather than what it is.
No, not as written. The definition of "function code" covers only the body and parameters, which means that the full |
Please re-read sequence above. Again, this definition does not matter for purpose of applying strict mode - it matters only for determining strictness. And, of course, to determine strictness, only function's body is used, not parameters or identifier, and after function body and parameters are set to slots, strictness is detected and is applied to entire FunctionDeclaration. |
To clarify again: 10.2.1
what is interesting here for us is
It's very explicit about strictness being determined using that slot. And that slot is assigned as part of function parsing -> Now, for example 14.1.2
It says "code matching this production" (which is "function code") is "strict mode code" - it is "strict mode code" as 10.2.1 clearly defines. I don't see any ambiguity here, and apparently neither does every other implementation. |
I don't understand the argument you're making. I don't dispute that the function's body is strict mode code. Of course this is true. I dispute that the That is, I agree the function code in question is strict, but I don't think the |
I see what you're concerned with... you're saying that you're unsure that "code matching this production is strict mode code" means "function code is strict mode code", right? But in that case other early errors from the same list that have exactly same wording wouldn't apply, for example:
yet you do have test |
@RReverser Yes, those are also at issue. Possibly I should move them. They're currently there because I confirmed with Allen that the early error for duplicate parameters is definitely intended to apply when the body has a Admittedly that's not that principled of a distinction, so, as I say, maybe I should recategorize the tests for duplicate parameters until we get the spec fixed. |
I see... this all feels just too vague, although intuitively seems connected. I agree it should be specified more clearly though. |
Just for the sake of thought experiment, trying again:
ok, what is "this production"?
ok, now we need to determine if "this production" is "strict mode code":
So we have So yeah, it's all clear on both sides apart from missing connector - whether "source code matching this production" is equivalent to "function code". |
Right. Except I don't think it's missing: "function code" is a defined term; it is defined to be "source text that is parsed to supply the value of the [[ECMAScriptCode]] and [[FormalParameters]] internal slots (see 9.2) of an ECMAScript function object". So, it includes the source text for the body and for the parameters, but not e.g. not the name, which is definitely not "parsed to supply the value of the [[ECMAScriptCode]] and [[FormalParameters]] internal slots". This implies the full production isn't "function code". |
I think this is where I see uncertainty - it doesn't state that the matched code is limited to populating only [[ECMAScriptCode]] and [[FormalParameters]], just that it's used to populate these slots. And indeed binding identifier doesn't have dedicated slot on function object, it's propagated as part of the lexical environment itself, so it couldn't fit into such definition of "function code" if it would be part of it. Which is why I believe defining "function code" via slots it populates is bad, and should instead explicitly say something like "code that is parsed with grammar production FunctionDeclaration / FunctionExpression" which wouldn't raise any confusion or questions. |
Btw, what do test262 tests say about this? Is there test explicitly checking one or another behaviour? |
I didn't think so, but looking again, it looks like it's testing that it's an error, though I can't find a test not using eval. These two projects should definitely agree. (And in fact I've been meaning to import the tests from test262, though I have to figure out a good way to deal with license information.) I've opened #13 to track resolving the inconsistency; the fix is probably going to be updating the spec and this repo. |
@bakkot Thanks. Guess this needs to be pinged upstream (again) for someone to take a look. Honestly I don't care which way will be the correct one as long as it's clearly specified and engines would do the same. |
If I have time this weekend I'll try to write some spec text and ask for consensus at the TC39 meeting this week, but it'll probably have to wait. |
Reading further (digging into ES5 / ES5.1 specs) I tend to agree that the spec text suggests that "use strict" in the body should not affect binding of function name to the lexical environment, but then it's even more annoying that all the engines disagree. |
I can bring this up in committee next week. I don't really have an opinion on which is better, so am fine with amending the spec to say the strictness also applies to the function binding. |
I would prefer what I understand to be the current spec text, which is that the binding is not considered strict mode code. It's already strange enough that parameter lists are strict mode code. |
Not really strange if you consider the fact that you need to use them inside of the function. If function has "use strict" at the beginning, you otherwise would be able to declare parameters with reserved names but not use them inside of the very same function, which would be really weird. |
@michaelficarra: given that parameter lists are strict mode code, it seems strange that other parts of the production are not strict. As I see it :) |
Closing this in favor of #13; the rest have been resolved. |
The text was updated successfully, but these errors were encountered: