legacy-callback-interface-object.html (2709B)
1 <!doctype html> 2 <meta charset="utf-8"> 3 <title>Legacy callback interface objects</title> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <link rel="author" title="Domenic Denicola" href="mailto:d@domenic.me"> 7 <link rel="help" href="https://webidl.spec.whatwg.org/#legacy-callback-interface-object"> 8 9 <script> 10 test(() => { 11 assert_equals(typeof NodeFilter, "function"); 12 }, "Must be a function according to typeof"); 13 14 test(() => { 15 assert_true(Object.getPrototypeOf(NodeFilter) === Function.prototype); 16 }, "Must have the correct [[Prototype]]"); 17 18 test(() => { 19 const propDesc = Object.getOwnPropertyDescriptor(window, "NodeFilter"); 20 assert_true(propDesc.writable, "writable"); 21 assert_false(propDesc.enumerable, "enumerable"); 22 assert_true(propDesc.configurable, "configurable"); 23 }, "Must have the correct property descriptor"); 24 25 test(() => { 26 assert_throws_js(TypeError, () => NodeFilter(), "call"); 27 assert_throws_js(TypeError, () => new NodeFilter(), "construct"); 28 }, "Must throw a TypeError when called or constructed") 29 30 test(() => { 31 assert_false(NodeFilter.hasOwnProperty("prototype")); 32 }, "Must not have a .prototype property"); 33 34 test(() => { 35 assert_true(NodeFilter.hasOwnProperty("name")); 36 assert_equals(NodeFilter.name, "NodeFilter"); 37 38 const propDesc = Object.getOwnPropertyDescriptor(NodeFilter, "name"); 39 assert_false(propDesc.writable, "writable"); 40 assert_false(propDesc.enumerable, "enumerable"); 41 assert_true(propDesc.configurable, "configurable"); 42 }, "Must have an own name property equal to the interface name and with the correct descriptors"); 43 44 test(() => { 45 assert_true(NodeFilter.hasOwnProperty("length")); 46 assert_equals(NodeFilter.length, 0); 47 48 const propDesc = Object.getOwnPropertyDescriptor(NodeFilter, "length"); 49 assert_false(propDesc.writable, "writable"); 50 assert_false(propDesc.enumerable, "enumerable"); 51 assert_true(propDesc.configurable, "configurable"); 52 }, "Must have an own length property with value zero and the correct descriptors"); 53 54 test(() => { 55 // The JS spec (OrdinaryHasInstance) bails out early for non-objects 56 // Historically we overrode [[HasInstance]] to throw anyway, but this was removed: 57 // https://github.com/heycam/webidl/pull/356 58 assert_false(5 instanceof NodeFilter, "5"); 59 60 // OrdinaryHasInstance throws a TypeError if the right-hand-side doesn't have a .prototype object, 61 // which is the case for callback interfaces. 62 assert_throws_js(TypeError, () => { 63 (function () { }) instanceof NodeFilter; 64 }); 65 assert_throws_js(TypeError, () => { 66 ({ }) instanceof NodeFilter; 67 }); 68 }, "instanceof must throw but only when we don't bail out early"); 69 </script>