Skip to content

Commit 199ff37

Browse files
authored
Fix DataCloneError's by preventing known unclonable values (will be… … send as string instead) (#224)
* Fix `DataCloneError`'s by preventing known unclonable values (will be send as string instead) * Fix unit test
1 parent b6e093a commit 199ff37

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src-runtime/inspectType.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ function inspectType(value, expect, loc, name, critical = true) {
106106
crossContextPostMessage({type: 'rti', action: 'deleteBreakpoint', destination: 'ui', key});
107107
}
108108
// Nytaralyxe: options.warns where each warn callback supports one system (node, div/dom etc.)
109+
// Don't post something that can't be transmitted cross-context, so we just stringify it.
110+
// See https://github.com/kungfooman/RuntimeTypeInspector.js/issues/223
111+
if (value instanceof Function) {
112+
value += "";
113+
}
109114
crossContextPostMessage({type: 'rti', action: 'addError', destination: 'ui', value, expect, loc, name, valueToString, strings, extras, key});
110115
}
111116
return ret;

test/convert-first/test-typeof.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ class TestClass2 {
1919
function callNew(someClass, ...args) {
2020
return new someClass(...args);
2121
}
22+
options.count = 0;
2223
const testClass1 = callNew(TestClass1, "hoi1");
2324
console.assert(options.count === 0, "Should have 0 errors here");
2425
const testClass2 = callNew(TestClass2, "hoi2");
2526
console.assert(options.count === 1, "Should have 1 error here");
27+
if (options.count === 1) {
28+
console.log("SUCCESS!");
29+
}

0 commit comments

Comments
 (0)