Skip to content

Commit

Permalink
feat: async encapsulation
Browse files Browse the repository at this point in the history
  • Loading branch information
brettz9 committed Aug 22, 2024
1 parent fd32e4a commit 7308737
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 95 deletions.
2 changes: 1 addition & 1 deletion badges/coverage-badge.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions instrumented/deepEqual.js

Large diffs are not rendered by default.

18 changes: 7 additions & 11 deletions instrumented/demo/index-schema.js

Large diffs are not rendered by default.

18 changes: 7 additions & 11 deletions instrumented/demo/index.js

Large diffs are not rendered by default.

18 changes: 7 additions & 11 deletions instrumented/demo/schema-preloaded-array.js

Large diffs are not rendered by default.

18 changes: 7 additions & 11 deletions instrumented/demo/schema-preloaded.js

Large diffs are not rendered by default.

20 changes: 8 additions & 12 deletions instrumented/formats/structuredCloning.js

Large diffs are not rendered by default.

68 changes: 33 additions & 35 deletions src/formats/structuredCloning.js
Original file line number Diff line number Diff line change
Expand Up @@ -484,47 +484,45 @@ const canonicalTypeToAvailableTypeAndSchema = (

/** @type {import('../formats.js').Format} */
const structuredCloning = {
iterate (records, stateObj) {
async iterate (records, stateObj) {
/* istanbul ignore if -- Just a guard */
if (!stateObj.format) {
stateObj.format = 'structuredCloning';
}
// Todo: Replace this with async typeson?
// eslint-disable-next-line promise/avoid-new -- Our own API for now
return new Promise((resolve, reject) => {
const structuredCloningFixed = structuredCloningThrowing.filter(
(typeSpecSet) => {
return ![
// Not yet supported within JSOE
'imagedata',
'imagebitmap',
'cryptokey',
'domquad'
].some((prop) => {
return Object.hasOwn(typeSpecSet, prop);
});
}
);
structuredCloningFixed.splice(
// Add after userObjects
1,
0,
noneditable
);
const typeson = new Typeson({
encapsulateObserver: encapsulateObserver(stateObj)
}).register(structuredCloningFixed);
typeson.encapsulate(records);
// Todo (low): We might want to run async encapsulate for
// async types (and put this after Promise resolves)
if (stateObj.error) {
reject(stateObj.error);
} else {
resolve(/** @type {Required<import('../types.js').StateObject>} */ (
stateObj
));

const structuredCloningFixed = structuredCloningThrowing.filter(
(typeSpecSet) => {
return ![
// Not yet supported within JSOE
'imagedata',
'imagebitmap',
'cryptokey',
'domquad'
].some((prop) => {
return Object.hasOwn(typeSpecSet, prop);
});
}
);
structuredCloningFixed.splice(
// Add after userObjects
1,
0,
noneditable
);
const typeson = new Typeson({
encapsulateObserver: encapsulateObserver(stateObj)
}).register(structuredCloningFixed);

await typeson.encapsulateAsync(records, null, {
throwOnBadSyncType: false
});

if (stateObj.error) {
throw stateObj.error;
}
return (/** @type {Required<import('../types.js').StateObject>} */ (
stateObj
));
},
getTypesAndSchemasForState (types, state) {
if (state && types.getContextInfo('structuredCloning', state)) {
Expand Down

0 comments on commit 7308737

Please sign in to comment.