Przeglądaj źródła

test(code-runtime): cover revoked constructor spoof

Tianyi Cui 1 miesiąc temu
rodzic
commit
a552a6ce63

+ 8 - 0
packages/code-runtime/code-runtime-worker/tests/worker-json.spec.ts

@@ -103,6 +103,13 @@ describe('snapshotCodeJsonValue', () => {
     Object.defineProperty(spoofedObjectPrototype, 'constructor', { value: SpoofedObject })
     const spoofedObject = Object.create(spoofedObjectPrototype) as Record<string, unknown>
     spoofedObject.value = 1
+    const revokedPrototype = Object.create(null) as Record<string, unknown>
+    const RevokedObject = function Object() {}
+    RevokedObject.prototype = revokedPrototype
+    const revokedConstructor = Proxy.revocable(RevokedObject, {})
+    Object.defineProperty(revokedPrototype, 'constructor', { value: revokedConstructor.proxy })
+    const revokedObject = Object.create(revokedPrototype) as Record<string, unknown>
+    revokedConstructor.revoke()
     const spoofedArrayPrototype: unknown[] = []
     Object.setPrototypeOf(spoofedArrayPrototype, Object.prototype)
     const SpoofedArray = function Array() {}
@@ -124,6 +131,7 @@ describe('snapshotCodeJsonValue', () => {
       customPrototypeObject,
       forgedArray,
       spoofedObject,
+      revokedObject,
       spoofedArray,
       cyclic,
       [undefined],