-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Labels
Description
Hi,
Encapsulation doesn't work when the object has properties that throw errors. These properties should be ignored.
To reproduce, open this HTML file in browser.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<script type="module">
import { Typeson } from "https://cdn.jsdelivr.net/npm/typeson@7.0.1/dist/typeson.esm.js";
new Typeson().encapsulate(Object.getPrototypeOf(navigator));
</script>
<script type="module">
import { Typeson } from "https://cdn.jsdelivr.net/npm/typeson@7.0.1/dist/typeson.esm.js";
const foo = {};
Object.defineProperty(foo, "bar", {
enumerable: true,
get() { throw Error("baz"); },
});
console.log(new Typeson().encapsulate(foo));
</script>
</head>
</html>This two errors are logged in console of Firefox:
Uncaught TypeError: 'get permissions' called on an object that does not implement interface Navigator.
_encapsulate https://cdn.jsdelivr.net/npm/typeson@7.0.1/dist/typeson.esm.js:1142
_adaptBuiltinStateObjectProperties https://cdn.jsdelivr.net/npm/typeson@7.0.1/dist/typeson.esm.js:957
_encapsulate https://cdn.jsdelivr.net/npm/typeson@7.0.1/dist/typeson.esm.js:1141
_encapsulate https://cdn.jsdelivr.net/npm/typeson@7.0.1/dist/typeson.esm.js:1135
encapsulate https://cdn.jsdelivr.net/npm/typeson@7.0.1/dist/typeson.esm.js:894
<anonymous> file:///home/regseb/testcase/index.html:7
typeson.esm.js:1142:25
Uncaught Error: baz
get file:///home/regseb/testcase/index.html:14
_encapsulate https://cdn.jsdelivr.net/npm/typeson@7.0.1/dist/typeson.esm.js:1142
_adaptBuiltinStateObjectProperties https://cdn.jsdelivr.net/npm/typeson@7.0.1/dist/typeson.esm.js:957
_encapsulate https://cdn.jsdelivr.net/npm/typeson@7.0.1/dist/typeson.esm.js:1141
_encapsulate https://cdn.jsdelivr.net/npm/typeson@7.0.1/dist/typeson.esm.js:1135
encapsulate https://cdn.jsdelivr.net/npm/typeson@7.0.1/dist/typeson.esm.js:894
<anonymous> file:///home/regseb/testcase/index.html:16
index.html:14:27
Or these errors in Chromium:
Uncaught TypeError: Illegal invocation
at typeson.esm.js:1142:47
at _adaptBuiltinStateObjectProperties (typeson.esm.js:957:9)
at typeson.esm.js:1141:13
at Array.forEach (<anonymous>)
at _encapsulate (typeson.esm.js:1135:23)
at Typeson.encapsulate (typeson.esm.js:894:17)
at index.html:7:23
Uncaught Error: baz
at Object.get [as bar] (index.html:14:27)
at typeson.esm.js:1142:47
at _adaptBuiltinStateObjectProperties (typeson.esm.js:957:9)
at typeson.esm.js:1141:13
at Array.forEach (<anonymous>)
at _encapsulate (typeson.esm.js:1135:23)
at Typeson.encapsulate (typeson.esm.js:894:17)
at index.html:16:35
Reactions are currently unavailable