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

Should throw TypeError Instead of Returning [object] #54

Closed
JitCompiler opened this issue Nov 5, 2017 · 0 comments
Closed

Should throw TypeError Instead of Returning [object] #54

JitCompiler opened this issue Nov 5, 2017 · 0 comments

Comments

@JitCompiler
Copy link

JitCompiler commented Nov 5, 2017

When trying to convert an object which has no "toString()" nor "valueOf()" method to string, the ECMAScript 5.1 spec specifies the js system should throw a TypeError exception (point 5 below). Testing shows that mujs returns the string "[object]" instead. Is it an intended non-standard behaviour?

The relevant paragraphs of the ECMAScript 5.1 spec are here:

8.12.8 [[DefaultValue]] (hint)
When the [[DefaultValue]] internal method of O is called with hint String, the following steps are taken:
1. Let toString be the result of calling the [[Get]] internal method of object O with argument "toString".
2. If IsCallable(toString) is true then,
a. Let str be the result of calling the [[Call]] internal method of toString, with O as the this value and
an empty argument list.
b. If str is a primitive value, return str.
3. Let valueOf be the result of calling the [[Get]] internal method of object O with argument "valueOf".
4. If IsCallable(valueOf) is true then,
a. Let val be the result of calling the [[Call]] internal method of valueOf, with O as the this value and
an empty argument list.
b. If val is a primitive value, return val.
5. Throw a TypeError exception

@ccxvii ccxvii closed this as completed Dec 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants