How to use exposed_in method in wpt

Best JavaScript code snippet using wpt

idlharness.js

Source:idlharness.js Github

copy

Full Screen

...415 set = [ set ];416 }417 return set;418}419function exposed_in(globals) {420 if ('document' in self) {421 return globals.indexOf("Window") >= 0;422 }423 if ('DedicatedWorkerGlobalScope' in self &&424 self instanceof DedicatedWorkerGlobalScope) {425 return globals.indexOf("Worker") >= 0 ||426 globals.indexOf("DedicatedWorker") >= 0;427 }428 if ('SharedWorkerGlobalScope' in self &&429 self instanceof SharedWorkerGlobalScope) {430 return globals.indexOf("Worker") >= 0 ||431 globals.indexOf("SharedWorker") >= 0;432 }433 if ('ServiceWorkerGlobalScope' in self &&434 self instanceof ServiceWorkerGlobalScope) {435 return globals.indexOf("Worker") >= 0 ||436 globals.indexOf("ServiceWorker") >= 0;437 }438 throw "Unexpected global object";439}440//@}441IdlArray.prototype.test = function()442//@{443{444 /** Entry point. See documentation at beginning of file. */445 // First merge in all the partial interfaces and implements statements we446 // encountered.447 this.partials.forEach(function(parsed_idl)448 {449 if (!(parsed_idl.name in this.members)450 || !(this.members[parsed_idl.name] instanceof IdlInterface))451 {452 throw "Partial interface " + parsed_idl.name + " with no original interface";453 }454 if (parsed_idl.extAttrs)455 {456 parsed_idl.extAttrs.forEach(function(extAttr)457 {458 this.members[parsed_idl.name].extAttrs.push(extAttr);459 }.bind(this));460 }461 parsed_idl.members.forEach(function(member)462 {463 this.members[parsed_idl.name].members.push(new IdlInterfaceMember(member));464 }.bind(this));465 }.bind(this));466 this.partials = [];467 for (var lhs in this["implements"])468 {469 this.recursively_get_implements(lhs).forEach(function(rhs)470 {471 var errStr = lhs + " implements " + rhs + ", but ";472 if (!(lhs in this.members)) throw errStr + lhs + " is undefined.";473 if (!(this.members[lhs] instanceof IdlInterface)) throw errStr + lhs + " is not an interface.";474 if (!(rhs in this.members)) throw errStr + rhs + " is undefined.";475 if (!(this.members[rhs] instanceof IdlInterface)) throw errStr + rhs + " is not an interface.";476 this.members[rhs].members.forEach(function(member)477 {478 this.members[lhs].members.push(new IdlInterfaceMember(member));479 }.bind(this));480 }.bind(this));481 }482 this["implements"] = {};483 Object.getOwnPropertyNames(this.members).forEach(function(memberName) {484 var member = this.members[memberName];485 if (!(member instanceof IdlInterface)) {486 return;487 }488 var globals = exposure_set(member, ["Window"]);489 member.exposed = exposed_in(globals);490 member.exposureSet = globals;491 }.bind(this));492 // Now run test() on every member, and test_object() for every object.493 for (var name in this.members)494 {495 this.members[name].test();496 if (name in this.objects)497 {498 this.objects[name].forEach(function(str)499 {500 this.members[name].test_object(str);501 }.bind(this));502 }503 }504};505//@}506IdlArray.prototype.assert_type_is = function(value, type)507//@{508{509 if (type.idlType in this.members510 && this.members[type.idlType] instanceof IdlTypedef) {511 this.assert_type_is(value, this.members[type.idlType].idlType);512 return;513 }514 if (type.union) {515 for (var i = 0; i < type.idlType.length; i++) {516 try {517 this.assert_type_is(value, type.idlType[i]);518 // No AssertionError, so we match one type in the union519 return;520 } catch(e) {521 if (e instanceof AssertionError) {522 // We didn't match this type, let's try some others523 continue;524 }525 throw e;526 }527 }528 // TODO: Is there a nice way to list the union's types in the message?529 assert_true(false, "Attribute has value " + format_value(value)530 + " which doesn't match any of the types in the union");531 }532 /**533 * Helper function that tests that value is an instance of type according534 * to the rules of WebIDL. value is any JavaScript value, and type is an535 * object produced by WebIDLParser.js' "type" production. That production536 * is fairly elaborate due to the complexity of WebIDL's types, so it's537 * best to look at the grammar to figure out what properties it might have.538 */539 if (type.idlType == "any")540 {541 // No assertions to make542 return;543 }544 if (type.nullable && value === null)545 {546 // This is fine547 return;548 }549 if (type.array)550 {551 // TODO: not supported yet552 return;553 }554 if (type.sequence)555 {556 assert_true(Array.isArray(value), "should be an Array");557 if (!value.length)558 {559 // Nothing we can do.560 return;561 }562 this.assert_type_is(value[0], type.idlType);563 return;564 }565 if (type.generic === "Promise") {566 assert_true("then" in value, "Attribute with a Promise type should have a then property");567 // TODO: Ideally, we would check on project fulfillment568 // that we get the right type569 // but that would require making the type check async570 return;571 }572 if (type.generic === "FrozenArray") {573 assert_true(Array.isArray(value), "Value should be array");574 assert_true(Object.isFrozen(value), "Value should be frozen");575 if (!value.length)576 {577 // Nothing we can do.578 return;579 }580 this.assert_type_is(value[0], type.idlType);581 return;582 }583 type = type.idlType;584 switch(type)585 {586 case "void":587 assert_equals(value, undefined);588 return;589 case "boolean":590 assert_equals(typeof value, "boolean");591 return;592 case "byte":593 assert_equals(typeof value, "number");594 assert_equals(value, Math.floor(value), "should be an integer");595 assert_true(-128 <= value && value <= 127, "byte " + value + " should be in range [-128, 127]");596 return;597 case "octet":598 assert_equals(typeof value, "number");599 assert_equals(value, Math.floor(value), "should be an integer");600 assert_true(0 <= value && value <= 255, "octet " + value + " should be in range [0, 255]");601 return;602 case "short":603 assert_equals(typeof value, "number");604 assert_equals(value, Math.floor(value), "should be an integer");605 assert_true(-32768 <= value && value <= 32767, "short " + value + " should be in range [-32768, 32767]");606 return;607 case "unsigned short":608 assert_equals(typeof value, "number");609 assert_equals(value, Math.floor(value), "should be an integer");610 assert_true(0 <= value && value <= 65535, "unsigned short " + value + " should be in range [0, 65535]");611 return;612 case "long":613 assert_equals(typeof value, "number");614 assert_equals(value, Math.floor(value), "should be an integer");615 assert_true(-2147483648 <= value && value <= 2147483647, "long " + value + " should be in range [-2147483648, 2147483647]");616 return;617 case "unsigned long":618 assert_equals(typeof value, "number");619 assert_equals(value, Math.floor(value), "should be an integer");620 assert_true(0 <= value && value <= 4294967295, "unsigned long " + value + " should be in range [0, 4294967295]");621 return;622 case "long long":623 assert_equals(typeof value, "number");624 return;625 case "unsigned long long":626 case "DOMTimeStamp":627 assert_equals(typeof value, "number");628 assert_true(0 <= value, "unsigned long long should be positive");629 return;630 case "float":631 assert_equals(typeof value, "number");632 assert_equals(value, fround(value), "float rounded to 32-bit float should be itself");633 assert_not_equals(value, Infinity);634 assert_not_equals(value, -Infinity);635 assert_not_equals(value, NaN);636 return;637 case "DOMHighResTimeStamp":638 case "double":639 assert_equals(typeof value, "number");640 assert_not_equals(value, Infinity);641 assert_not_equals(value, -Infinity);642 assert_not_equals(value, NaN);643 return;644 case "unrestricted float":645 assert_equals(typeof value, "number");646 assert_equals(value, fround(value), "unrestricted float rounded to 32-bit float should be itself");647 return;648 case "unrestricted double":649 assert_equals(typeof value, "number");650 return;651 case "DOMString":652 assert_equals(typeof value, "string");653 return;654 case "ByteString":655 assert_equals(typeof value, "string");656 assert_regexp_match(value, /^[\x00-\x7F]*$/);657 return;658 case "USVString":659 assert_equals(typeof value, "string");660 assert_regexp_match(value, /^([\x00-\ud7ff\ue000-\uffff]|[\ud800-\udbff][\udc00-\udfff])*$/);661 return;662 case "object":663 assert_in_array(typeof value, ["object", "function"], "wrong type: not object or function");664 return;665 }666 if (!(type in this.members))667 {668 throw "Unrecognized type " + type;669 }670 if (this.members[type] instanceof IdlInterface)671 {672 // We don't want to run the full673 // IdlInterface.prototype.test_instance_of, because that could result674 // in an infinite loop. TODO: This means we don't have tests for675 // NoInterfaceObject interfaces, and we also can't test objects that676 // come from another self.677 assert_in_array(typeof value, ["object", "function"], "wrong type: not object or function");678 if (value instanceof Object679 && !this.members[type].has_extended_attribute("NoInterfaceObject")680 && type in self)681 {682 assert_true(value instanceof self[type], "instanceof " + type);683 }684 }685 else if (this.members[type] instanceof IdlEnum)686 {687 assert_equals(typeof value, "string");688 }689 else if (this.members[type] instanceof IdlDictionary)690 {691 // TODO: Test when we actually have something to test this on692 }693 else694 {695 throw "Type " + type + " isn't an interface or dictionary";696 }697};698//@}699/// IdlObject ///700function IdlObject() {}701IdlObject.prototype.test = function()702//@{703{704 /**705 * By default, this does nothing, so no actual tests are run for IdlObjects706 * that don't define any (e.g., IdlDictionary at the time of this writing).707 */708};709//@}710IdlObject.prototype.has_extended_attribute = function(name)711//@{712{713 /**714 * This is only meaningful for things that support extended attributes,715 * such as interfaces, exceptions, and members.716 */717 return this.extAttrs.some(function(o)718 {719 return o.name == name;720 });721};722//@}723/// IdlDictionary ///724// Used for IdlArray.prototype.assert_type_is725function IdlDictionary(obj)726//@{727{728 /**729 * obj is an object produced by the WebIDLParser.js "dictionary"730 * production.731 */732 /** Self-explanatory. */733 this.name = obj.name;734 /** A back-reference to our IdlArray. */735 this.array = obj.array;736 /** An array of objects produced by the "dictionaryMember" production. */737 this.members = obj.members;738 /**739 * The name (as a string) of the dictionary type we inherit from, or null740 * if there is none.741 */742 this.base = obj.inheritance;743}744//@}745IdlDictionary.prototype = Object.create(IdlObject.prototype);746IdlDictionary.prototype.get_inheritance_stack = function() {747 return IdlInterface.prototype.get_inheritance_stack.call(this);748};749/// IdlInterface ///750function IdlInterface(obj, is_callback)751//@{752{753 /**754 * obj is an object produced by the WebIDLParser.js "interface" production.755 */756 /** Self-explanatory. */757 this.name = obj.name;758 /** A back-reference to our IdlArray. */759 this.array = obj.array;760 /**761 * An indicator of whether we should run tests on the interface object and762 * interface prototype object. Tests on members are controlled by .untested763 * on each member, not this.764 */765 this.untested = obj.untested;766 /** An array of objects produced by the "ExtAttr" production. */767 this.extAttrs = obj.extAttrs;768 /** An array of IdlInterfaceMembers. */769 this.members = obj.members.map(function(m){return new IdlInterfaceMember(m); });770 if (this.has_extended_attribute("Unforgeable")) {771 this.members772 .filter(function(m) { return !m["static"] && (m.type == "attribute" || m.type == "operation"); })773 .forEach(function(m) { return m.isUnforgeable = true; });774 }775 /**776 * The name (as a string) of the type we inherit from, or null if there is777 * none.778 */779 this.base = obj.inheritance;780 this._is_callback = is_callback;781}782//@}783IdlInterface.prototype = Object.create(IdlObject.prototype);784IdlInterface.prototype.is_callback = function()785//@{786{787 return this._is_callback;788};789//@}790IdlInterface.prototype.has_constants = function()791//@{792{793 return this.members.some(function(member) {794 return member.type === "const";795 });796};797//@}798IdlInterface.prototype.is_global = function()799//@{800{801 return this.extAttrs.some(function(attribute) {802 return attribute.name === "Global" ||803 attribute.name === "PrimaryGlobal";804 });805};806//@}807IdlInterface.prototype.has_to_json_regular_operation = function() {808 return this.members.some(function(m) {809 return m.is_to_json_regular_operation();810 });811};812IdlInterface.prototype.has_default_to_json_regular_operation = function() {813 return this.members.some(function(m) {814 return m.is_to_json_regular_operation() && m.has_extended_attribute("Default");815 });816};817IdlInterface.prototype.get_inheritance_stack = function() {818 /**819 * See https://heycam.github.io/webidl/#create-an-inheritance-stack820 *821 * Returns an array of IdlInterface objects which contains itself822 * and all of its inherited interfaces.823 *824 * So given:825 *826 * A : B {};827 * B : C {};828 * C {};829 *830 * then A.get_inheritance_stack() should return [A, B, C],831 * and B.get_inheritance_stack() should return [B, C].832 *833 * Note: as dictionary inheritance is expressed identically by the AST,834 * this works just as well for getting a stack of inherited dictionaries. 835 */836 var stack = [this];837 var idl_interface = this;838 while (idl_interface.base) {839 var base = this.array.members[idl_interface.base];840 if (!base) {841 throw new Error(idl_interface.type + " " + idl_interface.base + " not found (inherited by " + idl_interface.name + ")");842 }843 idl_interface = base;844 stack.push(idl_interface);845 }846 return stack;847};848/**849 * Implementation of850 * https://heycam.github.io/webidl/#default-tojson-operation851 * for testing purposes.852 *853 * Collects the IDL types of the attributes that meet the criteria854 * for inclusion in the default toJSON operation for easy855 * comparison with actual value856 */857IdlInterface.prototype.default_to_json_operation = function(callback) {858 var map = new Map(), isDefault = false;859 this.traverse_inherited_and_consequential_interfaces(function(I) {860 if (I.has_default_to_json_regular_operation()) {861 isDefault = true;862 I.members.forEach(function(m) {863 if (!m.static && m.type == "attribute" && I.array.is_json_type(m.idlType)) {864 map.set(m.name, m.idlType);865 }866 });867 } else if (I.has_to_json_regular_operation()) {868 isDefault = false;869 }870 });871 return isDefault ? map : null;872};873/**874 * Traverses inherited interfaces from the top down875 * and imeplemented interfaces inside out.876 * Invokes |callback| on each interface.877 *878 * This is an abstract implementation of the traversal879 * algorithm specified in:880 * https://heycam.github.io/webidl/#collect-attribute-values881 * Given the following inheritance tree:882 *883 * F884 * |885 * C E - I886 * | |887 * B - D888 * |889 * G - A - H - J890 *891 * Invoking traverse_inherited_and_consequential_interfaces() on A892 * would traverse the tree in the following order:893 * C -> B -> F -> E -> I -> D -> A -> G -> H -> J894 */895IdlInterface.prototype.traverse_inherited_and_consequential_interfaces = function(callback) {896 if (typeof callback != "function") {897 throw new TypeError();898 }899 var stack = this.get_inheritance_stack();900 _traverse_inherited_and_consequential_interfaces(stack, callback);901};902function _traverse_inherited_and_consequential_interfaces(stack, callback) {903 var I = stack.pop();904 callback(I);905 var mixins = I.array["implements"][I.name];906 if (mixins) {907 mixins.forEach(id => {908 var mixin = I.array.members[id];909 if (!mixin) {910 throw new Error("Interface " + id + " not found (implemented by " + I.name + ")");911 }912 var interfaces = mixin.get_inheritance_stack();913 _traverse_inherited_and_consequential_interfaces(interfaces, callback);914 });915 }916 if (stack.length > 0) {917 _traverse_inherited_and_consequential_interfaces(stack, callback);918 }919}920IdlInterface.prototype.test = function()921//@{922{923 if (this.has_extended_attribute("NoInterfaceObject"))924 {925 // No tests to do without an instance. TODO: We should still be able926 // to run tests on the prototype object, if we obtain one through some927 // other means.928 return;929 }930 if (!this.exposed) {931 test(function() {932 assert_false(this.name in self);933 }.bind(this), this.name + " interface: existence and properties of interface object");934 return;935 }936 if (!this.untested)937 {938 // First test things to do with the exception/interface object and939 // exception/interface prototype object.940 this.test_self();941 }942 // Then test things to do with its members (constants, fields, attributes,943 // operations, . . .). These are run even if .untested is true, because944 // members might themselves be marked as .untested. This might happen to945 // interfaces if the interface itself is untested but a partial interface946 // that extends it is tested -- then the interface itself and its initial947 // members will be marked as untested, but the members added by the partial948 // interface are still tested.949 this.test_members();950};951//@}952IdlInterface.prototype.test_self = function()953//@{954{955 test(function()956 {957 // This function tests WebIDL as of 2015-01-13.958 // "For every interface that is exposed in a given ECMAScript global959 // environment and:960 // * is a callback interface that has constants declared on it, or961 // * is a non-callback interface that is not declared with the962 // [NoInterfaceObject] extended attribute,963 // a corresponding property MUST exist on the ECMAScript global object.964 // The name of the property is the identifier of the interface, and its965 // value is an object called the interface object.966 // The property has the attributes { [[Writable]]: true,967 // [[Enumerable]]: false, [[Configurable]]: true }."968 if (this.is_callback() && !this.has_constants()) {969 return;970 }971 // TODO: Should we test here that the property is actually writable972 // etc., or trust getOwnPropertyDescriptor?973 assert_own_property(self, this.name,974 "self does not have own property " + format_value(this.name));975 var desc = Object.getOwnPropertyDescriptor(self, this.name);976 assert_false("get" in desc, "self's property " + format_value(this.name) + " should not have a getter");977 assert_false("set" in desc, "self's property " + format_value(this.name) + " should not have a setter");978 assert_true(desc.writable, "self's property " + format_value(this.name) + " should be writable");979 assert_false(desc.enumerable, "self's property " + format_value(this.name) + " should not be enumerable");980 assert_true(desc.configurable, "self's property " + format_value(this.name) + " should be configurable");981 if (this.is_callback()) {982 // "The internal [[Prototype]] property of an interface object for983 // a callback interface must be the Function.prototype object."984 assert_equals(Object.getPrototypeOf(self[this.name]), Function.prototype,985 "prototype of self's property " + format_value(this.name) + " is not Object.prototype");986 return;987 }988 // "The interface object for a given non-callback interface is a989 // function object."990 // "If an object is defined to be a function object, then it has991 // characteristics as follows:"992 // Its [[Prototype]] internal property is otherwise specified (see993 // below).994 // "* Its [[Get]] internal property is set as described in ECMA-262995 // section 9.1.8."996 // Not much to test for this.997 // "* Its [[Construct]] internal property is set as described in998 // ECMA-262 section 19.2.2.3."999 // Tested below if no constructor is defined. TODO: test constructors1000 // if defined.1001 // "* Its @@hasInstance property is set as described in ECMA-2621002 // section 19.2.3.8, unless otherwise specified."1003 // TODO1004 // ES6 (rev 30) 19.1.3.6:1005 // "Else, if O has a [[Call]] internal method, then let builtinTag be1006 // "Function"."1007 assert_class_string(self[this.name], "Function", "class string of " + this.name);1008 // "The [[Prototype]] internal property of an interface object for a1009 // non-callback interface is determined as follows:"1010 var prototype = Object.getPrototypeOf(self[this.name]);1011 if (this.base) {1012 // "* If the interface inherits from some other interface, the1013 // value of [[Prototype]] is the interface object for that other1014 // interface."1015 var has_interface_object =1016 !this.array1017 .members[this.base]1018 .has_extended_attribute("NoInterfaceObject");1019 if (has_interface_object) {1020 assert_own_property(self, this.base,1021 'should inherit from ' + this.base +1022 ', but self has no such property');1023 assert_equals(prototype, self[this.base],1024 'prototype of ' + this.name + ' is not ' +1025 this.base);1026 }1027 } else {1028 // "If the interface doesn't inherit from any other interface, the1029 // value of [[Prototype]] is %FunctionPrototype% ([ECMA-262],1030 // section 6.1.7.4)."1031 assert_equals(prototype, Function.prototype,1032 "prototype of self's property " + format_value(this.name) + " is not Function.prototype");1033 }1034 if (!this.has_extended_attribute("Constructor")) {1035 // "The internal [[Call]] method of the interface object behaves as1036 // follows . . .1037 //1038 // "If I was not declared with a [Constructor] extended attribute,1039 // then throw a TypeError."1040 assert_throws(new TypeError(), function() {1041 self[this.name]();1042 }.bind(this), "interface object didn't throw TypeError when called as a function");1043 assert_throws(new TypeError(), function() {1044 new self[this.name]();1045 }.bind(this), "interface object didn't throw TypeError when called as a constructor");1046 }1047 }.bind(this), this.name + " interface: existence and properties of interface object");1048 if (!this.is_callback()) {1049 test(function() {1050 // This function tests WebIDL as of 2014-10-25.1051 // https://heycam.github.io/webidl/#es-interface-call1052 assert_own_property(self, this.name,1053 "self does not have own property " + format_value(this.name));1054 // "Interface objects for non-callback interfaces MUST have a1055 // property named “length” with attributes { [[Writable]]: false,1056 // [[Enumerable]]: false, [[Configurable]]: true } whose value is1057 // a Number."1058 assert_own_property(self[this.name], "length");1059 var desc = Object.getOwnPropertyDescriptor(self[this.name], "length");1060 assert_false("get" in desc, this.name + ".length should not have a getter");1061 assert_false("set" in desc, this.name + ".length should not have a setter");1062 assert_false(desc.writable, this.name + ".length should not be writable");1063 assert_false(desc.enumerable, this.name + ".length should not be enumerable");1064 assert_true(desc.configurable, this.name + ".length should be configurable");1065 var constructors = this.extAttrs1066 .filter(function(attr) { return attr.name == "Constructor"; });1067 var expected_length = minOverloadLength(constructors);1068 assert_equals(self[this.name].length, expected_length, "wrong value for " + this.name + ".length");1069 }.bind(this), this.name + " interface object length");1070 }1071 if (!this.is_callback() || this.has_constants()) {1072 test(function() {1073 // This function tests WebIDL as of 2015-11-17.1074 // https://heycam.github.io/webidl/#interface-object1075 assert_own_property(self, this.name,1076 "self does not have own property " + format_value(this.name));1077 // "All interface objects must have a property named “name” with1078 // attributes { [[Writable]]: false, [[Enumerable]]: false,1079 // [[Configurable]]: true } whose value is the identifier of the1080 // corresponding interface."1081 assert_own_property(self[this.name], "name");1082 var desc = Object.getOwnPropertyDescriptor(self[this.name], "name");1083 assert_false("get" in desc, this.name + ".name should not have a getter");1084 assert_false("set" in desc, this.name + ".name should not have a setter");1085 assert_false(desc.writable, this.name + ".name should not be writable");1086 assert_false(desc.enumerable, this.name + ".name should not be enumerable");1087 assert_true(desc.configurable, this.name + ".name should be configurable");1088 assert_equals(self[this.name].name, this.name, "wrong value for " + this.name + ".name");1089 }.bind(this), this.name + " interface object name");1090 }1091 if (this.has_extended_attribute("LegacyWindowAlias")) {1092 test(function()1093 {1094 var aliasAttrs = this.extAttrs.filter(function(o) { return o.name === "LegacyWindowAlias"; });1095 if (aliasAttrs.length > 1) {1096 throw "Invalid IDL: multiple LegacyWindowAlias extended attributes on " + this.name;1097 }1098 if (this.is_callback()) {1099 throw "Invalid IDL: LegacyWindowAlias extended attribute on non-interface " + this.name;1100 }1101 if (this.exposureSet.indexOf("Window") === -1) {1102 throw "Invalid IDL: LegacyWindowAlias extended attribute on " + this.name + " which is not exposed in Window";1103 }1104 // TODO: when testing of [NoInterfaceObject] interfaces is supported,1105 // check that it's not specified together with LegacyWindowAlias.1106 // TODO: maybe check that [LegacyWindowAlias] is not specified on a partial interface.1107 var rhs = aliasAttrs[0].rhs;1108 if (!rhs) {1109 throw "Invalid IDL: LegacyWindowAlias extended attribute on " + this.name + " without identifier";1110 }1111 var aliases;1112 if (rhs.type === "identifier-list") {1113 aliases = rhs.value;1114 } else { // rhs.type === identifier1115 aliases = [ rhs.value ];1116 }1117 // OK now actually check the aliases...1118 var alias;1119 if (exposed_in(exposure_set(this, this.exposureSet)) && 'document' in self) {1120 for (alias of aliases) {1121 assert_true(alias in self, alias + " should exist");1122 assert_equals(self[alias], self[this.name], "self." + alias + " should be the same value as self." + this.name);1123 var desc = Object.getOwnPropertyDescriptor(self, alias);1124 assert_equals(desc.value, self[this.name], "wrong value in " + alias + " property descriptor");1125 assert_true(desc.writable, alias + " should be writable");1126 assert_false(desc.enumerable, alias + " should not be enumerable");1127 assert_true(desc.configurable, alias + " should be configurable");1128 assert_false('get' in desc, alias + " should not have a getter");1129 assert_false('set' in desc, alias + " should not have a setter");1130 }1131 } else {1132 for (alias of aliases) {1133 assert_false(alias in self, alias + " should not exist");1134 }1135 }1136 }.bind(this), this.name + " interface: legacy window alias");1137 }1138 // TODO: Test named constructors if I find any interfaces that have them.1139 test(function()1140 {1141 // This function tests WebIDL as of 2015-01-21.1142 // https://heycam.github.io/webidl/#interface-object1143 if (this.is_callback() && !this.has_constants()) {1144 return;1145 }1146 assert_own_property(self, this.name,1147 "self does not have own property " + format_value(this.name));1148 if (this.is_callback()) {1149 assert_false("prototype" in self[this.name],1150 this.name + ' should not have a "prototype" property');1151 return;1152 }1153 // "An interface object for a non-callback interface must have a1154 // property named “prototype” with attributes { [[Writable]]: false,1155 // [[Enumerable]]: false, [[Configurable]]: false } whose value is an1156 // object called the interface prototype object. This object has1157 // properties that correspond to the regular attributes and regular1158 // operations defined on the interface, and is described in more detail1159 // in section 4.5.4 below."1160 assert_own_property(self[this.name], "prototype",1161 'interface "' + this.name + '" does not have own property "prototype"');1162 var desc = Object.getOwnPropertyDescriptor(self[this.name], "prototype");1163 assert_false("get" in desc, this.name + ".prototype should not have a getter");1164 assert_false("set" in desc, this.name + ".prototype should not have a setter");1165 assert_false(desc.writable, this.name + ".prototype should not be writable");1166 assert_false(desc.enumerable, this.name + ".prototype should not be enumerable");1167 assert_false(desc.configurable, this.name + ".prototype should not be configurable");1168 // Next, test that the [[Prototype]] of the interface prototype object1169 // is correct. (This is made somewhat difficult by the existence of1170 // [NoInterfaceObject].)1171 // TODO: Aryeh thinks there's at least other place in this file where1172 // we try to figure out if an interface prototype object is1173 // correct. Consolidate that code.1174 // "The interface prototype object for a given interface A must have an1175 // internal [[Prototype]] property whose value is returned from the1176 // following steps:1177 // "If A is declared with the [Global] or [PrimaryGlobal] extended1178 // attribute, and A supports named properties, then return the named1179 // properties object for A, as defined in §3.6.4 Named properties1180 // object.1181 // "Otherwise, if A is declared to inherit from another interface, then1182 // return the interface prototype object for the inherited interface.1183 // "Otherwise, if A is declared with the [LegacyArrayClass] extended1184 // attribute, then return %ArrayPrototype%.1185 // "Otherwise, return %ObjectPrototype%.1186 if (this.name === "Window") {1187 assert_class_string(Object.getPrototypeOf(self[this.name].prototype),1188 'WindowProperties',1189 'Class name for prototype of Window' +1190 '.prototype is not "WindowProperties"');1191 } else {1192 var inherit_interface, inherit_interface_has_interface_object;1193 if (this.base) {1194 inherit_interface = this.base;1195 inherit_interface_has_interface_object =1196 !this.array1197 .members[inherit_interface]1198 .has_extended_attribute("NoInterfaceObject");1199 } else if (this.has_extended_attribute('LegacyArrayClass')) {1200 inherit_interface = 'Array';1201 inherit_interface_has_interface_object = true;1202 } else {1203 inherit_interface = 'Object';1204 inherit_interface_has_interface_object = true;1205 }1206 if (inherit_interface_has_interface_object) {1207 assert_own_property(self, inherit_interface,1208 'should inherit from ' + inherit_interface + ', but self has no such property');1209 assert_own_property(self[inherit_interface], 'prototype',1210 'should inherit from ' + inherit_interface + ', but that object has no "prototype" property');1211 assert_equals(Object.getPrototypeOf(self[this.name].prototype),1212 self[inherit_interface].prototype,1213 'prototype of ' + this.name + '.prototype is not ' + inherit_interface + '.prototype');1214 } else {1215 // We can't test that we get the correct object, because this is the1216 // only way to get our hands on it. We only test that its class1217 // string, at least, is correct.1218 assert_class_string(Object.getPrototypeOf(self[this.name].prototype),1219 inherit_interface + 'Prototype',1220 'Class name for prototype of ' + this.name +1221 '.prototype is not "' + inherit_interface + 'Prototype"');1222 }1223 }1224 // "The class string of an interface prototype object is the1225 // concatenation of the interface’s identifier and the string1226 // “Prototype”."1227 // Skip these tests for now due to a specification issue about1228 // prototype name.1229 // https://www.w3.org/Bugs/Public/show_bug.cgi?id=282441230 // assert_class_string(self[this.name].prototype, this.name + "Prototype",1231 // "class string of " + this.name + ".prototype");1232 // String() should end up calling {}.toString if nothing defines a1233 // stringifier.1234 if (!this.has_stringifier()) {1235 // assert_equals(String(self[this.name].prototype), "[object " + this.name + "Prototype]",1236 // "String(" + this.name + ".prototype)");1237 }1238 }.bind(this), this.name + " interface: existence and properties of interface prototype object");1239 if (this.is_global() && typeof Object.setPrototypeOf === "function") {1240 // These functions test WebIDL as of 2017-06-06.1241 // https://heycam.github.io/webidl/#platform-object-setprototypeof1242 test(function() {1243 var originalValue = Object.getPrototypeOf(self[this.name].prototype);1244 var newValue = Object.create(null);1245 assert_throws(new TypeError(), function() {1246 Object.setPrototypeOf(self[this.name].prototype, newValue);1247 });1248 assert_equals(1249 Object.getPrototypeOf(self[this.name].prototype),1250 originalValue,1251 "original value not modified"1252 );1253 }.bind(this), this.name + " interface: internal [[SetPrototypeOf]] method " +1254 "of global platform object - setting to a new value via Object.setPrototypeOf " +1255 "should throw a TypeError");1256 test(function() {1257 var originalValue = Object.getPrototypeOf(self[this.name].prototype);1258 var newValue = Object.create(null);1259 assert_throws(new TypeError(), function() {1260 self[this.name].prototype.__proto__ = newValue;1261 });1262 assert_equals(1263 Object.getPrototypeOf(self[this.name].prototype),1264 originalValue,1265 "original value not modified"1266 );1267 }.bind(this), this.name + " interface: internal [[SetPrototypeOf]] method " +1268 "of global platform object - setting to a new value via __proto__ " +1269 "should throw a TypeError");1270 test(function() {1271 var originalValue = Object.getPrototypeOf(self[this.name].prototype);1272 var newValue = Object.create(null);1273 assert_false(Reflect.setPrototypeOf(self[this.name].prototype.__proto__, newValue));1274 assert_equals(1275 Object.getPrototypeOf(self[this.name].prototype),1276 originalValue,1277 "original value not modified"1278 );1279 }.bind(this), this.name + " interface: internal [[SetPrototypeOf]] method " +1280 "of global platform object - setting to a new value via Reflect.setPrototypeOf " +1281 "should return false");1282 test(function() {1283 var originalValue = Object.getPrototypeOf(self[this.name].prototype);1284 Object.setPrototypeOf(self[this.name].prototype, originalValue);1285 }.bind(this), this.name + " interface: internal [[SetPrototypeOf]] method " +1286 "of global platform object - setting to its original value via Object.setPrototypeOf " +1287 "should not throw");1288 test(function() {1289 var originalValue = Object.getPrototypeOf(self[this.name].prototype);1290 self[this.name].prototype.__proto__ = originalValue;1291 }.bind(this), this.name + " interface: internal [[SetPrototypeOf]] method " +1292 "of global platform object - setting to its original value via __proto__ " +1293 "should not throw");1294 test(function() {1295 var originalValue = Object.getPrototypeOf(self[this.name].prototype);1296 assert_true(Reflect.setPrototypeOf(self[this.name].prototype, originalValue));1297 }.bind(this), this.name + " interface: internal [[SetPrototypeOf]] method " +1298 "of global platform object - setting to its original value via Reflect.setPrototypeOf " +1299 "should return true");1300 }1301 test(function()1302 {1303 if (this.is_callback() && !this.has_constants()) {1304 return;1305 }1306 assert_own_property(self, this.name,1307 "self does not have own property " + format_value(this.name));1308 if (this.is_callback()) {1309 assert_false("prototype" in self[this.name],1310 this.name + ' should not have a "prototype" property');1311 return;1312 }1313 assert_own_property(self[this.name], "prototype",1314 'interface "' + this.name + '" does not have own property "prototype"');1315 // "If the [NoInterfaceObject] extended attribute was not specified on1316 // the interface, then the interface prototype object must also have a1317 // property named “constructor” with attributes { [[Writable]]: true,1318 // [[Enumerable]]: false, [[Configurable]]: true } whose value is a1319 // reference to the interface object for the interface."1320 assert_own_property(self[this.name].prototype, "constructor",1321 this.name + '.prototype does not have own property "constructor"');1322 var desc = Object.getOwnPropertyDescriptor(self[this.name].prototype, "constructor");1323 assert_false("get" in desc, this.name + ".prototype.constructor should not have a getter");1324 assert_false("set" in desc, this.name + ".prototype.constructor should not have a setter");1325 assert_true(desc.writable, this.name + ".prototype.constructor should be writable");1326 assert_false(desc.enumerable, this.name + ".prototype.constructor should not be enumerable");1327 assert_true(desc.configurable, this.name + ".prototype.constructor should be configurable");1328 assert_equals(self[this.name].prototype.constructor, self[this.name],1329 this.name + '.prototype.constructor is not the same object as ' + this.name);1330 }.bind(this), this.name + ' interface: existence and properties of interface prototype object\'s "constructor" property');1331};1332//@}1333IdlInterface.prototype.test_member_const = function(member)1334//@{1335{1336 if (!this.has_constants()) {1337 throw "Internal error: test_member_const called without any constants";1338 }1339 test(function()1340 {1341 assert_own_property(self, this.name,1342 "self does not have own property " + format_value(this.name));1343 // "For each constant defined on an interface A, there must be1344 // a corresponding property on the interface object, if it1345 // exists."1346 assert_own_property(self[this.name], member.name);1347 // "The value of the property is that which is obtained by1348 // converting the constant’s IDL value to an ECMAScript1349 // value."1350 assert_equals(self[this.name][member.name], constValue(member.value),1351 "property has wrong value");1352 // "The property has attributes { [[Writable]]: false,1353 // [[Enumerable]]: true, [[Configurable]]: false }."1354 var desc = Object.getOwnPropertyDescriptor(self[this.name], member.name);1355 assert_false("get" in desc, "property should not have a getter");1356 assert_false("set" in desc, "property should not have a setter");1357 assert_false(desc.writable, "property should not be writable");1358 assert_true(desc.enumerable, "property should be enumerable");1359 assert_false(desc.configurable, "property should not be configurable");1360 }.bind(this), this.name + " interface: constant " + member.name + " on interface object");1361 // "In addition, a property with the same characteristics must1362 // exist on the interface prototype object."1363 test(function()1364 {1365 assert_own_property(self, this.name,1366 "self does not have own property " + format_value(this.name));1367 if (this.is_callback()) {1368 assert_false("prototype" in self[this.name],1369 this.name + ' should not have a "prototype" property');1370 return;1371 }1372 assert_own_property(self[this.name], "prototype",1373 'interface "' + this.name + '" does not have own property "prototype"');1374 assert_own_property(self[this.name].prototype, member.name);1375 assert_equals(self[this.name].prototype[member.name], constValue(member.value),1376 "property has wrong value");1377 var desc = Object.getOwnPropertyDescriptor(self[this.name], member.name);1378 assert_false("get" in desc, "property should not have a getter");1379 assert_false("set" in desc, "property should not have a setter");1380 assert_false(desc.writable, "property should not be writable");1381 assert_true(desc.enumerable, "property should be enumerable");1382 assert_false(desc.configurable, "property should not be configurable");1383 }.bind(this), this.name + " interface: constant " + member.name + " on interface prototype object");1384};1385//@}1386IdlInterface.prototype.test_member_attribute = function(member)1387//@{1388 {1389 var a_test = async_test(this.name + " interface: attribute " + member.name);1390 a_test.step(function()1391 {1392 if (this.is_callback() && !this.has_constants()) {1393 a_test.done()1394 return;1395 }1396 assert_own_property(self, this.name,1397 "self does not have own property " + format_value(this.name));1398 assert_own_property(self[this.name], "prototype",1399 'interface "' + this.name + '" does not have own property "prototype"');1400 if (member["static"]) {1401 assert_own_property(self[this.name], member.name,1402 "The interface object must have a property " +1403 format_value(member.name));1404 a_test.done();1405 } else if (this.is_global()) {1406 assert_own_property(self, member.name,1407 "The global object must have a property " +1408 format_value(member.name));1409 assert_false(member.name in self[this.name].prototype,1410 "The prototype object should not have a property " +1411 format_value(member.name));1412 var getter = Object.getOwnPropertyDescriptor(self, member.name).get;1413 assert_equals(typeof(getter), "function",1414 format_value(member.name) + " must have a getter");1415 // Try/catch around the get here, since it can legitimately throw.1416 // If it does, we obviously can't check for equality with direct1417 // invocation of the getter.1418 var gotValue;1419 var propVal;1420 try {1421 propVal = self[member.name];1422 gotValue = true;1423 } catch (e) {1424 gotValue = false;1425 }1426 if (gotValue) {1427 assert_equals(propVal, getter.call(undefined),1428 "Gets on a global should not require an explicit this");1429 }1430 // do_interface_attribute_asserts must be the last thing we do,1431 // since it will call done() on a_test.1432 this.do_interface_attribute_asserts(self, member, a_test);1433 } else {1434 assert_true(member.name in self[this.name].prototype,1435 "The prototype object must have a property " +1436 format_value(member.name));1437 if (!member.has_extended_attribute("LenientThis")) {1438 if (member.idlType.generic !== "Promise") {1439 assert_throws(new TypeError(), function() {1440 self[this.name].prototype[member.name];1441 }.bind(this), "getting property on prototype object must throw TypeError");1442 // do_interface_attribute_asserts must be the last thing we1443 // do, since it will call done() on a_test.1444 this.do_interface_attribute_asserts(self[this.name].prototype, member, a_test);1445 } else {1446 promise_rejects(a_test, new TypeError(),1447 self[this.name].prototype[member.name])1448 .then(function() {1449 // do_interface_attribute_asserts must be the last1450 // thing we do, since it will call done() on a_test.1451 this.do_interface_attribute_asserts(self[this.name].prototype,1452 member, a_test);1453 }.bind(this));1454 }1455 } else {1456 assert_equals(self[this.name].prototype[member.name], undefined,1457 "getting property on prototype object must return undefined");1458 // do_interface_attribute_asserts must be the last thing we do,1459 // since it will call done() on a_test.1460 this.do_interface_attribute_asserts(self[this.name].prototype, member, a_test);1461 }1462 }1463 }.bind(this));1464};1465//@}1466IdlInterface.prototype.test_member_operation = function(member)1467//@{1468{1469 var a_test = async_test(this.name + " interface: operation " + member.name +1470 "(" + member.arguments.map(1471 function(m) {return m.idlType.idlType; } )1472 +")");1473 a_test.step(function()1474 {1475 // This function tests WebIDL as of 2015-12-29.1476 // https://heycam.github.io/webidl/#es-operations1477 if (this.is_callback() && !this.has_constants()) {1478 a_test.done();1479 return;1480 }1481 assert_own_property(self, this.name,1482 "self does not have own property " + format_value(this.name));1483 if (this.is_callback()) {1484 assert_false("prototype" in self[this.name],1485 this.name + ' should not have a "prototype" property');1486 a_test.done();1487 return;1488 }1489 assert_own_property(self[this.name], "prototype",1490 'interface "' + this.name + '" does not have own property "prototype"');1491 // "For each unique identifier of an exposed operation defined on the1492 // interface, there must exist a corresponding property, unless the1493 // effective overload set for that identifier and operation and with an1494 // argument count of 0 has no entries."1495 // TODO: Consider [Exposed].1496 // "The location of the property is determined as follows:"1497 var memberHolderObject;1498 // "* If the operation is static, then the property exists on the1499 // interface object."1500 if (member["static"]) {1501 assert_own_property(self[this.name], member.name,1502 "interface object missing static operation");1503 memberHolderObject = self[this.name];1504 // "* Otherwise, [...] if the interface was declared with the [Global]1505 // or [PrimaryGlobal] extended attribute, then the property exists1506 // on every object that implements the interface."1507 } else if (this.is_global()) {1508 assert_own_property(self, member.name,1509 "global object missing non-static operation");1510 memberHolderObject = self;1511 // "* Otherwise, the property exists solely on the interface’s1512 // interface prototype object."1513 } else {1514 assert_own_property(self[this.name].prototype, member.name,1515 "interface prototype object missing non-static operation");1516 memberHolderObject = self[this.name].prototype;1517 }1518 this.do_member_operation_asserts(memberHolderObject, member, a_test);1519 }.bind(this));1520};1521//@}1522IdlInterface.prototype.do_member_operation_asserts = function(memberHolderObject, member, a_test)1523//@{1524{1525 var done = a_test.done.bind(a_test);1526 var operationUnforgeable = member.isUnforgeable;1527 var desc = Object.getOwnPropertyDescriptor(memberHolderObject, member.name);1528 // "The property has attributes { [[Writable]]: B,1529 // [[Enumerable]]: true, [[Configurable]]: B }, where B is false if the1530 // operation is unforgeable on the interface, and true otherwise".1531 assert_false("get" in desc, "property should not have a getter");1532 assert_false("set" in desc, "property should not have a setter");1533 assert_equals(desc.writable, !operationUnforgeable,1534 "property should be writable if and only if not unforgeable");1535 assert_true(desc.enumerable, "property should be enumerable");1536 assert_equals(desc.configurable, !operationUnforgeable,1537 "property should be configurable if and only if not unforgeable");1538 // "The value of the property is a Function object whose1539 // behavior is as follows . . ."1540 assert_equals(typeof memberHolderObject[member.name], "function",1541 "property must be a function");1542 // "The value of the Function object’s “length” property is1543 // a Number determined as follows:1544 // ". . .1545 // "Return the length of the shortest argument list of the1546 // entries in S."1547 assert_equals(memberHolderObject[member.name].length,1548 minOverloadLength(this.members.filter(function(m) {1549 return m.type == "operation" && m.name == member.name;1550 })),1551 "property has wrong .length");1552 if (member.is_to_json_regular_operation()) {1553 this.test_to_json_operation(memberHolderObject, member);1554 }1555 // Make some suitable arguments1556 var args = member.arguments.map(function(arg) {1557 return create_suitable_object(arg.idlType);1558 });1559 // "Let O be a value determined as follows:1560 // ". . .1561 // "Otherwise, throw a TypeError."1562 // This should be hit if the operation is not static, there is1563 // no [ImplicitThis] attribute, and the this value is null.1564 //1565 // TODO: We currently ignore the [ImplicitThis] case. Except we manually1566 // check for globals, since otherwise we'll invoke window.close(). And we1567 // have to skip this test for anything that on the proto chain of "self",1568 // since that does in fact have implicit-this behavior.1569 if (!member["static"]) {1570 var cb;1571 if (!this.is_global() &&1572 memberHolderObject[member.name] != self[member.name])1573 {1574 cb = awaitNCallbacks(2, done);1575 throwOrReject(a_test, member, memberHolderObject[member.name], null, args,1576 "calling operation with this = null didn't throw TypeError", cb);1577 } else {1578 cb = awaitNCallbacks(1, done);1579 }1580 // ". . . If O is not null and is also not a platform object1581 // that implements interface I, throw a TypeError."1582 //1583 // TODO: Test a platform object that implements some other1584 // interface. (Have to be sure to get inheritance right.)1585 throwOrReject(a_test, member, memberHolderObject[member.name], {}, args,1586 "calling operation with this = {} didn't throw TypeError", cb);1587 } else {1588 done();1589 }1590}1591//@}1592IdlInterface.prototype.add_iterable_members = function(member)1593//@{1594{1595 this.members.push(new IdlInterfaceMember(1596 { type: "operation", name: "entries", idlType: "iterator", arguments: []}));1597 this.members.push(new IdlInterfaceMember(1598 { type: "operation", name: "keys", idlType: "iterator", arguments: []}));1599 this.members.push(new IdlInterfaceMember(1600 { type: "operation", name: "values", idlType: "iterator", arguments: []}));1601 this.members.push(new IdlInterfaceMember(1602 { type: "operation", name: "forEach", idlType: "void",1603 arguments:1604 [{ name: "callback", idlType: {idlType: "function"}},1605 { name: "thisValue", idlType: {idlType: "any"}, optional: true}]}));1606};1607IdlInterface.prototype.test_to_json_operation = function(memberHolderObject, member) {1608 if (member.has_extended_attribute("Default")) {1609 var map = this.default_to_json_operation();1610 test(function() {1611 var json = memberHolderObject.toJSON();1612 map.forEach(function(type, k) {1613 assert_true(k in json, "property " + k + " should be present in the output of " + this.name + ".prototype.toJSON()");1614 var descriptor = Object.getOwnPropertyDescriptor(json, k);1615 assert_true(descriptor.writable, "property " + k + " should be writable");1616 assert_true(descriptor.configurable, "property " + k + " should be configurable");1617 assert_true(descriptor.enumerable, "property " + k + " should be enumerable");1618 this.array.assert_type_is(json[k], type);1619 delete json[k];1620 }, this);1621 for (var k in json) {1622 assert_unreached("property " + k + " should not be present in the output of " + this.name + ".prototype.toJSON()");1623 }1624 }.bind(this), "Test default toJSON operation of " + this.name);1625 } else {1626 test(function() {1627 assert_true(this.array.is_json_type(member.idlType), JSON.stringify(member.idlType) + " is not an appropriate return value for the toJSON operation of " + this.name);1628 this.array.assert_type_is(memberHolderObject.toJSON(), member.idlType);1629 }.bind(this), "Test toJSON operation of " + this.name);1630 }1631};1632//@}1633IdlInterface.prototype.test_member_iterable = function(member)1634//@{1635{1636 var interfaceName = this.name;1637 var isPairIterator = member.idlType instanceof Array;1638 test(function()1639 {1640 var descriptor = Object.getOwnPropertyDescriptor(self[interfaceName].prototype, Symbol.iterator);1641 assert_true(descriptor.writable, "property should be writable");1642 assert_true(descriptor.configurable, "property should be configurable");1643 assert_false(descriptor.enumerable, "property should not be enumerable");1644 assert_equals(self[interfaceName].prototype[Symbol.iterator].name, isPairIterator ? "entries" : "values", "@@iterator function does not have the right name");1645 }, "Testing Symbol.iterator property of iterable interface " + interfaceName);1646 if (isPairIterator) {1647 test(function() {1648 assert_equals(self[interfaceName].prototype[Symbol.iterator], self[interfaceName].prototype["entries"], "entries method is not the same as @@iterator");1649 }, "Testing pair iterable interface " + interfaceName);1650 } else {1651 test(function() {1652 ["entries", "keys", "values", "forEach", Symbol.Iterator].forEach(function(property) {1653 assert_equals(self[interfaceName].prototype[property], Array.prototype[property], property + " function is not the same as Array one");1654 });1655 }, "Testing value iterable interface " + interfaceName);1656 }1657};1658//@}1659IdlInterface.prototype.test_member_stringifier = function(member)1660//@{1661{1662 test(function()1663 {1664 if (this.is_callback() && !this.has_constants()) {1665 return;1666 }1667 assert_own_property(self, this.name,1668 "self does not have own property " + format_value(this.name));1669 if (this.is_callback()) {1670 assert_false("prototype" in self[this.name],1671 this.name + ' should not have a "prototype" property');1672 return;1673 }1674 assert_own_property(self[this.name], "prototype",1675 'interface "' + this.name + '" does not have own property "prototype"');1676 // ". . . the property exists on the interface prototype object."1677 var interfacePrototypeObject = self[this.name].prototype;1678 assert_own_property(self[this.name].prototype, "toString",1679 "interface prototype object missing non-static operation");1680 var stringifierUnforgeable = member.isUnforgeable;1681 var desc = Object.getOwnPropertyDescriptor(interfacePrototypeObject, "toString");1682 // "The property has attributes { [[Writable]]: B,1683 // [[Enumerable]]: true, [[Configurable]]: B }, where B is false if the1684 // stringifier is unforgeable on the interface, and true otherwise."1685 assert_false("get" in desc, "property should not have a getter");1686 assert_false("set" in desc, "property should not have a setter");1687 assert_equals(desc.writable, !stringifierUnforgeable,1688 "property should be writable if and only if not unforgeable");1689 assert_true(desc.enumerable, "property should be enumerable");1690 assert_equals(desc.configurable, !stringifierUnforgeable,1691 "property should be configurable if and only if not unforgeable");1692 // "The value of the property is a Function object, which behaves as1693 // follows . . ."1694 assert_equals(typeof interfacePrototypeObject.toString, "function",1695 "property must be a function");1696 // "The value of the Function object’s “length” property is the Number1697 // value 0."1698 assert_equals(interfacePrototypeObject.toString.length, 0,1699 "property has wrong .length");1700 // "Let O be the result of calling ToObject on the this value."1701 assert_throws(new TypeError(), function() {1702 self[this.name].prototype.toString.apply(null, []);1703 }, "calling stringifier with this = null didn't throw TypeError");1704 // "If O is not an object that implements the interface on which the1705 // stringifier was declared, then throw a TypeError."1706 //1707 // TODO: Test a platform object that implements some other1708 // interface. (Have to be sure to get inheritance right.)1709 assert_throws(new TypeError(), function() {1710 self[this.name].prototype.toString.apply({}, []);1711 }, "calling stringifier with this = {} didn't throw TypeError");1712 }.bind(this), this.name + " interface: stringifier");1713};1714//@}1715IdlInterface.prototype.test_members = function()1716//@{1717{1718 for (var i = 0; i < this.members.length; i++)1719 {1720 var member = this.members[i];1721 switch (member.type) {1722 case "iterable":1723 this.add_iterable_members(member);1724 break;1725 // TODO: add setlike and maplike handling.1726 default:1727 break;1728 }1729 }1730 for (var i = 0; i < this.members.length; i++)1731 {1732 var member = this.members[i];1733 if (member.untested) {1734 continue;1735 }1736 if (!exposed_in(exposure_set(member, this.exposureSet))) {1737 test(function() {1738 // It's not exposed, so we shouldn't find it anywhere.1739 assert_false(member.name in self[this.name],1740 "The interface object must not have a property " +1741 format_value(member.name));1742 assert_false(member.name in self[this.name].prototype,1743 "The prototype object must not have a property " +1744 format_value(member.name));1745 }.bind(this), this.name + " interface: member " + member.name);1746 continue;1747 }1748 switch (member.type) {1749 case "const":1750 this.test_member_const(member);1751 break;1752 case "attribute":1753 // For unforgeable attributes, we do the checks in1754 // test_interface_of instead.1755 if (!member.isUnforgeable)1756 {1757 this.test_member_attribute(member);1758 }1759 if (member.stringifier) {1760 this.test_member_stringifier(member);1761 }1762 break;1763 case "operation":1764 // TODO: Need to correctly handle multiple operations with the same1765 // identifier.1766 // For unforgeable operations, we do the checks in1767 // test_interface_of instead.1768 if (member.name) {1769 if (!member.isUnforgeable)1770 {1771 this.test_member_operation(member);1772 }1773 } else if (member.stringifier) {1774 this.test_member_stringifier(member);1775 }1776 break;1777 case "iterable":1778 this.test_member_iterable(member);1779 break;1780 default:1781 // TODO: check more member types.1782 break;1783 }1784 }1785};1786//@}1787IdlInterface.prototype.test_object = function(desc)1788//@{1789{1790 var obj, exception = null;1791 try1792 {1793 obj = eval(desc);1794 }1795 catch(e)1796 {1797 exception = e;1798 }1799 var expected_typeof =1800 this.members.some(function(member) { return member.legacycaller; })1801 ? "function"1802 : "object";1803 this.test_primary_interface_of(desc, obj, exception, expected_typeof);1804 var current_interface = this;1805 while (current_interface)1806 {1807 if (!(current_interface.name in this.array.members))1808 {1809 throw "Interface " + current_interface.name + " not found (inherited by " + this.name + ")";1810 }1811 if (current_interface.prevent_multiple_testing && current_interface.already_tested)1812 {1813 return;1814 }1815 current_interface.test_interface_of(desc, obj, exception, expected_typeof);1816 current_interface = this.array.members[current_interface.base];1817 }1818};1819//@}1820IdlInterface.prototype.test_primary_interface_of = function(desc, obj, exception, expected_typeof)1821//@{1822{1823 // Only the object itself, not its members, are tested here, so if the1824 // interface is untested, there is nothing to do.1825 if (this.untested)1826 {1827 return;1828 }1829 // We can't easily test that its prototype is correct if there's no1830 // interface object, or the object is from a different global environment1831 // (not instanceof Object). TODO: test in this case that its prototype at1832 // least looks correct, even if we can't test that it's actually correct.1833 if (!this.has_extended_attribute("NoInterfaceObject")1834 && (typeof obj != expected_typeof || obj instanceof Object))1835 {1836 test(function()1837 {1838 assert_equals(exception, null, "Unexpected exception when evaluating object");1839 assert_equals(typeof obj, expected_typeof, "wrong typeof object");1840 assert_own_property(self, this.name,1841 "self does not have own property " + format_value(this.name));1842 assert_own_property(self[this.name], "prototype",1843 'interface "' + this.name + '" does not have own property "prototype"');1844 // "The value of the internal [[Prototype]] property of the1845 // platform object is the interface prototype object of the primary1846 // interface from the platform object’s associated global1847 // environment."1848 assert_equals(Object.getPrototypeOf(obj),1849 self[this.name].prototype,1850 desc + "'s prototype is not " + this.name + ".prototype");1851 }.bind(this), this.name + " must be primary interface of " + desc);1852 }1853 // "The class string of a platform object that implements one or more1854 // interfaces must be the identifier of the primary interface of the1855 // platform object."1856 test(function()1857 {1858 assert_equals(exception, null, "Unexpected exception when evaluating object");1859 assert_equals(typeof obj, expected_typeof, "wrong typeof object");1860 assert_class_string(obj, this.name, "class string of " + desc);1861 if (!this.has_stringifier())1862 {1863 assert_equals(String(obj), "[object " + this.name + "]", "String(" + desc + ")");1864 }1865 }.bind(this), "Stringification of " + desc);1866};1867//@}1868IdlInterface.prototype.test_interface_of = function(desc, obj, exception, expected_typeof)1869//@{1870{1871 // TODO: Indexed and named properties, more checks on interface members1872 this.already_tested = true;1873 for (var i = 0; i < this.members.length; i++)1874 {1875 var member = this.members[i];1876 if (member.untested) {1877 continue;1878 }1879 if (!exposed_in(exposure_set(member, this.exposureSet))) {1880 test(function() {1881 assert_false(member.name in obj);1882 }.bind(this), this.name + "interface: " + desc + 'must not have property "' + member.name + '"');1883 continue;1884 }1885 if (member.type == "attribute" && member.isUnforgeable)1886 {1887 var a_test = async_test(this.name + " interface: " + desc + ' must have own property "' + member.name + '"');1888 a_test.step(function() {1889 assert_equals(exception, null, "Unexpected exception when evaluating object");1890 assert_equals(typeof obj, expected_typeof, "wrong typeof object");1891 // Call do_interface_attribute_asserts last, since it will call a_test.done()1892 this.do_interface_attribute_asserts(obj, member, a_test);1893 }.bind(this));...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1wpt.exposed_in('test.js');2wpt.exposed_in('test.js');3wpt.exposed_in('test.js');4wpt.exposed_in('test.js');5wpt.exposed_in('test.js');6wpt.exposed_in('test.js');7wpt.exposed_in('test.js');8wpt.exposed_in('test.js');9wpt.exposed_in('test.js');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.exposed_in('test', function (err, data) {4 if (err) {5 console.log(err);6 }7 console.log(data);8});9wpt.exposed_in(location, callback);10* `callback` - `function(err, data)`11wpt.exposed_in_all(callback);12* `callback` - `function(err, data)`13wpt.exposed_in_locations(callback);14* `callback` - `function(err, data)`15wpt.get_test(testId, callback);16* `callback` - `function(err, data)`17wpt.get_test_status(testId, callback);18* `callback` - `function(err, data)`19wpt.get_test_results(testId, callback);20* `callback` - `function(err, data)`21wpt.get_test_result(testId, resultId, callback);22* `callback` - `function(err, data)`23wpt.get_test_pagespeed(testId, callback);

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var server = wpt('www.webpagetest.org');3server.exposed_in('test', function (url, callback) {4 callback(url);5});6function test() {7 alert(url);8 });9}

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var webpagetest = new wpt('A.3a8a1e5c7b9d9a0c7a4f4d4c4b4e4a4f');3 if (err) return console.error(err);4 console.log(data);5});6var wpt = require('wpt');7var webpagetest = new wpt('A.3a8a1e5c7b9d9a0c7a4f4d4c4b4e4a4f');8var options = {

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful