Function.prototype.call versus Array.prototype.find #232
Labels
Ecma Incompatibility
Issues about Rhino being incompatible with the EcmaScript spec
Strict Mode
Issues related to non-compliance with the ES5 Strict Mode spec
The recent changes to enable Array.prototype.find seem to be causing some side-effects with Function.prototype.call, and I'm not sure how to resolve them.
If I look here:
http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf
Section 19.2.3.3 says that "Function.prototype.call" should pass "null" and "undefined" as the value of "this" to the function that it calls, which is different from ES 3. Evgeny recently made these changes in master.
However, this broke some Node.js code I was testing, and I found the following note, also in section 19.2.3.3:
"NOTE 1 The thisArg value is passed without modification as the this value. This is a change from Edition 3, where an undefined or null thisArg is replaced with the global object and ToObject is applied to all other values and that result is passed as the this value. Even though the thisArg is passed without modification, non-strict functions still perform these transformations upon entry to the function."
My interpretation of "non-strict functions still perform these transformations" is that the "old" behavior should be enabled in ScriptRuntime.applyOrCall, and that the new behavior should only be enabled when strict mode is in force -- and sainen just gave us a PR to enable strict mode.
Sure enough, when I changed "applyOrCall" to only apply the new behavior in strict mode, the legacy Node.js code worked.
However, the "array find" tests broke because they were expecting a TypeError in this case:
Array.prototype.find.call(null, function() { });
and that only happens when running in strict mode -- otherwise, "null" gets converted to the global object, and since that has no "length" property, "find" just does nothing.
(V8 version 3.28.73, under Node.js in "--harmony" mode, seems to use the old behavior.)
@eshepelyuk, do you have any ideas how to resolve this?
Some possibilities:
Sorry about the long issue but it's an interesting one. Thanks!
The text was updated successfully, but these errors were encountered: