Skip to content
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

semantic equivalence of f() <=> f(undefined) and so on #7

Closed
drsm opened this issue Apr 20, 2018 · 3 comments
Closed

semantic equivalence of f() <=> f(undefined) and so on #7

drsm opened this issue Apr 20, 2018 · 3 comments
Assignees
Labels
Milestone

Comments

@drsm
Copy link
Contributor

drsm commented Apr 20, 2018

The subject is broken in many places, i.e. #5 or:

>> 2..toString()
2
>> 2..toString(void 0)
RangeError
    at Number.prototype.toString (native)
    at main (native)
@xeioex
Copy link
Contributor

xeioex commented Apr 20, 2018

@drsm Can you, please, give me the link to the specification which requires this behavior for every function?

@drsm
Copy link
Contributor Author

drsm commented Apr 20, 2018

@xeioex i'll try to find out. but, i think it is a "common behavior", rather than requirement. my point is that if no special care has been taken to differentiate a call without an argument specified and a call with undefined(void) argument provided, then results of both calls should be the same. otherwise there will be inconsistencies between internal and user-defined functions.

>> function id(x) { return x; }
undefined
>> id() === id(void 0)
true
>> (function wrapfail(x) { return 2..toString(x); })()
RangeError
    at Number.prototype.toString (native)
    at anonymous (:1)
    at main (native)

also, if we want to implement the "default function parameters" feature, let's consider this sample:

> function defaults(x = 10) { return x; }
undefined
> defaults() === defaults(void 0)
true

and finally, all of [V8, Firefox, JJS] engines demonstrate the same behavior.

@drsm
Copy link
Contributor Author

drsm commented Apr 20, 2018

here it is:
https://www.ecma-international.org/ecma-262/5.1/#sec-10.5

4.d.ii If n is greater than argCount, let v be undefined otherwise let v be the value of the n’th element of args.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants