use toJSON for Date in value explorer

This commit is contained in:
Dmitry Vasilev
2024-02-28 01:48:37 +08:00
parent e70eaa31d5
commit 2cf94fe651
2 changed files with 5 additions and 17 deletions

View File

@@ -242,9 +242,9 @@ const make_patched_method = (window, original, name, use_context) => {
}
const patch_Date = (window) => {
const Date = window.Date
const Date_patched = make_patched_method(window, Date, 'Date', false)
window.Date = function(...args) {
const Date_original = window.Date
const Date_patched = make_patched_method(window, Date_original, 'Date', false)
window.Date = function Date(...args) {
if(args.length == 0) {
// return current Date, IO operation
if(new.target != null) {
@@ -255,14 +255,12 @@ const patch_Date = (window) => {
} else {
// pure function
if(new.target != null) {
return new Date(...args)
return new Date_original(...args)
} else {
return Date(...args)
return Date_original(...args)
}
}
}
window.Date.__original = Date
window.Date.parse = Date.parse
window.Date.now = Date.now
window.Date.UTC = Date.UTC

View File

@@ -13,12 +13,6 @@ const isError = object =>
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
const toJSON_safe = new Function('object', `
try {
@@ -108,8 +102,6 @@ export const stringify_for_header = (v, no_toJSON = false) => {
return `Promise<rejected: ${stringify_for_header(v.status.error)}>`
}
}
} else if (isDate(v)) {
return v.toString()
} else if(isError(v)) {
return v.toString()
} else if(Array.isArray(v)) {
@@ -181,8 +173,6 @@ export const header = (object, no_toJSON = false) => {
return `Promise<rejected: ${header(object.status.error)}>`
}
}
} else if(isDate(object)) {
return object.toString()
} else if(isError(object)) {
return object.toString()
} else if(Array.isArray(object)) {