-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
inconsistent order of host and type checks for eval #1495
Comments
It kinda makes sense to allow eval on non-strings, as it's just identity. |
Yeah. I could file bugs against Chrome and Safari or we could treat it as a web reality issue. |
Given that it’s a host-defined operation, i don’t see how the spec gets any opinion on it. Your test case isn’t necessarily evidence that HostCanCompileStrings isn’t called, it might also be that it chooses not to throw on non-strings. |
@ljharb HostEnsureCanCompileStrings doesn't know what is passed to eval, it just has the callee and caller context. |
Sure, but it’s host-defined. They can easily track what was passed to eval in a side channel and check it in the abstract op; there’s nothing in the spec i can see that prohibits that. |
reading the source, v8 checks for can compile strings after it checks if the input is a string, while the spec says before. |
Sure, but what i mean is, i don’t think the spec currently mandates doing the same thing in that abstract op regardless of input type. v8 could certainly swap the ordering but I’m not sure it’s really a bug. |
@ljharb, if you think this is not a web reality issue, I can file issues against Chrome & Safari and they can always choose to close them WAI. |
I don’t have a confident opinion formed :-) just not sure if this is something host-dependent or not. If so, then it’d be up to each engine to decide to conform or not; if not, then i think the spec language might need to be more explicit to make it clear. |
That's generally not how we write specifications. If an algorithm has access to such a value we'd make that explicit. This line of reasoning would mean we don't even need a hook for hosts at all. Given the name of the hook, it would make more sense for Firefox to change and to slightly adjust when this hook is called in the specification. |
@annevk in that case, it seems clear that there’s only two options to move forward - either change the spec to do this check after returning for non-strings, or change engines to do the check before. If Firefox changes so that the table in the OP is “allowed”, then we’d want to change the spec? (please confirm im reading things right) |
Yeah, unless there's a compelling reason to run this check for non-strings, but I can't think of any. |
strawman linked above wants to be called for every value, not just strings: https://github.com/mikesamuel/proposal-hostensurecancompilestrings-passthru |
Can you elaborate on what prior attestation means? |
This is a specification bug introduced post ES6. In the ES6 spec there are no observable actions that happen before the the type check on the argument. This behavior dates all the way back to the ES1 spec: It seems like the current spec. has an (unintentional??) breaking change. |
@allenwb Thanks for explaining. Should I prep an editorial change that consolidates the callouts in both indirect and direct eval into PerformEval after the type check? |
In #450, @domenic said "[putting the hook in] PerformEval is not sufficient since we need both the calleeRealm and the callerRealm to match web reality." That is,
Personally, I think I prefer the second. |
I would probably lean toward the first option, as keeping all of the "eval" logic in one place makes it less likely for readers to miss all of the important semantics. Either way, it appears that we need to decide whether we want to require all implementations to always allow non-strings. |
@jmdyck Good point. @zenparsing I'll ecmarkupize both so we can see how they look in context. |
https://mikesamuel.github.io/eval-in-order/ uses |
In option 1, PerformEval's preamble will need to be tweaked. In option 2, in the direct eval code, you need to change |
In option 1, edited the argument list description. In option 2, changed to "1. If Type(evalText) is not String, return evalText.". |
Option 2 seems much cleaner and simpler to me; ie, it no longer overloads “perform eval” with the unrelated task of “if it’s not a string, don’t try to eval it”. |
@mikesamuel: Thanks.
The initial assert (that there's at least two elements on the execution context stack) is there so reassure the reader that it's valid for step 3 to refer to the "second to top" element. It doesn't make much sense to separate those two steps, so I'd suggest moving the type-check up one more spot. |
@jmdyck Assuming you're talking about the below, maybe I'm getting too DbC, but something about fast-pathing out of caller/callee contract check seems off to me.
|
Swapping the order of the tests in the spec as a web reality change seems reasonable, or updating browsers also seems fine if they are interested. I agree with others above that it's important that the behavior be well-defined. It'd be great to add a web-platform-tests test for whatever semantics we decide on, to avoid divergence in the future. cc @domenic |
@littledan, Would https://github.com/web-platform-tests/wpt/tree/master/js/behaviours be an appropriate place to put them? The other content in https://github.com/web-platform-tests/wpt/tree/master/content-security-policy seems an awkward fit. |
@mikesamuel Seems good to me. We can discuss further in a code review. I'd recommend cc'ing @Ms2ger on that, who's more of a wpt expert than me. |
Fixes #1495 which identifies the ordering of host callouts and input type checks as a spec bug. This uses option 1 from #1495 (comment) to ensure that type checks happen before host callouts. This can't be tested in test262 but if this lands, I will follow up with tests via web-platform-tests/wpt.
This adds tests for tc39/ecma262#1504 which cannot be tested purely in JavaScript because it involves HostEnsureCanCompileStrings. As documented in a table on tc39/ecma262#1495 this passes on recent Chrome and Safari and fails on Firefox so this test probably shouldn't land right away.
@littledan 2 separate PRs for spec change and test out. Will schedule a few minutes next meeting to request consensus. |
... until tc39/ecma262#1495 lands.
* [js] test order of host callout & typecheck during eval This adds tests for tc39/ecma262#1504 which cannot be tested purely in JavaScript because it involves HostEnsureCanCompileStrings. As documented in a table on tc39/ecma262#1495 this passes on recent Chrome and Safari and fails on Firefox so this test probably shouldn't land right away. * Moved test to content-security-policy/generic I reformatted it to follow the guidance at https://github.com/web-platform-tests/wpt/blob/38f02ed8bb05f69ab4b061d17220f8f46709a0a3/content-security-policy/README.html#L37-L60 and moved the `<meta http-equiv=Content-Security-Policy>` content into a separate file per https://github.com/web-platform-tests/wpt/blob/38f02ed8bb05f69ab4b061d17220f8f46709a0a3/content-security-policy/README.html#L22-L24 * move `<title>` into `<head>` * Mark new test tentative ... until tc39/ecma262#1495 lands.
…1504) Fixes #1495 which identifies the ordering of host callouts and input type checks as a spec bug. This uses option 1 from #1495 (comment) to ensure that type checks happen before host callouts. This can't be tested in test262 but if this lands, I will follow up with tests via web-platform-tests/wpt.
…eck during eval, a=testonly Automatic update from web-platform-tests [csp] test order of host callout & typecheck during eval (#16301) * [js] test order of host callout & typecheck during eval This adds tests for tc39/ecma262#1504 which cannot be tested purely in JavaScript because it involves HostEnsureCanCompileStrings. As documented in a table on tc39/ecma262#1495 this passes on recent Chrome and Safari and fails on Firefox so this test probably shouldn't land right away. * Moved test to content-security-policy/generic I reformatted it to follow the guidance at https://github.com/web-platform-tests/wpt/blob/38f02ed8bb05f69ab4b061d17220f8f46709a0a3/content-security-policy/README.html#L37-L60 and moved the `<meta http-equiv=Content-Security-Policy>` content into a separate file per https://github.com/web-platform-tests/wpt/blob/38f02ed8bb05f69ab4b061d17220f8f46709a0a3/content-security-policy/README.html#L22-L24 * move `<title>` into `<head>` * Mark new test tentative ... until tc39/ecma262#1495 lands. -- wpt-commits: e3d0146264093a389148cc555ee9be69bd75719b wpt-pr: 16301
…eck during eval, a=testonly Automatic update from web-platform-tests [csp] test order of host callout & typecheck during eval (#16301) * [js] test order of host callout & typecheck during eval This adds tests for tc39/ecma262#1504 which cannot be tested purely in JavaScript because it involves HostEnsureCanCompileStrings. As documented in a table on tc39/ecma262#1495 this passes on recent Chrome and Safari and fails on Firefox so this test probably shouldn't land right away. * Moved test to content-security-policy/generic I reformatted it to follow the guidance at https://github.com/web-platform-tests/wpt/blob/38f02ed8bb05f69ab4b061d17220f8f46709a0a3/content-security-policy/README.html#L37-L60 and moved the `<meta http-equiv=Content-Security-Policy>` content into a separate file per https://github.com/web-platform-tests/wpt/blob/38f02ed8bb05f69ab4b061d17220f8f46709a0a3/content-security-policy/README.html#L22-L24 * move `<title>` into `<head>` * Mark new test tentative ... until tc39/ecma262#1495 lands. -- wpt-commits: e3d0146264093a389148cc555ee9be69bd75719b wpt-pr: 16301
* [js] test order of host callout & typecheck during eval This adds tests for tc39/ecma262#1504 which cannot be tested purely in JavaScript because it involves HostEnsureCanCompileStrings. As documented in a table on tc39/ecma262#1495 this passes on recent Chrome and Safari and fails on Firefox so this test probably shouldn't land right away. * Moved test to content-security-policy/generic I reformatted it to follow the guidance at https://github.com/web-platform-tests/wpt/blob/38f02ed8bb05f69ab4b061d17220f8f46709a0a3/content-security-policy/README.html#L37-L60 and moved the `<meta http-equiv=Content-Security-Policy>` content into a separate file per https://github.com/web-platform-tests/wpt/blob/38f02ed8bb05f69ab4b061d17220f8f46709a0a3/content-security-policy/README.html#L22-L24 * move `<title>` into `<head>` * Mark new test tentative ... until tc39/ecma262#1495 lands.
…eck during eval, a=testonly Automatic update from web-platform-tests [csp] test order of host callout & typecheck during eval (#16301) * [js] test order of host callout & typecheck during eval This adds tests for tc39/ecma262#1504 which cannot be tested purely in JavaScript because it involves HostEnsureCanCompileStrings. As documented in a table on tc39/ecma262#1495 this passes on recent Chrome and Safari and fails on Firefox so this test probably shouldn't land right away. * Moved test to content-security-policy/generic I reformatted it to follow the guidance at https://github.com/web-platform-tests/wpt/blob/38f02ed8bb05f69ab4b061d17220f8f46709a0a3/content-security-policy/README.html#L37-L60 and moved the `<meta http-equiv=Content-Security-Policy>` content into a separate file per https://github.com/web-platform-tests/wpt/blob/38f02ed8bb05f69ab4b061d17220f8f46709a0a3/content-security-policy/README.html#L22-L24 * move `<title>` into `<head>` * Mark new test tentative ... until tc39/ecma262#1495 lands. -- wpt-commits: e3d0146264093a389148cc555ee9be69bd75719b wpt-pr: 16301 UltraBlame original commit: 88f30913db0b51d3ecb0e93e97bb57e9bd5802d5
…eck during eval, a=testonly Automatic update from web-platform-tests [csp] test order of host callout & typecheck during eval (#16301) * [js] test order of host callout & typecheck during eval This adds tests for tc39/ecma262#1504 which cannot be tested purely in JavaScript because it involves HostEnsureCanCompileStrings. As documented in a table on tc39/ecma262#1495 this passes on recent Chrome and Safari and fails on Firefox so this test probably shouldn't land right away. * Moved test to content-security-policy/generic I reformatted it to follow the guidance at https://github.com/web-platform-tests/wpt/blob/38f02ed8bb05f69ab4b061d17220f8f46709a0a3/content-security-policy/README.html#L37-L60 and moved the `<meta http-equiv=Content-Security-Policy>` content into a separate file per https://github.com/web-platform-tests/wpt/blob/38f02ed8bb05f69ab4b061d17220f8f46709a0a3/content-security-policy/README.html#L22-L24 * move `<title>` into `<head>` * Mark new test tentative ... until tc39/ecma262#1495 lands. -- wpt-commits: e3d0146264093a389148cc555ee9be69bd75719b wpt-pr: 16301 UltraBlame original commit: 88f30913db0b51d3ecb0e93e97bb57e9bd5802d5
…eck during eval, a=testonly Automatic update from web-platform-tests [csp] test order of host callout & typecheck during eval (#16301) * [js] test order of host callout & typecheck during eval This adds tests for tc39/ecma262#1504 which cannot be tested purely in JavaScript because it involves HostEnsureCanCompileStrings. As documented in a table on tc39/ecma262#1495 this passes on recent Chrome and Safari and fails on Firefox so this test probably shouldn't land right away. * Moved test to content-security-policy/generic I reformatted it to follow the guidance at https://github.com/web-platform-tests/wpt/blob/38f02ed8bb05f69ab4b061d17220f8f46709a0a3/content-security-policy/README.html#L37-L60 and moved the `<meta http-equiv=Content-Security-Policy>` content into a separate file per https://github.com/web-platform-tests/wpt/blob/38f02ed8bb05f69ab4b061d17220f8f46709a0a3/content-security-policy/README.html#L22-L24 * move `<title>` into `<head>` * Mark new test tentative ... until tc39/ecma262#1495 lands. -- wpt-commits: e3d0146264093a389148cc555ee9be69bd75719b wpt-pr: 16301 UltraBlame original commit: 88f30913db0b51d3ecb0e93e97bb57e9bd5802d5
JS engines are not consistent in the order in which they apply type checks and host callouts during
eval
.eval
applied to non string arguments is the identity function because of step 2 of the definition of PerformEval:This type check happens after the call to HostEnsureCanCompileStrings:
but when the argument is not a string, some engines do not seem to perform HostEnsureCanCompileStrings.
I tested this in various browsers via
eval(0)
I don't have IE / Edge handy.
The text was updated successfully, but these errors were encountered: