From ce739dffe192fcf0cdb480f3058985854703d44f Mon Sep 17 00:00:00 2001 From: hieuit095 <139037144+hieuit095@users.noreply.github.com> Date: Fri, 27 Mar 2026 16:11:49 +0700 Subject: [PATCH] refactor: fix serialization of native functions like number, string The issue is that serialize-javascript throws a TypeError when trying to serialize native functions (like `Number`, `String`, `Array`, etc.). The fix should detect native built-in constructors and serialize them by their name (e.g., `Number` instead of throwing an error). Affected files: index.js Signed-off-by: hieuit095 <139037144+hieuit095@users.noreply.github.com> --- index.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/index.js b/index.js index 2389110..edd06ab 100644 --- a/index.js +++ b/index.js @@ -159,6 +159,9 @@ module.exports = function serialize(obj, options) { function serializeFunc(fn, options) { var serializedFn = fn.toString(); if (IS_NATIVE_CODE_REGEXP.test(serializedFn)) { + if (fn.name) { + return fn.name; + } throw new TypeError('Serializing native function: ' + fn.name); }