summaryrefslogtreecommitdiff
path: root/ext/web/02_structured_clone.js
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2022-02-01 18:06:11 +0100
committerGitHub <noreply@github.com>2022-02-01 18:06:11 +0100
commit8176a4d1663529fb8aeebf7734c4994fa1d583f4 (patch)
tree94c7d6eb2679e641f59cf78640340f5b7af0022e /ext/web/02_structured_clone.js
parentabf89f8c4675ed78c992fafd6d758bf4bfca8a1a (diff)
refactor: primordials for instanceof (#13527)
Diffstat (limited to 'ext/web/02_structured_clone.js')
-rw-r--r--ext/web/02_structured_clone.js12
1 files changed, 7 insertions, 5 deletions
diff --git a/ext/web/02_structured_clone.js b/ext/web/02_structured_clone.js
index 005b668af..058390cfe 100644
--- a/ext/web/02_structured_clone.js
+++ b/ext/web/02_structured_clone.js
@@ -13,10 +13,12 @@
const { DOMException } = window.__bootstrap.domException;
const {
ArrayBuffer,
+ ArrayBufferPrototype,
ArrayBufferIsView,
- DataView,
+ DataViewPrototype,
+ ObjectPrototypeIsPrototypeOf,
TypedArrayPrototypeSlice,
- TypeError,
+ TypeErrorPrototype,
WeakMap,
WeakMapPrototypeSet,
} = window.__bootstrap.primordials;
@@ -42,7 +44,7 @@
function structuredClone(value) {
// Performance optimization for buffers, otherwise
// `serialize/deserialize` will allocate new buffer.
- if (value instanceof ArrayBuffer) {
+ if (ObjectPrototypeIsPrototypeOf(ArrayBufferPrototype, value)) {
const cloned = cloneArrayBuffer(
value,
0,
@@ -59,7 +61,7 @@
// only DataView has a length in bytes and TypedArrays use a length in
// terms of elements, so we adjust for that.
let length;
- if (value instanceof DataView) {
+ if (ObjectPrototypeIsPrototypeOf(DataViewPrototype, view)) {
length = value.byteLength;
} else {
length = value.length;
@@ -74,7 +76,7 @@
try {
return core.deserialize(core.serialize(value));
} catch (e) {
- if (e instanceof TypeError) {
+ if (ObjectPrototypeIsPrototypeOf(TypeErrorPrototype, e)) {
throw new DOMException("Uncloneable value", "DataCloneError");
}
throw e;