Skip to content

Increase test coverage: Array.prototype.toLocaleString #2716

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

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions tests/jerry/array-prototype-tolocalestring.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,38 @@ try {
assert (e.message === "foo");
assert (e instanceof ReferenceError);
}

/* ES v5.1 15.4.4.3.1.
Checking behavior when the function's this_argument is null */
try {
Array.prototype.toLocaleString.call(null);
assert(false);
} catch (e) {
assert(e instanceof TypeError);
}

/* ES v5.1 15.4.4.3.2.
Checking behavior when length throws error */
try {
var obj = {};
Object.defineProperty(obj, 'length', { 'get' : function () { throw new ReferenceError("foo"); } });
Array.prototype.toLocaleString.call(obj);
assert(false);
} catch (e) {
assert(e instanceof ReferenceError);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check the message as well! (And use unique messages)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The message is not checked. Why is this marked as resolved?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@akosthekiss Probably that was a miss click, I've just unresolved it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The thrown error and the one in the function are not the same ReferenceErrors, so as I check the message, I get assertion fail.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something is not right then. Q1: Why set the error message then, if it cannot be checked? Q2: Does the error object get replaced somewhere by the builtin implementation? Q3: If yes, why? Q4: If yes, is it necessary to throw a reference error within the anonymous function or any kind of error can be thrown?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something is a bit fishy there.

try {
  var obj = {};
  Object.defineProperty(obj, 'length', { 'get' : function () { throw new ReferenceError("foo"); } });
  Array.prototype.toLocaleString.call(obj);
  assert(false);
} catch (e) {
  assert(e instanceof ReferenceError);
  assert (e.message == "foo");
}

The suggested assertion for the message is correct in all engines that I've tested (V8, Spidermonkey, JSC) even in Jerry as well. Could you please give more detailed description about why this assert is failing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I made a typo, that is why it did not work.

assert(e.message == "foo");
}

/* ES v5.1 15.4.4.3.3.
Checking behavior when length is an object, which has a valueOf method that throws an error */
var len = { };
Object.defineProperty(len, 'valueOf', { 'get' : function () { throw new ReferenceError("vOf"); } });
var obj = { toLocaleString : Array.prototype.toLocaleString, length : len };

try {
obj.toLocaleString();
assert(false);
} catch (e) {
assert(e.message === 'vOf');
assert(e instanceof ReferenceError);
}