| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -56,7 +56,7 @@ const { | |||
| 56 | 56 | } = require('internal/util/types'); | |
| 57 | 57 | ||
| 58 | 58 | const { | |
| 59 | - JSTransferable, | ||
| 59 | + makeTransferable, | ||
| 60 | 60 | kClone, | |
| 61 | 61 | kDeserialize, | |
| 62 | 62 | } = require('internal/worker/js_transferable'); | |
@@ -630,14 +630,12 @@ function isKeyObject(obj) { | |||
| 630 | 630 | } | |
| 631 | 631 | ||
| 632 | 632 | // Our implementation of CryptoKey is a simple wrapper around a KeyObject | |
| 633 | - // that adapts it to the standard interface. This implementation also | ||
| 634 | - // extends the JSTransferable class, allowing the CryptoKey to be cloned | ||
| 635 | - // to Workers. | ||
| 633 | + // that adapts it to the standard interface. | ||
| 636 | 634 | // TODO(@jasnell): Embedder environments like electron may have issues | |
| 637 | 635 | // here similar to other things like URL. A chromium provided CryptoKey | |
| 638 | 636 | // will not be recognized as a Node.js CryptoKey, and vice versa. It | |
| 639 | 637 | // would be fantastic if we could find a way of making those interop. | |
| 640 | - class CryptoKey extends JSTransferable { | ||
| 638 | + class CryptoKey { | ||
| 641 | 639 | constructor() { | |
| 642 | 640 | throw new ERR_ILLEGAL_CONSTRUCTOR(); | |
| 643 | 641 | } | |
@@ -682,30 +680,6 @@ class CryptoKey extends JSTransferable { | |||
| 682 | 680 | throw new ERR_INVALID_THIS('CryptoKey'); | |
| 683 | 681 | return ArrayFrom(this[kKeyUsages]); | |
| 684 | 682 | } | |
| 685 | - | ||
| 686 | - [kClone]() { | ||
| 687 | - const keyObject = this[kKeyObject]; | ||
| 688 | - const algorithm = this.algorithm; | ||
| 689 | - const extractable = this.extractable; | ||
| 690 | - const usages = this.usages; | ||
| 691 | - | ||
| 692 | - return { | ||
| 693 | - data: { | ||
| 694 | - keyObject, | ||
| 695 | - algorithm, | ||
| 696 | - usages, | ||
| 697 | - extractable, | ||
| 698 | - }, | ||
| 699 | - deserializeInfo: 'internal/crypto/keys:InternalCryptoKey' | ||
| 700 | - }; | ||
| 701 | - } | ||
| 702 | - | ||
| 703 | - [kDeserialize]({ keyObject, algorithm, usages, extractable }) { | ||
| 704 | - this[kKeyObject] = keyObject; | ||
| 705 | - this[kAlgorithm] = algorithm; | ||
| 706 | - this[kKeyUsages] = usages; | ||
| 707 | - this[kExtractable] = extractable; | ||
| 708 | - } | ||
| 709 | 683 | } | |
| 710 | 684 | ||
| 711 | 685 | ObjectDefineProperties(CryptoKey.prototype, { | |
@@ -718,23 +692,50 @@ ObjectDefineProperties(CryptoKey.prototype, { | |||
| 718 | 692 | // All internal code must use new InternalCryptoKey to create | |
| 719 | 693 | // CryptoKey instances. The CryptoKey class is exposed to end | |
| 720 | 694 | // user code but is not permitted to be constructed directly. | |
| 721 | - class InternalCryptoKey extends JSTransferable { | ||
| 695 | + // Using makeTransferable also allows the CryptoKey to be | ||
| 696 | + // cloned to Workers. | ||
| 697 | + class InternalCryptoKey { | ||
| 722 | 698 | constructor( | |
| 723 | 699 | keyObject, | |
| 724 | 700 | algorithm, | |
| 725 | 701 | keyUsages, | |
| 726 | 702 | extractable) { | |
| 727 | - super(); | ||
| 728 | 703 | // Using symbol properties here currently instead of private | |
| 729 | 704 | // properties because (for now) the performance penalty of | |
| 730 | 705 | // private fields is still too high. | |
| 731 | 706 | this[kKeyObject] = keyObject; | |
| 732 | 707 | this[kAlgorithm] = algorithm; | |
| 733 | 708 | this[kExtractable] = extractable; | |
| 734 | 709 | this[kKeyUsages] = keyUsages; | |
| 710 | + | ||
| 711 | + // eslint-disable-next-line no-constructor-return | ||
| 712 | + return makeTransferable(this); | ||
| 735 | 713 | } | |
| 736 | - } | ||
| 737 | 714 | ||
| 715 | + [kClone]() { | ||
| 716 | + const keyObject = this[kKeyObject]; | ||
| 717 | + const algorithm = this.algorithm; | ||
| 718 | + const extractable = this.extractable; | ||
| 719 | + const usages = this.usages; | ||
| 720 | + | ||
| 721 | + return { | ||
| 722 | + data: { | ||
| 723 | + keyObject, | ||
| 724 | + algorithm, | ||
| 725 | + usages, | ||
| 726 | + extractable, | ||
| 727 | + }, | ||
| 728 | + deserializeInfo: 'internal/crypto/keys:InternalCryptoKey' | ||
| 729 | + }; | ||
| 730 | + } | ||
| 731 | + | ||
| 732 | + [kDeserialize]({ keyObject, algorithm, usages, extractable }) { | ||
| 733 | + this[kKeyObject] = keyObject; | ||
| 734 | + this[kAlgorithm] = algorithm; | ||
| 735 | + this[kKeyUsages] = usages; | ||
| 736 | + this[kExtractable] = extractable; | ||
| 737 | + } | ||
| 738 | + } | ||
| 738 | 739 | InternalCryptoKey.prototype.constructor = CryptoKey; | |
| 739 | 740 | ObjectSetPrototypeOf(InternalCryptoKey.prototype, CryptoKey.prototype); | |
| 740 | 741 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments