There are times I think JavaScript (and Node.js) do deserve their reputation…
(Ok, ok, I don’t, but what is this, really?)
“Date.prototype.toISOString called on incompatible receiver [object Date]”
*smh*
There are times I think JavaScript (and Node.js) do deserve their reputation…
(Ok, ok, I don’t, but what is this, really?)
“Date.prototype.toISOString called on incompatible receiver [object Date]”
*smh*
So in case, anyone was following this: it appears that built-in objects like Date in JavaScript have some internal magic (read: inconsistencies)* that means you can’t proxy them as you would normally.
More info: https://codeberg.org/small-tech/jsdb/issues/5
Not sure if this is fixable in JSDB. The “solution” might be to discourage use of Date objects and instead persist timestamps. Which is, quite frankly, a pain in the ass.
I’ll keep looking for a workaround…
* internal slots
@aral this wording mentioning 'receiver' makes me feel like a Proxy instance was involved, but they're not really used much outside testing frameworks I think :P
@dan Yep. Bloody inconsistencies…
Proxies are definitely used outside of testing frameworks. e.g., see https://codeberg.org/small-tech/jsdb which is entirely built on them ;)
Right, implemented workaround to JavaScript’s Proxy / Date object incompatibility in JavaScript Database (JSDB)¹ and released in version 3.0.1².
Calling methods on persisted Date objects read back into memory now works as it should.
Workaround (diff): https://codeberg.org/small-tech/jsdb/commit/9e039e76f7a149df2fa7ecbbf626f813e44c0ab2
Kudos to Pravin Divraniya for https://stackoverflow.com/a/57958494
¹ https://codeberg.org/small-tech/jsdb
² https://www.npmjs.com/package/@small-tech/jsdb
#JSDB #JavaScript #JS #database #SmallTech #Date #Proxy #web #dev
076萌SNS is a social network, courtesy of 076. It runs on GNU social, version 2.0.2-beta0, available under the GNU Affero General Public License.
All 076萌SNS content and data are available under the Creative Commons Attribution 3.0 license.