From 2cf94fe651e94395168e4228b54bfa5711ecbbd0 Mon Sep 17 00:00:00 2001 From: Dmitry Vasilev Date: Wed, 28 Feb 2024 01:48:37 +0800 Subject: [PATCH] use toJSON for Date in value explorer --- src/runtime/record_io.js | 12 +++++------- src/value_explorer_utils.js | 10 ---------- 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/src/runtime/record_io.js b/src/runtime/record_io.js index 696494f..efb4d4a 100644 --- a/src/runtime/record_io.js +++ b/src/runtime/record_io.js @@ -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 diff --git a/src/value_explorer_utils.js b/src/value_explorer_utils.js index 7699c7c..797c479 100644 --- a/src/value_explorer_utils.js +++ b/src/value_explorer_utils.js @@ -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` } } - } 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` } } - } else if(isDate(object)) { - return object.toString() } else if(isError(object)) { return object.toString() } else if(Array.isArray(object)) {