-
-
Notifications
You must be signed in to change notification settings - Fork 892
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
Date.prototype.toISOString called on non-finite value with Adobe Scripting #365
Comments
Do you know if it's the |
Can you confirm whether or not |
Yep. try {
require('es5-shim');
} catch (error) {
$.writeln('Caught an error:', error);
}
// Caught an error:Error: Date.prototype.toISOString called on non-finite value.
$.writeln(Object.keys({
"foo": 1,
"bar": 2
}));
// foo,bar
|
OK, that's great! It means it's fixable. Does |
|
Sorry for the back and forth - if any of that info points to anything besides that toISOString error, that would be very helpful. |
Happy to help, don't worry. Nope, my understanding is that it goes from top to bottom – it hits the first issue and throws an error, meaning there might be something further down the line. I just tried disabling the |
ok a few more questions - what does |
$.writeln(new Date(-1).getTime());
// -1
$.writeln(new Date(-62198755200000).getTime());
// -62198755200000 |
@ljharb I noticed you pushed a bunch of commits recently. Any chance they resolve this case? I'd offer a pr, but assume that this is something tricky? |
No, I haven't resolved this yet. Since I can't repro it myself, and since I don't know exactly what's failing, I'm a bit lost. Can you confirm that if you comment out the |
Yep, setting those two to
…some time later: Oh dear, I tried finding workaround and discovered that the first time shim is applied – it works, but goes wrong when it's being run the second time… That is because Adobe keeps the JS environment for the entire app session, so here's what happens:
Updating the following block works and shouldn't affect other environments. …
var hasUTCMethods = Date.prototype.getUTCFullYear && Date.prototype.getUTCMonth && Date.prototype.getUTCDate && Date.prototype.getUTCHours && Date.prototype.getUTCMinutes && Date.prototype.getUTCSeconds && Date.prototype.getUTCMilliseconds;
var hasNegativeDateBug = Date.prototype.toISOString && new Date(negativeDate).toISOString().indexOf(negativeYearString) === -1;
var hasSafari51DateBug = Date.prototype.toISOString && new Date(-1).toISOString() !== '1969-12-31T23:59:59.999Z';
hasUTCMethods && defineProperties(Date.prototype, {
… |
OK, so - you're saying that CS doesn't have any of If not, I'll want to shim all of those as well. |
…doesn’t observably look them up on the receiver. - Date#getUTCFullYear - Date#getUTCMonth - Date#getUTCDate - Date#getUTCHours - Date#getUTCMinutes - Date#getUTCSeconds - Date#getUTCMilliseconds This should also help expose the true cause of #365.
@ianbytchek if you could try checking on latest master, I suspect we'll now see an error on the first sourcing of the file, because those UTC methods aren't a function. |
That's right @ljharb. Just checked the master, can't see any difference in behaviour, it doesn't fail the first time and fails on consecutive runs like before on this line: throw new RangeError('Date.prototype.toISOString called on non-finite value.'); Might have you missed the point about the constant js environment? The main problem is that shim sees different things when it checks at what needs to be done when it runs for the first time and when it runs consecutively in the same environment. |
@ianbytchek yes, I got that :-) the issue seems to be that the |
@ljharb just making sure 😊 See below. $.writeln(this);
// Fri Jan 01 -1 04:00:00 GMT+0400
$.writeln(typeof this);
// object |
@ianbytchek Thanks - what about |
@ianbytchek any update? sorry for all the back and forth, but without a copy of Photoshop for my to test myself, it's hard for me to verify that a fix will work. |
@ljharb sorry, this got out of hands. I'll look into this towards the end of the week and will report. Happy to help. |
Thanks, much obliged! |
@ljharb here's what I've got. What do you think? if (!isFinite(this)) {
$.writeln(this); // Fri Jan 01 -1 04:00:00 GMT+0400
$.writeln(typeof this); // object
$.writeln(+this); // NaN
$.writeln(Number(this)); // NaN
$.writeln(this.getTime()); // -62198755200000
throw new RangeError('Date.prototype.toISOString called on non-finite value.');
} |
@ianbytchek Thanks! From here I think I can figure out what might be the issue - if you want to try making the condition It's super bizarre that a Date object would have a finite |
@ljharb replacing condition with if (!isFinite(this)) {
var date = new Date(-62198755200000);
$.writeln(+date); // NaN
$.writeln(Number(date)); // NaN
$.writeln(date.getTime()); // -62198755200000
throw new RangeError('Date.prototype.toISOString called on non-finite value.');
} |
Released as v4.5.5 |
👍 🍻 |
Thanks for reporting this and following through back and forth :-) I love these kinds of quirky environment issues. |
Try do something with adobe scripting, bet you'll change your mind! 😄 But there is that strange satisfaction… like when taking an old car, stuffing it with latest technology and see it rolling. |
Thanks guys, this just helped me! |
Trying to make use of es5-shim with Adobe Scripting, but getting the following exception:
Trying to do a very basic thing with:
The text was updated successfully, but these errors were encountered: