Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | "use strict"; |
michael@0 | 6 | |
michael@0 | 7 | module.metadata = { |
michael@0 | 8 | "stability": "unstable" |
michael@0 | 9 | }; |
michael@0 | 10 | |
michael@0 | 11 | const { Cc, Ci } = require('chrome'); |
michael@0 | 12 | const { EventEmitter } = require('../deprecated/events'); |
michael@0 | 13 | const { isValidURI, URL } = require('../url'); |
michael@0 | 14 | const { contract } = require('../util/contract'); |
michael@0 | 15 | const { extend } = require('../util/object'); |
michael@0 | 16 | |
michael@0 | 17 | // map of property validations |
michael@0 | 18 | const validItem = { |
michael@0 | 19 | id: { |
michael@0 | 20 | is: ['number', 'undefined', 'null'], |
michael@0 | 21 | }, |
michael@0 | 22 | group: { |
michael@0 | 23 | is: ['object', 'number', 'undefined', 'null'], |
michael@0 | 24 | ok: function (value) { |
michael@0 | 25 | return value && |
michael@0 | 26 | (value.toString && value.toString() === '[object Group]') || |
michael@0 | 27 | typeof value === 'number' || |
michael@0 | 28 | value.type === 'group'; |
michael@0 | 29 | }, |
michael@0 | 30 | msg: 'The `group` property must be a valid Group object' |
michael@0 | 31 | }, |
michael@0 | 32 | index: { |
michael@0 | 33 | is: ['undefined', 'null', 'number'], |
michael@0 | 34 | map: function (value) value == null ? -1 : value, |
michael@0 | 35 | msg: 'The `index` property must be a number.' |
michael@0 | 36 | }, |
michael@0 | 37 | updated: { |
michael@0 | 38 | is: ['number', 'undefined'] |
michael@0 | 39 | } |
michael@0 | 40 | }; |
michael@0 | 41 | |
michael@0 | 42 | const validTitle = { |
michael@0 | 43 | title: { |
michael@0 | 44 | is: ['string'], |
michael@0 | 45 | msg: 'The `title` property must be defined.' |
michael@0 | 46 | } |
michael@0 | 47 | }; |
michael@0 | 48 | |
michael@0 | 49 | const validURL = { |
michael@0 | 50 | url: { |
michael@0 | 51 | is: ['string'], |
michael@0 | 52 | ok: isValidURI, |
michael@0 | 53 | msg: 'The `url` property must be a valid URL.' |
michael@0 | 54 | } |
michael@0 | 55 | }; |
michael@0 | 56 | |
michael@0 | 57 | const validTags = { |
michael@0 | 58 | tags: { |
michael@0 | 59 | is: ['object'], |
michael@0 | 60 | ok: function (tags) tags instanceof Set, |
michael@0 | 61 | map: function (tags) { |
michael@0 | 62 | if (Array.isArray(tags)) |
michael@0 | 63 | return new Set(tags); |
michael@0 | 64 | if (tags == null) |
michael@0 | 65 | return new Set(); |
michael@0 | 66 | return tags; |
michael@0 | 67 | }, |
michael@0 | 68 | msg: 'The `tags` property must be a Set, or an array' |
michael@0 | 69 | } |
michael@0 | 70 | }; |
michael@0 | 71 | |
michael@0 | 72 | exports.bookmarkContract = contract( |
michael@0 | 73 | extend(validItem, validTitle, validURL, validTags)); |
michael@0 | 74 | exports.separatorContract = contract(validItem); |
michael@0 | 75 | exports.groupContract = contract(extend(validItem, validTitle)); |