summaryrefslogtreecommitdiff
path: root/ext/web/02_structured_clone.js
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2022-01-27 13:36:36 +0100
committerGitHub <noreply@github.com>2022-01-27 13:36:36 +0100
commit884143218fad0e18f7553aaf079d52de703f7601 (patch)
tree9b9e9d30ea647041438ef8fa974b8d4234cabf73 /ext/web/02_structured_clone.js
parentdcf8f144ab0516936bfa4e93357d71f1732d880e (diff)
refactor: update runtime code for primordial checks for "instanceof" (#13497)
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;