This repository was archived by the owner on Aug 20, 2019. It is now read-only.
toLocaleDateString() results in "Method invoked on an object that is not Date" error in Chrome#23
Open
TylerRick wants to merge 1 commit intojamesarosen:masterfrom
Conversation
…ack to the native Date implementation) before calling the delegate method. This works around "TypeError: Method invoked on an object that is not Date" errors that we would otherwise get in Chrome when calling toLocaleDateString().
Owner
|
I don't see this problem in a simplistic reduction: function MockDate(date) {
this._underlyingDate = date || new Date();
}
MockDate.prototype.toLocaleDateString = function() {
return this._underlyingDate.toLocaleDateString.apply(this._underlyingDate, arguments);
}
d1 = new MockDate()
d2 = new MockDate(d1)
d2.toLocaleDateString()
"7/16/2013"That suggests that something else is going wrong. |
Author
|
You might be right. I pasted your simplistic MockDate into the console of my Chrome browser and it worked fine. I guess I should find a minimal reproduction of the bug first. Don't have time at the moment though... |
Owner
|
I'll leave this open for a while. It sounds somewhat serious, so if we can find a test case, I'd like to solve it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
After calling Timecop.install and Timecop.travel, when I then call
toLocaleDateString()on any date object, I get this error:The backtrace is:
You can where the error is defined in the V8 source code here:
I don't understand it completely, but it looks like even though we called the
toLocaleDateTimemethod on an actual nativeDateobject (this._underlyingDate), the waytoLocaleDateTimeis defined (Object.defineProperty(Date.prototype, 'toLocaleDateString',...), it ends up callingtoLocaleDateTimewith a non-native Date object (presumably aTimecop.MockDate object) as the first argument. Hence my proposed workaround in the attached pull request...I'm using Chromium Version 28.0.1500.52 Ubuntu 12.04 (28.0.1500.52-0ubuntu1.12.04.2).