Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(889)

Side by Side Diff: third_party/WebKit/LayoutTests/http/tests/w3c/resources/WebIDLParser.js

Issue 1493473002: Update testharness.js and friends (and duplicate copies) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 1
2 2
3 (function () { 3 (function () {
4 var tokenise = function (str) { 4 var tokenise = function (str) {
5 var tokens = [] 5 var tokens = []
6 , re = { 6 , re = {
7 "float": /^-?(([0-9]+\.[0-9]*|[0-9]*\.[0-9]+)([Ee][-+]?[0 -9]+)?|[0-9]+[Ee][-+]?[0-9]+)/ 7 "float": /^-?(([0-9]+\.[0-9]*|[0-9]*\.[0-9]+)([Ee][-+]?[0 -9]+)?|[0-9]+[Ee][-+]?[0-9]+)/
8 , "integer": /^-?(0([Xx][0-9A-Fa-f]+|[0-7]*)|[1-9][0-9]*)/ 8 , "integer": /^-?(0([Xx][0-9A-Fa-f]+|[0-7]*)|[1-9][0-9]*)/
9 , "identifier": /^[A-Z_a-z][0-9A-Z_a-z]*/ 9 , "identifier": /^[A-Z_a-z][0-9A-Z_a-z]*/
10 , "string": /^"[^"]*"/ 10 , "string": /^"[^"]*"/
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 // Generic types 207 // Generic types
208 if (consume(OTHER, "<")) { 208 if (consume(OTHER, "<")) {
209 // backwards compat 209 // backwards compat
210 if (value === "sequence") { 210 if (value === "sequence") {
211 ret.sequence = true; 211 ret.sequence = true;
212 } 212 }
213 ret.generic = value; 213 ret.generic = value;
214 ret.idlType = type() || error("Error parsing generic type " + value); 214 ret.idlType = type() || error("Error parsing generic type " + value);
215 all_ws(); 215 all_ws();
216 if (!consume(OTHER, ">")) error("Unterminated generic type " + value); 216 if (!consume(OTHER, ">")) error("Unterminated generic type " + value);
217 all_ws(); 217 type_suffix(ret);
218 if (consume(OTHER, "?")) ret.nullable = true;
219 return ret; 218 return ret;
220 } 219 }
221 else { 220 else {
222 ret.idlType = value; 221 ret.idlType = value;
223 } 222 }
224 } 223 }
225 else { 224 else {
226 return; 225 return;
227 } 226 }
228 type_suffix(ret); 227 type_suffix(ret);
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 all_ws(); 323 all_ws();
325 var name = consume(ID); 324 var name = consume(ID);
326 if (!name) return; 325 if (!name) return;
327 var ret = { 326 var ret = {
328 name: name.value 327 name: name.value
329 , "arguments": null 328 , "arguments": null
330 }; 329 };
331 all_ws(); 330 all_ws();
332 var eq = consume(OTHER, "="); 331 var eq = consume(OTHER, "=");
333 if (eq) { 332 if (eq) {
333 var rhs;
334 all_ws(); 334 all_ws();
335 ret.rhs = consume(ID); 335 if (rhs = consume(ID)) {
336 ret.rhs = rhs
337 }
338 else if (consume(OTHER, "(")) {
339 // [Exposed=(Window,Worker)]
340 rhs = [];
341 var id = consume(ID);
342 if (id) {
343 rhs = [id.value];
344 }
345 identifiers(rhs);
346 consume(OTHER, ")") || error("Unexpected token in extended a ttribute argument list or type pair");
347 ret.rhs = {
348 type: "identifier-list",
349 value: rhs
350 };
351 }
336 if (!ret.rhs) return error("No right hand side to extended attri bute assignment"); 352 if (!ret.rhs) return error("No right hand side to extended attri bute assignment");
337 } 353 }
338 all_ws(); 354 all_ws();
339 if (consume(OTHER, "(")) { 355 if (consume(OTHER, "(")) {
340 var args, pair; 356 var args, pair;
341 // [Constructor(DOMString str)] 357 // [Constructor(DOMString str)]
342 if (args = argument_list(store)) { 358 if (args = argument_list(store)) {
343 ret["arguments"] = args; 359 ret["arguments"] = args;
344 } 360 }
345 // [MapClass(DOMString, DOMString)] 361 // [MapClass(DOMString, DOMString)]
(...skipping 27 matching lines...) Expand all
373 }; 389 };
374 390
375 var default_ = function () { 391 var default_ = function () {
376 all_ws(); 392 all_ws();
377 if (consume(OTHER, "=")) { 393 if (consume(OTHER, "=")) {
378 all_ws(); 394 all_ws();
379 var def = const_value(); 395 var def = const_value();
380 if (def) { 396 if (def) {
381 return def; 397 return def;
382 } 398 }
399 else if (consume(OTHER, "[")) {
400 if (!consume(OTHER, "]")) error("Default sequence value must be empty");
401 return { type: "sequence", value: [] };
402 }
383 else { 403 else {
384 var str = consume(STR) || error("No value for default"); 404 var str = consume(STR) || error("No value for default");
385 str.value = str.value.replace(/^"/, "").replace(/"$/, ""); 405 str.value = str.value.replace(/^"/, "").replace(/"$/, "");
386 return str; 406 return str;
387 } 407 }
388 } 408 }
389 }; 409 };
390 410
391 var const_ = function (store) { 411 var const_ = function (store) {
392 all_ws(store, "pea"); 412 all_ws(store, "pea");
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 operation_rest(ret, store); 575 operation_rest(ret, store);
556 return ret; 576 return ret;
557 } 577 }
558 if (consume(ID, "static")) { 578 if (consume(ID, "static")) {
559 ret["static"] = true; 579 ret["static"] = true;
560 ret.idlType = return_type(); 580 ret.idlType = return_type();
561 operation_rest(ret, store); 581 operation_rest(ret, store);
562 return ret; 582 return ret;
563 } 583 }
564 else if (consume(ID, "stringifier")) { 584 else if (consume(ID, "stringifier")) {
565 ret.stringifier = true; 585 ret.stringifier = true;-
566 all_ws(); 586 all_ws();
567 if (consume(OTHER, ";")) return ret; 587 if (consume(OTHER, ";")) return ret;
568 ret.idlType = return_type(); 588 ret.idlType = return_type();
569 operation_rest(ret, store); 589 operation_rest(ret, store);
570 return ret; 590 return ret;
571 } 591 }
572 ret.idlType = return_type(); 592 ret.idlType = return_type();
573 all_ws(); 593 all_ws();
574 if (consume(ID, "iterator")) { 594 if (consume(ID, "iterator")) {
575 all_ws(); 595 all_ws();
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 // noop, just parsing 681 // noop, just parsing
662 } 682 }
663 else { 683 else {
664 ret.idlType = return_type(); 684 ret.idlType = return_type();
665 all_ws(); 685 all_ws();
666 ret.operation = operation_rest(null, store); 686 ret.operation = operation_rest(null, store);
667 } 687 }
668 return ret; 688 return ret;
669 }; 689 };
670 690
691 var iterable_type = function() {
692 if (consume(ID, "iterable")) return "iterable";
693 else if (consume(ID, "legacyiterable")) return "legacyiterable";
694 else if (consume(ID, "maplike")) return "maplike";
695 else if (consume(ID, "setlike")) return "setlike";
696 else return;
697 }
698
699 var readonly_iterable_type = function() {
700 if (consume(ID, "maplike")) return "maplike";
701 else if (consume(ID, "setlike")) return "setlike";
702 else return;
703 }
704
705 var iterable = function (store) {
706 all_ws(store, "pea");
707 var grabbed = [],
708 ret = {type: null, idlType: null, readonly: false};
709 if (consume(ID, "readonly")) {
710 ret.readonly = true;
711 grabbed.push(last_token);
712 var w = all_ws();
713 if (w) grabbed.push(w);
714 }
715 var consumeItType = ret.readonly ? readonly_iterable_type : iterable _type;
716
717 var ittype = consumeItType();
718 if (!ittype) {
719 tokens = grabbed.concat(tokens);
720 return;
721 }
722
723 var secondTypeRequired = ittype === "maplike";
724 var secondTypeAllowed = secondTypeRequired || ittype === "iterable";
725 ret.type = ittype;
726 if (ret.type !== 'maplike' && ret.type !== 'setlike')
727 delete ret.readonly;
728 all_ws();
729 if (consume(OTHER, "<")) {
730 ret.idlType = type() || error("Error parsing " + ittype + " decl aration");
731 all_ws();
732 if (secondTypeAllowed) {
733 var type2 = null;
734 if (consume(OTHER, ",")) {
735 all_ws();
736 type2 = type();
737 all_ws();
738 }
739 if (type2)
740 ret.idlType = [ret.idlType, type2];
741 else if (secondTypeRequired)
742 error("Missing second type argument in " + ittype + " de claration");
743 }
744 if (!consume(OTHER, ">")) error("Unterminated " + ittype + " dec laration");
745 all_ws();
746 if (!consume(OTHER, ";")) error("Missing semicolon after " + itt ype + " declaration");
747 }
748 else
749 error("Error parsing " + ittype + " declaration");
750
751 return ret;
752 }
753
671 var interface_ = function (isPartial, store) { 754 var interface_ = function (isPartial, store) {
672 all_ws(isPartial ? null : store, "pea"); 755 all_ws(isPartial ? null : store, "pea");
673 if (!consume(ID, "interface")) return; 756 if (!consume(ID, "interface")) return;
674 all_ws(); 757 all_ws();
675 var name = consume(ID) || error("No name for interface"); 758 var name = consume(ID) || error("No name for interface");
676 var mems = [] 759 var mems = []
677 , ret = { 760 , ret = {
678 type: "interface" 761 type: "interface"
679 , name: name.value 762 , name: name.value
680 , partial: false 763 , partial: false
(...skipping 10 matching lines...) Expand all
691 return ret; 774 return ret;
692 } 775 }
693 var ea = extended_attrs(store ? mems : null); 776 var ea = extended_attrs(store ? mems : null);
694 all_ws(); 777 all_ws();
695 var cnt = const_(store ? mems : null); 778 var cnt = const_(store ? mems : null);
696 if (cnt) { 779 if (cnt) {
697 cnt.extAttrs = ea; 780 cnt.extAttrs = ea;
698 ret.members.push(cnt); 781 ret.members.push(cnt);
699 continue; 782 continue;
700 } 783 }
701 var mem = serialiser(store ? mems : null) || 784 var mem = (opt.allowNestedTypedefs && typedef(store ? mems : nul l)) ||
785 iterable(store ? mems : null) ||
786 serialiser(store ? mems : null) ||
702 attribute(store ? mems : null) || 787 attribute(store ? mems : null) ||
703 operation(store ? mems : null) || 788 operation(store ? mems : null) ||
704 error("Unknown member"); 789 error("Unknown member");
705 mem.extAttrs = ea; 790 mem.extAttrs = ea;
706 ret.members.push(mem); 791 ret.members.push(mem);
707 } 792 }
708 }; 793 };
709 794
710 var partial = function (store) { 795 var partial = function (store) {
711 all_ws(store, "pea"); 796 all_ws(store, "pea");
(...skipping 22 matching lines...) Expand all
734 consume(OTHER, "{") || error("Bodyless dictionary"); 819 consume(OTHER, "{") || error("Bodyless dictionary");
735 while (true) { 820 while (true) {
736 all_ws(store ? mems : null); 821 all_ws(store ? mems : null);
737 if (consume(OTHER, "}")) { 822 if (consume(OTHER, "}")) {
738 all_ws(); 823 all_ws();
739 consume(OTHER, ";") || error("Missing semicolon after dictio nary"); 824 consume(OTHER, ";") || error("Missing semicolon after dictio nary");
740 return ret; 825 return ret;
741 } 826 }
742 var ea = extended_attrs(store ? mems : null); 827 var ea = extended_attrs(store ? mems : null);
743 all_ws(store ? mems : null, "pea"); 828 all_ws(store ? mems : null, "pea");
829 var required = consume(ID, "required");
744 var typ = type() || error("No type for dictionary member"); 830 var typ = type() || error("No type for dictionary member");
745 all_ws(); 831 all_ws();
746 var name = consume(ID) || error("No name for dictionary member") ; 832 var name = consume(ID) || error("No name for dictionary member") ;
833 var dflt = default_();
834 if (required && dflt) error("Required member must not have a def ault");
747 ret.members.push({ 835 ret.members.push({
748 type: "field" 836 type: "field"
749 , name: name.value 837 , name: name.value
838 , required: !!required
750 , idlType: typ 839 , idlType: typ
751 , extAttrs: ea 840 , extAttrs: ea
752 , "default": default_() 841 , "default": dflt
753 }); 842 });
754 all_ws(); 843 all_ws();
755 consume(OTHER, ";") || error("Unterminated dictionary member"); 844 consume(OTHER, ";") || error("Unterminated dictionary member");
756 } 845 }
757 }; 846 };
758 847
759 var exception = function (store) { 848 var exception = function (store) {
760 all_ws(store, "pea"); 849 all_ws(store, "pea");
761 if (!consume(ID, "exception")) return; 850 if (!consume(ID, "exception")) return;
762 all_ws(); 851 all_ws();
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
811 , name: name.value 900 , name: name.value
812 , values: vals 901 , values: vals
813 }; 902 };
814 all_ws(); 903 all_ws();
815 consume(OTHER, "{") || error("No curly for enum"); 904 consume(OTHER, "{") || error("No curly for enum");
816 var saw_comma = false; 905 var saw_comma = false;
817 while (true) { 906 while (true) {
818 all_ws(store ? vals : null); 907 all_ws(store ? vals : null);
819 if (consume(OTHER, "}")) { 908 if (consume(OTHER, "}")) {
820 all_ws(); 909 all_ws();
821 if (saw_comma) error("Trailing comma in enum");
822 consume(OTHER, ";") || error("No semicolon after enum"); 910 consume(OTHER, ";") || error("No semicolon after enum");
823 return ret; 911 return ret;
824 } 912 }
825 var val = consume(STR) || error("Unexpected value in enum"); 913 var val = consume(STR) || error("Unexpected value in enum");
826 ret.values.push(val.value.replace(/"/g, "")); 914 ret.values.push(val.value.replace(/"/g, ""));
827 all_ws(store ? vals : null); 915 all_ws(store ? vals : null);
828 if (consume(OTHER, ",")) { 916 if (consume(OTHER, ",")) {
829 if (store) vals.push({ type: "," }); 917 if (store) vals.push({ type: "," });
830 all_ws(store ? vals : null); 918 all_ws(store ? vals : null);
831 saw_comma = true; 919 saw_comma = true;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
915 parse: function (str, opt) { 1003 parse: function (str, opt) {
916 if (!opt) opt = {}; 1004 if (!opt) opt = {};
917 var tokens = tokenise(str); 1005 var tokens = tokenise(str);
918 return parse(tokens, opt); 1006 return parse(tokens, opt);
919 } 1007 }
920 }; 1008 };
921 1009
922 if (inNode) module.exports = obj; 1010 if (inNode) module.exports = obj;
923 else self.WebIDL2 = obj; 1011 else self.WebIDL2 = obj;
924 }()); 1012 }());
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698