How to use create_suitable_object method in wpt

Best JavaScript code snippet using wpt

idlharness.js

Source:idlharness.js Github

copy

Full Screen

...844 })),845 "property has wrong .length");846 847 var args = member.arguments.map(function(arg) {848 return create_suitable_object(arg.idlType);849 });850 851 852 853 854 855 856 857 858 859 860 if (!member["static"]) {861 if (!this.is_global() &&862 memberHolderObject[member.name] != self[member.name])863 {864 assert_throws(new TypeError(), function() {865 memberHolderObject[member.name].apply(null, args);866 }, "calling operation with this = null didn't throw TypeError");867 }868 869 870 871 872 873 assert_throws(new TypeError(), function() {874 memberHolderObject[member.name].apply({}, args);875 }, "calling operation with this = {} didn't throw TypeError");876 }877}878IdlInterface.prototype.test_member_stringifier = function(member)879{880 test(function()881 {882 if (this.is_callback() && !this.has_constants()) {883 return;884 }885 assert_own_property(self, this.name,886 "self does not have own property " + format_value(this.name));887 if (this.is_callback()) {888 assert_false("prototype" in self[this.name],889 this.name + ' should not have a "prototype" property');890 return;891 }892 assert_own_property(self[this.name], "prototype",893 'interface "' + this.name + '" does not have own property "prototype"');894 895 var interfacePrototypeObject = self[this.name].prototype;896 assert_own_property(self[this.name].prototype, "toString",897 "interface prototype object missing non-static operation");898 var stringifierUnforgeable = member.isUnforgeable;899 var desc = Object.getOwnPropertyDescriptor(interfacePrototypeObject, "toString");900 901 902 903 assert_false("get" in desc, "property has getter");904 assert_false("set" in desc, "property has setter");905 assert_equals(desc.writable, !stringifierUnforgeable,906 "property should be writable if and only if not unforgeable");907 assert_true(desc.enumerable, "property is not enumerable");908 assert_equals(desc.configurable, !stringifierUnforgeable,909 "property should be configurable if and only if not unforgeable");910 911 912 assert_equals(typeof interfacePrototypeObject.toString, "function",913 "property must be a function");914 915 916 assert_equals(interfacePrototypeObject.toString.length, 0,917 "property has wrong .length");918 919 assert_throws(new TypeError(), function() {920 self[this.name].prototype.toString.apply(null, []);921 }, "calling stringifier with this = null didn't throw TypeError");922 923 924 925 926 927 assert_throws(new TypeError(), function() {928 self[this.name].prototype.toString.apply({}, []);929 }, "calling stringifier with this = {} didn't throw TypeError");930 }.bind(this), this.name + " interface: stringifier");931};932IdlInterface.prototype.test_members = function()933{934 for (var i = 0; i < this.members.length; i++)935 {936 var member = this.members[i];937 if (member.untested) {938 continue;939 }940 switch (member.type) {941 case "const":942 this.test_member_const(member);943 break;944 case "attribute":945 946 947 if (!member.isUnforgeable)948 {949 this.test_member_attribute(member);950 }951 break;952 case "operation":953 954 955 956 957 if (member.name) {958 if (!member.isUnforgeable)959 {960 this.test_member_operation(member);961 }962 } else if (member.stringifier) {963 this.test_member_stringifier(member);964 }965 break;966 default:967 968 break;969 }970 }971};972IdlInterface.prototype.test_object = function(desc)973{974 var obj, exception = null;975 try976 {977 obj = eval(desc);978 }979 catch(e)980 {981 exception = e;982 }983 984 985 var expected_typeof = this.members.some(function(member)986 {987 return member.legacycaller988 || ("idlType" in member && member.idlType.legacycaller)989 || ("idlType" in member && typeof member.idlType == "object"990 && "idlType" in member.idlType && member.idlType.idlType == "legacycaller");991 }) ? "function" : "object";992 this.test_primary_interface_of(desc, obj, exception, expected_typeof);993 var current_interface = this;994 while (current_interface)995 {996 if (!(current_interface.name in this.array.members))997 {998 throw "Interface " + current_interface.name + " not found (inherited by " + this.name + ")";999 }1000 if (current_interface.prevent_multiple_testing && current_interface.already_tested)1001 {1002 return;1003 }1004 current_interface.test_interface_of(desc, obj, exception, expected_typeof);1005 current_interface = this.array.members[current_interface.base];1006 }1007};1008IdlInterface.prototype.test_primary_interface_of = function(desc, obj, exception, expected_typeof)1009{1010 1011 1012 1013 1014 if (!this.has_extended_attribute("NoInterfaceObject")1015 && (typeof obj != expected_typeof || obj instanceof Object))1016 {1017 test(function()1018 {1019 assert_equals(exception, null, "Unexpected exception when evaluating object");1020 assert_equals(typeof obj, expected_typeof, "wrong typeof object");1021 assert_own_property(self, this.name,1022 "self does not have own property " + format_value(this.name));1023 assert_own_property(self[this.name], "prototype",1024 'interface "' + this.name + '" does not have own property "prototype"');1025 1026 1027 1028 1029 assert_equals(Object.getPrototypeOf(obj),1030 self[this.name].prototype,1031 desc + "'s prototype is not " + this.name + ".prototype");1032 }.bind(this), this.name + " must be primary interface of " + desc);1033 }1034 1035 1036 1037 test(function()1038 {1039 assert_equals(exception, null, "Unexpected exception when evaluating object");1040 assert_equals(typeof obj, expected_typeof, "wrong typeof object");1041 assert_class_string(obj, this.name, "class string of " + desc);1042 if (!this.has_stringifier())1043 {1044 assert_equals(String(obj), "[object " + this.name + "]", "String(" + desc + ")");1045 }1046 }.bind(this), "Stringification of " + desc);1047};1048IdlInterface.prototype.test_interface_of = function(desc, obj, exception, expected_typeof)1049{1050 1051 this.already_tested = true;1052 for (var i = 0; i < this.members.length; i++)1053 {1054 var member = this.members[i];1055 if (member.type == "attribute" && member.isUnforgeable)1056 {1057 test(function()1058 {1059 assert_equals(exception, null, "Unexpected exception when evaluating object");1060 assert_equals(typeof obj, expected_typeof, "wrong typeof object");1061 this.do_interface_attribute_asserts(obj, member);1062 }.bind(this), this.name + " interface: " + desc + ' must have own property "' + member.name + '"');1063 }1064 else if (member.type == "operation" &&1065 member.name &&1066 member.isUnforgeable)1067 {1068 test(function()1069 {1070 assert_equals(exception, null, "Unexpected exception when evaluating object");1071 assert_equals(typeof obj, expected_typeof, "wrong typeof object");1072 assert_own_property(obj, member.name,1073 "Doesn't have the unforgeable operation property");1074 this.do_member_operation_asserts(obj, member);1075 }.bind(this), this.name + " interface: " + desc + ' must have own property "' + member.name + '"');1076 }1077 else if ((member.type == "const"1078 || member.type == "attribute"1079 || member.type == "operation")1080 && member.name)1081 {1082 test(function()1083 {1084 assert_equals(exception, null, "Unexpected exception when evaluating object");1085 assert_equals(typeof obj, expected_typeof, "wrong typeof object");1086 if (!member["static"]) {1087 if (!this.is_global()) {1088 assert_inherits(obj, member.name);1089 } else {1090 assert_own_property(obj, member.name);1091 }1092 if (member.type == "const")1093 {1094 assert_equals(obj[member.name], constValue(member.value));1095 }1096 if (member.type == "attribute")1097 {1098 1099 1100 1101 var property, thrown = false;1102 try1103 {1104 property = obj[member.name];1105 }1106 catch (e)1107 {1108 thrown = true;1109 }1110 if (!thrown)1111 {1112 this.array.assert_type_is(property, member.idlType);1113 }1114 }1115 if (member.type == "operation")1116 {1117 assert_equals(typeof obj[member.name], "function");1118 }1119 }1120 }.bind(this), this.name + " interface: " + desc + ' must inherit property "' + member.name + '" with the proper type (' + i + ')');1121 }1122 1123 1124 1125 if (member.type == "operation" && member.name && member.arguments.length)1126 {1127 test(function()1128 {1129 assert_equals(exception, null, "Unexpected exception when evaluating object");1130 assert_equals(typeof obj, expected_typeof, "wrong typeof object");1131 if (!member["static"]) {1132 if (!this.is_global() && !member.isUnforgeable) {1133 assert_inherits(obj, member.name);1134 } else {1135 assert_own_property(obj, member.name);1136 }1137 }1138 else1139 {1140 assert_false(member.name in obj);1141 }1142 var minLength = minOverloadLength(this.members.filter(function(m) {1143 return m.type == "operation" && m.name == member.name;1144 }));1145 var args = [];1146 for (var i = 0; i < minLength; i++) {1147 assert_throws(new TypeError(), function()1148 {1149 obj[member.name].apply(obj, args);1150 }.bind(this), "Called with " + i + " arguments");1151 args.push(create_suitable_object(member.arguments[i].idlType));1152 }1153 }.bind(this), this.name + " interface: calling " + member.name +1154 "(" + member.arguments.map(function(m) { return m.idlType.idlType; }) +1155 ") on " + desc + " with too few arguments must throw TypeError");1156 }1157 }1158};1159IdlInterface.prototype.has_stringifier = function()1160{1161 if (this.members.some(function(member) { return member.stringifier; })) {1162 return true;1163 }1164 if (this.base &&1165 this.array.members[this.base].has_stringifier()) {1166 return true;1167 }1168 return false;1169};1170IdlInterface.prototype.do_interface_attribute_asserts = function(obj, member)1171{1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 assert_own_property(obj, member.name);1183 1184 1185 1186 1187 1188 1189 var desc = Object.getOwnPropertyDescriptor(obj, member.name);1190 assert_false("value" in desc, 'property descriptor has value but is supposed to be accessor');1191 assert_false("writable" in desc, 'property descriptor has "writable" field but is supposed to be accessor');1192 assert_true(desc.enumerable, "property is not enumerable");1193 if (member.isUnforgeable)1194 {1195 assert_false(desc.configurable, "[Unforgeable] property must not be configurable");1196 }1197 else1198 {1199 assert_true(desc.configurable, "property must be configurable");1200 }1201 1202 1203 assert_equals(typeof desc.get, "function", "getter must be Function");1204 1205 if (!member["static"]) {1206 1207 1208 1209 1210 if (!member.has_extended_attribute("LenientThis")) {1211 assert_throws(new TypeError(), function() {1212 desc.get.call({});1213 }.bind(this), "calling getter on wrong object type must throw TypeError");1214 } else {1215 assert_equals(desc.get.call({}), undefined,1216 "calling getter on wrong object type must return undefined");1217 }1218 }1219 1220 1221 assert_equals(desc.get.length, 0, "getter length must be 0");1222 1223 1224 if (member.readonly1225 && !member.has_extended_attribute("PutForwards")1226 && !member.has_extended_attribute("Replaceable"))1227 {1228 1229 1230 1231 assert_equals(desc.set, undefined, "setter must be undefined for readonly attributes");1232 }1233 else1234 {1235 1236 1237 assert_equals(typeof desc.set, "function", "setter must be function for PutForwards, Replaceable, or non-readonly attributes");1238 1239 if (!member["static"]) {1240 1241 1242 1243 1244 1245 1246 if (!member.has_extended_attribute("LenientThis")) {1247 assert_throws(new TypeError(), function() {1248 desc.set.call({});1249 }.bind(this), "calling setter on wrong object type must throw TypeError");1250 } else {1251 assert_equals(desc.set.call({}), undefined,1252 "calling setter on wrong object type must return undefined");1253 }1254 }1255 1256 1257 assert_equals(desc.set.length, 1, "setter length must be 1");1258 }1259}1260function IdlInterfaceMember(obj)1261{1262 1263 for (var k in obj)1264 {1265 this[k] = obj[k];1266 }1267 if (!("extAttrs" in this))1268 {1269 this.extAttrs = [];1270 }1271 this.isUnforgeable = this.has_extended_attribute("Unforgeable");1272}1273IdlInterfaceMember.prototype = Object.create(IdlObject.prototype);1274function create_suitable_object(type)1275{1276 1277 if (type.nullable)1278 {1279 return null;1280 }1281 switch (type.idlType)1282 {1283 case "any":1284 case "boolean":1285 return true;1286 case "byte": case "octet": case "short": case "unsigned short":1287 case "long": case "unsigned long": case "long long":1288 case "unsigned long long": case "float": case "double":...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var options = {3};4var wpt = new WebPageTest('www.webpagetest.org', options.key);5 if ( err ) {6 console.log( "Error in creating suitable object: " + err );7 }8 else {9 console.log( "Suitable object created: " + data );10 }11});

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