-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lib: convert transfer sequence to array in js
- Loading branch information
Showing
7 changed files
with
97 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
'use strict'; | ||
|
||
const { | ||
codes: { | ||
ERR_INVALID_ARG_TYPE, | ||
ERR_MISSING_ARGS, | ||
}, | ||
} = require('internal/errors'); | ||
const webidl = require('internal/webidl'); | ||
|
||
const { | ||
structuredClone: nativeStructuredClone, | ||
} = internalBinding('messaging'); | ||
|
||
webidl.converters['sequence<object>'] = webidl.createSequenceConverter(webidl.converters.any); | ||
|
||
function structuredClone(value, options) { | ||
if (arguments.length === 0) { | ||
throw new ERR_MISSING_ARGS('The value argument must be specified'); | ||
} | ||
|
||
// TODO(jazelly): implement generic webidl dictionary converter | ||
const prefix = 'Options'; | ||
const optionsType = webidl.type(options); | ||
if (optionsType !== 'Undefined' && optionsType !== 'Null' && optionsType !== 'Object') { | ||
throw new ERR_INVALID_ARG_TYPE( | ||
prefix, | ||
['object', 'null', 'undefined'], | ||
options, | ||
); | ||
} | ||
const key = 'transfer'; | ||
const idlOptions = { __proto__: null, [key]: [] }; | ||
if (options !== undefined && options !== null && key in options && options[key] !== undefined) { | ||
idlOptions[key] = webidl.converters['sequence<transfer>'](options[key], { | ||
__proto__: null, | ||
context: 'Transfer', | ||
}); | ||
} | ||
|
||
const serializedData = nativeStructuredClone(value, idlOptions); | ||
return serializedData; | ||
} | ||
|
||
module.exports = { | ||
structuredClone, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters