mirror of
https://github.com/leporello-js/leporello-js
synced 2026-01-13 13:04:30 -08:00
use toJSON for Date in value explorer
This commit is contained in:
@@ -242,9 +242,9 @@ const make_patched_method = (window, original, name, use_context) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const patch_Date = (window) => {
|
const patch_Date = (window) => {
|
||||||
const Date = window.Date
|
const Date_original = window.Date
|
||||||
const Date_patched = make_patched_method(window, Date, 'Date', false)
|
const Date_patched = make_patched_method(window, Date_original, 'Date', false)
|
||||||
window.Date = function(...args) {
|
window.Date = function Date(...args) {
|
||||||
if(args.length == 0) {
|
if(args.length == 0) {
|
||||||
// return current Date, IO operation
|
// return current Date, IO operation
|
||||||
if(new.target != null) {
|
if(new.target != null) {
|
||||||
@@ -255,14 +255,12 @@ const patch_Date = (window) => {
|
|||||||
} else {
|
} else {
|
||||||
// pure function
|
// pure function
|
||||||
if(new.target != null) {
|
if(new.target != null) {
|
||||||
return new Date(...args)
|
return new Date_original(...args)
|
||||||
} else {
|
} else {
|
||||||
return Date(...args)
|
return Date_original(...args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
window.Date.__original = Date
|
|
||||||
|
|
||||||
window.Date.parse = Date.parse
|
window.Date.parse = Date.parse
|
||||||
window.Date.now = Date.now
|
window.Date.now = Date.now
|
||||||
window.Date.UTC = Date.UTC
|
window.Date.UTC = Date.UTC
|
||||||
|
|||||||
@@ -13,12 +13,6 @@ const isError = object =>
|
|||||||
|
|
||||||
const isPromise = object => object?.[Symbol.toStringTag] == 'Promise'
|
const isPromise = object => object?.[Symbol.toStringTag] == 'Promise'
|
||||||
|
|
||||||
// Override behaviour for Date, becase Date has toJSON defined
|
|
||||||
const isDate = object =>
|
|
||||||
object instanceof globalThis.app_window.Date
|
|
||||||
||
|
|
||||||
object instanceof globalThis.app_window.Date.__original
|
|
||||||
|
|
||||||
// Workaround try/catch is not implemented currently
|
// Workaround try/catch is not implemented currently
|
||||||
const toJSON_safe = new Function('object', `
|
const toJSON_safe = new Function('object', `
|
||||||
try {
|
try {
|
||||||
@@ -108,8 +102,6 @@ export const stringify_for_header = (v, no_toJSON = false) => {
|
|||||||
return `Promise<rejected: ${stringify_for_header(v.status.error)}>`
|
return `Promise<rejected: ${stringify_for_header(v.status.error)}>`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (isDate(v)) {
|
|
||||||
return v.toString()
|
|
||||||
} else if(isError(v)) {
|
} else if(isError(v)) {
|
||||||
return v.toString()
|
return v.toString()
|
||||||
} else if(Array.isArray(v)) {
|
} else if(Array.isArray(v)) {
|
||||||
@@ -181,8 +173,6 @@ export const header = (object, no_toJSON = false) => {
|
|||||||
return `Promise<rejected: ${header(object.status.error)}>`
|
return `Promise<rejected: ${header(object.status.error)}>`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if(isDate(object)) {
|
|
||||||
return object.toString()
|
|
||||||
} else if(isError(object)) {
|
} else if(isError(object)) {
|
||||||
return object.toString()
|
return object.toString()
|
||||||
} else if(Array.isArray(object)) {
|
} else if(Array.isArray(object)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user