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

Side by Side Diff: third_party/WebKit/LayoutTests/imported/wpt/common/utils.js

Issue 2015623004: Import wpt@ed94c51f3dfaa5ff4c9c311add1a560408059c51 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months 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
(Empty)
1 function make_absolute_url(options) {
2 var loc = window.location;
3 var protocol = get(options, "protocol", loc.protocol);
4 if (protocol[protocol.length - 1] != ":") {
5 protocol += ":";
6 }
7
8 var hostname = get(options, "hostname", loc.hostname);
9
10 var subdomain = get(options, "subdomain");
11 if (subdomain) {
12 hostname = subdomain + "." + hostname;
13 }
14
15 var port = get(options, "port", loc.port)
16 var path = get(options, "path", loc.pathname);
17 var query = get(options, "query", loc.search);
18 var hash = get(options, "hash", loc.hash)
19
20 var url = protocol + "//" + hostname;
21 if (port) {
22 url += ":" + port;
23 }
24
25 if (path[0] != "/") {
26 url += "/";
27 }
28 url += path;
29 if (query) {
30 if (query[0] != "?") {
31 url += "?";
32 }
33 url += query;
34 }
35 if (hash) {
36 if (hash[0] != "#") {
37 url += "#";
38 }
39 url += hash;
40 }
41 return url;
42 }
43
44 function get(obj, name, default_val) {
45 if (obj.hasOwnProperty(name)) {
46 return obj[name];
47 }
48 return default_val;
49 }
50
51 function token() {
52 var uuid = [to_hex(rand_int(32), 8),
53 to_hex(rand_int(16), 4),
54 to_hex(0x4000 | rand_int(12), 4),
55 to_hex(0x8000 | rand_int(14), 4),
56 to_hex(rand_int(48), 12)].join("-")
57 return uuid;
58 }
59
60 function rand_int(bits) {
61 if (bits < 1 || bits > 53) {
62 throw new TypeError();
63 } else {
64 if (bits >= 1 && bits <= 30) {
65 return 0 | ((1 << bits) * Math.random());
66 } else {
67 var high = (0 | ((1 << (bits - 30)) * Math.random())) * (1 << 30);
68 var low = 0 | ((1 << 30) * Math.random());
69 return high + low;
70 }
71 }
72 }
73
74 function to_hex(x, length) {
75 var rv = x.toString(16);
76 while (rv.length < length) {
77 rv = "0" + rv;
78 }
79 return rv;
80 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698