Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src-runtime/inspectType.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {options } from './options.js';
import {validateType } from './validateType.js';
import {partition } from './partition.js';
import {importNamespaceSpecifiers} from './registerImportNamespaceSpecifier.js';
import {isClonable } from './isClonable.js';
const breakpoints = new Set();
// In the simplest case we are attaching to `window` here, but it's designed to handle
// more complex scenarious like running RTI inside a `Worker` or `<iframe>` aswell.
Expand Down Expand Up @@ -106,10 +107,9 @@ function inspectType(value, expect, loc, name, critical = true) {
crossContextPostMessage({type: 'rti', action: 'deleteBreakpoint', destination: 'ui', key});
}
// Nytaralyxe: options.warns where each warn callback supports one system (node, div/dom etc.)
// Don't post something that can't be transmitted cross-context, so we just stringify it.
// See https://github.com/kungfooman/RuntimeTypeInspector.js/issues/223
if (value instanceof Function) {
value += "";
// Don't post `value` when it can't be transmitted cross-context (just stringify it instead).
if (!isClonable(value)) {
value = valueToString;
}
crossContextPostMessage({type: 'rti', action: 'addError', destination: 'ui', value, expect, loc, name, valueToString, strings, extras, key});
}
Expand Down
13 changes: 13 additions & 0 deletions src-runtime/isClonable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* @param {*} value - The value that we need to validate.
* @returns {boolean} Boolean indicating if value is clonable.
*/
function isClonable(value) {
try {
structuredClone(value);
return true;
} catch (e) {
return false;
}
}
export {isClonable};