class-string-interface.any.js (2747B)
1 "use strict"; 2 3 test(() => { 4 assert_own_property(Blob.prototype, Symbol.toStringTag); 5 6 const propDesc = Object.getOwnPropertyDescriptor(Blob.prototype, Symbol.toStringTag); 7 assert_equals(propDesc.value, "Blob", "value"); 8 assert_equals(propDesc.configurable, true, "configurable"); 9 assert_equals(propDesc.enumerable, false, "enumerable"); 10 assert_equals(propDesc.writable, false, "writable"); 11 }, "@@toStringTag exists on the prototype with the appropriate descriptor"); 12 13 test(() => { 14 assert_not_own_property(new Blob(), Symbol.toStringTag); 15 }, "@@toStringTag must not exist on the instance"); 16 17 test(() => { 18 assert_equals(Object.prototype.toString.call(Blob.prototype), "[object Blob]"); 19 }, "Object.prototype.toString applied to the prototype"); 20 21 test(() => { 22 assert_equals(Object.prototype.toString.call(new Blob()), "[object Blob]"); 23 }, "Object.prototype.toString applied to an instance"); 24 25 test(t => { 26 assert_own_property(Blob.prototype, Symbol.toStringTag, "Precondition for this test: @@toStringTag on the prototype"); 27 28 t.add_cleanup(() => { 29 Object.defineProperty(Blob.prototype, Symbol.toStringTag, { value: "Blob" }); 30 }); 31 32 Object.defineProperty(Blob.prototype, Symbol.toStringTag, { value: "NotABlob" }); 33 assert_equals(Object.prototype.toString.call(Blob.prototype), "[object NotABlob]", "prototype"); 34 assert_equals(Object.prototype.toString.call(new Blob()), "[object NotABlob]", "instance"); 35 }, "Object.prototype.toString applied after modifying the prototype's @@toStringTag"); 36 37 test(t => { 38 const instance = new Blob(); 39 assert_not_own_property(instance, Symbol.toStringTag, "Precondition for this test: no @@toStringTag on the instance"); 40 41 Object.defineProperty(instance, Symbol.toStringTag, { value: "NotABlob" }); 42 assert_equals(Object.prototype.toString.call(instance), "[object NotABlob]"); 43 }, "Object.prototype.toString applied to the instance after modifying the instance's @@toStringTag"); 44 45 // Chrome had a bug (https://bugs.chromium.org/p/chromium/issues/detail?id=793406) where if there 46 // was no @@toStringTag in the prototype, it would fall back to a magic class string. This tests 47 // that the bug is fixed. 48 49 test(() => { 50 const instance = new Blob(); 51 Object.setPrototypeOf(instance, null); 52 53 assert_equals(Object.prototype.toString.call(instance), "[object Object]"); 54 }, "Object.prototype.toString applied to a null-prototype instance"); 55 56 // This test must be last. 57 test(() => { 58 delete Blob.prototype[Symbol.toStringTag]; 59 60 assert_equals(Object.prototype.toString.call(Blob.prototype), "[object Object]", "prototype"); 61 assert_equals(Object.prototype.toString.call(new Blob()), "[object Object]", "instance"); 62 }, "Object.prototype.toString applied after deleting @@toStringTag");