~ubuntu-branches/ubuntu/vivid/emscripten/vivid

« back to all changes in this revision

Viewing changes to tools/node_modules/source-map/lib/source-map/util.js

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-09-20 22:44:35 UTC
  • mfrom: (4.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20130920224435-apuwj4fsl3fqv1a6
Tags: 1.5.6~20130920~6010666-1
* New snapshot release
* Update the list of supported architectures to the same as libv8
  (Closes: #723129)
* emlibtool has been removed from upstream.
* Fix warning syntax-error-in-dep5-copyright
* Refresh of the patches

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: js; js-indent-level: 2; -*- */
 
2
/*
 
3
 * Copyright 2011 Mozilla Foundation and contributors
 
4
 * Licensed under the New BSD license. See LICENSE or:
 
5
 * http://opensource.org/licenses/BSD-3-Clause
 
6
 */
 
7
if (typeof define !== 'function') {
 
8
    var define = require('amdefine')(module);
 
9
}
 
10
define(function (require, exports, module) {
 
11
 
 
12
  /**
 
13
   * This is a helper function for getting values from parameter/options
 
14
   * objects.
 
15
   *
 
16
   * @param args The object we are extracting values from
 
17
   * @param name The name of the property we are getting.
 
18
   * @param defaultValue An optional value to return if the property is missing
 
19
   * from the object. If this is not specified and the property is missing, an
 
20
   * error will be thrown.
 
21
   */
 
22
  function getArg(aArgs, aName, aDefaultValue) {
 
23
    if (aName in aArgs) {
 
24
      return aArgs[aName];
 
25
    } else if (arguments.length === 3) {
 
26
      return aDefaultValue;
 
27
    } else {
 
28
      throw new Error('"' + aName + '" is a required argument.');
 
29
    }
 
30
  }
 
31
  exports.getArg = getArg;
 
32
 
 
33
  var urlRegexp = /([\w+\-.]+):\/\/((\w+:\w+)@)?([\w.]+)?(:(\d+))?(\S+)?/;
 
34
 
 
35
  function urlParse(aUrl) {
 
36
    var match = aUrl.match(urlRegexp);
 
37
    if (!match) {
 
38
      return null;
 
39
    }
 
40
    return {
 
41
      scheme: match[1],
 
42
      auth: match[3],
 
43
      host: match[4],
 
44
      port: match[6],
 
45
      path: match[7]
 
46
    };
 
47
  }
 
48
  exports.urlParse = urlParse;
 
49
 
 
50
  function urlGenerate(aParsedUrl) {
 
51
    var url = aParsedUrl.scheme + "://";
 
52
    if (aParsedUrl.auth) {
 
53
      url += aParsedUrl.auth + "@"
 
54
    }
 
55
    if (aParsedUrl.host) {
 
56
      url += aParsedUrl.host;
 
57
    }
 
58
    if (aParsedUrl.port) {
 
59
      url += ":" + aParsedUrl.port
 
60
    }
 
61
    if (aParsedUrl.path) {
 
62
      url += aParsedUrl.path;
 
63
    }
 
64
    return url;
 
65
  }
 
66
  exports.urlGenerate = urlGenerate;
 
67
 
 
68
  function join(aRoot, aPath) {
 
69
    var url;
 
70
 
 
71
    if (aPath.match(urlRegexp)) {
 
72
      return aPath;
 
73
    }
 
74
 
 
75
    if (aPath.charAt(0) === '/' && (url = urlParse(aRoot))) {
 
76
      url.path = aPath;
 
77
      return urlGenerate(url);
 
78
    }
 
79
 
 
80
    return aRoot.replace(/\/$/, '') + '/' + aPath;
 
81
  }
 
82
  exports.join = join;
 
83
 
 
84
  /**
 
85
   * Because behavior goes wacky when you set `__proto__` on objects, we
 
86
   * have to prefix all the strings in our set with an arbitrary character.
 
87
   *
 
88
   * See https://github.com/mozilla/source-map/pull/31 and
 
89
   * https://github.com/mozilla/source-map/issues/30
 
90
   *
 
91
   * @param String aStr
 
92
   */
 
93
  function toSetString(aStr) {
 
94
    return '$' + aStr;
 
95
  }
 
96
  exports.toSetString = toSetString;
 
97
 
 
98
  function fromSetString(aStr) {
 
99
    return aStr.substr(1);
 
100
  }
 
101
  exports.fromSetString = fromSetString;
 
102
 
 
103
  function relative(aRoot, aPath) {
 
104
    aRoot = aRoot.replace(/\/$/, '');
 
105
 
 
106
    var url = urlParse(aRoot);
 
107
    if (aPath.charAt(0) == "/" && url && url.path == "/") {
 
108
      return aPath.slice(1);
 
109
    }
 
110
 
 
111
    return aPath.indexOf(aRoot + '/') === 0
 
112
      ? aPath.substr(aRoot.length + 1)
 
113
      : aPath;
 
114
  }
 
115
  exports.relative = relative;
 
116
 
 
117
});